/*! * \file uart.c * * \brief Target uart implementation * * \copyright Revised BSD License, see section \ref LICENSE. * * \code * * _ __ _ ________ _ * | |/ /(_)___ / ____/ /_ (_)___ * | // / __ \/ / / __ \/ / __ \ * / |/ / / / / /___/ / / / / /_/ / * /_/|_/_/_/ /_/\____/_/ /_/_/ .___/ * /_/ * (C) 2022-2025 XinChip * * \endcode * * \author ( XinChip ) Alex-J * * \author ( XinChip ) */ /*----------------------------------------------------------------------------------- INCLUDE HEADE FILES ------------------------------------------------------------------------------------*/ #include "uart.h" #include "xc_drv_uart.h" /*------------------------------------------------------------------------------------ Macros -------------------------------------------------------------------------------------*/ /*------------------------------------------------------------------------------------ Global Variables -------------------------------------------------------------------------------------*/ uint8_t only_read_charactertics_buffer[5]; uint8_t only_read_charactertics_buffer_length = 5; ring_buffer_t uart0_ring_buff; uint8_t buffer[5] = {0xAA, 0xAA, 0xAA, 0xAA, 0xAA}; uint8_t uart0_buff[UART0_BUFFER_LEN]; extern bool buffer_complet_flag; // void uart_receive_cb(uint8_t *buff, uint16_t len) { // static uint8_t cnt = 0; // for (int i = 0; i < len; i++) { // // uart_user_ctl.r_buff[cnt++] = buff[i]; // // uart_user_ctl.r_len++; // ring_buffer_queue(&uart0_ring_buff, buff[i]); // } // // if (cnt == sizeof(uart_user_ctl.r_buff)) // { // //uart_user_ctl.rx_done = true; // cnt = 0; // } } /// void scan_uart(uint8_t *arr) { uint8_t uart_handle = UART0_IDX; buffer_complet_flag=false; // 组帧:帧头 + 数据 + 校验 uint8_t frame[6]; // 1字节帧头 + 4字节数据 + 1字节校验位 frame[0] = 0xAA; // 帧头标志 for (uint8_t i = 0; i < 4; i++) { frame[1 + i] = arr[i]; // 填充数据 } // 校验位:简单累加校验 uint8_t checksum = 0; for (uint8_t i = 0; i < 5; i++) // 帧头和数据 { checksum += frame[i]; } frame[5] = checksum; // 校验位 //DEBUG("fff\n"); //LOGI("ffff\r\n"); // 发送帧 xc_uart_send_data(uart_handle, frame, 6); // 发送完整帧 // DEBUG("temp[0]:%d,temp[1]:%d,temp[2]:%d,temp[3]:%d,temp[4]:%d,temp[5]:%d\n",frame[0],frame[1],frame[2],frame[3],frame[4],frame[5]); } void scan_uart_ota(uint8_t *arr){ uint8_t uart_handle = UART0_IDX; buffer_complet_flag = false; // 清除标志 xc_uart_send_data(uart_handle, arr,139); // 发送完整帧 } void scan_uart_usr(uint8_t *arr){ uint8_t uart_handle = UART0_IDX; buffer_complet_flag = false; // 清除标志 xc_uart_send_data(uart_handle, arr,arr[1]); // 发送完整帧 }