* @brief Initialize a static mailbox object. * * @note For the static mailbox object, its memory space is allocated by the compiler during compiling, * and shall placed on the read-write data segment or on the uninitialized data segment. * By contrast, the rt_mb_create() function will allocate memory space automatically and initialize the mailbox. * * @see rt_
| 2344 | * @warning This function can ONLY be called from threads. |
| 2345 | */ |
| 2346 | rt_err_t rt_mb_init(rt_mailbox_t mb, |
| 2347 | const char *name, |
| 2348 | void *msgpool, |
| 2349 | rt_size_t size, |
| 2350 | rt_uint8_t flag) |
| 2351 | { |
| 2352 | RT_ASSERT(mb != RT_NULL); |
| 2353 | RT_ASSERT((flag == RT_IPC_FLAG_FIFO) || (flag == RT_IPC_FLAG_PRIO)); |
| 2354 | |
| 2355 | /* initialize object */ |
| 2356 | rt_object_init(&(mb->parent.parent), RT_Object_Class_MailBox, name); |
| 2357 | |
| 2358 | /* set parent flag */ |
| 2359 | mb->parent.parent.flag = flag; |
| 2360 | |
| 2361 | /* initialize ipc object */ |
| 2362 | _ipc_object_init(&(mb->parent)); |
| 2363 | |
| 2364 | /* initialize mailbox */ |
| 2365 | mb->msg_pool = (rt_ubase_t *)msgpool; |
| 2366 | mb->size = (rt_uint16_t)size; |
| 2367 | mb->entry = 0; |
| 2368 | mb->in_offset = 0; |
| 2369 | mb->out_offset = 0; |
| 2370 | |
| 2371 | /* initialize an additional list of sender suspend thread */ |
| 2372 | rt_list_init(&(mb->suspend_sender_thread)); |
| 2373 | rt_spin_lock_init(&(mb->spinlock)); |
| 2374 | |
| 2375 | return RT_EOK; |
| 2376 | } |
| 2377 | RTM_EXPORT(rt_mb_init); |
| 2378 | |
| 2379 |