wakojosin 发表于 2024-2-26 23:39

KW41Z板卡Thread end device例程代码分析

<p><strong><span style="font-size:18px;">主要功能</span></strong></p>

<p>通过coap来进行数据交互,coap初始化,创建了3个URI,分别是&#39;/led&#39;、&#39;/temp&#39;和&#39;/sink&rsquo;。</p>

<p>sink用来配置目标地址,默认是in6addr_realmlocal_allthreadnodes,看着像广播地址;</p>

<p>led用来控制板子上的led状态;</p>

<p>temp用来读取温度传感器值;</p>

<p>&nbsp;</p>

<p><strong><span style="font-size:18px;">代码调用过程</span></strong></p>

<p><strong><span style="font-size:16px;">应用的主要实现</span></strong></p>

<p>main_task://nwk_ip/app/common/app_init.c<br />
&nbsp; &nbsp; THR_Init://nwk_ip/app/common/app_thread_init.c<br />
&nbsp; &nbsp; &nbsp; &nbsp; OSA_TaskCreate():THR_Task</p>

<p>//THR_Task:用于处理来自物理层、ip层、协议层的任务消息,优先级依次降低;</p>

<p>//&nbsp; &nbsp; 内部调用了NWKU_MsgHandler,未找到源码。<br />
&nbsp; &nbsp; APP_Init://source/end_device_app.c<br />
&nbsp; &nbsp; &nbsp; &nbsp; THR_StartInstance(mThrInstanceId, pStackCfg) //使用默认参数,参数内容有点长,不列出<br />
&nbsp; &nbsp; &nbsp; &nbsp; APP_InitCoapDemo()<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; COAP_CreateInstance()//无源码<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //初始化创建了3个coap URI,分别是&#39;/led&#39;,&#39;/temp&#39;,&#39;/sink&#39;,服务端口5683<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //&#39;/led&#39;回调APP_CoapLedCb:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; APP_ProcessLedCmd:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //&#39;on&#39; &nbsp; &nbsp;:App_UpdateStateLeds(gDeviceState_AppLedOn_c)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //&#39;off&#39; &nbsp; :App_UpdateStateLeds(gDeviceState_AppLedOff_c)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //&#39;toggle&#39;:App_UpdateStateLeds(gDeviceState_AppLedToggle_c)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //&#39;flash&#39; :App_UpdateStateLeds(gDeviceState_AppLedFlash_c)</p>

<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //...<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; COAP_Send(gCoapMsgTypeAckSuccessChanged_c)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //&#39;/temp&#39;回调APP_CoapTempCb:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //gCoapGET_c:App_GetTempDataString<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //gCoapPOST_c:shell_printf(pData)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //&#39;/sink&#39;回调APP_CoapSinkCb:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //&#39;create&#39;:设置gCoapDestAddress,用于coap消息的目标地址<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //&#39;release&#39;:设置为默认值</p>

<p>&nbsp;</p>

<p><strong><span style="font-size:16px;">PHY的数据上报</span></strong></p>

<p>PD_SendMessage:phy层通过此接口调用PD_MAC_SapHandler发送接收的数据报文;<br />
&nbsp; &nbsp; PD_MAC_SapHandler:通过Phy_RegisterSapHandlers接口注册,Phy_RegisterSapHandlers未找到调用的地方<br />
&nbsp;</p>

<p><strong><span style="font-size:18px;">总结</span></strong></p>

<p>文章内容不多,主要是coap、thread等都是提供的库,SDK中没有实现的源码,所以只是大概的一个过程,接下去的计划是先找找看有没有NXP协议栈的源码,如果没有就打算以openthread再搭建工程来进行协议栈的学习,然后以openthread的内容进行分享了,这样也可以跟其他厂家芯片(以openthread作为thread协议栈的)进行方便的互联。</p>

Jacktang 发表于 2024-2-27 07:37

<p>虽然SDK中没有实现的源码,只是大概的一个过程,分析比较到位了</p>
页: [1]
查看完整版本: KW41Z板卡Thread end device例程代码分析