#include "m2m_type.h"
#include "m2m_os_lock_api.h"
M2M_T_OS_LOCK semaphore
.
/* Initialize a semaphore for a Critical Section: "val" value is equal to M2M_OS_LOCK_CS, it is
the initial semaphore count = 1*/
semaphore = m2m_os_lock_init(M2M_OS_LOCK_CS);
/* The retrieved semaphore count is one, then the semaphore count is decreased. The control is returned to the calling
task */
m2m_os_lock_lock(semaphore);
/* The current task executes its critical code section, any task trying to use m2m_os_lock_lock(semaphore) gets stuck */
/* Increase the semaphore count by one to unlock the semaphore. */
/* Pay attention: unlock the semaphore more times than it is locked changes its behaviour: it works as a counting
semaphore, (counter > 1). So its use is no more suited for Critical Sections which need binary semaphore */
m2m_os_lock_unlock(semaphore);
/* Destroy the semaphore */
m2m_os_lock_destroy(semaphore);
.