Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
simple-mbed-cloud-client/mbed-cloud-client/ns-hal-pal/arm_hal_timer.cpp@0:8f0bb79ddd48, 2021-05-04 (annotated)
- Committer:
- leothedragon
- Date:
- Tue May 04 08:55:12 2021 +0000
- Revision:
- 0:8f0bb79ddd48
nmn
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
leothedragon | 0:8f0bb79ddd48 | 1 | // ---------------------------------------------------------------------------- |
leothedragon | 0:8f0bb79ddd48 | 2 | // Copyright 2016-2017 ARM Ltd. |
leothedragon | 0:8f0bb79ddd48 | 3 | // |
leothedragon | 0:8f0bb79ddd48 | 4 | // SPDX-License-Identifier: Apache-2.0 |
leothedragon | 0:8f0bb79ddd48 | 5 | // |
leothedragon | 0:8f0bb79ddd48 | 6 | // Licensed under the Apache License, Version 2.0 (the "License"); |
leothedragon | 0:8f0bb79ddd48 | 7 | // you may not use this file except in compliance with the License. |
leothedragon | 0:8f0bb79ddd48 | 8 | // You may obtain a copy of the License at |
leothedragon | 0:8f0bb79ddd48 | 9 | // |
leothedragon | 0:8f0bb79ddd48 | 10 | // http://www.apache.org/licenses/LICENSE-2.0 |
leothedragon | 0:8f0bb79ddd48 | 11 | // |
leothedragon | 0:8f0bb79ddd48 | 12 | // Unless required by applicable law or agreed to in writing, software |
leothedragon | 0:8f0bb79ddd48 | 13 | // distributed under the License is distributed on an "AS IS" BASIS, |
leothedragon | 0:8f0bb79ddd48 | 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
leothedragon | 0:8f0bb79ddd48 | 15 | // See the License for the specific language governing permissions and |
leothedragon | 0:8f0bb79ddd48 | 16 | // limitations under the License. |
leothedragon | 0:8f0bb79ddd48 | 17 | // ---------------------------------------------------------------------------- |
leothedragon | 0:8f0bb79ddd48 | 18 | |
leothedragon | 0:8f0bb79ddd48 | 19 | // Include before mbed.h to properly get UINT*_C() |
leothedragon | 0:8f0bb79ddd48 | 20 | #include "ns_types.h" |
leothedragon | 0:8f0bb79ddd48 | 21 | |
leothedragon | 0:8f0bb79ddd48 | 22 | #include "pal.h" |
leothedragon | 0:8f0bb79ddd48 | 23 | #include "pal_rtos.h" |
leothedragon | 0:8f0bb79ddd48 | 24 | |
leothedragon | 0:8f0bb79ddd48 | 25 | #include "platform/arm_hal_timer.h" |
leothedragon | 0:8f0bb79ddd48 | 26 | #include "platform/arm_hal_interrupt.h" |
leothedragon | 0:8f0bb79ddd48 | 27 | |
leothedragon | 0:8f0bb79ddd48 | 28 | #include <assert.h> |
leothedragon | 0:8f0bb79ddd48 | 29 | |
leothedragon | 0:8f0bb79ddd48 | 30 | // Low precision platform tick timer variables |
leothedragon | 0:8f0bb79ddd48 | 31 | static void (*tick_timer_callback)(void); |
leothedragon | 0:8f0bb79ddd48 | 32 | static palTimerID_t tick_timer_id; |
leothedragon | 0:8f0bb79ddd48 | 33 | #define TICK_TIMER_ID 1 |
leothedragon | 0:8f0bb79ddd48 | 34 | |
leothedragon | 0:8f0bb79ddd48 | 35 | void timer_callback(void const *funcArgument) |
leothedragon | 0:8f0bb79ddd48 | 36 | { |
leothedragon | 0:8f0bb79ddd48 | 37 | (void)funcArgument; |
leothedragon | 0:8f0bb79ddd48 | 38 | if (tick_timer_callback != NULL) { |
leothedragon | 0:8f0bb79ddd48 | 39 | tick_timer_callback(); |
leothedragon | 0:8f0bb79ddd48 | 40 | } |
leothedragon | 0:8f0bb79ddd48 | 41 | } |
leothedragon | 0:8f0bb79ddd48 | 42 | |
leothedragon | 0:8f0bb79ddd48 | 43 | #ifdef MBED_CONF_NANOSTACK_EVENTLOOP_EXCLUDE_HIGHRES_TIMER |
leothedragon | 0:8f0bb79ddd48 | 44 | extern "C" int8_t ns_timer_sleep(void); |
leothedragon | 0:8f0bb79ddd48 | 45 | #endif |
leothedragon | 0:8f0bb79ddd48 | 46 | |
leothedragon | 0:8f0bb79ddd48 | 47 | // static method for creating the timer, called implicitly by platform_tick_timer_register if |
leothedragon | 0:8f0bb79ddd48 | 48 | // timer was not enabled already |
leothedragon | 0:8f0bb79ddd48 | 49 | static void tick_timer_create(void) |
leothedragon | 0:8f0bb79ddd48 | 50 | { |
leothedragon | 0:8f0bb79ddd48 | 51 | palStatus_t status; |
leothedragon | 0:8f0bb79ddd48 | 52 | status = pal_init(); |
leothedragon | 0:8f0bb79ddd48 | 53 | assert(PAL_SUCCESS == status); |
leothedragon | 0:8f0bb79ddd48 | 54 | status = pal_osTimerCreate(timer_callback, NULL, palOsTimerPeriodic, &tick_timer_id); |
leothedragon | 0:8f0bb79ddd48 | 55 | assert(PAL_SUCCESS == status); |
leothedragon | 0:8f0bb79ddd48 | 56 | |
leothedragon | 0:8f0bb79ddd48 | 57 | } |
leothedragon | 0:8f0bb79ddd48 | 58 | |
leothedragon | 0:8f0bb79ddd48 | 59 | // Low precision platform tick timer |
leothedragon | 0:8f0bb79ddd48 | 60 | extern "C" |
leothedragon | 0:8f0bb79ddd48 | 61 | int8_t platform_tick_timer_register(void (*tick_timer_cb_handler)(void)) |
leothedragon | 0:8f0bb79ddd48 | 62 | { |
leothedragon | 0:8f0bb79ddd48 | 63 | if (tick_timer_id == 0) { |
leothedragon | 0:8f0bb79ddd48 | 64 | tick_timer_create(); |
leothedragon | 0:8f0bb79ddd48 | 65 | } |
leothedragon | 0:8f0bb79ddd48 | 66 | tick_timer_callback = tick_timer_cb_handler; |
leothedragon | 0:8f0bb79ddd48 | 67 | return TICK_TIMER_ID; |
leothedragon | 0:8f0bb79ddd48 | 68 | } |
leothedragon | 0:8f0bb79ddd48 | 69 | |
leothedragon | 0:8f0bb79ddd48 | 70 | extern "C" |
leothedragon | 0:8f0bb79ddd48 | 71 | int8_t platform_tick_timer_start(uint32_t period_ms) |
leothedragon | 0:8f0bb79ddd48 | 72 | { |
leothedragon | 0:8f0bb79ddd48 | 73 | int8_t retval = -1; |
leothedragon | 0:8f0bb79ddd48 | 74 | if ((tick_timer_id != 0) && (PAL_SUCCESS == pal_osTimerStart(tick_timer_id, period_ms))) { |
leothedragon | 0:8f0bb79ddd48 | 75 | retval = 0; |
leothedragon | 0:8f0bb79ddd48 | 76 | } |
leothedragon | 0:8f0bb79ddd48 | 77 | return retval; |
leothedragon | 0:8f0bb79ddd48 | 78 | } |
leothedragon | 0:8f0bb79ddd48 | 79 | |
leothedragon | 0:8f0bb79ddd48 | 80 | extern "C" |
leothedragon | 0:8f0bb79ddd48 | 81 | int8_t platform_tick_timer_stop(void) |
leothedragon | 0:8f0bb79ddd48 | 82 | { |
leothedragon | 0:8f0bb79ddd48 | 83 | int8_t retval = -1; |
leothedragon | 0:8f0bb79ddd48 | 84 | if ((tick_timer_id != 0) && (PAL_SUCCESS == pal_osTimerStop(tick_timer_id))) { |
leothedragon | 0:8f0bb79ddd48 | 85 | retval = 0; |
leothedragon | 0:8f0bb79ddd48 | 86 | } |
leothedragon | 0:8f0bb79ddd48 | 87 | |
leothedragon | 0:8f0bb79ddd48 | 88 | // release PAL side resources |
leothedragon | 0:8f0bb79ddd48 | 89 | pal_osTimerDelete(&tick_timer_id); |
leothedragon | 0:8f0bb79ddd48 | 90 | pal_destroy(); |
leothedragon | 0:8f0bb79ddd48 | 91 | |
leothedragon | 0:8f0bb79ddd48 | 92 | return retval; |
leothedragon | 0:8f0bb79ddd48 | 93 | } |
leothedragon | 0:8f0bb79ddd48 | 94 | |
leothedragon | 0:8f0bb79ddd48 | 95 |