61 }
else if (data != 0xff) {
79 unsigned char tmp_rcv_buffer[8], counter = 0;
82 user_memset(tmp_rcv_buffer, 0xff,
sizeof(tmp_rcv_buffer));
85 for (; counter < 8; ++counter)
87 tmp_rcv_buffer[counter] = 0xff;
114 unsigned char temp_buf[12] = {0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
115 0x00, 0x00, 0x00, 0x00, 0x00, 0xff};
116 unsigned char mdtp_pack_counter;
119 for (mdtp_pack_counter = 0; mdtp_pack_counter < 8; mdtp_pack_counter++) {
120 if (buffer[mdtp_pack_counter] == 0xff) {
121 temp_buf[2 + mdtp_pack_counter] = 0x00;
122 temp_buf[10] = (temp_buf[10] | (1 << mdtp_pack_counter));
124 temp_buf[2 + mdtp_pack_counter] = buffer[mdtp_pack_counter];
128 if (temp_buf[10] == 0xff)
129 temp_buf[10] = temp_buf[2] = 0xa5;
132 temp_buf[1] = pid << 4 | ((~pid) & 0x0f);
135 for (mdtp_pack_counter = 0; mdtp_pack_counter < 12;
136 mdtp_pack_counter++) {
uart_sendbyte(temp_buf[mdtp_pack_counter]);
148 rcu_periph_clock_enable(RCU_GPIOA);
149 rcu_periph_clock_enable(RCU_USART0);
152 gpio_af_set(GPIOA, GPIO_AF_1, GPIO_PIN_9);
153 gpio_af_set(GPIOA, GPIO_AF_1, GPIO_PIN_10);
156 gpio_mode_set(GPIOA, GPIO_MODE_AF, GPIO_PUPD_PULLUP, GPIO_PIN_9);
157 gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, GPIO_PIN_9);
160 gpio_mode_set(GPIOA, GPIO_MODE_AF, GPIO_PUPD_PULLUP, GPIO_PIN_10);
161 gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, GPIO_PIN_10);
164 usart_deinit(USART0);
166 usart_transmit_config(USART0, USART_TRANSMIT_ENABLE);
167 usart_receive_config(USART0, USART_RECEIVE_ENABLE);
168 usart_enable(USART0);
171 usart_interrupt_enable(USART0, USART_INT_RBNE);
used to place important parameter configurations for users
#define UART_BAUDRATE
set UART baud rate to 512000
#define UART_PRIORITY
UART preemption priority set to 1.
void user_memset(void *buf, unsigned char data, unsigned char num)
format buffer array to fixed value, replace memset function
system basic function header file
static volatile unsigned char mdtp_receive_number_counter
medium capacity transport protocol receive character counter
static unsigned char mdtp_receive_data_buffer[10]
medium capacity transport protocol receive buffer array
void mdtp_receive_handler(unsigned char data)
medium capacity data transmission protocol unpacking handler
void mdtp_data_transmit(unsigned char pid, const unsigned char *buffer)
medium capacity data transmission protocol packing function
static volatile unsigned char mdtp_receive_status
medium capacity transport protocol receive state variable 0 idle state and waiting for start of packa...
void uart_config(void)
configure uart0 periph and its gpios
this is the header file of uart.c.
void mdtp_callback_handler(unsigned char pid, const unsigned char *data)
user callback function for unpacking completion of medium capacity transport protocol
#define uart_sendbyte(x)
UART send single byte macro.