Simulated product dispenser

Dependencies:   HTS221

Fork of mbed-cloud-workshop-connect-HTS221 by Jim Carver

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers arm_hal_timer.cpp Source File

arm_hal_timer.cpp

00001 // ----------------------------------------------------------------------------
00002 // Copyright 2016-2017 ARM Ltd.
00003 //
00004 // SPDX-License-Identifier: Apache-2.0
00005 //
00006 // Licensed under the Apache License, Version 2.0 (the "License");
00007 // you may not use this file except in compliance with the License.
00008 // You may obtain a copy of the License at
00009 //
00010 //     http://www.apache.org/licenses/LICENSE-2.0
00011 //
00012 // Unless required by applicable law or agreed to in writing, software
00013 // distributed under the License is distributed on an "AS IS" BASIS,
00014 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015 // See the License for the specific language governing permissions and
00016 // limitations under the License.
00017 // ----------------------------------------------------------------------------
00018 
00019 // Include before mbed.h to properly get UINT*_C()
00020 #include "ns_types.h"
00021 
00022 #include "pal.h"
00023 #include "pal_rtos.h"
00024 
00025 #include "platform/arm_hal_timer.h"
00026 #include "platform/arm_hal_interrupt.h"
00027 
00028 #include <assert.h>
00029 
00030 // Low precision platform tick timer variables
00031 static void (*tick_timer_callback)(void);
00032 static palTimerID_t tick_timer_id;
00033 #define TICK_TIMER_ID   1
00034 
00035 void timer_callback(void const *funcArgument)
00036 {
00037     (void)funcArgument;
00038     if (tick_timer_callback != NULL) {
00039         tick_timer_callback();
00040     }
00041 }
00042 
00043 #ifdef MBED_CONF_NANOSTACK_EVENTLOOP_EXCLUDE_HIGHRES_TIMER
00044 extern "C" int8_t ns_timer_sleep(void);
00045 #endif
00046 
00047 // static method for creating the timer, called implicitly by platform_tick_timer_register if
00048 // timer was not enabled already
00049 static void tick_timer_create(void)
00050 {
00051     palStatus_t status;
00052     status = pal_init();
00053     assert(PAL_SUCCESS == status);
00054     status = pal_osTimerCreate(timer_callback, NULL, palOsTimerPeriodic , &tick_timer_id);
00055     assert(PAL_SUCCESS == status);
00056     
00057 }
00058 
00059 // Low precision platform tick timer
00060 int8_t platform_tick_timer_register(void (*tick_timer_cb_handler)(void))
00061 {
00062     if (tick_timer_id == 0) {
00063         tick_timer_create();
00064     }
00065     tick_timer_callback = tick_timer_cb_handler;
00066     return TICK_TIMER_ID;
00067 }
00068 
00069 int8_t platform_tick_timer_start(uint32_t period_ms)
00070 {
00071     int8_t retval = -1;
00072     if ((tick_timer_id != 0) && (PAL_SUCCESS == pal_osTimerStart(tick_timer_id, period_ms))) {
00073         retval = 0;
00074     }
00075     return retval;
00076 }
00077 
00078 int8_t platform_tick_timer_stop(void)
00079 {
00080     int8_t retval = -1;
00081     if ((tick_timer_id != 0) && (PAL_SUCCESS == pal_osTimerStop(tick_timer_id))) {
00082         retval = 0;
00083     }
00084 
00085     // release PAL side resources
00086     pal_osTimerDelete(&tick_timer_id);
00087     pal_destroy();
00088 
00089     return retval;
00090 }
00091 
00092