I'm using stm32f103ret6 custom board (running at 72 Mzh) and have question.
I need to transfer large amounts of data between ICU and thread, which parse this data.
I choose mailbox for that purpose.
I create interrupt handler for ICU using TIM4 (with frequency 1 mhz), which catch pulses width (minimal pulse width around 30-50 uS):
Code: Select all
static void icu_width_callback(ICUDriver *icup)
{
msg_t msg;
pulse_width = icuGetWidthX(icup);
msg = pulse_width;
chSysLockFromISR();
if (chMBPostI(&mailbox, msg)!=MSG_OK)
{
// mailbox full, switch led on
palSetPad(IOPORT2, GPIOB_LED);
}
chSysUnlockFromISR();
...
}
And also casual thread is created, which catch this data:
Code: Select all
static THD_FUNCTION(mParseThread, arg) {
(void) arg;
msg_t msg;
/* Thread loop, until terminated.*/
while (chThdShouldTerminateX() == false) {
/* Waiting for a message.*/
chMBFetch(&mailbox, &msg, TIME_INFINITE);
...
In general all working fine, but from time to time i have 'mailbox full' case.
So, my question is: is it good idea to use mailbox for fast trasfer between ISR and Thread or not?
May be simple shared circle buffer is better (less overhead)?