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