aboutsummaryrefslogtreecommitdiffstats
path: root/src/testapp1/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testapp1/main.c')
-rw-r--r--src/testapp1/main.c77
1 files changed, 70 insertions, 7 deletions
diff --git a/src/testapp1/main.c b/src/testapp1/main.c
index b305372..117551a 100644
--- a/src/testapp1/main.c
+++ b/src/testapp1/main.c
@@ -6,18 +6,45 @@
#include "delay.h"
#include "morse.h"
-
+/* Definitions for pins */
#define PORTB_PTT (1 << 0)
+#define PORTB_SYNCn (1 << 2)
#define PORTB_LED (1 << 4)
-volatile uint8_t Timer; /* Timer (100Hz increment) */
+/* Specify ID here */
+static const uint8_t renard_id = 0;
+
+static const uint8_t num_renards_cycle = 4;
+// colon (:) represents ERROR
+static const char letters[] = "eish:";
+static const char unique_letter = letters[renard_id];
+
+volatile uint8_t reset_time;
+volatile uint8_t systick; /* Timer (100Hz increment) */
+volatile uint8_t seconds;
+volatile uint16_t minutes;
/*---------------------------------------------------------*/
/* 100Hz timer interrupt generated by OC2 */
/*---------------------------------------------------------*/
ISR(TIMER1_COMPA_vect)
{
- Timer++;
+ systick++;
+ if (systick == 10) {
+ systick = 0;
+ seconds += 1;
+ }
+
+ if (seconds == 60) {
+ seconds = 0;
+ minutes++;
+ }
+
+ if (reset_time) {
+ reset_time = 0;
+ seconds = 0;
+ minutes = 0;
+ }
}
static int inittimer(void)
@@ -76,6 +103,11 @@ void dit(void)
int main(void)
{
+ systick = 0;
+ seconds = 0;
+ minutes = 0;
+ reset_time = 0;
+
/* Enable PTT output on PB0 */
#if PTT_LOGIC_LOW
PORTB = PORTB_PTT;
@@ -86,14 +118,45 @@ int main(void)
/* initialise timer interrupt */
inittimer();
+ static char *morse_string = "MO ";
+ morse_string[2] = unique_letter;
+
+ const int permanent = (unique_letter == ':');
+
delay_ms(12*DIT_DURATION);
- morse("HB9EGM");
+ morse("HB9HI");
delay_ms(12*DIT_DURATION);
while (1) {
- // morse code !
- morse("MOH");
- delay_ms(6*DIT_DURATION);
+ if ((PINB & PORTB_SYNCn) == 0) {
+ reset_time = 1;
+ }
+
+ if (permanent) {
+ morse(morse_string);
+ delay_ms(6*DIT_DURATION);
+ }
+ else if (minutes >= 10) { // 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;
+
+ if (in_timeslot && seconds < 55) {
+ morse(morse_string);
+ delay_ms(6*DIT_DURATION);
+ }
+ else {
+ delay_ms(DIT_DURATION);
+ }
+ }
+ else {
+ /* renard id 0: start every 30s, with an additional 2s offset depending on renard_id */
+ const uint32_t second_offset = seconds % 30;
+
+ if (second_offset == 2 * renard_id) {
+ morse_char(unique_letter);
+ delay_ms(1000); // avoid retrigger in same second
+ }
+ }
}
return 0;