CC2530中OSAL的API函數

來源:互聯網
上載者:User

http://blog.163.com/qiang625@126/blog/static/170040164201211431959819/

一、資訊管理API

  1. osal_msg_allocate( )函數原型:任務是分配一個資訊緩衝區,當任務調用或函數被調用時,該空間被資訊填充或調用資訊發送函數osal_msg_send() 發送緩衝空間的資訊到其他任務,若該緩衝空間不能被分配,則設定msg_ptr=NULL空;

         uint8 *osal_msg_allocate( uint16 len ),返回的是指標,若返回為空白,則該資訊緩衝空間分配失敗。

   註:該函數不能與osal_mem_alloc()混淆,osal_mem_alloc()函數是用於為在任務間發送資訊分配緩衝區。該函數可以分配一個儲存空間。

2.osal_msg_deallocate( ) 資訊處理分配緩衝。該函數通過一個任務調用後完成處理一個接收的資訊。

        uint8 osal_msg_deallocate( uint8 *msg_ptr )

msg_ptr指向需要處理分配資訊緩衝的指標

成功;無效的資訊指標;緩衝被排隊。  

 3. osal_msg_send( )一個任務發送一個命令或資料資訊到其他任務或處理元素中。

uint8 osal_msg_send(uint8 destination_task, uint8 *msg_ptr )

 

4.osal_msg_receive( ) 任務接受一個命令資訊調用該函數

           uint8 *osal_msg_receive(uint8 task_id )

Return value is a pointer to a buffer containing the message or NULL if there is no received 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

二、任務同步API:允許一個任務等待某個事件的發生並返回等待期間的控制

作用:set events for a task and notify 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 ) 其中event_flag is a 2-byte bitmap ,每位對應一個事件
 There is only one system event (SYS_EVENT_MSG), the rest of the events/bits are defined by the receiving task

三、時間管理API該API允許定時器被內部和外部任務使用,具有開啟和停止一個定時器的功能,,該定時器能用1毫秒的增量設定。1.osal_start_timerEx( )啟動定時器 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 自動重載計數

3.osal_stop_timerEx( )停止已經被啟動的定時器 uint8 osal_stop_timerEx( uint8 task_id, uint16 event_id ); 4.osal_GetSystemClock( ) 讀取系統時鐘 uint32 osal_GetSystemClock( void );傳回值:The system clock in milliseconds.四、中斷管理API:是任務和外部中斷的介面,允許一個任務為每個中斷分配指定的服務程式1. osal_int_enable( ) 允許中斷 uint8 osal_int_enable( uint8 interrupt_id )2. osal_int_disable( )禁止某個中斷

 uint8 osal_int_disable( uint8 interrupt_id )

 

 五、任務管理API:用於添加和管理osal中的任務,每個任務都由初始化函數和事件處理函數組成。

OSAL calls 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] ); 計算數組元素個數

1.osal_init_system( )初始化osal系統:在啟動任何一個OSAL之前必須被調用

uint8 osal_init_system( void )傳回值為“SUCCESS”

2. osal_start_system( ) 任務系統的主迴圈函數

void osal_start_system( void )

3.osal_run_system( ) :void osal_run_system( void )

4.osal_self( )返回當前運行任務的ID號:uint8 osal_self( void )

 六、記憶體管理API:簡單的儲存分配系統。允許動態儲存裝置分配

1.osal_mem_alloc( ) 一簡單儲存分配函數,如果成功執行則返回指向一個緩衝的指標

void *osal_mem_alloc( uint16 size );一個無類型指標指向被分配的新的緩衝區

2. osal_mem_free( )釋放被分配的儲存空間以備再一次使用,只能釋放被 osal_mem_alloc()分配的儲存空間

void osal_mem_free( void *ptr );

七、電源管理API:當OSPL安全關閉接收器和外部硬體,並使處理器進入休眠模時,提供嚮應用/任務通報該事件的方法

osal_pwrmgr_device(), osal_pwrmgr_task_state( PWRMGR_HOLD )

1. osal_pwrmgr_init( ) :void osal_pwrmgr_init( void );不要調用此函數,因為已經在osal_init_system()中調用了

2. osal_pwrmgr_powerconserve( ) :void osal_pwrmgr_powerconserve( void );進入掉電模式

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 );

函數在電源供電狀態或者電源需要改變時調用,可以設定裝置電源管理的ON/OFF狀態,這函數應該在一個中心控制區別調用比如ZDO.

4.osal_pwrmgr_task_state( ):uint8 osal_pwrmgr_task_state(uint8 task_id, uint8 state );被每個任務調用,聲明該任務是否需要節能,當任務被建立時,預設是節能模式,如果總需要節能,那麼不需要調用該函數。state:傳回值八、非易失性儲存管理API:Non-Volatile Memory API

 NV 函數被設計為可以讀寫使用者定義的如結構或隊列等任意的資料類型組成的條目,flash or EEPROM

每個NV條目有個唯一的ID號,但都有規定和限制

 1.osal_nv_item_init( ):初始化一條目。該函數檢查一存在的條目,若它不存在,則它被建立並用攜帶的資料進行初始化,在對每個條目調用 osal_nv_read() or osal_nv_write()之前,這個函數必須被調用

uint8 osal_nv_item_init( uint16 id, uint16 len, void *buf );條目初始化資料的指標

2.osal_nv_read( ): uint8 osal_nv_read( uint16 id, uint16 offset, uint16 len, void *buf );從nv讀取資料。read an entire item from NV or an element of an item by indexing into the item with an offset。讀取的資料複製到*buf緩衝區

 

 3.osal_nv_write( ):寫資料到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( ):從nv中刪除條目。 uint8 osal_nv_delete( uint16 id, uint16 len );該函數檢查一存在的條目,若它存在,並且它的長度matches the length provided in the function call, 條目將從nv中移除。 5.osal_nv_item_len( ): uint16 osal_nv_item_len( uint16 id );在NV中得到一個條目的長度6.osal_offsetof( ):這個宏定義計算一個結構在記憶體中位移的大小(位元組) osal_offsetof(type, member)
 calculating the offset parameter 在NV API 函數中很有用。九、簡單的NV儲存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 the

OSAL Simple NV system implementation. 使用者可以讀寫整個條目但不能讀寫條目中的某部分

 1.osal_snv_read( ):uint8 osal_snv_read( osalSnvId_t id, osalSnvLen_t len, void *pBuf );從nv中讀取資料 2.osal_snv_write( ):寫資料到Nv:uint8 osal_snv_write( osalSnvId_t id, osalSnvLen_t len, void *pBuf );

 十、OSAL時鐘系統:為裝置保持日期和時間提供一種方法,This system will keep the number of seconds since 0 hrs, 0 minutes, 0 seconds on 1 January 2000 UTC,兩種資料類型或結構被定義在 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( ):從 osal_run_system()運行來更新時間,void osalTimeUpdate( void );
此函數reads the number of MAC 320usec ticks to maintain the OSAL Clock time. Do not call this function anywhere else2.osal_setClock( ) :初始化裝置時間。void osal_setClock( UTCTime newTime )

3.osal_getClock( ):調用這個函數來擷取裝置的目前時間。UTCTime osal_getClock( void );

4.osal_ConvertUTCTime( ) :將UTCTime轉換成 UTCTimeStruct的函數

void osal_ConvertUTCTime( UTCTimeStruct * tm, UTCTime secTime );

5.osal_ConvertUTCSecs( ) :將UTCTimeStruct轉換成UTCTime 的函數

UTCTime osal_ConvertUTCSecs( UTCTimeStruct * tm );

十一、OSAL Misc雜項:

This section describes miscellaneous OSAL functions that do not fit into the previous OSAL categories

描述不適合先前OSAL類別的多樣化OSAL函數。

1.osal_rand( ) :返回一個16位的隨機數uint16 osal_rand( void );

2. osal_memcmp( ) :比較記憶體部分。

uint8 osal_memcmp( const void GENERIC *src1, const void GENERIC *src2, unsigned int len );

傳回值:TRUE - same, FALSE - different

3.osal_memset( ):void *osal_memset( void *dest, uint8 value, int len );

功能Sets a buffer to a specific 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 );

功能Copies one buffer to another buffer,返回Pointer to end of destination buffer

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.