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