Skip to content

Commit

Permalink
Demo/CORTEX_MPU_M3_MPS2_QEMU_GCC: optimize _sbrk()
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
laroche committed Apr 18, 2024
1 parent 2023ac6 commit 91f3049
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
2 changes: 1 addition & 1 deletion FreeRTOS/Demo/CORTEX_MPU_M3_MPS2_QEMU_GCC/init/startup.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
extern void vPortSVCHandler( void );
extern void xPortPendSVHandler( void );
extern void xPortSysTickHandler( void );
extern void uart_init();
extern void uart_init( void );
extern int main();

extern uint32_t _estack, _sidata, _sdata, _edata, _sbss, _ebss;
Expand Down
17 changes: 5 additions & 12 deletions FreeRTOS/Demo/CORTEX_MPU_M3_MPS2_QEMU_GCC/syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ extern unsigned long g_ulBase;
/**
* @brief initializes the UART emulated hardware
*/
void uart_init()
void uart_init(void)
{
UART0_ADDR->BAUDDIV = 16;
UART0_ADDR->CTRL = UART_CTRL_TX_EN;
Expand Down Expand Up @@ -85,7 +85,7 @@ FILE *const stdout = &__stdio;

#else

static void * heap_end = 0;
static char * heap_end = ( char * ) &_heap_bottom;

/**
* @brief not used anywhere in the code
Expand Down Expand Up @@ -139,16 +139,9 @@ int _write( __attribute__( ( unused ) ) int file,
*/
void * _sbrk( int incr )
{
char * prev_heap_end;
void * prev_heap_end = heap_end;

if( heap_end == 0 )
{
heap_end = ( void * ) &_heap_bottom;
}

prev_heap_end = heap_end;

if( ( heap_end + incr ) > ( void * ) &_heap_top )
if( ( heap_end + incr ) > ( char * ) &_heap_top )
{
return ( void * ) -1;
}
Expand Down Expand Up @@ -202,7 +195,7 @@ void _kill( pid_t pid,
( void ) sig;
}

int _getpid()
int _getpid( void )
{
return 1;
}
Expand Down

0 comments on commit 91f3049

Please sign in to comment.