Skip to content

Commit

Permalink
update to 11.1.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
feilipu committed Apr 22, 2024
1 parent 5bcf511 commit ee52d8a
Show file tree
Hide file tree
Showing 28 changed files with 2,061 additions and 1,715 deletions.
4 changes: 2 additions & 2 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name=FreeRTOS
version=11.0.1-5
version=11.1.0-0
author=Richard Barry <[email protected]>
maintainer=Phillip Stevens <[email protected]>
sentence=FreeRTOS Real Time Operating System implemented for AVR (Uno, Nano, Leonardo, Mega).
sentence=FreeRTOS Real Time Operating System implemented for Arduino Uno R3, Nano, Leonardo, Mega, and related Microchip ATmega devices.
paragraph=The primary design goals are: Easy to use, Small footprint, Robust. Uses Watchdog Timer for 15ms resolution. Slow blink = stack overflow. Fast blink = heap malloc() failure.
category=Timing
url=https://github.com/feilipu/Arduino_FreeRTOS_Library
Expand Down
14 changes: 7 additions & 7 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
This is a fork of Richard Barry's freeRTOS, optimised for the Arduino AVR devices.
This is a fork of Richard Barry's FreeRTOS, optimised for the Arduino Microchip ATmega devices.

It has been created to provide access to FreeRTOS capabilities, with full compatibility to the Arduino IDE environment.
It does this by keeping hands off almost everything, and only touching the minimum of hardware to be successful.

If you want to use FreeRTOS on the Renesas family of Arduino like the Arduino UNO R4, it is [already included](https://github.com/arduino/ArduinoCore-renesas/tree/main/libraries/Arduino_FreeRTOS). All that is required is to include the header file `Arduino_FreeRTOS.h` provided by the Arduino IDE, as follow the information noted below.
If you want to use FreeRTOS on the Renesas family of Arduino like the Arduino UNO R4, it is [already included](https://github.com/arduino/ArduinoCore-renesas/tree/main/libraries/Arduino_FreeRTOS) in the default Arduino IDE. All that is required is to include the header file `Arduino_FreeRTOS.h` provided by the Arduino IDE, as follow the information noted below.

## Usage & Further Reading

Expand All @@ -15,22 +15,22 @@ My other [AVRfreeRTOS Sourceforge Repository](https://sourceforge.net/projects/a

This library was the genesis of [generalised support for the ATmega platform within FreeRTOS](https://github.com/FreeRTOS/FreeRTOS-Kernel/pull/48), and improvement of the [stack depth type management](https://github.com/FreeRTOS/FreeRTOS-Kernel/pull/942).

Over the past few years freeRTOS development has become increasingly 32-bit orientated, now including symmetric multiprocessing, with little change or improvement for the 8-bit world. As such I'm treating this FreeRTOS V11.0.1 (updated January 23 2024) as my LTS release.
Over the past few years FreeRTOS development has become increasingly 32-bit orientated, now including symmetric multiprocessing, with little change or improvement for the 8-bit world. As such I'm treating this FreeRTOS V11.1.0 (updated April 22 2024) as my LTS release.

## General

FreeRTOS has a multitude of configuration options, which can be specified from within the FreeRTOSConfig.h file.
To keep commonality with all of the Arduino hardware options, some sensible defaults have been selected. Feel free to change these defaults as you gain experience with FreeRTOS.

Normally, the AVR Watchdog Timer is used to generate 15ms time slices (Ticks). For applications requiring high precision timing, the Ticks can be sourced from a hardware timer or external clock. See chapter [Scheduler Tick Sources](./doc/tick_sources.md) for the configuration details.
Normally, the ATmega Watchdog Timer is used to generate 15ms time slices (Ticks). For applications requiring high precision timing, the Ticks can be sourced from a hardware timer or external clock. See chapter [Scheduler Tick Sources](./doc/tick_sources.md) for the configuration details.

Tasks that suspend or delay before their allocated time slice completes will revert execution back to the Scheduler.

The Arduino `delay()` function has been redefined to automatically use the FreeRTOS `vTaskDelay()` function when the delay required is one Tick or longer, by setting `configUSE_PORT_DELAY` to `1`, so that simple Arduino example sketches and tutorials work as expected. If you would like to measure a short millisecond delay of less than one Tick, then preferably use [`millis()`](https://www.arduino.cc/reference/en/language/functions/time/millis/) (or with greater granularity use [`micros()`](https://www.arduino.cc/reference/en/language/functions/time/micros/)) to achieve this outcome (for example see [BlinkWithoutDelay](https://docs.arduino.cc/built-in-examples/digital/BlinkWithoutDelay)). However, when the delay requested is less than one Tick then the original Arduino `delay()` function will be automatically selected.

The 8-bit AVR Timer0 has been added as an option for the experienced user. Please examine the Timer0 source code example to figure out how to use it. Reconfiguring Timer0 for the FreeRTOS Tick will break Arduino `millis()` and `micros()` though, as these functions rely on Timer0. Example support for the Logic Green hardware using Timer 3 is provided via an open PR.
The 8-bit ATmega Timer0 has been added as an option for the experienced user. Please examine the Timer0 source code example to figure out how to use it. Reconfiguring Timer0 for the FreeRTOS Tick will break Arduino `millis()` and `micros()` though, as these functions rely on the Arduino IDE configuring Timer0. Example support for the Logic Green hardware using Timer 3 is provided via an open PR.

Stack for the `loop()` function has been set at 192 Bytes. This can be configured by adjusting the `configMINIMAL_STACK_SIZE` parameter. If you have stack overflow issues just increase it (within the SRAM limitations of your hardware). Users should prefer to allocate larger structures, arrays, or buffers using `pvPortMalloc()`, rather than defining them locally on the stack. Ideally you should __not__ use `loop()` for your sketches, and then the Idle Task stack size can be reduced down to 85 Bytes which will save some valuable memory.
Stack for the `loop()` function has been set at 192 Bytes. This can be configured by adjusting the `configMINIMAL_STACK_SIZE` parameter. If you have stack overflow issues just increase it (within the SRAM limitations of your hardware). Users should prefer to allocate larger structures, arrays, or buffers on the heap using `pvPortMalloc()`, rather than defining them locally on the stack. Ideally you should __not__ use `loop()` for your sketches, and then the Idle Task stack size can be reduced down to 92 Bytes which will save some valuable memory.

Memory for the heap is allocated by the normal C `malloc()` function, wrapped by the FreeRTOS `pvPortMalloc()` function. This option has been selected because it is automatically adjusted to use the capabilities of each device. Other heap allocation schemes are supported by FreeRTOS, and they can used with some additional configuration.

Expand Down Expand Up @@ -73,7 +73,7 @@ The Arduino IDE supporting the Arduino UNO R4 already includes FreeRTOS as stand

* `Arduino_FreeRTOS.h` : Must always be `#include` first. It references other configuration files, and sets defaults where necessary.
* `FreeRTOSConfig.h` : Contains a multitude of API and environment configurations.
* `FreeRTOSVariant.h` : Contains the AVR specific configurations for this port of freeRTOS.
* `FreeRTOSVariant.h` : Contains the ATmega specific configurations for this port of FreeRTOS.
* `heap_3.c` : Contains the heap allocation scheme based on `malloc()`. Other schemes are available, but depend on user configuration for specific MCU choice.

### PlatformIO
Expand Down
69 changes: 50 additions & 19 deletions src/Arduino_FreeRTOS.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* FreeRTOS Kernel V11.0.1
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* FreeRTOS Kernel V11.1.0
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
Expand Down Expand Up @@ -96,6 +96,10 @@
#define configNUMBER_OF_CORES 1
#endif

#ifndef configUSE_MALLOC_FAILED_HOOK
#define configUSE_MALLOC_FAILED_HOOK 0
#endif

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

Expand Down Expand Up @@ -284,10 +288,6 @@
#warning Co-routines have been removed from FreeRTOS-Kernel versions released after V10.5.1. You can view previous versions of the FreeRTOS Kernel at github.com/freertos/freertos-kernel/tree/V10.5.1.
#endif

#ifndef configUSE_DAEMON_TASK_STARTUP_HOOK
#define configUSE_DAEMON_TASK_STARTUP_HOOK 0
#endif

#ifndef configUSE_APPLICATION_TASK_TAG
#define configUSE_APPLICATION_TASK_TAG 0
#endif
Expand All @@ -308,6 +308,24 @@
#define configUSE_TIMERS 0
#endif

#ifndef configUSE_EVENT_GROUPS
#define configUSE_EVENT_GROUPS 1
#endif

#ifndef configUSE_STREAM_BUFFERS
#define configUSE_STREAM_BUFFERS 1
#endif

#ifndef configUSE_DAEMON_TASK_STARTUP_HOOK
#define configUSE_DAEMON_TASK_STARTUP_HOOK 0
#endif

#if ( configUSE_DAEMON_TASK_STARTUP_HOOK != 0 )
#if ( configUSE_TIMERS == 0 )
#error configUSE_DAEMON_TASK_STARTUP_HOOK is set, but the daemon task is not created because configUSE_TIMERS is 0.
#endif
#endif

#ifndef configUSE_COUNTING_SEMAPHORES
#define configUSE_COUNTING_SEMAPHORES 0
#endif
Expand Down Expand Up @@ -474,6 +492,12 @@
#define configUSE_CORE_AFFINITY 0
#endif /* configUSE_CORE_AFFINITY */

#if ( ( configNUMBER_OF_CORES > 1 ) && ( configUSE_CORE_AFFINITY == 1 ) )
#ifndef configTASK_DEFAULT_CORE_AFFINITY
#define configTASK_DEFAULT_CORE_AFFINITY tskNO_AFFINITY
#endif
#endif

#ifndef configUSE_PASSIVE_IDLE_HOOK
#define configUSE_PASSIVE_IDLE_HOOK 0
#endif /* configUSE_PASSIVE_IDLE_HOOK */
Expand Down Expand Up @@ -948,15 +972,15 @@
#endif

#ifndef traceSTREAM_BUFFER_CREATE_FAILED
#define traceSTREAM_BUFFER_CREATE_FAILED( xIsMessageBuffer )
#define traceSTREAM_BUFFER_CREATE_FAILED( xStreamBufferType )
#endif

#ifndef traceSTREAM_BUFFER_CREATE_STATIC_FAILED
#define traceSTREAM_BUFFER_CREATE_STATIC_FAILED( xReturn, xIsMessageBuffer )
#define traceSTREAM_BUFFER_CREATE_STATIC_FAILED( xReturn, xStreamBufferType )
#endif

#ifndef traceSTREAM_BUFFER_CREATE
#define traceSTREAM_BUFFER_CREATE( pxStreamBuffer, xIsMessageBuffer )
#define traceSTREAM_BUFFER_CREATE( pxStreamBuffer, xStreamBufferType )
#endif

#ifndef traceSTREAM_BUFFER_DELETE
Expand All @@ -967,6 +991,10 @@
#define traceSTREAM_BUFFER_RESET( xStreamBuffer )
#endif

#ifndef traceSTREAM_BUFFER_RESET_FROM_ISR
#define traceSTREAM_BUFFER_RESET_FROM_ISR( xStreamBuffer )
#endif

#ifndef traceBLOCKING_ON_STREAM_BUFFER_SEND
#define traceBLOCKING_ON_STREAM_BUFFER_SEND( xStreamBuffer )
#endif
Expand Down Expand Up @@ -2364,15 +2392,15 @@
#endif

#ifndef traceENTER_xStreamBufferGenericCreate
#define traceENTER_xStreamBufferGenericCreate( xBufferSizeBytes, xTriggerLevelBytes, xIsMessageBuffer, pxSendCompletedCallback, pxReceiveCompletedCallback )
#define traceENTER_xStreamBufferGenericCreate( xBufferSizeBytes, xTriggerLevelBytes, xStreamBufferType, pxSendCompletedCallback, pxReceiveCompletedCallback )
#endif

#ifndef traceRETURN_xStreamBufferGenericCreate
#define traceRETURN_xStreamBufferGenericCreate( pvAllocatedMemory )
#endif

#ifndef traceENTER_xStreamBufferGenericCreateStatic
#define traceENTER_xStreamBufferGenericCreateStatic( xBufferSizeBytes, xTriggerLevelBytes, xIsMessageBuffer, pucStreamBufferStorageArea, pxStaticStreamBuffer, pxSendCompletedCallback, pxReceiveCompletedCallback )
#define traceENTER_xStreamBufferGenericCreateStatic( xBufferSizeBytes, xTriggerLevelBytes, xStreamBufferType, pucStreamBufferStorageArea, pxStaticStreamBuffer, pxSendCompletedCallback, pxReceiveCompletedCallback )
#endif

#ifndef traceRETURN_xStreamBufferGenericCreateStatic
Expand Down Expand Up @@ -2403,6 +2431,14 @@
#define traceRETURN_xStreamBufferReset( xReturn )
#endif

#ifndef traceENTER_xStreamBufferResetFromISR
#define traceENTER_xStreamBufferResetFromISR( xStreamBuffer )
#endif

#ifndef traceRETURN_xStreamBufferResetFromISR
#define traceRETURN_xStreamBufferResetFromISR( xReturn )
#endif

#ifndef traceENTER_xStreamBufferSetTriggerLevel
#define traceENTER_xStreamBufferSetTriggerLevel( xStreamBuffer, xTriggerLevel )
#endif
Expand Down Expand Up @@ -2633,10 +2669,6 @@
#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS()
#endif

#ifndef configUSE_MALLOC_FAILED_HOOK
#define configUSE_MALLOC_FAILED_HOOK 0
#endif

#ifndef portPRIVILEGE_BIT
#define portPRIVILEGE_BIT ( ( UBaseType_t ) 0x00 )
#endif
Expand Down Expand Up @@ -2789,9 +2821,9 @@

#ifndef configSTACK_DEPTH_TYPE

/* Defaults to uint16_t for backward compatibility, but can be overridden
* in FreeRTOSConfig.h if uint16_t is too restrictive. */
#define configSTACK_DEPTH_TYPE uint16_t
/* Defaults to StackType_t for backward compatibility, but can be overridden
* in FreeRTOSConfig.h if StackType_t is too restrictive. */
#define configSTACK_DEPTH_TYPE StackType_t
#endif

#ifndef configRUN_TIME_COUNTER_TYPE
Expand Down Expand Up @@ -3292,4 +3324,3 @@ typedef StaticStreamBuffer_t StaticMessageBuffer_t;
#include "FreeRTOSVariant.h"

#endif /* INC_ARDUINO_FREERTOS_H */

76 changes: 41 additions & 35 deletions src/FreeRTOSConfig.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* FreeRTOS Kernel V11.0.1
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* FreeRTOS Kernel V11.1.0
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
Expand Down Expand Up @@ -41,67 +41,73 @@
* FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE.
*
* See https://www.freertos.org/a00110.html.
*----------------------------------------------------------*/

/* Delay definition - here, the user can choose which delay implementation is required.
* The default is to change nothing. */
#define configUSE_PORT_DELAY 1

/* And on to the things the same no matter the AVR type... */
#define configUSE_PREEMPTION 1

#define configCPU_CLOCK_HZ ( ( uint32_t ) F_CPU ) // This F_CPU variable set by the environment
#define configTICK_TYPE_WIDTH_IN_BITS TICK_TYPE_WIDTH_16_BITS

#define configMAX_PRIORITIES 4
#define configIDLE_SHOULD_YIELD 1
#define configMINIMAL_STACK_SIZE ( 192 )
#define configMAX_TASK_NAME_LEN ( 8 )
#define configMAX_TASK_NAME_LEN 16

#define configQUEUE_REGISTRY_SIZE 0
#define configCHECK_FOR_STACK_OVERFLOW 1
/* Set the stack depth type to be uint16_t, otherwise it defaults to StackType_t */
#define configSTACK_DEPTH_TYPE uint16_t

#define configMINIMAL_STACK_SIZE 192
#define configCHECK_FOR_STACK_OVERFLOW 0
#define configUSE_TRACE_FACILITY 0
#define configTICK_TYPE_WIDTH_IN_BITS TICK_TYPE_WIDTH_16_BITS

#define configUSE_MUTEXES 1
#define configUSE_RECURSIVE_MUTEXES 1
#define configUSE_COUNTING_SEMAPHORES 1
#define configUSE_TIME_SLICING 1
#define configUSE_QUEUE_SETS 0
#define configUSE_MALLOC_FAILED_HOOK 1

#define configUSE_QUEUE_SETS 0
#define configUSE_APPLICATION_TASK_TAG 0
#define configUSE_MALLOC_FAILED_HOOK 0
#define configQUEUE_REGISTRY_SIZE 0
#define configSUPPORT_DYNAMIC_ALLOCATION 1
#define configSUPPORT_STATIC_ALLOCATION 0

#define configUSE_IDLE_HOOK 1
#define configIDLE_SHOULD_YIELD 1
#define configUSE_TICK_HOOK 0

/* Delay definition - here, the user can choose which delay implementation is required.
* The default is to change nothing. */
#define configUSE_PORT_DELAY 1

/* Timer definitions. */
#define configUSE_TIMERS 1
#define configTIMER_TASK_PRIORITY configMAX_PRIORITIES-1
#define configTIMER_QUEUE_LENGTH ( 10 )
#define configTIMER_TASK_STACK_DEPTH ( 85 )

/* Set the stack depth type to be uint16_t, otherwise it defaults to StackType_t */
#define configSTACK_DEPTH_TYPE uint16_t

/* Set the stack pointer type to be uint16_t, otherwise it defaults to unsigned long */
#define portPOINTER_SIZE_TYPE uint16_t
#define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES-1 )
#define configTIMER_TASK_STACK_DEPTH 92
#define configTIMER_QUEUE_LENGTH 10

/* Set the following definitions to 1 to include the API function, or zero
to exclude the API function. */

#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 1
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskCleanUpResources 1
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_vResumeFromISR 1
#define INCLUDE_xTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
#define INCLUDE_xTaskGetSchedulerState 0
#define INCLUDE_xTaskGetIdleTaskHandle 0 // create an idle task handle.
#define INCLUDE_xTaskGetCurrentTaskHandle 1
#define INCLUDE_uxTaskGetStackHighWaterMark 1
/* Set the following INCLUDE_* constants to 1 to incldue the named API function,
* or 0 to exclude the named API function. Most linkers will remove unused
* functions even when the constant is 1. */
#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 1
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_xTaskResumeFromISR 1
#define INCLUDE_xTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
#define INCLUDE_xTaskGetSchedulerState 0
#define INCLUDE_xTaskGetCurrentTaskHandle 1
#define INCLUDE_uxTaskGetStackHighWaterMark 1
#define INCLUDE_xTaskGetIdleTaskHandle 0
#define INCLUDE_eTaskGetState 0
#define INCLUDE_xEventGroupSetBitFromISR 1
#define INCLUDE_xTimerPendFunctionCall 0
#define INCLUDE_xTaskAbortDelay 0
#define INCLUDE_xTaskGetHandle 0

#define configMAX(a,b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _a > _b ? _a : _b; })
#define configMIN(a,b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _a < _b ? _a : _b; })
Expand Down
2 changes: 1 addition & 1 deletion src/FreeRTOSVariant.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ extern "C" {
#else
#warning "Variant configuration must define `configTICK_RATE_HZ` and `portTICK_PERIOD_MS` as either a macro or a constant"
#define configTICK_RATE_HZ 1
#define portTICK_PERIOD_MS ( (TickType_t) 1000 / configTICK_RATE_HZ )
#define portTICK_PERIOD_MS ( (TickType_t) ( 1000 / configTICK_RATE_HZ ) )
#endif

/*-----------------------------------------------------------*/
Expand Down
Loading

0 comments on commit ee52d8a

Please sign in to comment.