blob: acf57f935eac9664c6673c53d5502626c3596c41 [file] [log] [blame]
Armando Montanezc62a2d22021-12-08 16:02:07 -08001// 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 Chinchillaecf3d802021-12-08 12:35:54 -080017#include "pw_system/init.h"
Armando Montanezc62a2d22021-12-08 16:02:07 -080018#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
23namespace {
24
25class 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 Montanezc62a2d22021-12-08 16:02:07 -080037 PW_LOG_INFO("The cake is a lie!");
Carlos Chinchillaecf3d802021-12-08 12:35:54 -080038 vTaskDelay(1000);
Armando Montanezc62a2d22021-12-08 16:02:07 -080039 }
40 }
41};
42
43IdleThread idle_thread;
44std::array<StackType_t, 512> idle_stack;
45pw::thread::freertos::StaticContext idle_context(idle_stack);
46constexpr pw::thread::freertos::Options idle_thread_options =
47 pw::thread::freertos::Options()
48 .set_name("IdleThread")
49 .set_static_context(idle_context)
Carlos Chinchillaecf3d802021-12-08 12:35:54 -080050 .set_priority(tskIDLE_PRIORITY + 2);
Armando Montanezc62a2d22021-12-08 16:02:07 -080051
52} // namespace
53
54extern "C" int main() {
Carlos Chinchillaecf3d802021-12-08 12:35:54 -080055 PW_LOG_INFO("Demo app");
56 pw::system::Init();
Armando Montanezc62a2d22021-12-08 16:02:07 -080057 // Hand off the main stack to the kernel.
58 pw::thread::DetachedThread(idle_thread_options, idle_thread);
59 vTaskStartScheduler();
60}