Http://blog.163.com/qiang625@126/blog/static/170040164201211431959819/
I. Information management API
- Osal_msg_allocate () function prototype: a task allocates an information buffer. When a task call or function is called, the space is filled with information or the function osal_msg_send () is called () sends the buffer space information to other tasks. If the buffer space cannot be allocated, msg_ptr = NULL is set;
Uint8 * osal_msg_allocate (uint16 Len ),The pointer is returned. If the returned result is null, the information cache space allocation fails.
Note: This function cannot be confused with osal_mem_alloc (). The osal_mem_alloc () function is used to allocate a buffer for sending messages between tasks. This function can allocate a bucket.
2. osal_msg_deallocate () Information Processing allocation cache. This function is called by a task to process a received message.
Uint8 osal_msg_deallocate (uint8 * msg_ptr)
Msg_ptr: pointer to the allocated information cache to be processed
Successful; invalid information pointer; cache queued.
3. osal_msg_send () A task sends a command or data to another task or processing element.
Uint8 osal_msg_send (uint8 destination_task, uint8 * msg_ptr)
4. The osal_msg_receive () task receives a command to call this function.
Uint8 * osal_msg_receive (uint8 task_id)
Return value is a pointer to a buffer containing the message or null if there is no encoded ed message.
5. osal_msg_find ()
Osal_event_hdr_t * osal_msg_find (uint8 task_id, uint8 event)
This function searches for an existing osal message matching the task_id and event parameters
2. task synchronization API: allows a task to wait for an event and return control during the waiting period
Purpose: Set events for a task and configure y the task once any event is set
1. osal_set_event (): Set the event flags for a task
Uint8 osal_set_event (uint8 task_id, uint16 event_flag) WhereEvent_flag is a 2-byte bitmap, each corresponding to an event
There is only one system event (sys_event_msg), the rest of the events/bits are defined by the grouping task
3. Time management API this API allows the timer to be used by internal and external tasks. It has the function of enabling and stopping a timer, which can be set incrementally in 1 millisecond. 1. osal_start_timerex () start the timer
Uint8 osal_start_timerex (uint8 taskid, uint16 event_id, uint16 timeout_value );
2. osal_start_reload_timer ()
Uint8 osal_start_reload_timer (uint8 taskid, uint16 event_id, uint16 timeout_value );
Set an event bit and auto-Reload count
3. osal_stop_timerex () stops the timer that has been started.
Uint8 osal_stop_timerex (uint8 task_id, uint16 event_id );4. osal_getsystemclock () reads the system clock
Uint32 osal_getsystemclock (void );Returned value: the system clock in milliseconds. 4. interrupt management API: it is an interface for tasks and external interruptions. A task can be allocated to a specified service program for each interruption. 1. osal_int_enable () can be interrupted.
Uint8 osal_int_enable (uint8 interrupt_id)2. osal_int_disable () disables an interruption.
Uint8 osal_int_disable (uint8 interrupt_id)
5. task management API: Used to add and manage tasks in osal. Each task is composed of an initialization function and an event processing function.
Osal CILS
Osalinittasks ()[Application supplied] to initialize the tasks and osal uses a task table (const
Ptaskeventhandlerfn tasksarr[]) To call the event processor for each task (also application supplied). Example of a task table implementation:
Const ptaskeventhandlerfn tasksarr [] =
{
Maceventloop,
Nwk_event_loop,
Hal_processevent,
Mt_processevent,
Aps_event_loop,
Zdapp_event_loop,
};
Const uint8 taskscnt = sizeof (tasksarr)/sizeof (tasksarr [0]); calculate the number of array elements
1. osal_init_system () initialize the osal system: it must be called before starting any osal.
Uint8 osal_init_system (void) The returned value is "success"
2. Main cyclic functions of the osal_start_system () task System
Void osal_start_system (void)
3. osal_run_system (): void osal_run_system (void)
4. osal_self () returns the ID number of the current running task: uint8 osal_self (void)
6. Memory Management API: A simple storage allocation system. Allow Dynamic Storage Allocation
1. osal_mem_alloc (): A simple storage allocation function. If execution is successful, a pointer pointing to a cache is returned.
Void * osal_mem_alloc (uint16 size );A non-type Pointer Points to the allocated new cache Zone
2. osal_mem_free () releases the allocated bucket for reuse. Only the bucket allocated by osal_mem_alloc () can be released.
Void osal_mem_free (void * PTR );
VII. Power management API: When ospl safely disables the receiver and external hardware and enables the processor to enter the sleep mode, it provides a method to notify the application/task of this event.
Osal_pwrmgr_device (), osal_pwrmgr_task_state (pwrmgr_hold)
1. osal_pwrmgr_init ():Void osal_pwrmgr_init (void); Do not call this function because it has been called in osal_init_system ()
2. osal_pwrmgr_powerconserve ():Void osal_pwrmgr_powerconserve (void );Enter power-down mode
Do not call this function, it is already called in the osal main loop [osal_start_system ()].
3. osal_pwrmgr_device ():Void osal_pwrmgr_device (uint8 pwrmgr_device );
The function is called when the power supply status or power supply needs to change. You can set the on/off status of the device power management. This function should be called differently in a center, such as zdo.
4. osal_pwrmgr_task_state (): uint8 osal_pwrmgr_task_state (uint8 task_id, uint8 State); called by each task to determine whether the task requires energy saving. When the task is created, the default energy saving mode is used, if you need to save energy, you do not need to call this function. State: return value 8. non-volatile memory API
The NV function is designed to read and write user-defined entries consisting of any data types, such as structures or queues.
Each NV entry has a unique ID, but there are rules and restrictions.
1. osal_nv_item_init (): Initialize an entry. This function checks an existing entry. If it does not exist, it is created and initialized with the carried data. Before calling osal_nv_read () or osal_nv_write () for each entry, thisThe function must be called.
Uint8 osal_nv_item_init (uint16 ID, uint16 Len, void * BUF); entry initialization Data Pointer
2. osal_nv_read ():
Uint8 osal_nv_read (uint16 ID, uint16 offset, uint16 Len, void * BUF );Read data from NV. Read an entire item from NV or an element of an item by indexing into the item with an offset. Copy the read data to * Buf Buffer
3. osal_nv_write (): Write Data to NV.Uint8 osal_nv_write (uint16 ID, uint16 offset, uint16 Len, void * BUF );
Write an entire item to NV or an element of an item by indexing into the item with an offset
4. osal_nv_delete (): deletes an entry from NV.
Uint8 osal_nv_delete (uint16 ID, uint16 Len );This function checks an existing entry. If it exists and its length matches the length provided in the function call, the entry will be removed from NV. 5. osal_nv_item_len ():
Uint16 osal_nv_item_len (uint16 ID); obtain the length of an entry in NV.6. osal_offsetof (): This macro defines the size (in bytes) of a structure offset in the memory)
Osal_offsetof (type, member)
Calculating the offset parameter is useful in nv api functions. 9. Simple NV storage API: like the osal NV memory system, the simple NV memory system provides a way for applications to store information into the device's memory persistently. on the other hand, unlike the osal NV memory system, the simple NV memory system provides much simpler
API to drive the application code size and the stack code size down as well as the code size of
Osal simple NV system implementation.
You can read and write the entire entry but cannot read or write a part of the entry..
1. osal_snv_read ():Uint8 osal_snv_read (osalsnvid_t ID, osalsnvlen_t Len, void * pbuf); read data from NV2. osal_snv_write (): Write Data to nV:Uint8 osal_snv_write (osalsnvid_t ID, osalsnvlen_t Len, void * pbuf );
10. osal clock system: this system will keep the number of seconds since 0 hrs, 0 minutes, 0 seconds on 1 January 2000 UTC, the two data types or structures are defined in osal_clock.h.
Typedef uint32 utctime; // to be used with, in addition, this feature does not maintain time for sleeping devices
Typedef struct
{
Uint8 seconds; // 0-59
Uint8 minutes; // 0-59
Uint8 hour; // 0-23
Uint8 day; // 0-30
Uint8 month; // 0-11
Uint16 year; // 2000 +
} Utctimestruct;
1. osaltimeupdate (): update the time from the osal_run_system () run,Void osaltimeupdate (void );
This function reads the number of MAC 320 USEC ticks to maintain the osal clock time. Do not call this function anywhere else2.osal _ setclock (): Device initialization time.Void osal_setclock (utctime newtime)
3. osal_getclock (): Call this function to obtain the current time of the device. Utctime osal_getclock (void );
4. osal_convertutctime (): function for converting utctime to utctimestruct
Void osal_convertutctime (utctimestruct * TM, utctime sectime );
5. osal_convertutcsecs (): function for converting utctimestruct into utctime
Utctime osal_convertutcsecs (utctimestruct * TM );
11. osal MISC Miscellaneous:
This section describes miscellaneous osal functions that do not fit into the previous osal categories
The description is not suitable for diverse osal functions of the previous osal category.
1. osal_rand (): returns a 16-bit random number.Uint16 osal_rand (void );
2. osal_memcmp (): Compare the memory.
Uint8 osal_memcmp (const void generic * src1, const void generic * src2, unsigned int Len );
Return Value: True-Same, false-different
3. osal_memset ():Void * osal_memset (void * DEST, uint8 value, int Len );
Function sets a buffer to a specific value, return value pointer to where in the buffer this function stopped
4. osal_memcpy ():Void * osal_memcpy (void * DST, const void generic * SRC, unsigned int Len );
Function copies one buffer to another buffer, return pointer to end of destination Buffer