mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
bogdanm
Date:
Mon Aug 19 18:17:02 2013 +0300
Revision:
19:398f4c622e1b
Sync with official mbed library release 66

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bogdanm 19:398f4c622e1b 1 /* mbed Microcontroller Library
bogdanm 19:398f4c622e1b 2 * Copyright (c) 2006-2013 ARM Limited
bogdanm 19:398f4c622e1b 3 *
bogdanm 19:398f4c622e1b 4 * Licensed under the Apache License, Version 2.0 (the "License");
bogdanm 19:398f4c622e1b 5 * you may not use this file except in compliance with the License.
bogdanm 19:398f4c622e1b 6 * You may obtain a copy of the License at
bogdanm 19:398f4c622e1b 7 *
bogdanm 19:398f4c622e1b 8 * http://www.apache.org/licenses/LICENSE-2.0
bogdanm 19:398f4c622e1b 9 *
bogdanm 19:398f4c622e1b 10 * Unless required by applicable law or agreed to in writing, software
bogdanm 19:398f4c622e1b 11 * distributed under the License is distributed on an "AS IS" BASIS,
bogdanm 19:398f4c622e1b 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
bogdanm 19:398f4c622e1b 13 * See the License for the specific language governing permissions and
bogdanm 19:398f4c622e1b 14 * limitations under the License.
bogdanm 19:398f4c622e1b 15 */
bogdanm 19:398f4c622e1b 16 #include <stddef.h>
bogdanm 19:398f4c622e1b 17 #include "us_ticker_api.h"
bogdanm 19:398f4c622e1b 18 #include "PeripheralNames.h"
bogdanm 19:398f4c622e1b 19
bogdanm 19:398f4c622e1b 20 #define US_TICKER_TIMER ((LPC_TMR_TypeDef *)LPC_CT32B1_BASE)
bogdanm 19:398f4c622e1b 21 #define US_TICKER_TIMER_IRQn TIMER_32_1_IRQn
bogdanm 19:398f4c622e1b 22
bogdanm 19:398f4c622e1b 23 int us_ticker_inited = 0;
bogdanm 19:398f4c622e1b 24
bogdanm 19:398f4c622e1b 25 void us_ticker_init(void) {
bogdanm 19:398f4c622e1b 26 if (us_ticker_inited) return;
bogdanm 19:398f4c622e1b 27 us_ticker_inited = 1;
bogdanm 19:398f4c622e1b 28
bogdanm 19:398f4c622e1b 29 LPC_SYSCON->SYSAHBCLKCTRL |= (1<<10); // Clock TIMER_1
bogdanm 19:398f4c622e1b 30 uint32_t PCLK = SystemCoreClock;
bogdanm 19:398f4c622e1b 31
bogdanm 19:398f4c622e1b 32 US_TICKER_TIMER->TCR = 0x2; // reset
bogdanm 19:398f4c622e1b 33
bogdanm 19:398f4c622e1b 34 uint32_t prescale = PCLK / 1000000; // default to 1MHz (1 us ticks)
bogdanm 19:398f4c622e1b 35 US_TICKER_TIMER->PR = prescale - 1;
bogdanm 19:398f4c622e1b 36 US_TICKER_TIMER->TCR = 1; // enable = 1, reset = 0
bogdanm 19:398f4c622e1b 37
bogdanm 19:398f4c622e1b 38 NVIC_SetVector(US_TICKER_TIMER_IRQn, (uint32_t)us_ticker_irq_handler);
bogdanm 19:398f4c622e1b 39 NVIC_EnableIRQ(US_TICKER_TIMER_IRQn);
bogdanm 19:398f4c622e1b 40 }
bogdanm 19:398f4c622e1b 41
bogdanm 19:398f4c622e1b 42 uint32_t us_ticker_read() {
bogdanm 19:398f4c622e1b 43 if (!us_ticker_inited)
bogdanm 19:398f4c622e1b 44 us_ticker_init();
bogdanm 19:398f4c622e1b 45
bogdanm 19:398f4c622e1b 46 return US_TICKER_TIMER->TC;
bogdanm 19:398f4c622e1b 47 }
bogdanm 19:398f4c622e1b 48
bogdanm 19:398f4c622e1b 49 void us_ticker_set_interrupt(unsigned int timestamp) {
bogdanm 19:398f4c622e1b 50 // set match value
bogdanm 19:398f4c622e1b 51 US_TICKER_TIMER->MR0 = timestamp;
bogdanm 19:398f4c622e1b 52 // enable match interrupt
bogdanm 19:398f4c622e1b 53 US_TICKER_TIMER->MCR |= 1;
bogdanm 19:398f4c622e1b 54 }
bogdanm 19:398f4c622e1b 55
bogdanm 19:398f4c622e1b 56 void us_ticker_disable_interrupt(void) {
bogdanm 19:398f4c622e1b 57 US_TICKER_TIMER->MCR &= ~1;
bogdanm 19:398f4c622e1b 58 }
bogdanm 19:398f4c622e1b 59
bogdanm 19:398f4c622e1b 60 void us_ticker_clear_interrupt(void) {
bogdanm 19:398f4c622e1b 61 US_TICKER_TIMER->IR = 1;
bogdanm 19:398f4c622e1b 62 }