• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2022 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 //     https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14 
15 #include <array>
16 
17 #define PW_LOG_MODULE_NAME "pw_system"
18 
19 #include "FreeRTOS.h"
20 #include "pico/stdlib.h"
21 #include "pw_log/log.h"
22 #include "pw_string/util.h"
23 #include "pw_system/init.h"
24 #include "task.h"
25 
26 namespace {
27 
28 std::array<StackType_t, configMINIMAL_STACK_SIZE> freertos_idle_stack;
29 StaticTask_t freertos_idle_tcb;
30 
31 std::array<StackType_t, configTIMER_TASK_STACK_DEPTH> freertos_timer_stack;
32 StaticTask_t freertos_timer_tcb;
33 
34 std::array<char, configMAX_TASK_NAME_LEN> temp_thread_name_buffer;
35 
36 }  // namespace
37 
38 extern "C" {
39 // Functions needed when configGENERATE_RUN_TIME_STATS is on.
40 // void configureTimerForRunTimeStats(void) {}
41 // unsigned long getRunTimeCounterValue(void) { return time_us_64(); }
42 
43 // Required for configCHECK_FOR_STACK_OVERFLOW.
vApplicationStackOverflowHook(TaskHandle_t,char * pcTaskName)44 void vApplicationStackOverflowHook(TaskHandle_t, char* pcTaskName) {
45   pw::string::Copy(pcTaskName, temp_thread_name_buffer);
46   PW_CRASH("Stack OVF for task %s", temp_thread_name_buffer.data());
47 }
48 
49 // Required for configUSE_TIMERS.
vApplicationGetTimerTaskMemory(StaticTask_t ** ppxTimerTaskTCBBuffer,StackType_t ** ppxTimerTaskStackBuffer,uint32_t * pulTimerTaskStackSize)50 void vApplicationGetTimerTaskMemory(StaticTask_t** ppxTimerTaskTCBBuffer,
51                                     StackType_t** ppxTimerTaskStackBuffer,
52                                     uint32_t* pulTimerTaskStackSize) {
53   *ppxTimerTaskTCBBuffer = &freertos_timer_tcb;
54   *ppxTimerTaskStackBuffer = freertos_timer_stack.data();
55   *pulTimerTaskStackSize = freertos_timer_stack.size();
56 }
57 
vApplicationGetIdleTaskMemory(StaticTask_t ** ppxIdleTaskTCBBuffer,StackType_t ** ppxIdleTaskStackBuffer,uint32_t * pulIdleTaskStackSize)58 void vApplicationGetIdleTaskMemory(StaticTask_t** ppxIdleTaskTCBBuffer,
59                                    StackType_t** ppxIdleTaskStackBuffer,
60                                    uint32_t* pulIdleTaskStackSize) {
61   *ppxIdleTaskTCBBuffer = &freertos_idle_tcb;
62   *ppxIdleTaskStackBuffer = freertos_idle_stack.data();
63   *pulIdleTaskStackSize = freertos_idle_stack.size();
64 }
65 }
66 
main()67 int main() {
68   // PICO_SDK Inits
69   stdio_init_all();
70   setup_default_uart();
71   // stdio_usb_init();
72   PW_LOG_INFO("pw_system main");
73 
74   pw::system::Init();
75   vTaskStartScheduler();
76   PW_UNREACHABLE;
77 }
78