HAL层三类函数及其作用

       HAL的函数主要由三种,初始化函数(Initialization Function Calls)、服务访问函数(Service Access Function Calls )、以及回调函数(Callback Function Calls )。还是习惯看英文,觉得自己的中文翻译有的时候不伦不类,误导了亲们。

且看document定义:

Initialization Function Calls :

 

These function calls are used to initialize a service and /or to setup optional parameters for platform-specific data. Initialization functions are often called at the beginning stage when the device powers up. 

看到了吧,初始化函数主要是用于初始化,且是在上电后,而不是在系统中。且看在zstack中,main函数上电后的初始化中的一些函数吧,

 

int main( void )

{

...

  // Initialization for board related stuff such as LEDs

HAL_BOARD_INIT();

...

  // Initialze HAL drivers

  HalDriverInit();

...

 

} // main()

所以HAL的初始化函数大多数在这里调用,其余的位置没有显示的用HAL层的函数初始化,这里就不一一列举。

Service Access Function Calls :

These function calls can directly access hardware registers to get/set certain value of the hardware  (i.e.

ADC) or control the hardware components (i.e. LED).

主要是用于访问或者控制硬件的,直接从硬件读取硬件寄存器的值,看来这个还是很犀利的。

Callback Function Calls:

These functions must be implemented by the application and are used to pass events that are generated by

the hardware (interrupts, counters, timers…) or by polling mechanism (UART poll, Timer poll…) to upper

layers. Data accessed through callback function parameters (such as a pointer to data) are only valid for the execution of the function and should not be considered valid when the function returns.  If these functions execute in the context of the interrupt, it must be efficient and not perform CPU-intensive operations or use critical sections. 

 

  第三个是回调函数类型,回调函数这个时候还是系统打交道了。所以这个就相对复杂一点。这类函数由任务来实现,并用于传递事件。在这里我们先不先深入了解,只是了解一点简单的,后续讲有关串口的时候会用到这类函数,我会再讲讲。

转载于:https://www.cnblogs.com/farbeyond/p/5204605.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值