-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.c
More file actions
50 lines (42 loc) · 986 Bytes
/
debug.c
File metadata and controls
50 lines (42 loc) · 986 Bytes
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
#include <avr/io.h>
#include <stdio.h>
#include "serial.h"
#include "debug.h"
// stdio interface functions
static int debug_getchar(FILE *stream);
static int debug_putchar(char c, FILE *stream);
static FILE serial_port_file = FDEV_SETUP_STREAM(debug_putchar, debug_getchar, _FDEV_SETUP_RW);
void debug_init(void)
{
// connect stdio functions
stdin = stdout = &serial_port_file;
}
void debug_periodic(void)
{
// debug_flush_buffer();
}
#ifdef DEBUG
void debug_dumpmem(void *_ptr, uint16_t len)
{
uint8_t *ptr = _ptr;
report("Memory at 0x%x len 0x%x: [", ptr, len);
for(int i=0; i<len; i++){
if(i>0)
report(", ");
report("0x%02x", ptr[i]);
}
report("]\n");
}
#endif
static int debug_getchar(FILE *stream)
{
return serial_read_byte();
}
static int debug_putchar(char c, FILE *stream)
{
if(c == '\n')
serial_write_byte('\r');
serial_write_byte(c);
return 0;
}
/* vim:set shiftwidth=4 expandtab: */