Fix compiling with CLI and define most commands away

This commit is contained in:
Raphael Coeffic
2021-11-21 11:18:35 +01:00
committed by Raphael Coeffic
parent 043c1e6a2d
commit 7cfcac3e1e
2 changed files with 124 additions and 119 deletions
+124 -115
View File
@@ -348,11 +348,12 @@ int cliTestNew()
return 0;
}
#if 0 // TODO later defined(COLORLCD)
#if defined(COLORLCD)
extern bool perMainEnabled;
typedef void (*timedTestFunc_t)(void);
#if defined(DEBUG_LCD)
void testDrawSolidFilledRectangle()
{
lcdDrawFilledRect(0, 0, LCD_W, LCD_H, SOLID, COLOR_THEME_SECONDARY3);
@@ -365,42 +366,29 @@ void testDrawFilledRectangle()
void testDrawSolidFilledRoundedRectangle()
{
lcdDrawFilledRect(0, 0, LCD_W/2, LCD_H/2, SOLID, ROUND|COLOR_THEME_SECONDARY3);
lcdDrawFilledRect(0, 0, LCD_W / 2, LCD_H / 2, SOLID,
ROUND | COLOR_THEME_SECONDARY3);
}
void testDrawBlackOverlay()
{
lcdDrawBlackOverlay();
}
void testDrawBlackOverlay() { lcdDrawBlackOverlay(); }
void testDrawSolidHorizontalLine1()
{
lcdDrawSolidHorizontalLine(0, 0, 1, 0);
}
void testDrawSolidHorizontalLine1() { lcdDrawSolidHorizontalLine(0, 0, 1, 0); }
void testDrawSolidHorizontalLine2()
{
lcdDrawSolidHorizontalLine(0, 0, LCD_W, 0);
}
void testDrawSolidVerticalLine1()
{
lcdDrawSolidVerticalLine(0, 0, 1, 0);
}
void testDrawSolidVerticalLine1() { lcdDrawSolidVerticalLine(0, 0, 1, 0); }
void testDrawSolidVerticalLine2()
{
lcdDrawSolidVerticalLine(0, 0, LCD_H, 0);
}
void testDrawSolidVerticalLine2() { lcdDrawSolidVerticalLine(0, 0, LCD_H, 0); }
void testDrawDiagonalLine()
{
lcdDrawLine(0,0, LCD_W, LCD_H, SOLID, COLOR_THEME_SECONDARY1);
lcdDrawLine(0, 0, LCD_W, LCD_H, SOLID, COLOR_THEME_SECONDARY1);
}
void testEmpty()
{
}
void testEmpty() {}
void testDrawRect()
{
@@ -409,35 +397,38 @@ void testDrawRect()
void testDrawText()
{
lcdDrawText(0, LCD_H/2, "The quick brown fox jumps over the lazy dog", COLOR_THEME_SECONDARY1);
lcdDrawText(0, LCD_H / 2, "The quick brown fox jumps over the lazy dog",
COLOR_THEME_SECONDARY1);
}
void testDrawTextVertical()
{
lcdDrawText(30, LCD_H, "The quick brown fox ", COLOR_THEME_SECONDARY1|VERTICAL);
lcdDrawText(30, LCD_H, "The quick brown fox ",
COLOR_THEME_SECONDARY1 | VERTICAL);
}
void testClear()
{
lcdClear();
}
void testClear() { lcdClear(); }
#define RUN_GRAPHICS_TEST(name, runtime) runTimedFunctionTest(name, #name, runtime, 100)
#define RUN_GRAPHICS_TEST(name, runtime) \
runTimedFunctionTest(name, #name, runtime, 100)
float runTimedFunctionTest(timedTestFunc_t func, const char * name, uint32_t runtime, uint16_t step)
float runTimedFunctionTest(timedTestFunc_t func, const char *name,
uint32_t runtime, uint16_t step)
{
const uint32_t start = RTOS_GET_MS();
uint32_t noRuns = 0;
uint32_t actualRuntime = 0;
while ((actualRuntime = RTOS_GET_MS() - start) < runtime ) {
for (uint16_t n=0; n < step; n++) {
while ((actualRuntime = RTOS_GET_MS() - start) < runtime) {
for (uint16_t n = 0; n < step; n++) {
func();
}
lcdRefresh();
noRuns += step;
}
const float result = (noRuns * 500.0f) / (float)actualRuntime; // runs/second
serialPrint("Test %s speed: %lu.%02u, (%lu runs in %lu ms)", name, uint32_t(result), uint16_t((result - uint32_t(result)) * 100.0f), noRuns, actualRuntime);
const float result = (noRuns * 500.0f) / (float)actualRuntime; // runs/second
serialPrint("Test %s speed: %lu.%02u, (%lu runs in %lu ms)", name,
uint32_t(result), uint16_t((result - uint32_t(result)) * 100.0f),
noRuns, actualRuntime);
RTOS_WAIT_MS(200);
return result;
}
@@ -447,7 +438,7 @@ int cliTestGraphics()
serialPrint("Starting graphics performance test...");
RTOS_WAIT_MS(200);
watchdogSuspend(6000/*60s*/);
watchdogSuspend(6000 /*60s*/);
if (pulsesStarted()) {
pausePulses();
}
@@ -470,7 +461,8 @@ int cliTestGraphics()
result += RUN_GRAPHICS_TEST(testDrawTextVertical, 1000);
result += RUN_GRAPHICS_TEST(testClear, 1000);
serialPrint("Total speed: %lu.%02u", uint32_t(result), uint16_t((result - uint32_t(result)) * 100.0f));
serialPrint("Total speed: %lu.%02u", uint32_t(result),
uint16_t((result - uint32_t(result)) * 100.0f));
perMainEnabled = true;
if (pulsesStarted()) {
@@ -481,46 +473,47 @@ int cliTestGraphics()
return 0;
}
#endif
void memoryRead(const uint8_t * src, uint32_t size)
#if defined(DEBUG_RAM)
void memoryRead(const uint8_t *src, uint32_t size)
{
// uint8_t data;
while(size--) {
/*data =*/ *(const uint8_t volatile *)src;
while (size--) {
/*data =*/*(const uint8_t volatile *)src;
++src;
}
}
void memoryRead(const uint32_t * src, uint32_t size)
void memoryRead(const uint32_t *src, uint32_t size)
{
while(size--) {
while (size--) {
*(const uint32_t volatile *)src;
++src;
}
}
uint32_t * testbuff[100];
uint32_t *testbuff[100];
void memoryCopy(uint8_t * dest, const uint8_t * src, uint32_t size)
void memoryCopy(uint8_t *dest, const uint8_t *src, uint32_t size)
{
while(size--) {
while (size--) {
*dest = *src;
++src;
++dest;
}
}
void memoryCopy(uint32_t * dest, const uint32_t * src, uint32_t size)
void memoryCopy(uint32_t *dest, const uint32_t *src, uint32_t size)
{
while(size--) {
while (size--) {
*dest = *src;
++src;
++dest;
}
}
#define MEMORY_SPEED_BLOCK_SIZE (4*1024)
#define MEMORY_SPEED_BLOCK_SIZE (4 * 1024)
void testMemoryReadFrom_RAM_8bit()
{
@@ -529,7 +522,7 @@ void testMemoryReadFrom_RAM_8bit()
void testMemoryReadFrom_RAM_32bit()
{
memoryRead((const uint32_t *)0x20000000, MEMORY_SPEED_BLOCK_SIZE/4);
memoryRead((const uint32_t *)0x20000000, MEMORY_SPEED_BLOCK_SIZE / 4);
}
void testMemoryReadFrom_SDRAM_8bit()
@@ -539,41 +532,46 @@ void testMemoryReadFrom_SDRAM_8bit()
void testMemoryReadFrom_SDRAM_32bit()
{
memoryRead((const uint32_t *)0xD0000000, MEMORY_SPEED_BLOCK_SIZE/4);
memoryRead((const uint32_t *)0xD0000000, MEMORY_SPEED_BLOCK_SIZE / 4);
}
extern uint8_t * LCD_FIRST_FRAME_BUFFER;
extern uint8_t * LCD_SECOND_FRAME_BUFFER;
extern uint8_t *LCD_FIRST_FRAME_BUFFER;
extern uint8_t *LCD_SECOND_FRAME_BUFFER;
void testMemoryCopyFrom_RAM_to_SDRAM_32bit()
{
memoryCopy((uint32_t *)LCD_FIRST_FRAME_BUFFER, (const uint32_t * )cliLastLine, MEMORY_SPEED_BLOCK_SIZE/4);
memoryCopy((uint32_t *)LCD_FIRST_FRAME_BUFFER, (const uint32_t *)cliLastLine,
MEMORY_SPEED_BLOCK_SIZE / 4);
}
void testMemoryCopyFrom_RAM_to_SDRAM_8bit()
{
memoryCopy((uint8_t *)LCD_FIRST_FRAME_BUFFER, (const uint8_t * )cliLastLine, MEMORY_SPEED_BLOCK_SIZE);
memoryCopy((uint8_t *)LCD_FIRST_FRAME_BUFFER, (const uint8_t *)cliLastLine,
MEMORY_SPEED_BLOCK_SIZE);
}
void testMemoryCopyFrom_SDRAM_to_SDRAM_32bit()
{
memoryCopy((uint32_t *)LCD_FIRST_FRAME_BUFFER, (const uint32_t * )LCD_SECOND_FRAME_BUFFER, MEMORY_SPEED_BLOCK_SIZE/4);
memoryCopy((uint32_t *)LCD_FIRST_FRAME_BUFFER,
(const uint32_t *)LCD_SECOND_FRAME_BUFFER,
MEMORY_SPEED_BLOCK_SIZE / 4);
}
void testMemoryCopyFrom_SDRAM_to_SDRAM_8bit()
{
memoryCopy((uint8_t *)LCD_FIRST_FRAME_BUFFER, (const uint8_t * )LCD_SECOND_FRAME_BUFFER, MEMORY_SPEED_BLOCK_SIZE);
memoryCopy((uint8_t *)LCD_FIRST_FRAME_BUFFER,
(const uint8_t *)LCD_SECOND_FRAME_BUFFER, MEMORY_SPEED_BLOCK_SIZE);
}
#define RUN_MEMORY_TEST(name, runtime) runTimedFunctionTest(name, #name, runtime, 100)
#define RUN_MEMORY_TEST(name, runtime) \
runTimedFunctionTest(name, #name, runtime, 100)
int cliTestMemorySpeed()
{
serialPrint("Starting memory speed test...");
RTOS_WAIT_MS(200);
watchdogSuspend(6000/*60s*/);
watchdogSuspend(6000 /*60s*/);
if (pulsesStarted()) {
pausePulses();
}
@@ -603,7 +601,8 @@ int cliTestMemorySpeed()
result += RUN_MEMORY_TEST(testMemoryCopyFrom_SDRAM_to_SDRAM_8bit, 200);
result += RUN_MEMORY_TEST(testMemoryCopyFrom_SDRAM_to_SDRAM_32bit, 200);
serialPrint("Total speed: %lu.%02u", uint32_t(result), uint16_t((result - uint32_t(result)) * 100.0f));
serialPrint("Total speed: %lu.%02u", uint32_t(result),
uint16_t((result - uint32_t(result)) * 100.0f));
LTDC_Cmd(ENABLE);
@@ -616,7 +615,9 @@ int cliTestMemorySpeed()
return 0;
}
#endif
#if defined(DEBUG_MODELSLIST)
#include "modelslist.h"
using std::list;
@@ -625,56 +626,59 @@ int cliTestModelsList()
ModelsList modList;
modList.load();
int count=0;
int count = 0;
serialPrint("Starting fetching RF data 100x...");
const uint32_t start = RTOS_GET_MS();
const list<ModelsCategory*>& cats = modList.getCategories();
while(1) {
for (list<ModelsCategory*>::const_iterator cat_it = cats.begin();
const list<ModelsCategory *> &cats = modList.getCategories();
while (1) {
for (list<ModelsCategory *>::const_iterator cat_it = cats.begin();
cat_it != cats.end(); ++cat_it) {
for (ModelsCategory::iterator mod_it = (*cat_it)->begin();
mod_it != (*cat_it)->end(); mod_it++) {
if (!(*mod_it)->fetchRfData()) {
serialPrint("Error while fetching RF data...");
return 0;
}
if (++count >= 100)
goto done;
if (++count >= 100) goto done;
}
}
}
done:
serialPrint("Done fetching %ix RF data: %lu ms", count, (RTOS_GET_MS() - start));
done:
serialPrint("Done fetching %ix RF data: %lu ms", count,
(RTOS_GET_MS() - start));
return 0;
}
#endif
#endif // #if defined(COLORLCD)
#endif // #if defined(COLORLCD)
#if defined(DEBUG)
int cliTest(const char ** argv)
{
if (!strcmp(argv[1], "new")) {
return cliTestNew();
}
else if (!strcmp(argv[1], "std::exception")) {
serialPrint("Not implemented");
}
#if 0 // TODO later defined(COLORLCD)
#if defined(COLORLCD)
#if defined(DEBUG_LCD)
else if (!strcmp(argv[1], "graphics")) {
return cliTestGraphics();
}
#endif
#if defined(DEBUG_RAM)
else if (!strcmp(argv[1], "memspd")) {
return cliTestMemorySpeed();
}
#endif
#if defined(DEBUG_MODELSLIST)
else if (!strcmp(argv[1], "modelslist")) {
return cliTestModelsList();
}
#endif
#endif
else {
serialPrint("%s: Invalid argument \"%s\"", argv[0], argv[1]);
@@ -682,7 +686,6 @@ int cliTest(const char ** argv)
return 0;
}
#if defined(DEBUG)
int cliTrace(const char ** argv)
{
if (!strcmp(argv[1], "on")) {
@@ -696,7 +699,6 @@ int cliTrace(const char ** argv)
}
return 0;
}
#endif
int cliStackInfo(const char ** argv)
{
@@ -756,6 +758,7 @@ int cliMemoryInfo(const char ** argv)
#endif
return 0;
}
#endif
int cliReboot(const char ** argv)
{
@@ -786,23 +789,26 @@ const MemArea memAreas[] = {
{ nullptr, nullptr, 0 },
};
int cliSet(const char ** argv)
int cliSet(const char **argv)
{
if (!strcmp(argv[1], "rtc")) {
struct gtm t;
int year, month, day, hour, minute, second;
if (toInt(argv, 2, &year) > 0 && toInt(argv, 3, &month) > 0 && toInt(argv, 4, &day) > 0 && toInt(argv, 5, &hour) > 0 && toInt(argv, 6, &minute) > 0 && toInt(argv, 7, &second) > 0) {
t.tm_year = year-TM_YEAR_BASE;
t.tm_mon = month-1;
if (toInt(argv, 2, &year) > 0 && toInt(argv, 3, &month) > 0 &&
toInt(argv, 4, &day) > 0 && toInt(argv, 5, &hour) > 0 &&
toInt(argv, 6, &minute) > 0 && toInt(argv, 7, &second) > 0) {
t.tm_year = year - TM_YEAR_BASE;
t.tm_mon = month - 1;
t.tm_mday = day;
t.tm_hour = hour;
t.tm_min = minute;
t.tm_sec = second;
g_rtcTime = gmktime(&t); // update local timestamp and get wday calculated
g_rtcTime =
gmktime(&t); // update local timestamp and get wday calculated
rtcSetTime(&t);
}
else {
serialPrint("%s: Invalid arguments \"%s\" \"%s\"", argv[0], argv[1], argv[2]);
} else {
serialPrint("%s: Invalid arguments \"%s\" \"%s\"", argv[0], argv[1],
argv[2]);
}
}
#if !defined(SOFTWARE_VOLUME)
@@ -810,9 +816,9 @@ int cliSet(const char ** argv)
int level = 0;
if (toInt(argv, 2, &level) > 0) {
setVolume(level);
}
else {
serialPrint("%s: Invalid argument \"%s\" \"%s\"", argv[0], argv[1], argv[2]);
} else {
serialPrint("%s: Invalid argument \"%s\" \"%s\"", argv[0], argv[1],
argv[2]);
}
return 0;
}
@@ -820,7 +826,6 @@ int cliSet(const char ** argv)
return 0;
}
#if defined(DEBUG_INTERRUPTS)
void printInterrupts()
{
@@ -837,7 +842,6 @@ void printInterrupts()
#endif //#if defined(DEBUG_INTERRUPTS)
#if defined(DEBUG_TASKS)
void printTaskSwitchLog()
{
serialPrint("Tasks legend [<task_id>, <task name>]:");
@@ -888,7 +892,6 @@ void printTaskSwitchLog()
#endif // #if defined(DEBUG_TASKS)
#if defined(DEBUG_TIMERS)
void printDebugTime(uint32_t time)
{
if (time >= 30000) {
@@ -916,34 +919,37 @@ void printDebugTimers()
}
#endif
#include "OsMutex.h"
extern RTOS_MUTEX_HANDLE audioMutex;
#if defined(DEBUG_AUDIO)
void printAudioVars()
{
for(int n = 0; n < AUDIO_BUFFER_COUNT; n++) {
serialPrint("Audio Buffer %d: size: %u, ", n, (uint32_t)audioBuffers[n].size);
for (int n = 0; n < AUDIO_BUFFER_COUNT; n++) {
serialPrint("Audio Buffer %d: size: %u, ", n,
(uint32_t)audioBuffers[n].size);
dump((uint8_t *)audioBuffers[n].data, 32);
}
serialPrint("fragments:");
for(int n = 0; n < AUDIO_QUEUE_LENGTH; n++) {
serialPrint("%d: type %u: id: %u, repeat: %u, ", n, (uint32_t)audioQueue.fragmentsFifo.fragments[n].type,
(uint32_t)audioQueue.fragmentsFifo.fragments[n].id,
(uint32_t)audioQueue.fragmentsFifo.fragments[n].repeat);
if ( audioQueue.fragmentsFifo.fragments[n].type == FRAGMENT_FILE) {
for (int n = 0; n < AUDIO_QUEUE_LENGTH; n++) {
serialPrint("%d: type %u: id: %u, repeat: %u, ", n,
(uint32_t)audioQueue.fragmentsFifo.fragments[n].type,
(uint32_t)audioQueue.fragmentsFifo.fragments[n].id,
(uint32_t)audioQueue.fragmentsFifo.fragments[n].repeat);
if (audioQueue.fragmentsFifo.fragments[n].type == FRAGMENT_FILE) {
serialPrint(" file: %s", audioQueue.fragmentsFifo.fragments[n].file);
}
}
serialPrint("FragmentFifo: ridx: %d, widx: %d", audioQueue.fragmentsFifo.ridx, audioQueue.fragmentsFifo.widx);
serialPrint("audioQueue: readIdx: %d, writeIdx: %d, full: %d", audioQueue.buffersFifo.readIdx, audioQueue.buffersFifo.writeIdx, audioQueue.buffersFifo.bufferFull);
serialPrint("FragmentFifo: ridx: %d, widx: %d",
audioQueue.fragmentsFifo.ridx, audioQueue.fragmentsFifo.widx);
serialPrint("audioQueue: readIdx: %d, writeIdx: %d, full: %d",
audioQueue.buffersFifo.readIdx, audioQueue.buffersFifo.writeIdx,
audioQueue.buffersFifo.bufferFull);
serialPrint("normalContext: %u", (uint32_t)audioQueue.normalContext.fragment.type);
serialPrint("audioMutex[%u] = %u", (uint32_t)audioMutex, (uint32_t)MutexTbl[audioMutex].mutexFlag);
serialPrint("normalContext: %u",
(uint32_t)audioQueue.normalContext.fragment.type);
}
#endif
#if defined(DEBUG)
int cliDisplay(const char ** argv)
{
long long int address = 0;
@@ -1102,7 +1108,9 @@ int cliDebugVars(const char ** argv)
return 0;
}
#endif
#if defined(DEBUG)
int cliRepeat(const char ** argv)
{
int interval = 0;
@@ -1124,6 +1132,7 @@ int cliRepeat(const char ** argv)
}
return 0;
}
#endif
#if defined(JITTER_MEASURE)
int cliShowJitter(const char ** argv)
@@ -1194,7 +1203,7 @@ int cliBlueTooth(const char ** argv)
}
#endif
#if defined(ACCESS_DENIED)
#if defined(ACCESS_DENIED) && defined(DEBUG_CRYPT)
extern "C" {
#include "AccessDenied/access_denied.h"
@@ -1252,19 +1261,19 @@ const CliCommand cliCommands[] = {
{ "readsd", cliReadSD, "<start sector> <sectors count> <read buffer size (sectors)>" },
{ "testsd", cliTestSD, "" },
{ "play", cliPlay, "<filename>" },
{ "print", cliDisplay, "<address> [<size>] | <what>" },
{ "p", cliDisplay, "<address> [<size>] | <what>" },
{ "reboot", cliReboot, "[wdt]" },
{ "set", cliSet, "<what> <value>" },
#if defined(DEBUG)
{ "print", cliDisplay, "<address> [<size>] | <what>" },
{ "p", cliDisplay, "<address> [<size>] | <what>" },
{ "stackinfo", cliStackInfo, "" },
{ "meminfo", cliMemoryInfo, "" },
{ "test", cliTest, "new | std::exception | graphics | memspd" },
#if defined(DEBUG)
{ "test", cliTest, "new | graphics | memspd" },
{ "trace", cliTrace, "on | off" },
#endif
{ "help", cliHelp, "[<command>]" },
{ "debugvars", cliDebugVars, "" },
{ "repeat", cliRepeat, "<interval> <command>" },
#endif
{ "help", cliHelp, "[<command>]" },
#if defined(JITTER_MEASURE)
{ "jitter", cliShowJitter, "" },
#endif
@@ -1274,7 +1283,7 @@ const CliCommand cliCommands[] = {
#if defined(BLUETOOTH)
{ "bt", cliBlueTooth, "<baudrate>|<command>" },
#endif
#if defined(ACCESS_DENIED)
#if defined(ACCESS_DENIED) && defined(DEBUG_CRYPT)
{ "crypt", cliCrypt, "<string to be encrypted>" },
#endif
{ nullptr, nullptr, nullptr } /* sentinel */