uint8_t handle_pb620_receive(char *buffer)
{
uint8_t return_byte=0;
memset(buffer,0,USART_BUF_pb620);
if(fifo_pb620.buffer[fifo_pb620.buf_count]!=0)
{
uint16_t i;
fifo_pb620.clear = 0;
i = fifo_pb620.buffer[fifo_pb620.buf_count];
if(fifo_pb620.in < fifo_pb620.out)
{
for (uint16_t var = 0; var < fifo_pb620.buffer[fifo_pb620.buf_count]; ++var)
{
buffer[var] = usart_struct_bufer_pb620.RX_Buffer[fifo_pb620.in + var];
}
// memcpy(&buffer[0],&(usart_struct_bufer_pb620.RX_Buffer[fifo_pb620.in]),fifo_pb620.buffer[fifo_pb620.buf_count]);
}
else
{
for (uint16_t var = 0; var < (USART_BUF_pb620 - fifo_pb620.in); ++var)
{
buffer[var] = usart_struct_bufer_pb620.RX_Buffer[fifo_pb620.in + var];
}
// memcpy(&buffer[0],&(usart_struct_bufer_pb620.RX_Buffer[fifo_pb620.in]),USART_BUF_pb620 - fifo_pb620.in);
for(uint16_t k=0;k
{
buffer[USART_BUF_pb620 - fifo_pb620.in + k] = usart_struct_bufer_pb620.RX_Buffer[k];
}
}
}
下面是map文件
.bss.usart_struct_bufer_pb620
0x000000002000041c 0x384 ./drive/usart/drive_usart_pb620.o
0x000000002000041c usart_struct_bufer_pb620
.bss.calendar 0x00000000200007a0 0xa ./drive/rtc/bsp_rtc.o
0x00000000200007a0 calendar
*fill* 0x00000000200007aa 0x2
.bss.pb620_check_auto_send_cmd
0x00000000200007ac 0x14 ./Application/app_usart/app_usart_pb620.o
0x00000000200007ac pb620_check_auto_send_cmd
.bss.struct_gas_offline_data
0x00000000200007c0 0x48 ./Application/app_usart/app_usart_pb620.o
0x00000000200007c0 struct_gas_offline_data
#define FIFO_len_pb620 50 //FIFO缓存区存储每次接收的数据长度
#define USART_BUF_pb620 300 //接收数据长度
typedef struct
{
uint8_t RX_Buffer[USART_BUF_pb620]; //接收数组
uint8_t TX_Buffer[USART_BUF_pb620]; //发送数组
uint8_t com[USART_BUF_pb620]; //用于处理数据
}USART_buffer_pb620;
USART_buffer_pb620 usart_struct_bufer_pb620;
handle_pb620_receive中的参数是usart_struct_bufer_pb620.com,在使用memcpy时,每次拷贝的细节为41个,程序运行一段时间后,会导致后面定义的变量struct_gas_offline_data中的数据为memcpy拷贝的最后几个字节,该段程序在keil中使用时未出现问题。后来将memcpy更改为for循环拷贝,就没有问题。怀疑指针的地址指错了。不知道是什么原因引起的。