RobertBerger

Untitled

Nov 4th, 2025
939
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.63 KB | None | 0 0
  1. /*
  2.     FreeRTOS V6.0.0 - Copyright (C) 2009 Real Time Engineers Ltd.
  3.  
  4.     This file is part of the FreeRTOS distribution.
  5.  
  6.     FreeRTOS is free software; you can redistribute it and/or modify it under
  7.     the terms of the GNU General Public License (version 2) as published by the
  8.     Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
  9.     ***NOTE*** The exception to the GPL is included to allow you to distribute
  10.     a combined work that includes FreeRTOS without being obliged to provide the
  11.     source code for proprietary components outside of the FreeRTOS kernel.
  12.     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
  13.     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14.     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  15.     more details. You should have received a copy of the GNU General Public
  16.     License and the FreeRTOS license exception along with FreeRTOS; if not it
  17.     can be viewed here: http://www.freertos.org/a00114.html and also obtained
  18.     by writing to Richard Barry, contact details for whom are available on the
  19.     FreeRTOS WEB site.
  20.  
  21.     1 tab == 4 spaces!
  22.  
  23.     http://www.FreeRTOS.org - Documentation, latest information, license and
  24.     contact details.
  25.  
  26.     http://www.SafeRTOS.com - A version that is certified for use in safety
  27.     critical systems.
  28.  
  29.     http://www.OpenRTOS.com - Commercial support, development, porting,
  30.     licensing and training services.
  31. */
  32.  
  33. /* FreeRTOS.org includes. */
  34. #include "FreeRTOS.h"
  35. #include "task.h"
  36. #include <stdatomic.h>
  37.  
  38. /* Demo includes. */
  39. #include "basic_io.h"
  40.  
  41. /* The task function. */
  42. void vTaskFunction( void *pvParameters );
  43.  
  44. /* A variable that is incremented by the idle task hook function. */
  45. /* default: 1 */
  46. #if 1
  47.   /* non atomic - default */
  48.   static unsigned long ulIdleCycleCount = 0UL;
  49.   int GlobalVar;
  50. #else
  51.   /* atomic */
  52.   static atomic_ulong ulIdleCycleCount = 0UL;
  53.   atomic_int GlobalVar;
  54. #endif
  55.  
  56. /* Define the strings that will be passed in as the task parameters.  These are
  57. defined const and off the stack to ensure they remain valid when the tasks are
  58. executing. */
  59. const char *pcTextForTask1 = "Task 1 is running, ulIdleCycleCount = ";
  60. const char *pcTextForTask2 = "Task 2 is running, ulIdleCycleCount = ";
  61.  
  62. /*-----------------------------------------------------------*/
  63.  
  64. int main( void )
  65. {
  66.     GlobalVar |= 0x01;
  67.     /* Create the first task at priority 1... */
  68.     xTaskCreate( vTaskFunction, "Task 1", 240, (void*)pcTextForTask1, 1, NULL );
  69.  
  70.     /* ... and the second task at priority 2.  The priority is the second to
  71.     last parameter. */
  72.     xTaskCreate( vTaskFunction, "Task 2", 240, (void*)pcTextForTask2, 2, NULL );
  73.  
  74.     /* Start the scheduler so our tasks start executing. */
  75.     vTaskStartScheduler();
  76.  
  77.     for( ;; );
  78.     return 0;
  79. }
  80. /*-----------------------------------------------------------*/
  81.  
  82. void vTaskFunction( void *pvParameters )
  83. {
  84. char *pcTaskName;
  85.  
  86.     /* The string to print out is passed in via the parameter.  Cast this to a
  87.     character pointer. */
  88.     pcTaskName = ( char * ) pvParameters;
  89.  
  90.     /* As per most tasks, this task is implemented in an infinite loop. */
  91.     for( ;; )
  92.     {
  93.         /* Print out the name of this task AND the number of times ulIdleCycleCount
  94.         has been incremented. */
  95.         vPrintStringAndNumber( pcTaskName, ulIdleCycleCount );
  96.  
  97.         /* Delay for a period.  This time we use a call to vTaskDelay() which
  98.         puts the task into the Blocked state until the delay period has expired.
  99.         The delay period is specified in 'ticks'. */
  100.         vTaskDelay( 250 / portTICK_RATE_MS );
  101.     }
  102. }
  103. /*-----------------------------------------------------------*/
  104.  
  105. /* Idle hook functions MUST be called vApplicationIdleHook(), take no parameters,
  106. and return void. */
  107. void vApplicationIdleHook( void )
  108. {
  109.     /* This hook function does nothing but increment a counter. */
  110.     ulIdleCycleCount++;
  111. }
  112. /*-----------------------------------------------------------*/
  113.  
  114. void vApplicationMallocFailedHook( void )
  115. {
  116.     /* This function will only be called if an API call to create a task, queue
  117.     or semaphore fails because there is too little heap RAM remaining. */
  118.     for( ;; );
  119. }
  120. /*-----------------------------------------------------------*/
  121.  
  122. void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
  123. {
  124.     /* This function will only be called if a task overflows its stack.  Note
  125.     that stack overflow checking does slow down the context switch
  126.     implementation. */
  127.     for( ;; );
  128. }
  129. /*-----------------------------------------------------------*/
  130.  
  131. void vApplicationTickHook( void )
  132. {
  133.     /* This example does not use the tick hook to perform any processing. */
  134. }
  135.  
  136.  
Tags: atomic-1
Advertisement
Comments
  • wmgubuw
    2 days
    # text 0.12 KB | 0 0
    1. ⭐Make 3000$ with Swapzone Exchange Method
    2.  
    3. >>> docs.google.com/document/d/1IB4SkLZdU8hex0Kn-GyFHXSSV6kLUXhhOhxPwmEuuc4
Add Comment
Please, Sign In to add comment