1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include "chre/core/init.h" 18 #include "chre/core/event_loop_manager.h" 19 #include "chre/core/static_nanoapps.h" 20 #include "chre/embos/init.h" 21 22 #include "RTOS.h" 23 24 namespace { 25 26 constexpr char kChreTaskName[] = "CHRE"; 27 constexpr size_t kChreTaskNameLen = sizeof(kChreTaskName) - 1; 28 29 // The CHRE task priority was requested to be between the sub_task (prio=60), 30 // and the main task (prio=100). 31 constexpr OS_PRIO kChreTaskPriority = 80; 32 33 // Stack for the CHRE task of size 8KB (2048 * sizeof(uint32_t)). 34 constexpr size_t kChreTaskStackDepth = 2048; 35 OS_STACKPTR uint32_t gChreTaskStack[kChreTaskStackDepth]; 36 37 OS_TASK gChreTcb; 38 chreThreadEntry()39void chreThreadEntry() { 40 chre::init(); 41 chre::EventLoopManagerSingleton::get()->lateInit(); 42 chre::loadStaticNanoapps(); 43 44 chre::EventLoopManagerSingleton::get()->getEventLoop().run(); 45 46 // we only get here if the CHRE EventLoop exited 47 chre::deinit(); 48 } 49 50 } // anonymous namespace 51 chreEmbosInit()52void chreEmbosInit() { 53 OS_CREATETASK(&gChreTcb, kChreTaskName, chreThreadEntry, kChreTaskPriority, 54 gChreTaskStack); 55 } 56 chreEmbosDeinit()57void chreEmbosDeinit() { 58 if (OS_IsTask(&gChreTcb)) { 59 chre::EventLoopManagerSingleton::get()->getEventLoop().stop(); 60 } 61 } 62 getChreTaskName()63const char *getChreTaskName() { 64 return kChreTaskName; 65 } 66 getChreTaskNameLen()67size_t getChreTaskNameLen() { 68 return kChreTaskNameLen; 69 } 70