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