|
51 | 51 | #define _declare_box(pool,size,cnt) uint32_t pool[(((size)+3)/4)*(cnt) + 3] |
52 | 52 | #define _declare_box8(pool,size,cnt) uint64_t pool[(((size)+7)/8)*(cnt) + 2] |
53 | 53 |
|
54 | | -#define OS_TCB_SIZE 52 |
| 54 | +#define OS_TCB_SIZE 60 |
55 | 55 | #define OS_TMR_SIZE 8 |
56 | 56 |
|
57 | 57 | typedef void *OS_ID; |
@@ -527,11 +527,18 @@ extern uint32_t __end__[]; |
527 | 527 | #endif |
528 | 528 |
|
529 | 529 | void set_main_stack(void) { |
| 530 | + uint32_t interrupt_stack_size = ((uint32_t)OS_MAINSTKSIZE * 4); |
| 531 | + uint32_t heap_plus_stack_size = ((uint32_t)INITIAL_SP - (uint32_t)HEAP_START) - interrupt_stack_size; |
| 532 | + // Main thread's stack is 1/4 of the heap |
| 533 | + uint32_t main_stack_size = heap_plus_stack_size / 4; |
| 534 | + // The main thread must be 4 byte aligned |
| 535 | + uint32_t main_stack_start = ((uint32_t)INITIAL_SP - interrupt_stack_size - main_stack_size) & ~0x7; |
| 536 | + |
530 | 537 | // That is the bottom of the main stack block: no collision detection |
531 | | - os_thread_def_main.stack_pointer = HEAP_START; |
| 538 | + os_thread_def_main.stack_pointer = (uint32_t*)main_stack_start; |
532 | 539 |
|
533 | 540 | // Leave OS_MAINSTKSIZE words for the scheduler and interrupts |
534 | | - os_thread_def_main.stacksize = (INITIAL_SP - (unsigned int)HEAP_START) - (OS_MAINSTKSIZE * 4); |
| 541 | + os_thread_def_main.stacksize = main_stack_size; |
535 | 542 | } |
536 | 543 |
|
537 | 544 | #if defined (__CC_ARM) |
@@ -677,22 +684,22 @@ __attribute__((naked)) void software_init_hook_rtos (void) { |
677 | 684 | // Opaque declaration of _reent structure |
678 | 685 | struct _reent; |
679 | 686 |
|
680 | | -void __malloc_lock( struct _reent *_r ) |
| 687 | +void __rtos_malloc_lock( struct _reent *_r ) |
681 | 688 | { |
682 | 689 | osMutexWait(malloc_mutex_id, osWaitForever); |
683 | 690 | } |
684 | 691 |
|
685 | | -void __malloc_unlock( struct _reent *_r ) |
| 692 | +void __rtos_malloc_unlock( struct _reent *_r ) |
686 | 693 | { |
687 | 694 | osMutexRelease(malloc_mutex_id); |
688 | 695 | } |
689 | 696 |
|
690 | | -void __env_lock( struct _reent *_r ) |
| 697 | +void __rtos_env_lock( struct _reent *_r ) |
691 | 698 | { |
692 | 699 | osMutexWait(env_mutex_id, osWaitForever); |
693 | 700 | } |
694 | 701 |
|
695 | | -void __env_unlock( struct _reent *_r ) |
| 702 | +void __rtos_env_unlock( struct _reent *_r ) |
696 | 703 | { |
697 | 704 | osMutexRelease(env_mutex_id); |
698 | 705 | } |
|
0 commit comments