Skip to content

Commit 30e6b39

Browse files
author
camilo
committed
Logger improvements
1 parent 9321e58 commit 30e6b39

File tree

14 files changed

+102480
-157
lines changed

14 files changed

+102480
-157
lines changed
1.6 MB
Binary file not shown.
1.6 MB
Binary file not shown.

check/Release/BrowseInfo/sa_check.pbw

Lines changed: 102195 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
@REM This batch file has been generated by the IAR Embedded Workbench
2+
@REM C-SPY Debugger, as an aid to preparing a command line for running
3+
@REM the cspybat command line utility using the appropriate settings.
4+
@REM
5+
@REM Note that this file is generated every time a new debug session
6+
@REM is initialized, so you may want to move or rename the file before
7+
@REM making changes.
8+
@REM
9+
@REM You can launch cspybat by typing the name of this batch file followed
10+
@REM by the name of the debug file (usually an ELF/DWARF or UBROF file).
11+
@REM
12+
@REM Read about available command line parameters in the C-SPY Debugging
13+
@REM Guide. Hints about additional command line parameters that may be
14+
@REM useful in specific cases:
15+
@REM --download_only Downloads a code image without starting a debug
16+
@REM session afterwards.
17+
@REM --silent Omits the sign-on message.
18+
@REM --timeout Limits the maximum allowed execution time.
19+
@REM
20+
21+
22+
@echo off
23+
24+
if not "%~1" == "" goto debugFile
25+
26+
@echo on
27+
28+
"C:\iar\ewarm-9.60.2\common\bin\cspybat" -f "D:\Camilo\Documents\GitHub\QuarkTS-cpp\check\settings\sa_check.Release.general.xcl" --backend -f "D:\Camilo\Documents\GitHub\QuarkTS-cpp\check\settings\sa_check.Release.driver.xcl"
29+
30+
@echo off
31+
goto end
32+
33+
:debugFile
34+
35+
@echo on
36+
37+
"C:\iar\ewarm-9.60.2\common\bin\cspybat" -f "D:\Camilo\Documents\GitHub\QuarkTS-cpp\check\settings\sa_check.Release.general.xcl" "--debug_file=%~1" --backend -f "D:\Camilo\Documents\GitHub\QuarkTS-cpp\check\settings\sa_check.Release.driver.xcl"
38+
39+
@echo off
40+
:end
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
param([String]$debugfile = "");
2+
3+
# This powershell file has been generated by the IAR Embedded Workbench
4+
# C - SPY Debugger, as an aid to preparing a command line for running
5+
# the cspybat command line utility using the appropriate settings.
6+
#
7+
# Note that this file is generated every time a new debug session
8+
# is initialized, so you may want to move or rename the file before
9+
# making changes.
10+
#
11+
# You can launch cspybat by typing Powershell.exe -File followed by the name of this batch file, followed
12+
# by the name of the debug file (usually an ELF / DWARF or UBROF file).
13+
#
14+
# Read about available command line parameters in the C - SPY Debugging
15+
# Guide. Hints about additional command line parameters that may be
16+
# useful in specific cases :
17+
# --download_only Downloads a code image without starting a debug
18+
# session afterwards.
19+
# --silent Omits the sign - on message.
20+
# --timeout Limits the maximum allowed execution time.
21+
#
22+
23+
24+
if ($debugfile -eq "")
25+
{
26+
& "C:\iar\ewarm-9.60.2\common\bin\cspybat" -f "D:\Camilo\Documents\GitHub\QuarkTS-cpp\check\settings\sa_check.Release.general.xcl" --backend -f "D:\Camilo\Documents\GitHub\QuarkTS-cpp\check\settings\sa_check.Release.driver.xcl"
27+
}
28+
else
29+
{
30+
& "C:\iar\ewarm-9.60.2\common\bin\cspybat" -f "D:\Camilo\Documents\GitHub\QuarkTS-cpp\check\settings\sa_check.Release.general.xcl" --debug_file=$debugfile --backend -f "D:\Camilo\Documents\GitHub\QuarkTS-cpp\check\settings\sa_check.Release.driver.xcl"
31+
}

doc/pages/_2_foundations.dox

Lines changed: 92 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -418,35 +418,98 @@
418418
* @c DISABLED states.
419419
*
420420
* @section q_critical Critical sections
421-
* Since the kernel is non-preemptive, the only critical section that must be
422-
* handled are the shared resources accessed from the ISR context. Perhaps, the
423-
* most obvious way of achieving mutual exclusion is to allow the kernel to
424-
* disable interrupts before it enters their critical section and then, enable
425-
* interrupts after it leaves its critical section.
426-
*
427-
* By disabling interrupts, the CPU will be unable to change the current context.
428-
* This guarantees that the currently running job can use a shared resource
429-
* without another context accessing it. But, disabling interrupts, is a major
430-
* undertaking. At best, the system will not be able to service interrupts for
431-
* the time the current job is doing in its critical section, however, in QuarkTS++,
432-
* these critical sections are handled as quickly as possible.
433-
*
434-
* Considering that the kernel is hardware-independent, the application writer
435-
* should provide the necessary piece of code to enable and disable interrupts.
436-
*
437-
* For this, the qOS::critical::setInterruptsED() method should be used. In this way,
438-
* communication between ISR and tasks using queued notifications or data queues
439-
* is performed safely.
440-
*
441-
* In some systems, disabling the global IRQ flags is not enough, as they don't
442-
* save/restore state of interrupt, so here, the @c uint32_t argument and
443-
* return value in both functions (@c Disabler and @c Restorer) becomes relevant,
444-
* because they can be used by the application writer to save and restore the
445-
* current interrupt configuration. So, when a critical section is performed,
446-
* the @c Disabler, in addition to disabling the interrupts, returns the current
447-
* configuration to be retained by the kernel, later when the critical section
448-
* finish, this retained value is passed to @c Restorer to bring back the saved
449-
* configuration.
421+
*
422+
* Since the kernel is non-preemptive, the only critical sections that must be
423+
* handled are those involving shared resources accessed from ISR context.
424+
* The most straightforward way to achieve mutual exclusion is to temporarily
425+
* disable interrupts before entering a critical section and re-enable them
426+
* afterward.
427+
*
428+
* By disabling interrupts, the CPU cannot switch context, ensuring that the
429+
* currently running job accesses shared resources safely. However, this must
430+
* be done carefully and only for short periods. In QuarkTS++, critical
431+
* sections are minimized to keep interrupt latency as small as possible.
432+
*
433+
* Because the kernel is hardware-independent, the application developer must
434+
* provide the specific code for enabling and disabling interrupts.
435+
*
436+
* For this purpose, the qOS::critical::setInterruptsED() method should be
437+
* used. It allows the kernel to safely coordinate communication between ISRs
438+
* and tasks using queued notifications or data queues.
439+
*
440+
* Some MCUs require not only disabling global interrupt flags but also
441+
* saving and restoring the interrupt configuration. The @c uint32_t argument
442+
* and return values in the provided @c Disabler and @c Restorer functions are used
443+
* for this purpose.
444+
*
445+
* When a critical section is performed:
446+
* - The @c Disabler function disables interrupts and returns the previous
447+
* interrupt configuration.
448+
* - The kernel stores this configuration internally.
449+
* - After the critical section ends, the @c Restorer function restores
450+
* the saved configuration.
451+
*
452+
*
453+
* @subsection q_critical_examples Examples
454+
*
455+
* @subsubsection regintfcns Registering the interrupt control functions
456+
*
457+
* Before using any critical section, the application must register the
458+
* hardware-specific enable/disable routines:
459+
*
460+
* @code{.cpp}
461+
* using namespace qOS;
462+
*
463+
* static uint32_t disableInterrupts() {
464+
* uint32_t primask = __get_PRIMASK(); // Read current interrupt state
465+
* __disable_irq(); // Disable all interrupts
466+
* return primask; // Return the saved state
467+
* }
468+
*
469+
* static void restoreInterrupts(uint32_t primask) {
470+
* if (!primask) {
471+
* __enable_irq(); // Restore interrupt state
472+
* }
473+
* }
474+
*
475+
* void main( void ) {
476+
* critical::setInterruptsED(restoreInterrupts, disableInterrupts);
477+
* /* TODO : Setup OS and add tasks*/
478+
* }
479+
* @endcode
480+
*
481+
*
482+
* @subsubsection usecritscope Using critical::scope for quick inline protection
483+
*
484+
* This construct provides minimal syntax overhead for protecting short
485+
* critical sections. The section is automatically exited when the scope ends.
486+
*
487+
* @code{.cpp}
488+
* void example() {
489+
* // Normal code (non-critical)
490+
* critical::scope {
491+
* // This block runs with interrupts disabled
492+
* sharedCounter++;
493+
* }
494+
* // Back to normal code (interrupts enabled)
495+
* }
496+
* @endcode
497+
*
498+
*
499+
* @subsubsection usecritlock Using critical::lock (RAII-style)
500+
*
501+
* The qOS::critical::lock class automatically manages entry and exit of a
502+
* critical section using RAII semantics. When the object is created, interrupts
503+
* are disabled; when it goes out of scope, interrupts are restored.
504+
*
505+
* @code{.cpp}
506+
* void example() {
507+
* critical::lock lockGuard; // interrupts disabled here
508+
*
509+
* sharedBuffer.push(value); // safe shared access
510+
*
511+
* } // lockGuard destroyed → interrupts restored
512+
* @endcode
450513
*
451514
* @section q_configmacros Configuration macros
452515
* Some OS features can be customized using a set of macros located in the header

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cmake_minimum_required( VERSION 3.2 )
22
project( quarkts-cpp
3-
VERSION 1.7.8
3+
VERSION 1.7.9
44
DESCRIPTION "An open-source OS for small embedded applications"
55
LANGUAGES CXX )
66

src/QuarkTS.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ This file is part of the QuarkTS++ OS distribution.
4141
#ifndef QOS_CPP_H
4242
#define QOS_CPP_H
4343

44-
#define QUARKTS_CPP_VERSION "1.7.8"
45-
#define QUARKTS_CPP_VERNUM ( 178u )
44+
#define QUARKTS_CPP_VERSION "1.7.9"
45+
#define QUARKTS_CPP_VERNUM ( 179u )
4646
#define QUARKTS_CPP_CAPTION "QuarkTS++ OS " QUARKTS_CPP_VERSION
4747

4848
#include "config/config.h"
@@ -65,8 +65,9 @@ This file is part of the QuarkTS++ OS distribution.
6565
#include "include/logger.hpp"
6666

6767
namespace qOS {
68+
/*cstat -MISRAC++2008-0-1-4_b*/
6869
namespace build {
69-
constexpr const uint32_t number = 4215;
70+
constexpr const uint32_t number = 4238;
7071
constexpr const char* date = __DATE__;
7172
constexpr const char* time = __TIME__;
7273
constexpr const char* std = "c++11";
@@ -76,7 +77,7 @@ namespace qOS {
7677
constexpr const uint8_t number = QUARKTS_CPP_VERNUM;
7778
constexpr const uint8_t mayor = 1U;
7879
constexpr const uint8_t minor = 7U;
79-
constexpr const uint8_t rev = 8U;
80+
constexpr const uint8_t rev = 9U;
8081
}
8182
namespace product {
8283
constexpr const char* author = "J. Camilo Gomez C.";
@@ -90,6 +91,7 @@ namespace qOS {
9091
constexpr const char* source_model = "Open Source";
9192
constexpr const char* kernel_type = "Cooperative Real-Time Microkernel";
9293
}
94+
/*cstat +MISRAC++2008-0-1-4_b*/
9395
}
9496

9597
#endif /*QOS_CPP_H*/

src/include/critical.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,11 @@ namespace qOS {
6565
*
6666
* @code{.cpp}
6767
* void example() {
68+
* // code here : normal section(non-critical)
6869
* critical::scope {
6970
* // Code here runs in a critical section
7071
* }
72+
* // code here, normal section (non-critical)
7173
* }
7274
* @endcode
7375
*/

src/include/logger.hpp

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -324,31 +324,25 @@ namespace qOS {
324324
void writeNumStr( void ) noexcept;
325325
public:
326326
static _logger& getInstance( void ) noexcept;
327+
327328
template <typename T>
328-
inline _logger& _log_integer( const T& v, bool is_int )
329+
auto toLog(const T& v) -> decltype((void)(T(1) % 1), (void)(-T(1)), void()) // only valid for integrals
329330
{
330-
/*cstat -MISRAC++2008-5-0-9 -MISRAC++2008-5-0-8*/
331-
if ( is_int ) {
332-
(void)util::integerToString( static_cast<signed_t>( v ), buffer, base ); // skipcq: CXX-C1000
333-
}
334-
else {
335-
(void)util::unsignedToString( static_cast<unsigned_t>( v ), buffer, base ); // skipcq: CXX-C1000
331+
/*cstat -CERT-INT31-C_a -MISRAC++2008-5-0-8 -MISRAC++2008-5-0-9 -MISRAC++2008-0-1-2_b -MISRAC++2008-0-1-2_a*/
332+
if (T(-1) < T(0)) {
333+
(void)util::integerToString(static_cast<signed_t>(v), buffer, base);
334+
} else {
335+
(void)util::unsignedToString(static_cast<unsigned_t>(v), buffer, base);
336336
}
337-
/*cstat +MISRAC++2008-5-0-9 +MISRAC++2008-5-0-8*/
337+
/*cstat +CERT-INT31-C_a +MISRAC++2008-5-0-8 +MISRAC++2008-5-0-9 +MISRAC++2008-0-1-2_b +MISRAC++2008-0-1-2_a*/
338338
writeNumStr();
339-
return *this;
340339
}
341340

342341
void toLog( const char& v );
343342
void toLog( const char * s );
344-
void toLog( const short& v );
345-
void toLog( const int& v );
346-
void toLog( const long int& v );
347-
void toLog( const unsigned char& v );
348-
void toLog( const unsigned short& v );
349-
void toLog( const unsigned int& v );
350-
void toLog( const unsigned long& v );
351343
void toLog( const void * const p );
344+
345+
void toLog( const float32_t& v );
352346
void toLog( const float64_t& v );
353347
void toLog( const lout_base& f );
354348
void toLog( const mem& m );
@@ -373,17 +367,17 @@ namespace qOS {
373367
ChainLoggerProxy( const ChainLoggerProxy& ) = delete;
374368
ChainLoggerProxy( ChainLoggerProxy&& other ) noexcept : parent( other.parent ) {}
375369
~ChainLoggerProxy();
370+
371+
template<typename T>
372+
auto operator<<(const T& v) -> decltype((void)(v + 0), *this)
373+
{
374+
parent.toLog( v );
375+
return *this;
376+
}
377+
376378
ChainLoggerProxy& operator<<( const char& v );
377379
ChainLoggerProxy& operator<<( const char * s );
378-
ChainLoggerProxy& operator<<( const short& v );
379-
ChainLoggerProxy& operator<<( const int& v );
380-
ChainLoggerProxy& operator<<( const long int& v );
381-
ChainLoggerProxy& operator<<( const unsigned char& v );
382-
ChainLoggerProxy& operator<<( const unsigned short& v );
383-
ChainLoggerProxy& operator<<( const unsigned int& v );
384-
ChainLoggerProxy& operator<<( const unsigned long& v );
385380
ChainLoggerProxy& operator<<( const void * const p );
386-
ChainLoggerProxy& operator<<( const float64_t& v );
387381
ChainLoggerProxy& operator<<( const lout_base& f );
388382
ChainLoggerProxy& operator<<( const mem& m );
389383
ChainLoggerProxy& operator<<( const pre& m );

0 commit comments

Comments
 (0)