Hi All,
TARGET I am using C51 tools to compile a simple app for an ST uPSD33xx.
OUTLINE The problem I am experiencing maifests itself as an incorrect value in a pointer passed as an argument to a reentrant function.
DETAILS OK, I am writing a serial driver. Each channel of the serial driver has a struct to hold pointer to a data buffer, number of bytes, etc, etc. Each struct is static in XDATA as is the data buffer for each channel:
typedef struct serial_data_buffer_t { int8 xdata *pBuffer; uint16 read; uint16 write; uint16 length; uint16 bytesInBuffer; #ifdef SERIAL_HW_FLOW_CONTROL uint16 lowWater; uint16 highWater; #endif } SERIAL_DATA_BUFFER_T; typedef struct serial_channel_t { uint8 channelNumber; int32 baudRate; bool flowControlActive; bool txRunning; SERIAL_DATA_BUFFER_T txBuffer; SERIAL_DATA_BUFFER_T rxBuffer; } SERIAL_CHANNEL_T; #ifdef USE_SERIAL_PORT1 static int8 xdata serial1TxDataBuffer[SERIAL_PORT1_TX_BUFFER_SIZE]; static int8 xdata serial1RxDataBuffer[SERIAL_PORT1_RX_BUFFER_SIZE]; static SERIAL_CHANNEL_T xdata serialChannel1; #endif /* #ifdef USE_SERIAL_PORT1 */ #if (defined USE_SERIAL_PORT0) || (defined USE_SERIAL_PORT1) static void recieveByte (SERIAL_CHANNEL_T *pChannel) reentrant; static void sendByte (SERIAL_CHANNEL_T *pChannel) reentrant; static uint16 _writeSerial (char* buffer, uint16 numBytes, SERIAL_CHANNEL_T *pChannel); #endif /* #if (defined USE_SERIAL_PORT0) || defined (USE_SERIAL_PORT1) */
The pBuffer pointer is initialised at run time using straight forward assignment:
serialChannel1.txBuffer.pBuffer = (int8 xdata*) &serial1TxDataBuffer[0];
When a client wishes to transmit some data the following call chain takes place:
writeSerial1 ("Hello World!\n", strlen ("Hello World!\n"));
calls
bytesSent = _writeSerial (buffer, numBytes, &serialChannel1);
sendByte (pChannel);
The routine sendByte is declared reentrant as it is called from background (as just described) but also from the ISR (to contiune the transmission of the contents of the buffer).
The problem (first) occurs when sendByte is called from _writeSerial. The pChannel argument passed into sendByte is OK prior to the call (as viewed with the debugger), but once inside sendByte the pChannel argument contains a crazy value.
What could be causing this problem? Is there some fundamental problem or rule I am breaking here to cause this problem?
Any help appreciated
Cheers
Andy