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