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