generated from hulk/gd32e23x_template
暂存
This commit is contained in:
parent
a5c1c857a9
commit
39d800cb1b
@ -23,8 +23,10 @@
|
|||||||
#define PROTOCOL_BOARD_TYPE 0x04
|
#define PROTOCOL_BOARD_TYPE 0x04
|
||||||
#define PROTOCOL_PACKAGE_LENGTH 0x02
|
#define PROTOCOL_PACKAGE_LENGTH 0x02
|
||||||
|
|
||||||
|
#define PACKET_START_BYTE 0xD5
|
||||||
|
|
||||||
#define MAX_SERIAL_CMD_SIZE 16
|
#define MAX_SERIAL_CMD_SIZE 16
|
||||||
#define MAX_SERIAL_CMD_COUNT 8
|
#define BUF_SIZE 8
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/* memory map */
|
/* memory map */
|
||||||
MEMORY
|
MEMORY
|
||||||
{
|
{
|
||||||
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 16K
|
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 64K
|
||||||
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 4K
|
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 4K
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ void TIMER5_IRQHandler(void) {
|
|||||||
} else {
|
} else {
|
||||||
//! turn off led & reconfig timer13 period to 1000(100ms)
|
//! turn off led & reconfig timer13 period to 1000(100ms)
|
||||||
gpio_bit_write(LED_PORT, LED_PIN, SET);
|
gpio_bit_write(LED_PORT, LED_PIN, SET);
|
||||||
timer_autoreload_value_config(LED_BLINK_TIMER, 800);
|
timer_autoreload_value_config(LED_BLINK_TIMER, 8000);
|
||||||
}
|
}
|
||||||
led_status = !led_status;
|
led_status = !led_status;
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,8 @@ int main(void)
|
|||||||
while(1){
|
while(1){
|
||||||
// gd60914_get_object_tempture();
|
// gd60914_get_object_tempture();
|
||||||
|
|
||||||
delay_ms(50);
|
delay_ms(500);
|
||||||
|
// start_communication();
|
||||||
|
|
||||||
|
|
||||||
// ultrasonic_pwm_out_cycles(ULTRASONIC_TX_CYCLES);
|
// ultrasonic_pwm_out_cycles(ULTRASONIC_TX_CYCLES);
|
||||||
|
@ -10,7 +10,7 @@ static int buf_index_r = 0;
|
|||||||
static int buf_index_w = 0;
|
static int buf_index_w = 0;
|
||||||
static int buf_length = 0;
|
static int buf_length = 0;
|
||||||
|
|
||||||
static char cmd_buffer[MAX_SERIAL_CMD_COUNT][MAX_SERIAL_CMD_SIZE];
|
static char cmd_buffer[BUF_SIZE][MAX_SERIAL_CMD_SIZE];
|
||||||
static char serial_char = 0x00;
|
static char serial_char = 0x00;
|
||||||
|
|
||||||
static int serial_count = 0;
|
static int serial_count = 0;
|
||||||
@ -144,6 +144,15 @@ void ultrasonic_distance_report(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void start_communication(void) {
|
void start_communication(void) {
|
||||||
|
if (buf_length < (BUF_SIZE - 1)) {
|
||||||
|
get_command();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (buf_length) {
|
||||||
|
prcess_command();
|
||||||
|
buf_length--;
|
||||||
|
buf_index_r = (buf_index_r + 1) % BUF_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,10 +166,64 @@ void get_command(void) {
|
|||||||
|
|
||||||
if (uart_available() > 0)
|
if (uart_available() > 0)
|
||||||
delay_ms(5);
|
delay_ms(5);
|
||||||
while (uart_available() > 0 && buf_length < BUFSIZ)
|
while (uart_available() > 0 && buf_length < BUF_SIZE) {
|
||||||
|
delay_us(100);
|
||||||
|
serial_char = uart_read();
|
||||||
|
switch (packet_state) {
|
||||||
|
case PS_NULL:
|
||||||
|
if (serial_char == PACKET_START_BYTE) {
|
||||||
|
packet_state = PS_TYPE;
|
||||||
|
serial_count = 0;
|
||||||
|
check_sum = 0;
|
||||||
|
} else {
|
||||||
|
serial_count = 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case PS_TYPE:
|
||||||
|
packet_type = serial_char;
|
||||||
|
check_sum += serial_char;
|
||||||
|
packet_state = PS_LEN;
|
||||||
|
break;
|
||||||
|
case PS_LEN:
|
||||||
|
check_sum += serial_char;
|
||||||
|
packet_len = serial_char;
|
||||||
|
packet_state = PS_PAYLOAD;
|
||||||
|
break;
|
||||||
|
case PS_PAYLOAD:
|
||||||
|
check_sum += serial_char;
|
||||||
|
cmd_buffer[buf_index_w][serial_count++] = serial_char;
|
||||||
|
if (serial_count >= packet_len) {
|
||||||
|
packet_state = PS_CRC;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case PS_CRC:
|
||||||
|
packet_state = PS_NULL;
|
||||||
|
if (!serial_count || check_sum != serial_char) {
|
||||||
|
serial_count = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
cmd_buffer[buf_index_w][serial_count] = 0;
|
||||||
|
buf_index_w = (buf_index_w + 1) % BUF_SIZE;
|
||||||
|
buf_length++;
|
||||||
|
serial_count = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void prcess_command(void) {
|
void prcess_command(void) {
|
||||||
|
if (code_seen('M')) {
|
||||||
|
switch ((int)code_value()) {
|
||||||
|
case 1:
|
||||||
|
// ultrasonic_distance_report();
|
||||||
|
printf("M1");
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
// gd60914_tempture_report();
|
||||||
|
printf("M2");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user