-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_matrix.c
74 lines (64 loc) · 1.23 KB
/
main_matrix.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
* Main file.
*/
#define N 7
#include "config.h"
#include "src/onewire.h"
#include "data.h"
#include "uart.h"
#include <avr/interrupt.h>
#include <stdio.h>
#include "hamming_config.h"
#include "matrix.h"
#include "hamming.h"
volatile uint32_t i;
uint8_t j;
struct Matrix* data;
int main(void)
{
struct Hamming_config* conf = hamming_generate_config();
i = 1;
j = 0;
data = matrix_generate(N,1);
#ifdef DEBUG
//Setup led for debugging
//LED_DDR |= LED_PIN_MASK;
//LED_PORT &=~LED_PIN_MASK;
#endif
uart_init(BAUD_RATE);
// Pin change interrupt (INT1 pin)
EICRA |= (1 << ISC11); // Falling edge
EIMSK |= (1 << INT1); // Enable Interruption
EIFR |= (1 << INTF1);
char str[5];
// Enable interrupts.
sei();
//Main loop
for(;;)
{
sprintf(str, "%d\n", freeRam());
uart_tx_str(str);
if(i == 8)
{
struct Matrix* tmp = hamming_correction(data, conf);
struct Matrix* deco = hamming_decode(tmp, conf);
data_show(deco->data);
matrix_free(tmp);
matrix_free(deco);
i = 1;
}
}
}
ISR (INT1_vect) // Falling edge detected
{
_delay_us(T/4);
if(bus_read())
{
matrix_set(data, i, 1, 1);
}
else
{
matrix_set(data, i, 1, 0);
}
i += 1;
}