From 229807879af02db938b4f9d51b551d6071a0e23e Mon Sep 17 00:00:00 2001 From: ckormanyos Date: Sun, 22 Dec 2024 21:17:03 +0100 Subject: [PATCH] Improve FreeRTOS syntax chapter11_07 --- .../src/os/FreeRTOS/Source/event_groups.c | 8 +++--- .../src/os/FreeRTOS/Source/include/FreeRTOS.h | 25 +++---------------- .../cfg/GCC-ATMega328/FreeRTOSConfig.h | 4 +-- .../os/FreeRTOS/Source/include/event_groups.h | 2 +- .../src/os/FreeRTOS/Source/include/portable.h | 2 +- .../src/os/FreeRTOS/Source/include/projdefs.h | 2 +- .../src/os/FreeRTOS/Source/include/queue.h | 2 +- .../src/os/FreeRTOS/Source/include/semphr.h | 2 +- .../src/os/FreeRTOS/Source/include/task.h | 2 +- .../src/os/FreeRTOS/Source/include/timers.h | 2 +- .../src/os/FreeRTOS/Source/list.c | 4 +-- .../Source/portable/GCC-ATMega328/port.cpp | 9 +++---- .../Source/portable/GCC-ATMega328/portmacro.h | 2 ++ .../Source/portable/MSVC-MingW/port.c | 12 ++++----- .../src/os/FreeRTOS/Source/queue.c | 8 +++--- .../src/os/FreeRTOS/Source/tasks.c | 10 ++++---- .../src/os/FreeRTOS/Source/timers.c | 8 +++--- examples/chapter11_07/src/os/os_task.h | 8 +++--- .../target/micros/avr/startup/int_vect.cpp | 18 +++++-------- 19 files changed, 54 insertions(+), 76 deletions(-) diff --git a/examples/chapter11_07/src/os/FreeRTOS/Source/event_groups.c b/examples/chapter11_07/src/os/FreeRTOS/Source/event_groups.c index 795f601b5..a3f6a9c51 100644 --- a/examples/chapter11_07/src/os/FreeRTOS/Source/event_groups.c +++ b/examples/chapter11_07/src/os/FreeRTOS/Source/event_groups.c @@ -24,9 +24,6 @@ * */ -/* Standard includes. */ -#include - /* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining * all the API functions to use the MPU wrappers. That should only be done when * task.h is included from an application file. */ @@ -34,9 +31,12 @@ /* FreeRTOS includes. */ #include +#include #include #include -#include + +/* Standard includes. */ +#include /* Lint e961, e750 and e9021 are suppressed as a MISRA exception justified * because the MPU ports require MPU_WRAPPERS_INCLUDED_FROM_API_FILE to be defined diff --git a/examples/chapter11_07/src/os/FreeRTOS/Source/include/FreeRTOS.h b/examples/chapter11_07/src/os/FreeRTOS/Source/include/FreeRTOS.h index 6cf532c63..3899f5d0c 100644 --- a/examples/chapter11_07/src/os/FreeRTOS/Source/include/FreeRTOS.h +++ b/examples/chapter11_07/src/os/FreeRTOS/Source/include/FreeRTOS.h @@ -27,25 +27,8 @@ #ifndef INC_FREERTOS_H #define INC_FREERTOS_H -/* - * Include the generic headers required for the FreeRTOS port being used. - */ #include - -/* - * If stdint.h cannot be located then: - * + If using GCC ensure the -nostdint options is *not* being used. - * + Ensure the project's include path includes the directory in which your - * compiler stores stdint.h. - * + Set any compiler options necessary for it to support C99, as technically - * stdint.h is only mandatory with C99 (FreeRTOS does not require C99 in any - * other way). - * + The FreeRTOS download includes a simple stdint.h definition that can be - * used in cases where none is provided by the compiler. The files only - * contains the typedefs required to build FreeRTOS. Read the instructions - * in FreeRTOS/source/stdint.readme for more information. - */ -#include /* READ COMMENT ABOVE. */ +#include /* *INDENT-OFF* */ #ifdef __cplusplus @@ -54,13 +37,13 @@ /* *INDENT-ON* */ /* Application specific configuration options. */ -#include "FreeRTOSConfig.h" +#include /* Basic FreeRTOS definitions. */ -#include "projdefs.h" +#include /* Definitions specific to the port being used. */ -#include "portable.h" +#include /* Must be defaulted before configUSE_NEWLIB_REENTRANT is used below. */ #ifndef configUSE_NEWLIB_REENTRANT diff --git a/examples/chapter11_07/src/os/FreeRTOS/Source/include/cfg/GCC-ATMega328/FreeRTOSConfig.h b/examples/chapter11_07/src/os/FreeRTOS/Source/include/cfg/GCC-ATMega328/FreeRTOSConfig.h index d9a7d8e0e..26ca2ac1c 100644 --- a/examples/chapter11_07/src/os/FreeRTOS/Source/include/cfg/GCC-ATMega328/FreeRTOSConfig.h +++ b/examples/chapter11_07/src/os/FreeRTOS/Source/include/cfg/GCC-ATMega328/FreeRTOSConfig.h @@ -56,8 +56,8 @@ configTOTAL_HEAP_SIZE is not defined. */ #define configUSE_PREEMPTION 1 #define configUSE_IDLE_HOOK 0 #define configUSE_TICK_HOOK 0 -#define configCPU_CLOCK_HZ (( unsigned long) 16000000ULL) -#define configTICK_RATE_HZ (( TickType_t) 100ULL) +#define configCPU_CLOCK_HZ ((unsigned long) 16000000ULL) +#define configTICK_RATE_HZ ((TickType_t) 100ULL) #define configMAX_PRIORITIES (4) #define configMINIMAL_STACK_SIZE ((unsigned short) 48) #define configMAX_TASK_NAME_LEN (32) diff --git a/examples/chapter11_07/src/os/FreeRTOS/Source/include/event_groups.h b/examples/chapter11_07/src/os/FreeRTOS/Source/include/event_groups.h index e03b70dc8..b2af28914 100644 --- a/examples/chapter11_07/src/os/FreeRTOS/Source/include/event_groups.h +++ b/examples/chapter11_07/src/os/FreeRTOS/Source/include/event_groups.h @@ -32,7 +32,7 @@ #endif /* FreeRTOS includes. */ -#include "timers.h" +#include /* *INDENT-OFF* */ #ifdef __cplusplus diff --git a/examples/chapter11_07/src/os/FreeRTOS/Source/include/portable.h b/examples/chapter11_07/src/os/FreeRTOS/Source/include/portable.h index c047f82e7..aa600ff93 100644 --- a/examples/chapter11_07/src/os/FreeRTOS/Source/include/portable.h +++ b/examples/chapter11_07/src/os/FreeRTOS/Source/include/portable.h @@ -36,7 +36,7 @@ * included here. In this case the path to the correct portmacro.h header file * must be set in the compiler's include path. */ #ifndef portENTER_CRITICAL - #include "portmacro.h" + #include #endif #if portBYTE_ALIGNMENT == 32 diff --git a/examples/chapter11_07/src/os/FreeRTOS/Source/include/projdefs.h b/examples/chapter11_07/src/os/FreeRTOS/Source/include/projdefs.h index 7a620a0e5..00abbbc15 100644 --- a/examples/chapter11_07/src/os/FreeRTOS/Source/include/projdefs.h +++ b/examples/chapter11_07/src/os/FreeRTOS/Source/include/projdefs.h @@ -31,7 +31,7 @@ * Defines the prototype to which task functions must conform. Defined in this * file to ensure the type is known before portable.h is included. */ -typedef void (* TaskFunction_t)( void * ); +typedef void (*TaskFunction_t)(void*); /* Converts a time in milliseconds to a time in ticks. This macro can be * overridden by a macro of the same name defined in FreeRTOSConfig.h in case the diff --git a/examples/chapter11_07/src/os/FreeRTOS/Source/include/queue.h b/examples/chapter11_07/src/os/FreeRTOS/Source/include/queue.h index d2ea2ae3b..1da93acb0 100644 --- a/examples/chapter11_07/src/os/FreeRTOS/Source/include/queue.h +++ b/examples/chapter11_07/src/os/FreeRTOS/Source/include/queue.h @@ -38,7 +38,7 @@ #endif /* *INDENT-ON* */ -#include "task.h" +#include /** * Type by which queues are referenced. For example, a call to xQueueCreate() diff --git a/examples/chapter11_07/src/os/FreeRTOS/Source/include/semphr.h b/examples/chapter11_07/src/os/FreeRTOS/Source/include/semphr.h index 06e248bcc..51eab13ff 100644 --- a/examples/chapter11_07/src/os/FreeRTOS/Source/include/semphr.h +++ b/examples/chapter11_07/src/os/FreeRTOS/Source/include/semphr.h @@ -31,7 +31,7 @@ #error "include FreeRTOS.h" must appear in source files before "include semphr.h" #endif -#include "queue.h" +#include typedef QueueHandle_t SemaphoreHandle_t; diff --git a/examples/chapter11_07/src/os/FreeRTOS/Source/include/task.h b/examples/chapter11_07/src/os/FreeRTOS/Source/include/task.h index e11edd363..09d45d4ee 100644 --- a/examples/chapter11_07/src/os/FreeRTOS/Source/include/task.h +++ b/examples/chapter11_07/src/os/FreeRTOS/Source/include/task.h @@ -32,7 +32,7 @@ #error "include FreeRTOS.h must appear in source files before include task.h" #endif -#include "list.h" +#include /* *INDENT-OFF* */ #ifdef __cplusplus diff --git a/examples/chapter11_07/src/os/FreeRTOS/Source/include/timers.h b/examples/chapter11_07/src/os/FreeRTOS/Source/include/timers.h index ba5c41326..419a0c48f 100644 --- a/examples/chapter11_07/src/os/FreeRTOS/Source/include/timers.h +++ b/examples/chapter11_07/src/os/FreeRTOS/Source/include/timers.h @@ -34,7 +34,7 @@ /*lint -save -e537 This headers are only multiply included if the application code * happens to also be including task.h. */ -#include "task.h" +#include /*lint -restore */ /* *INDENT-OFF* */ diff --git a/examples/chapter11_07/src/os/FreeRTOS/Source/list.c b/examples/chapter11_07/src/os/FreeRTOS/Source/list.c index d11973a73..e5fe4adad 100644 --- a/examples/chapter11_07/src/os/FreeRTOS/Source/list.c +++ b/examples/chapter11_07/src/os/FreeRTOS/Source/list.c @@ -25,8 +25,6 @@ */ -#include - /* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining * all the API functions to use the MPU wrappers. That should only be done when * task.h is included from an application file. */ @@ -35,6 +33,8 @@ #include #include +#include + /* Lint e9021, e961 and e750 are suppressed as a MISRA exception justified * because the MPU ports require MPU_WRAPPERS_INCLUDED_FROM_API_FILE to be * defined for the header files above, but not in this file, in order to diff --git a/examples/chapter11_07/src/os/FreeRTOS/Source/portable/GCC-ATMega328/port.cpp b/examples/chapter11_07/src/os/FreeRTOS/Source/portable/GCC-ATMega328/port.cpp index c345eeed3..e9a16cfb6 100644 --- a/examples/chapter11_07/src/os/FreeRTOS/Source/portable/GCC-ATMega328/port.cpp +++ b/examples/chapter11_07/src/os/FreeRTOS/Source/portable/GCC-ATMega328/port.cpp @@ -40,16 +40,15 @@ Changes from Christopher Kormanyos 2020-10-07 + Clean up spaces, tabs and alignment of typing. + OS tick uses timer1 compare-match-a to generate a tick interrupt at 100Hz (every 10ms). - + Use an undecorated ISR handle name (__vector_11). + + Use an undecorated ISR handle named (__vector_11). + Use C++ register template access to setup the timer. */ -#include - #include +#include #include -#include +#include /*-------------------------------------------------------------------- * Implementation of functions defined in portable.h for the AVR port. @@ -356,7 +355,7 @@ void vPortYieldFromTick(void) asm volatile ( "ret" ); } -#if defined(configUSE_PREEMPTION) && (configUSE_PREEMPTION == 1) +#if (configUSE_PREEMPTION == 1) extern "C" void __vector_11(void) __attribute__((signal, used, externally_visible, naked)); diff --git a/examples/chapter11_07/src/os/FreeRTOS/Source/portable/GCC-ATMega328/portmacro.h b/examples/chapter11_07/src/os/FreeRTOS/Source/portable/GCC-ATMega328/portmacro.h index e0a7f9de5..4a43f3576 100644 --- a/examples/chapter11_07/src/os/FreeRTOS/Source/portable/GCC-ATMega328/portmacro.h +++ b/examples/chapter11_07/src/os/FreeRTOS/Source/portable/GCC-ATMega328/portmacro.h @@ -28,6 +28,8 @@ #ifndef PORTMACRO_H #define PORTMACRO_H +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/examples/chapter11_07/src/os/FreeRTOS/Source/portable/MSVC-MingW/port.c b/examples/chapter11_07/src/os/FreeRTOS/Source/portable/MSVC-MingW/port.c index 3b9d331ed..4007e9106 100644 --- a/examples/chapter11_07/src/os/FreeRTOS/Source/portable/MSVC-MingW/port.c +++ b/examples/chapter11_07/src/os/FreeRTOS/Source/portable/MSVC-MingW/port.c @@ -25,16 +25,16 @@ * 1 tab == 4 spaces! */ +/* Scheduler includes. */ +#include +#include + /* Standard includes. */ -#include #include - -/* Scheduler includes. */ -#include "FreeRTOS.h" -#include "task.h" +#include #ifdef __GNUC__ - #include "mmsystem.h" + #include #else #pragma comment(lib, "winmm.lib") #endif diff --git a/examples/chapter11_07/src/os/FreeRTOS/Source/queue.c b/examples/chapter11_07/src/os/FreeRTOS/Source/queue.c index 58eae3859..f69f28cc1 100644 --- a/examples/chapter11_07/src/os/FreeRTOS/Source/queue.c +++ b/examples/chapter11_07/src/os/FreeRTOS/Source/queue.c @@ -24,9 +24,6 @@ * */ -#include -#include - /* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining * all the API functions to use the MPU wrappers. That should only be done when * task.h is included from an application file. */ @@ -36,6 +33,9 @@ #include #include +#include +#include + #if ( configUSE_CO_ROUTINES == 1 ) #include "croutine.h" #endif @@ -81,7 +81,7 @@ typedef struct SemaphoreData #define queueSEMAPHORE_QUEUE_ITEM_LENGTH ( ( UBaseType_t ) 0 ) #define queueMUTEX_GIVE_BLOCK_TIME ( ( TickType_t ) 0U ) -#if ( configUSE_PREEMPTION == 0 ) +#if (defined(configUSE_PREEMPTION) && (configUSE_PREEMPTION == 0)) /* If the cooperative scheduler is being used then a yield should not be * performed just because a higher priority task has been woken. */ diff --git a/examples/chapter11_07/src/os/FreeRTOS/Source/tasks.c b/examples/chapter11_07/src/os/FreeRTOS/Source/tasks.c index fd3b61e57..7069a7e30 100644 --- a/examples/chapter11_07/src/os/FreeRTOS/Source/tasks.c +++ b/examples/chapter11_07/src/os/FreeRTOS/Source/tasks.c @@ -24,10 +24,6 @@ * */ -/* Standard includes. */ -#include -#include - /* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining * all the API functions to use the MPU wrappers. That should only be done when * task.h is included from an application file. */ @@ -35,9 +31,13 @@ /* FreeRTOS includes. */ #include +#include #include #include -#include + +/* Standard includes. */ +#include +#include /* Lint e9021, e961 and e750 are suppressed as a MISRA exception justified * because the MPU ports require MPU_WRAPPERS_INCLUDED_FROM_API_FILE to be defined diff --git a/examples/chapter11_07/src/os/FreeRTOS/Source/timers.c b/examples/chapter11_07/src/os/FreeRTOS/Source/timers.c index 6505341a1..c57101ebb 100644 --- a/examples/chapter11_07/src/os/FreeRTOS/Source/timers.c +++ b/examples/chapter11_07/src/os/FreeRTOS/Source/timers.c @@ -24,19 +24,19 @@ * */ -/* Standard includes. */ -#include - /* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining * all the API functions to use the MPU wrappers. That should only be done when * task.h is included from an application file. */ #define MPU_WRAPPERS_INCLUDED_FROM_API_FILE #include -#include #include +#include #include +/* Standard includes. */ +#include + #if ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 0 ) #error configUSE_TIMERS must be set to 1 to make the xTimerPendFunctionCall() function available. #endif diff --git a/examples/chapter11_07/src/os/os_task.h b/examples/chapter11_07/src/os/os_task.h index 1508b6945..5c454297e 100644 --- a/examples/chapter11_07/src/os/os_task.h +++ b/examples/chapter11_07/src/os/os_task.h @@ -1,12 +1,12 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2020 2021. +// Copyright Christopher Kormanyos 2020 - 2024. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) // -#ifndef OS_TASK_2020_10_08_H_ - #define OS_TASK_2020_10_08_H_ +#ifndef OS_TASK_2020_10_08_H + #define OS_TASK_2020_10_08_H #include #include @@ -30,4 +30,4 @@ #define OS_TASK_WAIT_YIELD(x) vTaskDelay((x)) -#endif // OS_TASK_2020_10_08_H_ +#endif // OS_TASK_2020_10_08_H diff --git a/examples/chapter11_07/target/micros/avr/startup/int_vect.cpp b/examples/chapter11_07/target/micros/avr/startup/int_vect.cpp index d1aa12b9e..34eefabfb 100644 --- a/examples/chapter11_07/target/micros/avr/startup/int_vect.cpp +++ b/examples/chapter11_07/target/micros/avr/startup/int_vect.cpp @@ -14,7 +14,7 @@ extern "C" void __my_startup () __attribute__((section(".startup"), used, noinline)); extern "C" void __vector_unused_irq() __attribute__((signal, used, externally_visible)); -#if (defined(configUSE_PREEMPTION) && (configUSE_PREEMPTION == 1)) +#if (configUSE_PREEMPTION == 1) extern "C" void __vector_11 () __attribute__((signal, used, externally_visible, naked)); #else extern "C" void __vector_11 () __attribute__((signal, used, externally_visible)); @@ -22,15 +22,9 @@ extern "C" void __vector_11 () __attribute__((signal, used, externally_vi extern "C" void __vector_16 () __attribute__((signal, used, externally_visible)); extern "C" -void __vector_unused_irq() -{ - for(;;) - { - mcal::cpu::nop(); - } -} +void __vector_unused_irq() { for(;;) { mcal::cpu::nop(); } } -namespace +namespace local { typedef struct isr_type { @@ -40,13 +34,13 @@ namespace const function_type func; // The interrupt service routine. } isr_type; -} +} // namespace local extern "C" -const volatile std::array __isr_vector __attribute__((section(".isr_vector"))); +const volatile std::array __isr_vector __attribute__((section(".isr_vector"))); extern "C" -const volatile std::array __isr_vector = +const volatile std::array __isr_vector = {{ // addr. nr. interrupt source { { 0x0C, 0x94 }, __my_startup }, // 0x00, 0, reset