summaryrefslogtreecommitdiffstats
path: root/rf_test/recv.c
blob: 2e5c1c90258323ed70033a4667f09a09fad13754 (plain)
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
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>

#include "rfm.h"
#include "serial.h"

#define TEST_LED    PB1
#define LOCK_LED    PD6
#define UNLOCK_LED  PD7

#define SYN    0xAA
#define LOCK   0xB5
#define UNLOCK 0xAE

#define SIGPIN PB0

static inline void led_init(void)
{
	DDRB  |= (1 << TEST_LED);
	DDRD  |= (1 << LOCK_LED) | (1 << UNLOCK_LED);
}

static inline void pcint2_init(void)
{
    PCICR |= (1 << PCIE2);
    PCMSK2 |= (1 << PCINT0);
}

int main(void)
{
	DDRB &= ~(1 << SIGPIN);
	PORTB &= ~(1 << SIGPIN);

	led_init();
	serial_init();
	pcint2_init();

	sei();

	for (;;)
		;

	return 0;
}

ISR(PCINT2_vect)
{
	char *s;
	uint8_t buf[2], n;	

	n = rfm_recvfrom(0x00, buf, 2);

	if (buf[1] == LOCK)
		s = "LOCK";
	else if (buf[1] == UNLOCK)
		s = "UNLOCK";
	else
		s = "Garbage";
	
	serial_write_line(s);
}