还是把NV写了吧。蛮累的 ,明天星期天,还得去工作,啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊。
什么是NV呢?NV就是Non Volatile缩写,就是非易失性存储性,通俗来说,就是即使系统掉电后,存储在该存储器的数据也不会丢失,在CC2530中这种存储器是Flash存储器。
在那个协议栈操作系统目录中 截个图吧 你就清楚了。
</pre><p></p><p></p><p><img src="http://img.blog.csdn.net/20151024211008516?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" /></p><p></p><p><span style="color:#006600">上边的宏定义有操作系统抽象类 网络层的 安全 设备对象等等对象已经使用了一些目录 给予用户的都在应用程序层的他有一个条目ID地址范围</span><span style="color:#cc33cc"> 0x0201~~0x0FFFF</span></p><p><span style="color:#cc0000">这就是我为什么定义0x0201原因了。</span></p><p><span style="color:#cc0000"></span></p><h1><span style="color:#cc0000">2改写程序的主Code了(大部分从GenericApp.c中复制稍微修改就好不用写)</span></h1><div><span style="color:#cc0000"></span></div><div><span style="color:#cc0000"></span></div><p><span style="color:#cc0000">如果你打开一个新协议栈 那么就把APP目录中的GenericApp.c和<span style="color:rgb(204,0,0)">GenericApp.h文件设成禁止编译 (如果不会就看上个博文第五步)然后新建文件Coordinator.c文件</span></span></p><p></p><pre name="code" class="cpp"><span style="background-color: rgb(51, 204, 0);">#include "OSAL.h" #include "AF.h" #include "ZDApp.h" #include "ZDObject.h" #include "ZDProfile.h" </span><span style="background-color: rgb(255, 255, 0);">#include "GenericApp.h" #include "DebugTrace.h" //不用写应该也可以</span><span style="background-color: rgb(51, 204, 0);"> #if !defined( WIN32 ) #include "OnBoard.h" #endif /* HAL */ #include "hal_lcd.h" #include "hal_led.h" #include "hal_key.h" #include "hal_uart.h" #include "OSAL_Nv.h"</span><span style="background-color: rgb(102, 51, 255);"> </span>const cId_t GenericApp_ClusterList[GENERICAPP_MAX_CLUSTERS] = { GENERICAPP_CLUSTERID }; const SimpleDescriptionFormat_t GenericApp_SimpleDesc = { GENERICAPP_ENDPOINT, // int Endpoint; GENERICAPP_PROFID, // uint16 AppProfId[2]; GENERICAPP_DEVICEID, // uint16 AppDeviceId[2]; GENERICAPP_DEVICE_VERSION, // int AppDevVer:4; GENERICAPP_FLAGS, // int AppFlags:4; GENERICAPP_MAX_CLUSTERS, // byte AppNumInClusters; (cId_t *)GenericApp_ClusterList, // byte *pAppInClusterList; 0, // byte AppNumInClusters; (cId_t *)NULL // byte *pAppInClusterList; }; endPointDesc_t GenericApp_epDesc; byte GenericApp_TaskID; byte GenericApp_TransID; void GenericApp_MessageMSGCB( afIncomingMSGPacket_t *pkt ); void GenericApp_SendTheMessage( void ); static void rxCB (uint8 port,uint8 event);//添加 void GenericApp_Init( byte task_id ) { halUARTCfg_t uartConfig;//声明一个新的串口 GenericApp_TaskID = task_id; //GenericApp_NwkState = DEV_INIT; GenericApp_TransID = 0; // Device hardware initialization can be added here or in main() (Zmain.c). // If the hardware is application specific - add it here. // If the hardware is other parts of the device add it in main(). //GenericApp_DstAddr.addrMode = (afAddrMode_t)AddrNotPresent; //GenericApp_DstAddr.endPoint = 0; //GenericApp_DstAddr.addr.shortAddr = 0; // Fill out the endpoint description. GenericApp_epDesc.endPoint = GENERICAPP_ENDPOINT; GenericApp_epDesc.task_id = &GenericApp_TaskID; GenericApp_epDesc.simpleDesc = (SimpleDescriptionFormat_t *)&GenericApp_SimpleDesc; GenericApp_epDesc.latencyReq = noLatencyReqs; // Register the endpoint description with the AF afRegister( &GenericApp_epDesc ); // // Register for all key events - This app will handle all key events // RegisterForKeys( GenericApp_TaskID ); // // // Update the display //#if defined ( LCD_SUPPORTED ) // HalLcdWriteString( "GenericApp", HAL_LCD_LINE_1 ); //#endif // // ZDO_RegisterForZDOMsg( GenericApp_TaskID, End_Device_Bind_rsp ); // ZDO_RegisterForZDOMsg( GenericApp_TaskID, Match_Desc_rsp ); uartConfig.configured = TRUE; uartConfig.baudRate = HAL_UART_BR_115200; uartConfig.flowControl = FALSE; uartConfig.callBackFunc = rxCB; HalUARTOpen (0,&uartConfig);//添加 } UINT16 GenericApp_ProcessEvent( byte task_id, UINT16 events ) { //用不着 所以为空就好 } static void rxCB(uint8 port,uint8 event) { uint8 value_read; <span style="background-color: rgb(102, 51, 255);"> uint8 value = 18;//这个18就是串口收到的数据</span> uint8 uartbuf[2]; uint8 cmd[6]; HalUARTRead(0,cmd,6); <span style="background-color: rgb(51, 102, 255);">if(osal_memcmp(cmd,"nvread",6))//这里的nvread就是从串口助手中向板子发射的信息</span> { osal_nv_item_init(TEST_NV,1,NULL); osal_nv_write(TEST_NV,0,1,&value); osal_nv_read(TEST_NV,0,1,&value_read); uartbuf[0]=value_read / 10+'0'; uartbuf[1]=value_read % 10+'0'; HalUARTWrite(0,uartbuf,2); } }<span style="background-color: rgb(255, 255, 255);"> </span>
实验结果
睡了 明天还有活儿。