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.
targets/hal/TARGET_NXP/TARGET_LPC15XX/us_ticker.c@559:a5bce224b5d8, 2015-06-04 (annotated)
- Committer:
- mbed_official
- Date:
- Thu Jun 04 16:15:09 2015 +0100
- Revision:
- 559:a5bce224b5d8
- Parent:
- 304:89b9c3a9a045
Synchronized with git revision 23e19ca3b52202fcc0a78ec2e94e5f20e2a4fd2a
Full URL: https://github.com/mbedmicro/mbed/commit/23e19ca3b52202fcc0a78ec2e94e5f20e2a4fd2a/
NUCLEO_F446RE - Clean-up of PeripheralPins.c + add DAC
Who changed what in which revision?
User | Revision | Line number | New 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 | } |