mbed

Fork of mbed-dev by mbed official

Committer:
AnnaBridge
Date:
Fri Feb 16 16:09:33 2018 +0000
Revision:
182:57724642e740
Parent:
175:b96e65c34a4d
mbed-dev library. Release version 159.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
<> 153:fa9ff456f731 1 /* mbed Microcontroller Library
<> 153:fa9ff456f731 2 * Copyright (c) 2006-2016 ARM Limited
<> 153:fa9ff456f731 3 *
<> 153:fa9ff456f731 4 * Licensed under the Apache License, Version 2.0 (the "License");
<> 153:fa9ff456f731 5 * you may not use this file except in compliance with the License.
<> 153:fa9ff456f731 6 * You may obtain a copy of the License at
<> 153:fa9ff456f731 7 *
<> 153:fa9ff456f731 8 * http://www.apache.org/licenses/LICENSE-2.0
<> 153:fa9ff456f731 9 *
<> 153:fa9ff456f731 10 * Unless required by applicable law or agreed to in writing, software
<> 153:fa9ff456f731 11 * distributed under the License is distributed on an "AS IS" BASIS,
<> 153:fa9ff456f731 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<> 153:fa9ff456f731 13 * See the License for the specific language governing permissions and
<> 153:fa9ff456f731 14 * limitations under the License.
<> 153:fa9ff456f731 15 */
<> 153:fa9ff456f731 16 #include <stddef.h>
<> 153:fa9ff456f731 17 #include "us_ticker_api.h"
<> 153:fa9ff456f731 18 #include "PeripheralNames.h"
<> 153:fa9ff456f731 19 #include "hal_tick.h"
<> 153:fa9ff456f731 20
<> 153:fa9ff456f731 21 // A 32-bit timer is used
<> 153:fa9ff456f731 22 #if !TIM_MST_16BIT
<> 153:fa9ff456f731 23
<> 153:fa9ff456f731 24 TIM_HandleTypeDef TimMasterHandle;
<> 153:fa9ff456f731 25
<> 153:fa9ff456f731 26 void us_ticker_init(void)
<> 153:fa9ff456f731 27 {
AnnaBridge 175:b96e65c34a4d 28 /* NOTE: assuming that HAL tick has already been initialized! */
<> 153:fa9ff456f731 29 }
<> 153:fa9ff456f731 30
<> 153:fa9ff456f731 31 uint32_t us_ticker_read()
<> 153:fa9ff456f731 32 {
<> 153:fa9ff456f731 33 return TIM_MST->CNT;
<> 153:fa9ff456f731 34 }
<> 153:fa9ff456f731 35
<> 153:fa9ff456f731 36 void us_ticker_set_interrupt(timestamp_t timestamp)
<> 153:fa9ff456f731 37 {
AnnaBridge 175:b96e65c34a4d 38 // NOTE: This function must be called with interrupts disabled to keep our
AnnaBridge 175:b96e65c34a4d 39 // timer interrupt setup atomic
AnnaBridge 175:b96e65c34a4d 40
AnnaBridge 168:9672193075cf 41 // disable IT while we are handling the correct timestamp
AnnaBridge 168:9672193075cf 42 __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC1);
<> 153:fa9ff456f731 43 // Set new output compare value
<> 153:fa9ff456f731 44 __HAL_TIM_SET_COMPARE(&TimMasterHandle, TIM_CHANNEL_1, (uint32_t)timestamp);
AnnaBridge 168:9672193075cf 45 // Enable IT
AnnaBridge 168:9672193075cf 46 __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC1);
<> 153:fa9ff456f731 47 }
<> 153:fa9ff456f731 48
AnnaBridge 175:b96e65c34a4d 49 void us_ticker_fire_interrupt(void)
AnnaBridge 175:b96e65c34a4d 50 {
AnnaBridge 175:b96e65c34a4d 51 LL_TIM_GenerateEvent_CC1(TimMasterHandle.Instance);
AnnaBridge 175:b96e65c34a4d 52 }
AnnaBridge 175:b96e65c34a4d 53
AnnaBridge 175:b96e65c34a4d 54 /* NOTE: must be called with interrupts disabled! */
<> 153:fa9ff456f731 55 void us_ticker_disable_interrupt(void)
<> 153:fa9ff456f731 56 {
<> 153:fa9ff456f731 57 __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC1);
<> 153:fa9ff456f731 58 }
<> 153:fa9ff456f731 59
AnnaBridge 175:b96e65c34a4d 60 /* NOTE: must be called with interrupts disabled! */
<> 153:fa9ff456f731 61 void us_ticker_clear_interrupt(void)
<> 153:fa9ff456f731 62 {
AnnaBridge 175:b96e65c34a4d 63 __HAL_TIM_CLEAR_FLAG(&TimMasterHandle, TIM_FLAG_CC1);
<> 153:fa9ff456f731 64 }
<> 153:fa9ff456f731 65
<> 153:fa9ff456f731 66 #endif // !TIM_MST_16BIT