From 3c8256df7de49a4fb64cdbcdea46ff471ff5f846 Mon Sep 17 00:00:00 2001 From: Kshitij Sisodia Date: Mon, 24 May 2021 16:12:40 +0100 Subject: MLECO-1948: Fix for SysTick init and GNU's stdout The counter val could have been 0 when read the first time quickly after the init function. The init function will now wait for the SysTick counter to start before returning. Also included are some minor changes to get around GNU's file stream implementation being line buffered. Change-Id: I8d51fef5d85f1261a6a5710608349d7ecc19ad62 --- .../bare-metal/bsp/bsp-packs/mps3/timer_mps3.c | 11 ++++----- .../platforms/bare-metal/bsp/cmsis-device/irqs.c | 8 ++++++- source/application/main/Mfcc.cc | 27 +++++++++------------- source/application/main/include/Mfcc.hpp | 4 ++-- source/use_case/ad/src/MainLoop.cc | 3 ++- source/use_case/asr/src/MainLoop.cc | 3 ++- source/use_case/img_class/src/MainLoop.cc | 3 ++- source/use_case/kws/src/MainLoop.cc | 3 ++- source/use_case/kws_asr/src/MainLoop.cc | 3 ++- 9 files changed, 35 insertions(+), 30 deletions(-) diff --git a/source/application/hal/platforms/bare-metal/bsp/bsp-packs/mps3/timer_mps3.c b/source/application/hal/platforms/bare-metal/bsp/bsp-packs/mps3/timer_mps3.c index a72103c..c0c3bdf 100644 --- a/source/application/hal/platforms/bare-metal/bsp/bsp-packs/mps3/timer_mps3.c +++ b/source/application/hal/platforms/bare-metal/bsp/bsp-packs/mps3/timer_mps3.c @@ -41,12 +41,11 @@ mps3_time_counter get_time_counter(void) .counter_fpga = MPS3_FPGAIO->COUNTER, .counter_systick = Get_SysTick_Cycle_Count() }; - debug("Timestamp:" - "\n\tCounter 1 Hz: %" PRIu32 - "\n\tCounter 100 Hz: %" PRIu32 - "\n\tCounter FPGA: %" PRIu32 - "\n\tCounter CPU: %" PRIu64 "\n", - t.counter_1Hz, t.counter_100Hz, t.counter_fpga, t.counter_systick); + debug("Timestamp:\n"); + debug("\tCounter 1 Hz: %" PRIu32 "\n", t.counter_1Hz); + debug("\tCounter 100 Hz: %" PRIu32 "\n", t.counter_100Hz); + debug("\tCounter FPGA: %" PRIu32 "\n", t.counter_fpga); + debug("\tCounter CPU: %" PRIu64 "\n", t.counter_systick); return t; } diff --git a/source/application/hal/platforms/bare-metal/bsp/cmsis-device/irqs.c b/source/application/hal/platforms/bare-metal/bsp/cmsis-device/irqs.c index 7c9f4b8..7d8aa06 100644 --- a/source/application/hal/platforms/bare-metal/bsp/cmsis-device/irqs.c +++ b/source/application/hal/platforms/bare-metal/bsp/cmsis-device/irqs.c @@ -71,7 +71,8 @@ __attribute__((noreturn)) static void DefaultHandler(void) #define DEFAULT_HANDLER_CALL(type) \ do { \ - printf("\n%s caught by function %s\n", \ + printf("\n"); \ + printf("%s caught by function %s\n", \ type, __FUNCTION__); \ DefaultHandler(); \ } while (0) @@ -238,6 +239,11 @@ int Init_SysTick(void) /* Enable interrupt again. */ NVIC_EnableIRQ(SysTick_IRQn); + /* Wait for SysTick to kick off */ + while (!err && !SysTick->VAL) { + __NOP(); + } + return err; } diff --git a/source/application/main/Mfcc.cc b/source/application/main/Mfcc.cc index c998ef2..2d697ee 100644 --- a/source/application/main/Mfcc.cc +++ b/source/application/main/Mfcc.cc @@ -45,22 +45,17 @@ namespace audio { m_useHtkMethod(useHtkMethod) {} - std::string MfccParams::Str() const + void MfccParams::Log() const { - char strC[1024]; - snprintf(strC, sizeof(strC) - 1, "\n \ - \n\t Sampling frequency: %f\ - \n\t Number of filter banks: %" PRIu32 "\ - \n\t Mel frequency limit (low): %f\ - \n\t Mel frequency limit (high): %f\ - \n\t Number of MFCC features: %" PRIu32 "\ - \n\t Frame length: %" PRIu32 "\ - \n\t Padded frame length: %" PRIu32 "\ - \n\t Using HTK for Mel scale: %s\n", - this->m_samplingFreq, this->m_numFbankBins, this->m_melLoFreq, - this->m_melHiFreq, this->m_numMfccFeatures, this->m_frameLen, - this->m_frameLenPadded, this->m_useHtkMethod ? "yes" : "no"); - return std::string{strC}; + debug("MFCC parameters:\n"); + debug("\t Sampling frequency: %f\n", this->m_samplingFreq); + debug("\t Number of filter banks: %" PRIu32 "\n", this->m_numFbankBins); + debug("\t Mel frequency limit (low): %f\n", this->m_melLoFreq); + debug("\t Mel frequency limit (high): %f\n", this->m_melHiFreq); + debug("\t Number of MFCC features: %" PRIu32 "\n", this->m_numMfccFeatures); + debug("\t Frame length: %" PRIu32 "\n", this->m_frameLen); + debug("\t Padded frame length: %" PRIu32 "\n", this->m_frameLenPadded); + debug("\t Using HTK for Mel scale: %s\n", this->m_useHtkMethod ? "yes" : "no"); } MFCC::MFCC(const MfccParams& params): @@ -84,7 +79,7 @@ namespace audio { } math::MathUtils::FftInitF32(this->m_params.m_frameLenPadded, this->m_fftInstance); - debug("Instantiated MFCC object: %s\n", this->m_params.Str().c_str()); + this->m_params.Log(); } void MFCC::Init() diff --git a/source/application/main/include/Mfcc.hpp b/source/application/main/include/Mfcc.hpp index 6b11ebb..86330ca 100644 --- a/source/application/main/include/Mfcc.hpp +++ b/source/application/main/include/Mfcc.hpp @@ -51,8 +51,8 @@ namespace audio { ~MfccParams() = default; - /** @brief String representation of parameters */ - std::string Str() const; + /** @brief Log parameters */ + void Log() const; }; /** diff --git a/source/use_case/ad/src/MainLoop.cc b/source/use_case/ad/src/MainLoop.cc index 6a7cbe0..6431509 100644 --- a/source/use_case/ad/src/MainLoop.cc +++ b/source/use_case/ad/src/MainLoop.cc @@ -31,7 +31,8 @@ enum opcodes static void DisplayMenu() { - printf("\n\nUser input required\n"); + printf("\n"); + printf("User input required\n"); printf("Enter option number from:\n\n"); printf(" %u. Classify next audio signal\n", MENU_OPT_RUN_INF_NEXT); printf(" %u. Classify audio signal at chosen index\n", MENU_OPT_RUN_INF_CHOSEN); diff --git a/source/use_case/asr/src/MainLoop.cc b/source/use_case/asr/src/MainLoop.cc index 9950541..24b6fcd 100644 --- a/source/use_case/asr/src/MainLoop.cc +++ b/source/use_case/asr/src/MainLoop.cc @@ -35,7 +35,8 @@ enum opcodes static void DisplayMenu() { - printf("\n\nUser input required\n"); + printf("\n\n"); + printf("User input required\n"); printf("Enter option number from:\n\n"); printf(" %u. Classify next audio clip\n", MENU_OPT_RUN_INF_NEXT); printf(" %u. Classify audio clip at chosen index\n", MENU_OPT_RUN_INF_CHOSEN); diff --git a/source/use_case/img_class/src/MainLoop.cc b/source/use_case/img_class/src/MainLoop.cc index 66d7064..255f8e0 100644 --- a/source/use_case/img_class/src/MainLoop.cc +++ b/source/use_case/img_class/src/MainLoop.cc @@ -35,7 +35,8 @@ enum opcodes static void DisplayMenu() { - printf("\n\nUser input required\n"); + printf("\n\n"); + printf("User input required\n"); printf("Enter option number from:\n\n"); printf(" %u. Classify next image\n", MENU_OPT_RUN_INF_NEXT); printf(" %u. Classify image at chosen index\n", MENU_OPT_RUN_INF_CHOSEN); diff --git a/source/use_case/kws/src/MainLoop.cc b/source/use_case/kws/src/MainLoop.cc index f971c30..48cdad4 100644 --- a/source/use_case/kws/src/MainLoop.cc +++ b/source/use_case/kws/src/MainLoop.cc @@ -35,7 +35,8 @@ enum opcodes static void DisplayMenu() { - printf("\n\nUser input required\n"); + printf("\n\n"); + printf("User input required\n"); printf("Enter option number from:\n\n"); printf(" %u. Classify next audio clip\n", MENU_OPT_RUN_INF_NEXT); printf(" %u. Classify audio clip at chosen index\n", MENU_OPT_RUN_INF_CHOSEN); diff --git a/source/use_case/kws_asr/src/MainLoop.cc b/source/use_case/kws_asr/src/MainLoop.cc index 631b7c1..3a69315 100644 --- a/source/use_case/kws_asr/src/MainLoop.cc +++ b/source/use_case/kws_asr/src/MainLoop.cc @@ -40,7 +40,8 @@ enum opcodes static void DisplayMenu() { - printf("\n\nUser input required\n"); + printf("\n\n"); + printf("User input required\n"); printf("Enter option number from:\n\n"); printf(" %u. Classify next audio clip\n", MENU_OPT_RUN_INF_NEXT); printf(" %u. Classify audio clip at chosen index\n", MENU_OPT_RUN_INF_CHOSEN); -- cgit v1.2.1