Zigbee网关 Zstack增加串口功能1-修改底层驱动MT/MT_UART.c
来源:互联网 发布:查找数组最大值最小值 编辑:程序博客网 时间:2024/06/04 18:55
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的协议,取消的方法在串口初始化函数里面
/*************************************************************************************************** * 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
- Zigbee网关 Zstack增加串口功能1-修改底层驱动MT/MT_UART.c
- Zigbee网关 Zstack增加串口功能2-修改应用层APP/ZigbeeGateWay.c
- Zigbee网关 上电时Zstack串口乱码
- Zigbee网关 cc2530 zstack添加1602驱动
- Zigbee网关 Zstack开启AES加密
- zigbee zstack 串口,按键,消息,定时器
- ZigBee Home Automation --- zstack串口应用总结
- zigbee网关 java 串口通信
- zigbee网关 CC2530 zstack用手机控制1602显示
- zigbee网关 zstack CC2530添加iic温度传感器lm75a
- ZigBee,ZStack
- ZigBee TI ZStack CC2530 3.18 串口01-发送
- ZigBee TI ZStack CC2530 3.20 串口03-printf()函数移植
- ZigBee TI ZStack CC2530 3.19 串口02-接收
- Zigbee网关 CC2530驱动1602显示屏
- zigbee网关 cc2530裸机驱动温度传感器LM75A
- ZigBee TI ZStack CC2530 3.12 LED驱动移植及使用
- ZigBee TI ZStack CC2530 3.15 按键驱动02-中断模式
- c++11单实例(singleton)初始化的几种方法(memory fence,atomic,call_once)
- ant批量打包
- mysql常用命令
- js 去掉字符串前后空格
- pAdTy_-7 管理活动的生命周期
- Zigbee网关 Zstack增加串口功能1-修改底层驱动MT/MT_UART.c
- 昂贵的聘礼
- extjs 4.2 学习笔记(一) 从“Hello World”开始
- textarea高度自适应
- DCMTK:DCM文件转QImage
- 编译器架构的王者LLVM——(7)函数的翻译方法
- 用户ID
- 统计表记录行数
- CUPS让Linux打印变得更轻松(转)