summaryrefslogtreecommitdiffstats
path: root/rf_test/recv.c
blob: 74d1672437a89fa8bf3bd4539d60d1494daaa672 (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
#include <avr/io.h>
#include <avr/interrupt.h>

#include "radio.h"
#include "serial.h"

#define BUFLEN         61

#define RX_PIN         PB0
#define RX_DDR         DDRB
#define RX_PORT        PORTB
#define RX_PCIE        PCIE0
#define RX_PCINT       PCINT0
#define RX_PCMSK       PCMSK0
#define RX_PCINTVEC    PCINT0_vect

int main(void)
{
	struct radio_cfg cfg;

	cfg.payload_len = PAYLOAD_LEN;

	RX_DDR &= ~(1 << RX_PIN);
	PCICR |= (1 << RX_PCIE);
	RX_PCMSK |= (1 << RX_PCINT);

	serial_init();
	radio_init(&cfg);

	sei();

	for (;;)
		;

	return 0;
}

ISR(RX_PCINTVEC)
{
	uint8_t i, n;
	char buf[BUFLEN + 1];

	cli();

	serial_write_line("Handling pin change IRQ");

	n = radio_recv(buf, BUFLEN);
	buf[n] = '\0';
	
	for (i = 0; i < n; i++)
		serial_write(buf[i]);
	serial_write('\r');
	serial_write('\n');

	sei();
}