Add a command to turn off Timer1.
This commit is contained in:
parent
424e2e710f
commit
8143ae4eaf
@ -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;
|
||||||
|
}
|
@ -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);
|
Loading…
Reference in New Issue
Block a user