summaryrefslogtreecommitdiffstats
path: root/mac/debug.h
blob: 0e6cb5eed1b07fe5732e7521ee76ca1fc7662003 (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
63
64
65
66
67
68
69
70
#ifndef MYRADIO_PHY_DEBUG_H_
#define MYRADIO_PHY_DEBUG_H_

/*** Debugging interface for the PHY ***/

#include "util.h"

#include <stdint.h>
#include <avr/io.h>

/* We have a debugwire that we can switch high/low
 * for debugging the PHY code. */

#define DEBUGWIRE_PORT		PORTC
#define DEBUGWIRE_DDR		DDRC
#define DEBUGWIRE_BIT		5

static inline void debug_set(bool bit_high)
{
	if (bit_high)
		DEBUGWIRE_PORT |= (1 << DEBUGWIRE_BIT);
	else
		DEBUGWIRE_PORT &= ~(1 << DEBUGWIRE_BIT);
}

static inline void debug_flip(void)
{
	DEBUGWIRE_PORT ^= (1 << DEBUGWIRE_BIT);
}

static inline void debug_put_signature(void)
{
	uint8_t i;

	debug_set(0);
	for (i = 0; i < 8; i++) {
		debug_flip();
		udelay(500);
	}
	debug_set(0);
}

static inline void debug_put_bytes(const void *_buf, uint8_t size,
				   uint8_t msec_delay)
{
	const uint8_t *buf = _buf;
	uint8_t i;
	int8_t j;

	debug_put_signature();
	mdelay(msec_delay);
	mdelay(msec_delay);
	for (i = 0; i < size; i++) {
		for (j = 7; j >= 0; j--) {
			debug_set(buf[i] & (1 << j));
			mdelay(msec_delay);
		}
	}
	mdelay(msec_delay);
	mdelay(msec_delay);
	debug_put_signature();
}

static inline void debug_initialize(void)
{
	debug_set(0);
	DEBUGWIRE_DDR |= (1 << DEBUGWIRE_BIT);
}

#endif /* MYRADIO_PHY_DEBUG_H_ */
bues.ch cgit interface