home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 2 / RISC_DISC_2.iso / pd_share / program / language / motasm / examples_hc11_as11_SYSTEM < prev    next >
Encoding:
Text File  |  1995-05-13  |  23.4 KB  |  410 lines

  1. *SYSTEM.AS                                                                   *
  2. *******************************************************************************
  3. *                                                                            *
  4. *                         SYSTEM CONFIGURATION                               *
  5. *                                                                            *
  6. * This information must be entered by the user to define the configuration of *
  7. * the system. These equates are used to define the extents of the MCX11       *
  8. * system tables. THIS FILE MUST BE THE FILE NAMED IN THE ASSEMBLY COMMAND     *
  9. * LINE. It may be named anything the user wishes. Remember that AS11 names    *
  10. * S-Record object file after the first file name encountered in the assembly  *
  11. * command.                                                                    *
  12. *                                                                            *
  13. *******************************************************************************
  14. *                                                                            *
  15. *                            APPLICATION EQUATES                             *
  16. *   (These VALUES should be changed for your application where indicated)    *
  17. *                                                                            *
  18. *   DO NOT CHANGE THE SYMBOL NAMES BECAUSE THEY ARE USED THROUGHOUT MCX11    *
  19. *                                                                            *
  20. *******************************************************************************
  21.  
  22. *******************************************************************************
  23. *                     BASIC CONFIGURATION DATA EQUATES                       *
  24. *                These should change for your application                    *
  25. *******************************************************************************
  26.  
  27. NTASKS equ    5                   Number of tasks in system
  28. NQUEUES equ    2                   Number of queues in system
  29. NNAMSEM equ    8                   Number of named semaphores in system
  30. NTIMERS equ    3                   Number of timers in system
  31.  
  32. *******************************************************************************
  33. *                           SYSTEM MEMORY EQUATES                            *
  34. *                These should change for your application                    *
  35. *******************************************************************************
  36.  
  37. MCXVAR equ    $EF                 Base RAM address of MCX variables (17 bytes
  38. *                                  are needed. For example, $ef - $ff)
  39. MCX11  equ    $E000               Base ROM address for MCX11
  40. MCXTABL equ    MCXVAR-1            Base RAM address of MCX system tables
  41.  
  42. *******************************************************************************
  43. *                          CLOCK AND PRESET EQUATES                          *
  44. *                These should change for your application                    *
  45. *******************************************************************************
  46.  
  47. TMSK2  equ    $1024
  48. TFLG2  equ    TMSK2+1
  49. PACTL  equ    TFLG2+1
  50. RTII   equ    $40                 RTI Interrupt enabled, prescale = 00
  51. RTR    equ    $02                 16.37 ms per TICK @ 8MHz
  52. RTIF   equ    $40
  53. TOCK   equ    3                   3 TICKs per TOCK (TOCK = 49.14 ms ~ 20 Hz)
  54.  
  55. *******************************************************************************
  56. *                             MCX11  EQUATES                                 *
  57. *                     (These should not be changed)                          *
  58. *******************************************************************************
  59.  
  60. TCBLEN equ    5                   Length of a Task Control Block
  61. TIMRLEN equ    8                   Length of a Timer Block
  62. QHDRLEN equ    3                   Length of a Queue Header
  63.  
  64. *******************************************************************************
  65. *                           SYSTEM TABLE EQUATES                             *
  66. *                     (These should not be changed)                          *
  67. *******************************************************************************
  68.  
  69. NT     equ    NTIMERS*TIMRLEN
  70. TIMERS equ    MCXTABL-NT          Base address of timer blocks
  71. NQ     equ    NQUEUES*QHDRLEN
  72. QHDRTBL equ    TIMERS-NQ           Base address of queue headers
  73. NQS    equ    NQUEUES*2
  74. FLGTBL equ    QHDRTBL-NNAMSEM-NTASKS-NQS  Base address of semaphores
  75. NTS    equ    NTASKS*TCBLEN
  76. STATLS equ    FLGTBL-NTS-TCBLEN   Base address of Task Control Blocks (TCB)
  77. QBODBAS equ    STATLS-1            Last address of Queue Bodies
  78.  
  79. *******************************************************************************
  80. *                  TCB INITIALIZATION DATA BLOCK EQUATES                     *
  81. *                     (These should not be changed)                          *
  82. *******************************************************************************
  83.  
  84. INITST equ    0                   Task STATE at system initialization
  85. STRTADR equ    1                   Task starting address
  86. RSTSP  equ    3                   *Base address of task@@s stack
  87. TCBADDR equ    5                   Address of task@@s TCB
  88. TCBDATL equ    7                   Length of a TCB initialization data block
  89.  
  90. *******************************************************************************
  91. *                 QUEUE INITIALIZATION DATA BLOCK EQUATES                    *
  92. *                     (These should not be changed)                          *
  93. *******************************************************************************
  94.  
  95. WIDTH  equ    0                   Width of the queue entry
  96. DEPTH  equ    1                   Depth of queue (# of entries)
  97. QHADR  equ    2                   Queue Header address
  98. QADDR  equ    4                   Address of the Queue Body
  99. QUEDATL equ    6                   Length of a Queue initialization data block
  100.  
  101. *******************************************************************************
  102. *   MCX ESR equates                                                          *
  103. *******************************************************************************
  104.  
  105. .wait.  equ   1                   Wait for an event to occur
  106. .signal. equ   2                   Signal the occurence of an event
  107. .pend.  equ   3                   Set a semaphore to PENDing state
  108. .send.  equ   4                   Send a message to a task
  109. .sendw. equ   5                   Send a message and wait for response
  110. .receive. equ   6                  Receive a message
  111. .deque. equ   7                   Dequeue an entery from a FIFO queue
  112. .enque. equ   8                   Enqueue an entry into a FIFO queue
  113. .resume. equ   9                   Resume a suspended task
  114. .suspend. equ   10                 Suspend a task
  115. .terminate. equ   11               Terminate a task
  116. .execute. equ   12                 Execute a task
  117. .delay. equ   13                  Delay a task for a period of time
  118. .timer. equ   14                  Set up a timer
  119. .purge. equ   15                  Purge active timer(s)
  120.  
  121. *******************************************************************************
  122. *                                                                            *
  123. *                TASK AND QUEUE INITIALIZATION DATA BLOCKS                   *
  124. *                These should change for your application                    *
  125. *                                                                            *
  126. * The next section contains the initialization data blocks for the TCB@@s and  *
  127. * the queues. The user should construct these tables as they define such data *
  128. * as queue sizes, task starting addresses, and stack sizes.                   *
  129. *                                                                            *
  130. *******************************************************************************
  131. *******************************************************************************
  132. *                     QUEUE INITIALIZATION DATA BLOCKS                       *
  133. *                           These must be in ROM                             *
  134. *             (Do Queue definitions before Task definitions)                 *
  135. *******************************************************************************
  136.  
  137.         ORG MCX11
  138.  
  139. QUEDATA equ    *                   Queue data (This must come first)
  140.  
  141. *******************************************************************************
  142. *                THESE ARE LOCAL SYMBOLS AND CAN BE CHANGED                  *
  143. *******************************************************************************
  144.  
  145.  
  146. Q1W    equ    1                   Queue 1 width
  147. Q1D    equ    8                   Queue 1 depth
  148. Q1SIZ  equ    Q1W*Q1D             Queue 1 size
  149. Q1BODY equ    QBODBAS-Q1SIZ+1     Address of Queue 1 body
  150. Q1HDR  equ    QHDRTBL             Address of Queue 1 Header
  151.         FCB   Q1W,Q1D             WIDTH,DEPTH
  152.         FDB   Q1HDR,Q1BODY        QHADR,QADDR
  153.  
  154. Q2W    equ    5                   Queue 2 width
  155. Q2D    equ    1                   Queue 2 depth
  156. Q2SIZ  equ    Q2W*Q2D             Queue 2 size
  157. Q2BODY equ    Q1BODY-Q2SIZ        Address of Queue 2 body
  158. Q2HDR  equ    Q1HDR+QHDRLEN       Address of Queue 1 Header
  159.         FCB   Q2W,Q2D             WIDTH,DEPTH
  160.         FDB   Q2HDR,Q2BODY        QHADR,QADDR
  161.  
  162. *******************************************************************************
  163. STKBASE equ    Q2BODY-1            Base address of all stacks. This is defined
  164. *                                   as the address of the last queue body - 1.
  165. *******************************************************************************
  166.  
  167. *******************************************************************************
  168. *                      TASK INITIALIZATION DATA BLOCKS                       *
  169. *                                                                            *
  170. *               (Do Task Definitions after Queue definitions)                *
  171. *******************************************************************************
  172.  
  173. TCBDATA equ    *                   Task data
  174.  
  175. *******************************************************************************
  176. *                THESE ARE LOCAL SYMBOLS AND CAN BE CHANGED                  *
  177. *******************************************************************************
  178. * You must define certain information about the tasks in your application.    *
  179. * The information MUST be supplied in the following sequence:                 *
  180. *                                                                            *
  181. *     1. Initial status of the task at Power-up                              *
  182. *     2. The starting address of the task                                    *
  183. *     3. The base address of the stack for the task                          *
  184. *     4. The TCB address of the task (This is redundant but it saves time)   *
  185. *                                                                            *
  186. * The TCB address, the base address of the stack, and the stack size can be   *
  187. * defined through equates and used in the definitions. REMEMBER, If you are   *
  188. * using an HC11 EVB, you must make the stack size for each task AT LEAST 18   *
  189. * bytes to accomodate the breakpoint mechanism.                               *
  190. *                                                                            *
  191. *                          --- N O T E ---                                   *
  192. *                                                                            *
  193. * In normal usage, MCX will have the clock driver as task number 1. That      *
  194. * it the highest priority task in the system and assures the best timing. You *
  195. * may change it to another if you wish, but it may not provide accurate time  *
  196. * measurement if it can be preempted by another task. It is strongly urged    *
  197. * that you always make task 1 the clock driver if your application is to use  *
  198. * a time base.                                                                *
  199. *******************************************************************************
  200.  
  201. TASK1  equ    STATLS              Task1 TCB address (Task 1 = CLOCK DRIVER)
  202. STAK1  equ    STKBASE             Base address of task 1 stack
  203. STK1SIZ equ    18                  Size of stack for task 1
  204.         FCB   0                   INITST is RUN
  205.         FDB   clkdrv,STAK1,TASK1  STRTADR,RSTSP,TCBADDR
  206.  
  207. TASK2  equ    TASK1+TCBLEN        Task 2 TCB address
  208. STAK2  equ    STAK1-STK1SIZ       Base address of task 2 stack
  209. STK2SIZ equ    23                  Size of stack for task 2
  210.         FCB   0                   INITST is RUN
  211.         FDB   $0002,STAK2,TASK2   STRTADR,RSTSP,TCBADDR
  212.  
  213. TASK3  equ    TASK2+TCBLEN        Task 3 TCB address
  214. STAK3  equ    STAK2-STK2SIZ       Base address of task 3 stack
  215. STK3SIZ equ    21                  Stack size for task 3
  216.         FCB   _IDLE               INITST
  217.         FDB   $0003,STAK3,TASK3   STRTADR,RSTSP,TCBADDR
  218.  
  219. TASK4  equ    TASK3+TCBLEN        Task 4 TCB address
  220. STAK4  equ    STAK3-STK3SIZ       Base address of task 4 stack
  221. STK4SIZ equ    18                  Stack size for task 4
  222.         FCB   _IDLE               INITST
  223.         FDB   $0004,STAK4,TASK4   STRTADR,RSTSP,TCBADDR
  224.  
  225. TASK5  equ    TASK4+TCBLEN        Task 5 TCB address
  226. STAK5  equ    STAK4-STK4SIZ       Base address of task 5 stack
  227. STK5SIZ equ    18                  Stack size for task 5
  228.         FCB   _IDLE               INITST
  229.         FDB   $0005,STAK5,TASK5   STRTADR,RSTSP,TCBADDR
  230.  
  231. *******************************************************************************
  232. * Now that the tasks are all defined, all that is left is the definition of   *
  233. * the base address of the system stack. It should be located 18 bytes below   *
  234. * the top of the stack area for the last task defined above. The 18 bytes are *
  235. * there for the stack for the null task.                                      *
  236. *******************************************************************************
  237.  
  238. SYSTACK equ    STAK5-STK5SIZ-18    Base address of system stack.
  239.  
  240. *******************************************************************************
  241. *******************************************************************************
  242. *******************************************************************************
  243.  
  244. nulltsk bra    *                   This is the null task. It is always runnable
  245. *                                   and always interruptable. It does nothing
  246. *                                   except provide an active task for the
  247. *                                   Dispatcher when all other tasks are busy.
  248. *                                 You may change this any way you wish as long
  249. *                                   it is never put into a non-ready state.
  250.  
  251. *******************************************************************************
  252. *******************************************************************************
  253. *******************************************************************************
  254. *                                                                            *
  255. *                           MCX11 INITIALIZATION                             *
  256. *                                                                            *
  257. * This is the MCX11 Initialization routine in which all of the 68HC11 RAM and *
  258. * internal registers get initialized. This routine is entered upon a Power On *
  259. * RESET; therefore the first 64 cycles must be spent initializing those areas *
  260. * of the 68HC11 control register space which must be set up during that brief *
  261. * period. Then all of the system tables must be set to their initial content. *
  262. * The user should also include any initialization operatons unique to his own *
  263. * application. Upon completion, the routine should jump to the start of the   *
  264. * MCX11 Dispatcher at lable "dispch".                                         *
  265. *                                                                            *
  266. *******************************************************************************
  267.  
  268. *******************************************************************************
  269. *    Put the special startup code here which must be done within the first   *
  270. *    64 cycles after Power-on/Reset & set up the internal registers with     *
  271. *    respect to the application requirements.                                *
  272. *******************************************************************************
  273.  
  274. mcxinit equ    *                   This is MCX11 entry point
  275.         lds   #SYSTACK
  276.         ldaa  #RTII
  277.         staa  TMSK2               Enable RTI Interrupt
  278.         ldaa  #RTR
  279.         staa  PACTL               Set up RTI clock rate
  280.  
  281. *******************************************************************************
  282. *                                                                            *
  283. * The following instruction is included for use with an EVM board. If you are *
  284. * going to want to initialize the EVM in such a manner that the MPU will use  *
  285. * the first 64 cycles to initialize the control registers, leave this one     *
  286. * instruction in place and perform the following startup procedure:           *
  287. *                                                                            *
  288. *           1. Press the USER RESET button on EVM board.
  289. *           2. Press ABORT SWITCH on EVM board.
  290. *           3. Ignore any ERROR MESSAGE from the EVM and press ENTER on your *
  291. *              debug console@@s keyboard. This should show the Register set.  *
  292. *           4. Change the content of Stack Pointer Register to legal value   *
  293. *           5. Start the program with a G command at the address of @@mcxgo@@. *
  294. *                                                                            *
  295. * If this is not used on an EVM board, and a normal RESET sequence is desired *
  296. * simply remove the following instruction.
  297. *                                                                            *
  298. *******************************************************************************
  299.  
  300.         bra    *                  Just wait for the ABORT.
  301.  
  302. *******************************************************************************
  303. * The second job in the initialization process is to link all of the system   *
  304. * timer blocks. The address of the first timer block is stored in the word    *
  305. * in RAM labled "FREE". The word labled "ACTIVE" is set to a 0.               *
  306. *******************************************************************************
  307.  
  308. mcxgo  ldaa   #TOCK
  309.         staa  tickcnt             Set up Tick counter
  310.         ldy   #NTIMERS            Set up counter for the number of timers
  311.         ldd   #TIMERS             Get address of Timer Blocks
  312.         std   FREE                Store it in the pointer to 1st free block
  313.         ldx   #TIMERS             Set up pointer to 1st Timer Block
  314. tmlp   dey                        Decrement timer counter and see if done.
  315.         beq   tmdone
  316.         addd  #TIMRLEN            If not done, calculate address of next block
  317.         std   0,x                 Store it in link word of current block.
  318.         ldx   0,x                 Then set up pointer to the next block.
  319.         bra   tmlp
  320. tmdone clrb
  321.         clra                     When done linking the timer blocks, set
  322.         std   0,x                   the link word of the last timer to 0.
  323.         std   ACTIVE              Set up 0 entry for no active timers.
  324.  
  325. *******************************************************************************
  326. * The third thing to do during initialization is to set up the queues. The    *
  327. * queues have a Header and a Body and they are not contiguous. The Queue      *
  328. * Headers are found immediately below the Timer Blocks in RAM. The Bodies are *
  329. * found immediately above the Task Control Blocks.                            *
  330. *******************************************************************************
  331.  
  332.         ldx   #QHDRTBL            Set up pointer to the 1st queue header
  333. qlp    clr    0,x                 Clear next byte in the queue header area.
  334.         inx
  335.         cpx   #TIMERS             See if all queue headers are cleared.
  336.         bne   qlp                 keep looping until done
  337.  
  338. *******************************************************************************
  339. * The fourth function during initialization is to set all of the semaphores   *
  340. * to a PENDing state. The number of semaphores is equal to the number of the  *
  341. * named semaphores + the number of tasks + twice the number of queues.        *
  342. *******************************************************************************
  343.  
  344.         ldaa  #NQUEUES            Get the number of queues in system.
  345.         asla                      Multiply it by 2.
  346.         adda  #NNAMSEM            Add the number of named semaphores
  347.         adda  #NTASKS             Then add the number of tasks.
  348.         ldx   #FLGTBL             Set up pointer to base of the semaphores.
  349.         ldab  #_PEND
  350. smlp   stab   0,x                 Store the PENDing value in the semaphore.
  351.         inx
  352.         deca                      Decrement the counter
  353.         bne   smlp                Keep looping until all are set to PENDing.
  354.  
  355.  
  356. *******************************************************************************
  357. * The fifth thing to do in the initialization is to set up the RAM resident   *
  358. * portions of the Task Control Blocks (TCB). The TCBs are found immediately   *
  359. * above the semaphores.                                                       *
  360. *******************************************************************************
  361.  
  362.         ldy   #TCBDATA            Set up pointer to User Defined list of
  363. *                                   TCB initialization data block.
  364.         ldaa  #NTASKS             Set up task counter too.
  365.         staa  notmt
  366. tcblp  ldx    TCBADDR,y           Set up a pointer to the TCB.
  367.         clr   MSGTHRD,x           Clear the message thread.
  368.         clr   MSGTHRD+1,x
  369.         ldab  INITST,y            Get the initial status of the task.
  370.         stab  STATE,x             Store it as the status byte of the TCB.
  371.         bne   nostart             Branch if task state show it is not ready.
  372.         ldd   RSTSP,y
  373.         subd  #9
  374.         std   ACTSP,x             Set up pointer to the stack context.
  375.         xgdx                      Put stacked context address into IX.
  376.         ldd   STRTADR,y
  377.         std   PC+1,x              Put task@@s starting address into PC word
  378.         clra                       of the context. Then clear ACCB, ACCA,
  379.         clrb                       and CCR.
  380.         staa  CCR+1,x
  381.         std   ACCB+1,x
  382. nostart ldab   #TCBDATL
  383.         aby                       Bump pointer to next TCB initialization
  384.         dec   notmt                data block.
  385.         bne   tcblp               Loop until done.
  386.  
  387. * Now set up the null task
  388.  
  389.         ldx   #SYSTACK+9
  390.         ldd   #nulltsk            Get the starting address of the null task.
  391.         std   PC+1,x              Put task@@s starting address into PC word
  392.         clr   CCR+1,x               of the context. Then clear ACCB, ACCA,
  393.         clr   ACCB+1,x              and CCR.
  394.         clr   ACCA+1,x
  395.         ldd   #NTASKS*TCBLEN+STATLS Get TCB address of the null task
  396.         xgdx
  397.         std   ACTSP,x             Save address of null task@@s context
  398.         clr   STATE,x             Make sure null task is READY.
  399.         clr   intlvl              Clear interrupt level.  ** (V1.1 #5)
  400.  
  401. *      jmp    dispch              Start the MCX Dispatcher
  402.  
  403. *******************************************************************************
  404. * The next location should contain the entry point to the Dispatcher.        *
  405. * The file "MCX.AS" should follow this file. If not, then you should remove  *
  406. * the asterisk on the line above which causes a direct jump to the label of  *
  407. * the Dispatcher, "dispch".                                                  *
  408. *******************************************************************************
  409.  
  410.