Skip to content

Commit 9c41113

Browse files
committed
Add system testing firmware
1 parent 8ef4afb commit 9c41113

File tree

2 files changed

+216
-0
lines changed

2 files changed

+216
-0
lines changed

firmware/DIU_TEST/main.c

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
2+
#include "main.h"
3+
4+
static char repeat_text[] = "Repeat test [y/n]: ";
5+
volatile unsigned char second;
6+
7+
ISR(PORTA_PORT_vect)
8+
{
9+
second++;
10+
EXTERNAL_INTERRUPT_TRIGGER_PORT.INTFLAGS = EXTERNAL_INTERRUPT_TRIGGER_PIN;
11+
}
12+
13+
ISR(TCA0_OVF_vect)
14+
{
15+
TCA0.SINGLE.INTFLAGS = TCA_SINGLE_OVF_bm;
16+
}
17+
18+
ISR(TCA0_CMP0_vect)
19+
{
20+
TCA0.SINGLE.INTFLAGS = TCA_SINGLE_CMP0_bm;
21+
}
22+
23+
ISR(TCB0_INT_vect)
24+
{
25+
PORTB.OUTTGL = PIN4_bm;
26+
27+
TCB0.INTFLAGS = TCB_CAPT_bm;
28+
}
29+
30+
static unsigned char confirm(void)
31+
{
32+
unsigned char repeat = '\0';
33+
34+
do
35+
{
36+
printf("%s", repeat_text);
37+
scanf("%c", &repeat);
38+
printf("\n\r");
39+
40+
} while (repeat != 'y' && repeat != 'n');
41+
42+
printf("\n\r");
43+
44+
if(repeat == 'n')
45+
{
46+
return 0;
47+
}
48+
return 1;
49+
}
50+
51+
static void counter_init(void)
52+
{
53+
TCB0.CCMP = 0x1387;
54+
TCB0.INTCTRL = TCB_CAPT_bm;
55+
TCB0.CTRLB = TCB_CNTMODE_INT_gc;
56+
TCB0.CTRLA = TCB_CLKSEL_CLKDIV2_gc | TCB_ENABLE_bm;
57+
sei();
58+
}
59+
60+
static void counter_disable(void)
61+
{
62+
TCA0.SINGLE.CTRLA &= ~(TCA_SINGLE_CLKSEL_DIV8_gc | TCA_SINGLE_ENABLE_bm);
63+
}
64+
65+
int main(void)
66+
{
67+
EXTERNAL_INTERRUPT_TRIGGER_PORT.DIRCLR = EXTERNAL_INTERRUPT_TRIGGER_PIN;
68+
EXTERNAL_INTERRUPT_TRIGGER_PORT.EXTERNAL_INTERRUPT_TRIGGER_PINCTRL = EXTERNAL_INTERRUPT_TRIGGER_PIN_SETUP;
69+
70+
system_init();
71+
72+
sei();
73+
74+
input_init();
75+
uart_init();
76+
mcp7940_init(RTC_Enable);
77+
clock_init();
78+
clock_setdata(0UL, 0UL, CLOCK_LED_None);
79+
80+
printf("\n\n\n\rStarting System Test:\n\n\r");
81+
82+
do
83+
{
84+
printf("1.) Button:\n\n\r");
85+
86+
for (unsigned char i=0; i < 4; i++)
87+
{
88+
printf(" -> Press S%1u: ", (i + 1));
89+
while (input_status((1<<i)) == OFF);
90+
printf("Push detected!\n\r");
91+
}
92+
printf("\n\r");
93+
94+
} while (confirm());
95+
96+
do
97+
{
98+
printf("2.) Running LED Test:\n\n\r");
99+
100+
for (unsigned char i=0; i < 24; i++)
101+
{
102+
clock_settime(i, 0, 0, CLOCK_LED_None);
103+
printf(" -> Hour: %2u\r", i);
104+
_delay_ms(250);
105+
}
106+
printf("\n\r");
107+
108+
for (unsigned char i=0; i < 60; i++)
109+
{
110+
clock_settime(0, i, 0, CLOCK_LED_None);
111+
printf(" -> Minute: %2u\r", i);
112+
_delay_ms(250);
113+
}
114+
printf("\n\r");
115+
116+
for (unsigned char i=0; i < 4; i++)
117+
{
118+
clock_settime(0, 0, 0, (1<<i));
119+
printf(" -> Clock Back-LEDS: %2u\r", (i + 1));
120+
_delay_ms(2000);
121+
}
122+
printf("\n\n\r");
123+
124+
} while (confirm());
125+
126+
do
127+
{
128+
printf("2.) Running Buzzer Test:\n\n\r");
129+
130+
PORTB.DIRSET = PIN4_bm;
131+
PORTB.OUTCLR = PIN4_bm;
132+
counter_init();
133+
134+
_delay_ms(5000);
135+
136+
counter_disable();
137+
PORTB.DIRCLR = PIN4_bm;
138+
PORTB.OUTCLR = PIN4_bm;
139+
140+
printf(" -> Done\r\n\n");
141+
142+
} while (confirm());
143+
144+
unsigned char fault = 0;
145+
146+
do
147+
{
148+
printf("3.) Running RTC Test:\n\n\r");
149+
printf(" -> Resetting\n\r");
150+
second = 0;
151+
152+
for (unsigned char i=0; i < 10; i++)
153+
{
154+
printf(" -> Wait for trigger: %2u\r", (10 - i));
155+
_delay_ms(1200);
156+
}
157+
158+
if (second > 9)
159+
{
160+
printf(" -> Trigger confirmed (%u)\n\r", second);
161+
printf(" -> Real Time Clock running\n\r");
162+
}
163+
else
164+
{
165+
printf(" -> Trigger not found (%u)\n\r", second);
166+
printf(" -> Real Time Clock error\n\r");
167+
168+
fault = 1;
169+
}
170+
printf("\n\r");
171+
172+
} while (confirm());
173+
174+
if(fault)
175+
{
176+
printf("\n\n\rSystem test failure, check system status!\n\r");
177+
}
178+
else
179+
{
180+
printf("\n\n\rSystem test successful, everything is running!\n\r");
181+
}
182+
183+
while (1)
184+
{
185+
}
186+
}
187+

firmware/DIU_TEST/main.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
#ifndef MAIN_H_
3+
#define MAIN_H_
4+
5+
#ifndef F_CPU
6+
#define F_CPU 20000000UL
7+
#endif
8+
9+
#ifndef EXTERNAL_INTERRUPT_TRIGGER_PORT
10+
#define EXTERNAL_INTERRUPT_TRIGGER_PORT PORTA
11+
#endif
12+
13+
#ifndef EXTERNAL_INTERRUPT_TRIGGER_PIN
14+
#define EXTERNAL_INTERRUPT_TRIGGER_PIN PIN7_bm
15+
#define EXTERNAL_INTERRUPT_TRIGGER_PINCTRL PIN7CTRL
16+
#define EXTERNAL_INTERRUPT_TRIGGER_PIN_SETUP PORT_ISC_FALLING_gc | PORT_PULLUPEN_bm
17+
#endif
18+
19+
#include <avr/io.h>
20+
#include <avr/interrupt.h>
21+
#include <util/delay.h>
22+
23+
#include "../lib/system/system.h"
24+
#include "../lib/input/input.h"
25+
#include "../lib/uart/uart.h"
26+
#include "../lib/clock/clock.h"
27+
#include "../lib/rtc/mcp7940.h"
28+
29+
#endif /* MAIN_H_ */

0 commit comments

Comments
 (0)