This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Generating interrupts in RTX51 Tiny applications

I am having problems generating serial port (RI and TI) interrupts in an application that I have.
I have two functions being running with Round Robin disabled. Both functions send signals to each other when the tasks need to switch.
I've gone through the threads, and tried to follow the instructions given when other people had similar problems, but none of that is working for me.
I am also using Timer 2 for Uart 0, and timer 1 for uart 1. Interrupt for both UARTs are enabled.
I can only set the priorities for both interrupts as high. I tried doing this but it didn't seem to help.

Any ideas, thoughts or suggestions?

Parents
  • /******************************************************************************/
    /*       serial_0:  serial receiver / transmitter interrupt                     */
    /******************************************************************************/
    void serial_0 (void) interrupt 4 {
    
      if (RI0)  {                          // if receiver interrupt
        RI0 = 0;                           // clear interrupt request flag
        inbuf_0[iend_0++ & (ILEN-1)] = SBUF0;  // read character
        if (itask_0 != 0xFF) isr_send_signal (itask_0);
      }
    
      if (TI0) {                           // if transmitter interrupt
        TI0 = 0;                           // clear interrupt request flag
        if (ostart_0 != oend_0)  {         // if characters in buffer and
          SBUF0 = outbuf_0[ostart_0++ & (OLEN-1)]; // transmit character
          sendfull_0 = 0;                  // clear 'sendfull' flag
                                           // if task waiting: signal ready
          if (otask_0 != 0xFF) isr_send_signal (otask_0);
        } else {
          sendactive_0 = 0;                // if all transmitted clear 'sendactive'
        }
      }
    }
    
    /******************************************************************************/
    /*       serial_1:  serial receiver / transmitter interrupt                     */
    /******************************************************************************/
    void serial_1 (void) interrupt 20 {
    
      if (RI1)  {                         // if receiver interrupt
        RI1 = 0;                          // clear interrupt request flag
        inbuf_1[iend_1++ & (ILEN-1)] = SBUF1;  // read character
        if (itask_1 != 0xFF) isr_send_signal (itask_1);
      }
    
      if (TI1)  {                         // if transmitter interrupt
        TI1 = 0;                          // clear interrupt request flag
        if (ostart_1 != oend_1)  {        // if characters in buffer and
          SBUF1 = outbuf_1[ostart_1++ & (OLEN-1)];      /* transmit character */
          sendfull_1 = 0;                 // clear 'sendfull' flag
                                          // if task waiting: signal ready
          if (otask_1 != 0xFF) isr_send_signal (otask_1);
        } else {
          sendactive_1 = 0;               // if all transmitted clear 'sendactive'
        }
      }
    }
    
    /***************************/
    /* Line Editor from UART_0 */
    /***************************/
    void getline_0 (uchar *line, uchar n)  {
      uchar cnt = 0;
      uchar c;
    
      do  {
        while  (iend_0 == istart_0)  {
          itask_0 = os_running_task_id ();  /* set input task number                */
          os_wait (K_SIG, 0, 0);            /* RTX-51 call: wait for signal         */
          itask_0 = 0xff;                   /* clear input task number              */
        }
        if ((c = inbuf_0[istart_0++ & (ILEN-1)]) == CR)  c = LF;    // read character
        *line = c;
        line++;                             /* increment line pointer         */
        cnt++;                              /* and count                      */
      }  while (cnt < n - 1  &&  c != LF);  /* check limit and line feed      */
    
      *line = 0;
    }
    
    /***************************/
    /* Line Editor from UART_1 */
    /***************************/
    void getline_1 (uchar *line, uchar n)  {
      uchar cnt = 0;
      uchar c;
    
      do  {
        while  (iend_1 == istart_1)  {
          itask_1 = os_running_task_id ();  /* set input task number          */
          os_wait (K_SIG, 0, 0);            /* RTX-51 call: wait for signal   */
          itask_1 = 0xff;                   /* clear input task number        */
        }
        if ((c = inbuf_1[istart_1++ & (ILEN-1)]) == CR)  c = LF;    // read character
        *line = c;
        line++;                             /* increment line pointer         */
        cnt++;                              /* and count                      */
      }  while (cnt < n - 1  &&  c != LF);  /* check limit and line feed      */
    
      *line = 0;
    }
    

Reply
  • /******************************************************************************/
    /*       serial_0:  serial receiver / transmitter interrupt                     */
    /******************************************************************************/
    void serial_0 (void) interrupt 4 {
    
      if (RI0)  {                          // if receiver interrupt
        RI0 = 0;                           // clear interrupt request flag
        inbuf_0[iend_0++ & (ILEN-1)] = SBUF0;  // read character
        if (itask_0 != 0xFF) isr_send_signal (itask_0);
      }
    
      if (TI0) {                           // if transmitter interrupt
        TI0 = 0;                           // clear interrupt request flag
        if (ostart_0 != oend_0)  {         // if characters in buffer and
          SBUF0 = outbuf_0[ostart_0++ & (OLEN-1)]; // transmit character
          sendfull_0 = 0;                  // clear 'sendfull' flag
                                           // if task waiting: signal ready
          if (otask_0 != 0xFF) isr_send_signal (otask_0);
        } else {
          sendactive_0 = 0;                // if all transmitted clear 'sendactive'
        }
      }
    }
    
    /******************************************************************************/
    /*       serial_1:  serial receiver / transmitter interrupt                     */
    /******************************************************************************/
    void serial_1 (void) interrupt 20 {
    
      if (RI1)  {                         // if receiver interrupt
        RI1 = 0;                          // clear interrupt request flag
        inbuf_1[iend_1++ & (ILEN-1)] = SBUF1;  // read character
        if (itask_1 != 0xFF) isr_send_signal (itask_1);
      }
    
      if (TI1)  {                         // if transmitter interrupt
        TI1 = 0;                          // clear interrupt request flag
        if (ostart_1 != oend_1)  {        // if characters in buffer and
          SBUF1 = outbuf_1[ostart_1++ & (OLEN-1)];      /* transmit character */
          sendfull_1 = 0;                 // clear 'sendfull' flag
                                          // if task waiting: signal ready
          if (otask_1 != 0xFF) isr_send_signal (otask_1);
        } else {
          sendactive_1 = 0;               // if all transmitted clear 'sendactive'
        }
      }
    }
    
    /***************************/
    /* Line Editor from UART_0 */
    /***************************/
    void getline_0 (uchar *line, uchar n)  {
      uchar cnt = 0;
      uchar c;
    
      do  {
        while  (iend_0 == istart_0)  {
          itask_0 = os_running_task_id ();  /* set input task number                */
          os_wait (K_SIG, 0, 0);            /* RTX-51 call: wait for signal         */
          itask_0 = 0xff;                   /* clear input task number              */
        }
        if ((c = inbuf_0[istart_0++ & (ILEN-1)]) == CR)  c = LF;    // read character
        *line = c;
        line++;                             /* increment line pointer         */
        cnt++;                              /* and count                      */
      }  while (cnt < n - 1  &&  c != LF);  /* check limit and line feed      */
    
      *line = 0;
    }
    
    /***************************/
    /* Line Editor from UART_1 */
    /***************************/
    void getline_1 (uchar *line, uchar n)  {
      uchar cnt = 0;
      uchar c;
    
      do  {
        while  (iend_1 == istart_1)  {
          itask_1 = os_running_task_id ();  /* set input task number          */
          os_wait (K_SIG, 0, 0);            /* RTX-51 call: wait for signal   */
          itask_1 = 0xff;                   /* clear input task number        */
        }
        if ((c = inbuf_1[istart_1++ & (ILEN-1)]) == CR)  c = LF;    // read character
        *line = c;
        line++;                             /* increment line pointer         */
        cnt++;                              /* and count                      */
      }  while (cnt < n - 1  &&  c != LF);  /* check limit and line feed      */
    
      *line = 0;
    }
    

Children
  • I've tried the suggestions. I am using pretty much the same code you put up. My problem is that it appears that my interrupts are not working.
    The TI_0 and RI_0 interrupts are not interrupting the OS. Furthermore, when I look at the RTX tiny task list, once the task 0 (init) task finishes running and exits, I notice that the system timer doesn't count down anymore, but I know that Timer 0 is still running.
    Its as if all interrupts are disabled, but when you look at the interrupt peripheral tool, EA is enabled.

    My interrupts are not working. My Conf_Tny file is almost identical to the file from Traffic.
    Any ideas?

    Thanks

  • Try C:\Keil\c51\RtxTiny2\Examples\Traffic
    Try to test Traffic in initial variant - without changes.
    Probably it is necessary to renominate pin for led.
    This example excellently works.
    If it not works then you have troubles with hardware.