home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_09_03 / 9n03045a < prev    next >
Text File  |  1991-01-18  |  5KB  |  199 lines

  1.  /*******************************************
  2.  * NAME       : Main.c
  3.  *
  4.  * DESCRIPTION : Main controlling routine
  5.  *               for the preset controller.
  6.  *******************************************/
  7.  
  8. #include "pcon.h"
  9. #include "que.h"
  10. #include "serial.h"
  11.  
  12. extern void key_msg();
  13. extern void message_out();
  14. extern void message_in();
  15. extern void display();
  16. extern void diag();
  17.  
  18.     /* at 08   Timer Control and Status Register:   */
  19. extern unsigned char TCSR;
  20.     /* at 09:0A  Counter: */
  21. extern unsigned char COUNTER;
  22.     /* at 0B:0C  Output Compare Register: */
  23. extern unsigned char OCR;
  24.     /* at 0D:0E  Input Capture Register: */
  25. extern unsigned char ICR;
  26.     /* at 0F   Port 3 Control and Status Register: */
  27. extern unsigned char P3CSR;
  28.     /* rate and mode control register: */
  29. extern unsigned char RMCR;
  30.     /* transmit/receive control register: */
  31. extern unsigned char TRCSR;
  32.     /* receive data register: */
  33. extern unsigned char RDR;
  34.     /* transmit data register: */
  35. extern unsigned char TDR;
  36.  
  37. extern unsigned char P1DDR;
  38. extern unsigned char P1DR;
  39. extern unsigned char P2DDR;
  40. extern unsigned char P2DR;
  41.  
  42.     /* for debugging */
  43. extern unsigned char over, received;
  44.  
  45. struct sale_status key_buf;
  46. struct rev_status  rev_stat;
  47. struct config_table config;
  48.  
  49. struct g_queue  key_que;
  50. struct g_queue  in_que;
  51. struct g_queue  out_que;
  52. struct g_queue  xmit_que;
  53.  
  54. int globaltime;
  55. int flashtime;
  56. unsigned char disable_on;
  57. unsigned char test_stat;
  58. unsigned char nozzle_up;
  59. extern unsigned char enable_timer;
  60.  
  61.     /* date of release */
  62. const char date[] = "022290";
  63.     /* major revision number */
  64. #define revis0 0
  65.     /* minor revision number */
  66. #define revis1 6
  67.  
  68.  /**************************************************
  69.   * NAME       : main
  70.   *
  71.   * DESCRIPTION: call all the initialization of
  72.   *              hardware and task setup then
  73.   *              loops forever and calls each task
  74.   *              in a round-robin fashion.  Each
  75.   *              task will run until it suspends
  76.   *              itself then return to main for
  77.   *              the next task in the list.
  78.   **************************************************/
  79.  
  80. void main()
  81. {
  82.    initsystem();
  83.    initstructures();
  84.    init_task(0,&display);
  85.    init_task(1,&message_in);
  86.    init_task(2,&message_out);
  87.    init_task(3,&key_msg);
  88.    clear_irq();
  89.    while(true)
  90.    {
  91.       continue_task(0);
  92.       continue_task(1);
  93.       continue_task(2);
  94.       continue_task(3);
  95.    }
  96. }
  97.  
  98.  
  99.  /**************************************************
  100.   * NAME       : initstructures
  101.   *
  102.   * DESCRIPTION: init the data structures for the
  103.   *              firmware sets up all pointers and
  104.   *              what ever else need doing
  105.   **************************************************/
  106.  
  107. initstructures ()
  108. {
  109.         int i;
  110.  
  111.          /* init the key queue */
  112.          key_que.insert = 0;
  113.          key_que.remove = 0;
  114.          key_que.empty  = true;
  115.  
  116.          /* init the in message que */
  117.          in_que.insert = 0;
  118.          in_que.remove = 0;
  119.          in_que.empty  = true;
  120.  
  121.          /* init the out message que */
  122.          out_que.insert = 0;
  123.          out_que.remove = 0;
  124.          out_que.empty  = true;
  125.  
  126.          /* init the Transmit que */
  127.          xmit_que.insert = 0;
  128.          xmit_que.remove = 0;
  129.          xmit_que.empty  = true;
  130.  
  131.          /* init the all other data as needed */
  132. }
  133.  
  134.  
  135.  /***************************************************
  136.   * NAME: initsystem
  137.   *
  138.   * DESCRIPTION:
  139.   *  Init the counter timer chip for continous
  140.   *  operation and to interupt at overflow.
  141.   *  Init the serial port for receive and send and
  142.   *  to generate an interrupt whenever the transmit
  143.   *  buffer is empty and the receive buffer is full.
  144.   ***************************************************/
  145.  
  146. #define ETOI 0x04
  147.  
  148. initsystem()
  149. {
  150.    /* set up the rate and mode control
  151.       for internal clock and 9600     */
  152.    RMCR = CC0 | SS0;
  153.  
  154.    /* set up the serial port to transmit and receive */
  155.    TRCSR = normal_mode;
  156.  
  157.    /* set up the free running counter
  158.       to interupt at overflow         */
  159.    TCSR = ETOI;
  160.  
  161.    /* set up port 1 bits 0-3 as write only
  162.       and bits 4-7 as read only            */
  163.    P1DDR = 0x0f;
  164.  
  165.    /* set up port 2 bit 0 as a write bit
  166.       and turn off the serial transmit buffer */
  167.    P2DDR = 0x01;
  168.    P2DR = 0xFF;
  169. }
  170.  
  171.  /**************************************************
  172.   * NAME       : set_irq, clear_irq
  173.   *
  174.   * DESCRIPTION: two routines that set the
  175.   *              interupt mask and clear the
  176.   *              interrupt mask in the condition
  177.   *              code register of the 6801
  178.   *************************************************/
  179.  
  180. /* routine to set the interupt mask */
  181.  
  182. set_irq()
  183. {
  184.    ;
  185.    #asm
  186.       sei
  187.    #endasm
  188. }
  189.  
  190.  /* routine to clear the interupt mask */
  191.  
  192. clear_irq()
  193. {
  194.    ;
  195.    #asm
  196.       cli
  197.    #endasm
  198. }
  199.