ATSAMV71Q21
void serial_rx_cb(const struct usart_async_descriptor *const io_descr)
{uint8_t ch,count;count = io_read(&USART_0.io,&ch,1);count =count;uart0_rx_buffer[uart0_recived_counter]=ch;if(uart0_comlete==1)return;switch (uart0_recived_counter){case 0 : {if (ch==0x55)uart0_recived_counter++;else uart0_recived_counter=0;}break;case 1 : {if (ch==0xAA)uart0_recived_counter++;else uart0_recived_counter=0;}break;case 3 : {uart0_recived_counter++;uart0_frame_count=uart0_rx_buffer[3];}break;default:{uart0_recived_counter++;}break;}if ((uart0_recived_counter==(uart0_frame_count+5))&&(uart0_frame_count!=0)){uart0_frame_count=0;uart0_comlete=1;}
}
void serial_tx_cb(const struct usart_async_descriptor *const io_descr)
{
}
void serial1_rx_cb(const struct usart_async_descriptor *const io_descr)
{uint8_t ch,count;count = io_read(&USART_1.io,&ch,1);count = count;if (uart1_comlete==1){return;}uart1_rx_buffer[uart1_recived_counter]=ch;uart1_recived_counter++;uart1_time_count_1ms=0; uart1_rx_begin=1;
}
void serial1_tx_cb(const struct usart_async_descriptor *const io_descr)
{
}
void usart_init_user()
{usart_async_register_callback(&USART_0, USART_ASYNC_TXC_CB, serial_tx_cb);usart_async_register_callback(&USART_0, USART_ASYNC_RXC_CB, serial_rx_cb);usart_async_enable(&USART_0);usart_async_register_callback(&USART_1, USART_ASYNC_TXC_CB, serial1_tx_cb);usart_async_register_callback(&USART_1, USART_ASYNC_RXC_CB, serial1_rx_cb);usart_async_enable(&USART_1);
}
void usart_tx(const uint8_t * tx_buffer,uint16_t len)
{if (len==0){return;}else io_write(&USART_0.io, tx_buffer, len);
}
void usart1_tx(const uint8_t * tx_buffer,uint16_t len)
{if (len==0){return;}else io_write(&USART_1.io, tx_buffer, len);
}