mbed library sources. Supersedes mbed-src.
Dependents: Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more
targets/TARGET_ARM_SSG/TARGET_MPS2/us_ticker.c@188:bcfe06ba3d64, 2018-11-08 (annotated)
- Committer:
- AnnaBridge
- Date:
- Thu Nov 08 11:46:34 2018 +0000
- Revision:
- 188:bcfe06ba3d64
- Parent:
- 174:b96e65c34a4d
mbed-dev library. Release version 164
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
<> | 144:ef7eb2e8f9f7 | 1 | /* mbed Microcontroller Library |
<> | 144:ef7eb2e8f9f7 | 2 | * Copyright (c) 2006-2015 ARM Limited |
<> | 144:ef7eb2e8f9f7 | 3 | * |
<> | 144:ef7eb2e8f9f7 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
<> | 144:ef7eb2e8f9f7 | 5 | * you may not use this file except in compliance with the License. |
<> | 144:ef7eb2e8f9f7 | 6 | * You may obtain a copy of the License at |
<> | 144:ef7eb2e8f9f7 | 7 | * |
<> | 144:ef7eb2e8f9f7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
<> | 144:ef7eb2e8f9f7 | 9 | * |
<> | 144:ef7eb2e8f9f7 | 10 | * Unless required by applicable law or agreed to in writing, software |
<> | 144:ef7eb2e8f9f7 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
<> | 144:ef7eb2e8f9f7 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
<> | 144:ef7eb2e8f9f7 | 13 | * See the License for the specific language governing permissions and |
<> | 144:ef7eb2e8f9f7 | 14 | * limitations under the License. |
<> | 144:ef7eb2e8f9f7 | 15 | */ |
<> | 144:ef7eb2e8f9f7 | 16 | #include <stddef.h> |
<> | 144:ef7eb2e8f9f7 | 17 | #include "us_ticker_api.h" |
<> | 144:ef7eb2e8f9f7 | 18 | #include "PeripheralNames.h" |
<> | 144:ef7eb2e8f9f7 | 19 | |
<> | 144:ef7eb2e8f9f7 | 20 | #define US_TICKER_TIMER1 CMSDK_DUALTIMER1 |
<> | 144:ef7eb2e8f9f7 | 21 | #define US_TICKER_TIMER2 CMSDK_DUALTIMER2 |
<> | 144:ef7eb2e8f9f7 | 22 | #define US_TICKER_TIMER_IRQn DUALTIMER_IRQn |
<> | 144:ef7eb2e8f9f7 | 23 | |
<> | 144:ef7eb2e8f9f7 | 24 | int us_ticker_inited = 0; |
<> | 144:ef7eb2e8f9f7 | 25 | |
<> | 144:ef7eb2e8f9f7 | 26 | void us_ticker_init(void) { |
<> | 144:ef7eb2e8f9f7 | 27 | if (us_ticker_inited) return; |
<> | 144:ef7eb2e8f9f7 | 28 | us_ticker_inited = 1; |
<> | 144:ef7eb2e8f9f7 | 29 | |
<> | 144:ef7eb2e8f9f7 | 30 | US_TICKER_TIMER1->TimerControl = 0x0; // disable timer |
<> | 144:ef7eb2e8f9f7 | 31 | US_TICKER_TIMER2->TimerControl = 0x00; // disable timer |
<> | 144:ef7eb2e8f9f7 | 32 | US_TICKER_TIMER1->TimerLoad = 0xFFFFFFFF; |
<> | 144:ef7eb2e8f9f7 | 33 | US_TICKER_TIMER2->TimerLoad = 0xFFFFFFFF; |
<> | 144:ef7eb2e8f9f7 | 34 | |
<> | 144:ef7eb2e8f9f7 | 35 | US_TICKER_TIMER1->TimerControl = 0x62; // enable interrupt and set to 32 bit counter and set to periodic mode |
<> | 144:ef7eb2e8f9f7 | 36 | US_TICKER_TIMER2->TimerControl = 0x42; // enable interrupt and set to 32 bit counter |
<> | 144:ef7eb2e8f9f7 | 37 | |
<> | 144:ef7eb2e8f9f7 | 38 | US_TICKER_TIMER1->TimerControl |= 0x80; // enable counter |
<> | 144:ef7eb2e8f9f7 | 39 | US_TICKER_TIMER2->TimerControl |= 0x80; // enable counter |
<> | 144:ef7eb2e8f9f7 | 40 | |
<> | 144:ef7eb2e8f9f7 | 41 | NVIC_SetVector(US_TICKER_TIMER_IRQn, (uint32_t)us_ticker_irq_handler); |
<> | 144:ef7eb2e8f9f7 | 42 | NVIC_EnableIRQ(US_TICKER_TIMER_IRQn); |
<> | 144:ef7eb2e8f9f7 | 43 | } |
<> | 144:ef7eb2e8f9f7 | 44 | |
<> | 144:ef7eb2e8f9f7 | 45 | uint32_t us_ticker_read() { |
<> | 144:ef7eb2e8f9f7 | 46 | uint32_t return_value = 0; |
<> | 144:ef7eb2e8f9f7 | 47 | if (!us_ticker_inited) |
<> | 144:ef7eb2e8f9f7 | 48 | us_ticker_init(); |
<> | 144:ef7eb2e8f9f7 | 49 | return_value = ((~US_TICKER_TIMER2->TimerValue)/25); |
<> | 144:ef7eb2e8f9f7 | 50 | return return_value; |
<> | 144:ef7eb2e8f9f7 | 51 | } |
<> | 144:ef7eb2e8f9f7 | 52 | |
<> | 144:ef7eb2e8f9f7 | 53 | void us_ticker_set_interrupt(timestamp_t timestamp) { |
<> | 144:ef7eb2e8f9f7 | 54 | if (!us_ticker_inited) |
<> | 144:ef7eb2e8f9f7 | 55 | us_ticker_init(); |
AnnaBridge | 174:b96e65c34a4d | 56 | |
AnnaBridge | 174:b96e65c34a4d | 57 | uint32_t delta = timestamp - us_ticker_read(); |
<> | 144:ef7eb2e8f9f7 | 58 | // enable interrupt |
<> | 144:ef7eb2e8f9f7 | 59 | US_TICKER_TIMER1->TimerControl = 0x0; // disable timer |
<> | 144:ef7eb2e8f9f7 | 60 | US_TICKER_TIMER1->TimerControl = 0x62; // enable interrupt and set to 32 bit counter and set to periodic mode |
<> | 144:ef7eb2e8f9f7 | 61 | US_TICKER_TIMER1->TimerLoad = (delta)*25; //initialise the timer value |
<> | 144:ef7eb2e8f9f7 | 62 | US_TICKER_TIMER1->TimerControl |= 0x80; //enable timer |
<> | 144:ef7eb2e8f9f7 | 63 | } |
<> | 144:ef7eb2e8f9f7 | 64 | |
AnnaBridge | 174:b96e65c34a4d | 65 | void us_ticker_fire_interrupt(void) |
AnnaBridge | 174:b96e65c34a4d | 66 | { |
AnnaBridge | 174:b96e65c34a4d | 67 | NVIC_SetPendingIRQ(US_TICKER_TIMER_IRQn); |
AnnaBridge | 174:b96e65c34a4d | 68 | } |
AnnaBridge | 174:b96e65c34a4d | 69 | |
AnnaBridge | 174:b96e65c34a4d | 70 | |
<> | 144:ef7eb2e8f9f7 | 71 | void us_ticker_disable_interrupt(void) { |
<> | 144:ef7eb2e8f9f7 | 72 | |
<> | 144:ef7eb2e8f9f7 | 73 | US_TICKER_TIMER1->TimerControl &= 0xDF; |
<> | 144:ef7eb2e8f9f7 | 74 | US_TICKER_TIMER2->TimerControl &= 0xDF; |
<> | 144:ef7eb2e8f9f7 | 75 | |
<> | 144:ef7eb2e8f9f7 | 76 | } |
<> | 144:ef7eb2e8f9f7 | 77 | |
<> | 144:ef7eb2e8f9f7 | 78 | void us_ticker_clear_interrupt(void) { |
<> | 144:ef7eb2e8f9f7 | 79 | |
<> | 144:ef7eb2e8f9f7 | 80 | US_TICKER_TIMER1->TimerIntClr = 0x1; |
<> | 144:ef7eb2e8f9f7 | 81 | US_TICKER_TIMER2->TimerIntClr = 0x1; |
<> | 144:ef7eb2e8f9f7 | 82 | |
<> | 144:ef7eb2e8f9f7 | 83 | } |
AnnaBridge | 188:bcfe06ba3d64 | 84 | |
AnnaBridge | 188:bcfe06ba3d64 | 85 | void us_ticker_free(void) |
AnnaBridge | 188:bcfe06ba3d64 | 86 | { |
AnnaBridge | 188:bcfe06ba3d64 | 87 | |
AnnaBridge | 188:bcfe06ba3d64 | 88 | } |