/*---------------------------------------------------------------------------- * CMSIS-RTOS - RTX *---------------------------------------------------------------------------- * Name: RTX_Conf_CM.C * Purpose: Configuration of CMSIS RTX Kernel for Cortex-M * Rev.: V4.70.1 *---------------------------------------------------------------------------- * * Copyright (c) 1999-2009 KEIL, 2009-2016 ARM Germany GmbH. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *---------------------------------------------------------------------------*/ #include "cmsis_os.h" /*---------------------------------------------------------------------------- * RTX User configuration part BEGIN *---------------------------------------------------------------------------*/ //-------- <<< Use Configuration Wizard in Context Menu >>> ----------------- // // Thread Configuration // ======================= // // Number of concurrent running user threads <1-250> // Defines max. number of user threads that will run at the same time. // Default: 6 #ifndef OS_TASKCNT #define OS_TASKCNT 6 #endif // Default Thread stack size [bytes] <64-4096:8><#/4> // Defines default stack size for threads with osThreadDef stacksz = 0 // Default: 200 #ifndef OS_STKSIZE #define OS_STKSIZE 50 // this stack size value is in words #endif // Main Thread stack size [bytes] <64-32768:8><#/4> // Defines stack size for main thread. // Default: 200 #ifndef OS_MAINSTKSIZE #define OS_MAINSTKSIZE 256 // this stack size value is in words #endif // Number of threads with user-provided stack size <0-250> // Defines the number of threads with user-provided stack size. // Default: 0 #ifndef OS_PRIVCNT #define OS_PRIVCNT 1 #endif // Total stack size [bytes] for threads with user-provided stack size <0-1048576:8><#/4> // Defines the combined stack size for threads with user-provided stack size. // Default: 0 #ifndef OS_PRIVSTKSIZE #define OS_PRIVSTKSIZE 16384 // this stack size value is in words #endif // Stack overflow checking // Enable stack overflow checks at thread switch. // Enabling this option increases slightly the execution time of a thread switch. #ifndef OS_STKCHECK #define OS_STKCHECK 1 #endif // Stack usage watermark // Initialize thread stack with watermark pattern for analyzing stack usage (current/maximum) in System and Thread Viewer. // Enabling this option increases significantly the execution time of osThreadCreate. #ifndef OS_STKINIT #define OS_STKINIT 0 #endif // Processor mode for thread execution // <0=> Unprivileged mode // <1=> Privileged mode // Default: Privileged mode #ifndef OS_RUNPRIV #define OS_RUNPRIV 1 #endif // // RTX Kernel Timer Tick Configuration // ====================================== // Use Cortex-M SysTick timer as RTX Kernel Timer // Cortex-M processors provide in most cases a SysTick timer that can be used as // as time-base for RTX. #ifndef OS_SYSTICK #define OS_SYSTICK 1 #endif // // RTOS Kernel Timer input clock frequency [Hz] <1-1000000000> // Defines the input frequency of the RTOS Kernel Timer. // When the Cortex-M SysTick timer is used, the input clock // is on most systems identical with the core clock. #ifndef OS_CLOCK #define OS_CLOCK 216000000 #endif // RTX Timer tick interval value [us] <1-1000000> // The RTX Timer tick interval value is used to calculate timeout values. // When the Cortex-M SysTick timer is enabled, the value also configures the SysTick timer. // Default: 1000 (1ms) #ifndef OS_TICK #define OS_TICK 1000 #endif // // System Configuration // ======================= // // Round-Robin Thread switching // =============================== // // Enables Round-Robin Thread switching. #ifndef OS_ROBIN #define OS_ROBIN 1 #endif // Round-Robin Timeout [ticks] <1-1000> // Defines how long a thread will execute before a thread switch. // Default: 5 #ifndef OS_ROBINTOUT #define OS_ROBINTOUT 5 #endif // // User Timers // ============== // Enables user Timers #ifndef OS_TIMERS #define OS_TIMERS 0 #endif // Timer Thread Priority // <1=> Low // <2=> Below Normal <3=> Normal <4=> Above Normal // <5=> High // <6=> Realtime (highest) // Defines priority for Timer Thread // Default: High #ifndef OS_TIMERPRIO #define OS_TIMERPRIO 5 #endif // Timer Thread stack size [bytes] <64-4096:8><#/4> // Defines stack size for Timer thread. // Default: 200 #ifndef OS_TIMERSTKSZ #define OS_TIMERSTKSZ 50 // this stack size value is in words #endif // Timer Callback Queue size <1-32> // Number of concurrent active timer callback functions. // Default: 4 #ifndef OS_TIMERCBQS #define OS_TIMERCBQS 4 #endif // // ISR FIFO Queue size<4=> 4 entries <8=> 8 entries // <12=> 12 entries <16=> 16 entries // <24=> 24 entries <32=> 32 entries // <48=> 48 entries <64=> 64 entries // <96=> 96 entries // ISR functions store requests to this buffer, // when they are called from the interrupt handler. // Default: 16 entries #ifndef OS_FIFOSZ #define OS_FIFOSZ 16 #endif // //------------- <<< end of configuration section >>> ----------------------- // Standard library system mutexes // =============================== // Define max. number system mutexes that are used to protect // the arm standard runtime library. For microlib they are not used. #ifndef OS_MUTEXCNT #define OS_MUTEXCNT 8 #endif /*---------------------------------------------------------------------------- * RTX User configuration part END *---------------------------------------------------------------------------*/ #define OS_TRV ((uint32_t)(((double)OS_CLOCK*(double)OS_TICK)/1E6)-1) /*---------------------------------------------------------------------------- * Global Functions *---------------------------------------------------------------------------*/ /*--------------------------- os_idle_demon ---------------------------------*/ /// \brief The idle demon is running when no other thread is ready to run void os_idle_demon (void) { for (;;) { /* HERE: include optional user code to be executed when no thread runs.*/ } } #if (OS_SYSTICK == 0) // Functions for alternative timer as RTX kernel timer /*--------------------------- os_tick_init ----------------------------------*/ /// \brief Initializes an alternative hardware timer as RTX kernel timer /// \return IRQ number of the alternative hardware timer int os_tick_init (void) { return (-1); /* Return IRQ number of timer (0..239) */ } /*--------------------------- os_tick_val -----------------------------------*/ /// \brief Get alternative hardware timer's current value (0 .. OS_TRV) /// \return Current value of the alternative hardware timer uint32_t os_tick_val (void) { return (0); } /*--------------------------- os_tick_ovf -----------------------------------*/ /// \brief Get alternative hardware timer's overflow flag /// \return Overflow flag\n /// - 1 : overflow /// - 0 : no overflow uint32_t os_tick_ovf (void) { return (0); } /*--------------------------- os_tick_irqack --------------------------------*/ /// \brief Acknowledge alternative hardware timer interrupt void os_tick_irqack (void) { /* ... */ } #endif // (OS_SYSTICK == 0) /*--------------------------- os_error --------------------------------------*/ /* OS Error Codes */ #define OS_ERROR_STACK_OVF 1 #define OS_ERROR_FIFO_OVF 2 #define OS_ERROR_MBX_OVF 3 #define OS_ERROR_TIMER_OVF 4 extern osThreadId svcThreadGetId (void); /// \brief Called when a runtime error is detected /// \param[in] error_code actual error code that has been detected void os_error (uint32_t error_code) { /* HERE: include optional code to be executed on runtime error. */ switch (error_code) { case OS_ERROR_STACK_OVF: /* Stack overflow detected for the currently running task. */ /* Thread can be identified by calling svcThreadGetId(). */ break; case OS_ERROR_FIFO_OVF: /* ISR FIFO Queue buffer overflow detected. */ break; case OS_ERROR_MBX_OVF: /* Mailbox overflow detected. */ break; case OS_ERROR_TIMER_OVF: /* User Timer Callback Queue overflow detected. */ break; default: break; } for (;;); } /*---------------------------------------------------------------------------- * RTX Configuration Functions *---------------------------------------------------------------------------*/ #include "RTX_CM_lib.h" /*---------------------------------------------------------------------------- * end of file *---------------------------------------------------------------------------*/