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:
Mon Nov 10 07:45:06 2014 +0000
Revision:
395:bfce16e86ea4
Parent:
361:56c2a6244bba
Child:
452:a2b30f7d1bc5
Synchronized with git revision 8adfd82aa1bf8859ec08537ee7bcd4aaaec1769b

Full URL: https://github.com/mbedmicro/mbed/commit/8adfd82aa1bf8859ec08537ee7bcd4aaaec1769b/

Targets: LPC176X - Add repeater pinmode

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 85:e1a8e879a6a9 1 /* mbed Microcontroller Library
mbed_official 104:a6a92e2e5a92 2 * Copyright (c) 2013 Nordic Semiconductor
mbed_official 85:e1a8e879a6a9 3 *
mbed_official 85:e1a8e879a6a9 4 * Licensed under the Apache License, Version 2.0 (the "License");
mbed_official 85:e1a8e879a6a9 5 * you may not use this file except in compliance with the License.
mbed_official 85:e1a8e879a6a9 6 * You may obtain a copy of the License at
mbed_official 85:e1a8e879a6a9 7 *
mbed_official 85:e1a8e879a6a9 8 * http://www.apache.org/licenses/LICENSE-2.0
mbed_official 85:e1a8e879a6a9 9 *
mbed_official 85:e1a8e879a6a9 10 * Unless required by applicable law or agreed to in writing, software
mbed_official 85:e1a8e879a6a9 11 * distributed under the License is distributed on an "AS IS" BASIS,
mbed_official 85:e1a8e879a6a9 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbed_official 85:e1a8e879a6a9 13 * See the License for the specific language governing permissions and
mbed_official 85:e1a8e879a6a9 14 * limitations under the License.
mbed_official 85:e1a8e879a6a9 15 */
mbed_official 85:e1a8e879a6a9 16 #include <stddef.h>
mbed_official 85:e1a8e879a6a9 17 #include "us_ticker_api.h"
mbed_official 85:e1a8e879a6a9 18 #include "cmsis.h"
mbed_official 85:e1a8e879a6a9 19 #include "PeripheralNames.h"
mbed_official 304:89b9c3a9a045 20 #include "app_timer.h"
mbed_official 127:ce7cebc0511f 21
mbed_official 304:89b9c3a9a045 22 static bool us_ticker_inited = false;
mbed_official 304:89b9c3a9a045 23 static volatile bool us_ticker_appTimerRunning = false;
mbed_official 304:89b9c3a9a045 24 static app_timer_id_t us_ticker_appTimerID = TIMER_NULL;
mbed_official 300:55638feb26a4 25
mbed_official 300:55638feb26a4 26 void us_ticker_init(void)
mbed_official 300:55638feb26a4 27 {
mbed_official 304:89b9c3a9a045 28 if (us_ticker_inited) {
mbed_official 85:e1a8e879a6a9 29 return;
mbed_official 85:e1a8e879a6a9 30 }
mbed_official 300:55638feb26a4 31
mbed_official 304:89b9c3a9a045 32 APP_TIMER_INIT(0 /*CFG_TIMER_PRESCALER*/ , 1 /*CFG_TIMER_MAX_INSTANCE*/, 1 /*CFG_TIMER_OPERATION_QUEUE_SIZE*/, false /*CFG_SCHEDULER_ENABLE*/);
mbed_official 300:55638feb26a4 33
mbed_official 304:89b9c3a9a045 34 us_ticker_inited = true;
mbed_official 85:e1a8e879a6a9 35 }
mbed_official 85:e1a8e879a6a9 36
mbed_official 300:55638feb26a4 37 uint32_t us_ticker_read()
mbed_official 300:55638feb26a4 38 {
mbed_official 304:89b9c3a9a045 39 if (!us_ticker_inited) {
mbed_official 304:89b9c3a9a045 40 us_ticker_init();
mbed_official 304:89b9c3a9a045 41 }
mbed_official 304:89b9c3a9a045 42
mbed_official 304:89b9c3a9a045 43 timestamp_t value;
mbed_official 304:89b9c3a9a045 44 app_timer_cnt_get(&value); /* This returns the RTC counter (which is fed by the 32khz crystal clock source) */
mbed_official 361:56c2a6244bba 45 return ((value * 1000000) / (uint32_t)APP_TIMER_CLOCK_FREQ); /* Return a pseudo microsecond counter value.
mbed_official 304:89b9c3a9a045 46 * This is only as precise as the 32khz low-freq
mbed_official 304:89b9c3a9a045 47 * clock source, but could be adequate.*/
mbed_official 304:89b9c3a9a045 48 }
mbed_official 304:89b9c3a9a045 49
mbed_official 304:89b9c3a9a045 50 /* An adaptor to interface us_ticker_irq_handler with the app_timer callback.
mbed_official 304:89b9c3a9a045 51 * Needed because the irq_handler() doesn't take any parameter.*/
mbed_official 304:89b9c3a9a045 52 static void us_ticker_app_timer_callback(void *context)
mbed_official 304:89b9c3a9a045 53 {
mbed_official 304:89b9c3a9a045 54 us_ticker_appTimerRunning = false;
mbed_official 304:89b9c3a9a045 55 us_ticker_irq_handler();
mbed_official 304:89b9c3a9a045 56 }
mbed_official 304:89b9c3a9a045 57
mbed_official 304:89b9c3a9a045 58 void us_ticker_set_interrupt(timestamp_t timestamp)
mbed_official 304:89b9c3a9a045 59 {
mbed_official 304:89b9c3a9a045 60 if (!us_ticker_inited) {
mbed_official 85:e1a8e879a6a9 61 us_ticker_init();
mbed_official 85:e1a8e879a6a9 62 }
mbed_official 300:55638feb26a4 63
mbed_official 304:89b9c3a9a045 64 if (us_ticker_appTimerID == TIMER_NULL) {
mbed_official 304:89b9c3a9a045 65 if (app_timer_create(&us_ticker_appTimerID, APP_TIMER_MODE_SINGLE_SHOT, us_ticker_app_timer_callback) != NRF_SUCCESS) {
mbed_official 304:89b9c3a9a045 66 /* placeholder to do something to recover from error */
mbed_official 304:89b9c3a9a045 67 return;
mbed_official 304:89b9c3a9a045 68 }
mbed_official 300:55638feb26a4 69 }
mbed_official 85:e1a8e879a6a9 70
mbed_official 304:89b9c3a9a045 71 if (us_ticker_appTimerRunning) {
mbed_official 304:89b9c3a9a045 72 return;
mbed_official 300:55638feb26a4 73 }
mbed_official 300:55638feb26a4 74
mbed_official 304:89b9c3a9a045 75 timestamp_t currentCounter64;
mbed_official 304:89b9c3a9a045 76 app_timer_cnt_get(&currentCounter64);
mbed_official 304:89b9c3a9a045 77 uint32_t currentCounter = currentCounter64 & MAX_RTC_COUNTER_VAL;
mbed_official 304:89b9c3a9a045 78 uint32_t targetCounter = ((uint32_t)((timestamp * (uint64_t)APP_TIMER_CLOCK_FREQ) / 1000000) + 1) & MAX_RTC_COUNTER_VAL;
mbed_official 304:89b9c3a9a045 79 uint32_t ticksToCount = (targetCounter >= currentCounter) ?
mbed_official 304:89b9c3a9a045 80 (targetCounter - currentCounter) : (MAX_RTC_COUNTER_VAL + 1) - (currentCounter - targetCounter);
mbed_official 361:56c2a6244bba 81 if (ticksToCount < APP_TIMER_MIN_TIMEOUT_TICKS) { /* Honour the minimum value of the timeout_ticks parameter of app_timer_start() */
mbed_official 361:56c2a6244bba 82 ticksToCount = APP_TIMER_MIN_TIMEOUT_TICKS;
mbed_official 300:55638feb26a4 83 }
mbed_official 361:56c2a6244bba 84
mbed_official 361:56c2a6244bba 85 uint32_t rc;
mbed_official 361:56c2a6244bba 86 rc = app_timer_start(us_ticker_appTimerID, ticksToCount, NULL /*p_context*/);
mbed_official 361:56c2a6244bba 87 if (rc != NRF_SUCCESS) {
mbed_official 361:56c2a6244bba 88 /* placeholder to do something to recover from error */
mbed_official 361:56c2a6244bba 89 return;
mbed_official 361:56c2a6244bba 90 }
mbed_official 361:56c2a6244bba 91 us_ticker_appTimerRunning = true;
mbed_official 85:e1a8e879a6a9 92 }
mbed_official 85:e1a8e879a6a9 93
mbed_official 300:55638feb26a4 94 void us_ticker_disable_interrupt(void)
mbed_official 300:55638feb26a4 95 {
mbed_official 304:89b9c3a9a045 96 if (us_ticker_appTimerRunning) {
mbed_official 304:89b9c3a9a045 97 app_timer_stop(us_ticker_appTimerID);
mbed_official 304:89b9c3a9a045 98 }
mbed_official 85:e1a8e879a6a9 99 }
mbed_official 300:55638feb26a4 100
mbed_official 300:55638feb26a4 101 void us_ticker_clear_interrupt(void)
mbed_official 300:55638feb26a4 102 {
mbed_official 304:89b9c3a9a045 103 if (us_ticker_appTimerRunning) {
mbed_official 304:89b9c3a9a045 104 app_timer_stop(us_ticker_appTimerID);
mbed_official 304:89b9c3a9a045 105 }
mbed_official 85:e1a8e879a6a9 106 }