Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: modem_ref_helper_for_v5_3_217 modem_ref_helper
Diff: WizziDebug.cpp
- Revision:
- 10:0e6e54fb08c0
- Parent:
- 9:87d9cc850af1
- Child:
- 11:45093cacde63
--- a/WizziDebug.cpp Thu Aug 01 08:32:35 2019 +0000
+++ b/WizziDebug.cpp Mon Jan 25 11:23:47 2021 +0000
@@ -1,14 +1,16 @@
#include "mbed.h"
#include "rtos.h"
#include "WizziDebug.h"
-#include "CBuffer.h"
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
-#define DBG_MAX_STRING_SIZE (512)
+#define DBG_MAX_STRING_SIZE (256)
+#define TX_BUF_SIZE (512)
-static CBuffer<uint8_t, 2048> g_dbg_buf;
+static kal_buf_circ_handle_t g_cbuf;
+static kal_buf_circ_static_handle_t g_cbuf_h;
+static kal_buf_circ_static_buffer_t(g_cbuf_b, TX_BUF_SIZE, sizeof(uint8_t));
static char g_dbg_msg[DBG_MAX_STRING_SIZE];
static Thread g_dbg_thread(osPriorityLow, 512);
static RawSerial* g_dbg_serial;
@@ -57,6 +59,9 @@
g_dbg_led = led;
g_dbg_missing = 0;
+ g_cbuf = &g_cbuf_h;
+ kal_buf_circ_create_static(&g_cbuf_h, g_cbuf_b, TX_BUF_SIZE, sizeof(char));
+
g_dbg_serial = new RawSerial(tx, rx, 115200);
g_dbg_serial->format(8, SerialBase::None, 1);
g_dbg_serial->attach(callback(&dbg_serial_rx_isr), Serial::RxIrq);
@@ -80,6 +85,8 @@
static void dbg_add_to_buf(char* msg, int size)
{
+ uint8_t c;
+
#ifdef __FORCE_FLUSH__
for (int i = 0; i < size; i++)
{
@@ -88,15 +95,16 @@
#else
if(size > 0)
{
- if (g_dbg_buf.remaining_space() < size)
+ if (kal_buf_circ_space(g_cbuf) < size)
{
#ifdef __FLUSH_IF_FULL__
// Flush just what is needed
do {
- g_dbg_serial->putc(g_dbg_buf.pop());
- } while (g_dbg_buf.remaining_space() < size);
+ kal_buf_circ_pop(g_cbuf, &c);
+ g_dbg_serial->putc(c);
+ } while (kal_buf_circ_space(g_cbuf) < size);
- g_dbg_buf.add((uint8_t*)msg, size);
+ kal_buf_circ_put(g_cbuf, (uint8_t*)msg, size);
#else
// Discard
g_dbg_missing++;
@@ -105,7 +113,7 @@
else
{
// add
- g_dbg_buf.add((uint8_t*)msg, size);
+ kal_buf_circ_put(g_cbuf, (uint8_t*)msg, size);
}
// Allow printing
@@ -172,10 +180,13 @@
// Flush the pending debug messages.
void dbg_flush( void )
{
+ uint8_t c;
+
g_dbg_ressource.lock();
- while(!g_dbg_buf.empty())
+ while(!kal_buf_circ_empty(g_cbuf))
{
- g_dbg_serial->putc(g_dbg_buf.pop());
+ kal_buf_circ_pop(g_cbuf, &c);
+ g_dbg_serial->putc(c);
}
g_dbg_ressource.unlock();
}
@@ -230,6 +241,8 @@
// Thread for printing debug messages.
void dbg_print_thread()
{
+ uint8_t c;
+
FPRINT("(id:0x%08x)\r\n", osThreadGetId());
while (true)
@@ -242,7 +255,7 @@
g_dbg_missing = 0;
}
- while(!g_dbg_buf.empty())
+ while(!kal_buf_circ_empty(g_cbuf))
{
g_dbg_ressource.lock();
@@ -250,12 +263,13 @@
// Flush until EOL
uint8_t byte;
do {
- byte = g_dbg_buf.pop();
- g_dbg_serial->putc(byte);
- } while (byte != '\n' && !g_dbg_buf.empty());
+ kal_buf_circ_pop(g_cbuf, &c);
+ g_dbg_serial->putc(c);
+ } while (byte != '\n' && !kal_buf_circ_empty(g_cbuf));
#else
// Flush characters one by one
- g_dbg_serial->putc(g_dbg_buf.pop());
+ kal_buf_circ_pop(g_cbuf, &c);
+ g_dbg_serial->putc(c);
#endif
g_dbg_ressource.unlock();