mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-29 14:52:12 +01:00
OP-423 do the arch specific stuff (in reset vector) to hide this from portable code:
- switch back to MSP stack before starting the scheduler so that the sheduler can use the IRQ stack (when/if needed). - call the C portable function in heap1 to claim some stack back (the number to claim is taken from linker file). - start the scheduler from reset vector (I move this here from main because it make sense to not go back to C (so that I don't need to copy the rolled stack in case the sheduler returns). This make it more clean. - Also I have added the call to the mem manager if sheduler return. that way, we don't reset indefinitely if memory runs out. We will go to this handler and figure things out (right now, it's just looping but at least not rebooting. Probably trap NMI would be better (later improvement). The part missing for this part is the weak attribute for the function in heap1.c so that we don't have to update everything with empty stub. I think the weak atrribute for C function called in assembly is arch dependent so I am not sure if this is possible (will look into it, maybe somebody outthere nows). Right now, it's heap1 dependent and won't work with heap2. I will clean that up the next couple of days. I did some test and it looks good. this is without init code re-organization so we don't free as much as we will be it's good starts. This compile with sim_posix (since it does not affect portable code) so this is really clean. I only tested this with CC. I will port it for OP when I will work on heap2.
This commit is contained in:
parent
0e6abd4f39
commit
c95b199166
@ -53,7 +53,7 @@ extern void PIOS_Board_Init(void);
|
||||
*
|
||||
* Initialize PiOS<BR>
|
||||
* Create the "System" task (SystemModInitializein Modules/System/systemmod.c) <BR>
|
||||
* Start FreeRTOS Scheduler (vTaskStartScheduler)<BR>
|
||||
* Start FreeRTOS Scheduler (vTaskStartScheduler) (Now handled by caller)
|
||||
* If something goes wrong, blink LED1 and LED2 every 100ms
|
||||
*
|
||||
*/
|
||||
@ -67,12 +67,15 @@ int main()
|
||||
|
||||
/* Initialize the system thread */
|
||||
SystemModInitialize();
|
||||
|
||||
/* Start the FreeRTOS scheduler */
|
||||
vTaskStartScheduler();
|
||||
|
||||
/* If all is well we will never reach here as the scheduler will now be running. */
|
||||
/* If we do get here, it will most likely be because we ran out of heap space. */
|
||||
#if defined(ARCH_POSIX) || defined(ARCH_WIN32)
|
||||
/* Start the FreeRTOS scheduler which never returns.*/
|
||||
/* only do this for posix and win32 since the caller will take care
|
||||
* of starting the scheduler and increase the heap and swith back to
|
||||
* MSP stack. (all arch specific is hidden from here and take care by reset handler)
|
||||
*/
|
||||
vTaskStartScheduler();
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -84,6 +84,8 @@ static union xRTOS_HEAP
|
||||
} xHeap __attribute__ ((section (".heap")));
|
||||
|
||||
static size_t xNextFreeByte = ( size_t ) 0;
|
||||
static size_t currentTOTAL_HEAP_SISE = configTOTAL_HEAP_SIZE;
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void *pvPortMalloc( size_t xWantedSize )
|
||||
@ -102,7 +104,7 @@ void *pvReturn = NULL;
|
||||
vTaskSuspendAll();
|
||||
{
|
||||
/* Check there is enough room left for the allocation. */
|
||||
if( ( ( xNextFreeByte + xWantedSize ) < configTOTAL_HEAP_SIZE ) &&
|
||||
if( ( ( xNextFreeByte + xWantedSize ) < currentTOTAL_HEAP_SISE ) &&
|
||||
( ( xNextFreeByte + xWantedSize ) > xNextFreeByte ) )/* Check for overflow. */
|
||||
{
|
||||
/* Return the next free byte then increment the index past this
|
||||
@ -145,8 +147,14 @@ void vPortInitialiseBlocks( void )
|
||||
|
||||
size_t xPortGetFreeHeapSize( void )
|
||||
{
|
||||
return ( configTOTAL_HEAP_SIZE - xNextFreeByte );
|
||||
return ( currentTOTAL_HEAP_SISE - xNextFreeByte );
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
|
||||
|
||||
void xPortIncreaseHeapSize( size_t bytes )
|
||||
{
|
||||
vTaskSuspendAll();
|
||||
currentTOTAL_HEAP_SISE = configTOTAL_HEAP_SIZE + bytes;
|
||||
xTaskResumeAll();
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
@ -1,5 +1,7 @@
|
||||
/* This is the size of the stack for early init and for all FreeRTOS IRQs */
|
||||
/* This is the size of the stack for all FreeRTOS IRQs */
|
||||
_irq_stack_size = 0x180;
|
||||
/* This is the size of the stack for early init: life span is until scheduler starts */
|
||||
_init_stack_size = 0x80;
|
||||
|
||||
/* Stub out these functions since we don't use them anyway */
|
||||
PROVIDE ( vPortSVCHandler = 0 ) ;
|
||||
@ -86,11 +88,17 @@ SECTIONS
|
||||
.heap (NOLOAD) :
|
||||
{
|
||||
_sheap = . ;
|
||||
_sheap_pre_rtos = . ;
|
||||
*(.heap)
|
||||
. = ALIGN(4);
|
||||
_eheap = . ;
|
||||
_eheap_pre_rtos = . ;
|
||||
_init_stack_end = . ;
|
||||
_sheap_post_rtos = . ;
|
||||
. = . + _init_stack_size ;
|
||||
. = ALIGN(4);
|
||||
_eheap_post_rtos = . ;
|
||||
_init_stack_top = . - 4 ;
|
||||
. = ALIGN(4);
|
||||
} > SRAM
|
||||
|
||||
. = ALIGN(4);
|
||||
|
@ -33,6 +33,8 @@
|
||||
|
||||
.global g_pfnVectors
|
||||
.global Default_Handler
|
||||
.global vTaskStartScheduler
|
||||
.global xPortIncreaseHeapSize
|
||||
|
||||
/* start address for the initialization values of the .data section.
|
||||
defined in linker script */
|
||||
@ -124,6 +126,19 @@ LoopFillZerobss:
|
||||
bcc FillZerobss
|
||||
/* Call the application's entry point.*/
|
||||
bl main
|
||||
/* Switches stack back momentarily to MSP */
|
||||
add r0, #0
|
||||
msr control, r0
|
||||
/* add heap_post_rtos to the heap (if the capability/function exist) */
|
||||
ldr r0, = _init_stack_size
|
||||
bl xPortIncreaseHeapSize
|
||||
/* Start the FreeRTOS scheduler which never returns.*/
|
||||
bl vTaskStartScheduler
|
||||
/* If all is well we will never reach here as the scheduler will now be running. */
|
||||
/* If we do get here, it will most likely be because we ran out of heap space. */
|
||||
/* let the Memory manager handler figure it out (at least for now, it will make it more obvious */
|
||||
bl MemManage_Handler
|
||||
/* will never return here for now until mem manager give up */
|
||||
bx lr
|
||||
.size Reset_Handler, .-Reset_Handler
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user