Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed-os by
uvisor_semaphore.c
00001 #include "api/inc/uvisor_semaphore_exports.h" 00002 #include "api/inc/uvisor_exports.h" 00003 #include "api/inc/halt_exports.h" 00004 #include "cmsis_os.h" 00005 #include <string.h> 00006 00007 typedef struct uvisor_semaphore_internal { 00008 osSemaphoreId id; 00009 osSemaphoreDef_t def; 00010 uint32_t data[2]; /* RTX expects this is 4-byte aligned */ 00011 } UVISOR_ALIGN(4) uvisor_semaphore_internal_t; 00012 00013 UVISOR_STATIC_ASSERT(UVISOR_SEMAPHORE_INTERNAL_SIZE >= sizeof(UvisorSemaphore), semaphore_size_too_small); 00014 00015 int __uvisor_semaphore_init(UvisorSemaphore * s, int32_t count) 00016 { 00017 uvisor_semaphore_internal_t * semaphore = (uvisor_semaphore_internal_t *) s; 00018 00019 memset(semaphore->data, 0, sizeof(semaphore->data)); 00020 semaphore->def.semaphore = semaphore->data; 00021 semaphore->id = osSemaphoreCreate(&semaphore->def, count); 00022 00023 /* Error when semaphore->id is NULL */ 00024 return semaphore->id == NULL ? UVISOR_ERROR_OUT_OF_STRUCTURES : 0; 00025 } 00026 00027 int __uvisor_semaphore_pend(UvisorSemaphore * s, uint32_t timeout_ms) 00028 { 00029 uvisor_semaphore_internal_t * semaphore = (uvisor_semaphore_internal_t *) s; 00030 00031 int32_t num_available_tokens = osSemaphoreWait(semaphore->id, timeout_ms); 00032 00033 if (num_available_tokens == -1) { 00034 return UVISOR_ERROR_INVALID_PARAMETERS; 00035 } 00036 00037 if (num_available_tokens == 0) { 00038 return UVISOR_ERROR_OUT_OF_STRUCTURES; 00039 } 00040 00041 return 0; 00042 } 00043 00044 int __uvisor_semaphore_post(UvisorSemaphore * s) { 00045 uvisor_semaphore_internal_t * semaphore = (uvisor_semaphore_internal_t *) s; 00046 return osSemaphoreRelease(semaphore->id); 00047 }
Generated on Tue Jul 12 2022 13:16:19 by
