Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve FreeRTOS syntax chapter11_07 #597

Merged
merged 1 commit into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions examples/chapter11_07/src/os/FreeRTOS/Source/event_groups.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@
*
*/

/* Standard includes. */
#include <stdlib.h>

/* 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

/* FreeRTOS includes. */
#include <FreeRTOS.h>
#include <event_groups.h>
#include <task.h>
#include <timers.h>
#include <event_groups.h>

/* Standard includes. */
#include <stdlib.h>

/* 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
Expand Down
25 changes: 4 additions & 21 deletions examples/chapter11_07/src/os/FreeRTOS/Source/include/FreeRTOS.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,8 @@
#ifndef INC_FREERTOS_H
#define INC_FREERTOS_H

/*
* Include the generic headers required for the FreeRTOS port being used.
*/
#include <stddef.h>

/*
* 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 <stdint.h> /* READ COMMENT ABOVE. */
#include <stdint.h>

/* *INDENT-OFF* */
#ifdef __cplusplus
Expand All @@ -54,13 +37,13 @@
/* *INDENT-ON* */

/* Application specific configuration options. */
#include "FreeRTOSConfig.h"
#include <FreeRTOSConfig.h>

/* Basic FreeRTOS definitions. */
#include "projdefs.h"
#include <projdefs.h>

/* Definitions specific to the port being used. */
#include "portable.h"
#include <portable.h>

/* Must be defaulted before configUSE_NEWLIB_REENTRANT is used below. */
#ifndef configUSE_NEWLIB_REENTRANT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#endif

/* FreeRTOS includes. */
#include "timers.h"
#include <timers.h>

/* *INDENT-OFF* */
#ifdef __cplusplus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <portmacro.h>
#endif

#if portBYTE_ALIGNMENT == 32
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#endif
/* *INDENT-ON* */

#include "task.h"
#include <task.h>

/**
* Type by which queues are referenced. For example, a call to xQueueCreate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#error "include FreeRTOS.h" must appear in source files before "include semphr.h"
#endif

#include "queue.h"
#include <queue.h>

typedef QueueHandle_t SemaphoreHandle_t;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#error "include FreeRTOS.h must appear in source files before include task.h"
#endif

#include "list.h"
#include <list.h>

/* *INDENT-OFF* */
#ifdef __cplusplus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <task.h>
/*lint -restore */

/* *INDENT-OFF* */
Expand Down
4 changes: 2 additions & 2 deletions examples/chapter11_07/src/os/FreeRTOS/Source/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
*/


#include <stdlib.h>

/* 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. */
Expand All @@ -35,6 +33,8 @@
#include <FreeRTOS.h>
#include <list.h>

#include <stdlib.h>

/* 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <cstdlib>

#include <FreeRTOS.h>
#include <mcal_reg.h>
#include <task.h>

#include <mcal_reg.h>
#include <cstdlib>

/*--------------------------------------------------------------------
* Implementation of functions defined in portable.h for the AVR port.
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#ifndef PORTMACRO_H
#define PORTMACRO_H

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@
* 1 tab == 4 spaces!
*/

/* Scheduler includes. */
#include <FreeRTOS.h>
#include <task.h>

/* Standard includes. */
#include <stdio.h>
#include <intrin.h>

/* Scheduler includes. */
#include "FreeRTOS.h"
#include "task.h"
#include <stdio.h>

#ifdef __GNUC__
#include "mmsystem.h"
#include <mmsystem.h>
#else
#pragma comment(lib, "winmm.lib")
#endif
Expand Down
8 changes: 4 additions & 4 deletions examples/chapter11_07/src/os/FreeRTOS/Source/queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
*
*/

#include <stdlib.h>
#include <string.h>

/* 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. */
Expand All @@ -36,6 +33,9 @@
#include <task.h>
#include <queue.h>

#include <string.h>
#include <stdlib.h>

#if ( configUSE_CO_ROUTINES == 1 )
#include "croutine.h"
#endif
Expand Down Expand Up @@ -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. */
Expand Down
10 changes: 5 additions & 5 deletions examples/chapter11_07/src/os/FreeRTOS/Source/tasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@
*
*/

/* Standard includes. */
#include <stdlib.h>
#include <string.h>

/* 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

/* FreeRTOS includes. */
#include <FreeRTOS.h>
#include <stack_macros.h>
#include <task.h>
#include <timers.h>
#include <stack_macros.h>

/* Standard includes. */
#include <string.h>
#include <stdlib.h>

/* 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
Expand Down
8 changes: 4 additions & 4 deletions examples/chapter11_07/src/os/FreeRTOS/Source/timers.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@
*
*/

/* Standard includes. */
#include <stdlib.h>

/* 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 <FreeRTOS.h>
#include <task.h>
#include <queue.h>
#include <task.h>
#include <timers.h>

/* Standard includes. */
#include <stdlib.h>

#if ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 0 )
#error configUSE_TIMERS must be set to 1 to make the xTimerPendFunctionCall() function available.
#endif
Expand Down
8 changes: 4 additions & 4 deletions examples/chapter11_07/src/os/os_task.h
Original file line number Diff line number Diff line change
@@ -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 <FreeRTOS.h>
#include <task.h>
Expand All @@ -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
18 changes: 6 additions & 12 deletions examples/chapter11_07/target/micros/avr/startup/int_vect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,17 @@

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));
#endif
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
{
Expand All @@ -40,13 +34,13 @@ namespace
const function_type func; // The interrupt service routine.
}
isr_type;
}
} // namespace local

extern "C"
const volatile std::array<isr_type, std::size_t { UINT8_C(26) }> __isr_vector __attribute__((section(".isr_vector")));
const volatile std::array<local::isr_type, std::size_t { UINT8_C(26) }> __isr_vector __attribute__((section(".isr_vector")));

extern "C"
const volatile std::array<isr_type, std::size_t { UINT8_C(26) }> __isr_vector =
const volatile std::array<local::isr_type, std::size_t { UINT8_C(26) }> __isr_vector =
{{
// addr. nr. interrupt source
{ { 0x0C, 0x94 }, __my_startup }, // 0x00, 0, reset
Expand Down
Loading