we implemented a new feature in our code that required a new mailbox. After hat we faced the issue that the thread-callup timings have increased. Not much, but enough to make a system-in-the-loop test fail.
we filled the mailbox here in sender.c, which is located in Thread A:
Code: Select all
int send(uint8_t payload) {
...
msg_t mbStatus = MSG_RESET;
mbStatus = chMBPostTimeout(&modbusDebugCommandMailbox, (msg_t) &payload, 500);
if (mbStatus == MSG_OK) {returncode = 0;}
return returncode;
}
we read out the mailbox here in receiver.c in Thread B:
Code: Select all
extern mailbox_t modbusDebugCommandMailbox;
msg_t mbStatus = chMBFetchTimeout(&modbusDebugCommandMailbox, &msg, 500);
uint8_t *payload = (uint8_t *) msg;
we defined and initialised the mailbox in a common file
Code: Select all
#define MODBUS_DEBUG_COMMAND_MAILBOX_BUFFER_SIZE 32
mailbox_t modbusDebugCommandMailbox;
msg_t modbusDebugCommandMailboxBuffer[MODBUS_DEBUG_COMMAND_MAILBOX_BUFFER_SIZE];
memset(modbusDebugCommandMailboxBuffer, 0, sizeof(modbusDebugCommandMailboxBuffer));
chMBObjectInit(&modbusDebugCommandMailbox, modbusDebugCommandMailboxBuffer, MODBUS_DEBUG_COMMAND_MAILBOX_BUFFER_SIZE);
So the mailbox is used to send data from Thread A to Thread B.
There is another Thread C, that has higher priority than A and B and is called every 66µs. This one doesn't use this mailbox at all. We measure the timings of this Thread C. It has an endless loop in it where we measure the time between the beginning of the loop and the end. In the production Code it takes about 56µs to complete. We found that with the mailboxes it takes about 1.5µs more time to complete. After removing the mailbox and implement the feature with a simple array (without mutexes) that stores the data, the timings were back to normal. After introducing the necessary mutexes to it, the timings were up again.
Has anyone an idea on why this happens and how to solve it?
thanks in advance and best