mbed library sources

Dependents:   frdm_kl05z_gpio_test

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Fri Aug 29 17:15:07 2014 +0100
Revision:
304:89b9c3a9a045
Parent:
117:e0a7df0a9a56
Synchronized with git revision 734f365d7da26ef199751f4b0d91611479b495ea

Full URL: https://github.com/mbedmicro/mbed/commit/734f365d7da26ef199751f4b0d91611479b495ea/

1. timestamp_t as an abstraction for time values managed by
Ticker. Using uint64_t for timestamp_t allows a wraparound-free
Ticker. This change forces us to update the definitions of usTicker
for all platforms; but the changes beyond nRF51822 aren't major.

2. reduce power consumption on the nRF51822 by removing the need for
the high-frequency processor timer; and reimplementing it using the
RTC.

I've also replaced high-frequency clock with low-frequency external
clock during system startup of the nRF51822. This brings a major win
in power consumption.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 103:9b881da47c92 1 /* mbed Microcontroller Library
mbed_official 103:9b881da47c92 2 * Copyright (c) 2006-2013 ARM Limited
mbed_official 103:9b881da47c92 3 *
mbed_official 103:9b881da47c92 4 * Licensed under the Apache License, Version 2.0 (the "License");
mbed_official 103:9b881da47c92 5 * you may not use this file except in compliance with the License.
mbed_official 103:9b881da47c92 6 * You may obtain a copy of the License at
mbed_official 103:9b881da47c92 7 *
mbed_official 103:9b881da47c92 8 * http://www.apache.org/licenses/LICENSE-2.0
mbed_official 103:9b881da47c92 9 *
mbed_official 103:9b881da47c92 10 * Unless required by applicable law or agreed to in writing, software
mbed_official 103:9b881da47c92 11 * distributed under the License is distributed on an "AS IS" BASIS,
mbed_official 103:9b881da47c92 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbed_official 103:9b881da47c92 13 * See the License for the specific language governing permissions and
mbed_official 103:9b881da47c92 14 * limitations under the License.
mbed_official 103:9b881da47c92 15 */
mbed_official 103:9b881da47c92 16 #include <stddef.h>
mbed_official 103:9b881da47c92 17 #include "us_ticker_api.h"
mbed_official 103:9b881da47c92 18 #include "PeripheralNames.h"
mbed_official 103:9b881da47c92 19
mbed_official 117:e0a7df0a9a56 20 #define US_TICKER_TIMER_IRQn RIT_IRQn
mbed_official 103:9b881da47c92 21
mbed_official 103:9b881da47c92 22 int us_ticker_inited = 0;
mbed_official 103:9b881da47c92 23
mbed_official 103:9b881da47c92 24 void us_ticker_init(void) {
mbed_official 103:9b881da47c92 25 if (us_ticker_inited) return;
mbed_official 103:9b881da47c92 26 us_ticker_inited = 1;
mbed_official 103:9b881da47c92 27
mbed_official 117:e0a7df0a9a56 28 // Enable the RIT clock
mbed_official 117:e0a7df0a9a56 29 LPC_SYSCON->SYSAHBCLKCTRL1 |= (1 << 1);
mbed_official 103:9b881da47c92 30
mbed_official 117:e0a7df0a9a56 31 // Clear peripheral reset the RIT
mbed_official 117:e0a7df0a9a56 32 LPC_SYSCON->PRESETCTRL1 |= (1 << 1);
mbed_official 117:e0a7df0a9a56 33 LPC_SYSCON->PRESETCTRL1 &= ~(1 << 1);
mbed_official 103:9b881da47c92 34
mbed_official 117:e0a7df0a9a56 35 LPC_RIT->MASK = 0;
mbed_official 117:e0a7df0a9a56 36 LPC_RIT->MASK_H = 0;
mbed_official 103:9b881da47c92 37
mbed_official 117:e0a7df0a9a56 38 LPC_RIT->COUNTER = 0;
mbed_official 117:e0a7df0a9a56 39 LPC_RIT->COUNTER_H = 0;
mbed_official 117:e0a7df0a9a56 40
mbed_official 117:e0a7df0a9a56 41 LPC_RIT->COMPVAL = 0xffffffff;
mbed_official 117:e0a7df0a9a56 42 LPC_RIT->COMPVAL_H = 0x0000ffff;
mbed_official 117:e0a7df0a9a56 43
mbed_official 117:e0a7df0a9a56 44 // Timer enable, enable for debug
mbed_official 117:e0a7df0a9a56 45 LPC_RIT->CTRL = 0xC;
mbed_official 103:9b881da47c92 46
mbed_official 103:9b881da47c92 47 NVIC_SetVector(US_TICKER_TIMER_IRQn, (uint32_t)us_ticker_irq_handler);
mbed_official 103:9b881da47c92 48 NVIC_EnableIRQ(US_TICKER_TIMER_IRQn);
mbed_official 103:9b881da47c92 49 }
mbed_official 103:9b881da47c92 50
mbed_official 103:9b881da47c92 51 uint32_t us_ticker_read() {
mbed_official 103:9b881da47c92 52 if (!us_ticker_inited)
mbed_official 103:9b881da47c92 53 us_ticker_init();
mbed_official 103:9b881da47c92 54
mbed_official 117:e0a7df0a9a56 55 uint64_t temp;
mbed_official 117:e0a7df0a9a56 56 temp = LPC_RIT->COUNTER | ((uint64_t)LPC_RIT->COUNTER_H << 32);
mbed_official 117:e0a7df0a9a56 57 temp /= (SystemCoreClock/1000000);
mbed_official 117:e0a7df0a9a56 58 return (uint32_t)temp;
mbed_official 103:9b881da47c92 59 }
mbed_official 103:9b881da47c92 60
mbed_official 304:89b9c3a9a045 61 void us_ticker_set_interrupt(timestamp_t timestamp) {
mbed_official 117:e0a7df0a9a56 62 uint64_t temp = ((uint64_t)timestamp * (SystemCoreClock/1000000));
mbed_official 117:e0a7df0a9a56 63 LPC_RIT->COMPVAL = (temp & 0xFFFFFFFFL);
mbed_official 117:e0a7df0a9a56 64 LPC_RIT->COMPVAL_H = ((temp >> 32)& 0x0000FFFFL);
mbed_official 103:9b881da47c92 65 }
mbed_official 103:9b881da47c92 66
mbed_official 103:9b881da47c92 67 void us_ticker_disable_interrupt(void) {
mbed_official 117:e0a7df0a9a56 68 LPC_RIT->CTRL |= (1 << 3);
mbed_official 103:9b881da47c92 69 }
mbed_official 103:9b881da47c92 70
mbed_official 103:9b881da47c92 71 void us_ticker_clear_interrupt(void) {
mbed_official 117:e0a7df0a9a56 72 LPC_RIT->CTRL |= (1 << 0);
mbed_official 103:9b881da47c92 73 }