今天是14号 15号更新,说明,刚开始看程序有点复杂 没办法,必须看代码
建议首先先把ADK3.5.1中的例程tutorials看完,对学习很有帮助
1.csr中的消息机制
1.1 adk3.5.1中的led的例子
- csr8670中是以消息机制进行任务调度的,根据消息调用相应的回调函数进行处理,如下面这个例子所示:在主函数中,首先设置PIO为输出并且设置为低电平,然后调用了messagesend函数和messageloop函数
- TaskData :这个结构体是最重要的,可以看出定义了一个函数指针,其参数有三个
typedef struct TaskData { void (*handler)(Task, MessageId, Message); } TaskData;
- messagesend:这个函数能够向某个任务发送消息
- messageloop:开始任务调度,不会返回
static void led_controller1( Task t, MessageId id, Message payload )
{
PioSet32( LED1, (PioGet32() ^ LED1) );
MessageSendLater( t, 0, 0, DELAY1 );
}
static void led_controller2( Task t, MessageId id, Message payload )
{
PioSet32( LED2, (PioGet32() ^ LED2) );
MessageSendLater( t, 0, 0, DELAY2 );
}
static TaskData led_controller1_task = { led_controller1 };//实例化了一个任务,并初始化了其参数,即回调函数
static TaskData led_controller2_task = { led_controller2 };
int main(void)
{
PioSetDir32(0xFF, 0xFF); /* Set all PIO to be output */
PioSet32(0xFF, 0); /* Set all PIO off (0) */
MessageSend( &led_controller1_task, 0 , 0 );//第一个参数为发送给哪个任务
MessageSend( &led_controller2_task, 0 , 0 );
MessageLoop();//开始任务调度
return 0;
}
1.2 hsTaskData结构体
csr中是以消息机制来进行任务的处理的,其中最大的任务为theSink,其结构体如下
/* Sink application data */
typedef struct
{
/* Main task */
TaskData task;//最重要的任务,指向最高层的回到函数,即main函数里边的app_handler
/* Config variables */
ButtonsTaskData *theButtonsTask;//按键的任务,这些是最高层任务之下的任务,之所以定义在最高层里面,应该是想让最高层具有知道所有事件运行情况的能力
LedTaskData *theLEDTask;//led显示的任务,同上
runtime_block1_t *rundata;//运行时的数据,目前还不了解
config_block1_t *conf1;//解下来的7个block以后会分析
config_block2_t *conf2;
config_block3_t *conf3;
config_block4_t *conf4;
config_block5_t *conf5;
config_block6_t *conf6;
config_block7_t *conf7;
ConfigTone_t gConfigTones;
volume_levels_t *volume_levels; /* current operating volume levels for a2dp/usb/wired modes */
power_table *user_power_table; /* pointer to user power table if available in ps */
hfp_common_plugin_params_t hfp_plugin_params;
HFP_features_type HFP_supp_features;
feature_config_type features;
bdaddr local_bd_addr; /* Local BD Address of the sink device available in ps */
/* Runtime variables */
/*下面这些运行时的变量都是在动态的生成或者释放的,每一个和button一样都是一个任务*/
Task codec_task ;
Sink routed_audio;
uint16 NoOfReconnectionAttempts;
profile_data_t profile_data[MAX_MULTIPOINT_CONNECTIONS];
a2dp_data *a2dp_link_data;
#ifdef ENABLE_AVRCP
avrcp_data *avrcp_link_data;
#endif
tp_bdaddr *confirmation_addr;
inquiry_data_t inquiry;
#ifdef ENABLE_PBAP
pbapc_data_t pbapc_data;
#endif
#ifdef ENABLE_USB
usb_info *usb;
#endif
#ifdef ENABLE_PEER
bdaddr remote_peer_ag_bd_addr;
#endif
user_eq_bank_t *PEQ;
/*! Runtime flags*/
/*word 1*/
unsigned PowerOffIsEnabled:1; /*自行百度结构体的用法,这样写应该是为了节省空间*/
unsigned SinkInitialising:1;
unsigned VolumeOrientationIsInverted:1; /*whether or not the vol buttons are inverted*/
unsigned NetworkIsPresent:1;
unsigned inquiry_scan_enabled:1;
unsigned page_scan_enabled:1 ;
unsigned csr_speech_recognition_is_active:1 ;
unsigned csr_speech_recognition_tuning_active:1 ;
unsigned panic_reconnect:1;
unsigned last_outgoing_ag:2 ; /* which AG made the last outgoing call */
unsigned audio_prompts_enabled:1;
unsigned confirmation:1;
unsigned debug_keys_enabled:1;
unsigned RepeatCallerIDFlag:1;
unsigned mute_all_outputs:1;
/*word 2*/
unsigned audio_prompt_language:4;
unsigned num_audio_prompt_languages:4;
unsi