]>
git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC15XX/us_ticker.c
1 /* mbed Microcontroller Library
2 * Copyright (c) 2006-2013 ARM Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "us_ticker_api.h"
18 #include "PeripheralNames.h"
20 #define US_TICKER_TIMER_IRQn RIT_IRQn
22 int us_ticker_inited
= 0;
24 void us_ticker_init(void) {
25 if (us_ticker_inited
) return;
28 // Enable the RIT clock
29 LPC_SYSCON
->SYSAHBCLKCTRL1
|= (1 << 1);
31 // Clear peripheral reset the RIT
32 LPC_SYSCON
->PRESETCTRL1
|= (1 << 1);
33 LPC_SYSCON
->PRESETCTRL1
&= ~(1 << 1);
39 LPC_RIT
->COUNTER_H
= 0;
41 LPC_RIT
->COMPVAL
= 0xffffffff;
42 LPC_RIT
->COMPVAL_H
= 0x0000ffff;
44 // Timer enable, enable for debug
47 NVIC_SetVector(US_TICKER_TIMER_IRQn
, (uint32_t)us_ticker_irq_handler
);
48 NVIC_EnableIRQ(US_TICKER_TIMER_IRQn
);
51 uint32_t us_ticker_read() {
52 if (!us_ticker_inited
)
56 temp
= LPC_RIT
->COUNTER
| ((uint64_t)LPC_RIT
->COUNTER_H
<< 32);
57 temp
/= (SystemCoreClock
/1000000);
58 return (uint32_t)temp
;
61 void us_ticker_set_interrupt(timestamp_t timestamp
) {
62 uint64_t temp
= ((uint64_t)timestamp
* (SystemCoreClock
/1000000));
63 LPC_RIT
->COMPVAL
= (temp
& 0xFFFFFFFFL
);
64 LPC_RIT
->COMPVAL_H
= ((temp
>> 32)& 0x0000FFFFL
);
67 void us_ticker_disable_interrupt(void) {
68 LPC_RIT
->CTRL
|= (1 << 3);
71 void us_ticker_clear_interrupt(void) {
72 LPC_RIT
->CTRL
|= (1 << 0);