.module kernel.c .area data 0200 _main_frame_ptr:: 0200 .blkb 2 .area idata --- 0000 0000 .word 0 .area data 0202 _main_frame_x_ptr:: 0202 .blkb 2 .area idata --- 0002 0000 .word 0 .area data 0204 _temp_task_frame_ptr:: 0204 .blkb 2 .area idata --- 0004 0000 .word 0 .area data 0206 _kdb_trace:: 0206 .blkb 2 .area idata --- 0006 0001 .word 1 .area data 0208 _kdb_trace_cycle:: 0208 .blkb 2 .area idata --- 0008 0000 .word 0 .area data .area text 102A _error_msg:: 102A 756E696D706C696D656E746564206675 .byte 'u,'n,'i,'m,'p,'l,'i,'m,'e,'n,'t,'e,'d,32,'f,'u 103A 6E6374696F6E00 .byte 'n,'c,'t,'i,'o,'n,0 1041 0000 .byte 0,0 1043 73796E746178206572726F7200 .byte 's,'y,'n,'t,'a,'x,32,'e,'r,'r,'o,'r,0 1050 00000000000000000000 .word 0,0,0,0,0 105A 0000 .byte 0,0 105C 696C6C6567616C207461736B20494400 .byte 'i,'l,'l,'e,'g,'a,'l,32,'t,'a,'s,'k,32,'I,'D,0 106C 000000000000000000 .byte 0,0,0,0,0,0,0,0,0 1075 696C6C6567616C207461736B20737461 .byte 'i,'l,'l,'e,'g,'a,'l,32,'t,'a,'s,'k,32,'s,'t,'a 1085 746500 .byte 't,'e,0 1088 000000000000 .byte 0,0,0,0,0,0 108E 696C6C6567616C207461736B20707269 .byte 'i,'l,'l,'e,'g,'a,'l,32,'t,'a,'s,'k,32,'p,'r,'i 109E 6F7269747900 .byte 'o,'r,'i,'t,'y,0 10A4 000000 .byte 0,0,0 10A7 6F7574206F66206D656D6F727900 .byte 'o,'u,'t,32,'o,'f,32,'m,'e,'m,'o,'r,'y,0 10B5 00000000000000000000 .word 0,0,0,0,0 10BF 00 .byte 0 10C0 696C6C6567616C206D75746578204944 .byte 'i,'l,'l,'e,'g,'a,'l,32,'m,'u,'t,'e,'x,32,'I,'D 10D0 00 .byte 0 10D1 0000000000000000 .byte 0,0,0,0,0,0,0,0 10D9 696C6C6567616C206D75746578207374 .byte 'i,'l,'l,'e,'g,'a,'l,32,'m,'u,'t,'e,'x,32,'s,'t 10E9 61746500 .byte 'a,'t,'e,0 10ED 0000000000 .byte 0,0,0,0,0 10F2 63616E6E6F7420637265617465207461 .byte 'c,'a,'n,'n,'o,'t,32,'c,'r,'e,'a,'t,'e,32,'t,'a 1102 736B00 .byte 's,'k,0 1105 000000000000 .byte 0,0,0,0,0,0 110B _error_src:: 110B 6B65726E656C206572726F723A00 .byte 'k,'e,'r,'n,'e,'l,32,'e,'r,'r,'o,'r,58,0 1119 00000000 .byte 0,0,0,0 111D 6B65726E656C2E63206572726F723A00 .byte 'k,'e,'r,'n,'e,'l,46,'c,32,'e,'r,'r,'o,'r,58,0 112D 0000 .byte 0,0 112F 6B65726E656C20525449206572726F72 .byte 'k,'e,'r,'n,'e,'l,32,'R,'T,'I,32,'e,'r,'r,'o,'r 113F 3A00 .byte 58,0 1141 7368656C6C206572726F723A00 .byte 's,'h,'e,'l,'l,32,'e,'r,'r,'o,'r,58,0 114E 0000000000 .byte 0,0,0,0,0 1153 ; lreg1 -> -4,x 1153 ; lreg2 -> -8,x 1153 ; ?temp -> -19,x 1153 ; ?temp -> -19,x 1153 ; ?temp -> -19,x 1153 ; ?temp -> -21,x 1153 ; ?temp -> -19,x 1153 ; id -> -17,x 1153 ; result -> -15,x 1153 ; priority_check -> -13,x 1153 ; deadline -> -12,x 1153 ; i -> -10,x 1153 _main:: 1153 34 pshx 1154 B775 tfr s,x 1156 1BF1EA leas -22,sp 1159 ; /* RLPOS: RLPotter Operating System 1159 ; 1159 ; Version 0.8 for the 68HC12D60A microcontroller 1159 ; by Ryan Potter 1159 ; ryan@rlpotter.com 1159 ; 1159 ; Compiled with the ImageCraft ICC12 compiler v6.15A 1159 ; - 912D60 Single Chip Mode 1159 ; - printf option: long 1159 ; 1159 ; 1159 ; 1159 ; v0.8 April 29, 2003: 1159 ; - made mutexes dynamic, and much more powerfull and complete. I had 1159 ; been calling them semaphores, but they've evolved into mutexes. 1159 ; - implemented the TOF_handler interrupt for use with sysTime. 1159 ; brings time resolution from 64 ms to 16 ms. 1159 ; - added kernel funct: get_sysTime(), set_sysTime(); shell cmd: time. 1159 ; - now tasks are 'int f()', and must return a value to the kernel 1159 ; when exiting. kernel doesn't handle it yet, though. 1159 ; - in shell, now names of tasks are shell commands (dynamic). 1159 ; - put all kernel initialization code into kernel_init(). 1159 ; - added kernel funct: remove_task(). 1159 ; 1159 ; 1159 ; v0.7 April 25, 2003: 11174 bytes: 1159 ; - combined kernel.c & semlib.c with rlpos.c to make one big kernel.c. 1159 ; - changed context switch mechanism to give each task a dedicated 1159 ; stack, making the kernel context switches >400% faster. 1159 ; - added a basic timer task that will eventually keep system time/date. 1159 ; 1159 ; v0.6 April 24, 2003: 11042 bytes 1159 ; - made the task block and the task control block dynamic, so that 1159 ; now tasks can create tasks, and can also start/stop them. 1159 ; - implemented the sysInit() task for kicking off a user system. 1159 ; - implemented a kernel debug command for tracing code execution. 1159 ; - implemented small msg box system in kernel for tasks. 1159 ; - implemented COP watchdog reset timer. 1159 ; - added system resources to semlib. 1159 ; - added skeleton ISR_handler() code for the other interrupts. 1159 ; - implemented _HC12Setup.c to initialize/harden the system. 1159 ; 1159 ; v0.5 April 16, 2003: 1159 ; - added priority preemption. 1159 ; - finished kernel task state switcher. 1159 ; - it is now officially a legitimate 1159 ; rate monotonic 1159 ; priority preemptive 1159 ; multitasking 1159 ; Real Time Operating System :) 1159 ; - made kernel.c and semlib.c consistent with the 1159 ; rest of the kernel. 1159 ; - included the early framework for a msg box system. 1159 ; 1159 ; v0.4 April 13, 2003: 8096 bytes 1159 ; - gerneralized the shell command-line input parser: 1159 ; cmd (up to 32 chars). 1159 ; - added kernel and shell functions. 1159 ; 1159 ; v0.3 April 12, 2003: 6155 bytes 1159 ; - added a beginning shell user interface. 1159 ; - added a resource control block and basic semaphore functions. 1159 ; - added basic kernel functions. 1159 ; 1159 ; v0.2 April 9, 2003: 1159 ; - able to round-robin with RTI interrupt. 1159 ; - bonified/certified multitasking with 3 tasks. :) 1159 ; 1159 ; v0.1 April 3, 2003: 1159 ; - able to round-robin without interrupts. 1159 ; - not multitasking, really. 1159 ; 1159 ; v0.0 started April 1, 2003; 0 bytes 1159 ; - no idea where to start. 1159 ; - don't want to look at anyone else's work. ;0) 1159 ; 1159 ; 1159 ; 1159 ; 1159 ; Architecture/C assumptions: 1159 ; 1) 'D' register is the accumulator 1159 ; 2) 'X' register points to the top of the current stack 1159 ; 3) 'Y' register is for general use in indexed operations 1159 ; 4) the heap grows upward and mem segments allocated by malloc, 1159 ; realloc, and calloc are linear and contiguous. 1159 ; 5) the stack grows downwards, and there is no boundary checking. 1159 ; 6) chars are one byte 1159 ; ints are two bytes 1159 ; longs are 4 bytes 1159 ; 7) only 1536 (1.5k) of the 2k ram are available 1159 ; 8) register base is 0x0000 1159 ; 1159 ; Potential problem areas: 1159 ; 1) 'running' section of the kernel get's compiled using extra 1159 ; push and pop instructions 1159 ; 2) run out of ram (global + stack + heap) 1159 ; 1159 ; */ 1159 ; 1159 ; 1159 ; 1159 ; #include <912d60.h> 1159 ; #include 1159 ; #include 1159 ; #include 1159 ; #include "kernel.h" 1159 ; 1159 ; 1159 ; 1159 ; // FUNCTION PROTOTYPES 1159 ; void RTI_handler(void); 1159 ; int sysInit(void); 1159 ; int shell(void); 1159 ; int idleTask(void); 1159 ; int (*task_ptr[MAXTASKS])(void); 1159 ; 1159 ; 1159 ; 1159 ; 1159 ; // GLOBAL VARIABLES 1159 ; unsigned char *main_frame_ptr = NULL; // bottom of main() frame 1159 ; unsigned char *main_frame_x_ptr = NULL; // top of main() frame (x-reg ptr) 1159 ; unsigned char *temp_task_frame_ptr = NULL; // temp CCR pointer for RTI 1159 ; 1159 ; 1159 ; unsigned int current; // current task id number 1159 ; unsigned long int system_tick; 1159 ; unsigned int cop_cycle; 1159 ; 1159 ; unsigned long int time_tick; // one tick every x microseconds 1159 ; 1159 ; 1159 ; // task control block 1159 ; typedef struct task_block { 1159 ; int (*address)(); // Address of the task 1159 ; unsigned char id; // ID of task 1159 ; char name[9]; // Name 1159 ; enum task_state state; // State 1159 ; unsigned char priority; // Priority 1159 ; unsigned long int period_tick; // for determining if deadline is up 1159 ; unsigned int interrupt_msg_box; // flags for pending interrupts 1159 ; enum message_box message; // misc flags 1159 ; unsigned char message_data[2]; // data for misc_msg_box flags 1159 ; unsigned int stack_size; // heap allocated for task stack 1159 ; unsigned char *top_of_stack; // top of task stack in the heap 1159 ; unsigned char *frame_ptr; // CCR pointer in idle stack 1159 ; }; 1159 ; 1159 ; 1159 ; // mutex control block 1159 ; typedef struct mutex_block { 1159 ; unsigned char id; // ID of mutex instance 1159 ; unsigned char type; // COM1, ATD1, etc 1159 ; char name[5]; // Name of mutex 1159 ; enum mutex_state state; // State (busy, free...) 1159 ; signed char owner; // Current mutex owner 1159 ; signed char queue[3]; // Tasks waiting on mutex 1159 ; unsigned char queue_ptr; // Next free spot in queue 1159 ; }; 1159 ; 1159 ; 1159 ; struct task_block *task[MAXTASKS]; 1159 ; struct mutex_block *mutex[MAXMUTEXES]; 1159 ; 1159 ; 1159 ; 1159 ; int kdb_trace = 1; 1159 ; int kdb_trace_cycle = 0; 1159 ; 1159 ; 1159 ; struct time { 1159 ; char hours; 1159 ; char minutes; 1159 ; char seconds; 1159 ; int milliseconds; 1159 ; }; 1159 ; 1159 ; int exit_status; 1159 ; 1159 ; 1159 ; 1159 ; // global interrupt flags 1159 ; //unsigned int interrupt_flags_ADC; 1159 ; //unsigned int interrupt_flags_TC; 1159 ; 1159 ; 1159 ; 1159 ; 1159 ; // error massages 1159 ; const char error_msg[][25] = {"unimplimented function", // error 0 1159 ; "syntax error", // error 1 1159 ; "illegal task ID", // error 2 1159 ; "illegal task state", // error 3 1159 ; "illegal task priority", // error 4 1159 ; "out of memory", // error 5 1159 ; "illegal mutex ID", // error 6 1159 ; "illegal mutex state", // error 7 1159 ; "cannot create task" // error 8 1159 ; }; 1159 ; const char error_src[][18] = {"kernel error:", // source 0 1159 ; "kernel.c error:", // source 1 1159 ; "kernel RTI error:", // source 2 1159 ; "shell error:", // source 3 1159 ; }; 1159 ; 1159 ; 1159 ; 1159 ; 1159 ; 1159 ; void main(void) { 1159 ; 1159 ; // LOCAL VARIABLES 1159 ; int result, id, i; 1159 ; unsigned char priority_check; 1159 ; unsigned int deadline; 1159 ; 1159 ; 1159 ; 1159 ; // INITIALIZE the kernel 1159 ; kernel_init(); 1159 16142A jsr _kernel_init 115C ; 115C ; 115C ; // save SP value for use in the RTI 115C ; asm("TFR s,d"); 115C B774 TFR s,d 115E 115E ; asm("STD _main_frame_ptr"); 115E 7C0200 STD _main_frame_ptr 1161 1161 ; // save X reg value for use in the RTI 1161 ; asm("TFR x,d"); 1161 B754 TFR x,d 1163 1163 ; asm("STD _main_frame_x_ptr"); 1163 7C0202 STD _main_frame_x_ptr 1166 1166 1820022A lbra L5 116A L4: 116A ; 116A ; 116A ; 116A ; // MULTITASKING KERNEL: Priority Preemptive, Real Time, multitasking 116A ; // KDB_TRACE Section 2 116A ; while(1) { 116A ; 116A ; //------------------------------- 116A ; /* REENTRY POINT after either 116A ; 1) task finishes, or 116A ; 2) RTI 116A ; */ 116A ; //------------------------------- 116A ; 116A ; 116A ; if (kdb_trace_cycle >= KDB_CYCLES) 116A FC0208 ldd _kdb_trace_cycle 116D 8C0004 cpd #4 1170 2D06 blt L7 1172 ; kdb_trace = 0; 1172 CC0000 ldd #0 1175 7C0206 std _kdb_trace 1178 L7: 1178 ; 1178 ; #ifdef KDB_TRACE_LEVEL_1 1178 ; if (kdb_trace) puts("kDB2.1"); 1178 ; #endif 1178 ; 1178 ; 1178 ; /* No RTI interrupts allowed inside of main(). Only allowed 1178 ; inside of non-critical sections of tasks */ 1178 ; //INTR_OFF(); 1178 ; 1178 ; 1178 ; // PET THE DOG: cop watchdog reset timer (pet freq = 2x COP freq) 1178 ; if (cop_cycle == 4) { 1178 FC0230 ldd _cop_cycle 117B 8C0004 cpd #4 117E 2610 bne L9 1180 ; COP_PET(0x55); 1180 C655 ldab #85 1182 7B0017 stab 0x17 1185 ; COP_PET(0xAA); 1185 C6AA ldab #170 1187 7B0017 stab 0x17 118A ; cop_cycle = 0; 118A CC0000 ldd #0 118D 7C0230 std _cop_cycle 1190 ; //putchar(':'); 1190 ; } 1190 L9: 1190 CC0000 ldd #0 1193 6C16 std -10,x 1195 L11: 1195 ; #ifdef KDB_TRACE_LEVEL_1 1195 ; if (kdb_trace) puts("kDB2.2-1"); 1195 ; #endif 1195 ; 1195 ; 1195 ; 1195 ; // CHANGE STATES ACCORDING TO MESSAGES 1195 ; // 'waiting' needs to have highest precedence here 1195 ; for (i=0; imessage && STATE_FLAG) { 11A3 EC16 ldd -10,x 11A5 59 lsld 11A6 C3021C addd #_task 11A9 B7C6 xgdy 11AB ED40 ldy 0,y 11AD E7E814 tst 20,y 11B0 2732 beq L17 11B2 ; // set task state to what the message says 11B2 ; task[i]->state = task[i]->message_data[STATE_BOX]; 11B2 EC16 ldd -10,x 11B4 59 lsld 11B5 C3021C addd #_task 11B8 B7C6 xgdy 11BA ED40 ldy 0,y 11BC 6DE1ED sty -19,x 11BF EDE1ED ldy -19,x 11C2 E6E815 ldab 21,y 11C5 EDE1ED ldy -19,x 11C8 6B4C stab 12,y 11CA ; // clear the STATE_FLAG 11CA ; task[i]->message &= ~(STATE_FLAG); 11CA EC16 ldd -10,x 11CC 59 lsld 11CD C3021C addd #_task 11D0 B7C6 xgdy 11D2 EC40 ldd 0,y 11D4 C30014 addd #20 11D7 6CE1EB std -21,x 11DA B746 tfr d,y 11DC 35 pshy ; spill 11DD EDE1EB ldy -21,x 11E0 31 puly ; reload 11E1 0D4001 bclr 0,y,#0x1 11E4 ; #ifdef KDB_TRACE_LEVEL_2 11E4 ; if (kdb_trace) puts("kDB2.3-2a"); 11E4 ; #endif 11E4 ; } 11E4 L17: 11E4 L12: 11E4 EC16 ldd -10,x 11E6 C30001 addd #1 11E9 6C16 std -10,x 11EB EC16 ldd -10,x 11ED 8C0008 cpd #8 11F0 2DA3 blt L11 11F2 CC0000 ldd #0 11F5 6C16 std -10,x 11F7 L19: 11F7 ; #ifdef KDB_TRACE_LEVEL_2 11F7 ; if (kdb_trace) puts("kDB2.3-2b"); 11F7 ; #endif 11F7 ; } 11F7 ; #ifdef KDB_TRACE_LEVEL_1 11F7 ; if (kdb_trace) puts("kDB2.3-1"); 11F7 ; #endif 11F7 ; 11F7 ; 11F7 ; 11F7 ; // RT PRIORITY BLOCK: 11F7 ; // set the current task id based on priority and deadline 11F7 ; 11F7 ; // determine if the deadline is up for idle tasks 11F7 ; /* deadline, is equal to period plus an initial time (t0) reference 11F7 ; (t0 = system_tick). Period = priority + 1. 11F7 ; Changing the state from idle to PENDING occurs here. */ 11F7 ; for (i=0; istate == IDLE) { 11F7 EC16 ldd -10,x 11F9 59 lsld 11FA C3021C addd #_task 11FD B7C6 xgdy 11FF ED40 ldy 0,y 1201 E74C tst 12,y 1203 2655 bne L23 1205 ; deadline = task[i]->period_tick + (task[i]->priority + 1); 1205 EC16 ldd -10,x 1207 59 lsld 1208 C3021C addd #_task 120B B7C6 xgdy 120D ED40 ldy 0,y 120F 6DE1ED sty -19,x 1212 EDE1ED ldy -19,x 1215 E64D ldab 13,y 1217 87 clra 1218 C30001 addd #1 121B 163AF8 jsr __d2lreg2 121E EDE1ED ldy -19,x 1221 194E leay 14,y 1223 1802401C movw 0,y,-4,x 1227 1802421E movw 2,y,-2,x 122B 163B40 jsr __ladd 122E 163B13 jsr __lreg2d 1231 6C14 std -12,x 1233 ; if (system_tick >= deadline) { 1233 CD0232 ldy #_system_tick 1236 1802401C movw 0,y,-4,x 123A 1802421E movw 2,y,-2,x 123E EC14 ldd -12,x 1240 6C1A std -6,x 1242 1800180000 movw #0,-8,x 1247 163CE1 jsr __lcmp 124A 250E blo L25 124C ; task[i]->state = PENDING; // change state at deadline 124C EC16 ldd -10,x 124E 59 lsld 124F C3021C addd #_task 1252 B7C6 xgdy 1254 ED40 ldy 0,y 1256 C601 ldab #1 1258 6B4C stab 12,y 125A ; #ifdef KDB_TRACE_LEVEL_2 125A ; if (kdb_trace) puts("kDB2.4-2"); 125A ; #endif 125A ; } 125A L25: 125A ; } 125A L23: 125A L20: 125A EC16 ldd -10,x 125C C30001 addd #1 125F 6C16 std -10,x 1261 EC16 ldd -10,x 1263 8C0008 cpd #8 1266 2D8F blt L19 1268 ; // if (task[i]->message) {} ??? 1268 ; } 1268 ; #ifdef KDB_TRACE_LEVEL_1 1268 ; if (kdb_trace) puts("kDB2.4-1"); 1268 ; #endif 1268 ; 1268 ; 1268 ; // set current = to highest priority pending/running task. 1268 ; priority_check = 255; // lowest possible 1268 C6FF ldab #255 126A 6B13 stab -13,x 126C CC0000 ldd #0 126F 6C16 std -10,x 1271 L27: 1271 ; 1271 ; for (i=0; istate == PENDING) || (task[i]->state == RUNNING)) { 129A ; if (task[i]->priority <= priority_check) { 129A EC16 ldd -10,x 129C 59 lsld 129D C3021C addd #_task 12A0 B7C6 xgdy 12A2 ED40 ldy 0,y 12A4 E64D ldab 13,y 12A6 E113 cmpb -13,x 12A8 2213 bhi L36 12AA ; current = i; 12AA EC16 ldd -10,x 12AC 7C0236 std _current 12AF ; priority_check = task[i]->priority; 12AF EC16 ldd -10,x 12B1 59 lsld 12B2 C3021C addd #_task 12B5 B7C6 xgdy 12B7 ED40 ldy 0,y 12B9 E64D ldab 13,y 12BB 6B13 stab -13,x 12BD ; #ifdef KDB_TRACE_LEVEL_2 12BD ; if (kdb_trace) puts("kDB2.5-2"); 12BD ; #endif 12BD ; } 12BD L36: 12BD ; } 12BD L33: 12BD ; } 12BD L31: 12BD L28: 12BD EC16 ldd -10,x 12BF C30001 addd #1 12C2 6C16 std -10,x 12C4 EC16 ldd -10,x 12C6 8C0008 cpd #8 12C9 2DA6 blt L27 12CB FC0236 ldd _current 12CE 59 lsld 12CF C3021C addd #_task 12D2 B7C6 xgdy 12D4 ED40 ldy 0,y 12D6 E64C ldab 12,y 12D8 87 clra 12D9 6CE1ED std -19,x 12DC 182700B4 lbeq L39 12E0 ECE1ED ldd -19,x 12E3 8C0001 cpd #1 12E6 2722 beq L42 12E8 ECE1ED ldd -19,x 12EB 8C0002 cpd #2 12EE 1827007F lbeq L43 12F2 ECE1ED ldd -19,x 12F5 8C0003 cpd #3 12F8 18270098 lbeq L39 12FC ECE1ED ldd -19,x 12FF 8C0004 cpd #4 1302 1827008E lbeq L39 1306 1820007E lbra L38 130A X0: 130A ; } 130A ; #ifdef KDB_TRACE_LEVEL_1 130A ; if (kdb_trace) puts("kDB2.5-1"); 130A ; #endif 130A ; 130A ; 130A ; 130A ; // DISPATCH, or otherwise deal with the current task 130A ; // KDB_TRACE Section 3 130A ; 130A ; #ifdef KDB_TRACE_LEVEL_2 130A ; if (kdb_trace) { 130A ; printf("task[%d]->state = %d\n", current, task[current]->state); 130A ; printf("task[%d]->prior = %d\n", current, task[current]->priority); 130A ; } 130A ; #endif 130A ; 130A ; switch (task[current]->state) { 130A ; case IDLE: // skip task 130A ; #ifdef KDB_TRACE_LEVEL_1 130A ; if (kdb_trace) puts("kDB3.1-1"); 130A ; #endif 130A ; break; 130A L42: 130A ; case PENDING: // ready and waiting to run 130A ; #ifdef KDB_TRACE_LEVEL_1 130A ; if (kdb_trace) puts("kDB3.2-1"); 130A ; #endif 130A ; #ifdef KDB_TRACE_LEVEL_2 130A ; if (kdb_trace) { 130A ; //puts("kDB3.2-2"); 130A ; putchar('S'); 130A ; putchar(current+48); 130A ; putchar('\n'); 130A ; } 130A ; #endif 130A ; task[current]->state = RUNNING; 130A FC0236 ldd _current 130D 59 lsld 130E C3021C addd #_task 1311 B7C6 xgdy 1313 ED40 ldy 0,y 1315 C602 ldab #2 1317 6B4C stab 12,y 1319 ; task[current]->period_tick = system_tick; 1319 FC0236 ldd _current 131C 59 lsld 131D C3021C addd #_task 1320 B7C6 xgdy 1322 ED40 ldy 0,y 1324 194E leay 14,y 1326 35 pshy ; spill 1327 CD0232 ldy #_system_tick 132A 1802401C movw 0,y,-4,x 132E 1802421E movw 2,y,-2,x 1332 31 puly ; reload 1333 18021C40 movw -4,x,0,y 1337 18021E42 movw -2,x,2,y 133B ; temp_task_frame_ptr = task[current]->top_of_stack; 133B FC0236 ldd _current 133E 59 lsld 133F C3021C addd #_task 1342 B7C6 xgdy 1344 ED40 ldy 0,y 1346 EDE819 ldy 25,y 1349 7D0204 sty _temp_task_frame_ptr 134C ; asm("LDS _temp_task_frame_ptr"); // set the SP 134C FF0204 LDS _temp_task_frame_ptr 134F 134F ; exit_status = (*task_ptr[current])(); // start the task 134F FC0236 ldd _current 1352 59 lsld 1353 C30238 addd #_task_ptr 1356 B7C6 xgdy 1358 ED40 ldy 0,y 135A 1540 jsr 0,y 135C 7C0212 std _exit_status 135F ; asm("LDS _main_frame_ptr"); // reset the SP 135F FF0200 LDS _main_frame_ptr 1362 1362 ; task[current]->state = IDLE; // task finished 1362 FC0236 ldd _current 1365 59 lsld 1366 C3021C addd #_task 1369 B7C6 xgdy 136B ED40 ldy 0,y 136D 694C clr 12,y 136F ; #ifdef KDB_TRACE_LEVEL_1 136F ; if (kdb_trace) puts("kDB3.3-1"); 136F ; #endif 136F ; #ifdef KDB_TRACE_LEVEL_2 136F ; if (kdb_trace) { 136F ; //puts("kDB3.3-2"); 136F ; putchar('F'); 136F ; putchar(current+48); 136F ; putchar('\n'); 136F ; } 136F ; #endif 136F ; break; 136F 2023 bra L39 1371 L43: 1371 ; case RUNNING: // interrupted. continue running. 1371 ; // restore context and run 1371 ; temp_task_frame_ptr = task[current]->frame_ptr; 1371 FC0236 ldd _current 1374 59 lsld 1375 C3021C addd #_task 1378 B7C6 xgdy 137A ED40 ldy 0,y 137C EDE81B ldy 27,y 137F 7D0204 sty _temp_task_frame_ptr 1382 ; asm("LDS _temp_task_frame_ptr"); 1382 FF0204 LDS _temp_task_frame_ptr 1385 1385 ; asm("RTI"); 1385 0B RTI 1386 1386 ; break; 1386 200C bra L39 1388 X1: 1388 ; case WAITING: // waiting on a mutex 1388 ; #ifdef KDB_TRACE_LEVEL_1 1388 ; if (kdb_trace) puts("kDB3.5-1"); 1388 ; #endif 1388 ; break; 1388 ; case STOPPED: // done running until later 1388 ; #ifdef KDB_TRACE_LEVEL_1 1388 ; if (kdb_trace) puts("kDB3.6-1"); 1388 ; #endif 1388 ; break; 1388 L38: 1388 ; default: // shouldn't happen, but, error if so. 1388 ; puts("KERNEL: task state error\n"); 1388 CC1EF6 ldd #L46 138B 163D7A jsr _puts 138E ; exit(1); 138E CC0001 ldd #1 1391 161028 jsr _exit 1394 ; } // end switch 1394 L39: 1394 L5: 1394 1820FDD2 lbra L4 1398 X2: 1398 ; 1398 ; 1398 ; 1398 ; // exit_status HANDLER 1398 ; //... 1398 ; 1398 ; 1398 ; 1398 ; } // end while(1) 1398 ; 1398 ; 1398 ; } // end main() 1398 L3: 1398 B757 tfr x,s 139A 30 pulx 139B .dbline 0 ; func end 139B 3D rts 139C ; lreg1 -> -4,x 139C ; lreg2 -> -8,x 139C _RTI_handler:: 139C 34 pshx 139D B775 tfr s,x 139F 1B98 leas -8,sp 13A1 ; 13A1 ; 13A1 ; 13A1 ; #pragma interrupt_handler RTI_handler() 13A1 ; 13A1 ; void RTI_handler(void) { 13A1 ; 13A1 ; //ACKNOWLEDGE THE INTERRUPT 13A1 ; RTIFLG = 0x0080; // acknowledge/clear the interrupt 13A1 C680 ldab #128 13A3 7B0015 stab 0x15 13A6 ; 13A6 ; 13A6 ; #ifdef KDB_TRACE_LEVEL_1 13A6 ; if (kdb_trace) putchar('.'); 13A6 ; #endif 13A6 ; //putchar('.'); 13A6 ; 13A6 ; 13A6 ; // SET THE FRAME POINTER for the interupted task. 13A6 ; // should point to the CCR entry on the stack. 13A6 ; asm("TFR x,d"); // start of RTI stack 13A6 B754 TFR x,d 13A8 13A8 ; asm("ADDD #2"); // adjust to CCR stack entry 13A8 C30002 ADDD #2 13AB 13AB ; asm("STD _temp_task_frame_ptr"); // put into task_frame_ptr 13AB 7C0204 STD _temp_task_frame_ptr 13AE 13AE ; task[current]->frame_ptr = temp_task_frame_ptr; 13AE FC0236 ldd _current 13B1 59 lsld 13B2 C3021C addd #_task 13B5 B7C6 xgdy 13B7 ED40 ldy 0,y 13B9 FC0204 ldd _temp_task_frame_ptr 13BC 6CE81B std 27,y 13BF ; 13BF ; 13BF ; 13BF ; // update system time base and cop reset counter 13BF ; system_tick++; 13BF CD0232 ldy #_system_tick 13C2 1802401C movw 0,y,-4,x 13C6 1802421E movw 2,y,-2,x 13CA CD1EF2 ldy #L48 13CD 18024018 movw 0,y,-8,x 13D1 1802421A movw 2,y,-6,x 13D5 163B40 jsr __ladd 13D8 CD0232 ldy #_system_tick 13DB 18021C40 movw -4,x,0,y 13DF 18021E42 movw -2,x,2,y 13E3 ; cop_cycle++; 13E3 FC0230 ldd _cop_cycle 13E6 C30001 addd #1 13E9 7C0230 std _cop_cycle 13EC ; if (time_tick > TIME_TICKS_PER_DAY) { 13EC CD022C ldy #_time_tick 13EF 1802401C movw 0,y,-4,x 13F3 1802421E movw 2,y,-2,x 13F7 CD1EEE ldy #L51 13FA 18024018 movw 0,y,-8,x 13FE 1802421A movw 2,y,-6,x 1402 163CE1 jsr __lcmp 1405 2316 bls L49 1407 ; time_tick = 0; 1407 CD1EEA ldy #L52 140A 1802401C movw 0,y,-4,x 140E 1802421E movw 2,y,-2,x 1412 CD022C ldy #_time_tick 1415 18021C40 movw -4,x,0,y 1419 18021E42 movw -2,x,2,y 141D ; } 141D L49: 141D ; 141D ; 141D ; 141D ; // RETURN: simulate a RTS instruction 141D ; // set stack pointer for main() 141D ; asm("LDS _main_frame_ptr"); 141D FF0200 LDS _main_frame_ptr 1420 1420 ; asm("LDX _main_frame_x_ptr"); 1420 FE0202 LDX _main_frame_x_ptr 1423 1423 ; /* return to main() at the reentry point 1423 ; and must be adjusted after some kernel mods/compilations!! */ 1423 ; asm("JMP $116A"); 1423 06116A JMP $116A 1426 1426 ; 1426 ; } 1426 L47: 1426 B757 tfr x,s 1428 30 pulx 1429 .dbline 0 ; func end 1429 0B rti 142A ; lreg1 -> -4,x 142A ; lreg2 -> -8,x 142A ; i -> -10,x 142A _kernel_init:: 142A 34 pshx 142B B775 tfr s,x 142D 1BF1EE leas -18,sp 1430 ; 1430 ; 1430 ; 1430 ; 1430 ; void kernel_init(void) { 1430 ; 1430 ; // LOCAL VARIABLES 1430 ; extern int _bss_end, _textmode; 1430 ; int i; 1430 ; 1430 ; 1430 ; 1430 ; // START/INITIALIZE the os 1430 ; // KDB_TRACE Section 1 1430 ; 1430 ; 1430 ; // initialize globals 1430 ; _textmode = 1; // maps '\n' to "CR/LF" for Windows terminals 1430 CC0001 ldd #1 1433 7C024C std __textmode 1436 ; 1436 ; 1436 ; // create and initialize the heap (for dynamic (runtime) var allocation) 1436 ; _NewHeap(&_bss_end, (char *)(&_bss_end) + (INITIAL_HEAP_SIZE)); 1436 CC074A ldd #__bss_end+1274 1439 6C80 std 0,sp 143B CC0250 ldd #__bss_end 143E 163A83 jsr __NewHeap 1441 ; 1441 ; 1441 ; // set up the serial port 1441 ; setbaud(BAUD38K); // actually running at 19K baud due to xtal speed 1441 CC000D ldd #13 1444 163821 jsr _setbaud 1447 ; #ifdef KDB_TRACE_LEVEL_1 1447 ; if (kdb_trace) puts("kDB1-0"); 1447 ; #endif 1447 ; 1447 ; 1447 ; // print the opening comments 1447 ; puts("rlpOS v0.8\n\n"); 1447 CC1EDD ldd #L55 144A 163D7A jsr _puts 144D ; 144D ; 144D ; // create the shell 144D ; if (create_task("shell", &shell, 0, PENDING, DEFAULT_SHELL_STACK_SIZE) < 0) 144D CC015E ldd #350 1450 6C86 std 6,sp 1452 CC0001 ldd #1 1455 6C84 std 4,sp 1457 CC0000 ldd #0 145A 6C82 std 2,sp 145C CC1F10 ldd #_shell 145F 6C80 std 0,sp 1461 CC1ED7 ldd #L58 1464 161827 jsr _create_task 1467 8C0000 cpd #0 146A 2C06 bge L56 146C ; puts("shell failure"); 146C CC1EC9 ldd #L59 146F 163D7A jsr _puts 1472 L56: 1472 ; #ifdef KDB_TRACE_LEVEL_1 1472 ; if (kdb_trace) puts("kDB1-2"); 1472 ; #endif 1472 ; 1472 ; 1472 ; if (create_task("idleTask", &idleTask, 255, PENDING, 32) < 0) 1472 CC0020 ldd #32 1475 6C86 std 6,sp 1477 CC0001 ldd #1 147A 6C84 std 4,sp 147C CC00FF ldd #255 147F 6C82 std 2,sp 1481 CC2E57 ldd #_idleTask 1484 6C80 std 0,sp 1486 CC1EC0 ldd #L62 1489 161827 jsr _create_task 148C 8C0000 cpd #0 148F 2C06 bge L60 1491 ; puts("idleTask failure"); 1491 CC1EAF ldd #L63 1494 163D7A jsr _puts 1497 L60: 1497 ; #ifdef KDB_TRACE_LEVEL_1 1497 ; if (kdb_trace) puts("kDB1-2"); 1497 ; #endif 1497 ; 1497 ; 1497 ; // create the COM1 mutex 1497 ; if (create_mutex(COM1, "COM1") < 0) 1497 CC1EAA ldd #L66 149A 6C80 std 0,sp 149C CC0003 ldd #3 149F 161A9E jsr _create_mutex 14A2 8C0000 cpd #0 14A5 2C06 bge L64 14A7 ; puts("COM1 failure"); 14A7 CC1E9D ldd #L67 14AA 163D7A jsr _puts 14AD L64: 14AD ; #ifdef KDB_TRACE_LEVEL_1 14AD ; if (kdb_trace) puts("kDB1-1"); 14AD ; #endif 14AD ; 14AD ; 14AD ; system_tick = 0; 14AD CD1EEA ldy #L52 14B0 1802401C movw 0,y,-4,x 14B4 1802421E movw 2,y,-2,x 14B8 CD0232 ldy #_system_tick 14BB 18021C40 movw -4,x,0,y 14BF 18021E42 movw -2,x,2,y 14C3 ; current = 0; 14C3 CC0000 ldd #0 14C6 7C0236 std _current 14C9 ; cop_cycle = 0; 14C9 CC0000 ldd #0 14CC 7C0230 std _cop_cycle 14CF ; COP_PET(0x55); 14CF C655 ldab #85 14D1 7B0017 stab 0x17 14D4 ; COP_PET(0xAA); 14D4 C6AA ldab #170 14D6 7B0017 stab 0x17 14D9 ; 14D9 ; 14D9 ; 14D9 ; /*// create the sysInit task 14D9 ; if (create_task("sysInit", &sysInit, 0, PENDING, 0) < 0) 14D9 ; puts("sysInit failure"); 14D9 ; #ifdef KDB_TRACE_LEVEL_1 14D9 ; if (kdb_trace) puts("kDB1-1"); 14D9 ; #endif*/ 14D9 ; sysInit(); 14D9 162DB1 jsr _sysInit 14DC ; 14DC ; } 14DC L53: 14DC B757 tfr x,s 14DE 30 pulx 14DF .dbline 0 ; func end 14DF 3D rts 14E0 ; id -> 3,x 14E0 _if_task_exists:: 14E0 3B pshd 14E1 34 pshx 14E2 B775 tfr s,x 14E4 ; 14E4 ; 14E4 ; 14E4 ; // KERNEL FUNCTIONS 14E4 ; 14E4 ; int if_task_exists(unsigned char id) { 14E4 ; 14E4 ; if (task[id] == NULL) 14E4 E603 ldab 3,x 14E6 87 clra 14E7 59 lsld 14E8 C3021C addd #_task 14EB B7C6 xgdy 14ED EC40 ldd 0,y 14EF 2605 bne L69 14F1 ; return -1; 14F1 CCFFFF ldd #-1 14F4 200E bra L68 14F6 L69: 14F6 ; else 14F6 ; return task[id]->id; 14F6 E603 ldab 3,x 14F8 87 clra 14F9 59 lsld 14FA C3021C addd #_task 14FD B7C6 xgdy 14FF ED40 ldy 0,y 1501 E642 ldab 2,y 1503 87 clra 1504 L68: 1504 B757 tfr x,s 1506 30 pulx 1507 1B82 leas 2,sp 1509 .dbline 0 ; func end 1509 3D rts 150A ; id -> 3,x 150A _get_task_address:: 150A 3B pshd 150B 34 pshx 150C B775 tfr s,x 150E ; 150E ; } 150E ; 150E ; 150E ; 150E ; 150E ; int get_task_address(unsigned char id) { 150E ; 150E ; return (int)task[id]->address; 150E E603 ldab 3,x 1510 87 clra 1511 59 lsld 1512 C3021C addd #_task 1515 B7C6 xgdy 1517 ECEB0000 ldd [0,y] 151B L71: 151B B757 tfr x,s 151D 30 pulx 151E 1B82 leas 2,sp 1520 .dbline 0 ; func end 1520 3D rts 1521 _get_task_id:: 1521 ; 1521 ; } 1521 ; 1521 ; 1521 ; 1521 ; 1521 ; char get_task_id() { 1521 ; 1521 ; return task[current]->id; 1521 FC0236 ldd _current 1524 59 lsld 1525 C3021C addd #_task 1528 B7C6 xgdy 152A ED40 ldy 0,y 152C E642 ldab 2,y 152E 87 clra 152F L72: 152F .dbline 0 ; func end 152F 3D rts 1530 ; id -> 3,x 1530 _get_task_name:: 1530 3B pshd 1531 34 pshx 1532 B775 tfr s,x 1534 ; } 1534 ; 1534 ; 1534 ; 1534 ; char *get_task_name(unsigned char id) { 1534 ; if (task[id] == NULL) 1534 E603 ldab 3,x 1536 87 clra 1537 59 lsld 1538 C3021C addd #_task 153B B7C6 xgdy 153D EC40 ldd 0,y 153F 2605 bne L74 1541 ; return NULL; 1541 CC0000 ldd #0 1544 200E bra L73 1546 L74: 1546 ; else 1546 ; return task[id]->name; 1546 E603 ldab 3,x 1548 87 clra 1549 59 lsld 154A C3021C addd #_task 154D B7C6 xgdy 154F EC40 ldd 0,y 1551 C30003 addd #3 1554 L73: 1554 B757 tfr x,s 1556 30 pulx 1557 1B82 leas 2,sp 1559 .dbline 0 ; func end 1559 3D rts 155A ; id -> 3,x 155A _get_task_state:: 155A 3B pshd 155B 34 pshx 155C B775 tfr s,x 155E ; } 155E ; 155E ; 155E ; 155E ; 155E ; int get_task_state(unsigned char id) { 155E ; 155E ; if (task[id] == NULL) 155E E603 ldab 3,x 1560 87 clra 1561 59 lsld 1562 C3021C addd #_task 1565 B7C6 xgdy 1567 EC40 ldd 0,y 1569 2605 bne L77 156B ; return -1; 156B CCFFFF ldd #-1 156E 2019 bra L76 1570 L77: 1570 ; else if (id < MAXTASKS) 1570 E603 ldab 3,x 1572 C108 cmpb #8 1574 2410 bhs L79 1576 ; return task[id]->state; 1576 E603 ldab 3,x 1578 87 clra 1579 59 lsld 157A C3021C addd #_task 157D B7C6 xgdy 157F ED40 ldy 0,y 1581 E64C ldab 12,y 1583 87 clra 1584 2003 bra L76 1586 L79: 1586 ; else { 1586 ; #ifdef KERNEL_ERROR_MSG 1586 ; puts(error_src[1]); puts(error_msg[3]); 1586 ; #endif 1586 ; return -1; 1586 CCFFFF ldd #-1 1589 L76: 1589 B757 tfr x,s 158B 30 pulx 158C 1B82 leas 2,sp 158E .dbline 0 ; func end 158E 3D rts 158F ; id -> 3,x 158F _get_task_messages:: 158F 3B pshd 1590 34 pshx 1591 B775 tfr s,x 1593 ; } 1593 ; 1593 ; } 1593 ; 1593 ; 1593 ; 1593 ; int get_task_messages(unsigned char id) { 1593 ; 1593 ; if (task[id] == NULL) 1593 E603 ldab 3,x 1595 87 clra 1596 59 lsld 1597 C3021C addd #_task 159A B7C6 xgdy 159C EC40 ldd 0,y 159E 2605 bne L82 15A0 ; return -1; 15A0 CCFFFF ldd #-1 15A3 201A bra L81 15A5 L82: 15A5 ; else if (id < MAXTASKS) 15A5 E603 ldab 3,x 15A7 C108 cmpb #8 15A9 2411 bhs L84 15AB ; return task[id]->message; 15AB E603 ldab 3,x 15AD 87 clra 15AE 59 lsld 15AF C3021C addd #_task 15B2 B7C6 xgdy 15B4 ED40 ldy 0,y 15B6 E6E814 ldab 20,y 15B9 87 clra 15BA 2003 bra L81 15BC L84: 15BC ; else { 15BC ; #ifdef KERNEL_ERROR_MSG 15BC ; puts(error_src[1]); puts(error_msg[3]); 15BC ; #endif 15BC ; return -1; 15BC CCFFFF ldd #-1 15BF L81: 15BF B757 tfr x,s 15C1 30 pulx 15C2 1B82 leas 2,sp 15C4 .dbline 0 ; func end 15C4 3D rts 15C5 ; id -> 3,x 15C5 _get_task_priority:: 15C5 3B pshd 15C6 34 pshx 15C7 B775 tfr s,x 15C9 ; } 15C9 ; 15C9 ; } 15C9 ; 15C9 ; 15C9 ; 15C9 ; int get_task_priority(unsigned char id) { 15C9 ; 15C9 ; INTR_OFF(); 15C9 1410 sei 15CB 15CB ; 15CB ; if (id < MAXTASKS) { 15CB E603 ldab 3,x 15CD C108 cmpb #8 15CF 2412 bhs L87 15D1 ; INTR_ON(); 15D1 10EF cli 15D3 15D3 ; return task[id]->priority; 15D3 E603 ldab 3,x 15D5 87 clra 15D6 59 lsld 15D7 C3021C addd #_task 15DA B7C6 xgdy 15DC ED40 ldy 0,y 15DE E64D ldab 13,y 15E0 87 clra 15E1 2005 bra L86 15E3 L87: 15E3 ; } 15E3 ; else { 15E3 ; #ifdef KERNEL_ERROR_MSG 15E3 ; puts(error_src[1]); puts(error_msg[4]); 15E3 ; #endif 15E3 ; INTR_ON(); 15E3 10EF cli 15E5 15E5 ; return -1; 15E5 CCFFFF ldd #-1 15E8 L86: 15E8 B757 tfr x,s 15EA 30 pulx 15EB 1B82 leas 2,sp 15ED .dbline 0 ; func end 15ED 3D rts 15EE ; ?temp -> -4,x 15EE ; ?temp -> -4,x 15EE ; ?temp -> -4,x 15EE ; ?temp -> -4,x 15EE ; ?temp -> -4,x 15EE ; ?temp -> -2,x 15EE ; newstate -> 7,x 15EE ; id -> 3,x 15EE _set_task_state:: 15EE 3B pshd 15EF 34 pshx 15F0 B775 tfr s,x 15F2 1B9C leas -4,sp 15F4 ; } 15F4 ; 15F4 ; } 15F4 ; 15F4 ; 15F4 ; 15F4 ; int set_task_state(unsigned char id, unsigned char newstate) { 15F4 ; 15F4 ; 15F4 ; INTR_OFF(); 15F4 1410 sei 15F6 15F6 ; 15F6 ; 15F6 ; // check id validity 15F6 ; if (id < MAXTASKS) { 15F6 E603 ldab 3,x 15F8 C108 cmpb #8 15FA 182401D9 lbhs L90 15FE ; 15FE ; if (task[id] == NULL) { 15FE E603 ldab 3,x 1600 87 clra 1601 59 lsld 1602 C3021C addd #_task 1605 B7C6 xgdy 1607 EC40 ldd 0,y 1609 2609 bne L92 160B ; #ifdef KERNEL_ERROR_MSG 160B ; puts(error_src[1]); puts(error_msg[2]); 160B ; #endif 160B ; INTR_ON(); 160B 10EF cli 160D 160D ; return -1; 160D CCFFFF ldd #-1 1610 182001CF lbra L89 1614 L92: 1614 ; } 1614 ; 1614 ; 1614 ; // check newstate validity 1614 ; if ((newstate == RUNNING) || 1614 E607 ldab 7,x 1616 C102 cmpb #2 1618 270C beq L97 161A E607 ldab 7,x 161C C103 cmpb #3 161E 2706 beq L97 1620 E607 ldab 7,x 1622 C104 cmpb #4 1624 2309 bls L94 1626 L97: 1626 ; (newstate == WAITING) || 1626 ; (newstate > STOPPED)) { 1626 ; #ifdef KERNEL_ERROR_MSG 1626 ; puts(error_src[1]); puts(error_msg[3]); 1626 ; #endif 1626 ; INTR_ON(); 1626 10EF cli 1628 1628 ; return -1; 1628 CCFFFF ldd #-1 162B 182001B4 lbra L89 162F L94: 162F E603 ldab 3,x 1631 87 clra 1632 59 lsld 1633 C3021C addd #_task 1636 B7C6 xgdy 1638 ED40 ldy 0,y 163A E64C ldab 12,y 163C 87 clra 163D 6C1E std -2,x 163F 271F beq L101 1641 EC1E ldd -2,x 1643 8C0001 cpd #1 1646 1827009C lbeq L108 164A EC1E ldd -2,x 164C 8C0002 cpd #2 164F 182700F0 lbeq L115 1653 EC1E ldd -2,x 1655 8C0004 cpd #4 1658 18270128 lbeq L118 165C 18200170 lbra L98 1660 X3: 1660 ; } 1660 ; 1660 ; // referenced to the task's current state: 1660 ; switch (task[id]->state) { 1660 L101: 1660 ; case IDLE: 1660 ; if (newstate == IDLE) { // no change 1660 E707 tst 7,x 1662 2609 bne L102 1664 ; INTR_ON(); 1664 10EF cli 1666 1666 ; return 0; 1666 CC0000 ldd #0 1669 18200176 lbra L89 166D L102: 166D ; } 166D ; else if (newstate == PENDING) { 166D E607 ldab 7,x 166F C101 cmpb #1 1671 2632 bne L104 1673 ; // pass msg to task[id]->msgbox; 1673 ; task[id]->message |= STATE_FLAG; 1673 E603 ldab 3,x 1675 87 clra 1676 59 lsld 1677 C3021C addd #_task 167A B7C6 xgdy 167C EC40 ldd 0,y 167E C30014 addd #20 1681 6C1C std -4,x 1683 B746 tfr d,y 1685 35 pshy ; spill 1686 ED1C ldy -4,x 1688 31 puly ; reload 1689 0C4001 bset 0,y,#1 168C ; task[id]->message_data[STATE_BOX] = PENDING; 168C E603 ldab 3,x 168E 87 clra 168F 59 lsld 1690 C3021C addd #_task 1693 B7C6 xgdy 1695 ED40 ldy 0,y 1697 C601 ldab #1 1699 6BE815 stab 21,y 169C ; INTR_ON(); 169C 10EF cli 169E 169E ; return 0; 169E CC0000 ldd #0 16A1 1820013E lbra L89 16A5 L104: 16A5 ; } 16A5 ; else if (newstate == STOPPED) { 16A5 E607 ldab 7,x 16A7 C104 cmpb #4 16A9 2632 bne L106 16AB ; // pass msg to task[id]->msgbox; 16AB ; task[id]->message |= STATE_FLAG; 16AB E603 ldab 3,x 16AD 87 clra 16AE 59 lsld 16AF C3021C addd #_task 16B2 B7C6 xgdy 16B4 EC40 ldd 0,y 16B6 C30014 addd #20 16B9 6C1C std -4,x 16BB B746 tfr d,y 16BD 35 pshy ; spill 16BE ED1C ldy -4,x 16C0 31 puly ; reload 16C1 0C4001 bset 0,y,#1 16C4 ; task[id]->message_data[STATE_BOX] = STOPPED; 16C4 E603 ldab 3,x 16C6 87 clra 16C7 59 lsld 16C8 C3021C addd #_task 16CB B7C6 xgdy 16CD ED40 ldy 0,y 16CF C604 ldab #4 16D1 6BE815 stab 21,y 16D4 ; INTR_ON(); 16D4 10EF cli 16D6 16D6 ; return 0; 16D6 CC0000 ldd #0 16D9 18200106 lbra L89 16DD L106: 16DD ; } 16DD ; else { // nothing else is legal; 16DD ; #ifdef KERNEL_ERROR_MSG 16DD ; puts(error_src[1]); puts(error_msg[3]); 16DD ; #endif 16DD ; INTR_ON(); 16DD 10EF cli 16DF 16DF ; return -1; 16DF CCFFFF ldd #-1 16E2 182000FD lbra L89 16E6 X4: 16E6 ; } 16E6 ; break; 16E6 L108: 16E6 ; case PENDING: 16E6 ; if (newstate == PENDING) { // no change 16E6 E607 ldab 7,x 16E8 C101 cmpb #1 16EA 2609 bne L109 16EC ; INTR_ON(); 16EC 10EF cli 16EE 16EE ; return 0; 16EE CC0000 ldd #0 16F1 182000EE lbra L89 16F5 L109: 16F5 ; } 16F5 ; else if (newstate == IDLE) { 16F5 E707 tst 7,x 16F7 2609 bne L111 16F9 ; // pass msg to task[id]->msgbox; 16F9 ; #ifdef KERNEL_ERROR_MSG 16F9 ; puts(error_src[1]); puts(error_msg[0]); 16F9 ; #endif 16F9 ; INTR_ON(); 16F9 10EF cli 16FB 16FB ; return -1; 16FB CCFFFF ldd #-1 16FE 182000E1 lbra L89 1702 L111: 1702 ; } 1702 ; else if (newstate == STOPPED) { 1702 E607 ldab 7,x 1704 C104 cmpb #4 1706 2632 bne L113 1708 ; // pass msg to task[id]->msgbox; 1708 ; task[id]->message |= STATE_FLAG; 1708 E603 ldab 3,x 170A 87 clra 170B 59 lsld 170C C3021C addd #_task 170F B7C6 xgdy 1711 EC40 ldd 0,y 1713 C30014 addd #20 1716 6C1C std -4,x 1718 B746 tfr d,y 171A 35 pshy ; spill 171B ED1C ldy -4,x 171D 31 puly ; reload 171E 0C4001 bset 0,y,#1 1721 ; task[id]->message_data[STATE_BOX] = STOPPED; 1721 E603 ldab 3,x 1723 87 clra 1724 59 lsld 1725 C3021C addd #_task 1728 B7C6 xgdy 172A ED40 ldy 0,y 172C C604 ldab #4 172E 6BE815 stab 21,y 1731 ; INTR_ON(); 1731 10EF cli 1733 1733 ; return 0; 1733 CC0000 ldd #0 1736 182000A9 lbra L89 173A L113: 173A ; } 173A ; else { 173A ; #ifdef KERNEL_ERROR_MSG 173A ; puts(error_src[1]); puts(error_msg[3]); 173A ; #endif 173A ; INTR_ON(); 173A 10EF cli 173C 173C ; return -1; 173C CCFFFF ldd #-1 173F 182000A0 lbra L89 1743 X5: 1743 ; } 1743 ; break; 1743 L115: 1743 ; case RUNNING: 1743 ; if (newstate == STOPPED) { 1743 E607 ldab 7,x 1745 C104 cmpb #4 1747 2632 bne L116 1749 ; // pass msg to task[id]->msgbox; 1749 ; task[id]->message |= STATE_FLAG; 1749 E603 ldab 3,x 174B 87 clra 174C 59 lsld 174D C3021C addd #_task 1750 B7C6 xgdy 1752 EC40 ldd 0,y 1754 C30014 addd #20 1757 6C1C std -4,x 1759 B746 tfr d,y 175B 35 pshy ; spill 175C ED1C ldy -4,x 175E 31 puly ; reload 175F 0C4001 bset 0,y,#1 1762 ; task[id]->message_data[STATE_BOX] = STOPPED; 1762 E603 ldab 3,x 1764 87 clra 1765 59 lsld 1766 C3021C addd #_task 1769 B7C6 xgdy 176B ED40 ldy 0,y 176D C604 ldab #4 176F 6BE815 stab 21,y 1772 ; 1772 ; INTR_ON(); 1772 10EF cli 1774 1774 ; return 0; 1774 CC0000 ldd #0 1777 18200068 lbra L89 177B L116: 177B ; } 177B ; else { 177B ; #ifdef KERNEL_ERROR_MSG 177B ; puts(error_src[1]); puts(error_msg[3]); 177B ; #endif 177B ; INTR_ON(); 177B 10EF cli 177D 177D ; return -1; 177D CCFFFF ldd #-1 1780 1820005F lbra L89 1784 X6: 1784 ; } 1784 ; break; 1784 L118: 1784 ; case STOPPED: 1784 ; if (newstate == STOPPED) { // no change 1784 E607 ldab 7,x 1786 C104 cmpb #4 1788 2609 bne L119 178A ; INTR_ON(); 178A 10EF cli 178C 178C ; return 0; 178C CC0000 ldd #0 178F 18200050 lbra L89 1793 L119: 1793 ; } 1793 ; else if (newstate == PENDING) { 1793 E607 ldab 7,x 1795 C101 cmpb #1 1797 2630 bne L121 1799 ; // pass msg to task[id]->msgbox; 1799 ; task[id]->message |= STATE_FLAG; 1799 E603 ldab 3,x 179B 87 clra 179C 59 lsld 179D C3021C addd #_task 17A0 B7C6 xgdy 17A2 EC40 ldd 0,y 17A4 C30014 addd #20 17A7 6C1C std -4,x 17A9 B746 tfr d,y 17AB 35 pshy ; spill 17AC ED1C ldy -4,x 17AE 31 puly ; reload 17AF 0C4001 bset 0,y,#1 17B2 ; task[id]->message_data[STATE_BOX] = PENDING; 17B2 E603 ldab 3,x 17B4 87 clra 17B5 59 lsld 17B6 C3021C addd #_task 17B9 B7C6 xgdy 17BB ED40 ldy 0,y 17BD C601 ldab #1 17BF 6BE815 stab 21,y 17C2 ; INTR_ON(); 17C2 10EF cli 17C4 17C4 ; return 0; 17C4 CC0000 ldd #0 17C7 201A bra L89 17C9 L121: 17C9 ; } 17C9 ; else { 17C9 ; #ifdef KERNEL_ERROR_MSG 17C9 ; puts(error_src[1]); puts(error_msg[3]); 17C9 ; #endif 17C9 ; INTR_ON(); 17C9 10EF cli 17CB 17CB ; return -1; 17CB CCFFFF ldd #-1 17CE 2013 bra L89 17D0 X7: 17D0 ; } 17D0 ; break; 17D0 L98: 17D0 ; default: 17D0 ; #ifdef KERNEL_ERROR_MSG 17D0 ; puts(error_src[1]); puts(error_msg[3]); 17D0 ; #endif 17D0 ; INTR_ON(); 17D0 10EF cli 17D2 17D2 ; return -1; 17D2 CCFFFF ldd #-1 17D5 200C bra L89 17D7 X8: 17D7 ; break; 17D7 L90: 17D7 ; 17D7 ; } // end switch (task[id]->state) 17D7 ; 17D7 ; } // if (id < MAXTASKS) 17D7 ; 17D7 ; else { 17D7 ; #ifdef KERNEL_ERROR_MSG 17D7 ; puts(error_src[1]); puts(error_msg[2]); 17D7 ; #endif 17D7 ; INTR_ON(); 17D7 10EF cli 17D9 17D9 ; return -1; 17D9 CCFFFF ldd #-1 17DC 2005 bra L89 17DE X9: 17DE ; } 17DE ; 17DE ; INTR_ON(); 17DE 10EF cli 17E0 17E0 ; return 0; 17E0 CC0000 ldd #0 17E3 L89: 17E3 B757 tfr x,s 17E5 30 pulx 17E6 1B82 leas 2,sp 17E8 .dbline 0 ; func end 17E8 3D rts 17E9 ; priority -> 7,x 17E9 ; id -> 3,x 17E9 _set_task_priority:: 17E9 3B pshd 17EA 34 pshx 17EB B775 tfr s,x 17ED ; 17ED ; } 17ED ; 17ED ; 17ED ; 17ED ; int set_task_priority(unsigned char id, unsigned char priority) { 17ED ; 17ED ; if (priority == 0) // priority 0 is reserved for the shell 17ED E707 tst 7,x 17EF 2604 bne L124 17F1 ; priority = 1; 17F1 C601 ldab #1 17F3 6B07 stab 7,x 17F5 L124: 17F5 ; 17F5 ; if (id >= (MAXTASKS)) { 17F5 E603 ldab 3,x 17F7 C108 cmpb #8 17F9 2505 blo L126 17FB ; #ifdef KERNEL_ERROR_MSG 17FB ; puts(error_src[1]); puts(error_msg[4]); 17FB ; #endif 17FB ; return -1; 17FB CCFFFF ldd #-1 17FE 2021 bra L123 1800 L126: 1800 E607 ldab 7,x 1802 C1FF cmpb #255 1804 2204 bhi L130 1806 E707 tst 7,x 1808 2405 bhs L128 180A L130: 180A ; } 180A ; else if ((priority > 255) || (priority < 0)) { 180A ; #ifdef KERNEL_ERROR_MSG 180A ; puts(error_src[1]); puts(error_msg[4]); 180A ; #endif 180A ; return -1; 180A CCFFFF ldd #-1 180D 2012 bra L123 180F L128: 180F ; } 180F ; else { 180F ; task[id]->priority = priority; 180F E603 ldab 3,x 1811 87 clra 1812 59 lsld 1813 C3021C addd #_task 1816 B7C6 xgdy 1818 ED40 ldy 0,y 181A E607 ldab 7,x 181C 6B4D stab 13,y 181E ; return 0; 181E CC0000 ldd #0 1821 L123: 1821 B757 tfr x,s 1823 30 pulx 1824 1B82 leas 2,sp 1826 .dbline 0 ; func end 1826 3D rts 1827 ; lreg1 -> -4,x 1827 ; lreg2 -> -8,x 1827 ; ?temp -> -15,x 1827 ; ?temp -> -13,x 1827 ; ?temp -> -11,x 1827 ; id -> -9,x 1827 ; stack_size -> 12,x 1827 ; state -> 10,x 1827 ; priority -> 9,x 1827 ; addr -> 6,x 1827 ; name -> 2,x 1827 _create_task:: 1827 3B pshd 1828 34 pshx 1829 B775 tfr s,x 182B 1BF1EA leas -22,sp 182E ; } 182E ; } 182E ; 182E ; 182E ; 182E ; 182E ; int create_task(char *name, 182E ; int (*addr)(), 182E ; unsigned char priority, 182E ; int state, 182E ; int stack_size) { 182E ; 182E ; // LOCAL VARIABLES 182E ; unsigned char id; 182E ; 182E ; 182E ; INTR_OFF(); // critical section 182E 1410 sei 1830 1830 6917 clr -9,x 1832 2015 bra L135 1834 L132: 1834 E617 ldab -9,x 1836 87 clra 1837 59 lsld 1838 C30238 addd #_task_ptr 183B B7C6 xgdy 183D EC40 ldd 0,y 183F 270E beq L134 1841 L133: 1841 E617 ldab -9,x 1843 87 clra 1844 C30001 addd #1 1847 6B17 stab -9,x 1849 L135: 1849 ; 1849 ; 1849 ; //if (get_free_memory() > 64) { 1849 ; 1849 ; // determine lowest free id available to assign to this task 1849 ; for (id=0; idaddress = addr; 1881 E617 ldab -9,x 1883 87 clra 1884 59 lsld 1885 C3021C addd #_task 1888 B7C6 xgdy 188A ED40 ldy 0,y 188C EC06 ldd 6,x 188E 6C40 std 0,y 1890 ; task[id]->id = id; 1890 E617 ldab -9,x 1892 87 clra 1893 59 lsld 1894 C3021C addd #_task 1897 B7C6 xgdy 1899 ED40 ldy 0,y 189B E617 ldab -9,x 189D 6B42 stab 2,y 189F ; strcpy(task[id]->name, name); 189F 18020280 movw 2,x,0,sp 18A3 E617 ldab -9,x 18A5 87 clra 18A6 59 lsld 18A7 C3021C addd #_task 18AA B7C6 xgdy 18AC EC40 ldd 0,y 18AE C30003 addd #3 18B1 163D6B jsr _strcpy 18B4 ; task[id]->state = state; 18B4 E617 ldab -9,x 18B6 87 clra 18B7 59 lsld 18B8 C3021C addd #_task 18BB B7C6 xgdy 18BD ED40 ldy 0,y 18BF EC0A ldd 10,x 18C1 6B4C stab 12,y 18C3 ; task[id]->priority = priority; 18C3 E617 ldab -9,x 18C5 87 clra 18C6 59 lsld 18C7 C3021C addd #_task 18CA B7C6 xgdy 18CC ED40 ldy 0,y 18CE E609 ldab 9,x 18D0 6B4D stab 13,y 18D2 ; task[id]->period_tick = 0; 18D2 E617 ldab -9,x 18D4 87 clra 18D5 59 lsld 18D6 C3021C addd #_task 18D9 B7C6 xgdy 18DB ED40 ldy 0,y 18DD 194E leay 14,y 18DF 35 pshy ; spill 18E0 CD1EEA ldy #L52 18E3 1802401C movw 0,y,-4,x 18E7 1802421E movw 2,y,-2,x 18EB 31 puly ; reload 18EC 18021C40 movw -4,x,0,y 18F0 18021E42 movw -2,x,2,y 18F4 ; task[id]->interrupt_msg_box = NULL; 18F4 E617 ldab -9,x 18F6 87 clra 18F7 59 lsld 18F8 C3021C addd #_task 18FB B7C6 xgdy 18FD ED40 ldy 0,y 18FF CC0000 ldd #0 1902 6CE812 std 18,y 1905 ; task[id]->message = NULL; 1905 E617 ldab -9,x 1907 87 clra 1908 59 lsld 1909 C3021C addd #_task 190C B7C6 xgdy 190E ED40 ldy 0,y 1910 69E814 clr 20,y 1913 ; task[id]->message_data[0] = NULL; 1913 E617 ldab -9,x 1915 87 clra 1916 59 lsld 1917 C3021C addd #_task 191A B7C6 xgdy 191C ED40 ldy 0,y 191E 69E815 clr 21,y 1921 ; task[id]->message_data[1] = NULL; 1921 E617 ldab -9,x 1923 87 clra 1924 59 lsld 1925 C3021C addd #_task 1928 B7C6 xgdy 192A ED40 ldy 0,y 192C 69E816 clr 22,y 192F ; if (stack_size <= 0) 192F EC0C ldd 12,x 1931 2E05 bgt L140 1933 ; stack_size = DEFAULT_STACK_SIZE; 1933 CC0040 ldd #64 1936 6C0C std 12,x 1938 L140: 1938 ; task[id]->stack_size = stack_size; 1938 E617 ldab -9,x 193A 87 clra 193B 59 lsld 193C C3021C addd #_task 193F B7C6 xgdy 1941 ED40 ldy 0,y 1943 EC0C ldd 12,x 1945 6CE817 std 23,y 1948 ; task[id]->top_of_stack = malloc(task[id]->stack_size); 1948 E617 ldab -9,x 194A 87 clra 194B 59 lsld 194C C3021C addd #_task 194F B7C6 xgdy 1951 ED40 ldy 0,y 1953 6D15 sty -11,x 1955 ED15 ldy -11,x 1957 ECE817 ldd 23,y 195A 163FD9 jsr _malloc 195D 6CE1EC std -20,x 1960 ED15 ldy -11,x 1962 ECE1EC ldd -20,x 1965 6CE819 std 25,y 1968 ; task[id]->top_of_stack += task[id]->stack_size; 1968 E617 ldab -9,x 196A 87 clra 196B 59 lsld 196C C3021C addd #_task 196F B7C6 xgdy 1971 ED40 ldy 0,y 1973 6D13 sty -13,x 1975 EC13 ldd -13,x 1977 C30019 addd #25 197A 6C11 std -15,x 197C ED13 ldy -13,x 197E ECE817 ldd 23,y 1981 E3E3FFF1 addd [-15,x] 1985 ED11 ldy -15,x 1987 6C40 std 0,y 1989 ; task[id]->frame_ptr = NULL; 1989 E617 ldab -9,x 198B 87 clra 198C 59 lsld 198D C3021C addd #_task 1990 B7C6 xgdy 1992 ED40 ldy 0,y 1994 CC0000 ldd #0 1997 6CE81B std 27,y 199A ; 199A ; } 199A ; //} 199A ; INTR_ON(); 199A 10EF cli 199C 199C ; 199C ; return id; 199C E617 ldab -9,x 199E 87 clra 199F L131: 199F B757 tfr x,s 19A1 30 pulx 19A2 1B82 leas 2,sp 19A4 .dbline 0 ; func end 19A4 3D rts 19A5 ; ?temp -> -2,x 19A5 ; id -> 3,x 19A5 _remove_task:: 19A5 3B pshd 19A6 34 pshx 19A7 B775 tfr s,x 19A9 1B9E leas -2,sp 19AB ; 19AB ; } 19AB ; 19AB ; 19AB ; 19AB ; int remove_task(unsigned char id) { 19AB ; 19AB ; if (task[id] == NULL) 19AB E603 ldab 3,x 19AD 87 clra 19AE 59 lsld 19AF C3021C addd #_task 19B2 B7C6 xgdy 19B4 EC40 ldd 0,y 19B6 2605 bne L143 19B8 ; return -1; 19B8 CCFFFF ldd #-1 19BB 2047 bra L142 19BD L143: 19BD ; 19BD ; 19BD ; free(task[id]->top_of_stack - task[id]->stack_size); 19BD E603 ldab 3,x 19BF 87 clra 19C0 59 lsld 19C1 C3021C addd #_task 19C4 B7C6 xgdy 19C6 ED40 ldy 0,y 19C8 6D1E sty -2,x 19CA ED1E ldy -2,x 19CC ECE819 ldd 25,y 19CF ED1E ldy -2,x 19D1 A3E817 subd 23,y 19D4 1641A7 jsr _free 19D7 ; free(task[id]); 19D7 E603 ldab 3,x 19D9 87 clra 19DA 59 lsld 19DB C3021C addd #_task 19DE B7C6 xgdy 19E0 EC40 ldd 0,y 19E2 1641A7 jsr _free 19E5 ; task[id] = NULL; 19E5 E603 ldab 3,x 19E7 87 clra 19E8 59 lsld 19E9 C3021C addd #_task 19EC B7C6 xgdy 19EE CC0000 ldd #0 19F1 6C40 std 0,y 19F3 ; task_ptr[id] = NULL; 19F3 E603 ldab 3,x 19F5 87 clra 19F6 59 lsld 19F7 C30238 addd #_task_ptr 19FA B7C6 xgdy 19FC CC0000 ldd #0 19FF 6C40 std 0,y 1A01 ; 1A01 ; return 0; 1A01 CC0000 ldd #0 1A04 L142: 1A04 B757 tfr x,s 1A06 30 pulx 1A07 1B82 leas 2,sp 1A09 .dbline 0 ; func end 1A09 3D rts 1A0A ; id -> 3,x 1A0A _get_mutex_name:: 1A0A 3B pshd 1A0B 34 pshx 1A0C B775 tfr s,x 1A0E ; 1A0E ; } 1A0E ; 1A0E ; 1A0E ; 1A0E ; char *get_mutex_name(unsigned char id) { 1A0E ; 1A0E ; if (mutex[id] == NULL) 1A0E E603 ldab 3,x 1A10 87 clra 1A11 59 lsld 1A12 C30214 addd #_mutex 1A15 B7C6 xgdy 1A17 EC40 ldd 0,y 1A19 2605 bne L146 1A1B ; return NULL; 1A1B CC0000 ldd #0 1A1E 200E bra L145 1A20 L146: 1A20 ; else 1A20 ; return mutex[id]->name; 1A20 E603 ldab 3,x 1A22 87 clra 1A23 59 lsld 1A24 C30214 addd #_mutex 1A27 B7C6 xgdy 1A29 EC40 ldd 0,y 1A2B C30002 addd #2 1A2E L145: 1A2E B757 tfr x,s 1A30 30 pulx 1A31 1B82 leas 2,sp 1A33 .dbline 0 ; func end 1A33 3D rts 1A34 ; id -> 3,x 1A34 _get_mutex_state:: 1A34 3B pshd 1A35 34 pshx 1A36 B775 tfr s,x 1A38 ; } 1A38 ; 1A38 ; 1A38 ; 1A38 ; 1A38 ; int get_mutex_state(unsigned char id) { 1A38 ; 1A38 ; if (id < MAXMUTEXES) { 1A38 E603 ldab 3,x 1A3A C104 cmpb #4 1A3C 2410 bhs L149 1A3E ; return mutex[id]->state; 1A3E E603 ldab 3,x 1A40 87 clra 1A41 59 lsld 1A42 C30214 addd #_mutex 1A45 B7C6 xgdy 1A47 ED40 ldy 0,y 1A49 E647 ldab 7,y 1A4B 87 clra 1A4C 2003 bra L148 1A4E L149: 1A4E ; } 1A4E ; else { 1A4E ; #ifdef KERNEL_ERROR_MSG 1A4E ; puts(error_src[1]); puts(error_msg[6]); 1A4E ; #endif 1A4E ; return -1; 1A4E CCFFFF ldd #-1 1A51 L148: 1A51 B757 tfr x,s 1A53 30 pulx 1A54 1B82 leas 2,sp 1A56 .dbline 0 ; func end 1A56 3D rts 1A57 ; id -> 3,x 1A57 _get_mutex_owner:: 1A57 3B pshd 1A58 34 pshx 1A59 B775 tfr s,x 1A5B ; } 1A5B ; 1A5B ; } 1A5B ; 1A5B ; 1A5B ; 1A5B ; 1A5B ; 1A5B ; int get_mutex_owner(unsigned char id) { 1A5B ; 1A5B ; if (id < MAXMUTEXES) { 1A5B E603 ldab 3,x 1A5D C104 cmpb #4 1A5F 2411 bhs L152 1A61 ; return mutex[id]->owner; 1A61 E603 ldab 3,x 1A63 87 clra 1A64 59 lsld 1A65 C30214 addd #_mutex 1A68 B7C6 xgdy 1A6A ED40 ldy 0,y 1A6C E648 ldab 8,y 1A6E B714 tfr b,d 1A70 2003 bra L151 1A72 L152: 1A72 ; } 1A72 ; else { 1A72 ; #ifdef KERNEL_ERROR_MSG 1A72 ; puts(error_src[1]); puts(error_msg[6]); 1A72 ; #endif 1A72 ; return -1; 1A72 CCFFFF ldd #-1 1A75 L151: 1A75 B757 tfr x,s 1A77 30 pulx 1A78 1B82 leas 2,sp 1A7A .dbline 0 ; func end 1A7A 3D rts 1A7B ; id -> 3,x 1A7B _get_mutex_queuelen:: 1A7B 3B pshd 1A7C 34 pshx 1A7D B775 tfr s,x 1A7F ; } 1A7F ; 1A7F ; } 1A7F ; 1A7F ; 1A7F ; 1A7F ; 1A7F ; int get_mutex_queuelen(unsigned char id) { 1A7F ; 1A7F ; if (id < MAXMUTEXES) { 1A7F E603 ldab 3,x 1A81 C104 cmpb #4 1A83 2410 bhs L155 1A85 ; return mutex[id]->queue_ptr; 1A85 E603 ldab 3,x 1A87 87 clra 1A88 59 lsld 1A89 C30214 addd #_mutex 1A8C B7C6 xgdy 1A8E ED40 ldy 0,y 1A90 E64C ldab 12,y 1A92 87 clra 1A93 2003 bra L154 1A95 L155: 1A95 ; } 1A95 ; else { 1A95 ; #ifdef KERNEL_ERROR_MSG 1A95 ; puts(error_src[1]); puts(error_msg[6]); 1A95 ; #endif 1A95 ; return -1; 1A95 CCFFFF ldd #-1 1A98 L154: 1A98 B757 tfr x,s 1A9A 30 pulx 1A9B 1B82 leas 2,sp 1A9D .dbline 0 ; func end 1A9D 3D rts 1A9E ; id -> -1,x 1A9E ; name -> 6,x 1A9E ; type -> 3,x 1A9E _create_mutex:: 1A9E 3B pshd 1A9F 34 pshx 1AA0 B775 tfr s,x 1AA2 1B9A leas -6,sp 1AA4 ; } 1AA4 ; 1AA4 ; } 1AA4 ; 1AA4 ; 1AA4 ; 1AA4 ; 1AA4 ; int create_mutex(unsigned char type, char *name) { 1AA4 ; 1AA4 ; // LOCAL VARIABLES 1AA4 ; unsigned char id; 1AA4 ; 1AA4 ; 1AA4 ; INTR_OFF(); // critical section 1AA4 1410 sei 1AA6 1AA6 691F clr -1,x 1AA8 2031 bra L161 1AAA L158: 1AAA ; 1AAA ; 1AAA ; // determine if the type already exists 1AAA ; for (id=0; idtype == type) { 1AB9 E61F ldab -1,x 1ABB 87 clra 1ABC 59 lsld 1ABD C30214 addd #_mutex 1AC0 B7C6 xgdy 1AC2 ED40 ldy 0,y 1AC4 E641 ldab 1,y 1AC6 E103 cmpb 3,x 1AC8 2609 bne L164 1ACA ; INTR_ON(); 1ACA 10EF cli 1ACC 1ACC ; return 0; 1ACC CC0000 ldd #0 1ACF 182000DD lbra L157 1AD3 L164: 1AD3 L159: 1AD3 E61F ldab -1,x 1AD5 87 clra 1AD6 C30001 addd #1 1AD9 6B1F stab -1,x 1ADB L161: 1ADB E61F ldab -1,x 1ADD C104 cmpb #4 1ADF 25C9 blo L158 1AE1 691F clr -1,x 1AE3 2015 bra L169 1AE5 L166: 1AE5 E61F ldab -1,x 1AE7 87 clra 1AE8 59 lsld 1AE9 C30214 addd #_mutex 1AEC B7C6 xgdy 1AEE EC40 ldd 0,y 1AF0 270E beq L168 1AF2 L167: 1AF2 E61F ldab -1,x 1AF4 87 clra 1AF5 C30001 addd #1 1AF8 6B1F stab -1,x 1AFA L169: 1AFA ; } 1AFA ; } 1AFA ; 1AFA ; 1AFA ; // determine lowest free id available to assign to this task 1AFA ; for (id=0; idid = id; 1B22 E61F ldab -1,x 1B24 87 clra 1B25 59 lsld 1B26 C30214 addd #_mutex 1B29 B7C6 xgdy 1B2B ED40 ldy 0,y 1B2D E61F ldab -1,x 1B2F 6B40 stab 0,y 1B31 ; mutex[id]->type = type; 1B31 E61F ldab -1,x 1B33 87 clra 1B34 59 lsld 1B35 C30214 addd #_mutex 1B38 B7C6 xgdy 1B3A ED40 ldy 0,y 1B3C E603 ldab 3,x 1B3E 6B41 stab 1,y 1B40 ; strcpy(mutex[id]->name, name); 1B40 18020680 movw 6,x,0,sp 1B44 E61F ldab -1,x 1B46 87 clra 1B47 59 lsld 1B48 C30214 addd #_mutex 1B4B B7C6 xgdy 1B4D EC40 ldd 0,y 1B4F C30002 addd #2 1B52 163D6B jsr _strcpy 1B55 ; mutex[id]->state = NOTBUSY; 1B55 E61F ldab -1,x 1B57 87 clra 1B58 59 lsld 1B59 C30214 addd #_mutex 1B5C B7C6 xgdy 1B5E ED40 ldy 0,y 1B60 6947 clr 7,y 1B62 ; mutex[id]->owner = -1; 1B62 E61F ldab -1,x 1B64 87 clra 1B65 59 lsld 1B66 C30214 addd #_mutex 1B69 B7C6 xgdy 1B6B ED40 ldy 0,y 1B6D C6FF ldab #-1 1B6F 6B48 stab 8,y 1B71 ; mutex[id]->queue[0] = -1; 1B71 E61F ldab -1,x 1B73 87 clra 1B74 59 lsld 1B75 C30214 addd #_mutex 1B78 B7C6 xgdy 1B7A ED40 ldy 0,y 1B7C C6FF ldab #-1 1B7E 6B49 stab 9,y 1B80 ; mutex[id]->queue[1] = -1; 1B80 E61F ldab -1,x 1B82 87 clra 1B83 59 lsld 1B84 C30214 addd #_mutex 1B87 B7C6 xgdy 1B89 ED40 ldy 0,y 1B8B C6FF ldab #-1 1B8D 6B4A stab 10,y 1B8F ; mutex[id]->queue[2] = -1; 1B8F E61F ldab -1,x 1B91 87 clra 1B92 59 lsld 1B93 C30214 addd #_mutex 1B96 B7C6 xgdy 1B98 ED40 ldy 0,y 1B9A C6FF ldab #-1 1B9C 6B4B stab 11,y 1B9E ; mutex[id]->queue_ptr = 0; 1B9E E61F ldab -1,x 1BA0 87 clra 1BA1 59 lsld 1BA2 C30214 addd #_mutex 1BA5 B7C6 xgdy 1BA7 ED40 ldy 0,y 1BA9 694C clr 12,y 1BAB ; } 1BAB ; 1BAB ; 1BAB ; INTR_ON(); 1BAB 10EF cli 1BAD 1BAD ; 1BAD ; return id; 1BAD E61F ldab -1,x 1BAF 87 clra 1BB0 L157: 1BB0 B757 tfr x,s 1BB2 30 pulx 1BB3 1B82 leas 2,sp 1BB5 .dbline 0 ; func end 1BB5 3D rts 1BB6 ; ?temp -> -8,x 1BB6 ; ?temp -> -6,x 1BB6 ; ?temp -> -4,x 1BB6 ; id -> -2,x 1BB6 ; type -> 3,x 1BB6 _get_mutex:: 1BB6 3B pshd 1BB7 34 pshx 1BB8 B775 tfr s,x 1BBA 1B96 leas -10,sp 1BBC ; 1BBC ; } 1BBC ; 1BBC ; 1BBC ; 1BBC ; 1BBC ; int get_mutex(unsigned char type) { 1BBC ; 1BBC ; /* Gives a mutex to a requesting task. 1BBC ; returns the mutex id number (0,1,2,...) if free. 1BBC ; otherwise returns -1. 1BBC ; 1BBC ; At this point, mutexs are a procedural control 1BBC ; that the tasks have to follow to avoid resource contention. 1BBC ; There is no kernel control over resources yet. */ 1BBC ; 1BBC ; 1BBC ; // LOCAL VARIABLES 1BBC ; int id; 1BBC ; 1BBC ; 1BBC ; 1BBC ; // critical section 1BBC ; INTR_OFF(); 1BBC 1410 sei 1BBE 1BBE CC0000 ldd #0 1BC1 6C1E std -2,x 1BC3 L175: 1BC3 ; 1BC3 ; 1BC3 ; // find id for mutex type 1BC3 ; for (id=0; idtype == type) 1BD1 EC1E ldd -2,x 1BD3 59 lsld 1BD4 C30214 addd #_mutex 1BD7 B7C6 xgdy 1BD9 ED40 ldy 0,y 1BDB E641 ldab 1,y 1BDD E103 cmpb 3,x 1BDF 2602 bne L181 1BE1 ; break; 1BE1 200E bra L177 1BE3 L181: 1BE3 L176: 1BE3 EC1E ldd -2,x 1BE5 C30001 addd #1 1BE8 6C1E std -2,x 1BEA EC1E ldd -2,x 1BEC 8C0004 cpd #4 1BEF 2DD2 blt L175 1BF1 L177: 1BF1 ; } 1BF1 ; 1BF1 ; 1BF1 ; // GET mutex 1BF1 ; 1BF1 ; // if mutex isn't taken, give it to the requesting task 1BF1 ; if (mutex[id]->state == NOTBUSY) { 1BF1 EC1E ldd -2,x 1BF3 59 lsld 1BF4 C30214 addd #_mutex 1BF7 B7C6 xgdy 1BF9 ED40 ldy 0,y 1BFB E747 tst 7,y 1BFD 2625 bne L183 1BFF ; mutex[id]->state = BUSY; 1BFF EC1E ldd -2,x 1C01 59 lsld 1C02 C30214 addd #_mutex 1C05 B7C6 xgdy 1C07 ED40 ldy 0,y 1C09 C601 ldab #1 1C0B 6B47 stab 7,y 1C0D ; mutex[id]->owner = current; 1C0D EC1E ldd -2,x 1C0F 59 lsld 1C10 C30214 addd #_mutex 1C13 B7C6 xgdy 1C15 ED40 ldy 0,y 1C17 F60237 ldab _current+1 1C1A 6B48 stab 8,y 1C1C ; 1C1C ; INTR_ON(); 1C1C 10EF cli 1C1E 1C1E ; return id; 1C1E EC1E ldd -2,x 1C20 18200088 lbra L174 1C24 L183: 1C24 ; } 1C24 ; 1C24 ; // mutex is taken/busy so make task wait 1C24 ; else { 1C24 ; // put waiting task into the mutexs queue if there's space 1C24 ; if (mutex[id]->queue_ptr < 3) { 1C24 EC1E ldd -2,x 1C26 59 lsld 1C27 C30214 addd #_mutex 1C2A B7C6 xgdy 1C2C ED40 ldy 0,y 1C2E E64C ldab 12,y 1C30 C103 cmpb #3 1C32 18240071 lbhs L185 1C36 ; task[current]->message |= STATE_FLAG; 1C36 FC0236 ldd _current 1C39 59 lsld 1C3A C3021C addd #_task 1C3D B7C6 xgdy 1C3F EC40 ldd 0,y 1C41 C30014 addd #20 1C44 6C1C std -4,x 1C46 B746 tfr d,y 1C48 35 pshy ; spill 1C49 ED1C ldy -4,x 1C4B 31 puly ; reload 1C4C 0C4001 bset 0,y,#1 1C4F ; task[current]->message_data[STATE_BOX] = WAITING; 1C4F FC0236 ldd _current 1C52 59 lsld 1C53 C3021C addd #_task 1C56 B7C6 xgdy 1C58 ED40 ldy 0,y 1C5A C603 ldab #3 1C5C 6BE815 stab 21,y 1C5F ; mutex[id]->queue[mutex[id]->queue_ptr] = current; 1C5F EC1E ldd -2,x 1C61 59 lsld 1C62 C30214 addd #_mutex 1C65 B7C6 xgdy 1C67 ED40 ldy 0,y 1C69 6D1A sty -6,x 1C6B ED1A ldy -6,x 1C6D E64C ldab 12,y 1C6F 87 clra 1C70 3B pshd ; spill 1C71 EC1A ldd -6,x 1C73 C30009 addd #9 1C76 6C16 std -10,x 1C78 3A puld ; reload 1C79 E316 addd -10,x 1C7B B7C6 xgdy 1C7D F60237 ldab _current+1 1C80 6B40 stab 0,y 1C82 ; mutex[id]->queue_ptr++; 1C82 EC1E ldd -2,x 1C84 59 lsld 1C85 C30214 addd #_mutex 1C88 B7C6 xgdy 1C8A EC40 ldd 0,y 1C8C C3000C addd #12 1C8F 6C18 std -8,x 1C91 B746 tfr d,y 1C93 E640 ldab 0,y 1C95 87 clra 1C96 C30001 addd #1 1C99 ED18 ldy -8,x 1C9B 6B40 stab 0,y 1C9D ; INTR_ON(); 1C9D 10EF cli 1C9F 1C9F ; asm("JMP $116A"); 1C9F 06116A JMP $116A 1CA2 1CA2 ; return 0; 1CA2 CC0000 ldd #0 1CA5 2005 bra L174 1CA7 L185: 1CA7 ; } 1CA7 ; else { // can't give mutex 1CA7 ; INTR_ON(); 1CA7 10EF cli 1CA9 1CA9 ; return -1; 1CA9 CCFFFF ldd #-1 1CAC L174: 1CAC B757 tfr x,s 1CAE 30 pulx 1CAF 1B82 leas 2,sp 1CB1 .dbline 0 ; func end 1CB1 3D rts 1CB2 ; ?temp -> -10,x 1CB2 ; ?temp -> -8,x 1CB2 ; ?temp -> -6,x 1CB2 ; ?temp -> -4,x 1CB2 ; ?temp -> -2,x 1CB2 ; id -> 3,x 1CB2 _give_mutex:: 1CB2 3B pshd 1CB3 34 pshx 1CB4 B775 tfr s,x 1CB6 1B96 leas -10,sp 1CB8 ; } 1CB8 ; } 1CB8 ; 1CB8 ; } 1CB8 ; 1CB8 ; 1CB8 ; 1CB8 ; 1CB8 ; int give_mutex(char id) { 1CB8 ; 1CB8 ; /* Takes a mutex back from a task. 1CB8 ; will (eventually) pass a message to a waiting task. 1CB8 ; 1CB8 ; At this point, mutexs are a procedural control 1CB8 ; that the tasks have to follow to avoid resource contention. 1CB8 ; There is no kernel control over resources yet. */ 1CB8 ; 1CB8 ; 1CB8 ; // critical section 1CB8 ; INTR_OFF(); 1CB8 1410 sei 1CBA 1CBA ; 1CBA ; 1CBA ; // if any tasks are waiting on the mutex, give it to them 1CBA ; if (mutex[id]->queue_ptr > 0) { 1CBA E603 ldab 3,x 1CBC 87 clra 1CBD 59 lsld 1CBE C30214 addd #_mutex 1CC1 B7C6 xgdy 1CC3 ED40 ldy 0,y 1CC5 E74C tst 12,y 1CC7 1823008B lbls L188 1CCB ; //mutex[id]->state = BUSY; 1CCB ; mutex[id]->owner = mutex[id]->queue[0]; 1CCB E603 ldab 3,x 1CCD 87 clra 1CCE 59 lsld 1CCF C30214 addd #_mutex 1CD2 B7C6 xgdy 1CD4 ED40 ldy 0,y 1CD6 6D1E sty -2,x 1CD8 ED1E ldy -2,x 1CDA E649 ldab 9,y 1CDC ED1E ldy -2,x 1CDE 6B48 stab 8,y 1CE0 ; 1CE0 ; // take the receiving task out of the waiting state 1CE0 ; task[current]->message |= STATE_FLAG; 1CE0 FC0236 ldd _current 1CE3 59 lsld 1CE4 C3021C addd #_task 1CE7 B7C6 xgdy 1CE9 EC40 ldd 0,y 1CEB C30014 addd #20 1CEE 6C1C std -4,x 1CF0 B746 tfr d,y 1CF2 35 pshy ; spill 1CF3 ED1C ldy -4,x 1CF5 31 puly ; reload 1CF6 0C4001 bset 0,y,#1 1CF9 ; task[current]->message_data[STATE_BOX] = RUNNING; 1CF9 FC0236 ldd _current 1CFC 59 lsld 1CFD C3021C addd #_task 1D00 B7C6 xgdy 1D02 ED40 ldy 0,y 1D04 C602 ldab #2 1D06 6BE815 stab 21,y 1D09 ; 1D09 ; // shift the queue 1D09 ; mutex[id]->queue[0] = mutex[id]->queue[1]; 1D09 E603 ldab 3,x 1D0B 87 clra 1D0C 59 lsld 1D0D C30214 addd #_mutex 1D10 B7C6 xgdy 1D12 ED40 ldy 0,y 1D14 6D1A sty -6,x 1D16 ED1A ldy -6,x 1D18 E64A ldab 10,y 1D1A ED1A ldy -6,x 1D1C 6B49 stab 9,y 1D1E ; mutex[id]->queue[1] = mutex[id]->queue[2]; 1D1E E603 ldab 3,x 1D20 87 clra 1D21 59 lsld 1D22 C30214 addd #_mutex 1D25 B7C6 xgdy 1D27 ED40 ldy 0,y 1D29 6D18 sty -8,x 1D2B ED18 ldy -8,x 1D2D E64B ldab 11,y 1D2F ED18 ldy -8,x 1D31 6B4A stab 10,y 1D33 ; mutex[id]->queue_ptr--; 1D33 E603 ldab 3,x 1D35 87 clra 1D36 59 lsld 1D37 C30214 addd #_mutex 1D3A B7C6 xgdy 1D3C EC40 ldd 0,y 1D3E C3000C addd #12 1D41 6C16 std -10,x 1D43 B746 tfr d,y 1D45 E640 ldab 0,y 1D47 87 clra 1D48 830001 subd #1 1D4B ED16 ldy -10,x 1D4D 6B40 stab 0,y 1D4F ; 1D4F ; INTR_ON(); 1D4F 10EF cli 1D51 1D51 ; return 0; 1D51 CC0000 ldd #0 1D54 2021 bra L187 1D56 L188: 1D56 ; } 1D56 ; else { 1D56 ; // return the mutex 1D56 ; mutex[id]->state = NOTBUSY; 1D56 E603 ldab 3,x 1D58 87 clra 1D59 59 lsld 1D5A C30214 addd #_mutex 1D5D B7C6 xgdy 1D5F ED40 ldy 0,y 1D61 6947 clr 7,y 1D63 ; mutex[id]->owner = -1; 1D63 E603 ldab 3,x 1D65 87 clra 1D66 59 lsld 1D67 C30214 addd #_mutex 1D6A B7C6 xgdy 1D6C ED40 ldy 0,y 1D6E C6FF ldab #-1 1D70 6B48 stab 8,y 1D72 ; INTR_ON(); 1D72 10EF cli 1D74 1D74 ; return 0; 1D74 CC0000 ldd #0 1D77 L187: 1D77 B757 tfr x,s 1D79 30 pulx 1D7A 1B82 leas 2,sp 1D7C .dbline 0 ; func end 1D7C 3D rts 1D7D ; lreg1 -> -4,x 1D7D ; lreg2 -> -8,x 1D7D ; slop -> -12,x 1D7D _get_sysTime:: 1D7D 34 pshx 1D7E B775 tfr s,x 1D80 1B94 leas -12,sp 1D82 ; } 1D82 ; 1D82 ; } 1D82 ; 1D82 ; 1D82 ; 1D82 ; unsigned long int get_sysTime(void) { 1D82 ; 1D82 ; // LOCAL VARIABLES 1D82 ; unsigned long int slop; 1D82 ; 1D82 ; 1D82 ; // returns the number of milliseconds since midnight (time_tick=0); 1D82 ; slop = time_tick / 40; 1D82 CD022C ldy #_time_tick 1D85 1802401C movw 0,y,-4,x 1D89 1802421E movw 2,y,-2,x 1D8D CD1E99 ldy #L191 1D90 18024018 movw 0,y,-8,x 1D94 1802421A movw 2,y,-6,x 1D98 163C02 jsr __ludiv 1D9B 1914 leay -12,x 1D9D 18021C40 movw -4,x,0,y 1DA1 18021E42 movw -2,x,2,y 1DA5 ; return (time_tick * ms_PER_TIME_TICK + slop); 1DA5 CD1E95 ldy #L192 1DA8 1802401C movw 0,y,-4,x 1DAC 1802421E movw 2,y,-2,x 1DB0 CD022C ldy #_time_tick 1DB3 18024018 movw 0,y,-8,x 1DB7 1802421A movw 2,y,-6,x 1DBB 163B62 jsr __lmul 1DBE 1914 leay -12,x 1DC0 18024018 movw 0,y,-8,x 1DC4 1802421A movw 2,y,-6,x 1DC8 163B40 jsr __ladd 1DCB 163B16 jsr __lret 1DCE L190: 1DCE B757 tfr x,s 1DD0 30 pulx 1DD1 .dbline 0 ; func end 1DD1 3D rts 1DD2 ; lreg1 -> -4,x 1DD2 ; lreg2 -> -8,x 1DD2 ; slop -> -12,x 1DD2 ; seconds -> 8,x 1DD2 ; minutes -> 6,x 1DD2 ; hours -> 2,x 1DD2 _set_sysTime:: 1DD2 3B pshd 1DD3 34 pshx 1DD4 B775 tfr s,x 1DD6 1B92 leas -14,sp 1DD8 ; 1DD8 ; } 1DD8 ; 1DD8 ; 1DD8 ; 1DD8 ; void set_sysTime(unsigned int hours, unsigned int minutes, unsigned int seconds) { 1DD8 ; 1DD8 ; // LOCAL VARIABLES 1DD8 ; extern unsigned long int time_tick; 1DD8 ; unsigned long int slop; 1DD8 ; 1DD8 ; 1DD8 ; time_tick = ((hours*3600)+(minutes*60)+(seconds)) * TIME_TICKS_PER_SECOND; 1DD8 CC003C ldd #60 1DDB ED06 ldy 6,x 1DDD 13 emul 1DDE 6C12 std -14,x 1DE0 CC0E10 ldd #3600 1DE3 ED02 ldy 2,x 1DE5 13 emul 1DE6 E312 addd -14,x 1DE8 E308 addd 8,x 1DEA 6C1A std -6,x 1DEC 1800180000 movw #0,-8,x 1DF1 CD1E91 ldy #L194 1DF4 1802401C movw 0,y,-4,x 1DF8 1802421E movw 2,y,-2,x 1DFC 163B62 jsr __lmul 1DFF CD022C ldy #_time_tick 1E02 18021C40 movw -4,x,0,y 1E06 18021E42 movw -2,x,2,y 1E0A ; slop = time_tick / 40; 1E0A CD022C ldy #_time_tick 1E0D 1802401C movw 0,y,-4,x 1E11 1802421E movw 2,y,-2,x 1E15 CD1E99 ldy #L191 1E18 18024018 movw 0,y,-8,x 1E1C 1802421A movw 2,y,-6,x 1E20 163C02 jsr __ludiv 1E23 1914 leay -12,x 1E25 18021C40 movw -4,x,0,y 1E29 18021E42 movw -2,x,2,y 1E2D ; time_tick += slop; 1E2D 1914 leay -12,x 1E2F 18024018 movw 0,y,-8,x 1E33 1802421A movw 2,y,-6,x 1E37 CD022C ldy #_time_tick 1E3A 1802401C movw 0,y,-4,x 1E3E 1802421E movw 2,y,-2,x 1E42 163B40 jsr __ladd 1E45 CD022C ldy #_time_tick 1E48 18021C40 movw -4,x,0,y 1E4C 18021E42 movw -2,x,2,y 1E50 ; 1E50 ; } 1E50 L193: 1E50 B757 tfr x,s 1E52 30 pulx 1E53 1B82 leas 2,sp 1E55 .dbline 0 ; func end 1E55 3D rts 1E56 ; last -> -6,x 1E56 ; memory -> -4,x 1E56 ; i -> -2,x 1E56 _get_free_memory:: 1E56 34 pshx 1E57 B775 tfr s,x 1E59 1B98 leas -8,sp 1E5B ; 1E5B ; 1E5B ; 1E5B ; 1E5B ; int get_free_memory(void) { 1E5B ; 1E5B ; // LOCAL VARIABLES 1E5B ; char *memory, *last; 1E5B ; int i; 1E5B ; 1E5B ; 1E5B ; INTR_OFF(); 1E5B 1410 sei 1E5D 1E5D CC0000 ldd #0 1E60 6C1E std -2,x 1E62 L196: 1E62 ; // check for largest free memory block 1E62 ; for (i=0; i -49,x ; ?temp -> -47,x ; cmd_length -> -46,x ; cmd -> -44,x ; argc -> -43,x ; argv -> -41,x ; cursor1 -> -39,x ; j -> -37,x ; cursor2 -> -36,x ; command -> -34,x ; i -> -1,x 1F10 _shell:: 1F10 34 pshx 1F11 B775 tfr s,x 1F13 1BF1C0 leas -64,sp 1F16 ; // shell.c 1F16 ; 1F16 ; #include <912d60.h> 1F16 ; #include 1F16 ; #include 1F16 ; #include 1F16 ; #include 1F16 ; #include "kernel.h" 1F16 ; 1F16 ; 1F16 ; 1F16 ; 1F16 ; // FUNCTION PROTOTYPES 1F16 ; void shellcmd_help(char *argv1); 1F16 ; void shellcmd_tcb(signed char id); 1F16 ; void shellcmd_mcb(signed char id); 1F16 ; void shellcmd_mcbPrint(signed char rid); 1F16 ; void shellcmd_ticks(void); 1F16 ; void shellcmd_startTask(unsigned char id); 1F16 ; void shellcmd_stopTask(unsigned char id); 1F16 ; void shellcmd_time(void); 1F16 ; void shellcmd_freeMemCheck(void); 1F16 ; void shellcmd_kdb(int onoff); 1F16 ; void shellcmd_quitShell(void); 1F16 ; /* 1F16 ; void shellcmd_setTaskPriority(unsigned char id, unsigned char priority); 1F16 ; */ 1F16 ; 1F16 ; 1F16 ; 1F16 ; 1F16 ; // GLOBAL VARIABLES 1F16 ; extern unsigned long int system_tick; 1F16 ; extern unsigned int current; // current task id number 1F16 ; 1F16 ; extern char error_msg[8][25]; 1F16 ; extern char error_src[5][18]; 1F16 ; 1F16 ; extern char kdb_trace; 1F16 ; 1F16 ; 1F16 ; 1F16 ; 1F16 ; int shell(void) { 1F16 ; 1F16 ; // LOCAL CONSTANTS 1F16 ; #define cmd_size (32+1) 1F16 ; 1F16 ; 1F16 ; 1F16 ; // LOCAL ENUMERATIONS 1F16 ; enum command_type { help = 1, 1F16 ; tcb, 1F16 ; mcb, 1F16 ; ticks, 1F16 ; start, 1F16 ; stop, 1F16 ; priority, 1F16 ; time, 1F16 ; freemem, 1F16 ; kdb, 1F16 ; quit, 1F16 ; taskname 1F16 ; }; 1F16 ; 1F16 ; 1F16 ; 1F16 ; // LOCAL VARIABLES 1F16 ; char command[cmd_size], i, j, **argv, *cursor1, *cursor2; 1F16 ; int cmd_length, argc; 1F16 ; enum command_type cmd; 1F16 ; 1F16 ; 1F16 ; 1F16 ; 1F16 ; // INITIALIZE SHELL 1F16 ; get_mutex(COM1); // get COM1 mutex 1F16 CC0003 ldd #3 1F19 161BB6 jsr _get_mutex 1F1C ; set_task_priority(current, 200); 1F1C CC00C8 ldd #200 1F1F 6C80 std 0,sp 1F21 FC0236 ldd _current 1F24 87 clra 1F25 1617E9 jsr _set_task_priority 1F28 ; INTR_ON(); // enable interrupts 1F28 10EF cli 1F2A 1F2A 18200661 lbra L5 1F2E L4: 1F2E ; 1F2E ; 1F2E ; 1F2E ; 1F2E ; 1F2E ; // SHELL COMMAND LINE INTERPRETER 1F2E ; while (1) { 1F2E ; 1F2E ; INTR_ON(); 1F2E 10EF cli 1F30 1F30 ; i = 0; 1F30 691F clr -1,x 1F32 ; cursor1 = command; 1F32 19E1DE leay -34,x 1F35 6DE1D9 sty -39,x 1F38 ; cursor2 = command; 1F38 19E1DE leay -34,x 1F3B 6DE1DC sty -36,x 1F3E ; 1F3E ; 1F3E ; // put a PROMPT 1F3E ; putchar('>'); putchar('>'); putchar(' '); 1F3E CC003E ldd #62 1F41 1637EF jsr _putchar 1F44 CC003E ldd #62 1F47 1637EF jsr _putchar 1F4A CC0020 ldd #32 1F4D 1637EF jsr _putchar 1F50 2056 bra L8 1F52 L7: 1F52 ; 1F52 ; 1F52 ; // GET AND ECHO THE COMMAND on the console 1F52 ; while (((command[i]=getchar()) != 0xD) && (i -- required arguments"); 22C1 CC2D4F ldd #L76 22C4 163D7A jsr _puts 22C7 ; puts("[] -- optional arguments\n"); 22C7 CC2D35 ldd #L77 22CA 163D7A jsr _puts 22CD ; puts("help [cmd] -- help on a specific command"); 22CD CC2D0C ldd #L78 22D0 163D7A jsr _puts 22D3 ; puts("tcb [task_id] -- prints task control block"); 22D3 CC2CE1 ldd #L79 22D6 163D7A jsr _puts 22D9 ; puts("mcb [[task_id] | [-b]] -- prints mutex control block"); 22D9 CC2CAC ldd #L80 22DC 163D7A jsr _puts 22DF ; puts("ticks -- shows system tick"); 22DF CC2C91 ldd #L81 22E2 163D7A jsr _puts 22E5 ; puts("start -- start a task"); 22E5 CC2C71 ldd #L82 22E8 163D7A jsr _puts 22EB ; puts("stop -- stop a task"); 22EB CC2C52 ldd #L83 22EE 163D7A jsr _puts 22F1 ; puts("priority , -- change prio"); 22F1 CC2C1E ldd #L84 22F4 163D7A jsr _puts 22F7 ; puts("time [ ]-- display/set the current system time"); 22F7 CC2BDE ldd #L85 22FA 163D7A jsr _puts 22FD ; puts("freemem -- get approximate free RAM space"); 22FD CC2BB4 ldd #L86 2300 163D7A jsr _puts 2303 ; puts("kdb [1|0] -- turn kernel debug on/off"); 2303 CC2B8E ldd #L87 2306 163D7A jsr _puts 2309 ; puts("quit -- quit the shell (carefull!)"); 2309 CC2B6B ldd #L88 230C 163D7A jsr _puts 230F ; putchar('\n'); 230F CC000A ldd #10 2312 1637EF jsr _putchar 2315 ; } 2315 18200248 lbra L70 2319 L73: 2319 ; else if (argc == 2) 2319 ECE1D5 ldd -43,x 231C 8C0002 cpd #2 231F 1826023E lbne L70 2323 ; shellcmd_help(argv[1]); 2323 EDE1D7 ldy -41,x 2326 EC42 ldd 2,y 2328 1625A2 jsr _shellcmd_help 232B ; break; 232B 18200232 lbra L70 232F L91: 232F ; case tcb: 232F ; if (argc == 1) 232F ECE1D5 ldd -43,x 2332 8C0001 cpd #1 2335 260A bne L92 2337 ; shellcmd_tcb(-1); 2337 CCFFFF ldd #-1 233A 1625A9 jsr _shellcmd_tcb 233D 18200220 lbra L70 2341 L92: 2341 ; else if (argc == 2) 2341 ECE1D5 ldd -43,x 2344 8C0002 cpd #2 2347 2611 bne L94 2349 ; shellcmd_tcb(atoi(argv[1])); 2349 EDE1D7 ldy -41,x 234C EC42 ldd 2,y 234E 1641DA jsr _atoi 2351 B714 tfr b,d 2353 1625A9 jsr _shellcmd_tcb 2356 18200207 lbra L70 235A L94: 235A ; else if (argc > 2) 235A ECE1D5 ldd -43,x 235D 8C0002 cpd #2 2360 182F01FD lble L70 2364 ; puts(error_msg[1]); 2364 CC1043 ldd #_error_msg+25 2367 163D7A jsr _puts 236A ; break; 236A 182001F3 lbra L70 236E L99: 236E ; case mcb: 236E ; if (argc == 1) // print entire rcb 236E ECE1D5 ldd -43,x 2371 8C0001 cpd #1 2374 260A bne L100 2376 ; shellcmd_mcb(-1); 2376 CCFFFF ldd #-1 2379 16266A jsr _shellcmd_mcb 237C 182001E1 lbra L70 2380 L100: 2380 ; else if (argc == 2) { 2380 ECE1D5 ldd -43,x 2383 8C0002 cpd #2 2386 262D bne L102 2388 ; if (!strcmp(argv[1], "-b")) { // print 'busy' only 2388 CC2B68 ldd #L106 238B 6C80 std 0,sp 238D EDE1D7 ldy -41,x 2390 EC42 ldd 2,y 2392 163D01 jsr _strcmp 2395 8C0000 cpd #0 2398 260A bne L104 239A ; shellcmd_mcb(-2); 239A CCFFFE ldd #-2 239D 16266A jsr _shellcmd_mcb 23A0 ; } 23A0 182001BD lbra L70 23A4 L104: 23A4 ; else 23A4 ; shellcmd_mcb(atoi(argv[1])); // single 23A4 EDE1D7 ldy -41,x 23A7 EC42 ldd 2,y 23A9 1641DA jsr _atoi 23AC B714 tfr b,d 23AE 16266A jsr _shellcmd_mcb 23B1 ; } 23B1 182001AC lbra L70 23B5 L102: 23B5 ; else if (argc > 2) 23B5 ECE1D5 ldd -43,x 23B8 8C0002 cpd #2 23BB 182F01A2 lble L70 23BF ; puts(error_msg[1]); 23BF CC1043 ldd #_error_msg+25 23C2 163D7A jsr _puts 23C5 ; break; 23C5 18200198 lbra L70 23C9 L110: 23C9 ; case ticks: 23C9 ; if (argc > 1) 23C9 ECE1D5 ldd -43,x 23CC 8C0001 cpd #1 23CF 2F0A ble L111 23D1 ; puts(error_msg[1]); 23D1 CC1043 ldd #_error_msg+25 23D4 163D7A jsr _puts 23D7 18200186 lbra L70 23DB L111: 23DB ; else 23DB ; shellcmd_ticks(); 23DB 16274D jsr _shellcmd_ticks 23DE ; break; 23DE 1820017F lbra L70 23E2 L114: 23E2 ; case start: 23E2 ; if ((argc != 2) || 23E2 ECE1D5 ldd -43,x 23E5 8C0002 cpd #2 23E8 2610 bne L117 23EA EDE1D7 ldy -41,x 23ED ED42 ldy 2,y 23EF E640 ldab 0,y 23F1 87 clra 23F2 163F7F jsr _isdigit 23F5 8C0000 cpd #0 23F8 260A bne L115 23FA L117: 23FA ; (!isdigit(*argv[1]))) 23FA ; puts(error_msg[1]); 23FA CC1043 ldd #_error_msg+25 23FD 163D7A jsr _puts 2400 1820015D lbra L70 2404 L115: 2404 ; else 2404 ; shellcmd_startTask(atoi(argv[1])); 2404 EDE1D7 ldy -41,x 2407 EC42 ldd 2,y 2409 1641DA jsr _atoi 240C 87 clra 240D 162775 jsr _shellcmd_startTask 2410 ; break; 2410 1820014D lbra L70 2414 L119: 2414 ; case stop: 2414 ; if ((argc != 2) || 2414 ECE1D5 ldd -43,x 2417 8C0002 cpd #2 241A 2610 bne L122 241C EDE1D7 ldy -41,x 241F ED42 ldy 2,y 2421 E640 ldab 0,y 2423 87 clra 2424 163F7F jsr _isdigit 2427 8C0000 cpd #0 242A 260A bne L120 242C L122: 242C ; (!isdigit(*argv[1]))) 242C ; puts(error_msg[1]); 242C CC1043 ldd #_error_msg+25 242F 163D7A jsr _puts 2432 1820012B lbra L70 2436 L120: 2436 ; else 2436 ; shellcmd_stopTask(atoi(argv[1])); 2436 EDE1D7 ldy -41,x 2439 EC42 ldd 2,y 243B 1641DA jsr _atoi 243E 87 clra 243F 1627A0 jsr _shellcmd_stopTask 2442 ; break; 2442 1820011B lbra L70 2446 L124: 2446 ; case priority: 2446 ; puts(error_msg[0]); 2446 CC102A ldd #_error_msg 2449 163D7A jsr _puts 244C ; break; 244C 18200111 lbra L70 2450 L125: 2450 ECE1D5 ldd -43,x 2453 8C0001 cpd #1 2456 270A beq L128 2458 ECE1D5 ldd -43,x 245B 8C0004 cpd #4 245E 2709 beq L129 2460 2055 bra L126 2462 X2: 2462 ; case time: 2462 ; switch (argc) { 2462 L128: 2462 ; case 1: 2462 ; shellcmd_time(); 2462 1627CD jsr _shellcmd_time 2465 ; break; 2465 182000F8 lbra L70 2469 L129: 2469 ; case 4: 2469 ; if (argv[1] && argv[2] && argv[3]) 2469 EDE1D7 ldy -41,x 246C EC42 ldd 2,y 246E 273D beq L130 2470 EDE1D7 ldy -41,x 2473 EC44 ldd 4,y 2475 2736 beq L130 2477 EDE1D7 ldy -41,x 247A EC46 ldd 6,y 247C 272F beq L130 247E ; set_sysTime(atoi(argv[1]), 247E EDE1D7 ldy -41,x 2481 EC42 ldd 2,y 2483 1641DA jsr _atoi 2486 6CE1C8 std -56,x 2489 EDE1D7 ldy -41,x 248C EC44 ldd 4,y 248E 1641DA jsr _atoi 2491 6CE1C6 std -58,x 2494 EDE1D7 ldy -41,x 2497 EC46 ldd 6,y 2499 1641DA jsr _atoi 249C 6C82 std 2,sp 249E ECE1C6 ldd -58,x 24A1 6C80 std 0,sp 24A3 ECE1C8 ldd -56,x 24A6 161DD2 jsr _set_sysTime 24A9 182000B4 lbra L70 24AD L130: 24AD ; atoi(argv[2]), 24AD ; atoi(argv[3])); 24AD ; else 24AD ; puts(error_msg[1]); 24AD CC1043 ldd #_error_msg+25 24B0 163D7A jsr _puts 24B3 ; break; 24B3 182000AA lbra L70 24B7 L126: 24B7 ; default: 24B7 ; puts(error_msg[1]); 24B7 CC1043 ldd #_error_msg+25 24BA 163D7A jsr _puts 24BD ; } 24BD ; break; 24BD 182000A0 lbra L70 24C1 L134: 24C1 ; case freemem: 24C1 ; shellcmd_freeMemCheck(); 24C1 1628D6 jsr _shellcmd_freeMemCheck 24C4 ; break; 24C4 18200099 lbra L70 24C8 L135: 24C8 ; case kdb: 24C8 ; if (argc < 2) 24C8 ECE1D5 ldd -43,x 24CB 8C0002 cpd #2 24CE 2C0A bge L136 24D0 ; puts(error_msg[1]); 24D0 CC1043 ldd #_error_msg+25 24D3 163D7A jsr _puts 24D6 18200087 lbra L70 24DA L136: 24DA ; else 24DA ; shellcmd_kdb(atoi(argv[1])); 24DA EDE1D7 ldy -41,x 24DD EC42 ldd 2,y 24DF 1641DA jsr _atoi 24E2 1628EE jsr _shellcmd_kdb 24E5 ; break; 24E5 18200078 lbra L70 24E9 L139: 24E9 ; case quit: 24E9 ; shellcmd_quitShell(); 24E9 1628FD jsr _shellcmd_quitShell 24EC ; return 1; 24EC CC0001 ldd #1 24EF 182000AB lbra L3 24F3 L140: 24F3 ; case taskname: 24F3 ; // start a stopped task that's already created 24F3 ; cmd = 0; 24F3 69E1D4 clr -44,x 24F6 691F clr -1,x 24F8 2042 bra L144 24FA L141: 24FA ; for (i=0; i 2,x 25A2 _shellcmd_help:: 25A2 ; 25A2 ; } // end shell() 25A2 ; 25A2 ; 25A2 ; 25A2 ; 25A2 ; 25A2 ; void shellcmd_help(char *argv1) { 25A2 ; 25A2 ; puts(error_msg[0]); 25A2 CC102A ldd #_error_msg 25A5 163D7A jsr _puts 25A8 ; } 25A8 L159: 25A8 .dbline 0 ; func end 25A8 3D rts 25A9 ; start -> -2,x 25A9 ; max -> -1,x 25A9 ; tid -> 3,x 25A9 _shellcmd_tcb:: 25A9 3B pshd 25AA 34 pshx 25AB B775 tfr s,x 25AD 1BF1EA leas -22,sp 25B0 ; 25B0 ; 25B0 ; 25B0 ; void shellcmd_tcb(signed char tid) { 25B0 ; 25B0 ; // Local Variables 25B0 ; unsigned char max, start; 25B0 ; 25B0 ; if (tid >= MAXTASKS) { 25B0 E603 ldab 3,x 25B2 C108 cmpb #8 25B4 2D0A blt L161 25B6 ; puts(error_msg[2]); 25B6 CC105C ldd #_error_msg+50 25B9 163D7A jsr _puts 25BC ; return; 25BC 182000A4 lbra L160 25C0 L161: 25C0 ; } 25C0 ; 25C0 ; if (tid < 0) { 25C0 E703 tst 3,x 25C2 2C08 bge L164 25C4 ; start = 0; 25C4 691E clr -2,x 25C6 ; max = MAXTASKS; 25C6 C608 ldab #8 25C8 6B1F stab -1,x 25CA ; } 25CA 200F bra L165 25CC L164: 25CC ; else { 25CC ; start = tid; 25CC E603 ldab 3,x 25CE B714 tfr b,d 25D0 6B1E stab -2,x 25D2 ; max = tid + 1; 25D2 E603 ldab 3,x 25D4 B714 tfr b,d 25D6 C30001 addd #1 25D9 6B1F stab -1,x 25DB ; } 25DB L165: 25DB ; 25DB ; puts("\nTask Control Block:"); 25DB CC2B53 ldd #L166 25DE 163D7A jsr _puts 25E1 E61E ldab -2,x 25E3 6B03 stab 3,x 25E5 2065 bra L170 25E7 L167: 25E7 ; for (tid=start; tid -1,x 266A ; option -> 3,x 266A _shellcmd_mcb:: 266A 3B pshd 266B 34 pshx 266C B775 tfr s,x 266E 1B9E leas -2,sp 2670 ; 2670 ; 2670 ; 2670 ; 2670 ; void shellcmd_mcb(signed char option) { 2670 ; 2670 ; // Local Variables 2670 ; unsigned char id; 2670 ; 2670 ; 2670 ; 2670 ; // print all 2670 ; if (option == -1) { 2670 E603 ldab 3,x 2672 C1FF cmpb #-1 2674 2628 bne L178 2676 691F clr -1,x 2678 201C bra L183 267A L180: 267A ; for (id=0; id= MAXMUTEXES) { 26CA E603 ldab 3,x 26CC C104 cmpb #4 26CE 2D08 blt L194 26D0 ; puts(error_msg[6]); 26D0 CC10C0 ldd #_error_msg+150 26D3 163D7A jsr _puts 26D6 ; return; 26D6 2019 bra L177 26D8 L194: 26D8 ; } 26D8 ; else 26D8 ; shellcmd_mcbPrint(option); 26D8 E603 ldab 3,x 26DA B714 tfr b,d 26DC 1626F7 jsr _shellcmd_mcbPrint 26DF ; 26DF ; } 26DF L187: 26DF L179: 26DF ; 26DF ; 26DF ; puts ("-----------+--------+----------+-----------+------------+"); 26DF CC2A08 ldd #L197 26E2 163D7A jsr _puts 26E5 ; 26E5 ; puts("\nState: 0=notbusy, 1=busy"); 26E5 CC29EE ldd #L198 26E8 163D7A jsr _puts 26EB ; puts("Owner: 0..15=task ID, -1=nobody"); 26EB CC29CE ldd #L199 26EE 163D7A jsr _puts 26F1 ; 26F1 ; } 26F1 L177: 26F1 B757 tfr x,s 26F3 30 pulx 26F4 1B82 leas 2,sp 26F6 .dbline 0 ; func end 26F6 3D rts 26F7 ; id -> 3,x 26F7 _shellcmd_mcbPrint:: 26F7 3B pshd 26F8 34 pshx 26F9 B775 tfr s,x 26FB 1B90 leas -16,sp 26FD ; 26FD ; 26FD ; 26FD ; void shellcmd_mcbPrint(signed char id) { 26FD ; 26FD ; puts ("-----------+--------+----------+-----------+------------+"); 26FD CC2A08 ldd #L197 2700 163D7A jsr _puts 2703 ; 2703 ; INTR_OFF(); 2703 1410 sei 2705 2705 ; printf("Type: %s | ID: %2d | State: %x | Owner: %2d | Waiting: %d |\n", 2705 E603 ldab 3,x 2707 B714 tfr b,d 2709 87 clra 270A 161A0A jsr _get_mutex_name 270D 6C1E std -2,x 270F E603 ldab 3,x 2711 B714 tfr b,d 2713 87 clra 2714 161A34 jsr _get_mutex_state 2717 6C1C std -4,x 2719 E603 ldab 3,x 271B B714 tfr b,d 271D 87 clra 271E 161A57 jsr _get_mutex_owner 2721 6C1A std -6,x 2723 E603 ldab 3,x 2725 B714 tfr b,d 2727 87 clra 2728 161A7B jsr _get_mutex_queuelen 272B 6C88 std 8,sp 272D ED1A ldy -6,x 272F 6D86 sty 6,sp 2731 ED1C ldy -4,x 2733 6D84 sty 4,sp 2735 E603 ldab 3,x 2737 B714 tfr b,d 2739 6C82 std 2,sp 273B ED1E ldy -2,x 273D 6D80 sty 0,sp 273F CC2991 ldd #L201 2742 163DB2 jsr _printf 2745 ; get_mutex_name(id), 2745 ; id, 2745 ; get_mutex_state(id), 2745 ; get_mutex_owner(id), 2745 ; get_mutex_queuelen(id)); 2745 ; INTR_ON(); 2745 10EF cli 2747 2747 ; 2747 ; } 2747 L200: 2747 B757 tfr x,s 2749 30 pulx 274A 1B82 leas 2,sp 274C .dbline 0 ; func end 274C 3D rts 274D ; lreg1 -> -4,x 274D ; lreg2 -> -8,x 274D _shellcmd_ticks:: 274D 34 pshx 274E B775 tfr s,x 2750 1B94 leas -12,sp 2752 ; 2752 ; 2752 ; 2752 ; void shellcmd_ticks(void) { 2752 ; 2752 ; INTR_OFF(); 2752 1410 sei 2754 2754 ; printf("ticks: %ld\n", system_tick); 2754 CD0232 ldy #_system_tick 2757 1802401C movw 0,y,-4,x 275B 1802421E movw 2,y,-2,x 275F 1980 leay 0,sp 2761 18021C40 movw -4,x,0,y 2765 18021E42 movw -2,x,2,y 2769 CC2985 ldd #L203 276C 163DB2 jsr _printf 276F ; INTR_ON(); 276F 10EF cli 2771 2771 ; } 2771 L202: 2771 B757 tfr x,s 2773 30 pulx 2774 .dbline 0 ; func end 2774 3D rts 2775 ; id -> 3,x 2775 _shellcmd_startTask:: 2775 3B pshd 2776 34 pshx 2777 B775 tfr s,x 2779 1B9E leas -2,sp 277B ; 277B ; 277B ; 277B ; 277B ; void shellcmd_startTask(unsigned char id) { 277B ; 277B ; INTR_OFF(); 277B 1410 sei 277D 277D ; if (set_task_state(id, PENDING) == 0) 277D CC0001 ldd #1 2780 6C80 std 0,sp 2782 E603 ldab 3,x 2784 87 clra 2785 1615EE jsr _set_task_state 2788 8C0000 cpd #0 278B 260B bne L205 278D ; printf("task %d started\n", id); 278D E603 ldab 3,x 278F 87 clra 2790 6C80 std 0,sp 2792 CC2974 ldd #L207 2795 163DB2 jsr _printf 2798 L205: 2798 ; INTR_ON(); 2798 10EF cli 279A 279A ; } 279A L204: 279A B757 tfr x,s 279C 30 pulx 279D 1B82 leas 2,sp 279F .dbline 0 ; func end 279F 3D rts 27A0 ; id -> 3,x 27A0 _shellcmd_stopTask:: 27A0 3B pshd 27A1 34 pshx 27A2 B775 tfr s,x 27A4 1B9E leas -2,sp 27A6 ; 27A6 ; 27A6 ; 27A6 ; 27A6 ; void shellcmd_stopTask(unsigned char id) { 27A6 ; 27A6 ; if ((set_task_state(id, STOPPED)) == 0) { 27A6 CC0004 ldd #4 27A9 6C80 std 0,sp 27AB E603 ldab 3,x 27AD 87 clra 27AE 1615EE jsr _set_task_state 27B1 8C0000 cpd #0 27B4 2611 bne L209 27B6 ; give_mutex(COM1); 27B6 CC0003 ldd #3 27B9 161CB2 jsr _give_mutex 27BC ; printf("task %d stopped\n", id); 27BC E603 ldab 3,x 27BE 87 clra 27BF 6C80 std 0,sp 27C1 CC2963 ldd #L211 27C4 163DB2 jsr _printf 27C7 ; } 27C7 L209: 27C7 ; 27C7 ; } 27C7 L208: 27C7 B757 tfr x,s 27C9 30 pulx 27CA 1B82 leas 2,sp 27CC .dbline 0 ; func end 27CC 3D rts 27CD ; lreg1 -> -4,x 27CD ; lreg2 -> -8,x 27CD ; ?temp -> -29,x 27CD ; milliseconds -> -25,x 27CD ; seconds -> -23,x 27CD ; minutes -> -22,x 27CD ; hours -> -21,x 27CD ; time -> -20,x 27CD ; remainder2 -> -16,x 27CD ; remainder1 -> -12,x 27CD _shellcmd_time:: 27CD 34 pshx 27CE B775 tfr s,x 27D0 1BF1DA leas -38,sp 27D3 ; 27D3 ; 27D3 ; 27D3 ; 27D3 ; void shellcmd_time(void) { 27D3 ; 27D3 ; // LOCAL VARIABLES 27D3 ; unsigned long int remainder1, remainder2, time; 27D3 ; char hours, minutes, seconds; 27D3 ; int milliseconds; 27D3 ; 27D3 ; 27D3 ; // get the current time, in milliseconds 27D3 ; time = get_sysTime(); 27D3 161D7D jsr _get_sysTime 27D6 19E1E3 leay -29,x 27D9 18021C40 movw -4,x,0,y 27DD 18021E42 movw -2,x,2,y 27E1 19E1E3 leay -29,x 27E4 1802401C movw 0,y,-4,x 27E8 1802421E movw 2,y,-2,x 27EC 19E1EC leay -20,x 27EF 18021C40 movw -4,x,0,y 27F3 18021E42 movw -2,x,2,y 27F7 ; 27F7 ; // convert to hh:mm:ss.ms 27F7 ; hours = time / mS_PER_HOUR; 27F7 19E1EC leay -20,x 27FA 1802401C movw 0,y,-4,x 27FE 1802421E movw 2,y,-2,x 2802 CD295F ldy #L213 2805 18024018 movw 0,y,-8,x 2809 1802421A movw 2,y,-6,x 280D 163C02 jsr __ludiv 2810 163B13 jsr __lreg2d 2813 6BE1EB stab -21,x 2816 ; remainder1 = time % mS_PER_HOUR; 2816 19E1EC leay -20,x 2819 1802401C movw 0,y,-4,x 281D 1802421E movw 2,y,-2,x 2821 CD295F ldy #L213 2824 18024018 movw 0,y,-8,x 2828 1802421A movw 2,y,-6,x 282C 163C20 jsr __lumod 282F 1914 leay -12,x 2831 18021C40 movw -4,x,0,y 2835 18021E42 movw -2,x,2,y 2839 ; minutes = remainder1 / mS_PER_MINUTE; 2839 1914 leay -12,x 283B 1802401C movw 0,y,-4,x 283F 1802421E movw 2,y,-2,x 2843 CD295B ldy #L214 2846 18024018 movw 0,y,-8,x 284A 1802421A movw 2,y,-6,x 284E 163C02 jsr __ludiv 2851 163B13 jsr __lreg2d 2854 6BE1EA stab -22,x 2857 ; remainder2 = remainder1 % mS_PER_MINUTE; 2857 1914 leay -12,x 2859 1802401C movw 0,y,-4,x 285D 1802421E movw 2,y,-2,x 2861 CD295B ldy #L214 2864 18024018 movw 0,y,-8,x 2868 1802421A movw 2,y,-6,x 286C 163C20 jsr __lumod 286F 1910 leay -16,x 2871 18021C40 movw -4,x,0,y 2875 18021E42 movw -2,x,2,y 2879 ; seconds = remainder2 / mS_PER_SECOND; 2879 1910 leay -16,x 287B 1802401C movw 0,y,-4,x 287F 1802421E movw 2,y,-2,x 2883 CD2957 ldy #L215 2886 18024018 movw 0,y,-8,x 288A 1802421A movw 2,y,-6,x 288E 163C02 jsr __ludiv 2891 163B13 jsr __lreg2d 2894 6BE1E9 stab -23,x 2897 ; milliseconds = remainder2 % mS_PER_SECOND; 2897 1910 leay -16,x 2899 1802401C movw 0,y,-4,x 289D 1802421E movw 2,y,-2,x 28A1 CD2957 ldy #L215 28A4 18024018 movw 0,y,-8,x 28A8 1802421A movw 2,y,-6,x 28AC 163C20 jsr __lumod 28AF 163B13 jsr __lreg2d 28B2 6CE1E7 std -25,x 28B5 ; 28B5 ; printf(" %d:%d:%d.%d\n", hours, minutes,seconds, milliseconds); 28B5 EDE1E7 ldy -25,x 28B8 6D86 sty 6,sp 28BA E6E1E9 ldab -23,x 28BD 87 clra 28BE 6C84 std 4,sp 28C0 E6E1EA ldab -22,x 28C3 87 clra 28C4 6C82 std 2,sp 28C6 E6E1EB ldab -21,x 28C9 87 clra 28CA 6C80 std 0,sp 28CC CC2949 ldd #L216 28CF 163DB2 jsr _printf 28D2 ; 28D2 ; } 28D2 L212: 28D2 B757 tfr x,s 28D4 30 pulx 28D5 .dbline 0 ; func end 28D5 3D rts 28D6 _shellcmd_freeMemCheck:: 28D6 34 pshx 28D7 B775 tfr s,x 28D9 1B9E leas -2,sp 28DB ; 28DB ; 28DB ; 28DB ; 28DB ; void shellcmd_freeMemCheck(void) { 28DB ; 28DB ; 28DB ; INTR_OFF(); 28DB 1410 sei 28DD 28DD ; printf("approximate free heap memory: %d bytes\n", get_free_memory()); 28DD 161E56 jsr _get_free_memory 28E0 6C80 std 0,sp 28E2 CC2921 ldd #L218 28E5 163DB2 jsr _printf 28E8 ; INTR_ON(); 28E8 10EF cli 28EA 28EA ; 28EA ; } 28EA L217: 28EA B757 tfr x,s 28EC 30 pulx 28ED .dbline 0 ; func end 28ED 3D rts 28EE ; onoff -> 2,x 28EE _shellcmd_kdb:: 28EE 3B pshd 28EF 34 pshx 28F0 B775 tfr s,x 28F2 ; 28F2 ; 28F2 ; 28F2 ; void shellcmd_kdb(int onoff) { 28F2 ; 28F2 ; 28F2 ; kdb_trace = onoff; 28F2 EC02 ldd 2,x 28F4 7B0206 stab _kdb_trace 28F7 ; 28F7 ; } 28F7 L219: 28F7 B757 tfr x,s 28F9 30 pulx 28FA 1B82 leas 2,sp 28FC .dbline 0 ; func end 28FC 3D rts 28FD _shellcmd_quitShell:: 28FD ; 28FD ; 28FD ; 28FD ; 28FD ; void shellcmd_quitShell(void) { 28FD ; 28FD ; puts("exiting shell"); 28FD CC2913 ldd #L221 2900 163D7A jsr _puts 2903 ; puts("\n"); 2903 CC2911 ldd #L222 2906 163D7A jsr _puts 2909 ; shellcmd_stopTask(get_task_id()); 2909 161521 jsr _get_task_id 290C 87 clra 290D 1627A0 jsr _shellcmd_stopTask 2910 ; 2910 ; } 2910 L220: 2910 .dbline 0 ; func end 2910 3D rts 2911 L222: 2911 0A00 .byte 10,0 2913 L221: 2913 65786974696E67207368656C6C00 .byte 'e,'x,'i,'t,'i,'n,'g,32,'s,'h,'e,'l,'l,0 2921 L218: 2921 617070726F78696D6174652066726565 .byte 'a,'p,'p,'r,'o,'x,'i,'m,'a,'t,'e,32,'f,'r,'e,'e 2931 2068656170206D656D6F72793A202564 .byte 32,'h,'e,'a,'p,32,'m,'e,'m,'o,'r,'y,58,32,37,'d 2941 2062797465730A00 .byte 32,'b,'y,'t,'e,'s,10,0 2949 L216: 2949 2025643A25643A25642E25640A00 .byte 32,37,'d,58,37,'d,58,37,'d,46,37,'d,10,0 2957 L215: 2957 000003E8 .word 0,1000 295B L214: 295B 0000EA60 .word 0,60000 295F L213: 295F 0036EE80 .word 54,61056 2963 L211: 2963 7461736B2025642073746F707065640A .byte 't,'a,'s,'k,32,37,'d,32,'s,'t,'o,'p,'p,'e,'d,10 2973 00 .byte 0 2974 L207: 2974 7461736B20256420737461727465640A .byte 't,'a,'s,'k,32,37,'d,32,'s,'t,'a,'r,'t,'e,'d,10 2984 00 .byte 0 2985 L203: 2985 7469636B733A20256C640A00 .byte 't,'i,'c,'k,'s,58,32,37,'l,'d,10,0 2991 L201: 2991 547970653A202573207C2049443A2025 .byte 'T,'y,'p,'e,58,32,37,'s,32,124,32,'I,'D,58,32,37 29A1 3264207C2053746174653A202578207C .byte 50,'d,32,124,32,'S,'t,'a,'t,'e,58,32,37,'x,32,124 29B1 204F776E65723A20253264207C205761 .byte 32,'O,'w,'n,'e,'r,58,32,37,50,'d,32,124,32,'W,'a 29C1 6974696E673A202564207C0A00 .byte 'i,'t,'i,'n,'g,58,32,37,'d,32,124,10,0 29CE L199: 29CE 4F776E65723A20302E2E31353D746173 .byte 'O,'w,'n,'e,'r,58,32,48,46,46,49,53,61,'t,'a,'s 29DE 6B2049442C202D313D6E6F626F647900 .byte 'k,32,'I,'D,44,32,45,49,61,'n,'o,'b,'o,'d,'y,0 29EE L198: 29EE 0A53746174653A20303D6E6F74627573 .byte 10,'S,'t,'a,'t,'e,58,32,48,61,'n,'o,'t,'b,'u,'s 29FE 792C20313D6275737900 .byte 'y,44,32,49,61,'b,'u,'s,'y,0 2A08 L197: 2A08 2D2D2D2D2D2D2D2D2D2D2D2B2D2D2D2D .byte 45,45,45,45,45,45,45,45,45,45,45,43,45,45,45,45 2A18 2D2D2D2D2B2D2D2D2D2D2D2D2D2D2D2B .byte 45,45,45,45,43,45,45,45,45,45,45,45,45,45,45,43 2A28 2D2D2D2D2D2D2D2D2D2D2D2B2D2D2D2D .byte 45,45,45,45,45,45,45,45,45,45,45,43,45,45,45,45 2A38 2D2D2D2D2D2D2D2D2B00 .byte 45,45,45,45,45,45,45,45,43,0 2A42 L176: 2A42 4D6573736167653A205B206269743720 .byte 'M,'e,'s,'s,'a,'g,'e,58,32,91,32,'b,'i,'t,55,32 2A52 7C2062697436207C2062697435207C20 .byte 124,32,'b,'i,'t,54,32,124,32,'b,'i,'t,53,32,124,32 2A62 62697434207C2062697433207C206269 .byte 'b,'i,'t,52,32,124,32,'b,'i,'t,51,32,124,32,'b,'i 2A72 7432207C207072696F207C2073746174 .byte 't,50,32,124,32,'p,'r,'i,'o,32,124,32,'s,'t,'a,'t 2A82 65205D00 .byte 'e,32,93,0 2A86 L175: 2A86 0A53746174653A20303D69646C652C20 .byte 10,'S,'t,'a,'t,'e,58,32,48,61,'i,'d,'l,'e,44,32 2A96 313D70656E64696E672C20323D72756E .byte 49,61,'p,'e,'n,'d,'i,'n,'g,44,32,50,61,'r,'u,'n 2AA6 6E696E672C20333D77616974696E672C .byte 'n,'i,'n,'g,44,32,51,61,'w,'a,'i,'t,'i,'n,'g,44 2AB6 20343D73746F7070656400 .byte 32,52,61,'s,'t,'o,'p,'p,'e,'d,0 2AC1 L174: 2AC1 4E616D653A20253873207C2049443A20 .byte 'N,'a,'m,'e,58,32,37,56,'s,32,124,32,'I,'D,58,32 2AD1 2564207C2053746174653A202564207C .byte 37,'d,32,124,32,'S,'t,'a,'t,'e,58,32,37,'d,32,124 2AE1 205072696F3A20253364207C20416464 .byte 32,'P,'r,'i,'o,58,32,37,51,'d,32,124,32,'A,'d,'d 2AF1 723A20253478207C204D7367733A2030 .byte 'r,58,32,37,52,'x,32,124,32,'M,'s,'g,'s,58,32,48 2B01 78253278207C0A00 .byte 'x,37,50,'x,32,124,10,0 2B09 L173: 2B09 2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2B .byte 45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,43 2B19 2D2D2D2D2D2D2D2B2D2D2D2D2D2D2D2D .byte 45,45,45,45,45,45,45,43,45,45,45,45,45,45,45,45 2B29 2D2D2B2D2D2D2D2D2D2D2D2D2D2D2B2D .byte 45,45,43,45,45,45,45,45,45,45,45,45,45,45,43,45 2B39 2D2D2D2D2D2D2D2D2D2D2D2B2D2D2D2D .byte 45,45,45,45,45,45,45,45,45,45,45,43,45,45,45,45 2B49 2D2D2D2D2D2D2D2D2B00 .byte 45,45,45,45,45,45,45,45,43,0 2B53 L166: 2B53 0A5461736B20436F6E74726F6C20426C .byte 10,'T,'a,'s,'k,32,'C,'o,'n,'t,'r,'o,'l,32,'B,'l 2B63 6F636B3A00 .byte 'o,'c,'k,58,0 2B68 L106: 2B68 2D6200 .byte 45,'b,0 2B6B L88: 2B6B 71756974202D2D207175697420746865 .byte 'q,'u,'i,'t,32,45,45,32,'q,'u,'i,'t,32,'t,'h,'e 2B7B 207368656C6C20286361726566756C6C .byte 32,'s,'h,'e,'l,'l,32,40,'c,'a,'r,'e,'f,'u,'l,'l 2B8B 212900 .byte 33,41,0 2B8E L87: 2B8E 6B6462205B317C305D202D2D20747572 .byte 'k,'d,'b,32,91,49,124,48,93,32,45,45,32,'t,'u,'r 2B9E 6E206B65726E656C206465627567206F .byte 'n,32,'k,'e,'r,'n,'e,'l,32,'d,'e,'b,'u,'g,32,'o 2BAE 6E2F6F666600 .byte 'n,47,'o,'f,'f,0 2BB4 L86: 2BB4 667265656D656D202D2D206765742061 .byte 'f,'r,'e,'e,'m,'e,'m,32,45,45,32,'g,'e,'t,32,'a 2BC4 7070726F78696D617465206672656520 .byte 'p,'p,'r,'o,'x,'i,'m,'a,'t,'e,32,'f,'r,'e,'e,32 2BD4 52414D20737061636500 .byte 'R,'A,'M,32,'s,'p,'a,'c,'e,0 2BDE L85: 2BDE 74696D65205B3C6872733E203C6D696E .byte 't,'i,'m,'e,32,91,60,'h,'r,'s,62,32,60,'m,'i,'n 2BEE 3E203C7365633E205D2D2D2064697370 .byte 62,32,60,'s,'e,'c,62,32,93,45,45,32,'d,'i,'s,'p 2BFE 6C61792F736574207468652063757272 .byte 'l,'a,'y,47,'s,'e,'t,32,'t,'h,'e,32,'c,'u,'r,'r 2C0E 656E742073797374656D2074696D6500 .byte 'e,'n,'t,32,'s,'y,'s,'t,'e,'m,32,'t,'i,'m,'e,0 2C1E L84: 2C1E 7072696F72697479203C7461736B5F69 .byte 'p,'r,'i,'o,'r,'i,'t,'y,32,60,'t,'a,'s,'k,95,'i 2C2E 643E2C203C7461736B5F7072696F7269 .byte 'd,62,44,32,60,'t,'a,'s,'k,95,'p,'r,'i,'o,'r,'i 2C3E 74793E20202D2D206368616E67652070 .byte 't,'y,62,32,32,45,45,32,'c,'h,'a,'n,'g,'e,32,'p 2C4E 72696F00 .byte 'r,'i,'o,0 2C52 L83: 2C52 73746F70203C7461736B5F69643E2020 .byte 's,'t,'o,'p,32,60,'t,'a,'s,'k,95,'i,'d,62,32,32 2C62 2D2D2073746F702061207461736B00 .byte 45,45,32,'s,'t,'o,'p,32,'a,32,'t,'a,'s,'k,0 2C71 L82: 2C71 7374617274203C7461736B5F69643E20 .byte 's,'t,'a,'r,'t,32,60,'t,'a,'s,'k,95,'i,'d,62,32 2C81 2D2D2073746172742061207461736B00 .byte 45,45,32,'s,'t,'a,'r,'t,32,'a,32,'t,'a,'s,'k,0 2C91 L81: 2C91 7469636B73202D2D2073686F77732073 .byte 't,'i,'c,'k,'s,32,45,45,32,'s,'h,'o,'w,'s,32,'s 2CA1 797374656D207469636B00 .byte 'y,'s,'t,'e,'m,32,'t,'i,'c,'k,0 2CAC L80: 2CAC 6D6362205B5B7461736B5F69645D207C .byte 'm,'c,'b,32,91,91,'t,'a,'s,'k,95,'i,'d,93,32,124 2CBC 205B2D625D5D202D2D207072696E7473 .byte 32,91,45,'b,93,93,32,45,45,32,'p,'r,'i,'n,'t,'s 2CCC 206D7574657820636F6E74726F6C2062 .byte 32,'m,'u,'t,'e,'x,32,'c,'o,'n,'t,'r,'o,'l,32,'b 2CDC 6C6F636B00 .byte 'l,'o,'c,'k,0 2CE1 L79: 2CE1 746362205B7461736B5F69645D202D2D .byte 't,'c,'b,32,91,'t,'a,'s,'k,95,'i,'d,93,32,45,45 2CF1 207072696E7473207461736B20636F6E .byte 32,'p,'r,'i,'n,'t,'s,32,'t,'a,'s,'k,32,'c,'o,'n 2D01 74726F6C20626C6F636B00 .byte 't,'r,'o,'l,32,'b,'l,'o,'c,'k,0 2D0C L78: 2D0C 68656C70205B636D645D202D2D206865 .byte 'h,'e,'l,'p,32,91,'c,'m,'d,93,32,45,45,32,'h,'e 2D1C 6C70206F6E2061207370656369666963 .byte 'l,'p,32,'o,'n,32,'a,32,'s,'p,'e,'c,'i,'f,'i,'c 2D2C 20636F6D6D616E6400 .byte 32,'c,'o,'m,'m,'a,'n,'d,0 2D35 L77: 2D35 5B5D202D2D206F7074696F6E616C2061 .byte 91,93,32,45,45,32,'o,'p,'t,'i,'o,'n,'a,'l,32,'a 2D45 7267756D656E74730A00 .byte 'r,'g,'u,'m,'e,'n,'t,'s,10,0 2D4F L76: 2D4F 3C3E202D2D2072657175697265642061 .byte 60,62,32,45,45,32,'r,'e,'q,'u,'i,'r,'e,'d,32,'a 2D5F 7267756D656E747300 .byte 'r,'g,'u,'m,'e,'n,'t,'s,0 2D68 L75: 2D68 2D2D2D48454C502D2D2D0A00 .byte 45,45,45,'H,'E,'L,'P,45,45,45,10,0 2D74 L66: 2D74 7175697400 .byte 'q,'u,'i,'t,0 2D79 L63: 2D79 6B646200 .byte 'k,'d,'b,0 2D7D L60: 2D7D 667265656D656D00 .byte 'f,'r,'e,'e,'m,'e,'m,0 2D85 L57: 2D85 74696D6500 .byte 't,'i,'m,'e,0 2D8A L54: 2D8A 7072696F7269747900 .byte 'p,'r,'i,'o,'r,'i,'t,'y,0 2D93 L51: 2D93 73746F7000 .byte 's,'t,'o,'p,0 2D98 L48: 2D98 737461727400 .byte 's,'t,'a,'r,'t,0 2D9E L45: 2D9E 7469636B7300 .byte 't,'i,'c,'k,'s,0 2DA4 L42: 2DA4 6D636200 .byte 'm,'c,'b,0 2DA8 L39: 2DA8 74636200 .byte 't,'c,'b,0 2DAC L36: 2DAC 68656C7000 .byte 'h,'e,'l,'p,0 .module sysInit.c .area text ; id -> -2,x 2DB1 _sysInit:: 2DB1 34 pshx 2DB2 B775 tfr s,x 2DB4 1B96 leas -10,sp 2DB6 ; // sysInit.c 2DB6 ; 2DB6 ; #include <912d60.h> 2DB6 ; #include 2DB6 ; #include "kernel.h" 2DB6 ; 2DB6 ; 2DB6 ; 2DB6 ; // TASK PROTOTYPES 2DB6 ; int task1(void); 2DB6 ; int task2(void); 2DB6 ; 2DB6 ; 2DB6 ; 2DB6 ; 2DB6 ; int sysInit(void) { 2DB6 ; 2DB6 ; // LOCAL VARIABLES 2DB6 ; int id; 2DB6 ; 2DB6 ; 2DB6 ; /* must create all the tasks without interrupt, because this task 2DB6 ; will die when it finishes. */ 2DB6 ; //INTR_OFF(); 2DB6 ; 2DB6 ; 2DB6 ; // set up the serial port 2DB6 ; //setbaud(BAUD38K); // actually running at 19K baud due to xtal speed 2DB6 ; 2DB6 ; // any additional user setup goes here 2DB6 ; //---------------------------------------- 2DB6 ; //| | 2DB6 ; //---------------------------------------- 2DB6 ; 2DB6 ; 2DB6 ; 2DB6 ; // create task1 2DB6 ; if (create_task("dummy", &task1, 18, IDLE, 0) < 0) 2DB6 CC0000 ldd #0 2DB9 6C86 std 6,sp 2DBB CC0000 ldd #0 2DBE 6C84 std 4,sp 2DC0 CC0012 ldd #18 2DC3 6C82 std 2,sp 2DC5 CC2E5B ldd #_task1 2DC8 6C80 std 0,sp 2DCA CC2E51 ldd #L6 2DCD 161827 jsr _create_task 2DD0 8C0000 cpd #0 2DD3 2C06 bge L4 2DD5 ; puts("task1 failure"); 2DD5 CC2E43 ldd #L7 2DD8 163D7A jsr _puts 2DDB L4: 2DDB ; 2DDB ; 2DDB ; // create task2 2DDB ; if (create_task("timer", &task2, 0, STOPPED, 255) < 0) 2DDB CC00FF ldd #255 2DDE 6C86 std 6,sp 2DE0 CC0004 ldd #4 2DE3 6C84 std 4,sp 2DE5 CC0000 ldd #0 2DE8 6C82 std 2,sp 2DEA CC2F08 ldd #_task2 2DED 6C80 std 0,sp 2DEF CC2E3D ldd #L10 2DF2 161827 jsr _create_task 2DF5 8C0000 cpd #0 2DF8 2C06 bge L8 2DFA ; puts("task2 failure"); 2DFA CC2E2F ldd #L11 2DFD 163D7A jsr _puts 2E00 L8: 2E00 ; 2E00 ; 2E00 ; // create the COM2 mutex 2E00 ; if (create_mutex(COM2, "COM2") < 0) 2E00 CC2E2A ldd #L14 2E03 6C80 std 0,sp 2E05 CC0004 ldd #4 2E08 161A9E jsr _create_mutex 2E0B 8C0000 cpd #0 2E0E 2C06 bge L12 2E10 ; puts("COM1 failure"); 2E10 CC2E1D ldd #L15 2E13 163D7A jsr _puts 2E16 L12: 2E16 ; 2E16 ; 2E16 ; return 0; 2E16 CC0000 ldd #0 2E19 L3: 2E19 B757 tfr x,s 2E1B 30 pulx 2E1C .dbline 0 ; func end 2E1C 3D rts 2E1D L15: 2E1D 434F4D31206661696C75726500 .byte 'C,'O,'M,49,32,'f,'a,'i,'l,'u,'r,'e,0 2E2A L14: 2E2A 434F4D3200 .byte 'C,'O,'M,50,0 2E2F L11: 2E2F 7461736B32206661696C75726500 .byte 't,'a,'s,'k,50,32,'f,'a,'i,'l,'u,'r,'e,0 2E3D L10: 2E3D 74696D657200 .byte 't,'i,'m,'e,'r,0 2E43 L7: 2E43 7461736B31206661696C75726500 .byte 't,'a,'s,'k,49,32,'f,'a,'i,'l,'u,'r,'e,0 2E51 L6: 2E51 64756D6D7900 .byte 'd,'u,'m,'m,'y,0 .module idleTask.c .area text 2E57 _idleTask:: 2E57 ; // idleTask.c 2E57 ; 2E57 ; #include <912D60.h> 2E57 ; #include "kernel.h" 2E57 ; 2E57 ; 2E57 ; 2E57 ; int idleTask(void) { 2E57 ; 2E57 ; // will eventually put cpu into low-power mode 2E57 ; return 0; 2E57 CC0000 ldd #0 2E5A L3: 2E5A .dbline 0 ; func end 2E5A 3D rts .module task1.c .area text ; i -> -2,x 2E5B _task1:: 2E5B 34 pshx 2E5C B775 tfr s,x 2E5E 1B9E leas -2,sp 2E60 ; // task1.c 2E60 ; 2E60 ; #include 2E60 ; #include <912d60.h> 2E60 ; #include "kernel.h" 2E60 ; 2E60 ; 2E60 ; 2E60 ; /* dummy task to eat up time, and to give the kernel 2E60 ; something to multitask with */ 2E60 ; int task1 (void) { 2E60 ; 2E60 ; int i; 2E60 ; 2E60 ; get_mutex(COM1); 2E60 CC0003 ldd #3 2E63 161BB6 jsr _get_mutex 2E66 ; INTR_ON(); 2E66 10EF cli 2E68 2E68 ; 2E68 ; 2E68 ; puts("T1 Starting"); 2E68 CC2EFC ldd #L4 2E6B 163D7A jsr _puts 2E6E CC0000 ldd #0 2E71 6C1E std -2,x 2E73 L5: 2E73 L6: 2E73 ; for (i=0; i<0x0800; i++); 2E73 EC1E ldd -2,x 2E75 C30001 addd #1 2E78 6C1E std -2,x 2E7A EC1E ldd -2,x 2E7C 8C0800 cpd #2048 2E7F 2DF2 blt L5 2E81 ; puts("T1.1"); 2E81 CC2EF7 ldd #L9 2E84 163D7A jsr _puts 2E87 CC0000 ldd #0 2E8A 6C1E std -2,x 2E8C L10: 2E8C L11: 2E8C ; 2E8C ; for (i=0; i<0x1000; i++); 2E8C EC1E ldd -2,x 2E8E C30001 addd #1 2E91 6C1E std -2,x 2E93 EC1E ldd -2,x 2E95 8C1000 cpd #4096 2E98 2DF2 blt L10 2E9A ; puts("T1.2"); 2E9A CC2EF2 ldd #L14 2E9D 163D7A jsr _puts 2EA0 CC0000 ldd #0 2EA3 6C1E std -2,x 2EA5 L15: 2EA5 L16: 2EA5 ; 2EA5 ; for (i=0; i<0x1A00; i++); 2EA5 EC1E ldd -2,x 2EA7 C30001 addd #1 2EAA 6C1E std -2,x 2EAC EC1E ldd -2,x 2EAE 8C1A00 cpd #6656 2EB1 2DF2 blt L15 2EB3 ; puts("T1.3"); 2EB3 CC2EED ldd #L19 2EB6 163D7A jsr _puts 2EB9 CC0000 ldd #0 2EBC 6C1E std -2,x 2EBE L20: 2EBE L21: 2EBE ; 2EBE ; for (i=0; i<0x2000; i++); 2EBE EC1E ldd -2,x 2EC0 C30001 addd #1 2EC3 6C1E std -2,x 2EC5 EC1E ldd -2,x 2EC7 8C2000 cpd #8192 2ECA 2DF2 blt L20 2ECC ; puts("T1 Finished"); 2ECC CC2EE1 ldd #L24 2ECF 163D7A jsr _puts 2ED2 ; 2ED2 ; 2ED2 ; 2ED2 ; INTR_OFF(); 2ED2 1410 sei 2ED4 2ED4 ; give_mutex(COM1); 2ED4 CC0003 ldd #3 2ED7 161CB2 jsr _give_mutex 2EDA ; 2EDA ; return 0; 2EDA CC0000 ldd #0 2EDD L3: 2EDD B757 tfr x,s 2EDF 30 pulx 2EE0 .dbline 0 ; func end 2EE0 3D rts 2EE1 L24: 2EE1 54312046696E697368656400 .byte 'T,49,32,'F,'i,'n,'i,'s,'h,'e,'d,0 2EED L19: 2EED 54312E3300 .byte 'T,49,46,51,0 2EF2 L14: 2EF2 54312E3200 .byte 'T,49,46,50,0 2EF7 L9: 2EF7 54312E3100 .byte 'T,49,46,49,0 2EFC L4: 2EFC 5431205374617274696E6700 .byte 'T,49,32,'S,'t,'a,'r,'t,'i,'n,'g,0 .module task2.c .area data --- 0000 L4: --- 0000 .blkb 1 .area idata --- 0000 00 .byte 0 .area data --- 0001 L5: --- 0001 .blkb 1 .area idata --- 0001 00 .byte 0 .area data --- 0002 L6: --- 0002 .blkb 1 .area idata --- 0002 00 .byte 0 .area data --- 0003 L7: --- 0003 .blkb 1 .area idata --- 0003 00 .byte 0 .area data --- 0004 L8: --- 0004 .blkb 1 .area idata --- 0004 00 .byte 0 .area data --- 0005 L9: --- 0005 .blkb 1 .area idata --- 0005 00 .byte 0 .area data --- 0006 L10: --- 0006 .blkb 1 .area idata --- 0006 00 .byte 0 .area data .area bss --- 0000 L11: --- 0000 .blkb 4 .area data --- 0007 L12: --- 0007 .blkb 1 .area idata --- 0007 01 .byte 1 .area data .area text ; lreg1 -> -4,x ; lreg2 -> -8,x ; delta_t -> -15,x ; redraw -> -11,x ; i -> -9,x 2F08 _task2:: 2F08 34 pshx 2F09 B775 tfr s,x 2F0B 1B90 leas -16,sp 2F0D ; // task2.c 2F0D ; 2F0D ; #include 2F0D ; #include <912d60.h> 2F0D ; #include "kernel.h" 2F0D ; 2F0D ; 2F0D ; 2F0D ; /* counts seconds and displays them */ 2F0D ; int task2 (void) { 2F0D ; 2F0D ; 2F0D ; char i; 2F0D ; unsigned long int delta_t; 2F0D ; extern unsigned long int time_tick; 2F0D ; 2F0D ; 2F0D ; static unsigned char hh=0, hm=0, hl=0, mh=0, ml=0, sh=0, sl=0; 2F0D ; static unsigned long int last_mark; 2F0D ; int redraw; 2F0D ; static char startup = 1; 2F0D ; 2F0D ; 2F0D ; INTR_ON(); 2F0D 10EF cli 2F0F 2F0F ; 2F0F ; 2F0F ; 2F0F ; delta_t = (time_tick - last_mark) * uS_PER_TIME_TICK; 2F0F CD022C ldy #_time_tick 2F12 1802401C movw 0,y,-4,x 2F16 1802421E movw 2,y,-2,x 2F1A CD0248 ldy #L11 2F1D 18024018 movw 0,y,-8,x 2F21 1802421A movw 2,y,-6,x 2F25 163B51 jsr __lsub 2F28 18021E1A movw -2,x,-6,x 2F2C 18021C18 movw -4,x,-8,x 2F30 CD3157 ldy #L13 2F33 1802401C movw 0,y,-4,x 2F37 1802421E movw 2,y,-2,x 2F3B 163B62 jsr __lmul 2F3E 1911 leay -15,x 2F40 18021C40 movw -4,x,0,y 2F44 18021E42 movw -2,x,2,y 2F48 ; 2F48 ; if (delta_t > uS_PER_SECOND) { 2F48 1911 leay -15,x 2F4A 1802401C movw 0,y,-4,x 2F4E 1802421E movw 2,y,-2,x 2F52 CD3153 ldy #L16 2F55 18024018 movw 0,y,-8,x 2F59 1802421A movw 2,y,-6,x 2F5D 163CE1 jsr __lcmp 2F60 182301E6 lbls L14 2F64 ; last_mark = time_tick; 2F64 CD022C ldy #_time_tick 2F67 1802401C movw 0,y,-4,x 2F6B 1802421E movw 2,y,-2,x 2F6F CD0248 ldy #L11 2F72 18021C40 movw -4,x,0,y 2F76 18021E42 movw -2,x,2,y 2F7A ; sl++; 2F7A F60210 ldab L10 2F7D 87 clra 2F7E C30001 addd #1 2F81 7B0210 stab L10 2F84 ; redraw = 1; 2F84 CC0001 ldd #1 2F87 6C15 std -11,x 2F89 ; if (sl > 9) { 2F89 F60210 ldab L10 2F8C C109 cmpb #9 2F8E 2312 bls L17 2F90 ; sh++; 2F90 F6020F ldab L9 2F93 87 clra 2F94 C30001 addd #1 2F97 7B020F stab L9 2F9A ; sl = 0; 2F9A 790210 clr L10 2F9D ; redraw = 2; 2F9D CC0002 ldd #2 2FA0 6C15 std -11,x 2FA2 ; } 2FA2 L17: 2FA2 ; if (sh > 5) { 2FA2 F6020F ldab L9 2FA5 C105 cmpb #5 2FA7 2312 bls L19 2FA9 ; ml++; 2FA9 F6020E ldab L8 2FAC 87 clra 2FAD C30001 addd #1 2FB0 7B020E stab L8 2FB3 ; sh = 0; 2FB3 79020F clr L9 2FB6 ; redraw = 4; 2FB6 CC0004 ldd #4 2FB9 6C15 std -11,x 2FBB ; } 2FBB L19: 2FBB ; if (ml > 9) { 2FBB F6020E ldab L8 2FBE C109 cmpb #9 2FC0 2312 bls L21 2FC2 ; mh++; 2FC2 F6020D ldab L7 2FC5 87 clra 2FC6 C30001 addd #1 2FC9 7B020D stab L7 2FCC ; ml = 0; 2FCC 79020E clr L8 2FCF ; redraw = 5; 2FCF CC0005 ldd #5 2FD2 6C15 std -11,x 2FD4 ; } 2FD4 L21: 2FD4 ; if (mh > 5) { 2FD4 F6020D ldab L7 2FD7 C105 cmpb #5 2FD9 2312 bls L23 2FDB ; hl++; 2FDB F6020C ldab L6 2FDE 87 clra 2FDF C30001 addd #1 2FE2 7B020C stab L6 2FE5 ; mh = 0; 2FE5 79020D clr L7 2FE8 ; redraw = 7; 2FE8 CC0007 ldd #7 2FEB 6C15 std -11,x 2FED ; } 2FED L23: 2FED ; if (hl > 9) { 2FED F6020C ldab L6 2FF0 C109 cmpb #9 2FF2 2312 bls L25 2FF4 ; hm++; 2FF4 F6020B ldab L5 2FF7 87 clra 2FF8 C30001 addd #1 2FFB 7B020B stab L5 2FFE ; hl = 0; 2FFE 79020C clr L6 3001 ; redraw = 8; 3001 CC0008 ldd #8 3004 6C15 std -11,x 3006 ; } 3006 L25: 3006 ; if (hm > 9) { 3006 F6020B ldab L5 3009 C109 cmpb #9 300B 2312 bls L27 300D ; hh++; 300D F6020A ldab L4 3010 87 clra 3011 C30001 addd #1 3014 7B020A stab L4 3017 ; hm = 0; 3017 79020B clr L5 301A ; redraw = 9; 301A CC0009 ldd #9 301D 6C15 std -11,x 301F ; } 301F L27: 301F ; if (hh > 9) { 301F F6020A ldab L4 3022 C109 cmpb #9 3024 2308 bls L29 3026 ; hh = 0; 3026 79020A clr L4 3029 ; redraw = 9; 3029 CC0009 ldd #9 302C 6C15 std -11,x 302E ; } 302E L29: 302E ; 302E ; 302E ; // display time 302E ; if (startup) { 302E F70211 tst L12 3031 2760 beq L31 3033 ; putchar(hh+48); 3033 F6020A ldab L4 3036 87 clra 3037 C30030 addd #48 303A 87 clra 303B 1637EF jsr _putchar 303E ; putchar(hm+48); 303E F6020B ldab L5 3041 87 clra 3042 C30030 addd #48 3045 87 clra 3046 1637EF jsr _putchar 3049 ; putchar(hl+48); 3049 F6020C ldab L6 304C 87 clra 304D C30030 addd #48 3050 87 clra 3051 1637EF jsr _putchar 3054 ; putchar(':'); 3054 CC003A ldd #58 3057 1637EF jsr _putchar 305A ; putchar(mh+48); 305A F6020D ldab L7 305D 87 clra 305E C30030 addd #48 3061 87 clra 3062 1637EF jsr _putchar 3065 ; putchar(ml+48); 3065 F6020E ldab L8 3068 87 clra 3069 C30030 addd #48 306C 87 clra 306D 1637EF jsr _putchar 3070 ; putchar(':'); 3070 CC003A ldd #58 3073 1637EF jsr _putchar 3076 ; putchar(sh+48); 3076 F6020F ldab L9 3079 87 clra 307A C30030 addd #48 307D 87 clra 307E 1637EF jsr _putchar 3081 ; putchar(sl+48); 3081 F60210 ldab L10 3084 87 clra 3085 C30030 addd #48 3088 87 clra 3089 1637EF jsr _putchar 308C ; 308C ; startup = 0; 308C 790211 clr L12 308F ; } 308F 182000B7 lbra L32 3093 L31: 3093 ; else { 3093 ; for (i=0; i 315B ; #include <912D60.h> 315B ; #include "kernel.h" 315B ; 315B ; 315B ; 315B ; // FUNCTION PROTOTYPES 315B ; void _start(void); 315B ; 315B ; 315B ; 315B ; /* Example code flow for all of these handlers: 315B ; 315B ; // IF interrupt isn't very time critical: 315B ; figure out who cares, if anyone, then send a msg to the caring task 315B ; 315B ; 315B ; if (resource[ADC].owner != 255) 315B ; task[resource[ADC].owner].message |= ADC_MSG; 315B ; 315B ; 315B ; 315B ; // IF interrupt is time critical: (ie, there's data that needs to be serviced) 315B ; get the data, put it in a buffer, then put the data in the message buffer 315B ; 315B ; task[resource[ADC].owner].message_data[ADC_MSG] = ADC; // ADC = correct port definition? 315B ; */ 315B ; 315B ; 315B ; 315B ; 315B ; 315B ; // GLOBALS 315B ; extern unsigned int interrupt_flags_ADC; 315B ; extern unsigned int interrupt_flags_TC; 315B ; 315B ; 315B ; 315B ; 315B ; 315B ; #pragma interrupt_handler MDCOF_handler() 315B ; 315B ; void MDCOF_handler(void) { 315B ; 315B ; /*// LOCAL VARIABLES 315B ; extern unsigned long int time_tick; 315B ; 315B ; // acknowledge the interrupt, incriment global time_tick 315B ; MCFLG = 0x80; 315B ; time_tick++; 315B ; */ 315B ; 315B ; } 315B L3: 315B .dbline 0 ; func end 315B 0B rti 315C _KWU_handler:: 315C ; 315C ; 315C ; 315C ; #pragma interrupt_handler KWU_handler() 315C ; 315C ; void KWU_handler(void) {} 315C L4: 315C .dbline 0 ; func end 315C 0B rti 315D _ADC_handler:: 315D ; 315D ; 315D ; 315D ; #pragma interrupt_handler ADC_handler() 315D ; 315D ; void ADC_handler(void) {} 315D L5: 315D .dbline 0 ; func end 315D 0B rti 315E _SCI1_handler:: 315E ; 315E ; 315E ; 315E ; /* #pragma interrupt_handler SCI0_handler() 315E ; 315E ; void SCI0_handler(void) { 315E ; 315E ; 315E ; 315E ; } */ 315E ; 315E ; 315E ; 315E ; #pragma interrupt_handler SCI1_handler() 315E ; 315E ; void SCI1_handler(void) {} 315E L6: 315E .dbline 0 ; func end 315E 0B rti 315F _SPI_handler:: 315F ; 315F ; 315F ; 315F ; #pragma interrupt_handler SPI_handler() 315F ; 315F ; void SPI_handler(void) {} 315F L7: 315F .dbline 0 ; func end 315F 0B rti 3160 _PAIE_handler:: 3160 ; 3160 ; 3160 ; 3160 ; #pragma interrupt_handler PAIE_handler() 3160 ; 3160 ; void PAIE_handler(void) {} 3160 L8: 3160 .dbline 0 ; func end 3160 0B rti 3161 _PAO_handler:: 3161 ; 3161 ; 3161 ; 3161 ; #pragma interrupt_handler PAO_handler() 3161 ; 3161 ; void PAO_handler(void) {} 3161 L9: 3161 .dbline 0 ; func end 3161 0B rti 3162 ; lreg1 -> -4,x 3162 ; lreg2 -> -8,x 3162 _TOF_handler:: 3162 34 pshx 3163 B775 tfr s,x 3165 1B98 leas -8,sp 3167 ; 3167 ; 3167 ; 3167 ; #pragma interrupt_handler TOF_handler() 3167 ; 3167 ; void TOF_handler(void) { 3167 ; 3167 ; // LOCAL VARIABLES 3167 ; extern unsigned long int time_tick; 3167 ; 3167 ; // acknowledge the interrupt, incriment global time_tick 3167 ; TFLG2 = 0x80; 3167 C680 ldab #128 3169 7B008F stab 0x8f 316C ; time_tick++; 316C CD022C ldy #_time_tick 316F 1802401C movw 0,y,-4,x 3173 1802421E movw 2,y,-2,x 3177 CD31B5 ldy #L11 317A 18024018 movw 0,y,-8,x 317E 1802421A movw 2,y,-6,x 3182 163B40 jsr __ladd 3185 CD022C ldy #_time_tick 3188 18021C40 movw -4,x,0,y 318C 18021E42 movw -2,x,2,y 3190 ; 3190 ; } 3190 L10: 3190 B757 tfr x,s 3192 30 pulx 3193 .dbline 0 ; func end 3193 0B rti 3194 _TC7_handler:: 3194 ; 3194 ; 3194 ; 3194 ; #pragma interrupt_handler TC7_handler() 3194 ; 3194 ; void TC7_handler(void) {} 3194 L12: 3194 .dbline 0 ; func end 3194 0B rti 3195 _TC6_handler:: 3195 ; 3195 ; 3195 ; 3195 ; #pragma interrupt_handler TC6_handler() 3195 ; 3195 ; void TC6_handler(void) {} 3195 L13: 3195 .dbline 0 ; func end 3195 0B rti 3196 _TC5_handler:: 3196 ; 3196 ; 3196 ; 3196 ; #pragma interrupt_handler TC5_handler() 3196 ; 3196 ; void TC5_handler(void) {} 3196 L14: 3196 .dbline 0 ; func end 3196 0B rti 3197 _TC4_handler:: 3197 ; 3197 ; 3197 ; 3197 ; #pragma interrupt_handler TC4_handler() 3197 ; 3197 ; void TC4_handler(void) {} 3197 L15: 3197 .dbline 0 ; func end 3197 0B rti 3198 _TC3_handler:: 3198 ; 3198 ; 3198 ; 3198 ; #pragma interrupt_handler TC3_handler() 3198 ; 3198 ; void TC3_handler(void) {} 3198 L16: 3198 .dbline 0 ; func end 3198 0B rti 3199 _TC2_handler:: 3199 ; 3199 ; 3199 ; 3199 ; #pragma interrupt_handler TC2_handler() 3199 ; 3199 ; void TC2_handler(void) {} 3199 L17: 3199 .dbline 0 ; func end 3199 0B rti 319A _TC1_handler:: 319A ; 319A ; 319A ; 319A ; #pragma interrupt_handler TC1_handler() 319A ; 319A ; void TC1_handler(void) {} 319A L18: 319A .dbline 0 ; func end 319A 0B rti 319B _TC0_handler:: 319B ; 319B ; 319B ; 319B ; #pragma interrupt_handler TC0_handler() 319B ; 319B ; void TC0_handler(void) {} 319B L19: 319B .dbline 0 ; func end 319B 0B rti 319C _IRQ_handler:: 319C ; 319C ; 319C ; 319C ; #pragma interrupt_handler IRQ_handler() 319C ; 319C ; void IRQ_handler(void) {} 319C L20: 319C .dbline 0 ; func end 319C 0B rti 319D _XIRQ_handler:: 319D ; 319D ; 319D ; 319D ; #pragma interrupt_handler XIRQ_handler() 319D ; 319D ; void XIRQ_handler(void) {} 319D L21: 319D .dbline 0 ; func end 319D 0B rti 319E _SWI_handler:: 319E ; 319E ; 319E ; 319E ; #pragma interrupt_handler SWI_handler() 319E ; 319E ; void SWI_handler(void) {} 319E L22: 319E .dbline 0 ; func end 319E 0B rti 319F _COP_handler:: 319F ; 319F ; 319F ; 319F ; #pragma interrupt_handler COP_handler() 319F ; 319F ; void COP_handler(void) { 319F ; 319F ; puts("COP RESET!"); 319F CC31AA ldd #L24 31A2 163D7A jsr _puts 31A5 ; _start(); 31A5 161000 jsr __start 31A8 ; 31A8 ; } 31A8 L23: 31A8 .dbline 0 ; func end 31A8 0B rti 31A9 _CLM_handler:: 31A9 ; 31A9 ; 31A9 ; 31A9 ; #pragma interrupt_handler CLM_handler() 31A9 ; 31A9 ; void CLM_handler(void) {} 31A9 L25: 31A9 .dbline 0 ; func end 31A9 0B rti 31AA L24: 31AA 434F502052455345542100 .byte 'C,'O,'P,32,'R,'E,'S,'E,'T,33,0 31B5 L11: 31B5 00000001 .word 0,1 .module _HC12Setup.c .area text 31B9 __HC12Setup:: 31B9 ; // _HC12Setup.c 31B9 ; 31B9 ; #include <912d60.h> 31B9 ; #include "kernel.h" 31B9 ; 31B9 ; 31B9 ; 31B9 ; void _HC12Setup(void) { 31B9 ; 31B9 ; 31B9 ; // set the register base 31B9 ; //*(volatile unsigned char *)0x0011 = 0x08; 31B9 ; 31B9 ; // set up the SYSTEM CLOCKS 31B9 ; //SLOW = 0x00; // don't slow the RTI/COP clocks down 31B9 ; 31B9 ; 31B9 ; // set up the RTI INTERRUPT 31B9 ; INTR_OFF(); // disable/mask all maskable interrupts 31B9 1410 sei 31BB 31BB ; RTICTL = 0x86; // enable RTI at 65.536 miliseconds 31BB C686 ldab #134 31BD 7B0014 stab 0x14 31C0 ; //RTICTL = 0x85; // enable RTI at 32.768 miliseconds 31C0 ; RTIFLG = 0x80; // clear real time interrupt flag 31C0 C680 ldab #128 31C2 7B0015 stab 0x15 31C5 ; 31C5 ; 31C5 ; // set up the COP WATCHDOG clock monitor for 524.288 ms 31C5 ; COPCTL = 0xC5; // COP on 31C5 C6C5 ldab #197 31C7 7B0016 stab 0x16 31CA ; //COPCTL = 0x00; // COP off 31CA ; 31CA ; 31CA ; // set up the TOF interrupt 31CA ; TMSK2 = 0x80; // set to interrupt at 16.384 miliseconds 31CA C680 ldab #128 31CC 7B008D stab 0x8d 31CF ; TSCR = 0x80; // enable the timer 31CF C680 ldab #128 31D1 7B0086 stab 0x86 31D4 ; PACTL |= 0x0C; // ensure the timer is clocked from mclock divider 31D4 1C00A00C bset 0xa0,#12 31D8 ; HPRIO = 0xDE; // elevate the TOF interrupt 31D8 C6DE ldab #222 31DA 7B001F stab 0x1f 31DD ; 31DD ; 31DD ; /*// set up the MDC interrupt for time_tick 31DD ; HPRIO = 0xCC; // elevate to highest priority 31DD ; TSCR = 0x00; // setup 31DD ; MCCNT = 0x0000; // modulus down-count start point 31DD ; MCCTL = 0xC4; // enable 31DD ; */ 31DD ; 31DD ; } 31DD L3: 31DD .dbline 0 ; func end 31DD 3D rts