; ComtAPI.inc - Macro Defintions for the COMATOS Calls ; Copyright 1999 Benjamin M. Greenblatt (11/3/99) .include "comatos.inc" ; OSInit: Initializes OS constants ; ; Arguments ; OSMaxTimeout (2 byte constant), debug (either OSDebug or OSNoDebug) .macro OSInit push OSTempH push OSTempL push OSTempG ldi OSTempH, high(@0) ldi OSTempL, low(@0) ldi OSTempG, @1 rcall OSInitF pop OSTempG pop OSTempL pop OSTempH .endmacro ; OSStart: Begins execution of the scheduler ; ; Arguments ; none .macro OSStart sei ; Enable interrupts rjmp OSScheduler .endmacro ; OSCreateTask: Sets up a task and create a PCB for it ; ; Arguments ; EntryPoint, Timeout, MessageMask ; ; NOTE: If you choose not to use the message mask and only rely on ; timeouts, set MessageMask to 0xff .macro OSCreateTask push OSTempH push OSTempL push OSAddrRegH push OSAddrRegL ldi OSAddrRegH, high(@0) ldi OSAddrRegL, low(@0) ldi OSTempH, @1 ldi OSTempL, @2 rcall OSCreateTaskF pop OSAddrRegL pop OSAddrRegH pop OSTempL pop OSTempH .endmacro ; OSPCBZ: Puts the current PCB address in Z ; ; Arguments ; none .macro OSPCBZ lds ZH, OSBase+OSCurrPCBH lds ZL, OSBase+OSCurrPCBL .endmacro ; OSHextoAscY: Converts a hex byte into an ascii string and stores ; in the location pointed to by Y ; ; Arguments ; Rs (Source register) (Y is implicit) .macro OSHextoAscY push OSTempG mov OSTempG, @0 rcall OSHextoAscYF pop OSTempG .endmacro ; OSUARTWait: Starts transmission and then waits for the completion signal ; Returns when transmission is done ; ; Arguments ; Rs (Source register containing first character to send) .macro OSUARTWait push OSDumpReg lds OSDumpReg, OSBase+OSStatus cbr OSDumpReg, exp2(txdone) ; Clear the bit indicating txdone sts OSBase+OSStatus, OSDumpReg pop OSDumpReg push OSDumpReg ; Get the original value back mov OSDumpReg, @0 rcall OSUARTWaitF pop OSDumpReg .endmacro ; OSGetMessageSrc: Returns the byte representing who sent the current task ; a message ; Arguments ; Rd (destination register) .macro OSGetMessageSrc push OSTempG rcall OSGetMessageSrcF mov @0, OSTempG ; Store result in proper register pop OSTempG .endmacro ; OSGetAck: Returns the current processes ackbyte ; ; Arguments ; Rd (destination register) .macro OSGetAck push OSTempG rcall OSGetAckF mov @0, OSTempG pop OSTempG .endmacro ; OSSendAck: Sets the current process' ack bit in the target process' ack byte ; ; Arguments ; TargetProcess (constant) .macro OSSendAck push OSTempG ldi OSTempG, @0 rcall OSSendAckF pop OSTempG .endmacro ; OSSetOwnAck: Sets the current process' ackbyte ; ; Arguments ; Rs (register containing the new contents of ackbyte) .macro OSSetOwnAck push ZH push ZL lds ZH, OSBase+OSCurrPCBH lds ZL, OSBase+OSCurrPCBL std Z+PCBAck, @0 ; Write the new ackbyte to memory pop ZL pop ZH .endmacro ; OSGetMess: Gets a message sent to the current process ; ; Arguments ; Rd (destination register), sender (constant processId of the sender) ; NOTE: Do not use registers r16-r18 for Rd .macro OSGetMess push OSTempG push OSTempH ldi OSTempH, @1 ; Put the sender's pid in a register rcall OSGetMessF mov @0, OSTempG pop OSTempH pop OSTempG .endmacro ; OSSendMess: Sends a message to the specified task ; ; Arguments ; Rs (register containing the message), task (constant pid of the target task) .macro OSSendMess push OSTempG push OSTempH push OSTempL mov OSTempG, @0 ldi OSTempL, @1 lds OSTempH, OSBase+OSCurrentTask rcall OSSendMessF pop OSTempL pop OSTempH pop OSTempG .endmacro ; ISRSendMess: Called by an ISR to send a message ; ; Arguments ; Rs (register containing the message), task (constant pid of the target), sender (constant pid of the sender ISR) .macro ISRSendMess push OSTempG push OSTempH push OSTempL mov OSTempG, @0 ldi OSTempL, @1 ldi OSTempH, @2 rcall OSSendMessF pop OSTempL pop OSTempH pop OSTempG .endmacro ; OSGetState: Gets the state byte for the current task ; ; Arguments ; Rd (destination register) .macro OSGetState push ZH push ZL lds ZH, OSBase+OSCurrPCBH lds ZL, OSBase+OSCurrPCBL ; Aim Z at the current PCB ldd @0, Z+PCBState ; Pull in the state pop ZL pop ZH .endmacro ; OSSetState: Sets the state byte for the current task ; ; Arguments ; state (Constant) .macro OSSetState push ZH push ZL push OSTempG lds ZH, OSBase+OSCurrPCBH lds ZL, OSBase+OSCurrPCBL ; Aim Z at the current PCB ldi OSTempG, @0 std Z+PCBState, OSTempG ; Write the new state pop OSTempG pop ZL pop ZH .endmacro ; OSSetTimeout: Changes the current tasks timeout value ; ; Arguments ; Rs (register) .macro OSSetTimeout push OSTempG mov OSTempG, @0 rcall OSSetTimeoutF pop OSTempG .endmacro ; OSSetMessMask: Indicates which tasks this task is waiting on ; ; Arguments ; mask (constant) .macro OSSetMessMask push OSTempG ldi OSTempG, @0 rcall OSSetMessMaskF pop OSTempG .endmacro ; OSReturn: Returns from the current task ; ; Arguments: ; retCode (constant) .macro OSReturn push OSTempG ldi OSTempG, @0 sts OSBase+OSReturnVal, OSTempG pop OSTempG ret .endmacro ; OSRegDump: Dumps the register contents to the UART ; ; Arguments: ; none .macro OSRegDump rcall OSRegDumpF .endmacro ; OSSetEntryPt ; ; Arguments ; entry (2 byte constant) .macro OSSetEntryPt push OSTempL push OSTempH ldi OSTempH, high(@0) ldi OSTempL, low(@0) rcall OSSetEntryPtF pop OSTempH pop OSTempL .endmacro