* @brief Creating an event object. * * @note For the event object, its memory space is allocated automatically. * By contrast, the rt_event_init() function will initialize a static event object. * * @see rt_event_init() * * @param name is a pointer to the name that given to the event. * * @param flag is the event flag, which determines the queuing way of how mu
| 1878 | * @warning This function can ONLY be called from threads. |
| 1879 | */ |
| 1880 | rt_event_t rt_event_create(const char *name, rt_uint8_t flag) |
| 1881 | { |
| 1882 | rt_event_t event; |
| 1883 | |
| 1884 | RT_ASSERT((flag == RT_IPC_FLAG_FIFO) || (flag == RT_IPC_FLAG_PRIO)); |
| 1885 | |
| 1886 | RT_DEBUG_NOT_IN_INTERRUPT; |
| 1887 | |
| 1888 | /* allocate object */ |
| 1889 | event = (rt_event_t)rt_object_allocate(RT_Object_Class_Event, name); |
| 1890 | if (event == RT_NULL) |
| 1891 | return event; |
| 1892 | |
| 1893 | /* set parent */ |
| 1894 | event->parent.parent.flag = flag; |
| 1895 | |
| 1896 | /* initialize ipc object */ |
| 1897 | _ipc_object_init(&(event->parent)); |
| 1898 | |
| 1899 | /* initialize event */ |
| 1900 | event->set = 0; |
| 1901 | rt_spin_lock_init(&(event->spinlock)); |
| 1902 | |
| 1903 | return event; |
| 1904 | } |
| 1905 | RTM_EXPORT(rt_event_create); |
| 1906 | |
| 1907 |