Armando Montanez | c62a2d2 | 2021-12-08 16:02:07 -0800 | [diff] [blame] | 1 | // Copyright 2021 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 "FreeRTOS.h" |
| 16 | #include "pw_log/log.h" |
Carlos Chinchilla | ecf3d80 | 2021-12-08 12:35:54 -0800 | [diff] [blame] | 17 | #include "pw_system/init.h" |
Armando Montanez | c62a2d2 | 2021-12-08 16:02:07 -0800 | [diff] [blame] | 18 | #include "pw_thread/detached_thread.h" |
| 19 | #include "pw_thread/thread.h" |
| 20 | #include "pw_thread/thread_core.h" |
| 21 | #include "pw_thread_freertos/context.h" |
| 22 | |
| 23 | namespace { |
| 24 | |
| 25 | class IdleThread : public pw::thread::ThreadCore { |
| 26 | public: |
| 27 | IdleThread() = default; |
| 28 | ~IdleThread() = default; |
| 29 | IdleThread(const IdleThread&) = delete; |
| 30 | IdleThread(IdleThread&&) = delete; |
| 31 | IdleThread& operator=(const IdleThread&) = delete; |
| 32 | IdleThread& operator=(IdleThread&&) = delete; |
| 33 | |
| 34 | // From pw::thread::ThreadCore |
| 35 | void Run() final { |
| 36 | while (true) { |
Armando Montanez | c62a2d2 | 2021-12-08 16:02:07 -0800 | [diff] [blame] | 37 | PW_LOG_INFO("The cake is a lie!"); |
Carlos Chinchilla | ecf3d80 | 2021-12-08 12:35:54 -0800 | [diff] [blame] | 38 | vTaskDelay(1000); |
Armando Montanez | c62a2d2 | 2021-12-08 16:02:07 -0800 | [diff] [blame] | 39 | } |
| 40 | } |
| 41 | }; |
| 42 | |
| 43 | IdleThread idle_thread; |
| 44 | std::array<StackType_t, 512> idle_stack; |
| 45 | pw::thread::freertos::StaticContext idle_context(idle_stack); |
| 46 | constexpr pw::thread::freertos::Options idle_thread_options = |
| 47 | pw::thread::freertos::Options() |
| 48 | .set_name("IdleThread") |
| 49 | .set_static_context(idle_context) |
Carlos Chinchilla | ecf3d80 | 2021-12-08 12:35:54 -0800 | [diff] [blame] | 50 | .set_priority(tskIDLE_PRIORITY + 2); |
Armando Montanez | c62a2d2 | 2021-12-08 16:02:07 -0800 | [diff] [blame] | 51 | |
| 52 | } // namespace |
| 53 | |
| 54 | extern "C" int main() { |
Carlos Chinchilla | ecf3d80 | 2021-12-08 12:35:54 -0800 | [diff] [blame] | 55 | PW_LOG_INFO("Demo app"); |
| 56 | pw::system::Init(); |
Armando Montanez | c62a2d2 | 2021-12-08 16:02:07 -0800 | [diff] [blame] | 57 | // Hand off the main stack to the kernel. |
| 58 | pw::thread::DetachedThread(idle_thread_options, idle_thread); |
| 59 | vTaskStartScheduler(); |
| 60 | } |