void main ()
{
volatile sBSP430hplTIMER * const hpl = xBSP430hplLookupTIMER(BSP430_PERIPH_TA0);
unsigned long ta0_Hz;
unsigned int delta_ta0;
const struct sLPMconfig * lcp = lpm_configs;
const struct sLPMconfig * const elcp = lpm_configs + sizeof(lpm_configs)/sizeof(*lpm_configs);
vBSP430platformInitialize_ni();
(void)iBSP430consoleInitialize();
TA0CTL = TASSEL_1 | MC_2 | TACLR;
ta0_Hz = ulBSP430timerFrequency_Hz_ni(BSP430_PERIPH_TA0);
#if 0
/* This sequence eliminates the wakeup delay on the MSP430F5438A.
* The ramifications of doing this are to be found in the Power
* Management Module and Supply Voltage Supervisor chapter of the
* 5xx/6xx Family User's Guide, in the section "SVS and SVM
* Performance Modes and Wakeup Times".
*
* Also check MCU errata related to the PMM. THere are several that
* appear relevant when changing the module from its power-up
* state. */
PMMCTL0_H = PMMPW_H;
#if 1
/* This variant works */
SVSMLCTL &= ~(SVSLE | SVMLE);
#else
/* This appears to have no effect, though it should work. */
SVSMLCTL |= SVSLFP;
#endif
PMMCTL0_H = !PMMPW_H;
#endif
BSP430_CORE_ENABLE_INTERRUPT();
cputs("\n\nTimer LPM wake delay test\n");
delta_ta0 = ta0_Hz / 4;
cprintf("TA0 is at %lu Hz; sleep time %u ticks\n", ta0_Hz, delta_ta0);
cprintf("Standard mode SR is %04x\n", __read_status_register());
cprintf("SR bits: SCG0 %04x ; SCG1 %04x\n", SCG0, SCG1);
cprintf("LPM exit from ISRs clears: %04x\n", BSP430_CORE_LPM_EXIT_MASK);
cputs("LPMx CCR0 CAP0 Delta0 CCR1 CAP1 Delta1 SR");
while (lcp < elcp) {
unsigned int tar;
cprintf("%s: ", lcp->tag);
BSP430_CORE_DISABLE_INTERRUPT();
ta0r = 0;
hpl->cctl[0] = CCIE;
tar = uiBSP430timerAsyncCounterRead_ni(hpl);
hpl->ccr[0] = tar + delta_ta0;
BSP430_CORE_LPM_ENTER_NI(lcp->lpm_bits);
cprintf("%5u %5u %5u ", hpl->ccr[0], ta0r, ta0r-hpl->ccr[0]);
BSP430_CORE_DISABLE_INTERRUPT();
ta0r = 0;
hpl->cctl[1] = CCIE;
tar = uiBSP430timerAsyncCounterRead_ni(hpl);
hpl->ccr[1] = tar + delta_ta0;
BSP430_CORE_LPM_ENTER_NI(lcp->lpm_bits);
cprintf("%5u %5u %5u ", hpl->ccr[1], ta0r, ta0r-hpl->ccr[1]);
cprintf("%04x\n", __read_status_register());
++lcp;
}
cprintf("Done\n");
}
开发者ID:shiohuang,项目名称:bsp430,代码行数:71,代码来源:main.c
示例4: entry
void entry()
{
char ch;
clrscr();
ptr=fopen("shop.dat","a+b");
ch='y';
while(ch=='y')
{
clrscr();
design();
textcolor(14);
t();
gotoxy(14,3);
cprintf("\xDB\xDB\xDB\xDB\xDB\xB2 PURSHASE \xB2\xDB\xDB\xDB\xDB\xDB ");
{
gotoxy(7,5);
cprintf("\xDB\xDB\xB2 ENTER PRODUCT ID : ");
ventry(temp.id,1);
//
flushall();
gotoxy(7,7);
cprintf("\xDB\xDB\xB2 ENTER DESCRIPTION : ");
ventry(temp.desc,0);
flushall();
gotoxy(7,9);
cprintf("\xDB\xDB\xB2 ENTER RACK NO : ");
ventry(a,1);
temp.rack= atoi(a);
flushall();
gotoxy(7,11);
cprintf("\xDB\xDB\xB2 ENTER CABNIT NO : ");
ventry(a,1);
temp.cabnit= atoi(a);
//
flushall();
gotoxy(7,13);
///////////////////////
cprintf("\xDB\xDB\xB2 ENTER UNIT COST :$ ");
ventry(a,1);
temp.unit= atof(a);
flushall();
gotoxy(7,15);
cprintf("\xDB\xDB\xB2 ENTER SALE PRICE :$ ");
ventry(a,1);
temp.sale= atof(a);
flushall();
gotoxy(7,17);
cprintf("\xDB\xDB\xB2 ENTER QUANTITY : ");
ventry(a,1);
temp.quantity= atoi(a);
flushall();
gotoxy(7,18);
cprintf("=====================================");
temp.total=temp.quantity*temp.sale;
textcolor(10);
gotoxy(10,20);
cprintf("\xB2\xDB\xB2 TOTAL PRICE = $ %.2f",temp.total);
temp.cost=(temp.unit*temp.quantity);
gotoxy(40,20);
cprintf("\xDB\xB2 TOTAL COST = $ %.2f",temp.cost);
}
fwrite(&temp,sizeof(temp),1,ptr);
textcolor(10);
gotoxy(10,23);
cprintf("More entries [y/n]");
ch=getche();
}
fclose(ptr);
}
开发者ID:ASAP-Project,项目名称:ASAP,代码行数:80,代码来源:INVEN.C
示例5: menu
/***************************main menu*************************************/
menu()
{
int x;
do {
{
clrscr();
design();
t();
textcolor(WHITE);
gotoxy(24,3);
cprintf("\xDB\xDB\xDB\xDB\xB2 LYDIA'S DEPARTMENT STORE \xB2\xDB\xDB\xDB\xDB");
gotoxy(3,4);
cprintf("--------------------------------------------------------------------------");
gotoxy(35,5);
cprintf("MAIN MENU");
gotoxy(26,8);
cprintf(" 1 - INFORMATION ABOUT PRODUCTS ");
gotoxy(26,9);
cprintf(" 2 - ENTER PURCHASE RECORDS ");
gotoxy(26,10);
cprintf(" 3 - ENTER PRODUCTS TO BE SALE ");
gotoxy(26,11);
cprintf(" 4 - SEARCH FOR RECORD ");
gotoxy(26,12);
cprintf(" 5 - DELETE RECORD FROM STORE DATABASE ");
gotoxy(26,13);
cprintf(" 6 - VIEW SALES , PURCHASE & PROFIT REPORT ");
gotoxy(26,14);
cprintf(" 7 - PRINT RECORDS ");
gotoxy(26,15);
cprintf(" 8 - BAR GRAPH OF QUANTITY / PROFIT ");
gotoxy(26,16);
cprintf(" 9 - RETRIEVE INFORMATION ");
gotoxy(26,17);
cprintf(" H - HELP ");
gotoxy(26,18);
cprintf(" E - EXIT ");
gotoxy(26,23);
//
cprintf("ENTER YOUR CHOICE :: ");
gotoxy(47,23);
x=toupper(getch());
switch(x)
{
case '1':
infor();
break;
case '2':
entry();
break;
case '3':
edit();
break;
case '4':
search();
break;
case '5':
del();
break;
case '6':
report2();
break;
case '7':
print();
break;
case 'h':
case'H':
help();
break;
case'8':
graph1();
break;
case '9':
display();
break;
case 'e':
case 'E':
exit(0);
break;
default:
clrscr();
design();
gotoxy(17,12);
printf("\a\xDB\xB2 WRONG ENTRY : PRESS ANY KEY AND TRY AGAIN");
getche();
}
}
} while((x!='e')||(x!='E'));
//.........这里部分代码省略.........
void
page_fault_handler(struct Trapframe *tf)
{
uint64_t fault_va;
// Read processor's CR2 register to find the faulting address
fault_va = rcr2();
// Handle kernel-mode page faults.
// LAB 3: Your code here.
if (!(tf->tf_cs & 0x3)) {
print_trapframe(tf);
panic("unhandled trap in kernel");
}
// We've already handled kernel-mode exceptions, so if we get here,
// the page fault happened in user mode.
// Call the environment's page fault upcall, if one exists. Set up a
// page fault stack frame on the user exception stack (below
// UXSTACKTOP), then branch to curenv->env_pgfault_upcall.
//
// The page fault upcall might cause another page fault, in which case
// we branch to the page fault upcall recursively, pushing another
// page fault stack frame on top of the user exception stack.
//
// The trap handler needs one word of scratch space at the top of the
// trap-time stack in order to return. In the non-recursive case, we
// don't have to worry about this because the top of the regular user
// stack is free. In the recursive case, this means we have to leave
// an extra word between the current top of the exception stack and
// the new stack frame because the exception stack _is_ the trap-time
// stack.
//
//
// If there's no page fault upcall, the environment didn't allocate a
// page for its exception stack or can't write to it, or the exception
// stack overflows, then destroy the environment that caused the fault.
// Note that the grade script assumes you will first check for the page
// fault upcall and print the "user fault va" message below if there is
// none. The remaining three checks can be combined into a single test.
//
// Hints:
// user_mem_assert() and env_run() are useful here.
// To change what the user environment runs, modify 'curenv->env_tf'
// (the 'tf' variable points at 'curenv->env_tf').
if (curenv->env_pgfault_upcall) {
struct UTrapframe *utexp;
if (tf->tf_rsp <= UXSTACKTOP-1 && tf->tf_rsp >= UXSTACKTOP-PGSIZE) {
utexp = (struct UTrapframe*) (tf->tf_rsp - sizeof(struct UTrapframe) - 8);
}
else {
utexp = (struct UTrapframe*)(UXSTACKTOP - sizeof(struct UTrapframe));
}
//storing that 64 bit thingy.(this was tough!, I'm weak with bits ;) )
//(time frame) to be stored...but how does it get pushed into the stack...you assign it to uxstacktop
//thats brilliant. Thank you! thank you...wait a minute...see if it overflows!
user_mem_assert(curenv, (void*)utexp, sizeof(struct UTrapframe), PTE_W|PTE_U);
utexp->utf_fault_va = fault_va;
utexp->utf_err = tf->tf_err;
utexp->utf_regs = tf->tf_regs;
utexp->utf_rip = tf->tf_rip;
utexp->utf_eflags = tf->tf_eflags;
utexp->utf_rsp = tf->tf_rsp;
//How do i run the upcall...set the rip...thats nice...thank you exercise 10 :)
tf->tf_rip = (uint64_t)curenv->env_pgfault_upcall;
tf->tf_rsp = (uint64_t)utexp;
env_run(curenv);
}
// LAB 4: Your code here.
// Destroy the environment that caused the fault.
cprintf("[%08x] user fault va %08x ip %08x\n", curenv->env_id, fault_va, tf->tf_rip);
print_trapframe(tf);
env_destroy(curenv);
}
static void
trap_dispatch(struct Trapframe *tf)
{
// Handle processor exceptions.
// LAB 3: Your code here.
int32_t ret;
// if (tf->tf_trapno != 48) cprintf("****** No. %d\n", tf->tf_trapno);
// Handle clock interrupts.
// LAB 4: Your code here.
if (tf->tf_trapno == IRQ_OFFSET + 0){
// cprintf("Timer interrupt\n");
time_tick();
sched_yield();
return ;
}
// Add time tick increment to clock interrupts.
// LAB 6: Your code here.
// Add time_tick above sched_yield
// Handle spurious interrupts
// The hardware sometimes raises these because of noise on the
// IRQ line or other reasons. We don't care.
if (tf->tf_trapno == IRQ_OFFSET + IRQ_SPURIOUS) {
cprintf("Spurious interrupt on irq 7\n");
print_trapframe(tf);
return;
}
// LAB 7: Keyboard interface
if (tf->tf_trapno == IRQ_OFFSET + 1){
kbd_intr();
return ;
}
if (tf->tf_trapno == IRQ_OFFSET + 4){
serial_intr();
return ;
}
if (tf->tf_trapno == T_DIVIDE || tf->tf_trapno == T_ILLOP || tf->tf_trapno == T_GPFLT){
// cprintf("*************");
// return ;
}
if (tf->tf_trapno == T_DEBUG){
// Debug info
// cprintf("*** trap %08x %s ***\n", tf->tf_trapno, trapname(tf->tf_trapno));
// Invoke monitor
monitor(tf);
return ;
}
if (tf->tf_trapno == T_BRKPT){
// Debug info
// cprintf("*** trap %08x %s ***\n", tf->tf_trapno, trapname(tf->tf_trapno));
// Invoke monitor
monitor(tf);
return ;
}
if (tf->tf_trapno == T_PGFLT){
page_fault_handler(tf);
}
if (tf->tf_trapno == T_SYSCALL){
ret = syscall(tf->tf_regs.reg_eax,
tf->tf_regs.reg_edx,
tf->tf_regs.reg_ecx,
tf->tf_regs.reg_ebx,
tf->tf_regs.reg_edi,
tf->tf_regs.reg_esi);
tf->tf_regs.reg_eax = ret;
return ;
}
// Handle keyboard and serial interrupts.
// LAB 7: Your code here.
// Unexpected trap: The user process or the kernel has a bug.
print_trapframe(tf);
if (tf->tf_cs == GD_KT){
if (tf->tf_trapno == T_DEBUG){
return ;
}
panic("unhandled trap in kernel");
}
else {
env_destroy(curenv);
return;
}
}
开发者ID:ChenLanbo,项目名称:OS-Lab,代码行数:95,代码来源:trap.c
示例11: page_fault_handler
// interrupt and trap handlers
void
page_fault_handler(struct Trapframe *tf)
{
uint32_t fault_va;
// Read processor's CR2 register to find the faulting address
fault_va = rcr2();
// Handle kernel-mode page faults.
// previlage level = 0
if ((tf->tf_cs & 3) == 0){
panic("kernel page fault");
}
// LAB 3: Your code here.
// We've already handled kernel-mode exceptions, so if we get here,
// the page fault happened in user mode.
// Call the environment's page fault upcall, if one exists. Set up a
// page fault stack frame on the user exception stack (below
// UXSTACKTOP), then branch to curenv->env_pgfault_upcall.
//
// The page fault upcall might cause another page fault, in which case
// we branch to the page fault upcall recursively, pushing another
// page fault stack frame on top of the user exception stack.
//
// The trap handler needs one word of scratch space at the top of the
// trap-time stack in order to return. In the non-recursive case, we
// don't have to worry about this because the top of the regular user
// stack is free. In the recursive case, this means we have to leave
// an extra word between the current top of the exception stack and
// the new stack frame because the exception stack _is_ the trap-time
// stack.
//
// If there's no page fault upcall, the environment didn't allocate a
// page for its exception stack or can't write to it, or the exception
// stack overflows, then destroy the environment that caused the fault.
// Note that the grade script assumes you will first check for the page
// fault upcall and print the "user fault va" message below if there is
// none. The remaining three checks can be combined into a single test.
//
// Hints:
// user_mem_assert() and env_run() are useful here.
// To change what the user environment runs, modify 'curenv->env_tf'
// (the 'tf' variable points at 'curenv->env_tf').
// LAB 4: Your code here.
// Now we are in kernel mode
if (curenv->env_pgfault_upcall != NULL){
struct UTrapframe *utf;
// Check tf_esp is in UXSTACK
// -4, scratch space to save eip return address
if (tf->tf_esp >= UXSTACKTOP - PGSIZE && tf->tf_esp < UXSTACKTOP){
utf = (struct UTrapframe *)(tf->tf_esp - sizeof(struct UTrapframe) - 4);
} else {
utf = (struct UTrapframe *)(UXSTACKTOP - sizeof(struct UTrapframe));
}
// Check permission
user_mem_assert(curenv, (void *)utf, sizeof(struct UTrapframe), PTE_U | PTE_W);
// dump Trapframe info to UTrapframe
utf->utf_fault_va = fault_va;
utf->utf_err = tf->tf_err;
utf->utf_regs = tf->tf_regs;
utf->utf_eip = tf->tf_eip;
utf->utf_eflags = tf->tf_eflags;
utf->utf_esp = tf->tf_esp;
// set eip to env_pgfault_upcall
curenv->env_tf.tf_eip = (uint32_t)curenv->env_pgfault_upcall;
curenv->env_tf.tf_esp = (uint32_t)utf;
// Debug info
// cprintf("Dispatch to user-mode page fault handler: fault_va %08x\n", fault_va);
// if (fault_va >= USTACKTOP - PGSIZE && fault_va < USTACKTOP) cprintf("pgfautl on stack\n");
env_run(curenv);
} else {
cprintf("ERROR: %x env_pgfault_upcall is NULL\n", curenv->env_id);
}
// Destroy the environment that caused the fault.
cprintf("[%08x] user fault va %08x ip %08x\n",
curenv->env_id, fault_va, tf->tf_eip);
print_trapframe(tf);
env_destroy(curenv);
}
static void
trap_dispatch(struct Trapframe *tf)
{
// Handle processor exceptions.
// LAB 3: Your code here.
// Handle spurious interrupts
// The hardware sometimes raises these because of noise on the
// IRQ line or other reasons. We don't care.
if (tf->tf_trapno == IRQ_OFFSET + IRQ_SPURIOUS) {
cprintf("Spurious interrupt on irq 7\n");
print_trapframe(tf);
return;
}
// Handle clock interrupts. Don't forget to acknowledge the
// interrupt using lapic_eoi() before calling the scheduler!
// LAB 4: Your code here.
if (tf->tf_trapno == IRQ_OFFSET + IRQ_TIMER) {
lapic_eoi();
time_tick();
sched_yield();
return;
}
// Add time tick increment to clock interrupts.
// Be careful! In multiprocessors, clock interrupts are
// triggered on every CPU.
// LAB 6: Your code here.
// Handle keyboard and serial interrupts.
// LAB 5: Your code here.
if (tf->tf_trapno == IRQ_OFFSET + IRQ_KBD) {
kbd_intr();
return;
}
if (tf->tf_trapno == IRQ_OFFSET + IRQ_SERIAL) {
serial_intr();
return;
}
// Unexpected trap: The user process or the kernel has a bug.
switch(tf->tf_trapno) {
case T_PGFLT:
page_fault_handler(tf);
break;
case T_BRKPT:
monitor(tf);
break;
case T_SYSCALL:
tf->tf_regs.reg_rax = syscall(tf->tf_regs.reg_rax,
tf->tf_regs.reg_rdx,
tf->tf_regs.reg_rcx,
tf->tf_regs.reg_rbx,
tf->tf_regs.reg_rdi,
tf->tf_regs.reg_rsi);
break;
default:
print_trapframe(tf);
if (tf->tf_cs == GD_KT) {
panic("unhandled trap in kernel");
}
else {
env_destroy(curenv);
return;
}
}
}
请发表评论