44922004.doc
gpio_int_polarity_type polarity, gpio_int_handler_type handler ) /*指定ISR 以及触发极性*/ typedef enum {
/* GPIO_GROUP 1*/ GPIO_INT_0 = 0, GPIO_INT_1, GPIO_INT_2, GPIO_INT_3, GPIO_INT_4, … …
} gpio_int_type; typedef enum {
DETECT_LEVEL = 0, DETECT_EDGE } gpio_int_detect_type; typedef enum {
ACTIVE_LOW = 0, ACTIVE_HIGH } gpio_int_polarity_type;
A) 参数which_group_int 指定GPIO , detect 指定中断是电平触发方式还是边沿触发方式。 B) 参数which_group_int 指定GPIO, polarity 与gpio_int_set_detect 中指定的detect 值相关, 若detect 指定电平触发方式,polarity 就表示指定中断是高电平触发还是低电平触发;若detect 指定
polarity 就表示指定中断是上升沿触发还是下降沿触发。handler 指定该中断的ISR,边沿触发方式,
若handle 为NULL 则表示取消此GPIO 的中断处理,
联想移动产品开发部软件处 - 18 -
44922004.doc
也就是说以后此GPIO 输入任何信号都不会触发中断了。 例子:/*将GPIO 3 设置为中断高电平触发*/
gpio_int_set_detect (GPIO_INT_3, DETECT_LEVEL );
gpio_int_set_handler(GPIO_INT_3, ACTIVE_HIGH, &GPIO_3_isr);
3.3.3 GPIO注意事项
1. 必须保证我们要用的GPIO 没有已被其他地方用作其它用途,否则可能会出现一些莫名其妙的现象。
2. 确保GPIO 已被正确配置。每个GPIO 都有缺省的配置,如果缺省的配置不符合我们的要求,我们就需要对GPIO 进行重新配置。
3. 注意GPIO 的上拉电阻或者下拉电阻的设置情况。例如:将GPIO 设置为有下来电阻输入口,若外部输入的高电平电压不够高,就可能导致读入电平介于高低电平电压之间,从而无法准确辨别出高电平还是低电平。
3.4 内存管理
高通平台上内存管理机制由三个部分组成:队列(Queue)、DS存储池、Watermark。其中真正存放数据的DS存储池,其他两个则是管理机制。 3.4.1 队列(Queue)
? Single-linked list of data blocks (数据块单链表)
? Each data block has a link field to the next data block (每个数据块有一个指针域(link field)指向下一个数据块)
? Always use queue functions to use the queues (总是使用队列函数来操作队列)
– Declared in queue.h
– q_init( ) – initializes the queue (初始化队列)
– q_link( ) – initializes the link field of the item (初始化队列的指针域)
– q_get() – removes the element from the head of the queue (从队列头部取出一个元素并将
其从队列中去除) – q_check() – returns the pointer to the first element; does not remove (返回队列的第一个元
素的指针,但不删除它)
联想移动产品开发部软件处 - 19 -
44922004.doc
– q_put() – puts the element at the tail of the queue (添加一个元素到队列尾部) – q_cnt() – counts the number of elements in the queue (计算队列中有几个元素) The model of Queue :
队列广泛使用在DS的存储池中,贯穿于整个DS的相关代码中。
3.4.2 DS存储池 在高通软件平台上,它的数据存储方式比较特别。事先划分一块区域用于数据存储,并且为不同应用再细分一个Pool(池),这个Pool是由固定大小item(用于存储数据块)组成。应用不同,这个item的数据容量也不一样。每个用户申请的就是这个item.它的具体特点: ? Statically allocated memory in RAM (静态分配于RAM中) ? A number of DSM pools (不止一个DSM pool)
– Each pool is allocated as a static array(每一个pool都是以一个静态数组的形式分配空间的) – Flow control is built into each pool based on the number of free items many, few, dont_exceed (流控制被构造于每个DSM pool中)
? Each pool has a fixed number of items (called DSM items)(每个存储池都有固定数量的item成为DSM items)
联想移动产品开发部软件处 - 20 -
44922004.doc
– Each DSM item in each pool has the same fixed number of payload bytes (在同一个存储池中的所有DSM item都有相同的有效字节数)
– All DSM items across all pools have the same overhead bytes(所有存储池中的所有DSM item都有相同的字节数?)
? Can link each DSM two dimensionally (每个DSM都可以以二维方式连接构造) – link_ptr for queues (队列方式) – pkt_ptr for items (条目方式)
使用时,只要将数据Copy到data_ptr,并将数据长度赋给used,其他成员在申请,系统已经初始化好了。注:Copy时要注意每个Item最大数据容量—size.如果一个不够,再申请一个,强制copy一个超出范围的数据,会将Pool污染。导致后续莫名死机。
联想移动产品开发部软件处 - 21 -
44922004.doc
3.4.3 Watermark –flow control point
Watermark用于提供通用数据流控制解决方案,具体怎样实现可以从它的结构体和代码入手分析:
可以看出,一个watermark中包含了字节数(current_cnt)、底限(lo_watermark)、上限(hi_watermark)以及各种call back指针(hiwater_func_ptr)和队列Q的指针等。
当上层应用(比如DS)通过底层设备来进行数据传输时(具体流程我们会在SIO章节中介绍),他们共同维护watermark,高通提供一些使用watermark的函数。 以下是代码中提供的几个watermark相关函数接口: dsm_enqueue(wmark, item)
联想移动产品开发部软件处 - 22 -