连续签到天数:1天 | 签到总天数:1170天 | 签到总奖励:45846金币 |
|
发表于 2020-7-20 11:38:46
|
显示全部楼层
本帖最后由 basketcase 于 2020-9-8 01:01 编辑
给你个参考吧,头文件自己补全就行了。IO随便指定都可以,htf不需要配置
- /*! \brief UI task structure */
- typedef struct
- {
- /*! The UART task */
- TaskData task;
- /*! The UART task status */
- bool initialised;
- /*! The UART Source */
- Source source;
- /*! The UART Sink */
- Sink sink;
- }uartTaskData;
复制代码
- #define BOARD_UART_TX 0xa
- #define BOARD_UART_RX 0xb
- #define BOARD_UART_RTS 0x0
- #define BOARD_UART_CTS 0x0
复制代码- void appUartSendToSink(const char *cmd)
- {
- uint16 cmd_len = strlen(cmd);
-
- if(uartData.sink && (SinkSlack(uartData.sink)) >= cmd_len)
- {
- /* Claim space in the sink, getting the offset to it. */
- uint16 offset = SinkClaim(uartData.sink, cmd_len);
- /* Check we have a valid offset */
- if (offset != 0xFFFF)
- {
- /* Map the sink into memory space. */
- uint8 *snk = SinkMap(uartData.sink);
-
- if(snk == NULL)
- {
- //DEBUG_LOG("Invalid Sink pointer");
- }
- (void) PanicNull(snk);
- /* Copy the string into the claimed space. */
- memcpy(snk+offset, cmd, cmd_len);
-
- /* Flush the data out to the UART. */
- PanicZero(SinkFlush(uartData.sink, cmd_len));
- }
- else
- {
- //DEBUG_LOG("Invalid sink offset");
- }
- }
- else
- {
- //DEBUG_LOG("Invalid UART Sink or Insufficient space in Sink");
- }
- }
复制代码
- /*! UART Message Handler
- Expecting MESSAGE_MORE_DATA for each AT command
- */
- static void appUartHandler(Task task, MessageId id, Message msg)
- {
- UNUSED(task);
- UNUSED(msg);
- switch (id)
- {
- case MESSAGE_MORE_DATA:
- {
- }
- break;
- default:
- break;
- }
- }
复制代码
- bool appUartInitConnection(void)
- {
- /* Assign the appropriate PIOs to be used by UART. */
- bool status = FALSE;
- uint32 bank = 0;
- uint32 mask = (1<<BOARD_UART_RTS) | (1<<BOARD_UART_CTS) | (1<<BOARD_UART_TX) | (1<<BOARD_UART_RX);
- if (!uartData.initialised)
- {
- //DEBUG_LOG("appUartInitConnection start");
- status = PioSetMapPins32Bank(bank, mask, 0);
- PanicNotZero(status);
-
- PioSetFunction(BOARD_UART_RTS, UART_RTS);
- PioSetFunction(BOARD_UART_CTS, UART_CTS);
- PioSetFunction(BOARD_UART_TX, UART_TX);
- PioSetFunction(BOARD_UART_RX, UART_RX);
- StreamUartConfigure(VM_UART_RATE_1382K4, VM_UART_STOP_ONE, VM_UART_PARITY_NONE);
- uartData.sink = StreamUartSink();
- PanicNull(uartData.sink);
- /* Configure the sink such that messages are not received */
- SinkConfigure(uartData.sink, VM_SINK_MESSAGES, VM_MESSAGES_NONE);
- uartData.source = StreamUartSource();
- PanicNull(uartData.source);
- /* Configure the source for getting all the messages */
- SourceConfigure(uartData.source, VM_SOURCE_MESSAGES, VM_MESSAGES_ALL);
- /* Associate the task with the stream source */
- uartData.task.handler = appUartHandler;
- MessageStreamTaskFromSink(StreamSinkFromSource(uartData.source), (Task) &uartData.task);
- //DEBUG_LOG("appUartInitConnection end");
- uartData.initialised=TRUE;
- }
- else
- {
- //DEBUG_LOG("UART Already Initialised");
- }
-
- return uartData.initialised;
- }
复制代码
|
评分
-
查看全部评分
|