CSR8670蓝牙串口通信--UART
最近一直在学习CSR8670蓝牙芯片的开发,这方面的学习资料少的可怜,学习过程也很单一。我的主要学习过程:逛各种蓝牙学习论坛、阅读ADK安装包中的英文文档、请教各位硬件软件大牛,对于从未接触过硬件开发的我来说,过程真心痛苦。最近刚刚调通利用UART协议实现蓝牙串口通信的代码,Mark一下,也跟大家分享一下,请大家多多指教!
编译环境:ADK3.5
uart.h
1 #include <panic.h> 2 #include <stddef.h> 3 #include <led.h> 4 #include <string.h> 5 #include <stream.h> 6 #include <message.h> 7 8 #ifndef UARTDEMO_H 9 #define UARTDEMO_H 10 typedef struct 11 { 12 13 TaskData uart_task; 14 15 }Uart_TaskDataTest; 16 17 enum 18 { 19 SEND_UART_DATA 20 }; 21 22 void PilAppUARTInit(void); 23 24 void uart_send(const char *data, uint16 lenth); 25 26 void uart_handler(Task task, MessageId id, Message message); 27 28 void uart_rev(void); 29 #endif
uart.c
1 #include <panic.h> 2 #include <stddef.h> 3 #include <led.h> 4 #include <string.h> 5 #include <stream.h> 6 #include <message.h> 7 #include "uart.h" 8 #include "sink_private.h" 9 10 11 void PilAppUARTInit(void) 12 { 13 int lSize = sizeof(Uart_TaskDataTest) ; 14 theSink.UART_Task = mallocPanic(lSize); 15 memset(theSink.UART_Task, 0, lSize); 16 theSink.UART_Task->uart_task.handler = uart_handler; 17 MessageSinkTask(StreamUartSink(),&theSink.UART_Task->uart_task); 18 19 StreamUartConfigure(VM_UART_RATE_9K6 ,VM_UART_STOP_ONE,VM_UART_PARITY_NONE); 20 } 21 22 void uart_send(const char *data, uint16 lenth) 23 { 24 Sink uart = StreamUartSink(); 25 if (uart == 0) 26 { 27 return; 28 } 29 30 if(SinkClaim(uart, lenth) != 0xFFFF) 31 { 32 memcpy(SinkMap(uart), data, lenth); 33 (void) PanicZero(SinkFlush(uart, lenth)); 34 } 35 36 } 37 void uart_rev(void) 38 { 39 Source src=StreamUartSource(); 40 uint16 size=SourceSize(src); 41 SourceDrop(src, size); 42 43 } 44 45 46 void uart_handler(Task task, MessageId id, Message message) 47 { 48 switch(id) 49 { 50 case MESSAGE_MORE_DATA: 51 uart_rev(); 52 break; 53 default: 54 break; 55 } 56 }
sink_private.h的结构体hsTaskData中添加:Uart_TaskDataTest *UART_Task;
main.c中添加:PilAppUARTInit();
修改配置:sink工程->Properties->Bulid System->Transport选择:Raw