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:
mbed_official
Date:
Fri Sep 11 09:30:09 2015 +0100
Revision:
621:9c82b0f79f3d
Parent:
554:edd95c0879f8
Synchronized with git revision 6c1d63e069ab9bd86de92e8296ca783681257538

Full URL: https://github.com/mbedmicro/mbed/commit/6c1d63e069ab9bd86de92e8296ca783681257538/

ignore target files not supported by the yotta module

Who changed what in which revision?

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