#include "context.h" void scheduler() { // // set the variable current_task to point to the descriptor of the task // that should be scheduled next. Example: current_task = taskdesc+1 would // schedule the cyclic scheduler because taskdesc+1 was the pointer used // when the cyclic scheduler task was created. current_task = taskdesc+0 // would schedule the background (aperiodic) thread. // } void cyclic_scheduler(void) { // // put your cyclic scheduler code here. After the job(s) assigned to a time slice // is/are complete, call yield(). This will relinquish the processor until the next // time the cyclic scheduler is scheduled. // } void create_task(task_descriptor xdata *td, void (code *task)(void), char idata *stack) { td->t_pc = task; td->t_sp = stack - 1; td->psw = 0; } char idata stack1[16]; // stack space for the cyclic scheduler main() { WDTCN = 0xde; // disable watchdog WDTCN = 0xad; XBR2 = 0x40; // enable port output XBR0 = 4; // enable uart 0 OSCXCN = 0x67; // turn on external crystal TMOD = 0x20; // wait 1ms using T1 mode 2 TH1 = -167; // 2MHz clock, 167 counts - 1ms TR1 = 1; while ( TF1 == 0 ) { } // wait 1ms while ( !(OSCXCN & 0x80) ) { } // wait till oscillator stable OSCICN = 8; // switch over to 22.1184MHz SCON0 = 0x50; // 8-bit, variable baud, receive enable TH1 = -6; // 9600 baud P1MDOUT = 0x40; context_init(); create_task(taskdesc+1,cyclic_scheduler,stack1); EA = 1; // enable interrupts and start multi-tasking for ( ; ; ) { // put your code to execute aperiodic tasks here }