Demo/CORTEX_MPU_M3_MPS2_QEMU_GCC: optimize _sbrk() (#1211)

Optimize _sbrk() from runtime to compiletime initialization.
Fix compiler warnings by adjusting (void *) and (char *) types.

Complete function declarations for uart_init() and _getpid().

Signed-off-by: Florian La Roche <Florian.LaRoche@gmail.com>
Co-authored-by: Rahul Kar <118818625+kar-rahul-aws@users.noreply.github.com>
This commit is contained in:
Florian La Roche 2024-04-19 01:56:06 +02:00 committed by GitHub
parent 17eeb79698
commit 022447b855
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 13 deletions

View file

@ -34,7 +34,7 @@
extern void vPortSVCHandler( void ); extern void vPortSVCHandler( void );
extern void xPortPendSVHandler( void ); extern void xPortPendSVHandler( void );
extern void xPortSysTickHandler( void ); extern void xPortSysTickHandler( void );
extern void uart_init(); extern void uart_init( void );
extern int main(); extern int main();
extern uint32_t _estack, _sidata, _sdata, _edata, _sbss, _ebss; extern uint32_t _estack, _sidata, _sdata, _edata, _sbss, _ebss;

View file

@ -53,7 +53,7 @@ extern unsigned long g_ulBase;
/** /**
* @brief initializes the UART emulated hardware * @brief initializes the UART emulated hardware
*/ */
void uart_init() void uart_init(void)
{ {
UART0_ADDR->BAUDDIV = 16; UART0_ADDR->BAUDDIV = 16;
UART0_ADDR->CTRL = UART_CTRL_TX_EN; UART0_ADDR->CTRL = UART_CTRL_TX_EN;
@ -85,7 +85,7 @@ FILE *const stdout = &__stdio;
#else #else
static void * heap_end = 0; static char * heap_end = ( char * ) &_heap_bottom;
/** /**
* @brief not used anywhere in the code * @brief not used anywhere in the code
@ -139,16 +139,9 @@ int _write( __attribute__( ( unused ) ) int file,
*/ */
void * _sbrk( int incr ) void * _sbrk( int incr )
{ {
char * prev_heap_end; void * prev_heap_end = heap_end;
if( heap_end == 0 ) if( ( heap_end + incr ) > ( char * ) &_heap_top )
{
heap_end = ( void * ) &_heap_bottom;
}
prev_heap_end = heap_end;
if( ( heap_end + incr ) > ( void * ) &_heap_top )
{ {
return ( void * ) -1; return ( void * ) -1;
} }
@ -202,7 +195,7 @@ void _kill( pid_t pid,
( void ) sig; ( void ) sig;
} }
int _getpid() int _getpid( void )
{ {
return 1; return 1;
} }