-
Notifications
You must be signed in to change notification settings - Fork 5
/
test.c
125 lines (110 loc) · 2.59 KB
/
test.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include "test.h"
#include "common.h"
#include "serial.h"
#include "ringbuffer.h"
void print_size_u8() {
int i = sizeof(uint8_t);
uart_puts("Size of 8");
while (i--) {
uart_putc('Q');
}
}
void print_size_u16() {
int i = sizeof(uint16_t);
uart_puts("Size of 16");
while (i--) {
uart_putc('W');
}
}
void print_size_u32() {
int i = sizeof(uint32_t);
uart_puts("Size of 32");
while (i--) {
uart_putc('E');
}
}
void print_size_pointer() {
int i = sizeof(uint32_t *);
uart_puts("Size of 32p");
while (i--) {
uart_putc('R');
}
}
void print_size_int() {
int i = sizeof(int);
uart_puts("Size of int");
while (i--) {
uart_putc('T');
}
}
void dump_memory(uint8_t *start, int len) {
uart_puts("memory dump\r\n");
for (int i=0; i < len; i++) {
uart_put_u8(*start);
start++;
if(i % 32 == 0) {
uart_putc('\r');
uart_putc('\n');
} else if (i % 4 == 0) {
uart_putc(' ');
}
}
uart_puts("\r\nend\r\n");
}
static uint8_t test_buffer[8];
static struct ringbuffer_t testring = {
.start = test_buffer,
.last = test_buffer + 8 - 1,
.read = test_buffer,
.write = test_buffer,
.status = 0,
};
static void print_ringbuffer(struct ringbuffer_t *ring) {
uart_puts("\r\n=ringbuffer");
uart_puts("\r\npo ");
uart_put_pointer(ring);
uart_puts("\r\nst ");
uart_put_pointer(ring->start);
uart_puts("\r\nla ");
uart_put_pointer(ring->last);
uart_puts("\r\nrd ");
uart_put_pointer(ring->read);
uart_puts("\r\nwr ");
uart_put_pointer(ring->write);
}
void test_ringbuffer() {
uint16_t ret = 0;
char ch = 0;
uart_puts("ringbuffer test\r\n");
uart_puts("\r\nringbuffer is empty. Check is_readable\r\n");
uart_puts("should be 0000. is : ");
uart_put_u16(ring_is_readable(&testring));
uart_puts("\r\n");
uart_puts("writing 4 bytes into ringbuffer (1234)\r\n");
ringbuffer_write(&testring, '1');
ringbuffer_write(&testring, '2');
ringbuffer_write(&testring, '3');
ringbuffer_write(&testring, '4');
print_ringbuffer(&testring);
uart_puts("check if ring is readable\r\n");
uart_puts("check readable : ");
uart_put_u16(ring_is_readable(&testring));
uart_puts("\r\n");
uart_puts("read out all avaiable bytes until ring isnt readable\r\n");
while (ring_is_readable(&testring)) {
uart_puts("read return code ");
ret = ringbuffer_read(&testring, &ch);
uart_put_u16(ret);
uart_puts(" char is : ");
uart_putc(ch);
uart_puts("\r\n");
}
uart_puts("end reading variables\r\n");
uart_puts("try to read even when ring isnt readable");
uart_puts("read return code ");
ret = ringbuffer_read(&testring, &ch);
uart_put_u16(ret);
uart_puts(" char is : ");
uart_putc(ch);
uart_puts("\r\n");
}