This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

accessing class member variables from within interrupts

Does anyone know why can't I access member variables from within __interrupt?  

  1. I have a class (UARTBuffer) defined as following:
    1. class UARTBuffer: public __HHI__::DataBuffer {
    2. public:
    3.        UARTBuffer();
    4.        virtual ~UARTBuffer();
    5.        void Init();
    6.        void FetchCmdToQueue();
    7.        void SendData(unsigned char *);
    8.        void DispatchCmd(void);
    9.        unsigned char PackDataForRF(char, char, char, void *, char);
    10. private:
    11.        char                 cmdSupported[10];
    12.        _cmdQueue            qList[QUEUE_SIZE];
    13.        _cmdQueue            uartCmd;
    14.        _cmdQueue            uartRcv;
    15.        _respQueue           uartTx;
    16.        char                 RespData[RESP_DATA_SIZE];
    17.        char                 qCount;
    18.        char                 qFront;
    19.        char                 qRear;
    20.        char                 lastRefNum;
    21.        char                 pkRefNum;
    22.        static unsigned char       uartRcvIndex;
    23.        unsigned char        uartTxIndex;
    24.        unsigned char        RespDataCount;
    25.        unsigned char        *ptrUartTx;
    26.        unsigned char        uartStatus;
    27. aa.  

bb. private:

  1. cc.        static __interrupt void USCIA1_UART_ISR(void);

dd. };

  1. I would like to access its member “uartRcvIndex” in interrupt:
    1. #pragma vector=USCI_A1_VECTOR
    2. __interrupt void UARTBuffer::USCIA1_UART_ISR(void)
    3. {
    4.        motor.DisableInterrupts();
    5.        if (UCA1IFG & UCRXIFG)
    6.        {
    7.               // Handle UART RX event.
    8.               if (uartRcvIndex > CMD_SIZE)
    9.                      uartRcvIndex = 0;
    10. Compiler complains:
      1. undefined                         first referenced            
      2.   symbol                               in file                 
      3.  ---------                         ----------------            
      4.  __HHI__::UARTBuffer::uartRcvIndex ./Source Files/UARTBuffer.obj
  • Ken Yeh said:
    Compiler complains:
    1. undefined                         first referenced            
    2.   symbol                               in file                 
    3.  ---------                         ----------------            
    4.  __HHI__::UARTBuffer::uartRcvIndex ./Source Files/UARTBuffer.obj

    That is the linker reporting the unresolved symbol, rather than the compiler. You need to define the static member "uartRcvIndex". i.e. try adding the following to the .cpp file which defines the class:
    unsigned char UARTBuffer::uartRcvIndex;
  • hi Chester,

    thanks for the reply.  

    uartRcvIndex is defined as static in the class UARTBuff though.

  • It's only *declared* in the class.  It still needs to be *defined* someplace.

    The class declaration is roughly equivalent to having "extern uchar uartRcvIndex;" in the header file.  You would still need "uchar uartRcvIndex;" in a single source file to create the variable.

  • hi Chester,

    thanks, it make sense.

    Ken