串口中斷接收與環形緩沖實例(apollo3 blue plus)

#define DEV_UART1 ? ? ? ? ? ? ? ?1

#define GPS_POWER_PIN ?? ?13

#define GPS_LOG_ENABLE?? ?1

#define MAX_UART1_SIZE ? ? ? ? ? ??? ??? ?1024


#define AM_BSP_GPIO_COM_UART1_TX ? ? ? ? 8
#define AM_BSP_GPIO_COM_UART1_RX ? ? ? ? 9

// 定義環形緩沖區結構
typedef struct?
{
? ? uint8_t RxBuffer[MAX_UART1_SIZE];
? ? volatile uint16_t head; ?// 寫指針(由中斷回調修改)
? ? volatile uint16_t tail; ?// 讀指針(由主任務修改)
? ? uint8_t ready;
} RingBuffer;

typedef struct
{
?? ?uint8_t TxBuffer[MAX_UART1_SIZE];
}uart1_dev_t;

typedef struct
{
?? ?uint8_t position_flag;
?? ?uint8_t printf_enable;
?? ?uint8_t status;
?? ?char time_hour[6];
?? ?char time_date[6];
?? ?char latitude[17];
?? ?char longitude[17];?
?? ?float gps_latitude;
?? ?float gps_longitude;
}Gps_Module_Data;

#include <stdint.h>
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include "am_mcu_apollo.h"
#include "am_bsp.h"
#include "am_util.h"
#include <string.h>
#include "FreeRTOSConfig.h"
#include "dev_gps.h"
#include "FreeRTOS.h"
#include "task.h"
#include "time.h"
#include "queue.h"?
#include "ble_app.h"

void *uart1_dev_Handle;
uart1_dev_t uart1_dev;
void *g_pvUART1;

TaskHandle_t gps_task_thread;?

Gps_Module_Data gps_module_data;

static RingBuffer uart1_rx = {0};


//*****************************************************************************
//
// Configuration options
//
//*****************************************************************************
const am_hal_gpio_pincfg_t g_AM_BSP_GPIO_COM_UART1_TX =
{
? ? .uFuncSel ? ? ? ? ? ?= AM_HAL_PIN_8_UART1TX,
? ? .eDriveStrength ? ? ?= AM_HAL_GPIO_PIN_DRIVESTRENGTH_2MA
};

const am_hal_gpio_pincfg_t g_AM_BSP_GPIO_COM_UART1_RX =
{
? ? .uFuncSel ? ? ? ? ? ?= AM_HAL_PIN_9_UART1RX
};

//*****************************************************************************
//
// init uart1 defualt
//
//*****************************************************************************
void dev_uart1_gpio_config_defualt(void)
{
?? ?g_pvUART1=NULL;
?? ?am_hal_gpio_pinconfig(AM_BSP_GPIO_COM_UART1_TX, g_AM_HAL_GPIO_DISABLE);
? ??? ?am_hal_gpio_pinconfig(AM_BSP_GPIO_COM_UART1_RX, g_AM_HAL_GPIO_DISABLE);
}

//*****************************************************************************
//
// deinit uart1
//
//*****************************************************************************
void dev_uart1_deinit(void)
{
?? ?am_hal_uart_tx_flush(g_pvUART1);
?? ?__NVIC_DisableIRQ((IRQn_Type)(UART0_IRQn + DEV_UART1));

?? ?am_hal_uart_power_control(g_pvUART1, AM_HAL_SYSCTRL_DEEPSLEEP, false);
?? ?am_hal_uart_deinitialize(g_pvUART1);

?? ?dev_uart1_gpio_config_defualt();
}

//*****************************************************************************
//
// read uart1 data
//
//*****************************************************************************
uint32_t dev_uart1_read_buf(uint8_t *data)
{
?? ?uint32_t ui32BytesRead;
?? ?
?? ?am_hal_uart_transfer_t sRead =
?? ?{
?? ??? ?.ui32Direction = AM_HAL_UART_READ,
?? ??? ?.pui8Data = data,
?? ??? ?.ui32NumBytes = 23,
?? ??? ?.ui32TimeoutMs = 0,
?? ??? ?.pui32BytesTransferred = &ui32BytesRead,
?? ?};
?? ?
?? ?am_hal_uart_transfer(g_pvUART1, &sRead);
?? ?return ui32BytesRead;
}

//*****************************************************************************
//
// uart1 send data
//
//*****************************************************************************
void dev_uart1_send(uint8_t *data,uint32_t len)
{
??? ?am_hal_uart_transfer_t sWrite =
? ? ? ?{
? ? ? ? ? .ui32Direction = AM_HAL_UART_WRITE,
? ? ? ? ? .pui8Data = data,
? ? ? ? ? .ui32NumBytes = len,
? ? ? ? ? .ui32TimeoutMs = AM_HAL_UART_WAIT_FOREVER,
? ? ? ? ? .pui32BytesTransferred = 0,
? ? ? ?};


? ? ?am_hal_uart_transfer(g_pvUART1, &sWrite);
?? ?// am_util_debug_printf("uart send\r\n");
}

//*****************************************************************************
//
// 注冊串口1中斷回調函數
//
//*****************************************************************************
void dev_uart1_register(dev_uart1_callback cb)
{
?? ?uart1_isr_status = cb;
}

//*****************************************************************************
//
// uart1 isr
//
//*****************************************************************************
void am_uart1_isr(void)
{
?? ?uint32_t ui32Status;
?? ? ? //
?? ? ? // Read the masked interrupt status from the UART.
?? ? ? //
?? ?am_hal_uart_interrupt_status_get(g_pvUART1, &ui32Status, true);
?? ?am_hal_uart_interrupt_clear(g_pvUART1, ui32Status);
?? ?am_hal_uart_interrupt_service(g_pvUART1, ui32Status, 0);
//?? ?am_util_debug_printf("uart1 isr Status=%d\r\n",ui32Status);?? ?
?? ?if(uart1_isr_status !=NULL)
?? ??? ?uart1_isr_status(ui32Status);

}

void gps_power_gpio_init(void)
{
?? ?const am_hal_gpio_pincfg_t gps_pin =
?? ?{
?? ? ? ?.eDriveStrength = AM_HAL_GPIO_PIN_DRIVESTRENGTH_2MA,
?? ??? ?.eGPOutcfg ? ? ?= AM_HAL_GPIO_PIN_OUTCFG_PUSHPULL,
? ? ?? ?.uFuncSel ? ? ? = 3?? ??? ??? ?//GPIO功能
?? ?};
?? ?am_hal_gpio_pinconfig(GPS_POWER_PIN, gps_pin);
?? ?am_hal_gpio_output_set(GPS_POWER_PIN);
?? ?gps_module_data.status = 1;
}


/*
**將傳入的字符串按照分隔符分隔開,如果兩個分隔符中間沒數據,返回\0
**函數返回值為分割之后,后面剩下的數據
**data:傳入的字符串,control:分隔符,out_string:分隔符中間的數據
*/
char *cut_string(char *data,const char * control,char *out_string)
{
?? ?char *p1 = NULL;//
?? ?char *p2 = NULL;//
?? ?p1 = strstr(data,control);
?? ?if(p1==NULL)return NULL;
?? ?p2 = strstr(p1+1,control);
?? ?if(p2==NULL)return NULL;
?? ?if((p2-p1)==1)//
?? ?{
?? ??? ?*out_string='\0';
?? ??? ?data = p2;
?? ?}
?? ?else
?? ?{
?? ??? ?memcpy(out_string,p1+1,(int)(p2-p1-1));//
?? ??? ?*(out_string+(p2-p1-1))='\0';
?? ??? ?data = p2;
?? ?}
?? ?return data;
}

//字符轉換浮點數
static float parse_lat_long(char *str)
{
? ? float ll = strtof(str, NULL);
? ? int deg = ((int)ll) / 100;
? ? float min = ll - (deg * 100);
? ? ll = deg + min / 60.0f;
? ? return ll;
}

//$GNRMC,100512.000,A,2232.3339,N,11401.5394,E,0.49,83.03,1 A * 54
static uint8_t gps_get_latitude_and_longitude(char *data)
{
?? ?char string[15]={0};
?? ?char *aaa = NULL;
?? ?uint8_t cnt = 0;
?? ?char *p1=NULL,*p2=NULL;
?? ?uint8_t ret = 0,valid = 0;
?? ?
?? ?if(((p1=strstr(data,"RMC"))!=NULL)&&((p2=strstr(p1,"*"))!=NULL)&&(p2-p1<100))
?? ?{
?? ??? ?aaa = p1;
?? ??? ?while(aaa!=NULL)
?? ??? ?{
?? ??? ??? ?cnt++;
?? ??? ??? ?aaa=cut_string(aaa,",",string);
?? ??? ??? ?if(aaa==NULL)break;

?? ??? ? ? ?if(cnt == 1)//UTC(Coordinated Universal Time)時間,hhmmss(時分秒
?? ??? ??? ?{
?? ??? ??? ??? ?memset(gps_module_data.time_hour,0,sizeof(gps_module_data.time_hour));
?? ??? ??? ??? ?if((string[0]!=0)&&(strstr(string,".")!=NULL))
?? ??? ??? ??? ?{
?? ??? ??? ??? ??? ?memcpy(gps_module_data.time_hour,string,6);
?? ??? ??? ??? ?}
?? ??? ??? ??? ?else
?? ??? ??? ??? ?{
?? ??? ??? ??? ??? ?break;
?? ??? ??? ??? ?}
?? ??? ??? ?}
?? ??? ? ? else if((cnt == 2)&&(string[0]!=0))
?? ??? ??? ?{
?? ??? ??? ??? ?//am_util_debug_printf("valid 0:%d",string[0]);
?? ??? ??? ??? ?if(string[0] == 'A')
?? ??? ??? ??? ??? ?{
?? ??? ??? ??? ??? ?//?? ?gps_module_data.position_flag = 1;
?? ??? ??? ??? ??? ??? ?valid = 1;
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?else?
?? ??? ??? ??? ??? ?{
?? ??? ??? ??? ??? ?//?? ?gps_module_data.position_flag = 0;
?? ??? ??? ??? ??? ??? ?valid = 0;
?? ??? ??? ??? ??? ?}
?? ??? ??? ?}
?? ??? ? else if(cnt == 3)//緯度
?? ??? ??? ?{
?? ??? ??? ??? ?memset(gps_module_data.latitude,0,sizeof(gps_module_data.latitude));
?? ??? ??? ??? ?if((string[0]!=0)&&(strstr(string,".")!=NULL))
?? ??? ??? ??? ?{
?? ??? ??? ??? ??? ?memcpy(gps_module_data.latitude+3,string,strlen(string));
?? ??? ??? ??? ?}
?? ??? ??? ??? ?else
?? ??? ??? ??? ?{
?? ??? ??? ??? ??? ?break;
?? ??? ??? ??? ?}
?? ??? ??? ?}
?? ??? ??? ?else if(cnt == 4)//N ? S
?? ??? ??? ?{
?? ??? ??? ??? ?if(string[0] == 'S')
?? ??? ??? ??? ?{
?? ??? ??? ??? ??? ?gps_module_data.latitude[0] = string[0];
?? ??? ??? ??? ??? ?gps_module_data.latitude[1] = ':';
?? ??? ??? ??? ??? ?gps_module_data.latitude[2] = '-';
?? ??? ??? ??? ??? ?if(GPS_LOG_ENABLE)am_util_debug_printf("latitude:%s\n",gps_module_data.latitude);
?? ??? ??? ??? ?//?? ?gps_module_data.gps_latitude = parse_lat_long(&gps_module_data.latitude[2]);
?? ??? ??? ??? ?//?? ?if(GPS_LOG_ENABLE)am_util_debug_printf("gps-latitude:%lf\n",gps_module_data.gps_latitude);
?? ??? ??? ??? ?}
?? ??? ??? ??? ?else if(string[0] == 'N')
?? ??? ??? ??? ?{
?? ??? ??? ??? ??? ?gps_module_data.latitude[0] = string[0];
?? ??? ??? ??? ??? ?gps_module_data.latitude[1] = ':';
?? ??? ??? ??? ??? ?gps_module_data.latitude[2] = '0';
?? ??? ??? ??? ??? ?if(GPS_LOG_ENABLE)am_util_debug_printf("latitude:%s\n",gps_module_data.latitude);
?? ??? ??? ??? ?//?? ?gps_module_data.gps_latitude = parse_lat_long(&gps_module_data.latitude[2]);
?? ??? ??? ??? ?//?? ?if(GPS_LOG_ENABLE)am_util_debug_printf("gps-latitude:%lf\n",gps_module_data.gps_latitude);
?? ??? ??? ??? ?}
?? ??? ??? ??? ?else
?? ??? ??? ??? ?{
?? ??? ??? ??? ??? ?break;
?? ??? ??? ??? ?}
?? ??? ??? ?}
?? ??? ??? ?else if(cnt == 5)//經度
?? ??? ??? ?{
?? ??? ??? ??? ?memset(gps_module_data.longitude,0,sizeof(gps_module_data.longitude));
?? ??? ??? ??? ?if((string[0]!=0)&&(strstr(string,".")!=NULL))
?? ??? ??? ??? ?{
?? ??? ??? ??? ??? ?memcpy(gps_module_data.longitude+3,string,strlen(string));
?? ??? ??? ??? ?}
?? ??? ??? ??? ?else
?? ??? ??? ??? ?{
?? ??? ??? ??? ??? ?break;
?? ??? ??? ??? ?}
?? ??? ??? ?}
?? ??? ??? ?else if(cnt == 6)//W ? E
?? ??? ??? ?{
?? ??? ??? ??? ?if(string[0] == 'W')
?? ??? ??? ??? ?{
?? ??? ??? ??? ??? ?gps_module_data.longitude[0] = string[0];
?? ??? ??? ??? ??? ?gps_module_data.longitude[1] = ':';
?? ??? ??? ??? ??? ?gps_module_data.longitude[2] = '-';
?? ??? ??? ??? ??? ?if(GPS_LOG_ENABLE)am_util_debug_printf("longitude:%s\n",gps_module_data.longitude);
?? ??? ??? ??? ?//?? ?gps_module_data.gps_longitude = parse_lat_long(&gps_module_data.longitude[2]);
?? ??? ??? ??? ?//?? ?if(GPS_LOG_ENABLE)am_util_debug_printf("gps-longitude:%lf\n",gps_module_data.gps_longitude);
?? ??? ??? ??? ?}
?? ??? ??? ??? ?else if(string[0] == 'E')
?? ??? ??? ??? ?{
?? ??? ??? ??? ??? ?gps_module_data.longitude[0] = string[0];
?? ??? ??? ??? ??? ?gps_module_data.longitude[1] = ':';
?? ??? ??? ??? ??? ?gps_module_data.longitude[2] = '0';
?? ??? ??? ??? ??? ?if(GPS_LOG_ENABLE)am_util_debug_printf("longitude:%s\n",gps_module_data.longitude);
?? ??? ??? ??? ?//?? ?gps_module_data.gps_longitude = parse_lat_long(&gps_module_data.longitude[2]);
?? ??? ??? ??? ?//?? ?if(GPS_LOG_ENABLE)am_util_debug_printf("gps-longitude:%lf\n",gps_module_data.gps_longitude);
?? ??? ??? ??? ?}
?? ??? ??? ??? ?else
?? ??? ??? ??? ?{
?? ??? ??? ??? ??? ?break;
?? ??? ??? ??? ?}
?? ??? ??? ?}
?? ??? ??? ?else if(cnt == 7)//地面速率
?? ??? ??? ?{?? ?
?? ??? ??? ??? ?
?? ??? ??? ?}
?? ??? ??? ?else if(cnt == 8)//地面航向
?? ??? ??? ?{
?? ??? ??? ??? ?
?? ??? ??? ?}
?? ??? ? ? else if(cnt == 9)//UTC日期,ddmmyy(日月年)格式
?? ??? ??? ?{
?? ??? ??? ??? ?memset(gps_module_data.time_date,0,sizeof(gps_module_data.time_date));
?? ??? ??? ??? ?if(string[0]!=0)
?? ??? ??? ??? ?{
?? ??? ??? ??? ??? ?memcpy(gps_module_data.time_date,string,6);
?? ??? ??? ??? ??? ?struct tm lt;?? ??? ?//C標準庫time.h?
?? ??? ??? ??? ??? ?int timezone = 0;

?? ??? ??? ??? ??? ?lt.tm_mday = (gps_module_data.time_date[0] - '0')*10 + (gps_module_data.time_date[1] - '0');
?? ??? ??? ??? ??? ?lt.tm_mon = (gps_module_data.time_date[2] - '0')*10 + (gps_module_data.time_date[3] - '0');
?? ??? ??? ??? ??? ?lt.tm_year = (gps_module_data.time_date[4] - '0')*10 + (gps_module_data.time_date[5] - '0');

?? ??? ??? ??? ??? ?lt.tm_hour = (gps_module_data.time_hour[0] - '0')*10 + (gps_module_data.time_hour[1] - '0');
?? ??? ??? ??? ??? ?lt.tm_min = (gps_module_data.time_hour[2] - '0')*10 + (gps_module_data.time_hour[3] - '0');
?? ??? ??? ??? ??? ?lt.tm_sec = (gps_module_data.time_hour[4] - '0')*10 + (gps_module_data.time_hour[5] - '0');
?? ??? ??? ??? ??? ?
?? ??? ??? ??? ?//?? ?gps time:211122095858
?? ??? ??? ??? ??? ?if(GPS_LOG_ENABLE)am_util_debug_printf("cclk:%d-%d-%d %d:%d:%d\n",lt.tm_mday,lt.tm_mon,lt.tm_year,lt.tm_hour,lt.tm_min,lt.tm_sec);
?? ??? ??? ??? ??? ?lt.tm_year = lt.tm_year + 100;
?? ??? ??? ??? ??? ?lt.tm_mon = lt.tm_mon - 1;
?? ??? ??? ??? ??? ?work.current_time = mktime(&lt)-(timezone/4*3600);
?? ??? ??? ??? ??? ?am_util_debug_printf("current_time : %lld",work.current_time);?? ?//北京時間
?? ??? ??? ??? ??? ?
?? ??? ??? ??? ??? ?if(valid)
?? ??? ??? ??? ??? ?{
?? ??? ??? ??? ??? ??? ?gps_module_data.gps_latitude = parse_lat_long(&gps_module_data.latitude[2]);
?? ??? ??? ??? ??? ??? ?if(GPS_LOG_ENABLE)am_util_debug_printf("gps-latitude:%f\n",gps_module_data.gps_latitude);
?? ??? ??? ??? ??? ??? ?
?? ??? ??? ??? ??? ??? ?gps_module_data.gps_longitude = parse_lat_long(&gps_module_data.longitude[2]);
?? ??? ??? ??? ??? ??? ?if(GPS_LOG_ENABLE)am_util_debug_printf("gps-longitude:%f\n",gps_module_data.gps_longitude);

?? ??? ??? ??? ??? ??? ?if(gps_module_data.position_flag == 0)
?? ??? ??? ??? ??? ??? ??? ?{
?? ??? ??? ??? ??? ??? ??? ??? ?gps_module_data.position_flag = 1;
?? ??? ??? ??? ??? ??? ??? ??? ?am_util_debug_printf("gps valid report\n");
?? ??? ??? ??? ??? ??? ??? ?}
?? ??? ??? ??? ??? ??? ?ret = 1;
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?}
?? ??? ??? ?}
?? ??? ?}
?? ?}

?? ?return ret;
}

void open_gps(void)
{
?? ?gps_module_data.status = 1;
?? ?gps_module_data.position_flag = 0;
?? ?am_hal_gpio_output_set(GPS_POWER_PIN);
?? ?vTaskResume(gps_task_thread);
?? ?am_util_debug_printf("gps task resume\n");
}

void close_gps(void)
{
?? ?if(gps_module_data.printf_enable == 1)return;
?? ?gps_module_data.status = 0;
?? ?gps_module_data.position_flag = 0;
?? ?am_hal_gpio_output_clear(GPS_POWER_PIN);
?? ?vTaskSuspend(gps_task_thread);?? ?//掛起UDP任務,直到解除掛起,

?? ?am_util_debug_printf("gps task suspend\n");
}


// ?獲取可讀數據量 添加環形緩沖區輔助函數
uint32_t RingBuffer_Available(RingBuffer *rb)
{
? ? uint32_t head = rb->head;
? ? uint32_t tail = rb->tail;

? ? if (head >= tail) return (head - tail);
? ? return (MAX_UART1_SIZE - tail + head);
}


// 讀取數據(在主任務中調用,帶臨界區保護)
uint8_t RingBuffer_Get(RingBuffer *rb)
{
? ? __disable_irq();
? ? if (rb->tail == rb->head)?
?? ?{
? ? ? ? __enable_irq();
? ? ? ? return 0; ?// 無數據
? ? }
? ? uint8_t data = rb->RxBuffer[rb->tail];
? ? rb->tail = (rb->tail + 1) % MAX_UART1_SIZE;
? ? __enable_irq();
? ? return data;
}

// 修改后的環形緩沖區寫入函數(適配實際硬件)
static void RingBuffer_Put(RingBuffer *rb, uint8_t data)
{
? ? uint32_t next_head = (rb->head + 1) % MAX_UART1_SIZE;
? ??
? ? // 當緩沖區未滿時寫入
? ? if (next_head != rb->tail)?
?? ?{
? ? ? ? rb->RxBuffer[rb->head] = data;
? ? ? ? rb->head = next_head;
? ? }
? ? if (next_head == rb->tail)
?? ?{
? ? ?? ?am_util_debug_printf("--uart1 rx over--\n");// 處理緩沖區滿的情況
?? ?}
}

//*****************************************************************************
//
// 串口1回調函數處理
//
//*****************************************************************************
void uart1_dev_receiver_handle(uint32_t ui32Status)
{
?? ?//am_util_debug_printf("reveier ui32Status=%d\r\n",ui32Status);
?if (ui32Status & (AM_HAL_UART_INT_RX_TMOUT | AM_HAL_UART_INT_RX))
? ? {
? ? ? ? uint32_t i,totallen, ui32BytesRead = 0;
?? ??? ?uint8_t temp_buf[64]; ?

?? ??? ?ui32BytesRead = dev_uart1_read_buf(temp_buf);?? ?//每次最多讀23個字節
?? ??? ?totallen = ui32BytesRead;
? ? ? ? // 將數據寫入環形緩沖區
? ? ? ? for (i = 0; i < ui32BytesRead; i++)
?? ??? ?{
? ? ? ? ? ? RingBuffer_Put(&uart1_rx, temp_buf[i]);
? ? ? ? }
?? ??? ?//am_util_debug_printf("uart rx:%d\n",totallen);
? ? ? ? if (ui32Status & (AM_HAL_UART_INT_RX_TMOUT))
? ? ? ? {
? ? ? ? ??? ?ui32BytesRead = dev_uart1_read_buf(temp_buf);
?? ??? ??? ?totallen += ui32BytesRead;
? ? ? ? ?? ?// 將數據寫入環形緩沖區
? ? ? ? ?? ?for (i = 0; i < ui32BytesRead; i++)
?? ??? ??? ?{
? ? ? ? ? ? ?? ?RingBuffer_Put(&uart1_rx, temp_buf[i]);
? ? ? ? ?? ?}?? ??? ??? ?
?? ??? ??? ?//am_util_debug_printf("uart1:%d %s\r\n",totallen, uart1_rx.RxBuffer);
?? ??? ??? ?//am_util_debug_printf("uart tmout:%d\n",totallen);
?? ??? ?}
?? ??? ?uart1_rx.ready = true;
? ?}
?
}


//*****************************************************************************
//
// init uart
//
//*****************************************************************************
void ?dev_uart1_init(void)
{
? ? am_hal_uart_config_t sUartConfig =
? ? {
? ? ? ? //
? ? ? ? // Standard UART settings: 115200-8-N-1
? ? ? ? //
? ? ? ? .ui32BaudRate ? ?= 115200,
? ? ? ? .ui32DataBits ? ?= AM_HAL_UART_DATA_BITS_8,
? ? ? ? .ui32Parity ? ? ?= AM_HAL_UART_PARITY_NONE,
? ? ? ? .ui32StopBits ? ?= AM_HAL_UART_ONE_STOP_BIT,
? ? ? ? .ui32FlowControl = AM_HAL_UART_FLOW_CTRL_NONE,

? ? ? ? //
? ? ? ? // Set TX and RX FIFOs to interrupt at three-quarters full.
? ? ? ? //
? ? ? ? .ui32FifoLevels = (AM_HAL_UART_TX_FIFO_3_4 |
? ? ? ? ? ? ? ? ? ? ? ? ? ?AM_HAL_UART_RX_FIFO_3_4),

? ? ? ? //
? ? ? ? // This code will use the standard interrupt handling for UART TX, but
? ? ? ? // we will have a custom routine for UART RX.
? ? ? ? //
? ? ? ? .pui8TxBuffer = uart1_dev.TxBuffer,
? ? ? ? .ui32TxBufferSize = MAX_UART1_SIZE,
? ? ? ?? ?.pui8RxBuffer = 0,
? ? ? ? .ui32RxBufferSize = 0,
? ? };

? ? am_hal_uart_initialize(DEV_UART1, &g_pvUART1);
? ? am_hal_uart_power_control(g_pvUART1, AM_HAL_SYSCTRL_WAKE, false);
? ? am_hal_uart_configure(g_pvUART1, &sUartConfig);
?? ?//hl_dev_uart_gpio_config(g_pvUART1,config->ui32module);
?? ?am_hal_gpio_pinconfig(AM_BSP_GPIO_COM_UART1_TX, g_AM_BSP_GPIO_COM_UART1_TX);
? ? am_hal_gpio_pinconfig(AM_BSP_GPIO_COM_UART1_RX, g_AM_BSP_GPIO_COM_UART1_RX);
? ? //
? ? // Make sure to enable the interrupts for RX, since the HAL doesn't already
? ? // know we intend to use them.
? ? //
? ? NVIC_EnableIRQ((IRQn_Type)(UART0_IRQn + DEV_UART1));
?? ?NVIC_SetPriority(UART0_IRQn+DEV_UART1, NVIC_configMAX_SYSCALL_INTERRUPT_PRIORITY);
? ? am_hal_uart_interrupt_enable(g_pvUART1, (AM_HAL_UART_INT_RX |
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?AM_HAL_UART_INT_RX_TMOUT));

?? ?dev_uart1_register(uart1_dev_receiver_handle);
?? ?am_util_debug_printf("uart1 init:\r\n");
}

//*****************************************************************************
//
//initial setup for the gps task.
//
//*****************************************************************************
void gps_task(void *pvParameters)

{
?? ?char data[1024] = {0};
?? ?uint16_t i, len;
?? ?uint16_t available;
?? ?
?? ?gps_power_gpio_init();
?? ?dev_uart1_init();
?? ?am_util_debug_printf("gps init\n");
?? ?
? ? while (1)?
?? ??? ?{?? ??? ??? ?
?? ??? ??? ?if(uart1_rx.ready)?? ?//20ms,230 BITS
?? ??? ??? ??? ?{
? ? ? ? ?? ??? ??? ?// Read data from the UART?
?? ??? ??? ??? ??? ?available = RingBuffer_Available(&uart1_rx);

?? ??? ??? ??? ??? ?if(available > 0)
?? ??? ??? ??? ??? ?{
? ? ? ? ? ? ?? ??? ??? ?len = available > MAX_UART1_SIZE ? MAX_UART1_SIZE : available;
? ? ? ? ? ??
? ? ? ? ? ? ?? ??? ??? ?// 讀取數據到臨時緩沖區
? ? ? ? ? ? ?? ??? ??? ?for (i = 0; i < len; i++)
?? ??? ??? ??? ??? ??? ?{
? ? ? ? ? ? ? ? ?? ??? ??? ?data[i] = RingBuffer_Get(&uart1_rx);
? ? ? ? ? ? ?? ??? ??? ?}
?? ??? ??? ??? ??? ?
?? ??? ??? ??? ??? ?//?? ?if(gps_module_data.printf_enable)
?? ??? ??? ??? ??? ?//?? ?{
?? ??? ??? ??? ??? ??? ??? ?am_util_debug_printf("rec:%d,%s\r\n",len,data);
?? ??? ??? ??? ??? ?//?? ?}
?? ??? ??? ??? ??? ??? ?if(strstr(data,"RMC")!=NULL)
?? ??? ??? ??? ??? ??? ?{
?? ??? ??? ??? ??? ??? ??? ?gps_get_latitude_and_longitude(data);
?? ??? ??? ??? ??? ??? ??? ?//gps_connect_flag = 1;
?? ??? ??? ??? ??? ??? ?}?? ??? ??? ?
?? ??? ??? ??? ??? ??? ?memset(data,0,sizeof(data));
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ??? ?uart1_rx.ready = false;
?? ??? ??? ??? ?}?? ??? ??? ?
?? ??? ??? ?else vTaskDelay(20 / portTICK_PERIOD_MS);?? ??? ?//115200 BITS/S 20ms,230 BITS
? ? ?? ?}
}

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/diannao/76374.shtml
繁體地址,請注明出處:http://hk.pswp.cn/diannao/76374.shtml
英文地址,請注明出處:http://en.pswp.cn/diannao/76374.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

操作系統高頻(五)linux命令

操作系統高頻&#xff08;五&#xff09;linux命令 1.Linux中查看進程運行狀態的指令、tar解壓文件的參數。??? 在Linux中&#xff0c;可以使用以下指令查看進程的運行狀態&#xff1a; top&#xff1a; 用于實時監視系統的進程活動和系統資源使用情況。在終端中運行top…

Spring Boot 快速入手

前言&#xff1a;為什么選擇 Spring Boot&#xff1f; &#x1f680; 在現代 Java 開發中&#xff0c;Spring Boot 已成為最流行的后端框架之一。無論是小型 Web 應用、企業級系統&#xff0c;還是微服務架構&#xff0c;Spring Boot 都能提供快速開發、自動配置、輕量級部署的…

oracle-blob導出,在ob導入失敗

導出&#xff1a; [oraclelncs dmp]$ /home/oracle/sqluldr2 gistar/res#pwd192.168.205.58:1521/lndb query"select * from an_odn_picture where length(PIC_CONTENT)<25000" filean_odn_picture.csv Charsetutf8 textCSV 0 rows exported at 2025-…

RK3568 pinctrl內容講解

文章目錄 一、pinctrl的概念`pinctrl` 的作用設備樹中的 `pinctrl` 節點典型的 `pinctrl` 節點結構例子`pinctrl` 的重要性總結二、RK3568的pinctrl講解1. `pinctrl` 節點2. `gpio0` 至 `gpio4` 子節點每個 `gpioX` 子節點的結構和作用3. `gpio1` 到 `gpio4` 子節點總結1. `aco…

北京南文觀點:后糖酒會營銷,以戰略傳播重構品牌信心坐標

第112屆全國糖酒會落下帷幕&#xff0c;參展品牌面臨一個關鍵命題。如何在流量洪流中沉淀品牌價值&#xff1f;北京南文&#xff08;全稱&#xff1a;南文樂園科技文化&#xff08;北京&#xff09;有限公司&#xff09;認為&#xff0c;糖酒會的結束恰是算法時代品牌認知戰的真…

html5時鐘升級!支持切換深淺模式 Canvas實現現代化動態時鐘

HTML5 Canvas實現現代化動態時鐘 這里寫目錄標題 HTML5 Canvas實現現代化動態時鐘項目介紹技術實現1. 項目架構2. Canvas繪圖實現2.1 表盤繪制2.2 刻度繪制2.3 指針繪制 3. 動畫效果4. 主題切換 項目亮點技術要點總結項目收獲改進方向結語 項目介紹 本項目使用HTML5 Canvas技術…

《SRv6 網絡編程:開啟IP網絡新時代》第2章、第3章:SRv6基本原理和基礎協議

背景 根據工作要求、本人掌握的知識情況&#xff0c;僅針對《SRv6 網絡編程&#xff1a;開啟IP網絡新時代》書籍中涉及的部分知識點進行總結梳理&#xff0c;并與工作小組進行分享&#xff0c;不涉及對原作的逐字搬運。 問題 組內同事提出的問題&#xff1a;本文缺擴展頭描述…

衛星電話究竟是“錦上添花”?還是“剛需之選”?

在萬物互聯的時代浪潮中&#xff0c;衛星電話究竟是可有可無的“錦上添花”&#xff0c;還是至關重要的“剛需之選”&#xff1f;隨著通信技術的持續進步與應用場景的日益拓展&#xff0c;這一問題的答案正逐漸明晰。 在5G基站覆蓋99%行政村的今天&#xff0c;人類依然要直面自…

C語言復習筆記--指針(1)

今天我們進入指針的復習了.這部分有很多知識,話不多說,讓我們進入指針的世界吧. 內存和地址 要想學指針就不能不學內存和地址. 內存 其中&#xff0c;每個內存單元&#xff0c;相當于?個學?宿舍&#xff0c;? 個字節空間??能放8個?特位&#xff0c;就好?同學們 住的??…

【藍橋杯每日一題】4.1

&#x1f3dd;?專欄&#xff1a; 【藍橋杯備篇】 &#x1f305;主頁&#xff1a; f狐o貍x "今日禿頭刷題&#xff0c;明日榮耀加冕&#xff01;" 今天我們來練習二分算法 不熟悉二分算法的朋友可以看&#xff1a;【C語言刷怪篇】二分法_編程解決算術問題-CSDN博客 …

【設計模式】過濾器模式

過濾器顧名思義&#xff0c;定義一些過濾規則&#xff0c;將符合要求的內容篩選&#xff0c;就比如過濾不同大小或者不同顏色的水果&#xff0c;需要顏色和大小過濾器&#xff0c;篩選條件獨立為對象&#xff0c;可以通過靈活組合形成過濾鏈條。避免大量使用判斷語句。 案例代…

STM32 CAN學習(一)

CAN總線應用最多的是汽車領域。 CAN&#xff08;Controller Area Network&#xff09;控制器 局域 網 局域網&#xff1a;把幾臺電腦連接到一臺路由器上&#xff0c;這幾臺電腦就可以進行通訊了。 控制器在汽車中的專業術語叫做ECU&#xff08;Electronic Control Unit&…

多線程開發中List的使用

由于ArrayList在多線程高并發情況下是不安全的&#xff0c;因此要慎用&#xff0c;那么此時如果涉及到集合操作&#xff0c;應該怎么選&#xff1a; 方案一&#xff1a;Vector: 特點&#xff1a;通過給所有方法都用 synchronized 修飾從而保證線程安全&#xff0c; 缺點&…

論文閱讀筆記:Denoising Diffusion Implicit Models (2)

0、快速訪問 論文閱讀筆記&#xff1a;Denoising Diffusion Implicit Models &#xff08;1&#xff09; 論文閱讀筆記&#xff1a;Denoising Diffusion Implicit Models &#xff08;2&#xff09; 論文閱讀筆記&#xff1a;Denoising Diffusion Implicit Models &#xff08…

人工智能在醫療領域的前沿應用與挑戰

在當今數字化時代&#xff0c;人工智能&#xff08;AI&#xff09;技術正以前所未有的速度改變著我們的生活&#xff0c;其中醫療領域無疑是受益最為顯著的行業之一。從疾病診斷、治療方案制定到患者護理&#xff0c;AI的應用不僅提高了醫療服務的效率和質量&#xff0c;還為醫…

【計算機網絡】HTTP與HTTPS

文章目錄 1. HTTP定義2. HTTP交互3. HTTP報文格式3.1 抓包工具-fiddler3.2 抓包操作3.3 報文格式3.3.1 請求報文3.3.2 響應報文 4. URL5. 請求頭中的方法6. GET和POST的區別7. HTTP報頭7.1 Host7.2 Content_Length7.3 Content_Type7.4 User-Agent(UA)7.5 Referer7.6 Cookie 8 狀…

怎樣提升大語言模型(LLM)回答準確率

怎樣提升大語言模型(LLM)回答準確率 目錄 怎樣提升大語言模型(LLM)回答準確率激勵與規范類知識關聯類情感與語境類逆向思維類:為什么不,反面案例群體智慧類明確指令類示例引導類思維引導類約束限制類反饋交互類:對話激勵與規范類 給予獎勵暗示:在提示詞中暗示模型如果回…

【分享】內外網文件擺渡系統:讓數據傳輸更安全更可靠

【分享】Ftrans內外網文件擺渡系統&#xff1a;讓數據傳輸更安全更可靠&#xff01; 隨著大數據時代的到來&#xff0c;數據的重要性日漸得到重視&#xff0c;數據作為數字經濟時代下的基礎性資源和戰略性資源&#xff0c;是決定國家經濟發展水平和競爭力的核心驅動力。以行業…

Python自動化面試通關秘籍

Python自動化測試工程師面試&#xff0c;不僅僅是考察你的代碼能力&#xff0c;更看重你如何在項目中靈活運用工具和框架解決實際問題。如果你正準備面試&#xff0c;這篇文章將為你總結最常見的高頻考題及答題技巧&#xff0c;幫助你快速上手&#xff0c;通關面試&#xff0c;…

Logstash開啟定時任務增量同步mysql數據到es的時區問題

本文使用修改時間modify_date作為增量同步檢測字段&#xff0c;可檢測新增和修改&#xff0c;檢測不到刪除&#xff0c;檢測刪除請使用canal查詢binlog日志同步數據 檢測修改時間字段為varchar的時候可以先創建索引&#xff0c;并設置對應的mapping為&#xff08;可以無視時區…