.module vectors.c .area memory(abs) .org 0xffd0 FFD0 _interrupt_vectors:: FFD0 FFFF .word 65535 FFD2 2591 .word _ADC_handler FFD4 FFFF .word 65535 FFD6 2592 .word _SCI1_handler FFD8 2593 .word _SPI_handler FFDA 2594 .word _PAIE_handler FFDC 2595 .word _PAO_handler FFDE 2596 .word _TOF_handler FFE0 2597 .word _TC7_handler FFE2 2598 .word _TC6_handler FFE4 2599 .word _TC5_handler FFE6 259A .word _TC4_handler FFE8 259B .word _TC3_handler FFEA 259C .word _TC2_handler FFEC 259D .word _TC1_handler FFEE 259E .word _TC0_handler FFF0 1482 .word _RTI_handler FFF2 259F .word _IRQ_handler FFF4 25A0 .word _XIRQ_handler FFF6 25A1 .word _SWI_handler FFF8 FFFF .word 65535 FFFA 25A2 .word _COP_handler FFFC 25A3 .word _CLM_handler FFFE 1000 .word __start .area data .module rlpos.c .area data 0200 _task_ptr:: 0200 .blkw 1 .area idata --- 0000 0000 .word _shell .area data --- 0002 .blkw 1 .area idata --- 0002 0000 .word _task1 .area data --- 0004 .blkw 1 .area idata --- 0004 0000 .word _task2 .area data 0206 _main_frame_ptr:: 0206 .blkb 2 .area idata --- 0006 0000 .word 0 .area data 0208 _main_frame_x_ptr:: 0208 .blkb 2 .area idata --- 0008 0000 .word 0 .area data 020A _temp_task_frame_ptr:: 020A .blkb 2 .area idata --- 000A 0000 .word 0 .area data .area text ; lreg1 -> -4,x ; lreg2 -> -8,x ; ?temp -> -29,x ; ?temp -> -29,x ; ?temp -> -29,x ; ?temp -> -29,x ; ?temp -> -27,x ; result -> -25,x ; temp_heap_ptr -> -23,x ; last_task -> -21,x ; cop_cycle -> -19,x ; temp -> -18,x ; temp_heap_size -> -17,x ; priority_check -> -15,x ; deadline -> -14,x ; i -> -10,x 102A _main:: 102A 34 pshx 102B B775 tfr s,x 102D 1BF1DC leas -36,sp 1030 ; /* RLPOS: RLPotter Operating System 1030 ; 1030 ; Version 0.5.1 for the 68HC12D60A microcontroller 1030 ; by Ryan Potter 1030 ; ryan@rlpotter.com 1030 ; 1030 ; 1030 ; v0.5.2: 1030 ; - make task_block and resource_block dynamic 1030 ; 1030 ; v0.5.1: 1030 ; - implemented task msg box system for states in kernel 1030 ; - implemented COP watchdog reset timer 1030 ; - added system resources to semlib 1030 ; - added skeleton ISR_handler() code for the other interrupts 1030 ; - implemented _HC12Setup.c to initialize/harden the system 1030 ; 1030 ; v0.5 April 16, 2003: 1030 ; - added priority preemption 1030 ; - finished kernel task state switcher 1030 ; - it is now officially a legitimate 1030 ; rate monotonic 1030 ; priority preemptive 1030 ; multitasking 1030 ; Real Time Operating System :) 1030 ; - made kernel.c and semlib.c consistent with the 1030 ; rest of the kernel 1030 ; - included the early framework for a msg box system 1030 ; 1030 ; v0.4 April 13, 2003: 8096 bytes 1030 ; - gerneralized the shell command-line input parser: 1030 ; cmd (up to 32 chars) 1030 ; - added kernel and shell functions 1030 ; 1030 ; v0.3 April 12, 2003: 6155 bytes 1030 ; - added a beginning shell user interface. 1030 ; - added a resource control block and basic semaphore functions. 1030 ; - added basic kernel functions 1030 ; 1030 ; v0.2 April 9, 2003: 1030 ; - able to round-robin with RTI interrupt. 1030 ; - bonified/certified multitasking with 3 tasks. :) 1030 ; 1030 ; v0.1 April 3, 2003: 1030 ; - able to round-robin without interrupts. 1030 ; - not multitasking, really. 1030 ; 1030 ; v0.0 started April 1, 2003; 0 bytes 1030 ; - no idea where to start. 1030 ; - don't want to look at anyone else's work. ;0) 1030 ; 1030 ; 1030 ; 1030 ; 1030 ; Architecture/C assumptions: 1030 ; 1) 'D' register is the accumulator 1030 ; 2) 'X' register points to the top of the current stack 1030 ; 3) 'Y' register is for general use in indexed operations 1030 ; 4) the heap grows upward and mem segments allocated by malloc, 1030 ; realloc, and calloc are linear and contiguous. 1030 ; 5) the stack grows downwards, and there is no boundary checking. 1030 ; 1030 ; Potential problem areas: 1030 ; 1) 'running' section of the kernel get's compiled using extra 1030 ; push and pop instructions 1030 ; 2) run out of ram (global + stack + heap) 1030 ; 1030 ; */ 1030 ; 1030 ; 1030 ; 1030 ; #include <912d60.h> 1030 ; #include 1030 ; #include 1030 ; #include 1030 ; #include "kernel.h" 1030 ; 1030 ; 1030 ; 1030 ; 1030 ; // FUNCTION PROTOTYPES 1030 ; void RTI_handler(void); 1030 ; void shell(void); 1030 ; void task1(void); 1030 ; void task2(void); 1030 ; void (*task_ptr[])(void) = {&shell, &task1, &task2}; 1030 ; 1030 ; 1030 ; 1030 ; 1030 ; // GLOBAL VARIABLES 1030 ; unsigned char *main_frame_ptr = NULL; // bottom of main() frame 1030 ; unsigned char *main_frame_x_ptr = NULL; // top of main() frame (x-reg ptr) 1030 ; unsigned char *temp_task_frame_ptr = NULL; // temp CCR pointer for RTI 1030 ; 1030 ; 1030 ; extern unsigned int current; // current task id number 1030 ; extern unsigned long int system_tick; 1030 ; 1030 ; 1030 ; // task control block 1030 ; extern struct task_block { 1030 ; unsigned char id; // ID of task 1030 ; char name[9]; // Name 1030 ; enum task_state state; // State 1030 ; unsigned char priority; // Priority 1030 ; unsigned long int period_tick; // for determining if deadline is up 1030 ; unsigned int interrupt_msg_box; // flags for pending interrupts 1030 ; enum message_box message; // misc flags 1030 ; unsigned char message_data[2]; // data for misc_msg_box flags 1030 ; unsigned char *heap_ptr; // heap addr while not current task 1030 ; unsigned int heap_size; // heap size 1030 ; unsigned char *frame_ptr; // CCR pointer 1030 ; }; 1030 ; 1030 ; 1030 ; // resource control block 1030 ; extern struct resource_block { 1030 ; unsigned char id; // ID of resource 1030 ; char name[5]; // Name of resource 1030 ; enum resource_state state; // State (busy, free...) 1030 ; unsigned char owner; // Current resource owner 1030 ; signed char queue[3]; // Tasks waiting on resource 1030 ; unsigned char queue_ptr; // Next free spot in queue 1030 ; }; 1030 ; 1030 ; 1030 ; extern struct task_block task[NUMTASKS]; 1030 ; extern struct resource_block resource[NUMRESOURCES]; 1030 ; 1030 ; 1030 ; extern char error_msg[8][25]; 1030 ; extern char error_src[5][18]; 1030 ; 1030 ; 1030 ; 1030 ; 1030 ; 1030 ; 1030 ; main() { 1030 ; 1030 ; // LOCAL VARIABLES 1030 ; int result; 1030 ; unsigned int i, temp_heap_size; 1030 ; unsigned int last_task = 0; 1030 CC0000 ldd #0 1033 6CE1EB std -21,x 1036 ; unsigned char *temp_heap_ptr, temp, priority_check, cop_cycle; 1036 ; unsigned long int deadline; 1036 ; 1036 ; extern int _bss_end, _textmode; 1036 ; extern unsigned int current; 1036 ; extern unsigned long int system_tick; 1036 ; 1036 ; _textmode = 1; // maps '\n' to "CR/LF" for Windows terminals 1036 CC0001 ldd #1 1039 7C0491 std __textmode 103C ; current = 0; // start the shell first 103C CC0000 ldd #0 103F 7C048F std _current 1042 ; cop_cycle = 0; // fresh watchdog 1042 69E1ED clr -19,x 1045 ; 1045 ; 1045 ; 1045 ; INTR_OFF(); // disable all maskable interrupts 1045 1410 sei 1047 1047 CC0000 ldd #0 104A 6C16 std -10,x 104C 18200082 lbra L7 1050 L4: 1050 CC001B ldd #27 1053 ED16 ldy -10,x 1055 13 emul 1056 C303B3 addd #_task 1059 B7C6 xgdy 105B EC16 ldd -10,x 105D 6B40 stab 0,y 105F CC001B ldd #27 1062 ED16 ldy -10,x 1064 13 emul 1065 C303BD addd #_task+10 1068 B7C6 xgdy 106A 6940 clr 0,y 106C CC001B ldd #27 106F ED16 ldy -10,x 1071 13 emul 1072 C303BE addd #_task+11 1075 B7C6 xgdy 1077 C6FF ldab #255 1079 6B40 stab 0,y 107B CC001B ldd #27 107E ED16 ldy -10,x 1080 13 emul 1081 C303BF addd #_task+12 1084 B7C6 xgdy 1086 35 pshy ; spill 1087 CD15B3 ldy #L11 108A 1802401C movw 0,y,-4,x 108E 1802421E movw 2,y,-2,x 1092 31 puly ; reload 1093 18021C40 movw -4,x,0,y 1097 18021E42 movw -2,x,2,y 109B CC001B ldd #27 109E ED16 ldy -10,x 10A0 13 emul 10A1 C303C8 addd #_task+21 10A4 B7C6 xgdy 10A6 CC0000 ldd #0 10A9 6C40 std 0,y 10AB CC001B ldd #27 10AE ED16 ldy -10,x 10B0 13 emul 10B1 C303CA addd #_task+23 10B4 B7C6 xgdy 10B6 CC0000 ldd #0 10B9 6C40 std 0,y 10BB CC001B ldd #27 10BE ED16 ldy -10,x 10C0 13 emul 10C1 C303CC addd #_task+25 10C4 B7C6 xgdy 10C6 CC0000 ldd #0 10C9 6C40 std 0,y 10CB L5: 10CB EC16 ldd -10,x 10CD C30001 addd #1 10D0 6C16 std -10,x 10D2 L7: 10D2 ; 10D2 ; 10D2 ; 10D2 ; // initialize the task structures 10D2 ; for (i=0; i= NUMTASKS) 123D ; next_task = 0; 123D ; current = next_task;*/ 123D ; 123D ; 123D ; 123D ; // CHANGE STATES ACCORDING TO MESSAGES 123D ; // 'waiting' needs to have highest precedence here 123D ; for (i=0; i= deadline) { 12D2 1912 leay -14,x 12D4 18024018 movw 0,y,-8,x 12D8 1802421A movw 2,y,-6,x 12DC CD048B ldy #_system_tick 12DF 1802401C movw 0,y,-4,x 12E3 1802421E movw 2,y,-2,x 12E7 1630A8 jsr __lcmp 12EA 250F blo L73 12EC ; task[i].state = pending; // change state at deadline 12EC CC001B ldd #27 12EF ED16 ldy -10,x 12F1 13 emul 12F2 C303BD addd #_task+10 12F5 B7C6 xgdy 12F7 C601 ldab #1 12F9 6B40 stab 0,y 12FB ; //puts("promote"); 12FB ; } 12FB L73: 12FB ; } 12FB L68: 12FB L65: 12FB EC16 ldd -10,x 12FD C30001 addd #1 1300 6C16 std -10,x 1302 L67: 1302 EC16 ldd -10,x 1304 8C0008 cpd #8 1307 1825FF84 lblo L64 130B ; // if (task[i].message) {} 130B ; } 130B ; 130B ; // set current = to highest priority pending/running task. 130B ; priority_check = 255; // lowest possible 130B C6FF ldab #255 130D 6B11 stab -15,x 130F CC0000 ldd #0 1312 6C16 std -10,x 1314 204E bra L79 1316 L76: 1316 ; for (i=0; i -4,x 1482 ; lreg2 -> -8,x 1482 ; ?temp -> -16,x 1482 ; local_thp -> -14,x 1482 ; frame_size -> -12,x 1482 ; i -> -10,x 1482 _RTI_handler:: 1482 34 pshx 1483 B775 tfr s,x 1485 1BF1EC leas -20,sp 1488 ; 1488 ; 1488 ; 1488 ; #pragma interrupt_handler RTI_handler() 1488 ; 1488 ; void RTI_handler(void) { 1488 ; 1488 ; size_t frame_size; 1488 ; unsigned int i; 1488 ; unsigned char *local_thp; 1488 ; 1488 ; 1488 ; //ACKNOWLEDGE THE INTERRUPT 1488 ; INTR_OFF(); // redundant. automatically done by the processor 1488 1410 sei 148A 148A ; RTIFLG = 0x0080; // acknowledge/clear the interrupt 148A C680 ldab #128 148C 7B0015 stab 0x15 148F ; 148F ; 148F ; //putchar('.'); 148F ; 148F ; 148F ; // SET THE FRAME POINTER for the interupted task. 148F ; // should point to the CCR entry on the stack. 148F ; asm("TFR x,d"); // start of RTI stack 148F B754 TFR x,d 1491 1491 ; asm("ADDD #2"); // adjust to CCR stack entry 1491 C30002 ADDD #2 1494 1494 ; asm("STD _temp_task_frame_ptr"); // put into task_frame_ptr 1494 7C020A STD _temp_task_frame_ptr 1497 1497 ; task[current].frame_ptr = temp_task_frame_ptr; 1497 CC001B ldd #27 149A FD048F ldy _current 149D 13 emul 149E C303CC addd #_task+25 14A1 B7C6 xgdy 14A3 FC020A ldd _temp_task_frame_ptr 14A6 6C40 std 0,y 14A8 ; 14A8 ; 14A8 ; 14A8 ; //PLACE CURRENT TASK CONTEXT ONTO THE HEAP 14A8 ; // determine size of heap segment needed 14A8 ; frame_size = main_frame_ptr - temp_task_frame_ptr; // always positive 14A8 FC0206 ldd _main_frame_ptr 14AB B3020A subd _temp_task_frame_ptr 14AE 6C14 std -12,x 14B0 ; task[current].heap_size = (int)frame_size; 14B0 CC001B ldd #27 14B3 FD048F ldy _current 14B6 13 emul 14B7 C303CA addd #_task+23 14BA B7C6 xgdy 14BC EC14 ldd -12,x 14BE 6C40 std 0,y 14C0 ; 14C0 ; // reallocate heap memory 14C0 ; task[current].heap_ptr = realloc(task[current].heap_ptr, frame_size); 14C0 18021480 movw -12,x,0,sp 14C4 CC001B ldd #27 14C7 FD048F ldy _current 14CA 13 emul 14CB 6C10 std -16,x 14CD C303C8 addd #_task+21 14D0 B7C6 xgdy 14D2 EC40 ldd 0,y 14D4 16346D jsr _realloc 14D7 6CE1EE std -18,x 14DA EC10 ldd -16,x 14DC C303C8 addd #_task+21 14DF B7C6 xgdy 14E1 ECE1EE ldd -18,x 14E4 6C40 std 0,y 14E6 ; local_thp = task[current].heap_ptr; 14E6 CC001B ldd #27 14E9 FD048F ldy _current 14EC 13 emul 14ED C303C8 addd #_task+21 14F0 B7C6 xgdy 14F2 ED40 ldy 0,y 14F4 6D12 sty -14,x 14F6 ; 14F6 ; if (local_thp == NULL) { 14F6 EC12 ldd -14,x 14F8 260C bne L115 14FA ; puts("out of heap space!"); 14FA CC1562 ldd #L117 14FD 163141 jsr _puts 1500 ; exit(0); 1500 CC0000 ldd #0 1503 161028 jsr _exit 1506 ; } 1506 L115: 1506 CC0000 ldd #0 1509 6C16 std -10,x 150B 201A bra L121 150D L118: 150D EC16 ldd -10,x 150F F3020A addd _temp_task_frame_ptr 1512 B7C6 xgdy 1514 E640 ldab 0,y 1516 3B pshd ; spill 1517 EC16 ldd -10,x 1519 E312 addd -14,x 151B B7C6 xgdy 151D 3A puld ; reload 151E 6B40 stab 0,y 1520 L119: 1520 EC16 ldd -10,x 1522 C30001 addd #1 1525 6C16 std -10,x 1527 L121: 1527 ; 1527 ; // transfer task frame to the heap one byte at a time. 1527 ; // assumes the heap grows from low to high addr. 1527 ; for(i=0; i -6,x ; ?temp -> -4,x ; ?temp -> -2,x ; rid -> 3,x 15B7 _sem_get:: 15B7 3B pshd 15B8 34 pshx 15B9 B775 tfr s,x 15BB 1B98 leas -8,sp 15BD ; // semlib.c 15BD ; #include <912d60.h> 15BD ; #include "kernel.h" 15BD ; #include "semlib.h" 15BD ; 15BD ; 15BD ; 15BD ; 15BD ; // GLOBAL VARIABLES 15BD ; extern unsigned int current; // current task id number 15BD ; 15BD ; // task control block 15BD ; extern struct task_block { 15BD ; unsigned char id; // ID of task 15BD ; char name[9]; // Name 15BD ; enum task_state state; // State 15BD ; unsigned char priority; // Priority 15BD ; unsigned long int period_tick; // for determining if deadline is up 15BD ; unsigned int interrupt_msg_box; // flags for pending interrupts 15BD ; enum message_box message; // misc flags 15BD ; unsigned char message_data[2]; // data for misc_msg_box flags 15BD ; unsigned char *heap_ptr; // heap addr while not current task 15BD ; unsigned int heap_size; // heap size 15BD ; unsigned char *frame_ptr; // CCR pointer 15BD ; }; 15BD ; 15BD ; 15BD ; // resource control block 15BD ; extern struct resource_block { 15BD ; unsigned char id; // ID of resource 15BD ; char name[5]; // Name of resource 15BD ; enum resource_state state; // State (busy, free...) 15BD ; unsigned char owner; // Current resource owner 15BD ; signed char queue[3]; // Tasks waiting on resource 15BD ; unsigned char queue_ptr; // Next free spot in queue 15BD ; }; 15BD ; 15BD ; 15BD ; extern struct task_block task[NUMTASKS]; 15BD ; extern struct resource_block resource[NUMRESOURCES]; 15BD ; 15BD ; extern char error_msg[8][25]; 15BD ; extern char error_src[5][18]; 15BD ; 15BD ; 15BD ; 15BD ; 15BD ; 15BD ; 15BD ; 15BD ; int sem_get(char rid) { 15BD ; 15BD ; /* Gives a resource to a requesting task. 15BD ; returns the resource id number (0,1,2,...) if free. 15BD ; otherwise returns -1. 15BD ; 15BD ; At this point, semaphores are a procedural control 15BD ; that the tasks have to follow to avoid resource contention. 15BD ; There is no kernel control over resources yet. */ 15BD ; 15BD ; 15BD ; // critical section 15BD ; INTR_OFF(); 15BD 1410 sei 15BF 15BF ; 15BF ; 15BF ; 15BF ; // GET SEMAPHORE 15BF ; // give semaphore to task 15BF ; if (resource[rid].state == NOTBUSY) { 15BF E603 ldab 3,x 15C1 87 clra 15C2 B7C6 xgdy 15C4 CC000C ldd #12 15C7 1813 emuls 15C9 C30335 addd #_resource+6 15CC B7C6 xgdy 15CE E740 tst 0,y 15D0 2630 bne L4 15D2 ; resource[rid].state = BUSY; 15D2 E603 ldab 3,x 15D4 87 clra 15D5 B7C6 xgdy 15D7 CC000C ldd #12 15DA 1813 emuls 15DC C30335 addd #_resource+6 15DF B7C6 xgdy 15E1 C601 ldab #1 15E3 6B40 stab 0,y 15E5 ; resource[rid].owner = current; 15E5 E603 ldab 3,x 15E7 87 clra 15E8 B7C6 xgdy 15EA CC000C ldd #12 15ED 1813 emuls 15EF C30336 addd #_resource+7 15F2 B7C6 xgdy 15F4 FC048F ldd _current 15F7 6B40 stab 0,y 15F9 ; 15F9 ; INTR_ON(); 15F9 10EF cli 15FB 15FB ; return rid; 15FB E603 ldab 3,x 15FD 87 clra 15FE 18200080 lbra L3 1602 L4: 1602 ; } 1602 ; 1602 ; // resource is taken/busy so make task wait 1602 ; else { 1602 ; task[current].message |= STATE_FLAG; 1602 CC001B ldd #27 1605 FD048F ldy _current 1608 13 emul 1609 C303C5 addd #_task+18 160C 6C1E std -2,x 160E B746 tfr d,y 1610 35 pshy ; spill 1611 ED1E ldy -2,x 1613 31 puly ; reload 1614 0C4001 bset 0,y,#1 1617 ; task[current].message_data[STATE_BOX] = waiting; 1617 CC001B ldd #27 161A FD048F ldy _current 161D 13 emul 161E C303C6 addd #_task+19 1621 B7C6 xgdy 1623 C603 ldab #3 1625 6B40 stab 0,y 1627 ; 1627 ; // put waiting task into the resources queue if there's space 1627 ; if (resource[rid].queue_ptr < 3) { 1627 E603 ldab 3,x 1629 87 clra 162A B7C6 xgdy 162C CC000C ldd #12 162F 1813 emuls 1631 C3033A addd #_resource+11 1634 B7C6 xgdy 1636 E640 ldab 0,y 1638 C103 cmpb #3 163A 2441 bhs L11 163C ; resource[rid].queue[resource[rid].queue_ptr] = current; 163C E603 ldab 3,x 163E 87 clra 163F B7C6 xgdy 1641 CC000C ldd #12 1644 1813 emuls 1646 6C1C std -4,x 1648 C3033A addd #_resource+11 164B B7C6 xgdy 164D E640 ldab 0,y 164F 87 clra 1650 3B pshd ; spill 1651 EC1C ldd -4,x 1653 C30337 addd #_resource+8 1656 6C18 std -8,x 1658 3A puld ; reload 1659 E318 addd -8,x 165B B7C6 xgdy 165D F60490 ldab _current+1 1660 6B40 stab 0,y 1662 ; resource[rid].queue_ptr++; 1662 E603 ldab 3,x 1664 87 clra 1665 B7C6 xgdy 1667 CC000C ldd #12 166A 1813 emuls 166C C3033A addd #_resource+11 166F 6C1A std -6,x 1671 B746 tfr d,y 1673 E640 ldab 0,y 1675 87 clra 1676 C30001 addd #1 1679 ED1A ldy -6,x 167B 6B40 stab 0,y 167D ; } 167D L11: 167D ; 167D ; INTR_ON(); 167D 10EF cli 167F 167F ; return -1; 167F CCFFFF ldd #-1 1682 L3: 1682 B757 tfr x,s 1684 30 pulx 1685 1B82 leas 2,sp 1687 .dbline 0 ; func end 1687 3D rts 1688 ; rid -> 3,x 1688 _sem_give:: 1688 3B pshd 1689 34 pshx 168A B775 tfr s,x 168C ; } 168C ; 168C ; } 168C ; 168C ; 168C ; 168C ; 168C ; int sem_give(char rid) { 168C ; 168C ; /* Takes a resource back from a task. 168C ; will (eventually) pass a message to a waiting task. 168C ; 168C ; At this point, semaphores are a procedural control 168C ; that the tasks have to follow to avoid resource contention. 168C ; There is no kernel control over resources yet. */ 168C ; 168C ; 168C ; // critical section 168C ; INTR_OFF(); 168C 1410 sei 168E 168E ; 168E ; 168E ; // return the resource 168E ; resource[rid].state = NOTBUSY; 168E E603 ldab 3,x 1690 87 clra 1691 B7C6 xgdy 1693 CC000C ldd #12 1696 1813 emuls 1698 C30335 addd #_resource+6 169B B7C6 xgdy 169D 6940 clr 0,y 169F ; 169F ; INTR_ON(); 169F 10EF cli 16A1 16A1 ; 16A1 ; return 0; 16A1 CC0000 ldd #0 16A4 L17: 16A4 B757 tfr x,s 16A6 30 pulx 16A7 1B82 leas 2,sp 16A9 .dbline 0 ; func end 16A9 3D rts .module shell.c .area text ; ?temp -> -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 16AA _shell:: 16AA 34 pshx 16AB B775 tfr s,x 16AD 1BF1C4 leas -60,sp 16B0 ; // shell.c 16B0 ; 16B0 ; 16B0 ; #include <912d60.h> 16B0 ; #include 16B0 ; #include 16B0 ; #include 16B0 ; #include 16B0 ; #include "kernel.h" 16B0 ; #include "semlib.h" 16B0 ; 16B0 ; 16B0 ; 16B0 ; 16B0 ; // FUNCTION PROTOTYPES 16B0 ; void shellcmd_help(char *argv1); 16B0 ; void shellcmd_tcb(signed char id); 16B0 ; void shellcmd_rcb(signed char id); 16B0 ; void shellcmd_rcbPrint(signed char rid); 16B0 ; void shellcmd_ticks(void); 16B0 ; void shellcmd_startTask(unsigned char id); 16B0 ; 16B0 ; void shellcmd_freeMemCheck(void); 16B0 ; 16B0 ; /*void shellcmd_stopTask(unsigned char id); 16B0 ; void shellcmd_setTaskPriority(unsigned char id, unsigned char priority); 16B0 ; void shellcmd_quitShell(void);*/ 16B0 ; 16B0 ; 16B0 ; 16B0 ; 16B0 ; // GLOBAL VARIABLES 16B0 ; extern unsigned long int system_tick; 16B0 ; extern unsigned int current; // current task id number 16B0 ; 16B0 ; extern char error_msg[8][25]; 16B0 ; extern char error_src[5][18]; 16B0 ; 16B0 ; 16B0 ; 16B0 ; 16B0 ; 16B0 ; void shell(void) { 16B0 ; 16B0 ; // LOCAL CONSTANTS 16B0 ; #define cmd_size (32+1) 16B0 ; 16B0 ; 16B0 ; 16B0 ; // LOCAL ENUMERATIONS 16B0 ; enum command_type { help = 1, 16B0 ; tcb, 16B0 ; rcb, 16B0 ; ticks, 16B0 ; start, 16B0 ; stop, 16B0 ; priority, 16B0 ; freemem, 16B0 ; quit 16B0 ; }; 16B0 ; 16B0 ; 16B0 ; 16B0 ; // LOCAL VARIABLES 16B0 ; char command[cmd_size], i, j, **argv, *cursor1, *cursor2; 16B0 ; int cmd_length, argc; 16B0 ; enum command_type cmd; 16B0 ; 16B0 ; 16B0 ; 16B0 ; 16B0 ; // INITIALIZE SHELL 16B0 ; sem_get(COM1); // get COM1 semaphore 16B0 CC0003 ldd #3 16B3 1615B7 jsr _sem_get 16B6 ; INTR_ON(); // enable interrupts 16B6 10EF cli 16B8 16B8 182004E1 lbra L5 16BC L4: 16BC ; 16BC ; 16BC ; 16BC ; 16BC ; // SHELL COMMAND LINE INTERPRETER 16BC ; while (1) { 16BC ; 16BC ; i = 0; 16BC 691F clr -1,x 16BE ; cursor1 = command; 16BE 19E1DE leay -34,x 16C1 6DE1D9 sty -39,x 16C4 ; cursor2 = command; 16C4 19E1DE leay -34,x 16C7 6DE1DC sty -36,x 16CA ; 16CA ; 16CA ; // put a PROMPT 16CA ; putchar('>'); putchar('>'); putchar(' '); 16CA CC003E ldd #62 16CD 162BB6 jsr _putchar 16D0 CC003E ldd #62 16D3 162BB6 jsr _putchar 16D6 CC0020 ldd #32 16D9 162BB6 jsr _putchar 16DC 2056 bra L8 16DE L7: 16DE ; 16DE ; 16DE ; // GET AND ECHO THE COMMAND on the console 16DE ; while (((command[i]=getchar()) != 0xD) && (i -- required arguments"); 1A1D CC210B ldd #L74 1A20 163141 jsr _puts 1A23 ; puts("[] -- optional arguments\n"); 1A23 CC20F1 ldd #L75 1A26 163141 jsr _puts 1A29 ; puts("help [cmd] -- help on a specific command"); 1A29 CC20C8 ldd #L76 1A2C 163141 jsr _puts 1A2F ; puts("tcb [task_id] -- prints task control block"); 1A2F CC209D ldd #L77 1A32 163141 jsr _puts 1A35 ; puts("rcb [[task_id] | [-b]] -- prints resource control block"); 1A35 CC2065 ldd #L78 1A38 163141 jsr _puts 1A3B ; puts("ticks -- shows system tick"); 1A3B CC204A ldd #L79 1A3E 163141 jsr _puts 1A41 ; puts("start -- start a task"); 1A41 CC202A ldd #L80 1A44 163141 jsr _puts 1A47 ; puts("stop -- stop a task"); 1A47 CC200B ldd #L81 1A4A 163141 jsr _puts 1A4D ; puts("priority , -- change prio"); 1A4D CC1FD7 ldd #L82 1A50 163141 jsr _puts 1A53 ; puts("freemem -- get approximate free RAM space"); 1A53 CC1FAD ldd #L83 1A56 163141 jsr _puts 1A59 ; puts("quit -- quit the shell (carefull!)"); 1A59 CC1F8A ldd #L84 1A5C 163141 jsr _puts 1A5F ; putchar('\n'); 1A5F CC000A ldd #10 1A62 162BB6 jsr _putchar 1A65 ; } 1A65 18200106 lbra L68 1A69 L71: 1A69 ; else if (argc == 2) 1A69 ECE1D5 ldd -43,x 1A6C 8C0002 cpd #2 1A6F 182600FC lbne L68 1A73 ; shellcmd_help(argv[1]); 1A73 EDE1D7 ldy -41,x 1A76 EC42 ldd 2,y 1A78 161BAD jsr _shellcmd_help 1A7B ; break; 1A7B 182000F0 lbra L68 1A7F L87: 1A7F ; case tcb: 1A7F ; if (argc == 1) 1A7F ECE1D5 ldd -43,x 1A82 8C0001 cpd #1 1A85 260A bne L88 1A87 ; shellcmd_tcb(-1); 1A87 CCFFFF ldd #-1 1A8A 161BB4 jsr _shellcmd_tcb 1A8D 182000DE lbra L68 1A91 L88: 1A91 ; else if (argc == 2) 1A91 ECE1D5 ldd -43,x 1A94 8C0002 cpd #2 1A97 2611 bne L90 1A99 ; shellcmd_tcb(atoi(argv[1])); 1A99 EDE1D7 ldy -41,x 1A9C EC42 ldd 2,y 1A9E 1635A1 jsr _atoi 1AA1 B714 tfr b,d 1AA3 161BB4 jsr _shellcmd_tcb 1AA6 182000C5 lbra L68 1AAA L90: 1AAA ; else if (argc > 2) 1AAA ECE1D5 ldd -43,x 1AAD 8C0002 cpd #2 1AB0 182F00BB lble L68 1AB4 ; puts(error_msg[1]); 1AB4 CC0225 ldd #_error_msg+25 1AB7 163141 jsr _puts 1ABA ; break; 1ABA 182000B1 lbra L68 1ABE L95: 1ABE ; case rcb: 1ABE ; if (argc == 1) // print entire rcb 1ABE ECE1D5 ldd -43,x 1AC1 8C0001 cpd #1 1AC4 260A bne L96 1AC6 ; shellcmd_rcb(-1); 1AC6 CCFFFF ldd #-1 1AC9 161C5C jsr _shellcmd_rcb 1ACC 1820009F lbra L68 1AD0 L96: 1AD0 ; else if (argc == 2) { 1AD0 ECE1D5 ldd -43,x 1AD3 8C0002 cpd #2 1AD6 2629 bne L98 1AD8 ; if (!strcmp(argv[1], "-b")) { // print 'busy' only 1AD8 CC1F87 ldd #L102 1ADB 6C80 std 0,sp 1ADD EDE1D7 ldy -41,x 1AE0 EC42 ldd 2,y 1AE2 1630C8 jsr _strcmp 1AE5 8C0000 cpd #0 1AE8 2608 bne L100 1AEA ; shellcmd_rcb(-2); 1AEA CCFFFE ldd #-2 1AED 161C5C jsr _shellcmd_rcb 1AF0 ; } 1AF0 207D bra L68 1AF2 L100: 1AF2 ; else 1AF2 ; shellcmd_rcb(atoi(argv[1])); // single 1AF2 EDE1D7 ldy -41,x 1AF5 EC42 ldd 2,y 1AF7 1635A1 jsr _atoi 1AFA B714 tfr b,d 1AFC 161C5C jsr _shellcmd_rcb 1AFF ; } 1AFF 206E bra L68 1B01 L98: 1B01 ; else if (argc > 2) 1B01 ECE1D5 ldd -43,x 1B04 8C0002 cpd #2 1B07 2F66 ble L68 1B09 ; puts(error_msg[1]); 1B09 CC0225 ldd #_error_msg+25 1B0C 163141 jsr _puts 1B0F ; break; 1B0F 205E bra L68 1B11 L106: 1B11 ; case ticks: 1B11 ; if (argc > 1) 1B11 ECE1D5 ldd -43,x 1B14 8C0001 cpd #1 1B17 2F08 ble L107 1B19 ; puts(error_msg[1]); 1B19 CC0225 ldd #_error_msg+25 1B1C 163141 jsr _puts 1B1F 204E bra L68 1B21 L107: 1B21 ; else 1B21 ; shellcmd_ticks(); 1B21 161D24 jsr _shellcmd_ticks 1B24 ; break; 1B24 2049 bra L68 1B26 L110: 1B26 ; case start: 1B26 ; if ((argc != 2) || 1B26 ECE1D5 ldd -43,x 1B29 8C0002 cpd #2 1B2C 2610 bne L113 1B2E EDE1D7 ldy -41,x 1B31 ED42 ldy 2,y 1B33 E640 ldab 0,y 1B35 87 clra 1B36 163346 jsr _isdigit 1B39 8C0000 cpd #0 1B3C 2608 bne L111 1B3E L113: 1B3E ; (!isdigit(*argv[1]))) 1B3E ; puts(error_msg[1]); 1B3E CC0225 ldd #_error_msg+25 1B41 163141 jsr _puts 1B44 2029 bra L68 1B46 L111: 1B46 ; else 1B46 ; shellcmd_startTask(atoi(argv[1])); 1B46 EDE1D7 ldy -41,x 1B49 EC42 ldd 2,y 1B4B 1635A1 jsr _atoi 1B4E 87 clra 1B4F 161D4C jsr _shellcmd_startTask 1B52 ; break; 1B52 201B bra L68 1B54 L115: 1B54 ; case stop: 1B54 ; puts(error_msg[0]); 1B54 CC020C ldd #_error_msg 1B57 163141 jsr _puts 1B5A ; break; 1B5A 2013 bra L68 1B5C L116: 1B5C ; case priority: 1B5C ; puts(error_msg[0]); 1B5C CC020C ldd #_error_msg 1B5F 163141 jsr _puts 1B62 ; break; 1B62 200B bra L68 1B64 L117: 1B64 ; case freemem: 1B64 ; shellcmd_freeMemCheck(); 1B64 161D73 jsr _shellcmd_freeMemCheck 1B67 ; break; 1B67 2006 bra L68 1B69 L118: 1B69 ; case quit: 1B69 ; puts(error_msg[0]); 1B69 CC020C ldd #_error_msg 1B6C 163141 jsr _puts 1B6F ; break; 1B6F ; default: 1B6F ; break; 1B6F L68: 1B6F ; 1B6F ; }} // end switch/if 1B6F L65: 1B6F ; 1B6F ; 1B6F ; 1B6F ; // free the argc and argv array memory 1B6F ; for (i=0; i 2,x 1BAD _shellcmd_help:: 1BAD ; 1BAD ; 1BAD ; 1BAD ; 1BAD ; void shellcmd_help(char *argv1) { 1BAD ; 1BAD ; puts(error_msg[0]); 1BAD CC020C ldd #_error_msg 1BB0 163141 jsr _puts 1BB3 ; } 1BB3 L123: 1BB3 .dbline 0 ; func end 1BB3 3D rts 1BB4 ; start -> -2,x 1BB4 ; max -> -1,x 1BB4 ; tid -> 3,x 1BB4 _shellcmd_tcb:: 1BB4 3B pshd 1BB5 34 pshx 1BB6 B775 tfr s,x 1BB8 1BF1EE leas -18,sp 1BBB ; 1BBB ; 1BBB ; 1BBB ; void shellcmd_tcb(signed char tid) { 1BBB ; 1BBB ; // Local Variables 1BBB ; unsigned char max, start; 1BBB ; 1BBB ; if (tid >= NUMTASKS) { 1BBB E603 ldab 3,x 1BBD C108 cmpb #8 1BBF 2D0A blt L125 1BC1 ; puts(error_msg[2]); 1BC1 CC023E ldd #_error_msg+50 1BC4 163141 jsr _puts 1BC7 ; return; 1BC7 1820008B lbra L124 1BCB L125: 1BCB ; } 1BCB ; 1BCB ; if (tid < 0) { 1BCB E703 tst 3,x 1BCD 2C08 bge L128 1BCF ; start = 0; 1BCF 691E clr -2,x 1BD1 ; max = NUMTASKS; 1BD1 C608 ldab #8 1BD3 6B1F stab -1,x 1BD5 ; } 1BD5 200F bra L129 1BD7 L128: 1BD7 ; else { 1BD7 ; start = tid; 1BD7 E603 ldab 3,x 1BD9 B714 tfr b,d 1BDB 6B1E stab -2,x 1BDD ; max = tid + 1; 1BDD E603 ldab 3,x 1BDF B714 tfr b,d 1BE1 C30001 addd #1 1BE4 6B1F stab -1,x 1BE6 ; } 1BE6 L129: 1BE6 ; 1BE6 ; puts("\nTask Control Block:"); 1BE6 CC1F72 ldd #L130 1BE9 163141 jsr _puts 1BEC E61E ldab -2,x 1BEE 6B03 stab 3,x 1BF0 204A bra L134 1BF2 L131: 1BF2 CC1F34 ldd #L135 1BF5 163141 jsr _puts 1BF8 1410 sei 1BFA 1BFA E603 ldab 3,x 1BFC B714 tfr b,d 1BFE 87 clra 1BFF 16222C jsr _get_task_name 1C02 6C1C std -4,x 1C04 E603 ldab 3,x 1C06 B714 tfr b,d 1C08 87 clra 1C09 162243 jsr _get_task_state 1C0C 6C1A std -6,x 1C0E E603 ldab 3,x 1C10 B714 tfr b,d 1C12 87 clra 1C13 1622A9 jsr _get_task_priority 1C16 6C18 std -8,x 1C18 E603 ldab 3,x 1C1A B714 tfr b,d 1C1C 87 clra 1C1D 162276 jsr _get_task_messages 1C20 6C88 std 8,sp 1C22 ED18 ldy -8,x 1C24 6D86 sty 6,sp 1C26 ED1A ldy -6,x 1C28 6D84 sty 4,sp 1C2A E603 ldab 3,x 1C2C B714 tfr b,d 1C2E 6C82 std 2,sp 1C30 ED1C ldy -4,x 1C32 6D80 sty 0,sp 1C34 CC1EF7 ldd #L136 1C37 163179 jsr _printf 1C3A L132: 1C3A 6203 inc 3,x 1C3C L134: 1C3C ; for (tid=start; tid -1,x 1C5C ; option -> 3,x 1C5C _shellcmd_rcb:: 1C5C 3B pshd 1C5D 34 pshx 1C5E B775 tfr s,x 1C60 1B9E leas -2,sp 1C62 ; 1C62 ; 1C62 ; 1C62 ; 1C62 ; void shellcmd_rcb(signed char option) { 1C62 ; 1C62 ; // Local Variables 1C62 ; unsigned char rid; 1C62 ; 1C62 ; 1C62 ; 1C62 ; // print all 1C62 ; if (option == -1) { 1C62 E603 ldab 3,x 1C64 C1FF cmpb #-1 1C66 261B bne L140 1C68 691F clr -1,x 1C6A 200F bra L145 1C6C L142: 1C6C E61F ldab -1,x 1C6E B714 tfr b,d 1C70 161CDC jsr _shellcmd_rcbPrint 1C73 L143: 1C73 E61F ldab -1,x 1C75 87 clra 1C76 C30001 addd #1 1C79 6B1F stab -1,x 1C7B L145: 1C7B ; for (rid=0; rid= NUMRESOURCES) { 1CAF E603 ldab 3,x 1CB1 C10B cmpb #11 1CB3 2D08 blt L154 1CB5 ; puts(error_msg[6]); 1CB5 CC02A2 ldd #_error_msg+150 1CB8 163141 jsr _puts 1CBB ; return; 1CBB 2019 bra L139 1CBD L154: 1CBD ; } 1CBD ; else 1CBD ; shellcmd_rcbPrint(option); 1CBD E603 ldab 3,x 1CBF B714 tfr b,d 1CC1 161CDC jsr _shellcmd_rcbPrint 1CC4 ; 1CC4 ; } 1CC4 L147: 1CC4 L141: 1CC4 ; 1CC4 ; 1CC4 ; puts ("-----------+----------+------------+------------+"); 1CC4 CC1E45 ldd #L157 1CC7 163141 jsr _puts 1CCA ; 1CCA ; puts("\nState: 0=notbusy, 1=busy"); 1CCA CC1E2B ldd #L158 1CCD 163141 jsr _puts 1CD0 ; puts("Owner: 0..15=task ID, 255=nobody"); 1CD0 CC1E0A ldd #L159 1CD3 163141 jsr _puts 1CD6 ; 1CD6 ; } 1CD6 L139: 1CD6 B757 tfr x,s 1CD8 30 pulx 1CD9 1B82 leas 2,sp 1CDB .dbline 0 ; func end 1CDB 3D rts 1CDC ; rid -> 3,x 1CDC _shellcmd_rcbPrint:: 1CDC 3B pshd 1CDD 34 pshx 1CDE B775 tfr s,x 1CE0 1B94 leas -12,sp 1CE2 ; 1CE2 ; 1CE2 ; 1CE2 ; void shellcmd_rcbPrint(signed char rid) { 1CE2 ; 1CE2 ; puts ("-----------+----------+------------+------------+"); 1CE2 CC1E45 ldd #L157 1CE5 163141 jsr _puts 1CE8 ; 1CE8 ; INTR_OFF(); 1CE8 1410 sei 1CEA 1CEA ; printf("RsrcID: %2d | State: %x | Owner: %3d | Waiting: %d |\n", 1CEA E603 ldab 3,x 1CEC B714 tfr b,d 1CEE 87 clra 1CEF 1624BB jsr _get_resource_state 1CF2 6C1E std -2,x 1CF4 E603 ldab 3,x 1CF6 B714 tfr b,d 1CF8 87 clra 1CF9 1624EE jsr _get_resource_owner 1CFC 6C1C std -4,x 1CFE E603 ldab 3,x 1D00 B714 tfr b,d 1D02 87 clra 1D03 162521 jsr _get_resource_queuelen 1D06 6C86 std 6,sp 1D08 ED1C ldy -4,x 1D0A 6D84 sty 4,sp 1D0C ED1E ldy -2,x 1D0E 6D82 sty 2,sp 1D10 E603 ldab 3,x 1D12 B714 tfr b,d 1D14 6C80 std 0,sp 1D16 CC1DD4 ldd #L161 1D19 163179 jsr _printf 1D1C ; rid, 1D1C ; get_resource_state(rid), 1D1C ; get_resource_owner(rid), 1D1C ; get_resource_queuelen(rid)); 1D1C ; INTR_ON(); 1D1C 10EF cli 1D1E 1D1E ; 1D1E ; } 1D1E L160: 1D1E B757 tfr x,s 1D20 30 pulx 1D21 1B82 leas 2,sp 1D23 .dbline 0 ; func end 1D23 3D rts 1D24 ; lreg1 -> -4,x 1D24 ; lreg2 -> -8,x 1D24 _shellcmd_ticks:: 1D24 34 pshx 1D25 B775 tfr s,x 1D27 1B94 leas -12,sp 1D29 ; 1D29 ; 1D29 ; 1D29 ; void shellcmd_ticks(void) { 1D29 ; 1D29 ; INTR_OFF(); 1D29 1410 sei 1D2B 1D2B ; printf("ticks: %ld\n", system_tick); 1D2B CD048B ldy #_system_tick 1D2E 1802401C movw 0,y,-4,x 1D32 1802421E movw 2,y,-2,x 1D36 1980 leay 0,sp 1D38 18021C40 movw -4,x,0,y 1D3C 18021E42 movw -2,x,2,y 1D40 CC1DC8 ldd #L163 1D43 163179 jsr _printf 1D46 ; INTR_ON(); 1D46 10EF cli 1D48 1D48 ; } 1D48 L162: 1D48 B757 tfr x,s 1D4A 30 pulx 1D4B .dbline 0 ; func end 1D4B 3D rts 1D4C ; id -> 3,x 1D4C _shellcmd_startTask:: 1D4C 3B pshd 1D4D 34 pshx 1D4E B775 tfr s,x 1D50 1B9E leas -2,sp 1D52 ; 1D52 ; 1D52 ; 1D52 ; 1D52 ; void shellcmd_startTask(unsigned char id) { 1D52 ; 1D52 ; if (set_task_state(id, pending) == 0) 1D52 CC0001 ldd #1 1D55 6C80 std 0,sp 1D57 E603 ldab 3,x 1D59 87 clra 1D5A 1622E2 jsr _set_task_state 1D5D 8C0000 cpd #0 1D60 260B bne L165 1D62 ; printf("task %d started\n", id); 1D62 E603 ldab 3,x 1D64 87 clra 1D65 6C80 std 0,sp 1D67 CC1DB7 ldd #L167 1D6A 163179 jsr _printf 1D6D L165: 1D6D ; } 1D6D L164: 1D6D B757 tfr x,s 1D6F 30 pulx 1D70 1B82 leas 2,sp 1D72 .dbline 0 ; func end 1D72 3D rts 1D73 ; free -> -2,x 1D73 _shellcmd_freeMemCheck:: 1D73 34 pshx 1D74 B775 tfr s,x 1D76 1B9C leas -4,sp 1D78 ; 1D78 ; 1D78 ; 1D78 ; 1D78 ; void shellcmd_freeMemCheck(void) { 1D78 ; 1D78 ; // LOCAL VARIABLES 1D78 ; int free; 1D78 ; 1D78 ; 1D78 ; free = get_free_memory(); 1D78 162554 jsr _get_free_memory 1D7B 6C1E std -2,x 1D7D ; INTR_OFF(); 1D7D 1410 sei 1D7F 1D7F ; printf("approximate free heap memory: %d bytes\n", free); 1D7F 18021E80 movw -2,x,0,sp 1D83 CC1D8F ldd #L169 1D86 163179 jsr _printf 1D89 ; INTR_ON(); 1D89 10EF cli 1D8B 1D8B ; 1D8B ; } 1D8B L168: 1D8B B757 tfr x,s 1D8D 30 pulx 1D8E .dbline 0 ; func end 1D8E 3D rts 1D8F L169: 1D8F 617070726F78696D6174652066726565 .byte 'a,'p,'p,'r,'o,'x,'i,'m,'a,'t,'e,32,'f,'r,'e,'e 1D9F 2068656170206D656D6F72793A202564 .byte 32,'h,'e,'a,'p,32,'m,'e,'m,'o,'r,'y,58,32,37,'d 1DAF 2062797465730A00 .byte 32,'b,'y,'t,'e,'s,10,0 1DB7 L167: 1DB7 7461736B20256420737461727465640A .byte 't,'a,'s,'k,32,37,'d,32,'s,'t,'a,'r,'t,'e,'d,10 1DC7 00 .byte 0 1DC8 L163: 1DC8 7469636B733A20256C640A00 .byte 't,'i,'c,'k,'s,58,32,37,'l,'d,10,0 1DD4 L161: 1DD4 5273726349443A20253264207C205374 .byte 'R,'s,'r,'c,'I,'D,58,32,37,50,'d,32,124,32,'S,'t 1DE4 6174653A202578207C204F776E65723A .byte 'a,'t,'e,58,32,37,'x,32,124,32,'O,'w,'n,'e,'r,58 1DF4 20253364207C2057616974696E673A20 .byte 32,37,51,'d,32,124,32,'W,'a,'i,'t,'i,'n,'g,58,32 1E04 2564207C0A00 .byte 37,'d,32,124,10,0 1E0A L159: 1E0A 4F776E65723A20302E2E31353D746173 .byte 'O,'w,'n,'e,'r,58,32,48,46,46,49,53,61,'t,'a,'s 1E1A 6B2049442C203235353D6E6F626F6479 .byte 'k,32,'I,'D,44,32,50,53,53,61,'n,'o,'b,'o,'d,'y 1E2A 00 .byte 0 1E2B L158: 1E2B 0A53746174653A20303D6E6F74627573 .byte 10,'S,'t,'a,'t,'e,58,32,48,61,'n,'o,'t,'b,'u,'s 1E3B 792C20313D6275737900 .byte 'y,44,32,49,61,'b,'u,'s,'y,0 1E45 L157: 1E45 2D2D2D2D2D2D2D2D2D2D2D2B2D2D2D2D .byte 45,45,45,45,45,45,45,45,45,45,45,43,45,45,45,45 1E55 2D2D2D2D2D2D2B2D2D2D2D2D2D2D2D2D .byte 45,45,45,45,45,45,43,45,45,45,45,45,45,45,45,45 1E65 2D2D2D2B2D2D2D2D2D2D2D2D2D2D2D2D .byte 45,45,45,43,45,45,45,45,45,45,45,45,45,45,45,45 1E75 2B00 .byte 43,0 1E77 L138: 1E77 4D6573736167653A205B206269743720 .byte 'M,'e,'s,'s,'a,'g,'e,58,32,91,32,'b,'i,'t,55,32 1E87 7C2062697436207C2062697435207C20 .byte 124,32,'b,'i,'t,54,32,124,32,'b,'i,'t,53,32,124,32 1E97 62697434207C2062697433207C206269 .byte 'b,'i,'t,52,32,124,32,'b,'i,'t,51,32,124,32,'b,'i 1EA7 7432207C207072696F207C2073746174 .byte 't,50,32,124,32,'p,'r,'i,'o,32,124,32,'s,'t,'a,'t 1EB7 65205D00 .byte 'e,32,93,0 1EBB L137: 1EBB 0A53746174653A20303D69646C652C20 .byte 10,'S,'t,'a,'t,'e,58,32,48,61,'i,'d,'l,'e,44,32 1ECB 313D70656E64696E672C20323D72756E .byte 49,61,'p,'e,'n,'d,'i,'n,'g,44,32,50,61,'r,'u,'n 1EDB 6E696E672C20333D77616974696E672C .byte 'n,'i,'n,'g,44,32,51,61,'w,'a,'i,'t,'i,'n,'g,44 1EEB 20343D66696E697368656400 .byte 32,52,61,'f,'i,'n,'i,'s,'h,'e,'d,0 1EF7 L136: 1EF7 4E616D653A20253873207C2049443A20 .byte 'N,'a,'m,'e,58,32,37,56,'s,32,124,32,'I,'D,58,32 1F07 253264207C2053746174653A20256420 .byte 37,50,'d,32,124,32,'S,'t,'a,'t,'e,58,32,37,'d,32 1F17 7C205072696F3A20253364207C204D73 .byte 124,32,'P,'r,'i,'o,58,32,37,51,'d,32,124,32,'M,'s 1F27 67733A203078302578207C0A00 .byte 'g,'s,58,32,48,'x,48,37,'x,32,124,10,0 1F34 L135: 1F34 2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2B .byte 45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,43 1F44 2D2D2D2D2D2D2D2D2B2D2D2D2D2D2D2D .byte 45,45,45,45,45,45,45,45,43,45,45,45,45,45,45,45 1F54 2D2D2D2B2D2D2D2D2D2D2D2D2D2D2D2B .byte 45,45,45,43,45,45,45,45,45,45,45,45,45,45,45,43 1F64 2D2D2D2D2D2D2D2D2D2D2D2D2B00 .byte 45,45,45,45,45,45,45,45,45,45,45,45,43,0 1F72 L130: 1F72 0A5461736B20436F6E74726F6C20426C .byte 10,'T,'a,'s,'k,32,'C,'o,'n,'t,'r,'o,'l,32,'B,'l 1F82 6F636B3A00 .byte 'o,'c,'k,58,0 1F87 L102: 1F87 2D6200 .byte 45,'b,0 1F8A L84: 1F8A 71756974202D2D207175697420746865 .byte 'q,'u,'i,'t,32,45,45,32,'q,'u,'i,'t,32,'t,'h,'e 1F9A 207368656C6C20286361726566756C6C .byte 32,'s,'h,'e,'l,'l,32,40,'c,'a,'r,'e,'f,'u,'l,'l 1FAA 212900 .byte 33,41,0 1FAD L83: 1FAD 667265656D656D202D2D206765742061 .byte 'f,'r,'e,'e,'m,'e,'m,32,45,45,32,'g,'e,'t,32,'a 1FBD 7070726F78696D617465206672656520 .byte 'p,'p,'r,'o,'x,'i,'m,'a,'t,'e,32,'f,'r,'e,'e,32 1FCD 52414D20737061636500 .byte 'R,'A,'M,32,'s,'p,'a,'c,'e,0 1FD7 L82: 1FD7 7072696F72697479203C7461736B5F69 .byte 'p,'r,'i,'o,'r,'i,'t,'y,32,60,'t,'a,'s,'k,95,'i 1FE7 643E2C203C7461736B5F7072696F7269 .byte 'd,62,44,32,60,'t,'a,'s,'k,95,'p,'r,'i,'o,'r,'i 1FF7 74793E20202D2D206368616E67652070 .byte 't,'y,62,32,32,45,45,32,'c,'h,'a,'n,'g,'e,32,'p 2007 72696F00 .byte 'r,'i,'o,0 200B L81: 200B 73746F70203C7461736B5F69643E2020 .byte 's,'t,'o,'p,32,60,'t,'a,'s,'k,95,'i,'d,62,32,32 201B 2D2D2073746F702061207461736B00 .byte 45,45,32,'s,'t,'o,'p,32,'a,32,'t,'a,'s,'k,0 202A L80: 202A 7374617274203C7461736B5F69643E20 .byte 's,'t,'a,'r,'t,32,60,'t,'a,'s,'k,95,'i,'d,62,32 203A 2D2D2073746172742061207461736B00 .byte 45,45,32,'s,'t,'a,'r,'t,32,'a,32,'t,'a,'s,'k,0 204A L79: 204A 7469636B73202D2D2073686F77732073 .byte 't,'i,'c,'k,'s,32,45,45,32,'s,'h,'o,'w,'s,32,'s 205A 797374656D207469636B00 .byte 'y,'s,'t,'e,'m,32,'t,'i,'c,'k,0 2065 L78: 2065 726362205B5B7461736B5F69645D207C .byte 'r,'c,'b,32,91,91,'t,'a,'s,'k,95,'i,'d,93,32,124 2075 205B2D625D5D202D2D207072696E7473 .byte 32,91,45,'b,93,93,32,45,45,32,'p,'r,'i,'n,'t,'s 2085 207265736F7572636520636F6E74726F .byte 32,'r,'e,'s,'o,'u,'r,'c,'e,32,'c,'o,'n,'t,'r,'o 2095 6C20626C6F636B00 .byte 'l,32,'b,'l,'o,'c,'k,0 209D L77: 209D 746362205B7461736B5F69645D202D2D .byte 't,'c,'b,32,91,'t,'a,'s,'k,95,'i,'d,93,32,45,45 20AD 207072696E7473207461736B20636F6E .byte 32,'p,'r,'i,'n,'t,'s,32,'t,'a,'s,'k,32,'c,'o,'n 20BD 74726F6C20626C6F636B00 .byte 't,'r,'o,'l,32,'b,'l,'o,'c,'k,0 20C8 L76: 20C8 68656C70205B636D645D202D2D206865 .byte 'h,'e,'l,'p,32,91,'c,'m,'d,93,32,45,45,32,'h,'e 20D8 6C70206F6E2061207370656369666963 .byte 'l,'p,32,'o,'n,32,'a,32,'s,'p,'e,'c,'i,'f,'i,'c 20E8 20636F6D6D616E6400 .byte 32,'c,'o,'m,'m,'a,'n,'d,0 20F1 L75: 20F1 5B5D202D2D206F7074696F6E616C2061 .byte 91,93,32,45,45,32,'o,'p,'t,'i,'o,'n,'a,'l,32,'a 2101 7267756D656E74730A00 .byte 'r,'g,'u,'m,'e,'n,'t,'s,10,0 210B L74: 210B 3C3E202D2D2072657175697265642061 .byte 60,62,32,45,45,32,'r,'e,'q,'u,'i,'r,'e,'d,32,'a 211B 7267756D656E747300 .byte 'r,'g,'u,'m,'e,'n,'t,'s,0 2124 L73: 2124 2D2D2D48454C502D2D2D0A00 .byte 45,45,45,'H,'E,'L,'P,45,45,45,10,0 2130 L63: 2130 00 .byte 0 2131 L60: 2131 7175697400 .byte 'q,'u,'i,'t,0 2136 L57: 2136 667265656D656D00 .byte 'f,'r,'e,'e,'m,'e,'m,0 213E L54: 213E 7072696F7269747900 .byte 'p,'r,'i,'o,'r,'i,'t,'y,0 2147 L51: 2147 73746F7000 .byte 's,'t,'o,'p,0 214C L48: 214C 737461727400 .byte 's,'t,'a,'r,'t,0 2152 L45: 2152 7469636B7300 .byte 't,'i,'c,'k,'s,0 2158 L42: 2158 72636200 .byte 'r,'c,'b,0 215C L39: 215C 74636200 .byte 't,'c,'b,0 2160 L36: 2160 68656C7000 .byte 'h,'e,'l,'p,0 .module sys_time.c .area text 2165 _sys_time:: 2165 34 pshx 2166 B775 tfr s,x 2168 1B9C leas -4,sp 216A ; // sys_time.c 216A ; #include 216A ; #include <912d60.h> 216A ; #include "kernel.h" 216A ; 216A ; 216A ; // GLOBAL VARIABLES 216A ; static unsigned char abort; 216A ; 216A ; 216A ; void sys_time(void) { 216A ; 216A ; abort = 0; 216A 79032E clr _abort 216D ; set_task_priority(get_task_id(), 1); 216D 16221C jsr _get_task_id 2170 6C1E std -2,x 2172 CC0001 ldd #1 2175 6C80 std 0,sp 2177 EC1E ldd -2,x 2179 87 clra 217A 162461 jsr _set_task_priority 217D ; //spawn(sys_time_abort()); 217D ; INTR_ON(); 217D 10EF cli 217F 217F L4: 217F L5: 217F ; 217F ; while (!abort) { 217F F7032E tst _abort 2182 27FB beq L4 2184 ; 2184 ; // DISPLAY TIME: hh:mm:ss 2184 ; 2184 ; } 2184 ; 2184 ; INTR_OFF(); 2184 1410 sei 2186 2186 ; 2186 ; } 2186 L3: 2186 B757 tfr x,s 2188 30 pulx 2189 .dbline 0 ; func end 2189 3D rts 218A _sys_time_abort:: 218A ; 218A ; 218A ; 218A ; void sys_time_abort(void) { 218A ; 218A ; INTR_ON(); 218A 10EF cli 218C 218C ; getchar(); 218C 162BDE jsr _getchar 218F ; abort = 1; 218F C601 ldab #1 2191 7B032E stab _abort 2194 ; INTR_OFF(); 2194 1410 sei 2196 2196 ; 2196 ; 2196 ; } 2196 L7: 2196 .dbline 0 ; func end 2196 3D rts .area bss --- 0000 _abort: --- 0000 .blkb 1 .module task1.c .area text ; i -> -2,x 2197 _task1:: 2197 34 pshx 2198 B775 tfr s,x 219A 1B9E leas -2,sp 219C ; #include 219C ; #include <912d60.h> 219C ; #include "semlib.h" 219C ; 219C ; 219C ; 219C ; /* dummy task to eat up time, and to give the kernel 219C ; something to multitask with */ 219C ; void task1 (void) { 219C ; 219C ; int i; 219C ; 219C ; sem_get(COM1); 219C CC0003 ldd #3 219F 1615B7 jsr _sem_get 21A2 ; INTR_ON(); 21A2 10EF cli 21A4 21A4 CC0000 ldd #0 21A7 6C1E std -2,x 21A9 L4: 21A9 L5: 21A9 ; 21A9 ; 21A9 ; //puts("T1 Starting"); 21A9 ; for (i=0; i<0x1000; i++); 21A9 EC1E ldd -2,x 21AB C30001 addd #1 21AE 6C1E std -2,x 21B0 EC1E ldd -2,x 21B2 8C1000 cpd #4096 21B5 2DF2 blt L4 21B7 CC0000 ldd #0 21BA 6C1E std -2,x 21BC L8: 21BC L9: 21BC ; //puts("T1.1"); 21BC ; 21BC ; for (i=0; i<0x1800; i++); 21BC EC1E ldd -2,x 21BE C30001 addd #1 21C1 6C1E std -2,x 21C3 EC1E ldd -2,x 21C5 8C1800 cpd #6144 21C8 2DF2 blt L8 21CA CC0000 ldd #0 21CD 6C1E std -2,x 21CF L12: 21CF L13: 21CF ; //puts("T1.2"); 21CF ; 21CF ; for (i=0; i<0x2000; i++); 21CF EC1E ldd -2,x 21D1 C30001 addd #1 21D4 6C1E std -2,x 21D6 EC1E ldd -2,x 21D8 8C2000 cpd #8192 21DB 2DF2 blt L12 21DD CC0000 ldd #0 21E0 6C1E std -2,x 21E2 L16: 21E2 L17: 21E2 ; //puts("T1.3"); 21E2 ; 21E2 ; for (i=0; i<0x2800; i++); 21E2 EC1E ldd -2,x 21E4 C30001 addd #1 21E7 6C1E std -2,x 21E9 EC1E ldd -2,x 21EB 8C2800 cpd #10240 21EE 2DF2 blt L16 21F0 ; //puts("T1 Finished"); 21F0 ; 21F0 ; //puts("-T1-"); 21F0 ; 21F0 ; 21F0 ; INTR_OFF(); 21F0 1410 sei 21F2 21F2 ; sem_give(COM1); 21F2 CC0003 ldd #3 21F5 161688 jsr _sem_give 21F8 ; 21F8 ; } 21F8 L3: 21F8 B757 tfr x,s 21FA 30 pulx 21FB .dbline 0 ; func end 21FB 3D rts .module task2.c .area text ; i -> -2,x 21FC _task2:: 21FC 34 pshx 21FD B775 tfr s,x 21FF 1B9E leas -2,sp 2201 ; #include 2201 ; #include <912d60.h> 2201 ; #include "kernel.h" 2201 ; 2201 ; 2201 ; 2201 ; /* dummy task to eat up time, and to give the kernel 2201 ; something to multitask with */ 2201 ; void task2 (void) { 2201 ; 2201 ; int i; 2201 ; 2201 ; INTR_ON(); 2201 10EF cli 2203 2203 CC0000 ldd #0 2206 6C1E std -2,x 2208 L4: 2208 L5: 2208 ; 2208 ; //0x800 = ~ 12ms 2208 ; for (i=0; i<0x0E00; i++); 2208 EC1E ldd -2,x 220A C30001 addd #1 220D 6C1E std -2,x 220F EC1E ldd -2,x 2211 8C0E00 cpd #3584 2214 2DF2 blt L4 2216 ; //puts("-T2-"); 2216 ; 2216 ; INTR_OFF(); 2216 1410 sei 2218 2218 ; 2218 ; } 2218 L3: 2218 B757 tfr x,s 221A 30 pulx 221B .dbline 0 ; func end 221B 3D rts .module kernel.c .area data 020C _error_msg:: 020C .blkb 23 .area idata --- 0000 756E696D706C696D656E746564206675 .byte 'u,'n,'i,'m,'p,'l,'i,'m,'e,'n,'t,'e,'d,32,'f,'u --- 0010 6E6374696F6E00 .byte 'n,'c,'t,'i,'o,'n,0 .area data --- 0017 .blkb 2 .area idata --- 0017 0000 .byte 0,0 .area data --- 0019 .blkb 13 .area idata --- 0019 73796E746178206572726F7200 .byte 's,'y,'n,'t,'a,'x,32,'e,'r,'r,'o,'r,0 .area data --- 0026 .blkb 12 .area idata --- 0026 00000000000000000000 .word 0,0,0,0,0 --- 0030 0000 .byte 0,0 .area data --- 0032 .blkb 16 .area idata --- 0032 696C6C6567616C207461736B20494400 .byte 'i,'l,'l,'e,'g,'a,'l,32,'t,'a,'s,'k,32,'I,'D,0 .area data --- 0042 .blkb 9 .area idata --- 0042 000000000000000000 .byte 0,0,0,0,0,0,0,0,0 .area data --- 004B .blkb 19 .area idata --- 004B 696C6C6567616C207461736B20737461 .byte 'i,'l,'l,'e,'g,'a,'l,32,'t,'a,'s,'k,32,'s,'t,'a --- 005B 746500 .byte 't,'e,0 .area data --- 005E .blkb 6 .area idata --- 005E 000000000000 .byte 0,0,0,0,0,0 .area data --- 0064 .blkb 22 .area idata --- 0064 696C6C6567616C207461736B20707269 .byte 'i,'l,'l,'e,'g,'a,'l,32,'t,'a,'s,'k,32,'p,'r,'i --- 0074 6F7269747900 .byte 'o,'r,'i,'t,'y,0 .area data --- 007A .blkb 3 .area idata --- 007A 000000 .byte 0,0,0 .area data --- 007D .blkb 14 .area idata --- 007D 6F7574206F66206D656D6F727900 .byte 'o,'u,'t,32,'o,'f,32,'m,'e,'m,'o,'r,'y,0 .area data --- 008B .blkb 11 .area idata --- 008B 00000000000000000000 .word 0,0,0,0,0 --- 0095 00 .byte 0 .area data --- 0096 .blkb 20 .area idata --- 0096 696C6C6567616C207265736F75726365 .byte 'i,'l,'l,'e,'g,'a,'l,32,'r,'e,'s,'o,'u,'r,'c,'e --- 00A6 20494400 .byte 32,'I,'D,0 .area data --- 00AA .blkb 5 .area idata --- 00AA 0000000000 .byte 0,0,0,0,0 .area data --- 00AF .blkb 23 .area idata --- 00AF 696C6C6567616C207265736F75726365 .byte 'i,'l,'l,'e,'g,'a,'l,32,'r,'e,'s,'o,'u,'r,'c,'e --- 00BF 20737461746500 .byte 32,'s,'t,'a,'t,'e,0 .area data --- 00C6 .blkb 2 .area idata --- 00C6 0000 .byte 0,0 .area data 02D4 _error_src:: 02D4 .blkb 14 .area idata --- 00C8 6B65726E656C206572726F723A00 .byte 'k,'e,'r,'n,'e,'l,32,'e,'r,'r,'o,'r,58,0 .area data --- 00D6 .blkb 4 .area idata --- 00D6 00000000 .byte 0,0,0,0 .area data --- 00DA .blkb 16 .area idata --- 00DA 6B65726E656C2E63206572726F723A00 .byte 'k,'e,'r,'n,'e,'l,46,'c,32,'e,'r,'r,'o,'r,58,0 .area data --- 00EA .blkb 2 .area idata --- 00EA 0000 .byte 0,0 .area data --- 00EC .blkb 18 .area idata --- 00EC 6B65726E656C20525449206572726F72 .byte 'k,'e,'r,'n,'e,'l,32,'R,'T,'I,32,'e,'r,'r,'o,'r --- 00FC 3A00 .byte 58,0 .area data --- 00FE .blkb 13 .area idata --- 00FE 7368656C6C206572726F723A00 .byte 's,'h,'e,'l,'l,32,'e,'r,'r,'o,'r,58,0 .area data --- 010B .blkb 5 .area idata --- 010B 0000000000 .byte 0,0,0,0,0 .area data --- 0110 .blkb 16 .area idata --- 0110 73656D6C69622E63206572726F723A00 .byte 's,'e,'m,'l,'i,'b,46,'c,32,'e,'r,'r,'o,'r,58,0 .area data --- 0120 .blkb 2 .area idata --- 0120 0000 .byte 0,0 .area data .area text 221C _get_task_id:: 221C ; //kernel.c 221C ; 221C ; #include <912d60.h> 221C ; #include 221C ; #include 221C ; #include "kernel.h" 221C ; 221C ; 221C ; // GLOBAL VARIABLE DEFINITIONS 221C ; unsigned int current; // current task id number 221C ; unsigned long int system_tick; 221C ; 221C ; 221C ; // task control block 221C ; typedef struct task_block { 221C ; unsigned char id; // ID of task 221C ; char name[9]; // Name 221C ; enum task_state state; // State 221C ; unsigned char priority; // Priority 221C ; unsigned long int period_tick; // for determining if deadline is up 221C ; unsigned int interrupt_msg_box; // flags for pending interrupts 221C ; enum message_box message; // misc flags 221C ; unsigned char message_data[2]; // data for misc_msg_box flags 221C ; unsigned char *heap_ptr; // heap addr while not current task 221C ; unsigned int heap_size; // heap size 221C ; unsigned char *frame_ptr; // CCR pointer 221C ; }; 221C ; 221C ; 221C ; // resource control block 221C ; typedef struct resource_block { 221C ; unsigned char id; // ID of resource 221C ; char name[5]; // Name of resource 221C ; enum resource_state state; // State (busy, free...) 221C ; unsigned char owner; // Current resource owner 221C ; signed char queue[3]; // Tasks waiting on resource 221C ; unsigned char queue_ptr; // Next free spot in queue 221C ; }; 221C ; 221C ; 221C ; struct task_block task[NUMTASKS]; 221C ; // struct task_block **tasks; 221C ; struct resource_block resource[NUMRESOURCES]; 221C ; // unsigned int numresources; 221C ; // struct resource_block **resources; 221C ; 221C ; 221C ; // global interrupt flags 221C ; //unsigned int interrupt_flags_ADC; 221C ; //unsigned int interrupt_flags_TC; 221C ; 221C ; 221C ; // error massages 221C ; char error_msg[][25] = {"unimplimented function", // error 0 221C ; "syntax error", // error 1 221C ; "illegal task ID", // error 2 221C ; "illegal task state", // error 3 221C ; "illegal task priority", // error 4 221C ; "out of memory", // error 5 221C ; "illegal resource ID", // error 6 221C ; "illegal resource state" // error 7 221C ; }; 221C ; char error_src[][18] = {"kernel error:", // source 0 221C ; "kernel.c error:", // source 1 221C ; "kernel RTI error:", // source 2 221C ; "shell error:", // source 3 221C ; "semlib.c error:" // source 4 221C ; }; 221C ; 221C ; 221C ; 221C ; // FUNCTIONS 221C ; 221C ; char get_task_id() { 221C ; return task[current].id; 221C CC001B ldd #27 221F FD048F ldy _current 2222 13 emul 2223 C303B3 addd #_task 2226 B7C6 xgdy 2228 E640 ldab 0,y 222A 87 clra 222B L3: 222B .dbline 0 ; func end 222B 3D rts 222C ; id -> 3,x 222C _get_task_name:: 222C 3B pshd 222D 34 pshx 222E B775 tfr s,x 2230 ; } 2230 ; 2230 ; 2230 ; 2230 ; char *get_task_name(unsigned char id) { 2230 ; return task[id].name; 2230 E603 ldab 3,x 2232 87 clra 2233 B7C6 xgdy 2235 CC001B ldd #27 2238 1813 emuls 223A C303B4 addd #_task+1 223D L4: 223D B757 tfr x,s 223F 30 pulx 2240 1B82 leas 2,sp 2242 .dbline 0 ; func end 2242 3D rts 2243 ; id -> 3,x 2243 _get_task_state:: 2243 3B pshd 2244 34 pshx 2245 B775 tfr s,x 2247 ; } 2247 ; 2247 ; 2247 ; 2247 ; 2247 ; int get_task_state(unsigned char id) { 2247 ; 2247 ; if (id < NUMTASKS) { 2247 E603 ldab 3,x 2249 C108 cmpb #8 224B 2414 bhs L7 224D ; return task[id].state; 224D E603 ldab 3,x 224F 87 clra 2250 B7C6 xgdy 2252 CC001B ldd #27 2255 1813 emuls 2257 C303BD addd #_task+10 225A B7C6 xgdy 225C E640 ldab 0,y 225E 87 clra 225F 200F bra L6 2261 L7: 2261 ; } 2261 ; else { 2261 ; #ifdef KERNEL_ERROR_MSG 2261 ; puts(error_src[1]); puts(error_msg[3]); 2261 CC02E6 ldd #_error_src+18 2264 163141 jsr _puts 2267 CC0257 ldd #_error_msg+75 226A 163141 jsr _puts 226D ; #endif 226D ; return -1; 226D CCFFFF ldd #-1 2270 L6: 2270 B757 tfr x,s 2272 30 pulx 2273 1B82 leas 2,sp 2275 .dbline 0 ; func end 2275 3D rts 2276 ; id -> 3,x 2276 _get_task_messages:: 2276 3B pshd 2277 34 pshx 2278 B775 tfr s,x 227A ; } 227A ; 227A ; } 227A ; 227A ; 227A ; 227A ; int get_task_messages(unsigned char id) { 227A ; 227A ; if (id < NUMTASKS) { 227A E603 ldab 3,x 227C C108 cmpb #8 227E 2414 bhs L13 2280 ; return task[id].message; 2280 E603 ldab 3,x 2282 87 clra 2283 B7C6 xgdy 2285 CC001B ldd #27 2288 1813 emuls 228A C303C5 addd #_task+18 228D B7C6 xgdy 228F E640 ldab 0,y 2291 87 clra 2292 200F bra L12 2294 L13: 2294 ; } 2294 ; else { 2294 ; #ifdef KERNEL_ERROR_MSG 2294 ; puts(error_src[1]); puts(error_msg[3]); 2294 CC02E6 ldd #_error_src+18 2297 163141 jsr _puts 229A CC0257 ldd #_error_msg+75 229D 163141 jsr _puts 22A0 ; #endif 22A0 ; return -1; 22A0 CCFFFF ldd #-1 22A3 L12: 22A3 B757 tfr x,s 22A5 30 pulx 22A6 1B82 leas 2,sp 22A8 .dbline 0 ; func end 22A8 3D rts 22A9 ; id -> 3,x 22A9 _get_task_priority:: 22A9 3B pshd 22AA 34 pshx 22AB B775 tfr s,x 22AD ; } 22AD ; 22AD ; } 22AD ; 22AD ; 22AD ; 22AD ; int get_task_priority(unsigned char id) { 22AD ; 22AD ; INTR_OFF(); 22AD 1410 sei 22AF 22AF ; 22AF ; if (id < NUMTASKS) { 22AF E603 ldab 3,x 22B1 C108 cmpb #8 22B3 2416 bhs L19 22B5 ; INTR_ON(); 22B5 10EF cli 22B7 22B7 ; return task[id].priority; 22B7 E603 ldab 3,x 22B9 87 clra 22BA B7C6 xgdy 22BC CC001B ldd #27 22BF 1813 emuls 22C1 C303BE addd #_task+11 22C4 B7C6 xgdy 22C6 E640 ldab 0,y 22C8 87 clra 22C9 2011 bra L18 22CB L19: 22CB ; } 22CB ; else { 22CB ; #ifdef KERNEL_ERROR_MSG 22CB ; puts(error_src[1]); puts(error_msg[4]); 22CB CC02E6 ldd #_error_src+18 22CE 163141 jsr _puts 22D1 CC0270 ldd #_error_msg+100 22D4 163141 jsr _puts 22D7 ; #endif 22D7 ; INTR_ON(); 22D7 10EF cli 22D9 22D9 ; return -1; 22D9 CCFFFF ldd #-1 22DC L18: 22DC B757 tfr x,s 22DE 30 pulx 22DF 1B82 leas 2,sp 22E1 .dbline 0 ; func end 22E1 3D rts 22E2 ; ?temp -> -2,x 22E2 ; state -> 7,x 22E2 ; id -> 3,x 22E2 _set_task_state:: 22E2 3B pshd 22E3 34 pshx 22E4 B775 tfr s,x 22E6 1B9E leas -2,sp 22E8 ; } 22E8 ; 22E8 ; } 22E8 ; 22E8 ; 22E8 ; 22E8 ; int set_task_state(unsigned char id, unsigned char state) { 22E8 ; 22E8 ; 22E8 ; INTR_OFF(); 22E8 1410 sei 22EA 22EA ; 22EA ; 22EA ; // check id validity 22EA ; if (id < NUMTASKS) { 22EA E603 ldab 3,x 22EC C108 cmpb #8 22EE 18240151 lbhs L25 22F2 ; 22F2 ; // check state validity 22F2 ; if ((state == running) || 22F2 E607 ldab 7,x 22F4 C102 cmpb #2 22F6 270C beq L30 22F8 E607 ldab 7,x 22FA C103 cmpb #3 22FC 2706 beq L30 22FE E607 ldab 7,x 2300 C104 cmpb #4 2302 2315 bls L27 2304 L30: 2304 ; (state == waiting) || 2304 ; (state > finished)) { 2304 ; #ifdef KERNEL_ERROR_MSG 2304 ; puts(error_src[1]); puts(error_msg[3]); 2304 CC02E6 ldd #_error_src+18 2307 163141 jsr _puts 230A CC0257 ldd #_error_msg+75 230D 163141 jsr _puts 2310 ; #endif 2310 ; INTR_ON(); 2310 10EF cli 2312 2312 ; return -1; 2312 CCFFFF ldd #-1 2315 18200142 lbra L24 2319 L27: 2319 E603 ldab 3,x 231B 87 clra 231C B7C6 xgdy 231E CC001B ldd #27 2321 1813 emuls 2323 C303BD addd #_task+10 2326 B7C6 xgdy 2328 E640 ldab 0,y 232A 87 clra 232B 6C1E std -2,x 232D 2716 beq L37 232F EC1E ldd -2,x 2331 8C0001 cpd #1 2334 18270065 lbeq L48 2338 EC1E ldd -2,x 233A 8C0004 cpd #4 233D 182700B4 lbeq L59 2341 182000EB lbra L33 2345 X0: 2345 ; } 2345 ; 2345 ; switch (task[id].state) { 2345 L37: 2345 ; case idle: 2345 ; if (state == idle) { // no change 2345 E707 tst 7,x 2347 2609 bne L38 2349 ; INTR_ON(); 2349 10EF cli 234B 234B ; return 0; 234B CC0000 ldd #0 234E 18200109 lbra L24 2352 L38: 2352 ; } 2352 ; else if (state == pending) { 2352 E607 ldab 7,x 2354 C101 cmpb #1 2356 2615 bne L40 2358 ; // pass msg to task[id].msgbox; 2358 ; #ifdef KERNEL_ERROR_MSG 2358 ; puts(error_src[1]); puts(error_msg[0]); 2358 CC02E6 ldd #_error_src+18 235B 163141 jsr _puts 235E CC020C ldd #_error_msg 2361 163141 jsr _puts 2364 ; #endif 2364 ; INTR_ON(); 2364 10EF cli 2366 2366 ; return -1; 2366 CCFFFF ldd #-1 2369 182000EE lbra L24 236D L40: 236D ; } 236D ; else if (state == finished) { 236D E607 ldab 7,x 236F C104 cmpb #4 2371 2615 bne L43 2373 ; // pass msg to task[id].msgbox; 2373 ; #ifdef KERNEL_ERROR_MSG 2373 ; puts(error_src[1]); puts(error_msg[0]); 2373 CC02E6 ldd #_error_src+18 2376 163141 jsr _puts 2379 CC020C ldd #_error_msg 237C 163141 jsr _puts 237F ; #endif 237F ; INTR_ON(); 237F 10EF cli 2381 2381 ; return -1; 2381 CCFFFF ldd #-1 2384 182000D3 lbra L24 2388 L43: 2388 ; } 2388 ; else { // nothing else is legalox; 2388 ; #ifdef KERNEL_ERROR_MSG 2388 ; puts(error_src[1]); puts(error_msg[3]); 2388 CC02E6 ldd #_error_src+18 238B 163141 jsr _puts 238E CC0257 ldd #_error_msg+75 2391 163141 jsr _puts 2394 ; #endif 2394 ; INTR_ON(); 2394 10EF cli 2396 2396 ; return -1; 2396 CCFFFF ldd #-1 2399 182000BE lbra L24 239D X1: 239D ; } 239D ; break; 239D L48: 239D ; case pending: 239D ; if (state == pending) { // no change 239D E607 ldab 7,x 239F C101 cmpb #1 23A1 2609 bne L49 23A3 ; INTR_ON(); 23A3 10EF cli 23A5 23A5 ; return 0; 23A5 CC0000 ldd #0 23A8 182000AF lbra L24 23AC L49: 23AC ; } 23AC ; else if (state == idle) { 23AC E707 tst 7,x 23AE 2615 bne L51 23B0 ; // pass msg to task[id].msgbox; 23B0 ; #ifdef KERNEL_ERROR_MSG 23B0 ; puts(error_src[1]); puts(error_msg[0]); 23B0 CC02E6 ldd #_error_src+18 23B3 163141 jsr _puts 23B6 CC020C ldd #_error_msg 23B9 163141 jsr _puts 23BC ; #endif 23BC ; INTR_ON(); 23BC 10EF cli 23BE 23BE ; return -1; 23BE CCFFFF ldd #-1 23C1 18200096 lbra L24 23C5 L51: 23C5 ; } 23C5 ; else if (state == finished) { 23C5 E607 ldab 7,x 23C7 C104 cmpb #4 23C9 2615 bne L54 23CB ; // pass msg to task[id].msgbox; 23CB ; #ifdef KERNEL_ERROR_MSG 23CB ; puts(error_src[1]); puts(error_msg[0]); 23CB CC02E6 ldd #_error_src+18 23CE 163141 jsr _puts 23D1 CC020C ldd #_error_msg 23D4 163141 jsr _puts 23D7 ; #endif 23D7 ; INTR_ON(); 23D7 10EF cli 23D9 23D9 ; return -1; 23D9 CCFFFF ldd #-1 23DC 1820007B lbra L24 23E0 L54: 23E0 ; } 23E0 ; else { 23E0 ; #ifdef KERNEL_ERROR_MSG 23E0 ; puts(error_src[1]); puts(error_msg[3]); 23E0 CC02E6 ldd #_error_src+18 23E3 163141 jsr _puts 23E6 CC0257 ldd #_error_msg+75 23E9 163141 jsr _puts 23EC ; #endif 23EC ; INTR_ON(); 23EC 10EF cli 23EE 23EE ; return -1; 23EE CCFFFF ldd #-1 23F1 18200066 lbra L24 23F5 X2: 23F5 ; } 23F5 ; break; 23F5 L59: 23F5 ; 23F5 ; case finished: 23F5 ; if (state == finished) { // no change 23F5 E607 ldab 7,x 23F7 C104 cmpb #4 23F9 2609 bne L60 23FB ; INTR_ON(); 23FB 10EF cli 23FD 23FD ; return 0; 23FD CC0000 ldd #0 2400 18200057 lbra L24 2404 L60: 2404 ; } 2404 ; else if (state == pending) { 2404 E607 ldab 7,x 2406 C101 cmpb #1 2408 2613 bne L62 240A ; // pass msg to task[id].msgbox; 240A ; #ifdef KERNEL_ERROR_MSG 240A ; puts(error_src[1]); puts(error_msg[0]); 240A CC02E6 ldd #_error_src+18 240D 163141 jsr _puts 2410 CC020C ldd #_error_msg 2413 163141 jsr _puts 2416 ; #endif 2416 ; INTR_ON(); 2416 10EF cli 2418 2418 ; return -1; 2418 CCFFFF ldd #-1 241B 203E bra L24 241D L62: 241D ; } 241D ; else { 241D ; #ifdef KERNEL_ERROR_MSG 241D ; puts(error_src[1]); puts(error_msg[3]); 241D CC02E6 ldd #_error_src+18 2420 163141 jsr _puts 2423 CC0257 ldd #_error_msg+75 2426 163141 jsr _puts 2429 ; #endif 2429 ; INTR_ON(); 2429 10EF cli 242B 242B ; return -1; 242B CCFFFF ldd #-1 242E 202B bra L24 2430 X3: 2430 ; } 2430 ; break; 2430 L33: 2430 ; default: 2430 ; #ifdef KERNEL_ERROR_MSG 2430 ; puts(error_src[1]); puts(error_msg[3]); 2430 CC02E6 ldd #_error_src+18 2433 163141 jsr _puts 2436 CC0257 ldd #_error_msg+75 2439 163141 jsr _puts 243C ; #endif 243C ; INTR_ON(); 243C 10EF cli 243E 243E ; return -1; 243E CCFFFF ldd #-1 2441 2018 bra L24 2443 X4: 2443 ; break; 2443 L25: 2443 ; 2443 ; } // end switch (task[id].state) 2443 ; 2443 ; } // if 2443 ; 2443 ; else { 2443 ; #ifdef KERNEL_ERROR_MSG 2443 ; puts(error_src[1]); puts(error_msg[2]); 2443 CC02E6 ldd #_error_src+18 2446 163141 jsr _puts 2449 CC023E ldd #_error_msg+50 244C 163141 jsr _puts 244F ; #endif 244F ; INTR_ON(); 244F 10EF cli 2451 2451 ; return -1; 2451 CCFFFF ldd #-1 2454 2005 bra L24 2456 X5: 2456 ; } 2456 ; 2456 ; INTR_ON(); 2456 10EF cli 2458 2458 ; return 0; 2458 CC0000 ldd #0 245B L24: 245B B757 tfr x,s 245D 30 pulx 245E 1B82 leas 2,sp 2460 .dbline 0 ; func end 2460 3D rts 2461 ; priority -> 7,x 2461 ; id -> 3,x 2461 _set_task_priority:: 2461 3B pshd 2462 34 pshx 2463 B775 tfr s,x 2465 ; 2465 ; } 2465 ; 2465 ; 2465 ; 2465 ; int set_task_priority(unsigned char id, unsigned char priority) { 2465 ; 2465 ; if (priority == 0) // priority 0 is reserved for the shell 2465 E707 tst 7,x 2467 2604 bne L72 2469 ; priority = 1; 2469 C601 ldab #1 246B 6B07 stab 7,x 246D L72: 246D ; 246D ; if (id >= (NUMTASKS)) { 246D E603 ldab 3,x 246F C108 cmpb #8 2471 2511 blo L74 2473 ; #ifdef KERNEL_ERROR_MSG 2473 ; puts(error_src[1]); puts(error_msg[4]); 2473 CC02E6 ldd #_error_src+18 2476 163141 jsr _puts 2479 CC0270 ldd #_error_msg+100 247C 163141 jsr _puts 247F ; #endif 247F ; return -1; 247F CCFFFF ldd #-1 2482 2031 bra L71 2484 L74: 2484 E607 ldab 7,x 2486 C1FF cmpb #255 2488 2204 bhi L80 248A E707 tst 7,x 248C 2411 bhs L78 248E L80: 248E ; } 248E ; else if ((priority > 255) || (priority < 0)) { 248E ; #ifdef KERNEL_ERROR_MSG 248E ; puts(error_src[1]); puts(error_msg[4]); 248E CC02E6 ldd #_error_src+18 2491 163141 jsr _puts 2494 CC0270 ldd #_error_msg+100 2497 163141 jsr _puts 249A ; #endif 249A ; return -1; 249A CCFFFF ldd #-1 249D 2016 bra L71 249F L78: 249F ; } 249F ; else { 249F ; task[id].priority=priority; 249F E603 ldab 3,x 24A1 87 clra 24A2 B7C6 xgdy 24A4 CC001B ldd #27 24A7 1813 emuls 24A9 C303BE addd #_task+11 24AC B7C6 xgdy 24AE E607 ldab 7,x 24B0 6B40 stab 0,y 24B2 ; return 0; 24B2 CC0000 ldd #0 24B5 L71: 24B5 B757 tfr x,s 24B7 30 pulx 24B8 1B82 leas 2,sp 24BA .dbline 0 ; func end 24BA 3D rts 24BB ; rid -> 3,x 24BB _get_resource_state:: 24BB 3B pshd 24BC 34 pshx 24BD B775 tfr s,x 24BF ; } 24BF ; } 24BF ; 24BF ; 24BF ; 24BF ; 24BF ; int get_resource_state(unsigned char rid) { 24BF ; 24BF ; if (rid < NUMRESOURCES) { 24BF E603 ldab 3,x 24C1 C10B cmpb #11 24C3 2414 bhs L85 24C5 ; return resource[rid].state; 24C5 E603 ldab 3,x 24C7 87 clra 24C8 B7C6 xgdy 24CA CC000C ldd #12 24CD 1813 emuls 24CF C30335 addd #_resource+6 24D2 B7C6 xgdy 24D4 E640 ldab 0,y 24D6 87 clra 24D7 200F bra L84 24D9 L85: 24D9 ; } 24D9 ; else { 24D9 ; #ifdef KERNEL_ERROR_MSG 24D9 ; puts(error_src[1]); puts(error_msg[6]); 24D9 CC02E6 ldd #_error_src+18 24DC 163141 jsr _puts 24DF CC02A2 ldd #_error_msg+150 24E2 163141 jsr _puts 24E5 ; #endif 24E5 ; return -1; 24E5 CCFFFF ldd #-1 24E8 L84: 24E8 B757 tfr x,s 24EA 30 pulx 24EB 1B82 leas 2,sp 24ED .dbline 0 ; func end 24ED 3D rts 24EE ; rid -> 3,x 24EE _get_resource_owner:: 24EE 3B pshd 24EF 34 pshx 24F0 B775 tfr s,x 24F2 ; } 24F2 ; 24F2 ; } 24F2 ; 24F2 ; 24F2 ; 24F2 ; 24F2 ; 24F2 ; int get_resource_owner(unsigned char rid) { 24F2 ; 24F2 ; if (rid < NUMRESOURCES) { 24F2 E603 ldab 3,x 24F4 C10B cmpb #11 24F6 2414 bhs L91 24F8 ; return resource[rid].owner; 24F8 E603 ldab 3,x 24FA 87 clra 24FB B7C6 xgdy 24FD CC000C ldd #12 2500 1813 emuls 2502 C30336 addd #_resource+7 2505 B7C6 xgdy 2507 E640 ldab 0,y 2509 87 clra 250A 200F bra L90 250C L91: 250C ; } 250C ; else { 250C ; #ifdef KERNEL_ERROR_MSG 250C ; puts(error_src[1]); puts(error_msg[6]); 250C CC02E6 ldd #_error_src+18 250F 163141 jsr _puts 2512 CC02A2 ldd #_error_msg+150 2515 163141 jsr _puts 2518 ; #endif 2518 ; return -1; 2518 CCFFFF ldd #-1 251B L90: 251B B757 tfr x,s 251D 30 pulx 251E 1B82 leas 2,sp 2520 .dbline 0 ; func end 2520 3D rts 2521 ; rid -> 3,x 2521 _get_resource_queuelen:: 2521 3B pshd 2522 34 pshx 2523 B775 tfr s,x 2525 ; } 2525 ; 2525 ; } 2525 ; 2525 ; 2525 ; 2525 ; 2525 ; int get_resource_queuelen(unsigned char rid) { 2525 ; 2525 ; if (rid < NUMRESOURCES) { 2525 E603 ldab 3,x 2527 C10B cmpb #11 2529 2414 bhs L97 252B ; return resource[rid].queue_ptr; 252B E603 ldab 3,x 252D 87 clra 252E B7C6 xgdy 2530 CC000C ldd #12 2533 1813 emuls 2535 C3033A addd #_resource+11 2538 B7C6 xgdy 253A E640 ldab 0,y 253C 87 clra 253D 200F bra L96 253F L97: 253F ; } 253F ; else { 253F ; #ifdef KERNEL_ERROR_MSG 253F ; puts(error_src[1]); puts(error_msg[6]); 253F CC02E6 ldd #_error_src+18 2542 163141 jsr _puts 2545 CC02A2 ldd #_error_msg+150 2548 163141 jsr _puts 254B ; #endif 254B ; return -1; 254B CCFFFF ldd #-1 254E L96: 254E B757 tfr x,s 2550 30 pulx 2551 1B82 leas 2,sp 2553 .dbline 0 ; func end 2553 3D rts 2554 ; last -> -6,x 2554 ; memory -> -4,x 2554 ; i -> -2,x 2554 _get_free_memory:: 2554 34 pshx 2555 B775 tfr s,x 2557 1B98 leas -8,sp 2559 ; } 2559 ; 2559 ; } 2559 ; 2559 ; 2559 ; 2559 ; 2559 ; int get_free_memory(void) { 2559 CC0000 ldd #0 255C 6C1E std -2,x 255E L103: 255E ; 255E ; // LOCAL VARIABLES 255E ; char *memory, *last; 255E ; int i; 255E ; 255E ; 255E ; // check for largest free memory block 255E ; for (i=0; i 25A4 ; #include "kernel.h" 25A4 ; 25A4 ; 25A4 ; 25A4 ; void _HC12Setup(void) { 25A4 ; 25A4 ; // set the register base to 0x800 25A4 ; //*(volatile unsigned char *)0x0011 = 0x08; 25A4 ; 25A4 ; } 25A4 L3: 25A4 .dbline 0 ; func end 25A4 3D rts