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.c126
1 files changed, 126 insertions, 0 deletions
diff --git a/src/testapp1/main.c b/src/testapp1/main.c
new file mode 100644
index 0000000..9ce1456
--- /dev/null
+++ b/src/testapp1/main.c
@@ -0,0 +1,126 @@
+#include <stdio.h>
+#include <avr/pgmspace.h>
+#include <avr/io.h>
+#include <avr/interrupt.h>
+
+#include "delay.h"
+
+#define PORTB_PTT (1 << 0)
+
+volatile uint8_t Timer; /* Timer (100Hz increment) */
+
+/*---------------------------------------------------------*/
+/* 100Hz timer interrupt generated by OC2 */
+/*---------------------------------------------------------*/
+ISR(TIMER1_COMPA_vect)
+{
+ Timer++;
+}
+
+static int inittimer(void)
+{
+ /* Start 100Hz system timer (TC2.OC) */
+ TCCR0B |= (1 << WGM02); // Configure timer for CTC mode
+ TIMSK |= (1 << OCIE1A); // enable overflow 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
+
+ // Enable interrupts
+ sei();
+
+ return 0;
+}
+
+#define DIT_DURATION 100 // ms
+#define PTT_LOGIC_LOW 0
+
+#if PTT_LOGIC_LOW
+void dah()
+{
+ PORTB = 0; // PTT is inverted logic
+ delay_ms(3*DIT_DURATION);
+
+ PORTB = PORTB_PTT; // PTT is inverted logic
+ delay_ms(DIT_DURATION);
+}
+
+void dit()
+{
+ PORTB = 0; // PTT is inverted logic
+ delay_ms(DIT_DURATION);
+
+ PORTB = PORTB_PTT; // PTT is inverted logic
+ delay_ms(DIT_DURATION);
+}
+#else
+void dah()
+{
+ PORTB = PORTB_PTT;
+ delay_ms(3*DIT_DURATION);
+
+ PORTB = 0;
+ delay_ms(DIT_DURATION);
+}
+
+void dit()
+{
+ PORTB = PORTB_PTT;
+ delay_ms(DIT_DURATION);
+
+ PORTB = 0;
+ delay_ms(DIT_DURATION);
+}
+#endif
+
+int main ( void )
+{
+ /* Enable PTT output on PB0 */
+ PORTB = PORTB_PTT;
+ DDRB = PORTB_PTT;
+
+ /* initialise timer interrupt */
+ inittimer();
+
+ while (1) {
+ // morse code !
+ dah();
+ dah();
+
+ delay_ms(2*DIT_DURATION);
+ dah();
+ dah();
+ dah();
+
+ delay_ms(2*DIT_DURATION);
+ dit();
+ dit();
+ dit();
+
+ delay_ms(6*DIT_DURATION);
+ }
+
+ return 0;
+}
+
+#if 0
+static void some_old_function(uint32_t data)
+{
+ uint32_t test_status;
+ int sleep_ticks;
+
+ /* Enable all LEDs */
+ DDRB = 0xFF;
+ PORTB = 0xFF;
+
+ /* Flash LED once per second if passed, very quickly if failed */
+ sleep_ticks = (test_status == 0) ? SYSTEM_TICKS_PER_SEC : (SYSTEM_TICKS_PER_SEC/8);
+
+ /* Test finished, flash slowly for pass, fast for fail */
+ while (1)
+ {
+ /* Toggle a LED */
+ PORTB ^= (1 << 0);
+ }
+}
+#endif
+