Modified for BG96

Fork of mbed-dev by mbed official

Committer:
WaleedElmughrabi
Date:
Thu Sep 20 16:11:23 2018 +0000
Revision:
188:60408c49b6d4
Parent:
187:0387e8f68319
Fork modified for BG96 error

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AnnaBridge 187:0387e8f68319 1 /* mbed Microcontroller Library
AnnaBridge 187:0387e8f68319 2 * Copyright (c) 2006-2018 ARM Limited
AnnaBridge 187:0387e8f68319 3 *
AnnaBridge 187:0387e8f68319 4 * Licensed under the Apache License, Version 2.0 (the "License");
AnnaBridge 187:0387e8f68319 5 * you may not use this file except in compliance with the License.
AnnaBridge 187:0387e8f68319 6 * You may obtain a copy of the License at
AnnaBridge 187:0387e8f68319 7 *
AnnaBridge 187:0387e8f68319 8 * http://www.apache.org/licenses/LICENSE-2.0
AnnaBridge 187:0387e8f68319 9 *
AnnaBridge 187:0387e8f68319 10 * Unless required by applicable law or agreed to in writing, software
AnnaBridge 187:0387e8f68319 11 * distributed under the License is distributed on an "AS IS" BASIS,
AnnaBridge 187:0387e8f68319 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
AnnaBridge 187:0387e8f68319 13 * See the License for the specific language governing permissions and
AnnaBridge 187:0387e8f68319 14 * limitations under the License.
AnnaBridge 187:0387e8f68319 15 */
AnnaBridge 187:0387e8f68319 16 #include "hal/us_ticker_api.h"
AnnaBridge 187:0387e8f68319 17 #include "us_ticker_data.h"
AnnaBridge 187:0387e8f68319 18
AnnaBridge 187:0387e8f68319 19 // This variable is set to 1 at the of mbed_sdk_init function.
AnnaBridge 187:0387e8f68319 20 // The ticker_read_us function must not be called until the mbed_sdk_init is terminated.
AnnaBridge 187:0387e8f68319 21 extern int mbed_sdk_inited;
AnnaBridge 187:0387e8f68319 22
AnnaBridge 187:0387e8f68319 23 // Defined in us_ticker.c
AnnaBridge 187:0387e8f68319 24 void init_16bit_timer(void);
AnnaBridge 187:0387e8f68319 25 void init_32bit_timer(void);
AnnaBridge 187:0387e8f68319 26
AnnaBridge 187:0387e8f68319 27 #if TIM_MST_BIT_WIDTH == 16
AnnaBridge 187:0387e8f68319 28 // Variables also reset in us_ticker_init()
AnnaBridge 187:0387e8f68319 29 uint32_t prev_time = 0;
AnnaBridge 187:0387e8f68319 30 uint32_t elapsed_time = 0;
AnnaBridge 187:0387e8f68319 31 #endif
AnnaBridge 187:0387e8f68319 32
AnnaBridge 187:0387e8f68319 33 // Overwrite default HAL functions defined as "weak"
AnnaBridge 187:0387e8f68319 34
AnnaBridge 187:0387e8f68319 35 HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
AnnaBridge 187:0387e8f68319 36 {
AnnaBridge 187:0387e8f68319 37 #if TIM_MST_BIT_WIDTH == 16
AnnaBridge 187:0387e8f68319 38 init_16bit_timer();
AnnaBridge 187:0387e8f68319 39 #else
AnnaBridge 187:0387e8f68319 40 init_32bit_timer();
AnnaBridge 187:0387e8f68319 41 #endif
AnnaBridge 187:0387e8f68319 42 return HAL_OK;
AnnaBridge 187:0387e8f68319 43 }
AnnaBridge 187:0387e8f68319 44
AnnaBridge 187:0387e8f68319 45 uint32_t HAL_GetTick()
AnnaBridge 187:0387e8f68319 46 {
AnnaBridge 187:0387e8f68319 47 #if TIM_MST_BIT_WIDTH == 16
AnnaBridge 187:0387e8f68319 48 uint32_t new_time;
AnnaBridge 187:0387e8f68319 49 if (mbed_sdk_inited) {
AnnaBridge 187:0387e8f68319 50 // Apply the latest time recorded just before the sdk is inited
AnnaBridge 187:0387e8f68319 51 new_time = ticker_read_us(get_us_ticker_data()) + prev_time;
AnnaBridge 187:0387e8f68319 52 prev_time = 0; // Use this time only once
AnnaBridge 187:0387e8f68319 53 return (new_time / 1000);
AnnaBridge 187:0387e8f68319 54 }
AnnaBridge 187:0387e8f68319 55 else {
AnnaBridge 187:0387e8f68319 56 new_time = us_ticker_read();
AnnaBridge 187:0387e8f68319 57 elapsed_time += (new_time - prev_time) & 0xFFFF; // Only use the lower 16 bits
AnnaBridge 187:0387e8f68319 58 prev_time = new_time;
AnnaBridge 187:0387e8f68319 59 return (elapsed_time / 1000);
AnnaBridge 187:0387e8f68319 60 }
AnnaBridge 187:0387e8f68319 61 #else // 32-bit timer
AnnaBridge 187:0387e8f68319 62 if (mbed_sdk_inited) {
AnnaBridge 187:0387e8f68319 63 return (ticker_read_us(get_us_ticker_data()) / 1000);
AnnaBridge 187:0387e8f68319 64 }
AnnaBridge 187:0387e8f68319 65 else {
AnnaBridge 187:0387e8f68319 66 return (us_ticker_read() / 1000);
AnnaBridge 187:0387e8f68319 67 }
AnnaBridge 187:0387e8f68319 68 #endif
AnnaBridge 187:0387e8f68319 69 }
AnnaBridge 187:0387e8f68319 70
AnnaBridge 187:0387e8f68319 71 void HAL_SuspendTick(void)
AnnaBridge 187:0387e8f68319 72 {
AnnaBridge 187:0387e8f68319 73 // Do nothing
AnnaBridge 187:0387e8f68319 74 }
AnnaBridge 187:0387e8f68319 75
AnnaBridge 187:0387e8f68319 76 void HAL_ResumeTick(void)
AnnaBridge 187:0387e8f68319 77 {
AnnaBridge 187:0387e8f68319 78 // Do nothing
AnnaBridge 187:0387e8f68319 79 }