;TTERS51G.ASM -- tiny-Tiny Embedded Real-time Software Environment. ;This version is for the 8051 family. ;This is the single-processor cut-down "G" version. ;This version has a modified "extractmsgs" for performance. $MOD51 ;config. info for Metalink assembler. DSEG ORG 2Dh flags: DS 1 ;flags.1,2,3,4 = 1, msg on terminal-1, -2, -3, -4. pdata1: DS 1 data1: DS 5 ;reserve 5 bytes. pdata2: DS 1 data2: DS 5 ;reserve 5 bytes. pdata3: DS 1 data3: DS 5 ;reserve 5 bytes.(end is address 3Fh) ;.................................................... CSEG START: ajmp start1 ;reset entry point. ;leave space for isrs.... ORG 32h emptyst EQU 07 numentries EQU 5 signatures: DB 255, 0,08,22,152 ;starting node has signature=zero. nodenum: DB 0, 1, 2, 3, 4 nodeptr: ;these occupy 2 bytes each. ajmp node0 ;1st node in table is error-handler(always node-0). ajmp node1 ;this must be in ascending order ajmp node2 ;of node number. ajmp node3 ; ajmp node4 ;..... ;msgs will always be two bytes... POSTMSG MACRO node,term,notif,datavalue IF ((node >= 0) AND (node <= 31)) IF ((term > 0) AND (term <= 4)) IF ((notif = 0) OR (notif = 1)) mov b,datavalue push b mov b,#(node + ((term-1)*32) + (notif*128)) push b ENDIF ENDIF ENDIF POSTMSG ENDM ;note that TERM is stored one-less. EX: TERM-1 is stored as 00. ;Headerformat: bit7=notif, 5-6=term, 0-4=node. NORMALEXIT MACRO ;use this one for normal operation. ajmp nodereturn NORMALEXIT ENDM FASTEXIT MACRO nextnode ;bypasses signature calc. & lookup, mov r5,#nextnode ; if you know the next node. ajmp gonode FASTEXIT ENDM ;........................................................................ ;*****MAIN LOOP******* start1: ;program entry point 1. mov pdata1,#data1 ;initalise pointers, to buffers empty. mov pdata2,#data2 ;/ mov pdata3,#data3 ;/ ajmp start2 nodereturn: start2: ;program entry point 2. mov r2,#0 ;initially, make signature = zero. ;calculate the signature.... mov r0,sp ;save initial sp. loop3: cjne r0,#emptyst,loop2 ajmp sigout loop2: mov a,@r0 ;get 1st byte of msg. mov r1,a ;save it for calcsig. dec r0 ;go past Header. dec r0 ;bypass the data. jb acc.7,loop3 ;ignore notifications. calcsig: ;entered with r1=msg-header, r2=accumulated signature (starts =0) mov a,r2 jnb acc.7,sig1 ;jump if bit a.7 is clear. xrl a,#00100001b ;tapping points. sig1: xrl a,r1 rl a mov r2,a ajmp loop3 sigout: ;if comes out of above, with sig=0, diagram will restart, as must be ;complete... lookup: ;signature in r2, use lookup table to get address of node... mov r0,#numentries mov dptr,#signatures loop1: mov a,r0 dec a movc a,@a+dptr ;start at end of array. xrl a,r2 ;compare signatures jz gotonode ;signature found. no2: djnz r0,loop1 ;...sig. not found.... inc r0 ;make r0=1. (r0= lookup-index + 1). sigfnd: gotonode: mov dptr,#nodenum ;get node number. mov a,r0 ; / dec a ; / movc a,@a+dptr ; / mov r5,a ; / -->r5 gonode: anl flags,#11100001b ;bits 1-4 set by extractmsgs... ajmp extractmsgs ;extracts all msgs for this node.(comes back main1: ; here)(preserves r5) mov dptr,#nodeptr mov a,r5 rl a ;*2 --each entry is 2 bytes. jmp @a+dptr ;jump to next node to execute. ;r5 = node-number.(0--> ). ;.... ;*****END MAIN LOOP***** ;......................................................................... extractmsgs: ;entered with r5=node-number (0 --> 31, node-0 = 0, etc) ;extracts all msgs for this node-->r1,r2,... first-bank of registers, ;where r1 is terminal-1, etc. Dumps msg-header. mov r0,sp rex1: cjne r0,#emptyst,ex2 ajmp main1 ;*get out*>>>>>>>> ex2: mov a,@r0 ;get msg header. anl a,#1Fh ;extract node. cjne a,05,ex3 ;test if required node. mov a,@r0 ;yes. dec r0 anl a,#60h ;extract term cjne a,#0,nxt1 ;test if term1 mov 01,@r0 setb flags.1 ajmp ex4 nxt1: cjne a,#20h,nxt2 ;test if term2 mov 02,@r0 setb flags.2 ajmp ex4 nxt2: cjne a,#40h,nxt3 ;test if term3 mov 03,@r0 setb flags.3 ajmp ex4 nxt3: mov 04,@r0 ;term4 setb flags.4 ex4: pop acc ;move top msg down to fill gap. pop b mov @r0,b inc r0 mov @r0,a ex3: dec r0 dec r0 ajmp rex1 ;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ ;a node is entered with r5 (address 05) = node number. ;(first register-bank selected, as rest used by stack, so r1 is addr.01,etc) ;msgs are in terminal-order, in addresses 01,02,03,04. ;bit-addressable "flags" has bits set if msg present ; -- example, msg in term1 (addr.01, or r1), then flags.1 is set. ;................. node0: ;node-0 is the error-handler NORMALEXIT ;................................................................... node1: POSTMSG 2,1,0,#34h ;node-2,term-1,not-notif.,immediate-data. POSTMSG 3,1,0,#00h ;node3,term1,notnotif,immediate-data. NORMALEXIT ;................................................................... node3: POSTMSG 4,2,0,32h ;node4,term2,notnotif,direct-data. NORMALEXIT ;.................................................................. node2: jnb flags.2,n22 ;...notification is in r1 n22: POSTMSG 4,1,0,#00h ;node4,term1,0,immediate-data. NORMALEXIT ;................................................................... node4: POSTMSG 2,2,1,#11 ;notification, back to node-2,term-2. NORMALEXIT ;................ ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ;COPYRIGHT & LIABILITY NOTICE ;**************************** ;This product may be freely used and adapted, however acknowledgement ;must always be given to myself, Barry Kauler, as the originator of the principles. ;The name TERSE may be used, with pre and postfixes to identify ;individual products, with acknowledgement to me. ;Any derivative product, that uses the principles employed in TERSE, ;such as the Signature Scheduling, must acknowledge me. ;Also, any use of TERSE, or derivative from TERSE, must acknowledge ;at least one reference publication about TERSE and written by me and ;my Web site. ;I accept no liability for how this product performs. ;(c) Copyright Barry Kauler 1995 ;email: B.KAULER@COWAN.EDU.AU ;WWW: http://scorpion.cowan.edu.au/science/terse/terse.htm ;................................................................... END