Introduce cmd_worker() that handles commands cyclically.

This commit is contained in:
Marco 2022-05-31 20:23:10 +02:00
parent ebd763cbe7
commit 4ca7afbb6f
3 changed files with 4 additions and 10 deletions

View File

@ -16,9 +16,9 @@ cmd_t command = {
int cmd_terminated = 0; int cmd_terminated = 0;
cmd_t *cmd_getcommand(void) void cmd_worker(void)
{ {
return &command; cmd_handle(&command);
} }
void cmd_collect_char(char c) void cmd_collect_char(char c)

View File

@ -3,7 +3,7 @@ typedef struct {
int index; int index;
} cmd_t; } cmd_t;
cmd_t *cmd_getcommand(void); void cmd_worker(void);
void cmd_collect_char(char c); void cmd_collect_char(char c);
void cmd_handle(cmd_t *command); void cmd_handle(cmd_t *command);

View File

@ -15,22 +15,16 @@ int main()
/* With this MCU frequency (8MHz), 12 is a baudrate of 38.4k baud */ /* With this MCU frequency (8MHz), 12 is a baudrate of 38.4k baud */
uart_init(12); uart_init(12);
pwm_init(); pwm_init();
timer_initT1(); timer_initT1();
DDRB |= (1 << DDB5); DDRB |= (1 << DDB5);
DDRD |= (1 << DDD7); DDRD |= (1 << DDD7);
printf("Up and running.\n\r"); printf("Up and running.\n\r");
while (1) { while (1) {
/* We handle terminated commands here. cmd_worker();
Outside of the context of the UART receive interrupt. */
cmd_handle(cmd_getcommand());
pwm_worker(); pwm_worker();
} }