int16_t RetVal;
uint8_t Data;
// Here Address and Data variables are turned into a sixteen bit value to send out
// This sixteen bit value is a static variable to this module
DisableReception(); // Disable Rx pin interrpt
// The timer bit-bashes the data and enables the Rx pin interrupt if necessary
// when the sixteen bits have been sent out
StartTimer();if (ReceiveData == TRUE) { if (xQueueReceive(xRxQueue,Data,TIMEOUTVALUE) == pdTRUE) RetVal = (int16t)Data; // Pin int fills xRxQueue else return NODATARECEIVED; } else RetVal = NODATARETURN_REQUESTED;
return RetVal;
}
The xRxQueue is filled by the pin interrupt if a slave is [supposed to be] returning data.
This works a treat for the one interface. I can easily write a version for the second interface, to end up with two functions:
int16t SendMessageA(uint8t Address, uint8t Data, uint8t ReceiveData);
int16t SendMessageB(uint8t Address, uint8t Data, uint8t ReceiveData);
The two functions would have their own RxQueue, use their own timer and own pin interrupt of course.
I have a commands.c/commands.h module which calls this SendMessage() function. Here is an example:
uint8t ProgramShortAddress(uint8t NewShortAddress)
{
int16_t Reply;
uint8_t RetVal;
NewShortAddress <<= 1;
NewShortAddress |= 1;
Reply = SendMessage(PROGRAM_SHORT_ADDRESS, NewShortAddress, TRUE);
if (Reply == 0xFF)
RetVal = TRUE;
else
RetVal = FALSE;
return RetVal;
}
Now, I would like to mod this and all the other similar commands this so I pass an extra variable in to the function, which specifies which of the two interfaces I am addressing. It would become:
uint8t ProgramShortAddress(uint8t NewShortAddress, uint8_t Interface)
{
// All stays the same inside the function except:
if (Interface == INTERFACE_A)
Reply = SendMessageA(PROGRAM_SHORT_ADDRESS, NewShortAddress, TRUE);
else if (Interface == INTERFACE_B)
Reply = SendMessageB(PROGRAM_SHORT_ADDRESS, NewShortAddress, TRUE);
}
So, here is the crux of the matter:
If I have two threads, one running for interface A and one for interface B, one calls ProgramShortAddress(), its time slice ends while in this function and the other interface calls ProgramShortAddress(), is this going to be an issue? It’s not like having an SPI port and locking it out with a mutex as far as I can see, as it’s going to talk to one of two interfaces. There would never be an occasion when two threads would try to access the same interface.
Does this make sense? Have I explained it clearly enough? Am I worrying over nothing or maybe I am tackling this in completely the wrong manner?
Many thanks.