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 Jan 26 17:45:07 2015 +0000
Revision:
453:a290c6acf95e
Parent:
452:a2b30f7d1bc5
Child:
495:01cb89f68337
Synchronized with git revision 18a61f8a2a132c6c869d50eac7cb656fa994cff1

Full URL: https://github.com/mbedmicro/mbed/commit/18a61f8a2a132c6c869d50eac7cb656fa994cff1/

Tools - expoters init file - tempdir name fix

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 453:a290c6acf95e 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 304:89b9c3a9a045 33 us_ticker_inited = true;
mbed_official 85:e1a8e879a6a9 34 }
mbed_official 85:e1a8e879a6a9 35
mbed_official 300:55638feb26a4 36 uint32_t us_ticker_read()
mbed_official 300:55638feb26a4 37 {
mbed_official 304:89b9c3a9a045 38 if (!us_ticker_inited) {
mbed_official 304:89b9c3a9a045 39 us_ticker_init();
mbed_official 304:89b9c3a9a045 40 }
mbed_official 304:89b9c3a9a045 41
mbed_official 452:a2b30f7d1bc5 42 uint64_t value;
mbed_official 304:89b9c3a9a045 43 app_timer_cnt_get(&value); /* This returns the RTC counter (which is fed by the 32khz crystal clock source) */
mbed_official 361:56c2a6244bba 44 return ((value * 1000000) / (uint32_t)APP_TIMER_CLOCK_FREQ); /* Return a pseudo microsecond counter value.
mbed_official 304:89b9c3a9a045 45 * This is only as precise as the 32khz low-freq
mbed_official 304:89b9c3a9a045 46 * clock source, but could be adequate.*/
mbed_official 304:89b9c3a9a045 47 }
mbed_official 304:89b9c3a9a045 48
mbed_official 304:89b9c3a9a045 49 /* An adaptor to interface us_ticker_irq_handler with the app_timer callback.
mbed_official 304:89b9c3a9a045 50 * Needed because the irq_handler() doesn't take any parameter.*/
mbed_official 304:89b9c3a9a045 51 static void us_ticker_app_timer_callback(void *context)
mbed_official 304:89b9c3a9a045 52 {
mbed_official 304:89b9c3a9a045 53 us_ticker_appTimerRunning = false;
mbed_official 304:89b9c3a9a045 54 us_ticker_irq_handler();
mbed_official 304:89b9c3a9a045 55 }
mbed_official 304:89b9c3a9a045 56
mbed_official 304:89b9c3a9a045 57 void us_ticker_set_interrupt(timestamp_t timestamp)
mbed_official 304:89b9c3a9a045 58 {
mbed_official 304:89b9c3a9a045 59 if (!us_ticker_inited) {
mbed_official 85:e1a8e879a6a9 60 us_ticker_init();
mbed_official 85:e1a8e879a6a9 61 }
mbed_official 300:55638feb26a4 62
mbed_official 304:89b9c3a9a045 63 if (us_ticker_appTimerID == TIMER_NULL) {
mbed_official 304:89b9c3a9a045 64 if (app_timer_create(&us_ticker_appTimerID, APP_TIMER_MODE_SINGLE_SHOT, us_ticker_app_timer_callback) != NRF_SUCCESS) {
mbed_official 304:89b9c3a9a045 65 /* placeholder to do something to recover from error */
mbed_official 304:89b9c3a9a045 66 return;
mbed_official 304:89b9c3a9a045 67 }
mbed_official 300:55638feb26a4 68 }
mbed_official 85:e1a8e879a6a9 69
mbed_official 304:89b9c3a9a045 70 if (us_ticker_appTimerRunning) {
mbed_official 304:89b9c3a9a045 71 return;
mbed_official 300:55638feb26a4 72 }
mbed_official 300:55638feb26a4 73
mbed_official 452:a2b30f7d1bc5 74 uint64_t currentCounter64;
mbed_official 304:89b9c3a9a045 75 app_timer_cnt_get(&currentCounter64);
mbed_official 304:89b9c3a9a045 76 uint32_t currentCounter = currentCounter64 & MAX_RTC_COUNTER_VAL;
mbed_official 304:89b9c3a9a045 77 uint32_t targetCounter = ((uint32_t)((timestamp * (uint64_t)APP_TIMER_CLOCK_FREQ) / 1000000) + 1) & MAX_RTC_COUNTER_VAL;
mbed_official 304:89b9c3a9a045 78 uint32_t ticksToCount = (targetCounter >= currentCounter) ?
mbed_official 304:89b9c3a9a045 79 (targetCounter - currentCounter) : (MAX_RTC_COUNTER_VAL + 1) - (currentCounter - targetCounter);
mbed_official 361:56c2a6244bba 80 if (ticksToCount < APP_TIMER_MIN_TIMEOUT_TICKS) { /* Honour the minimum value of the timeout_ticks parameter of app_timer_start() */
mbed_official 361:56c2a6244bba 81 ticksToCount = APP_TIMER_MIN_TIMEOUT_TICKS;
mbed_official 300:55638feb26a4 82 }
mbed_official 361:56c2a6244bba 83
mbed_official 361:56c2a6244bba 84 uint32_t rc;
mbed_official 361:56c2a6244bba 85 rc = app_timer_start(us_ticker_appTimerID, ticksToCount, NULL /*p_context*/);
mbed_official 361:56c2a6244bba 86 if (rc != NRF_SUCCESS) {
mbed_official 361:56c2a6244bba 87 /* placeholder to do something to recover from error */
mbed_official 361:56c2a6244bba 88 return;
mbed_official 361:56c2a6244bba 89 }
mbed_official 361:56c2a6244bba 90 us_ticker_appTimerRunning = true;
mbed_official 85:e1a8e879a6a9 91 }
mbed_official 85:e1a8e879a6a9 92
mbed_official 300:55638feb26a4 93 void us_ticker_disable_interrupt(void)
mbed_official 300:55638feb26a4 94 {
mbed_official 304:89b9c3a9a045 95 if (us_ticker_appTimerRunning) {
mbed_official 452:a2b30f7d1bc5 96 if (app_timer_stop(us_ticker_appTimerID) == NRF_SUCCESS) {
mbed_official 452:a2b30f7d1bc5 97 us_ticker_appTimerRunning = false;
mbed_official 452:a2b30f7d1bc5 98 }
mbed_official 304:89b9c3a9a045 99 }
mbed_official 85:e1a8e879a6a9 100 }
mbed_official 300:55638feb26a4 101
mbed_official 300:55638feb26a4 102 void us_ticker_clear_interrupt(void)
mbed_official 300:55638feb26a4 103 {
mbed_official 304:89b9c3a9a045 104 if (us_ticker_appTimerRunning) {
mbed_official 452:a2b30f7d1bc5 105 if (app_timer_stop(us_ticker_appTimerID) == NRF_SUCCESS) {
mbed_official 452:a2b30f7d1bc5 106 us_ticker_appTimerRunning = false;
mbed_official 452:a2b30f7d1bc5 107 }
mbed_official 304:89b9c3a9a045 108 }
mbed_official 85:e1a8e879a6a9 109 }