aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2020-06-04 14:56:52 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2020-06-04 14:56:52 +0200
commit4c9a0e8ee2e261ea56d79aa1726b54492f6d67b2 (patch)
treed20da57c2aa52950cd93fc3b6c5a3330a461819c
parent949800520856178ab54e05812e6a510fc191bd8d (diff)
downloadrenard_hb9hi-4c9a0e8ee2e261ea56d79aa1726b54492f6d67b2.tar.gz
renard_hb9hi-4c9a0e8ee2e261ea56d79aa1726b54492f6d67b2.tar.bz2
renard_hb9hi-4c9a0e8ee2e261ea56d79aa1726b54492f6d67b2.zip
Try to get sync to work
-rw-r--r--src/testapp1/main.c34
1 files changed, 17 insertions, 17 deletions
diff --git a/src/testapp1/main.c b/src/testapp1/main.c
index 046acaa..d7e571d 100644
--- a/src/testapp1/main.c
+++ b/src/testapp1/main.c
@@ -18,11 +18,11 @@ static const uint8_t num_renards_cycle = 4;
// colon (:) represents ERROR
static const char letters[] = "EISH:";
static const char unique_letter = letters[renard_id];
+static char *morse_string = "M O ";
volatile uint8_t reset_time;
volatile uint8_t systick; /* Timer (100Hz increment) */
-volatile uint8_t seconds;
-volatile uint16_t minutes;
+volatile uint32_t seconds;
/*---------------------------------------------------------*/
/* 100Hz timer interrupt generated by OC2 */
@@ -35,15 +35,9 @@ ISR(TIMER1_COMPA_vect)
seconds += 1;
}
- if (seconds == 60) {
- seconds = 0;
- minutes++;
- }
-
if (reset_time) {
reset_time = 0;
seconds = 0;
- minutes = 0;
}
}
@@ -51,7 +45,7 @@ static int inittimer(void)
{
/* Start 100Hz system timer (TC2.OC) */
TCCR0B |= (1 << WGM02); // Configure timer for CTC mode
- TIMSK |= (1 << OCIE1A); // enable overflow interrupt
+ TIMSK |= (1 << OCIE1A); // enable compare match A interrupt
OCR1A = (uint8_t)(F_CPU / 64 / 1000 / 100 - 1); // Set CTC compare value to 10ms
TCCR0B |= ((1 << CS10) | (1 << CS11)); // Start timer at Fcpu/64
@@ -105,7 +99,6 @@ int main(void)
{
systick = 0;
seconds = 0;
- minutes = 0;
reset_time = 0;
/* Enable PTT output on PB0 */
@@ -118,7 +111,6 @@ int main(void)
/* initialise timer interrupt */
inittimer();
- static char *morse_string = "M O ";
morse_string[4] = unique_letter;
const int permanent = (unique_letter == ':');
@@ -132,20 +124,25 @@ int main(void)
delay_ms(12*DIT_DURATION);
while (1) {
+ const uint32_t second = seconds % 60uL;
+ const uint32_t minute = seconds / 60uL;
+
if ((PINB & PORTB_SYNCn) == 0) {
reset_time = 1;
sync_pending = 0;
- }
- if (permanent || sync_pending) {
+ morse("Y");
+ delay_ms(6*DIT_DURATION);
+ }
+ else if (permanent || sync_pending) {
morse(morse_string);
delay_ms(6*DIT_DURATION);
}
- else if (minutes >= 10) { // see README.md
+ else if (minute >= 1 /* TODO */ ) { // see README.md
/* renard id 0: start at (k * num_renards_cycle) * 60, end at (k * num_renards_cycle) * 60 + 55 */
- const int in_timeslot = (minutes % num_renards_cycle) == renard_id;
+ const int in_timeslot = (minute % (uint32_t)num_renards_cycle) == renard_id;
- if (in_timeslot && seconds < 55) {
+ if (in_timeslot && second < 55) {
morse(morse_string);
delay_ms(6*DIT_DURATION);
}
@@ -155,12 +152,15 @@ int main(void)
}
else {
/* renard id 0: start every 30s, with an additional 2s offset depending on renard_id */
- const uint32_t second_offset = seconds % 30;
+ const uint32_t second_offset = second % 10uL; // TODO
if (second_offset == 2 * renard_id) {
morse_char(unique_letter);
delay_ms(1000); // avoid retrigger in same second
}
+ else {
+ delay_ms(50);
+ }
}
}