blob: fe0e9be4bc7e33a52fa0fad541c76fc2c87dac5c [file] [log] [blame]
Kevin Schoedel3a505012021-09-08 15:21:38 -04001/*
2 *
3 * Copyright (c) 2021 Project CHIP Authors
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18/**
19 * @file
Jean-Francois Penvenb6864632022-04-20 11:43:39 -040020 * This file declares an implementation of LayerImplFreeRTOS using LwIP.
Kevin Schoedel3a505012021-09-08 15:21:38 -040021 */
22
23#pragma once
24
25#include <lib/support/ObjectLifeCycle.h>
26#include <system/SystemLayer.h>
Kevin Schoedel51e5bfb2021-12-07 09:45:23 -050027#include <system/SystemTimer.h>
Kevin Schoedel3a505012021-09-08 15:21:38 -040028
29namespace chip {
30namespace System {
31
Jean-Francois Penvenb6864632022-04-20 11:43:39 -040032class LayerImplFreeRTOS : public LayerFreeRTOS
Kevin Schoedel3a505012021-09-08 15:21:38 -040033{
34public:
Jean-Francois Penvenb6864632022-04-20 11:43:39 -040035 LayerImplFreeRTOS();
36 ~LayerImplFreeRTOS() { VerifyOrDie(mLayerState.Destroy()); }
Kevin Schoedel3a505012021-09-08 15:21:38 -040037
38 // Layer overrides.
39 CHIP_ERROR Init() override;
Michael Spang63870492022-06-28 08:41:08 -040040 void Shutdown() override;
Kevin Schoedel3a505012021-09-08 15:21:38 -040041 bool IsInitialized() const override { return mLayerState.IsInitialized(); }
Kevin Schoedelea1b4432021-10-21 16:52:54 -040042 CHIP_ERROR StartTimer(Clock::Timeout delay, TimerCompleteCallback onComplete, void * appState) override;
Junior Martinez803c5ae2023-06-21 13:27:33 -040043 CHIP_ERROR ExtendTimerTo(Clock::Timeout delay, TimerCompleteCallback onComplete, void * appState) override;
44 bool IsTimerActive(TimerCompleteCallback onComplete, void * appState) override;
lpbeliveau-silabs3799c412024-02-26 10:11:48 -050045 Clock::Timeout GetRemainingTime(TimerCompleteCallback onComplete, void * appState) override;
Kevin Schoedel3a505012021-09-08 15:21:38 -040046 void CancelTimer(TimerCompleteCallback onComplete, void * appState) override;
47 CHIP_ERROR ScheduleWork(TimerCompleteCallback onComplete, void * appState) override;
48
Kevin Schoedel3a505012021-09-08 15:21:38 -040049public:
50 // Platform implementation.
Kevin Schoedel3a505012021-09-08 15:21:38 -040051 CHIP_ERROR HandlePlatformTimer(void);
52
53private:
54 friend class PlatformEventing;
55
Kevin Schoedelea1b4432021-10-21 16:52:54 -040056 CHIP_ERROR StartPlatformTimer(System::Clock::Timeout aDelay);
Kevin Schoedel3a505012021-09-08 15:21:38 -040057
Kevin Schoedel51e5bfb2021-12-07 09:45:23 -050058 TimerPool<TimerList::Node> mTimerPool;
59 TimerList mTimerList;
Kevin Schoedel3a505012021-09-08 15:21:38 -040060 bool mHandlingTimerComplete; // true while handling any timer completion
Kevin Schoedel3a505012021-09-08 15:21:38 -040061 ObjectLifeCycle mLayerState;
62};
63
Jean-Francois Penvenb6864632022-04-20 11:43:39 -040064using LayerImpl = LayerImplFreeRTOS;
Kevin Schoedel3a505012021-09-08 15:21:38 -040065
66} // namespace System
67} // namespace chip