diff --git a/src/commands.c b/src/commands.c index a1053ad..7dc15d3 100644 --- a/src/commands.c +++ b/src/commands.c @@ -5,41 +5,46 @@ #include "commands.h" #include "pins.h" +#include "uart.h" + cmd_t command = { .buf = {0}, .index = 0 }; -void cmd_mirror_char(char c) +int cmd_terminated = 0; + +cmd_t *cmd_getcommand(void) { - printf("%c", c); + return &command; } void cmd_collect_char(char c) { command.buf[command.index] = c; - cmd_mirror_char(c); command.index++; - if (c == 0x3) { /* React on Ctl-C */ command.index = 0; printf("\r\n"); } - if (c == 0xD) { /* Null-terminate the string */ command.buf[command.index-1] = '\0'; - cmd_handle(&command); + command.index = 0; + cmd_terminated = 1; } } void cmd_handle(cmd_t *command) { + if (!cmd_terminated) + return; + printf("\n\r"); char *tok1 = strtok(command->buf, " "); @@ -51,6 +56,8 @@ void cmd_handle(cmd_t *command) if (0 == strcmp(tok1, "switch") || 0 == strcmp(tok1, "sw")) cmd_handle_switch(tok2, tok3); + + cmd_terminated = 0; } void cmd_handle_set(char *op1, char *op2) @@ -67,6 +74,15 @@ void cmd_handle_set(char *op1, char *op2) else printf("No valid value for t0_top given\n\r"); } + else if (0 == strcmp(op1, "t1_top")) { + val = strtol(op2, &end, 10); + if (op2 != end) { + OCR0A = val; + printf("Setting Timer1 TOP to %li\r\n", val); + } + else + printf("No valid value for t0_top given\n\r"); + } else if (0 == strcmp(op1, "t0_ps")) { val = strtol(op2, &end, 10); TCCR0B &= ~((1 << CS00) | (1 << CS01) | (1 << CS02)); diff --git a/src/include/commands.h b/src/include/commands.h index 2ba8201..054f187 100644 --- a/src/include/commands.h +++ b/src/include/commands.h @@ -3,7 +3,8 @@ typedef struct { int index; } cmd_t; -void cmd_mirror_char(char c); +cmd_t *cmd_getcommand(void); + void cmd_collect_char(char c); void cmd_handle(cmd_t *command); void cmd_handle_set(char *op1, char *op2); diff --git a/src/inverter.c b/src/inverter.c index 172a7ce..e07df02 100644 --- a/src/inverter.c +++ b/src/inverter.c @@ -9,21 +9,17 @@ int main() { - /* With this MCU frequency, it is 38,4k baud */ + sei(); + + /* With this MCU frequency (8MHz), 12 is a baudrate of 38.4k baud */ uart_init(12); - printf("Starting up!\r\n"); - - /* - * We are using Timer 1 Compare Match Unit B. - * OC1B is on Pin PB6. Let's make it an output. - */ - DDRB |= (1 << DDB6); - initPwmTimer1(); while (1) { - + /* We handle terminated commands here. + Outside of the context of the UART receive interrupt. */ + cmd_handle(cmd_getcommand()); } return 0;