int main( void ) { #if defined ( __IAR_SYSTEMS_ICC__ ) /* IAR allows init functions in __low_level_init(), but it is run before global * variables have been initialised, so the following init still needs to be done * When using GCC, this is done in crt0_GCC.c */ extern void platform_init_mcu_infrastructure( void ); extern void platform_init_external_devices( void ); platform_init_mcu_infrastructure( ); platform_init_external_devices( ); #endif /* #elif defined ( __IAR_SYSTEMS_ICC__ ) */ /* Enter the ThreadX kernel. */ tx_kernel_enter( ); return 0; }
void _start( void ) { unsigned long ctor_num; /* Stack pointer is usually set up by boot process, but if program was loaded via jtag in RAM, that might not have happened */ __asm__( " ldr r1, =link_stack_end\n" " mov sp, r1\n" ); /* Setup the interrupt vectors address */ SCB->VTOR = (unsigned long) &link_interrupt_vectors_location; /* Enable CPU Cycle counting */ CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; /* Global Enable for DWT */ DWT->CYCCNT = 0; /* Reset the counter */ DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk; /* Enable cycle counter */ /* Copy from flash any code to be run from RAM. Setup .fastcode section first in case init_clocks() needs it */ if ( ( &link_run_from_ram_code_ram_location != &link_run_from_ram_code_flash_location ) && ( link_run_from_ram_code_size != 0 ) ) { memcpy( &link_run_from_ram_code_ram_location, &link_run_from_ram_code_flash_location, (size_t) link_run_from_ram_code_size ); } /* Initialise clocks and memory. init_clocks() and init_memory() must NOT depend on globals as global data and bss sections aren't initialised yet */ platform_init_system_clocks(); platform_init_memory(); /* Copy initial values for global variables into RAM */ if ( ( &link_global_data_start != &link_global_data_initial_values ) && ( link_global_data_size != 0 ) ) { memcpy( &link_global_data_start, &link_global_data_initial_values, (size_t) link_global_data_size ); } /* BSS segment is for zero initialised elements, so memset it to zero */ memset( &link_bss_location, 0, (size_t) link_bss_size ); #if 0 /* was ifdef DEBUG */ /* This is not a valid way to fill the stack, since it is currently in use - causes a problem in release with debug on - optimisation of active stack overwriting causes hardfault */ memset( &link_stack_location, 0xA5, link_stack_size ); /* Fill stack with pattern to allow checking of stack usage */ #endif /* if 0 */ /* * Run global C++ constructors if any */ /* TODO: make this an unconditional goto?, so that return address stuff doesn't get put on the stack. (what happens if main returns in this case?) */ platform_init_mcu_infrastructure( ); platform_init_external_devices( ); for ( ctor_num = 0; ctor_num < link_constructors_size/sizeof(constructor_ptr_t); ctor_num++ ) { link_constructors_location[ctor_num](); } main( ); /* the main loop has returned - there is now nothing to do - reboot. */ /* Reset request */ SCB->AIRCR = SCB_AIRCR_SYSRESETREQ_Msk | SCB_AIRCR_VECTKEY; }