]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_MPU_STM32L4_Discovery_GCC_IAR_Keil/Projects/GCC/Startup/sysmem.c
Rename STM32Cube to GCC for STM32L4 Discovery projects as GCC is
[freertos] / FreeRTOS / Demo / CORTEX_MPU_STM32L4_Discovery_GCC_IAR_Keil / Projects / GCC / Startup / sysmem.c
1 /**
2 *****************************************************************************
3 **
4 **  File        : sysmem.c
5 **
6 **  Author          : Auto-generated by STM32CubeIDE
7 **
8 **  Abstract    : STM32CubeIDE Minimal System Memory calls file
9 **
10 **                        For more information about which c-functions
11 **                need which of these lowlevel functions
12 **                please consult the Newlib libc-manual
13 **
14 **  Environment : STM32CubeIDE MCU
15 **
16 **  Distribution: The file is distributed as is, without any warranty
17 **                of any kind.
18 **
19 *****************************************************************************
20 **
21 ** <h2><center>&copy; COPYRIGHT(c) 2018 STMicroelectronics</center></h2>
22 **
23 ** Redistribution and use in source and binary forms, with or without modification,
24 ** are permitted provided that the following conditions are met:
25 **   1. Redistributions of source code must retain the above copyright notice,
26 **      this list of conditions and the following disclaimer.
27 **   2. Redistributions in binary form must reproduce the above copyright notice,
28 **      this list of conditions and the following disclaimer in the documentation
29 **      and/or other materials provided with the distribution.
30 **   3. Neither the name of STMicroelectronics nor the names of its contributors
31 **      may be used to endorse or promote products derived from this software
32 **      without specific prior written permission.
33 **
34 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
35 ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
36 ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
37 ** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
38 ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
39 ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
40 ** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
41 ** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
42 ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
43 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 **
45 **
46 *****************************************************************************
47 */
48
49 /* Includes */
50 #include <errno.h>
51 #include <stdio.h>
52
53 /* Variables */
54 extern int errno;
55 register char * stack_ptr asm("sp");
56
57 /* Functions */
58
59 /**
60  _sbrk
61  Increase program data space. Malloc and related functions depend on this
62 **/
63 caddr_t _sbrk(int incr)
64 {
65         extern char end asm("end");
66         static char *heap_end;
67         char *prev_heap_end;
68
69         if (heap_end == 0)
70                 heap_end = &end;
71
72         prev_heap_end = heap_end;
73         if (heap_end + incr > stack_ptr)
74         {
75                 errno = ENOMEM;
76                 return (caddr_t) -1;
77         }
78
79         heap_end += incr;
80
81         return (caddr_t) prev_heap_end;
82 }
83