forked from bristlemouth/bm_protocol
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.c
More file actions
48 lines (40 loc) · 1.01 KB
/
debug.c
File metadata and controls
48 lines (40 loc) · 1.01 KB
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
#include <string.h>
#include "debug.h"
#include "bsp.h"
#include "FreeRTOS.h"
#include "semphr.h"
static DebugPutc_t debugPutcFn = NULL;
static SemaphoreHandle_t debugPrintMutex;
/*
Override newlib printf implementation with our own internal one. This will send
characters over the USB virtual COM port.
*/
int printf(const char* format, ...) {
if(debugPutcFn == NULL){
return -1;
}
configASSERT(xSemaphoreTake(debugPrintMutex, portMAX_DELAY) == pdTRUE);
va_list va;
va_start(va, format);
int rval = vfctprintf(debugPutcFn, NULL, format, va);
va_end(va);
xSemaphoreGive(debugPrintMutex);
return rval;
}
void debugInit(DebugPutc_t fn) {
debugPutcFn = fn;
debugPrintMutex = xSemaphoreCreateMutex();
configASSERT(debugPrintMutex);
}
void swoPutchar(char character, void* arg) {
(void)arg;
ITM_SendChar(character);
}
void debugPrintBuff(void *buff, size_t len) {
configASSERT(buff != NULL);
uint8_t *bytes = (uint8_t *)buff;
while(len-- > 0) {
printf("%02X ", *bytes++);
}
printf("\n");
}