mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Mon Feb 09 09:30:07 2015 +0000
Revision:
469:fc4922e0c183
Child:
583:967d0d8b7aed
Synchronized with git revision 06e2b3c8802cb4f78e9958ba9923755bd458e8b7

Full URL: https://github.com/mbedmicro/mbed/commit/06e2b3c8802cb4f78e9958ba9923755bd458e8b7/

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 469:fc4922e0c183 1 /* mbed Microcontroller Library
mbed_official 469:fc4922e0c183 2 * Copyright (c) 2014, STMicroelectronics
mbed_official 469:fc4922e0c183 3 * All rights reserved.
mbed_official 469:fc4922e0c183 4 *
mbed_official 469:fc4922e0c183 5 * Redistribution and use in source and binary forms, with or without
mbed_official 469:fc4922e0c183 6 * modification, are permitted provided that the following conditions are met:
mbed_official 469:fc4922e0c183 7 *
mbed_official 469:fc4922e0c183 8 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 469:fc4922e0c183 9 * this list of conditions and the following disclaimer.
mbed_official 469:fc4922e0c183 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 469:fc4922e0c183 11 * this list of conditions and the following disclaimer in the documentation
mbed_official 469:fc4922e0c183 12 * and/or other materials provided with the distribution.
mbed_official 469:fc4922e0c183 13 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 469:fc4922e0c183 14 * may be used to endorse or promote products derived from this software
mbed_official 469:fc4922e0c183 15 * without specific prior written permission.
mbed_official 469:fc4922e0c183 16 *
mbed_official 469:fc4922e0c183 17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 469:fc4922e0c183 18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 469:fc4922e0c183 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 469:fc4922e0c183 20 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 469:fc4922e0c183 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 469:fc4922e0c183 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 469:fc4922e0c183 23 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 469:fc4922e0c183 24 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 469:fc4922e0c183 25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 469:fc4922e0c183 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 469:fc4922e0c183 27 */
mbed_official 469:fc4922e0c183 28 #include <stddef.h>
mbed_official 469:fc4922e0c183 29 #include "us_ticker_api.h"
mbed_official 469:fc4922e0c183 30 #include "PeripheralNames.h"
mbed_official 469:fc4922e0c183 31
mbed_official 469:fc4922e0c183 32 #if defined(TARGET_STM32F070RB)
mbed_official 469:fc4922e0c183 33
mbed_official 469:fc4922e0c183 34 // Timer selection
mbed_official 469:fc4922e0c183 35 #define TIM_MST TIM1
mbed_official 469:fc4922e0c183 36
mbed_official 469:fc4922e0c183 37 static TIM_HandleTypeDef TimMasterHandle;
mbed_official 469:fc4922e0c183 38 static int us_ticker_inited = 0;
mbed_official 469:fc4922e0c183 39
mbed_official 469:fc4922e0c183 40 volatile uint32_t SlaveCounter = 0;
mbed_official 469:fc4922e0c183 41 volatile uint32_t oc_int_part = 0;
mbed_official 469:fc4922e0c183 42 volatile uint16_t oc_rem_part = 0;
mbed_official 469:fc4922e0c183 43
mbed_official 469:fc4922e0c183 44 void set_compare(uint16_t count)
mbed_official 469:fc4922e0c183 45 {
mbed_official 469:fc4922e0c183 46 TimMasterHandle.Instance = TIM_MST;
mbed_official 469:fc4922e0c183 47 // Set new output compare value
mbed_official 469:fc4922e0c183 48 __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_1, count);
mbed_official 469:fc4922e0c183 49 // Enable IT
mbed_official 469:fc4922e0c183 50 __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC1);
mbed_official 469:fc4922e0c183 51 }
mbed_official 469:fc4922e0c183 52
mbed_official 469:fc4922e0c183 53 void us_ticker_init(void)
mbed_official 469:fc4922e0c183 54 {
mbed_official 469:fc4922e0c183 55 if (us_ticker_inited) return;
mbed_official 469:fc4922e0c183 56 us_ticker_inited = 1;
mbed_official 469:fc4922e0c183 57
mbed_official 469:fc4922e0c183 58 HAL_InitTick(0); // The passed value is not used
mbed_official 469:fc4922e0c183 59 }
mbed_official 469:fc4922e0c183 60
mbed_official 469:fc4922e0c183 61 uint32_t us_ticker_read()
mbed_official 469:fc4922e0c183 62 {
mbed_official 469:fc4922e0c183 63 uint32_t counter, counter2;
mbed_official 469:fc4922e0c183 64 if (!us_ticker_inited) us_ticker_init();
mbed_official 469:fc4922e0c183 65 // A situation might appear when Master overflows right after Slave is read and before the
mbed_official 469:fc4922e0c183 66 // new (overflowed) value of Master is read. Which would make the code below consider the
mbed_official 469:fc4922e0c183 67 // previous (incorrect) value of Slave and the new value of Master, which would return a
mbed_official 469:fc4922e0c183 68 // value in the past. Avoid this by computing consecutive values of the timer until they
mbed_official 469:fc4922e0c183 69 // are properly ordered.
mbed_official 469:fc4922e0c183 70 counter = (uint32_t)(SlaveCounter << 16);
mbed_official 469:fc4922e0c183 71 counter += TIM_MST->CNT;
mbed_official 469:fc4922e0c183 72 while (1) {
mbed_official 469:fc4922e0c183 73 counter2 = (uint32_t)(SlaveCounter << 16);
mbed_official 469:fc4922e0c183 74 counter2 += TIM_MST->CNT;
mbed_official 469:fc4922e0c183 75 if (counter2 > counter) {
mbed_official 469:fc4922e0c183 76 break;
mbed_official 469:fc4922e0c183 77 }
mbed_official 469:fc4922e0c183 78 counter = counter2;
mbed_official 469:fc4922e0c183 79 }
mbed_official 469:fc4922e0c183 80 return counter2;
mbed_official 469:fc4922e0c183 81 }
mbed_official 469:fc4922e0c183 82
mbed_official 469:fc4922e0c183 83 void us_ticker_set_interrupt(timestamp_t timestamp)
mbed_official 469:fc4922e0c183 84 {
mbed_official 469:fc4922e0c183 85 int delta = (int)((uint32_t)timestamp - us_ticker_read());
mbed_official 469:fc4922e0c183 86 uint16_t cval = TIM_MST->CNT;
mbed_official 469:fc4922e0c183 87
mbed_official 469:fc4922e0c183 88 if (delta <= 0) { // This event was in the past
mbed_official 469:fc4922e0c183 89 us_ticker_irq_handler();
mbed_official 469:fc4922e0c183 90 } else {
mbed_official 469:fc4922e0c183 91 oc_int_part = (uint32_t)(delta >> 16);
mbed_official 469:fc4922e0c183 92 oc_rem_part = (uint16_t)(delta & 0xFFFF);
mbed_official 469:fc4922e0c183 93 if (oc_rem_part <= (0xFFFF - cval)) {
mbed_official 469:fc4922e0c183 94 set_compare(cval + oc_rem_part);
mbed_official 469:fc4922e0c183 95 oc_rem_part = 0;
mbed_official 469:fc4922e0c183 96 } else {
mbed_official 469:fc4922e0c183 97 set_compare(0xFFFF);
mbed_official 469:fc4922e0c183 98 oc_rem_part = oc_rem_part - (0xFFFF - cval);
mbed_official 469:fc4922e0c183 99 }
mbed_official 469:fc4922e0c183 100 }
mbed_official 469:fc4922e0c183 101 }
mbed_official 469:fc4922e0c183 102
mbed_official 469:fc4922e0c183 103 void us_ticker_disable_interrupt(void)
mbed_official 469:fc4922e0c183 104 {
mbed_official 469:fc4922e0c183 105 TimMasterHandle.Instance = TIM_MST;
mbed_official 469:fc4922e0c183 106 __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC1);
mbed_official 469:fc4922e0c183 107 }
mbed_official 469:fc4922e0c183 108
mbed_official 469:fc4922e0c183 109 void us_ticker_clear_interrupt(void)
mbed_official 469:fc4922e0c183 110 {
mbed_official 469:fc4922e0c183 111 TimMasterHandle.Instance = TIM_MST;
mbed_official 469:fc4922e0c183 112 if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) {
mbed_official 469:fc4922e0c183 113 __HAL_TIM_CLEAR_FLAG(&TimMasterHandle, TIM_FLAG_CC1);
mbed_official 469:fc4922e0c183 114 }
mbed_official 469:fc4922e0c183 115 }
mbed_official 469:fc4922e0c183 116
mbed_official 469:fc4922e0c183 117 #elif defined(TARGET_STM32F030R8) || defined (TARGET_STM32F051R8)
mbed_official 469:fc4922e0c183 118
mbed_official 469:fc4922e0c183 119 // Timer selection:
mbed_official 469:fc4922e0c183 120 #define TIM_MST TIM1
mbed_official 469:fc4922e0c183 121 #define TIM_MST_UP_IRQ TIM1_BRK_UP_TRG_COM_IRQn
mbed_official 469:fc4922e0c183 122 #define TIM_MST_OC_IRQ TIM1_CC_IRQn
mbed_official 469:fc4922e0c183 123 #define TIM_MST_RCC __TIM1_CLK_ENABLE()
mbed_official 469:fc4922e0c183 124
mbed_official 469:fc4922e0c183 125 static TIM_HandleTypeDef TimMasterHandle;
mbed_official 469:fc4922e0c183 126
mbed_official 469:fc4922e0c183 127
mbed_official 469:fc4922e0c183 128 static int us_ticker_inited = 0;
mbed_official 469:fc4922e0c183 129 static volatile uint32_t SlaveCounter = 0;
mbed_official 469:fc4922e0c183 130 static volatile uint32_t oc_int_part = 0;
mbed_official 469:fc4922e0c183 131 static volatile uint16_t oc_rem_part = 0;
mbed_official 469:fc4922e0c183 132
mbed_official 469:fc4922e0c183 133 void set_compare(uint16_t count)
mbed_official 469:fc4922e0c183 134 {
mbed_official 469:fc4922e0c183 135 TimMasterHandle.Instance = TIM_MST;
mbed_official 469:fc4922e0c183 136
mbed_official 469:fc4922e0c183 137 // Set new output compare value
mbed_official 469:fc4922e0c183 138 __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_1, count);
mbed_official 469:fc4922e0c183 139 // Enable IT
mbed_official 469:fc4922e0c183 140 __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC1);
mbed_official 469:fc4922e0c183 141 }
mbed_official 469:fc4922e0c183 142
mbed_official 469:fc4922e0c183 143 // Used to increment the slave counter
mbed_official 469:fc4922e0c183 144 static void tim_update_irq_handler(void)
mbed_official 469:fc4922e0c183 145 {
mbed_official 469:fc4922e0c183 146 TimMasterHandle.Instance = TIM_MST;
mbed_official 469:fc4922e0c183 147
mbed_official 469:fc4922e0c183 148 // Clear Update interrupt flag
mbed_official 469:fc4922e0c183 149 if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_UPDATE) == SET) {
mbed_official 469:fc4922e0c183 150 __HAL_TIM_CLEAR_FLAG(&TimMasterHandle, TIM_FLAG_UPDATE);
mbed_official 469:fc4922e0c183 151 SlaveCounter++;
mbed_official 469:fc4922e0c183 152 }
mbed_official 469:fc4922e0c183 153 }
mbed_official 469:fc4922e0c183 154
mbed_official 469:fc4922e0c183 155 // Used by interrupt system
mbed_official 469:fc4922e0c183 156 static void tim_oc_irq_handler(void)
mbed_official 469:fc4922e0c183 157 {
mbed_official 469:fc4922e0c183 158 uint16_t cval = TIM_MST->CNT;
mbed_official 469:fc4922e0c183 159 TimMasterHandle.Instance = TIM_MST;
mbed_official 469:fc4922e0c183 160
mbed_official 469:fc4922e0c183 161 // Clear CC1 interrupt flag
mbed_official 469:fc4922e0c183 162 if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) {
mbed_official 469:fc4922e0c183 163 __HAL_TIM_CLEAR_FLAG(&TimMasterHandle, TIM_FLAG_CC1);
mbed_official 469:fc4922e0c183 164 }
mbed_official 469:fc4922e0c183 165 if (oc_rem_part > 0) {
mbed_official 469:fc4922e0c183 166 set_compare(oc_rem_part); // Finish the remaining time left
mbed_official 469:fc4922e0c183 167 oc_rem_part = 0;
mbed_official 469:fc4922e0c183 168 } else {
mbed_official 469:fc4922e0c183 169 if (oc_int_part > 0) {
mbed_official 469:fc4922e0c183 170 set_compare(0xFFFF);
mbed_official 469:fc4922e0c183 171 oc_rem_part = cval; // To finish the counter loop the next time
mbed_official 469:fc4922e0c183 172 oc_int_part--;
mbed_official 469:fc4922e0c183 173 } else {
mbed_official 469:fc4922e0c183 174 us_ticker_irq_handler();
mbed_official 469:fc4922e0c183 175 }
mbed_official 469:fc4922e0c183 176 }
mbed_official 469:fc4922e0c183 177
mbed_official 469:fc4922e0c183 178 }
mbed_official 469:fc4922e0c183 179
mbed_official 469:fc4922e0c183 180 void us_ticker_init(void)
mbed_official 469:fc4922e0c183 181 {
mbed_official 469:fc4922e0c183 182
mbed_official 469:fc4922e0c183 183 if (us_ticker_inited) return;
mbed_official 469:fc4922e0c183 184 us_ticker_inited = 1;
mbed_official 469:fc4922e0c183 185
mbed_official 469:fc4922e0c183 186 // Enable timer clock
mbed_official 469:fc4922e0c183 187 TIM_MST_RCC;
mbed_official 469:fc4922e0c183 188
mbed_official 469:fc4922e0c183 189 // Configure time base
mbed_official 469:fc4922e0c183 190 TimMasterHandle.Instance = TIM_MST;
mbed_official 469:fc4922e0c183 191 TimMasterHandle.Init.Period = 0xFFFF;
mbed_official 469:fc4922e0c183 192 TimMasterHandle.Init.Prescaler = (uint32_t)(SystemCoreClock / 1000000) - 1; // 1 �s tick
mbed_official 469:fc4922e0c183 193 TimMasterHandle.Init.ClockDivision = 0;
mbed_official 469:fc4922e0c183 194 TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
mbed_official 469:fc4922e0c183 195 HAL_TIM_Base_Init(&TimMasterHandle);
mbed_official 469:fc4922e0c183 196
mbed_official 469:fc4922e0c183 197 // Configure interrupts
mbed_official 469:fc4922e0c183 198 __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_UPDATE);
mbed_official 469:fc4922e0c183 199
mbed_official 469:fc4922e0c183 200 // Update interrupt used for 32-bit counter
mbed_official 469:fc4922e0c183 201 NVIC_SetVector(TIM_MST_UP_IRQ, (uint32_t)tim_update_irq_handler);
mbed_official 469:fc4922e0c183 202 NVIC_EnableIRQ(TIM_MST_UP_IRQ);
mbed_official 469:fc4922e0c183 203
mbed_official 469:fc4922e0c183 204 // Output compare interrupt used for timeout feature
mbed_official 469:fc4922e0c183 205 NVIC_SetVector(TIM_MST_OC_IRQ, (uint32_t)tim_oc_irq_handler);
mbed_official 469:fc4922e0c183 206 NVIC_EnableIRQ(TIM_MST_OC_IRQ);
mbed_official 469:fc4922e0c183 207
mbed_official 469:fc4922e0c183 208 // Enable timer
mbed_official 469:fc4922e0c183 209 HAL_TIM_Base_Start(&TimMasterHandle);
mbed_official 469:fc4922e0c183 210 }
mbed_official 469:fc4922e0c183 211
mbed_official 469:fc4922e0c183 212 uint32_t us_ticker_read()
mbed_official 469:fc4922e0c183 213 {
mbed_official 469:fc4922e0c183 214 uint32_t counter, counter2;
mbed_official 469:fc4922e0c183 215 if (!us_ticker_inited) us_ticker_init();
mbed_official 469:fc4922e0c183 216 // A situation might appear when Master overflows right after Slave is read and before the
mbed_official 469:fc4922e0c183 217 // new (overflowed) value of Master is read. Which would make the code below consider the
mbed_official 469:fc4922e0c183 218 // previous (incorrect) value of Slave and the new value of Master, which would return a
mbed_official 469:fc4922e0c183 219 // value in the past. Avoid this by computing consecutive values of the timer until they
mbed_official 469:fc4922e0c183 220 // are properly ordered.
mbed_official 469:fc4922e0c183 221 counter = (uint32_t)(SlaveCounter << 16);
mbed_official 469:fc4922e0c183 222 counter += TIM_MST->CNT;
mbed_official 469:fc4922e0c183 223 while (1) {
mbed_official 469:fc4922e0c183 224 counter2 = (uint32_t)(SlaveCounter << 16);
mbed_official 469:fc4922e0c183 225 counter2 += TIM_MST->CNT;
mbed_official 469:fc4922e0c183 226 if (counter2 > counter) {
mbed_official 469:fc4922e0c183 227 break;
mbed_official 469:fc4922e0c183 228 }
mbed_official 469:fc4922e0c183 229 counter = counter2;
mbed_official 469:fc4922e0c183 230 }
mbed_official 469:fc4922e0c183 231 return counter2;
mbed_official 469:fc4922e0c183 232 }
mbed_official 469:fc4922e0c183 233
mbed_official 469:fc4922e0c183 234 void us_ticker_set_interrupt(timestamp_t timestamp)
mbed_official 469:fc4922e0c183 235 {
mbed_official 469:fc4922e0c183 236 int delta = (int)((uint32_t)timestamp - us_ticker_read());
mbed_official 469:fc4922e0c183 237 uint16_t cval = TIM_MST->CNT;
mbed_official 469:fc4922e0c183 238
mbed_official 469:fc4922e0c183 239 if (delta <= 0) { // This event was in the past
mbed_official 469:fc4922e0c183 240 us_ticker_irq_handler();
mbed_official 469:fc4922e0c183 241 } else {
mbed_official 469:fc4922e0c183 242 oc_int_part = (uint32_t)(delta >> 16);
mbed_official 469:fc4922e0c183 243 oc_rem_part = (uint16_t)(delta & 0xFFFF);
mbed_official 469:fc4922e0c183 244 if (oc_rem_part <= (0xFFFF - cval)) {
mbed_official 469:fc4922e0c183 245 set_compare(cval + oc_rem_part);
mbed_official 469:fc4922e0c183 246 oc_rem_part = 0;
mbed_official 469:fc4922e0c183 247 } else {
mbed_official 469:fc4922e0c183 248 set_compare(0xFFFF);
mbed_official 469:fc4922e0c183 249 oc_rem_part = oc_rem_part - (0xFFFF - cval);
mbed_official 469:fc4922e0c183 250 }
mbed_official 469:fc4922e0c183 251 }
mbed_official 469:fc4922e0c183 252 }
mbed_official 469:fc4922e0c183 253
mbed_official 469:fc4922e0c183 254 void us_ticker_disable_interrupt(void)
mbed_official 469:fc4922e0c183 255 {
mbed_official 469:fc4922e0c183 256 TimMasterHandle.Instance = TIM_MST;
mbed_official 469:fc4922e0c183 257 __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC1);
mbed_official 469:fc4922e0c183 258 }
mbed_official 469:fc4922e0c183 259
mbed_official 469:fc4922e0c183 260 void us_ticker_clear_interrupt(void)
mbed_official 469:fc4922e0c183 261 {
mbed_official 469:fc4922e0c183 262 TimMasterHandle.Instance = TIM_MST;
mbed_official 469:fc4922e0c183 263 if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) {
mbed_official 469:fc4922e0c183 264 __HAL_TIM_CLEAR_FLAG(&TimMasterHandle, TIM_FLAG_CC1);
mbed_official 469:fc4922e0c183 265 }
mbed_official 469:fc4922e0c183 266 }
mbed_official 469:fc4922e0c183 267
mbed_official 469:fc4922e0c183 268 #else
mbed_official 469:fc4922e0c183 269
mbed_official 469:fc4922e0c183 270 // 32-bit timer selection
mbed_official 469:fc4922e0c183 271 #define TIM_MST TIM2
mbed_official 469:fc4922e0c183 272
mbed_official 469:fc4922e0c183 273 static TIM_HandleTypeDef TimMasterHandle;
mbed_official 469:fc4922e0c183 274 static int us_ticker_inited = 0;
mbed_official 469:fc4922e0c183 275
mbed_official 469:fc4922e0c183 276 void us_ticker_init(void)
mbed_official 469:fc4922e0c183 277 {
mbed_official 469:fc4922e0c183 278 if (us_ticker_inited) return;
mbed_official 469:fc4922e0c183 279 us_ticker_inited = 1;
mbed_official 469:fc4922e0c183 280
mbed_official 469:fc4922e0c183 281 TimMasterHandle.Instance = TIM_MST;
mbed_official 469:fc4922e0c183 282
mbed_official 469:fc4922e0c183 283 HAL_InitTick(0); // The passed value is not used
mbed_official 469:fc4922e0c183 284 }
mbed_official 469:fc4922e0c183 285
mbed_official 469:fc4922e0c183 286 uint32_t us_ticker_read()
mbed_official 469:fc4922e0c183 287 {
mbed_official 469:fc4922e0c183 288 if (!us_ticker_inited) us_ticker_init();
mbed_official 469:fc4922e0c183 289 return TIM_MST->CNT;
mbed_official 469:fc4922e0c183 290 }
mbed_official 469:fc4922e0c183 291
mbed_official 469:fc4922e0c183 292 void us_ticker_set_interrupt(timestamp_t timestamp)
mbed_official 469:fc4922e0c183 293 {
mbed_official 469:fc4922e0c183 294 // Set new output compare value
mbed_official 469:fc4922e0c183 295 __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_1, (uint32_t)timestamp);
mbed_official 469:fc4922e0c183 296 // Enable IT
mbed_official 469:fc4922e0c183 297 __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC1);
mbed_official 469:fc4922e0c183 298 }
mbed_official 469:fc4922e0c183 299
mbed_official 469:fc4922e0c183 300 void us_ticker_disable_interrupt(void)
mbed_official 469:fc4922e0c183 301 {
mbed_official 469:fc4922e0c183 302 __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC1);
mbed_official 469:fc4922e0c183 303 }
mbed_official 469:fc4922e0c183 304
mbed_official 469:fc4922e0c183 305 void us_ticker_clear_interrupt(void)
mbed_official 469:fc4922e0c183 306 {
mbed_official 469:fc4922e0c183 307 __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1);
mbed_official 469:fc4922e0c183 308 }
mbed_official 469:fc4922e0c183 309 #endif