Share a resource between threads and VT?
Posted: Mon Jun 30, 2014 10:12 pm
Hi,
I'm implementing a message passing (over serial) system which talks to a circular buffer to transmit data as (example):
However some messages are periodic, and each periodic message is implemented as a Virtual Timer with the correct frequency.
The problem I'm facing and am unable to come to a good solution to is: How do I make the VTs wait until he mutex is unlocked until they try to access the circular buffer?
VT's ISRs in between it is no problem since each ISR is locked from the other ISRs, however if a thread has locked the buffer it must not try to access it.
What is the best way to do this using ChibiOS?
I was thinking of disabling the VTs before locking the circular buffer, and re-enabling them after the thread is finished, but perhaps there is a more elegant way to do it which I have yet to find?
Thanks in advance!
I'm implementing a message passing (over serial) system which talks to a circular buffer to transmit data as (example):
Code: Select all
void SendMessage(....)
{
/* Claim the circular buffer for writing */
chMtxLock(cb_mutex);
{
/* Write to Circular buffer for transmission over serial */
}
/* Release the circular buffer */
chMtxUnlock(cb_mutex);
}
However some messages are periodic, and each periodic message is implemented as a Virtual Timer with the correct frequency.
The problem I'm facing and am unable to come to a good solution to is: How do I make the VTs wait until he mutex is unlocked until they try to access the circular buffer?
VT's ISRs in between it is no problem since each ISR is locked from the other ISRs, however if a thread has locked the buffer it must not try to access it.
What is the best way to do this using ChibiOS?
I was thinking of disabling the VTs before locking the circular buffer, and re-enabling them after the thread is finished, but perhaps there is a more elegant way to do it which I have yet to find?
Thanks in advance!