Francisco Paez / freertos

Dependents:   frdm_k64f_freertos_lib

Committer:
fep
Date:
Wed May 31 02:27:10 2017 +0000
Revision:
0:62cd296ba2a7
FreeRTOS v9.0.0 for Cortex-M4F (FRDM-K64F and others...)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
fep 0:62cd296ba2a7 1 /*
fep 0:62cd296ba2a7 2 FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd.
fep 0:62cd296ba2a7 3 All rights reserved
fep 0:62cd296ba2a7 4
fep 0:62cd296ba2a7 5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
fep 0:62cd296ba2a7 6
fep 0:62cd296ba2a7 7 This file is part of the FreeRTOS distribution.
fep 0:62cd296ba2a7 8
fep 0:62cd296ba2a7 9 FreeRTOS is free software; you can redistribute it and/or modify it under
fep 0:62cd296ba2a7 10 the terms of the GNU General Public License (version 2) as published by the
fep 0:62cd296ba2a7 11 Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
fep 0:62cd296ba2a7 12
fep 0:62cd296ba2a7 13 ***************************************************************************
fep 0:62cd296ba2a7 14 >>! NOTE: The modification to the GPL is included to allow you to !<<
fep 0:62cd296ba2a7 15 >>! distribute a combined work that includes FreeRTOS without being !<<
fep 0:62cd296ba2a7 16 >>! obliged to provide the source code for proprietary components !<<
fep 0:62cd296ba2a7 17 >>! outside of the FreeRTOS kernel. !<<
fep 0:62cd296ba2a7 18 ***************************************************************************
fep 0:62cd296ba2a7 19
fep 0:62cd296ba2a7 20 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
fep 0:62cd296ba2a7 21 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
fep 0:62cd296ba2a7 22 FOR A PARTICULAR PURPOSE. Full license text is available on the following
fep 0:62cd296ba2a7 23 link: http://www.freertos.org/a00114.html
fep 0:62cd296ba2a7 24
fep 0:62cd296ba2a7 25 ***************************************************************************
fep 0:62cd296ba2a7 26 * *
fep 0:62cd296ba2a7 27 * FreeRTOS provides completely free yet professionally developed, *
fep 0:62cd296ba2a7 28 * robust, strictly quality controlled, supported, and cross *
fep 0:62cd296ba2a7 29 * platform software that is more than just the market leader, it *
fep 0:62cd296ba2a7 30 * is the industry's de facto standard. *
fep 0:62cd296ba2a7 31 * *
fep 0:62cd296ba2a7 32 * Help yourself get started quickly while simultaneously helping *
fep 0:62cd296ba2a7 33 * to support the FreeRTOS project by purchasing a FreeRTOS *
fep 0:62cd296ba2a7 34 * tutorial book, reference manual, or both: *
fep 0:62cd296ba2a7 35 * http://www.FreeRTOS.org/Documentation *
fep 0:62cd296ba2a7 36 * *
fep 0:62cd296ba2a7 37 ***************************************************************************
fep 0:62cd296ba2a7 38
fep 0:62cd296ba2a7 39 http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
fep 0:62cd296ba2a7 40 the FAQ page "My application does not run, what could be wrong?". Have you
fep 0:62cd296ba2a7 41 defined configASSERT()?
fep 0:62cd296ba2a7 42
fep 0:62cd296ba2a7 43 http://www.FreeRTOS.org/support - In return for receiving this top quality
fep 0:62cd296ba2a7 44 embedded software for free we request you assist our global community by
fep 0:62cd296ba2a7 45 participating in the support forum.
fep 0:62cd296ba2a7 46
fep 0:62cd296ba2a7 47 http://www.FreeRTOS.org/training - Investing in training allows your team to
fep 0:62cd296ba2a7 48 be as productive as possible as early as possible. Now you can receive
fep 0:62cd296ba2a7 49 FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
fep 0:62cd296ba2a7 50 Ltd, and the world's leading authority on the world's leading RTOS.
fep 0:62cd296ba2a7 51
fep 0:62cd296ba2a7 52 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
fep 0:62cd296ba2a7 53 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
fep 0:62cd296ba2a7 54 compatible FAT file system, and our tiny thread aware UDP/IP stack.
fep 0:62cd296ba2a7 55
fep 0:62cd296ba2a7 56 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
fep 0:62cd296ba2a7 57 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
fep 0:62cd296ba2a7 58
fep 0:62cd296ba2a7 59 http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
fep 0:62cd296ba2a7 60 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
fep 0:62cd296ba2a7 61 licenses offer ticketed support, indemnification and commercial middleware.
fep 0:62cd296ba2a7 62
fep 0:62cd296ba2a7 63 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
fep 0:62cd296ba2a7 64 engineered and independently SIL3 certified version for use in safety and
fep 0:62cd296ba2a7 65 mission critical applications that require provable dependability.
fep 0:62cd296ba2a7 66
fep 0:62cd296ba2a7 67 1 tab == 4 spaces!
fep 0:62cd296ba2a7 68 */
fep 0:62cd296ba2a7 69
fep 0:62cd296ba2a7 70
fep 0:62cd296ba2a7 71 /*
fep 0:62cd296ba2a7 72 * The simplest possible implementation of pvPortMalloc(). Note that this
fep 0:62cd296ba2a7 73 * implementation does NOT allow allocated memory to be freed again.
fep 0:62cd296ba2a7 74 *
fep 0:62cd296ba2a7 75 * See heap_2.c, heap_3.c and heap_4.c for alternative implementations, and the
fep 0:62cd296ba2a7 76 * memory management pages of http://www.FreeRTOS.org for more information.
fep 0:62cd296ba2a7 77 */
fep 0:62cd296ba2a7 78 #include <stdlib.h>
fep 0:62cd296ba2a7 79
fep 0:62cd296ba2a7 80 /* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining
fep 0:62cd296ba2a7 81 all the API functions to use the MPU wrappers. That should only be done when
fep 0:62cd296ba2a7 82 task.h is included from an application file. */
fep 0:62cd296ba2a7 83 #define MPU_WRAPPERS_INCLUDED_FROM_API_FILE
fep 0:62cd296ba2a7 84
fep 0:62cd296ba2a7 85 #include "FreeRTOS.h"
fep 0:62cd296ba2a7 86 #include "task.h"
fep 0:62cd296ba2a7 87
fep 0:62cd296ba2a7 88 #undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE
fep 0:62cd296ba2a7 89
fep 0:62cd296ba2a7 90 #if( configSUPPORT_DYNAMIC_ALLOCATION == 0 )
fep 0:62cd296ba2a7 91 #error This file must not be used if configSUPPORT_DYNAMIC_ALLOCATION is 0
fep 0:62cd296ba2a7 92 #endif
fep 0:62cd296ba2a7 93
fep 0:62cd296ba2a7 94 /* A few bytes might be lost to byte aligning the heap start address. */
fep 0:62cd296ba2a7 95 #define configADJUSTED_HEAP_SIZE ( configTOTAL_HEAP_SIZE - portBYTE_ALIGNMENT )
fep 0:62cd296ba2a7 96
fep 0:62cd296ba2a7 97 /* Allocate the memory for the heap. */
fep 0:62cd296ba2a7 98 /* Allocate the memory for the heap. */
fep 0:62cd296ba2a7 99 #if( configAPPLICATION_ALLOCATED_HEAP == 1 )
fep 0:62cd296ba2a7 100 /* The application writer has already defined the array used for the RTOS
fep 0:62cd296ba2a7 101 heap - probably so it can be placed in a special segment or address. */
fep 0:62cd296ba2a7 102 extern uint8_t ucHeap[ configTOTAL_HEAP_SIZE ];
fep 0:62cd296ba2a7 103 #else
fep 0:62cd296ba2a7 104 static uint8_t ucHeap[ configTOTAL_HEAP_SIZE ];
fep 0:62cd296ba2a7 105 #endif /* configAPPLICATION_ALLOCATED_HEAP */
fep 0:62cd296ba2a7 106
fep 0:62cd296ba2a7 107 static size_t xNextFreeByte = ( size_t ) 0;
fep 0:62cd296ba2a7 108
fep 0:62cd296ba2a7 109 /*-----------------------------------------------------------*/
fep 0:62cd296ba2a7 110
fep 0:62cd296ba2a7 111 void *pvPortMalloc( size_t xWantedSize )
fep 0:62cd296ba2a7 112 {
fep 0:62cd296ba2a7 113 void *pvReturn = NULL;
fep 0:62cd296ba2a7 114 static uint8_t *pucAlignedHeap = NULL;
fep 0:62cd296ba2a7 115
fep 0:62cd296ba2a7 116 /* Ensure that blocks are always aligned to the required number of bytes. */
fep 0:62cd296ba2a7 117 #if( portBYTE_ALIGNMENT != 1 )
fep 0:62cd296ba2a7 118 {
fep 0:62cd296ba2a7 119 if( xWantedSize & portBYTE_ALIGNMENT_MASK )
fep 0:62cd296ba2a7 120 {
fep 0:62cd296ba2a7 121 /* Byte alignment required. */
fep 0:62cd296ba2a7 122 xWantedSize += ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) );
fep 0:62cd296ba2a7 123 }
fep 0:62cd296ba2a7 124 }
fep 0:62cd296ba2a7 125 #endif
fep 0:62cd296ba2a7 126
fep 0:62cd296ba2a7 127 vTaskSuspendAll();
fep 0:62cd296ba2a7 128 {
fep 0:62cd296ba2a7 129 if( pucAlignedHeap == NULL )
fep 0:62cd296ba2a7 130 {
fep 0:62cd296ba2a7 131 /* Ensure the heap starts on a correctly aligned boundary. */
fep 0:62cd296ba2a7 132 pucAlignedHeap = ( uint8_t * ) ( ( ( portPOINTER_SIZE_TYPE ) &ucHeap[ portBYTE_ALIGNMENT ] ) & ( ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK ) ) );
fep 0:62cd296ba2a7 133 }
fep 0:62cd296ba2a7 134
fep 0:62cd296ba2a7 135 /* Check there is enough room left for the allocation. */
fep 0:62cd296ba2a7 136 if( ( ( xNextFreeByte + xWantedSize ) < configADJUSTED_HEAP_SIZE ) &&
fep 0:62cd296ba2a7 137 ( ( xNextFreeByte + xWantedSize ) > xNextFreeByte ) )/* Check for overflow. */
fep 0:62cd296ba2a7 138 {
fep 0:62cd296ba2a7 139 /* Return the next free byte then increment the index past this
fep 0:62cd296ba2a7 140 block. */
fep 0:62cd296ba2a7 141 pvReturn = pucAlignedHeap + xNextFreeByte;
fep 0:62cd296ba2a7 142 xNextFreeByte += xWantedSize;
fep 0:62cd296ba2a7 143 }
fep 0:62cd296ba2a7 144
fep 0:62cd296ba2a7 145 traceMALLOC( pvReturn, xWantedSize );
fep 0:62cd296ba2a7 146 }
fep 0:62cd296ba2a7 147 ( void ) xTaskResumeAll();
fep 0:62cd296ba2a7 148
fep 0:62cd296ba2a7 149 #if( configUSE_MALLOC_FAILED_HOOK == 1 )
fep 0:62cd296ba2a7 150 {
fep 0:62cd296ba2a7 151 if( pvReturn == NULL )
fep 0:62cd296ba2a7 152 {
fep 0:62cd296ba2a7 153 extern void vApplicationMallocFailedHook( void );
fep 0:62cd296ba2a7 154 vApplicationMallocFailedHook();
fep 0:62cd296ba2a7 155 }
fep 0:62cd296ba2a7 156 }
fep 0:62cd296ba2a7 157 #endif
fep 0:62cd296ba2a7 158
fep 0:62cd296ba2a7 159 return pvReturn;
fep 0:62cd296ba2a7 160 }
fep 0:62cd296ba2a7 161 /*-----------------------------------------------------------*/
fep 0:62cd296ba2a7 162
fep 0:62cd296ba2a7 163 void vPortFree( void *pv )
fep 0:62cd296ba2a7 164 {
fep 0:62cd296ba2a7 165 /* Memory cannot be freed using this scheme. See heap_2.c, heap_3.c and
fep 0:62cd296ba2a7 166 heap_4.c for alternative implementations, and the memory management pages of
fep 0:62cd296ba2a7 167 http://www.FreeRTOS.org for more information. */
fep 0:62cd296ba2a7 168 ( void ) pv;
fep 0:62cd296ba2a7 169
fep 0:62cd296ba2a7 170 /* Force an assert as it is invalid to call this function. */
fep 0:62cd296ba2a7 171 configASSERT( pv == NULL );
fep 0:62cd296ba2a7 172 }
fep 0:62cd296ba2a7 173 /*-----------------------------------------------------------*/
fep 0:62cd296ba2a7 174
fep 0:62cd296ba2a7 175 void vPortInitialiseBlocks( void )
fep 0:62cd296ba2a7 176 {
fep 0:62cd296ba2a7 177 /* Only required when static memory is not cleared. */
fep 0:62cd296ba2a7 178 xNextFreeByte = ( size_t ) 0;
fep 0:62cd296ba2a7 179 }
fep 0:62cd296ba2a7 180 /*-----------------------------------------------------------*/
fep 0:62cd296ba2a7 181
fep 0:62cd296ba2a7 182 size_t xPortGetFreeHeapSize( void )
fep 0:62cd296ba2a7 183 {
fep 0:62cd296ba2a7 184 return ( configADJUSTED_HEAP_SIZE - xNextFreeByte );
fep 0:62cd296ba2a7 185 }
fep 0:62cd296ba2a7 186
fep 0:62cd296ba2a7 187
fep 0:62cd296ba2a7 188
fep 0:62cd296ba2a7 189