check we have enough stack free on all threads and the ISR stack */
| 828 | check we have enough stack free on all threads and the ISR stack |
| 829 | */ |
| 830 | void Scheduler::check_stack_free(void) |
| 831 | { |
| 832 | // we raise an internal error stack_overflow when the available |
| 833 | // stack on any thread or the ISR stack drops below this |
| 834 | // threshold. This means we get an overflow error when we haven't |
| 835 | // yet completely run out of stack. This gives us a good |
| 836 | // pre-warning when we are getting too close |
| 837 | #if defined(STM32F1) |
| 838 | const uint32_t min_stack = 32; |
| 839 | #else |
| 840 | const uint32_t min_stack = 64; |
| 841 | #endif |
| 842 | |
| 843 | if (stack_free(&__main_stack_base__) < min_stack) { |
| 844 | // use "line number" of 0xFFFF for ISR stack low |
| 845 | #if AP_INTERNALERROR_ENABLED |
| 846 | AP::internalerror().error(AP_InternalError::error_t::stack_overflow, 0xFFFF); |
| 847 | #endif |
| 848 | } |
| 849 | |
| 850 | for (thread_t *tp = chRegFirstThread(); tp; tp = chRegNextThread(tp)) { |
| 851 | if (stack_free(tp->wabase) < min_stack) { |
| 852 | // use task priority for line number. This allows us to |
| 853 | // identify the task fairly reliably |
| 854 | #if AP_INTERNALERROR_ENABLED |
| 855 | AP::internalerror().error(AP_InternalError::error_t::stack_overflow, tp->realprio); |
| 856 | #endif |
| 857 | } |
| 858 | } |
| 859 | } |
| 860 | #endif // CH_DBG_ENABLE_STACK_CHECK == TRUE |
| 861 | |
| 862 | #endif // CH_CFG_USE_DYNAMIC |
no test coverage detected