-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
158 additions
and
44 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#ifndef SERIAL_MONITOR_H | ||
#define SERIAL_MONITOR_H | ||
|
||
#include "cmsis_os.h" | ||
|
||
/* Function to queue a message to be sent on the UART stream */ | ||
int serial_print(const char* format, ...); | ||
|
||
/* Defining Temperature Monitor Task */ | ||
void vSerialMonitor(void* pv_params); | ||
|
||
extern osThreadId_t serial_monitor_handle; | ||
extern const osThreadAttr_t serial_monitor_attributes; | ||
|
||
#endif // SERIAL_MONITOR_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#include "serial_monitor.h" | ||
#include <stdarg.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#define PRINTF_QUEUE_SIZE 16 /* Strings */ | ||
#define PRINTF_BUFFER_LEN 128 /* Characters */ | ||
|
||
osMessageQueueId_t printf_queue; | ||
osThreadId_t serial_monitor_handle; | ||
const osThreadAttr_t serial_monitor_attributes; | ||
|
||
/* | ||
* Referenced https://github.com/esp8266/Arduino/blob/master/cores/esp8266/Print.cpp | ||
* Preformat string then put into a buffer | ||
*/ | ||
int serial_print(const char* format, ...) | ||
{ | ||
va_list arg; | ||
char* buffer = malloc(sizeof(char) * PRINTF_BUFFER_LEN); | ||
if (buffer == NULL) | ||
return -1; | ||
|
||
/* Format Variadic Args into string */ | ||
va_start(arg, format); | ||
size_t len = vsnprintf(buffer, PRINTF_BUFFER_LEN, format, arg); | ||
va_end(arg); | ||
|
||
/* Check to make sure we don't overflow buffer */ | ||
if (len > PRINTF_BUFFER_LEN - 1) { | ||
free(buffer); | ||
return -2; | ||
} | ||
|
||
/* If string can't be queued */ | ||
osStatus_t stat = osMessageQueuePut(printf_queue, &buffer, 0U, 0U); | ||
if (stat) { | ||
free(buffer); | ||
return -3; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
void vSerialMonitor(void* pv_params) | ||
{ | ||
char* message; | ||
osStatus_t status; | ||
|
||
printf_queue = osMessageQueueNew(PRINTF_QUEUE_SIZE, sizeof(char*), NULL); | ||
|
||
for (;;) { | ||
/* Wait until new printf message comes into queue */ | ||
status = osMessageQueueGet(printf_queue, &message, NULL, osWaitForever); | ||
if (status != osOK) { | ||
// TODO: Trigger fault ? | ||
} else { | ||
printf(message); | ||
free(message); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters