hi, I'm looking for 'struct os_**_cb ', such as 'struct os_mutex_cb' from the source code of CMSIS-RTOS, but just cannot find it.
'struct os_**_cb ' is used in os_cmsis.h, and I know they are implementation specific in every CMSIS-RTOS, but they are not defined in rt_CMSIS.c or any other files.
So , where are they defined in RTX?
Look at the #defines used to define these "items"
#define osSemaphoreDef(name) \ uint32_t os_semaphore_cb_##name[2] = { 0 }; \ const osSemaphoreDef_t os_semaphore_def_##name = { (os_semaphore_cb_##name) } #endif #
os_semaphore_cb is 2 uint32's. You will notice that this maps to the struct OS_SCB in rt_typedef.h (they are both 2 uint32's in size)
Yeah, thanks a lot, Robert. 'os_semaphore_cb' is indeed similar to 'struct OS_SCB'. But when it is used here in cmsis_os.h 'typedef struct os_semaphore_cb *osSemaphoreId', it is still not defined,right?
Though it can be compiled without any error, but I think 'os_semaphore_cb' is meaningless, while 'os_mailQ_cb' in 'typedef struct os_mailQ_cb *osMailQId' is defined before, and has its own structure members.
so i wonder why not just use 'void *osSemaphoreId' to replace 'typedef struct os_semaphore_cb *osSemaphoreId' ? what's taken into consideration here?
I mean use
typedef void *osSemaphoreId
to replace
typedef struct os_semaphore_cb *osSemaphoreId
the reason is that
os_semaphore_cb
is just not defined and meaningless.
Remember that:
doesn't give you any type checking.
But
lets the compiler check the pointer type, even if it doesn't know how to expand the actual struct.
It is quite common to play with pointers and references to data types you don't want the end user to see.
**** This is my guess as to why void* was not used and whey os_semaphore_cb* osSempahoreId is "better"
The reason it was written this way was to make it "easier" to understand (I would not use the term easy here)
void* tells you almost nothing about a variable (pointer, but no idea of pointer to what)
typedef struct os_semaphore_cb *osSemaphoreId DOES give you some information and maybe a place to look for more information. Your point of it not being any more specific about the type than void* is true, but the os_semaphore_cb more easily gets me to the #define that has:
uint32_t os_semaphore_cb_##name[2] = { 0 };
BUT add the the following very helpful comment -
/// Semaphore ID identifies the semaphore (pointer to a semaphore control block). typedef struct os_semaphore_cb *osSemaphoreId;
Semaphore Control Block is a term used in RTX. As it turns out osSemaphoreId is a pointer to an RTX Semaphore Control Block (OS_SCB is defined in rt_typedef.h)
Thanks, Robert and Per . I now somewhat understand it. it's designed for both readability and safety considerations.