Mbed SDK for XRange SX1272 LoRa module
Dependents: XRangePingPong XRange-LoRaWAN-lmic-app lora-transceiver
SX1272 LoRa RF module
https://www.netblocks.eu/xrange-sx1272-lora-datasheet/
targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE/us_ticker.c@339:ac6f3fd999f3, 2016-01-07 (annotated)
- Committer:
- netblocks
- Date:
- Thu Jan 07 13:01:25 2016 +0000
- Revision:
- 339:ac6f3fd999f3
- Parent:
- 336:1e18a06a987b
HSE_VALUE set for XTAL 16Mhz
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dudmuck | 336:1e18a06a987b | 1 | /* mbed Microcontroller Library |
dudmuck | 336:1e18a06a987b | 2 | * Copyright (c) 2014, STMicroelectronics |
dudmuck | 336:1e18a06a987b | 3 | * All rights reserved. |
dudmuck | 336:1e18a06a987b | 4 | * |
dudmuck | 336:1e18a06a987b | 5 | * Redistribution and use in source and binary forms, with or without |
dudmuck | 336:1e18a06a987b | 6 | * modification, are permitted provided that the following conditions are met: |
dudmuck | 336:1e18a06a987b | 7 | * |
dudmuck | 336:1e18a06a987b | 8 | * 1. Redistributions of source code must retain the above copyright notice, |
dudmuck | 336:1e18a06a987b | 9 | * this list of conditions and the following disclaimer. |
dudmuck | 336:1e18a06a987b | 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
dudmuck | 336:1e18a06a987b | 11 | * this list of conditions and the following disclaimer in the documentation |
dudmuck | 336:1e18a06a987b | 12 | * and/or other materials provided with the distribution. |
dudmuck | 336:1e18a06a987b | 13 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
dudmuck | 336:1e18a06a987b | 14 | * may be used to endorse or promote products derived from this software |
dudmuck | 336:1e18a06a987b | 15 | * without specific prior written permission. |
dudmuck | 336:1e18a06a987b | 16 | * |
dudmuck | 336:1e18a06a987b | 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
dudmuck | 336:1e18a06a987b | 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
dudmuck | 336:1e18a06a987b | 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
dudmuck | 336:1e18a06a987b | 20 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
dudmuck | 336:1e18a06a987b | 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
dudmuck | 336:1e18a06a987b | 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
dudmuck | 336:1e18a06a987b | 23 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
dudmuck | 336:1e18a06a987b | 24 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
dudmuck | 336:1e18a06a987b | 25 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
dudmuck | 336:1e18a06a987b | 26 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
dudmuck | 336:1e18a06a987b | 27 | */ |
dudmuck | 336:1e18a06a987b | 28 | #include <stddef.h> |
dudmuck | 336:1e18a06a987b | 29 | #include "us_ticker_api.h" |
dudmuck | 336:1e18a06a987b | 30 | #include "PeripheralNames.h" |
dudmuck | 336:1e18a06a987b | 31 | |
dudmuck | 336:1e18a06a987b | 32 | #define TIM_MST TIM5 |
dudmuck | 336:1e18a06a987b | 33 | |
dudmuck | 336:1e18a06a987b | 34 | static TIM_HandleTypeDef TimMasterHandle; |
dudmuck | 336:1e18a06a987b | 35 | static int us_ticker_inited = 0; |
dudmuck | 336:1e18a06a987b | 36 | |
dudmuck | 336:1e18a06a987b | 37 | void us_ticker_init(void) |
dudmuck | 336:1e18a06a987b | 38 | { |
dudmuck | 336:1e18a06a987b | 39 | if (us_ticker_inited) return; |
dudmuck | 336:1e18a06a987b | 40 | us_ticker_inited = 1; |
dudmuck | 336:1e18a06a987b | 41 | |
dudmuck | 336:1e18a06a987b | 42 | TimMasterHandle.Instance = TIM_MST; |
dudmuck | 336:1e18a06a987b | 43 | |
dudmuck | 336:1e18a06a987b | 44 | HAL_InitTick(0); // The passed value is not used |
dudmuck | 336:1e18a06a987b | 45 | } |
dudmuck | 336:1e18a06a987b | 46 | |
dudmuck | 336:1e18a06a987b | 47 | uint32_t us_ticker_read() |
dudmuck | 336:1e18a06a987b | 48 | { |
dudmuck | 336:1e18a06a987b | 49 | if (!us_ticker_inited) us_ticker_init(); |
dudmuck | 336:1e18a06a987b | 50 | return TIM_MST->CNT; |
dudmuck | 336:1e18a06a987b | 51 | } |
dudmuck | 336:1e18a06a987b | 52 | |
dudmuck | 336:1e18a06a987b | 53 | void us_ticker_set_interrupt(timestamp_t timestamp) |
dudmuck | 336:1e18a06a987b | 54 | { |
dudmuck | 336:1e18a06a987b | 55 | // Set new output compare value |
dudmuck | 336:1e18a06a987b | 56 | __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_1, (uint32_t)timestamp); |
dudmuck | 336:1e18a06a987b | 57 | // Enable IT |
dudmuck | 336:1e18a06a987b | 58 | __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC1); |
dudmuck | 336:1e18a06a987b | 59 | } |
dudmuck | 336:1e18a06a987b | 60 | |
dudmuck | 336:1e18a06a987b | 61 | void us_ticker_disable_interrupt(void) |
dudmuck | 336:1e18a06a987b | 62 | { |
dudmuck | 336:1e18a06a987b | 63 | __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC1); |
dudmuck | 336:1e18a06a987b | 64 | } |
dudmuck | 336:1e18a06a987b | 65 | |
dudmuck | 336:1e18a06a987b | 66 | void us_ticker_clear_interrupt(void) |
dudmuck | 336:1e18a06a987b | 67 | { |
dudmuck | 336:1e18a06a987b | 68 | __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); |
dudmuck | 336:1e18a06a987b | 69 | } |