-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSegger_functions.c
96 lines (83 loc) · 2.25 KB
/
Segger_functions.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
#include "Universal.h"
#include <stdio.h>
#include <stdint.h>
#include "SEGGER_RTT.h"
void Segger_write_hex_value(uint8_t value) {
#ifdef DEGUB_PRINTS
static uint8_t previous_value;
char str[20];
int count;
if( value != previous_value) {
count = sprintf(str, "Value: 0x%02xh\n", value);
if(count == 0 ) {
SEGGER_RTT_WriteString(DEFAULT_SEGGER_JLINK_RTT_VIEWER_CONSOLE, "Couldnt write to string.\n");
}
else {
SEGGER_RTT_WriteString(DEFAULT_SEGGER_JLINK_RTT_VIEWER_CONSOLE, str);
}
previous_value = value;
}
#endif
}
void Segger_write_one_hex_value(uint8_t value) {
#ifdef DEGUB_PRINTS
char str[20];
int count;
count = sprintf(str, "0x%02xh ", value);
if(count == 0 ) {
SEGGER_RTT_WriteString(DEFAULT_SEGGER_JLINK_RTT_VIEWER_CONSOLE, "Couldnt write to string.\n");
}
else {
SEGGER_RTT_WriteString(DEFAULT_SEGGER_JLINK_RTT_VIEWER_CONSOLE, str);
}
#endif
}
void Segger_write_string_int(const char* message, uint32_t value) {
#ifdef DEGUB_PRINTS
Segger_write_string(message);
char str[20];
int count;
count = sprintf(str, "%d ", value);
if(count == 0 ) {
SEGGER_RTT_WriteString(DEFAULT_SEGGER_JLINK_RTT_VIEWER_CONSOLE, "Couldnt write to string.\n");
}
else {
SEGGER_RTT_WriteString(DEFAULT_SEGGER_JLINK_RTT_VIEWER_CONSOLE, str);
SEGGER_RTT_WriteString(DEFAULT_SEGGER_JLINK_RTT_VIEWER_CONSOLE, "\n");
}
#endif
}
void Segger_write_one_hex_value_32(uint32_t value) {
#ifdef DEGUB_PRINTS
char str[20];
int count;
count = sprintf(str, "0x%08xh ", value);
if(count == 0 ) {
SEGGER_RTT_WriteString(DEFAULT_SEGGER_JLINK_RTT_VIEWER_CONSOLE, "Couldnt write to string.\n");
}
else {
SEGGER_RTT_WriteString(DEFAULT_SEGGER_JLINK_RTT_VIEWER_CONSOLE, str);
}
#endif
}
void Segger_write_string(const char *string) {
#ifdef DEGUB_PRINTS
SEGGER_RTT_WriteString(DEFAULT_SEGGER_JLINK_RTT_VIEWER_CONSOLE, string);
#endif
}
void Segger_write_string_value(const char *string, uint8_t value) {
#ifdef DEGUB_PRINTS
Segger_write_string(string);
Segger_write_one_hex_value(value);
Segger_write_string("\n");
#endif
}
void Print_Array(uint8_t Lenght, uint8_t* Message) {
#ifdef DEGUB_PRINTS
Segger_write_string("\t\t");
for(uint8_t i=0; i<Lenght; i++) {
Segger_write_one_hex_value(Message[i]);
}
Segger_write_string("\n");
#endif
}