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 25 14:15:10 2015 +0100
Revision:
627:4fa1328d9c60
Parent:
548:1abac31e188e
Synchronized with git revision fe238a91ab7a4d1d72c4cab9da04967c619d54ad

Full URL: https://github.com/mbedmicro/mbed/commit/fe238a91ab7a4d1d72c4cab9da04967c619d54ad/

Silicon Labs - Add support for low-power async Serial

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 627:4fa1328d9c60 1 /***************************************************************************//**
mbed_official 627:4fa1328d9c60 2 * @file lp_ticker.c
mbed_official 627:4fa1328d9c60 3 *******************************************************************************
mbed_official 627:4fa1328d9c60 4 * @section License
mbed_official 627:4fa1328d9c60 5 * <b>(C) Copyright 2015 Silicon Labs, http://www.silabs.com</b>
mbed_official 627:4fa1328d9c60 6 *******************************************************************************
mbed_official 525:c320967f86b9 7 *
mbed_official 627:4fa1328d9c60 8 * Permission is granted to anyone to use this software for any purpose,
mbed_official 627:4fa1328d9c60 9 * including commercial applications, and to alter it and redistribute it
mbed_official 627:4fa1328d9c60 10 * freely, subject to the following restrictions:
mbed_official 525:c320967f86b9 11 *
mbed_official 627:4fa1328d9c60 12 * 1. The origin of this software must not be misrepresented; you must not
mbed_official 627:4fa1328d9c60 13 * claim that you wrote the original software.
mbed_official 627:4fa1328d9c60 14 * 2. Altered source versions must be plainly marked as such, and must not be
mbed_official 627:4fa1328d9c60 15 * misrepresented as being the original software.
mbed_official 627:4fa1328d9c60 16 * 3. This notice may not be removed or altered from any source distribution.
mbed_official 525:c320967f86b9 17 *
mbed_official 627:4fa1328d9c60 18 * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Silicon Labs has no
mbed_official 627:4fa1328d9c60 19 * obligation to support this Software. Silicon Labs is providing the
mbed_official 627:4fa1328d9c60 20 * Software "AS IS", with no express or implied warranties of any kind,
mbed_official 627:4fa1328d9c60 21 * including, but not limited to, any implied warranties of merchantability
mbed_official 627:4fa1328d9c60 22 * or fitness for any particular purpose or warranties against infringement
mbed_official 627:4fa1328d9c60 23 * of any proprietary rights of a third party.
mbed_official 627:4fa1328d9c60 24 *
mbed_official 627:4fa1328d9c60 25 * Silicon Labs will not be liable for any consequential, incidental, or
mbed_official 627:4fa1328d9c60 26 * special damages, or any other relief, or for any claim by any third party,
mbed_official 627:4fa1328d9c60 27 * arising from your use of this Software.
mbed_official 627:4fa1328d9c60 28 *
mbed_official 627:4fa1328d9c60 29 ******************************************************************************/
mbed_official 525:c320967f86b9 30
mbed_official 525:c320967f86b9 31 #include "device.h"
mbed_official 525:c320967f86b9 32 #if DEVICE_LOWPOWERTIMER
mbed_official 525:c320967f86b9 33
mbed_official 525:c320967f86b9 34 #include "rtc_api.h"
mbed_official 525:c320967f86b9 35 #include "rtc_api_HAL.h"
mbed_official 525:c320967f86b9 36 #include "lp_ticker_api.h"
mbed_official 525:c320967f86b9 37
mbed_official 525:c320967f86b9 38 void lp_ticker_init()
mbed_official 525:c320967f86b9 39 {
mbed_official 525:c320967f86b9 40 rtc_init_real(RTC_INIT_LPTIMER);
mbed_official 525:c320967f86b9 41 rtc_set_comp0_handler((uint32_t)lp_ticker_irq_handler);
mbed_official 525:c320967f86b9 42 }
mbed_official 525:c320967f86b9 43
mbed_official 548:1abac31e188e 44 void lp_ticker_set_interrupt(timestamp_t timestamp)
mbed_official 548:1abac31e188e 45 {
mbed_official 548:1abac31e188e 46 uint64_t timestamp_ticks;
mbed_official 525:c320967f86b9 47 uint64_t current_ticks = RTC_CounterGet();
mbed_official 525:c320967f86b9 48 timestamp_t current_time = ((uint64_t)(current_ticks * 1000000) / (LOW_ENERGY_CLOCK_FREQUENCY / RTC_CLOCKDIV_INT));
mbed_official 548:1abac31e188e 49
mbed_official 548:1abac31e188e 50
mbed_official 525:c320967f86b9 51 /* calculate offset value */
mbed_official 525:c320967f86b9 52 timestamp_t offset = timestamp - current_time;
mbed_official 525:c320967f86b9 53 if(offset > 0xEFFFFFFF) offset = 100;
mbed_official 548:1abac31e188e 54
mbed_official 525:c320967f86b9 55 /* map offset to RTC value */
mbed_official 548:1abac31e188e 56 // ticks = offset * RTC frequency div 1000000
mbed_official 548:1abac31e188e 57 timestamp_ticks = ((uint64_t)offset * (LOW_ENERGY_CLOCK_FREQUENCY / RTC_CLOCKDIV_INT)) / 1000000;
mbed_official 525:c320967f86b9 58 timestamp_ticks += current_ticks;
mbed_official 525:c320967f86b9 59
mbed_official 548:1abac31e188e 60 /* RTC has 24 bit resolution */
mbed_official 548:1abac31e188e 61 timestamp_ticks &= 0xFFFFFF;
mbed_official 525:c320967f86b9 62
mbed_official 525:c320967f86b9 63 /* check for RTC limitation */
mbed_official 525:c320967f86b9 64 if((timestamp_ticks - RTC_CounterGet()) >= 0x800000) timestamp_ticks = RTC_CounterGet() + 2;
mbed_official 548:1abac31e188e 65
mbed_official 548:1abac31e188e 66 /* Set callback */
mbed_official 548:1abac31e188e 67 RTC_FreezeEnable(true);
mbed_official 548:1abac31e188e 68 RTC_CompareSet(0, (uint32_t)timestamp_ticks);
mbed_official 548:1abac31e188e 69 RTC_IntEnable(RTC_IF_COMP0);
mbed_official 548:1abac31e188e 70 RTC_FreezeEnable(false);
mbed_official 525:c320967f86b9 71 }
mbed_official 525:c320967f86b9 72
mbed_official 548:1abac31e188e 73 inline void lp_ticker_disable_interrupt()
mbed_official 548:1abac31e188e 74 {
mbed_official 548:1abac31e188e 75 RTC_IntDisable(RTC_IF_COMP0);
mbed_official 525:c320967f86b9 76 }
mbed_official 525:c320967f86b9 77
mbed_official 548:1abac31e188e 78 inline void lp_ticker_clear_interrupt()
mbed_official 548:1abac31e188e 79 {
mbed_official 548:1abac31e188e 80 RTC_IntClear(RTC_IF_COMP0);
mbed_official 525:c320967f86b9 81 }
mbed_official 525:c320967f86b9 82
mbed_official 548:1abac31e188e 83 timestamp_t lp_ticker_read()
mbed_official 548:1abac31e188e 84 {
mbed_official 548:1abac31e188e 85 uint64_t ticks_temp;
mbed_official 548:1abac31e188e 86 uint64_t ticks = RTC_CounterGet();
mbed_official 525:c320967f86b9 87
mbed_official 548:1abac31e188e 88 /* ticks = counter tick value
mbed_official 548:1abac31e188e 89 * timestamp = value in microseconds
mbed_official 548:1abac31e188e 90 * timestamp = ticks * 1.000.000 / RTC frequency
mbed_official 548:1abac31e188e 91 */
mbed_official 525:c320967f86b9 92
mbed_official 548:1abac31e188e 93 ticks_temp = (ticks * 1000000) / (LOW_ENERGY_CLOCK_FREQUENCY / RTC_CLOCKDIV_INT);
mbed_official 548:1abac31e188e 94 return (timestamp_t) (ticks_temp & 0xFFFFFFFF);
mbed_official 525:c320967f86b9 95 }
mbed_official 525:c320967f86b9 96
mbed_official 525:c320967f86b9 97 #endif