I am implementing a uart communication, where i have various functions and/or tasks which may want to perform transmission using uart. Hence prior to new transmission on uart, i want to ensure that the resource (uart) is not already in use. this can be achieved by a binary semaphore whose value can be checked prior to new transmissions. But keil RTOS doesnt have sem_getvalue, in absence of which i am unable to think of any way of implementation.
one way around is to have a global flag. But currently trying to use any idea by which i can avoid using a global flag. In case of no other way, will have to use global flag.
any suggestions?
No - I really do not understand the complications.
why not:
while forever { wait for mail kick-start UART with first character in mail wait for event from UART interrupt that UART transmit buffer has been fully consumed release mail buffer }
And a worker task:
while forever { wait for work perform work wait for free mail buffer send mail with result }
Receive task:
while forever { wait for uart data process uart data if forming command if poll command wait for free mail buffer send mail will poll result else inform worker thread what to do }
Whatever happens, your master processor must be bright enough to not send jobs or ask status requests faster than what the UART channel is able to send back responses or one or more of your threads in the slave processor will not be able to start with the next job because it is still waiting for a mail to use to report the previous result.
Whatever happens, your master processor must be bright enough to not send jobs or ask status requests faster than what the UART channel is able to send back responses... this is one of the problem....the master cant be smarter enough as different task at the slave take different amount of time. Though there is some pretty decent amount of delay that master will wait for (100ms or so) before sending a new command or the poll, but there is no estimation of this time period.
But it appears you really have no idea how that's supposed to be done with the help of a semaphore... kindly elaborate how its can be done
learn what a semaphore is, and what it does. suggest some good links or articles that may be noteworthy :)
before sending a new command or the poll, in absence of reply from slave...