From ee8f6387ad26c00f26d345ae1f931c3c1870fe83 Mon Sep 17 00:00:00 2001 From: Marco Date: Thu, 12 May 2022 18:25:38 +0200 Subject: [PATCH] =?UTF-8?q?Add=20command=20and=20play=20around=20with=20sh?= =?UTF-8?q?it.=20Change=20atoi()=20with=20strtol()=20because=20it=20is=20s?= =?UTF-8?q?afer.=20=C2=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands.c | 36 ++++++++++++++++++++++++++++++------ src/inverter.c | 9 +-------- src/timer.c | 8 ++++---- src/uart.c | 9 +++++++++ 4 files changed, 44 insertions(+), 18 deletions(-) diff --git a/src/commands.c b/src/commands.c index 5448225..7dd2253 100644 --- a/src/commands.c +++ b/src/commands.c @@ -25,8 +25,6 @@ void cmd_collect_char(char c) if (c == 0xD) { - printf("\n\r"); - /* Null-terminate the string */ command.buf[command.index-1] = '\0'; cmd_handle(&command); @@ -48,15 +46,41 @@ void cmd_handle(cmd_t *command) void cmd_handle_set(char *op1, char *op2) { - int val; + long int val; + char *end; if (0 == strcmp(op1, "t0_top")) { - val = atoi(op2); - if (val) { + val = strtol(op2, &end, 10); + if (op2 != end) { OCR0A = val; - printf("Setting Timer0 TOP to %i\r\n", val); + printf("Setting Timer0 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)); + switch (val) + { + case 0: + TCCR0B |= (1 << CS00); + break; + case 8: + TCCR0B |= (1 << CS01); + break; + case 64: + TCCR0B |= (1 << CS00) | (1 << CS01); + break; + case 256: + TCCR0B |= (1 << CS02); + break; + case 1024: + TCCR0B |= (1 << CS02) | (1 << CS00); + break; + default: + printf("No valid prescaler value.\n\r"); + break; + } + } } \ No newline at end of file diff --git a/src/inverter.c b/src/inverter.c index 0be082c..aa6e7f7 100644 --- a/src/inverter.c +++ b/src/inverter.c @@ -20,7 +20,7 @@ int main() while (1) { if ((PORTB & (1<1) { - _delay_us(10); + _delay_us(1); PORTB &= ~(1< +#include #include "include/uart.h" +#include "include/commands.h" static FILE stream = FDEV_SETUP_STREAM(uart_printf, NULL, _FDEV_SETUP_WRITE); @@ -40,3 +42,10 @@ int uart_printf(char var, FILE *stream) return 0; } +ISR(USART1_RX_vect) +{ + char u; + u = UDR1; + + cmd_collect_char(u); +} \ No newline at end of file