From 8143ae4eaf137dfb8ed3669e51b14c9b42054fc1 Mon Sep 17 00:00:00 2001 From: Marco Date: Tue, 31 May 2022 00:08:54 +0200 Subject: [PATCH] Add a command to turn off Timer1. --- src/commands.c | 36 +++++++++++++++++++++++++++++++++--- src/include/commands.h | 3 ++- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/commands.c b/src/commands.c index 7dc15d3..fa9ce16 100644 --- a/src/commands.c +++ b/src/commands.c @@ -6,6 +6,7 @@ #include "commands.h" #include "pins.h" #include "uart.h" +#include "timer.h" cmd_t command = { @@ -38,6 +39,11 @@ void cmd_collect_char(char c) command.index = 0; cmd_terminated = 1; } + + /* We are switching the timer off here because serial + * line handling is iffy with timer on */ + if (c == 0x18) + printf("T1: %d\r\n",cmd_handle_switch_timer()); } void cmd_handle(cmd_t *command) @@ -57,6 +63,7 @@ void cmd_handle(cmd_t *command) if (0 == strcmp(tok1, "switch") || 0 == strcmp(tok1, "sw")) cmd_handle_switch(tok2, tok3); + cmd_terminated = 0; } @@ -73,15 +80,24 @@ 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; + OCR1A = val; printf("Setting Timer1 TOP to %li\r\n", val); } else - printf("No valid value for t0_top given\n\r"); + printf("No valid value for t1_top given\n\r"); + } + else if (0 == strcmp(op1, "t1_cm")) { + val = strtol(op2, &end, 10); + if (op2 != end) { + OCR1B = val; + printf("Setting Timer1 Compare Match to %li\r\n", val); + } + else + printf("No valid value for t1_cm given\n\r"); } else if (0 == strcmp(op1, "t0_ps")) { val = strtol(op2, &end, 10); @@ -156,4 +172,18 @@ void cmd_handle_switch(char *op1, char *op2) else togglePin(&PORTD, PD0); } +} + +int cmd_handle_switch_timer(void) +{ + static int timer1_on = 1; + + if (timer1_on) + timer_disableT1(); + else + timer_enableT1(); + + timer1_on = !timer1_on; + + return timer1_on; } \ No newline at end of file diff --git a/src/include/commands.h b/src/include/commands.h index 054f187..43b368c 100644 --- a/src/include/commands.h +++ b/src/include/commands.h @@ -8,4 +8,5 @@ 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); -void cmd_handle_switch(char *op1, char *op2); \ No newline at end of file +void cmd_handle_switch(char *op1, char *op2); +int cmd_handle_switch_timer(void); \ No newline at end of file