Add a command to turn off Timer1.

This commit is contained in:
Marco 2022-05-31 00:08:54 +02:00
parent 424e2e710f
commit 8143ae4eaf
2 changed files with 35 additions and 4 deletions

View File

@ -6,6 +6,7 @@
#include "commands.h" #include "commands.h"
#include "pins.h" #include "pins.h"
#include "uart.h" #include "uart.h"
#include "timer.h"
cmd_t command = { cmd_t command = {
@ -38,6 +39,11 @@ void cmd_collect_char(char c)
command.index = 0; command.index = 0;
cmd_terminated = 1; 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) 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")) if (0 == strcmp(tok1, "switch") || 0 == strcmp(tok1, "sw"))
cmd_handle_switch(tok2, tok3); cmd_handle_switch(tok2, tok3);
cmd_terminated = 0; cmd_terminated = 0;
} }
@ -77,11 +84,20 @@ void cmd_handle_set(char *op1, char *op2)
else if (0 == strcmp(op1, "t1_top")) { else if (0 == strcmp(op1, "t1_top")) {
val = strtol(op2, &end, 10); val = strtol(op2, &end, 10);
if (op2 != end) { if (op2 != end) {
OCR0A = val; OCR1A = val;
printf("Setting Timer1 TOP to %li\r\n", val); printf("Setting Timer1 TOP to %li\r\n", val);
} }
else 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")) { else if (0 == strcmp(op1, "t0_ps")) {
val = strtol(op2, &end, 10); val = strtol(op2, &end, 10);
@ -157,3 +173,17 @@ void cmd_handle_switch(char *op1, char *op2)
togglePin(&PORTD, PD0); 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;
}

View File

@ -9,3 +9,4 @@ void cmd_collect_char(char c);
void cmd_handle(cmd_t *command); void cmd_handle(cmd_t *command);
void cmd_handle_set(char *op1, char *op2); void cmd_handle_set(char *op1, char *op2);
void cmd_handle_switch(char *op1, char *op2); void cmd_handle_switch(char *op1, char *op2);
int cmd_handle_switch_timer(void);