Zigbee网关 Zstack增加串口功能1-修改底层驱动MT/MT_UART.c
2015-11-11 09:38
323 查看
ZigbeeGateWay工程协调器用了串口, 对于协调器,uart接到了P1口(USART1),P0口用作跟以太网芯片通讯。
P1_6 --> TXD
P1_7 --> RXD
这正好与zstack定义宏ZTOOL_P1初始化的串口的引脚相同
而定义宏ZTOOL_P1的时候,系统的串口默认是跟PC机的Z-Tool 2.0.exe通信的,Z-Tool 2.0.exe默认目录C:\Texas Instruments\ZStack-CC2530-2.4.0-1.4.0\Tools\Z-Tool
所以,需要先取消与pc机的Ztool的协议,取消的方法在串口初始化函数里面
在初始化函数中,如果定义了(ZTOOL_P1)或者(ZTOOL_P2)默认回调函数是MT_UartProcessZToolData,把回调函数改成MT_UartProcessZAppData即可
将MT_UartMaxZAppBufLen改成20或者大一点的,这时设置接收buffer大小的;MT_UART_DEFAULT_IDLE_TIMEOUT是设置2个字符来的间隔如果在
MT_UART_DEFAULT_IDLE_TIMEOUT内,认为是一串的。
但是改成MT_UartProcessZAppData后编译提示找不到MT_UartMaxZAppBufLen 和MT_UartZAppRxStatus 所以将顶上的全局变量
中的宏定义
将
也注释掉,否则每次接受完的时候都得重新调用
MT_UartAppFlowControl ( MT_UART_ZAPP_RX_READY );
至此,底层的驱动修改完成
下一步应该修改app层应用,详见
http://blog.csdn.net/u010615629/article/details/49778155
P1_6 --> TXD
P1_7 --> RXD
这正好与zstack定义宏ZTOOL_P1初始化的串口的引脚相同
而定义宏ZTOOL_P1的时候,系统的串口默认是跟PC机的Z-Tool 2.0.exe通信的,Z-Tool 2.0.exe默认目录C:\Texas Instruments\ZStack-CC2530-2.4.0-1.4.0\Tools\Z-Tool
所以,需要先取消与pc机的Ztool的协议,取消的方法在串口初始化函数里面
/*************************************************************************************************** * LOCAL FUNCTIONS ***************************************************************************************************/ /*************************************************************************************************** * @fn MT_UartInit * * @brief Initialize MT with UART support * * @param None * * @return None ***************************************************************************************************/ void MT_UartInit () { halUARTCfg_t uartConfig; /* Initialize APP ID */ App_TaskID = 0; /* UART Configuration */ uartConfig.configured = TRUE; uartConfig.baudRate = MT_UART_DEFAULT_BAUDRATE; uartConfig.flowControl = FALSE;//MT_UART_DEFAULT_OVERFLOW; uartConfig.flowControlThreshold = MT_UART_DEFAULT_THRESHOLD; uartConfig.rx.maxBufSize = MT_UART_DEFAULT_MAX_RX_BUFF; uartConfig.tx.maxBufSize = MT_UART_DEFAULT_MAX_TX_BUFF; uartConfig.idleTimeout = MT_UART_DEFAULT_IDLE_TIMEOUT; uartConfig.intEnable = TRUE; #if defined (ZTOOL_P1) || defined (ZTOOL_P2) //uartConfig.callBackFunc = MT_UartProcessZToolData; uartConfig.callBackFunc = MT_UartProcessZAppData; #elif defined (ZAPP_P1) || defined (ZAPP_P2) uartConfig.callBackFunc = MT_UartProcessZAppData; #else uartConfig.callBackFunc = NULL; #endif /* Start UART */ #if defined (MT_UART_DEFAULT_PORT) HalUARTOpen (MT_UART_DEFAULT_PORT, &uartConfig); #else /* Silence IAR compiler warning */ (void)uartConfig; #endif /* Initialize for ZApp */ //#if defined (ZAPP_P1) || defined (ZAPP_P2) /* Default max bytes that ZAPP can take */ MT_UartMaxZAppBufLen = 20; MT_UartZAppRxStatus = MT_UART_ZAPP_RX_READY; //#endif }
在初始化函数中,如果定义了(ZTOOL_P1)或者(ZTOOL_P2)默认回调函数是MT_UartProcessZToolData,把回调函数改成MT_UartProcessZAppData即可
将MT_UartMaxZAppBufLen改成20或者大一点的,这时设置接收buffer大小的;MT_UART_DEFAULT_IDLE_TIMEOUT是设置2个字符来的间隔如果在
MT_UART_DEFAULT_IDLE_TIMEOUT内,认为是一串的。
但是改成MT_UartProcessZAppData后编译提示找不到MT_UartMaxZAppBufLen 和MT_UartZAppRxStatus 所以将顶上的全局变量
/*************************************************************************************************** * GLOBAL VARIABLES ***************************************************************************************************/ /* Used to indentify the application ID for osal task */ byte App_TaskID; /* ZTool protocal parameters */ uint8 state; uint8 CMD_Token[2]; uint8 LEN_Token; uint8 FSC_Token; mtOSALSerialData_t *pMsg; uint8 tempDataLen; //#if defined (ZAPP_P1) || defined (ZAPP_P2) uint16 MT_UartMaxZAppBufLen; bool MT_UartZAppRxStatus; //#endif
中的宏定义
//#if defined (ZAPP_P1) || defined (ZAPP_P2)注释掉,还有同时注释掉串口初始化函数中的宏#if
//#if defined (ZAPP_P1) || defined (ZAPP_P2) /* Default max bytes that ZAPP can take */ MT_UartMaxZAppBufLen = 20; MT_UartZAppRxStatus = MT_UART_ZAPP_RX_READY; //#endif最后注释宏#if使能跟App相关的一些方法
//#if defined (ZAPP_P1) || defined (ZAPP_P2) /*************************************************************************************************** * @fn MT_UartProcessZAppData * * @brief | SOP | CMD | Data Length | FSC | * | 1 | 2 | 1 | 1 | * * Parses the data and determine either is SPI or just simply serial data * then send the data to correct place (MT or APP) * * @param port - UART port * event - Event that causes the callback * * * @return None ***************************************************************************************************/ void MT_UartProcessZAppData ( uint8 port, uint8 event ) { osal_event_hdr_t *msg_ptr; uint16 length = 0; uint16 rxBufLen = Hal_UART_RxBufLen(MT_UART_DEFAULT_PORT); /* If maxZAppBufferLength is 0 or larger than current length the entire length of the current buffer is returned. */ if ((MT_UartMaxZAppBufLen != 0) && (MT_UartMaxZAppBufLen <= rxBufLen)) { length = MT_UartMaxZAppBufLen; } else { length = rxBufLen; } /* Verify events */ if (event == HAL_UART_TX_FULL) { // Do something when TX if full return; } if (event & ( HAL_UART_RX_FULL | HAL_UART_RX_ABOUT_FULL | HAL_UART_RX_TIMEOUT)) { if ( App_TaskID ) { /* If Application is ready to receive and there is something in the Rx buffer then send it up */ if ((MT_UartZAppRxStatus == MT_UART_ZAPP_RX_READY ) && (length != 0)) { /* Disable App flow control until it processes the current data */ // MT_UartAppFlowControl (MT_UART_ZAPP_RX_NOT_READY); /* 2 more bytes are added, 1 for CMD type, other for length */ msg_ptr = (osal_event_hdr_t *)osal_msg_allocate( length + sizeof(osal_event_hdr_t) ); if ( msg_ptr ) { msg_ptr->event = SPI_INCOMING_ZAPP_DATA; msg_ptr->status = length; /* Read the data of Rx buffer */ HalUARTRead( MT_UART_DEFAULT_PORT, (uint8 *)(msg_ptr + 1), length ); /* Send the raw data to application...or where ever */ osal_msg_send( App_TaskID, (uint8 *)msg_ptr ); } } } } } /*************************************************************************************************** * @fn SPIMgr_ZAppBufferLengthRegister * * @brief * * @param maxLen - Max Length that the application wants at a time * * @return None * ***************************************************************************************************/ void MT_UartZAppBufferLengthRegister ( uint16 maxLen ) { /* If the maxLen is larger than the RX buff, something is not right */ if (maxLen <= MT_UART_DEFAULT_MAX_RX_BUFF) MT_UartMaxZAppBufLen = maxLen; else MT_UartMaxZAppBufLen = 1; /* default is 1 byte */ } /*************************************************************************************************** * @fn SPIMgr_AppFlowControl * * @brief * * @param status - ready to send or not * * @return None * ***************************************************************************************************/ void MT_UartAppFlowControl ( bool status ) { /* Make sure only update if needed */ if (status != MT_UartZAppRxStatus ) { MT_UartZAppRxStatus = status; } /* App is ready to read again, ProcessZAppData have to be triggered too */ if (status == MT_UART_ZAPP_RX_READY) { MT_UartProcessZAppData (MT_UART_DEFAULT_PORT, HAL_UART_RX_TIMEOUT ); } } //#endif //ZAPP
将
MT_UartAppFlowControl (MT_UART_ZAPP_RX_NOT_READY);
也注释掉,否则每次接受完的时候都得重新调用
MT_UartAppFlowControl ( MT_UART_ZAPP_RX_READY );
至此,底层的驱动修改完成
下一步应该修改app层应用,详见
http://blog.csdn.net/u010615629/article/details/49778155
相关文章推荐
- Object-C中的内存管理小记
- hightchart属性(更新中...)
- linux命令:tar
- Asp.net文档的下载,基于httpp协议实现
- linux ssh without passwd
- android 三种定位方式
- JavaScript中清空数组的三种方式
- Android快速SDK(11)圆弧菜单库PathView【傻瓜模式】
- 详解Linux实际ID有效ID
- Oracle过程包加密
- linux命令:du,看文件大小
- linux命令:rm
- MySQL的安装以及基本的管理命令和设置
- Android开发 ListView下拉刷新和上拉加载
- JS中数组的操作
- Gentoo安装
- 微信扫码支付官方配置(一)
- 百度apistore第三方登陆使用说明
- 【NOIP2015】【BZOJ4326】运输计划
- VBA记录