Initial commit

Dependencies:   FastPWM

Committer:
lypinator
Date:
Wed Sep 16 01:11:49 2020 +0000
Revision:
0:bb348c97df44
Added PWM

Who changed what in which revision?

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