alternate way in absence of get_semaphore_value

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?

Parents
  • But keil RTOS doesnt have sem_getvalue, in absence of which i am unable to think of any way of implementation.

    I'm afraid you're attacking the wrong end of the problem there. The fact you believe you need a sem_getvalue() function indicates that your understanding of the purpose and meaning of semaphores is probably flawed. A semaphore is the wrong tool for that job.

    If you don't want to block in case of a failed access, you shouldn't be using a semaphore in the first place. You should be using other services provided by the RTOS, e.g. message passing.

Reply
  • But keil RTOS doesnt have sem_getvalue, in absence of which i am unable to think of any way of implementation.

    I'm afraid you're attacking the wrong end of the problem there. The fact you believe you need a sem_getvalue() function indicates that your understanding of the purpose and meaning of semaphores is probably flawed. A semaphore is the wrong tool for that job.

    If you don't want to block in case of a failed access, you shouldn't be using a semaphore in the first place. You should be using other services provided by the RTOS, e.g. message passing.

Children
More questions in this forum