test

Fork of mbed-dev by mbed official

Committer:
AnnaBridge
Date:
Wed Jun 21 17:46:44 2017 +0100
Revision:
168:e84263d55307
Parent:
153:fa9ff456f731
Child:
169:9672193075cf
This updates the lib to the mbed lib v 145

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 static int us_ticker_inited = 0;
<> 153:fa9ff456f731 27
<> 153:fa9ff456f731 28 void us_ticker_init(void)
<> 153:fa9ff456f731 29 {
<> 153:fa9ff456f731 30 if (us_ticker_inited) return;
<> 153:fa9ff456f731 31 us_ticker_inited = 1;
<> 153:fa9ff456f731 32
<> 153:fa9ff456f731 33 TimMasterHandle.Instance = TIM_MST;
<> 153:fa9ff456f731 34
<> 153:fa9ff456f731 35 HAL_InitTick(0); // The passed value is not used
<> 153:fa9ff456f731 36 }
<> 153:fa9ff456f731 37
<> 153:fa9ff456f731 38 uint32_t us_ticker_read()
<> 153:fa9ff456f731 39 {
<> 153:fa9ff456f731 40 if (!us_ticker_inited) us_ticker_init();
<> 153:fa9ff456f731 41 return TIM_MST->CNT;
<> 153:fa9ff456f731 42 }
<> 153:fa9ff456f731 43
<> 153:fa9ff456f731 44 void us_ticker_set_interrupt(timestamp_t timestamp)
<> 153:fa9ff456f731 45 {
<> 153:fa9ff456f731 46 TimMasterHandle.Instance = TIM_MST;
<> 153:fa9ff456f731 47 // Set new output compare value
<> 153:fa9ff456f731 48 __HAL_TIM_SET_COMPARE(&TimMasterHandle, TIM_CHANNEL_1, (uint32_t)timestamp);
<> 153:fa9ff456f731 49 // Enable IT
<> 153:fa9ff456f731 50 __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC1);
AnnaBridge 168:e84263d55307 51 // Check if timestamp has already passed, and if so, set the event immediately
AnnaBridge 168:e84263d55307 52 if ((int32_t)(timestamp - TIM_MST->CNT) <= 0) {
AnnaBridge 168:e84263d55307 53 LL_TIM_GenerateEvent_CC1(TimMasterHandle.Instance);
AnnaBridge 168:e84263d55307 54 }
<> 153:fa9ff456f731 55 }
<> 153:fa9ff456f731 56
<> 153:fa9ff456f731 57 void us_ticker_disable_interrupt(void)
<> 153:fa9ff456f731 58 {
<> 153:fa9ff456f731 59 TimMasterHandle.Instance = TIM_MST;
<> 153:fa9ff456f731 60 __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC1);
<> 153:fa9ff456f731 61 }
<> 153:fa9ff456f731 62
<> 153:fa9ff456f731 63 void us_ticker_clear_interrupt(void)
<> 153:fa9ff456f731 64 {
<> 153:fa9ff456f731 65 TimMasterHandle.Instance = TIM_MST;
<> 153:fa9ff456f731 66 __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1);
<> 153:fa9ff456f731 67 }
<> 153:fa9ff456f731 68
<> 153:fa9ff456f731 69 #endif // !TIM_MST_16BIT