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 Dec 15 09:00:08 2014 +0000
Revision:
437:0b72c0f86db6
Parent:
430:d406b7919023
Child:
460:3bcf9be0332c
Synchronized with git revision f3acd0e7aa3cbba2a6b264dc2e9f596891dea133

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

Tools: changed device name from nRF51822_xxAA -> nRF51xxx on all Nordic boards

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 390:35c2c1cf29cd 1 /* mbed Microcontroller Library
mbed_official 390:35c2c1cf29cd 2 * Copyright (c) 2006-2013 ARM Limited
mbed_official 390:35c2c1cf29cd 3 *
mbed_official 390:35c2c1cf29cd 4 * Licensed under the Apache License, Version 2.0 (the "License");
mbed_official 390:35c2c1cf29cd 5 * you may not use this file except in compliance with the License.
mbed_official 390:35c2c1cf29cd 6 * You may obtain a copy of the License at
mbed_official 390:35c2c1cf29cd 7 *
mbed_official 390:35c2c1cf29cd 8 * http://www.apache.org/licenses/LICENSE-2.0
mbed_official 390:35c2c1cf29cd 9 *
mbed_official 390:35c2c1cf29cd 10 * Unless required by applicable law or agreed to in writing, software
mbed_official 390:35c2c1cf29cd 11 * distributed under the License is distributed on an "AS IS" BASIS,
mbed_official 390:35c2c1cf29cd 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbed_official 390:35c2c1cf29cd 13 * See the License for the specific language governing permissions and
mbed_official 390:35c2c1cf29cd 14 * limitations under the License.
mbed_official 390:35c2c1cf29cd 15 */
mbed_official 390:35c2c1cf29cd 16 #include <stddef.h>
mbed_official 390:35c2c1cf29cd 17 #include "us_ticker_api.h"
mbed_official 390:35c2c1cf29cd 18 #include "PeripheralNames.h"
mbed_official 430:d406b7919023 19 #include "ostm_iodefine.h"
mbed_official 430:d406b7919023 20
mbed_official 430:d406b7919023 21 #include "RZ_A1_Init.h"
mbed_official 430:d406b7919023 22 #include "MBRZA1H.h"
mbed_official 390:35c2c1cf29cd 23
mbed_official 430:d406b7919023 24 #define US_TICKER_TIMER_IRQn (OSTMI1TINT_IRQn)
mbed_official 430:d406b7919023 25 #define CPG_STBCR5_BIT_MSTP50 (0x01u) /* OSTM1 */
mbed_official 430:d406b7919023 26
mbed_official 430:d406b7919023 27 #define US_TICKER_CLOCK_US_DEV (1000000)
mbed_official 390:35c2c1cf29cd 28
mbed_official 390:35c2c1cf29cd 29 int us_ticker_inited = 0;
mbed_official 430:d406b7919023 30 static double count_clock = 0;
mbed_official 437:0b72c0f86db6 31 static uint32_t last_read = 0;
mbed_official 437:0b72c0f86db6 32 static uint32_t wrap_arround = 0;
mbed_official 390:35c2c1cf29cd 33
mbed_official 390:35c2c1cf29cd 34 void us_ticker_interrupt(void) {
mbed_official 390:35c2c1cf29cd 35 us_ticker_irq_handler();
mbed_official 390:35c2c1cf29cd 36 }
mbed_official 390:35c2c1cf29cd 37
mbed_official 390:35c2c1cf29cd 38 void us_ticker_init(void) {
mbed_official 390:35c2c1cf29cd 39 if (us_ticker_inited) return;
mbed_official 390:35c2c1cf29cd 40 us_ticker_inited = 1;
mbed_official 437:0b72c0f86db6 41
mbed_official 430:d406b7919023 42 /* set Counter Clock(us) */
mbed_official 430:d406b7919023 43 if (false == RZ_A1_IsClockMode0()) {
mbed_official 437:0b72c0f86db6 44 count_clock = ((double)CM1_RENESAS_RZ_A1_P0_CLK / (double)US_TICKER_CLOCK_US_DEV);
mbed_official 430:d406b7919023 45 } else {
mbed_official 437:0b72c0f86db6 46 count_clock = ((double)CM0_RENESAS_RZ_A1_P0_CLK / (double)US_TICKER_CLOCK_US_DEV);
mbed_official 430:d406b7919023 47 }
mbed_official 430:d406b7919023 48
mbed_official 390:35c2c1cf29cd 49 /* Power Control for Peripherals */
mbed_official 430:d406b7919023 50 CPGSTBCR5 &= ~(CPG_STBCR5_BIT_MSTP50); /* enable OSTM1 clock */
mbed_official 390:35c2c1cf29cd 51
mbed_official 390:35c2c1cf29cd 52 // timer settings
mbed_official 430:d406b7919023 53 OSTM1TT = 0x01; /* Stop the counter and clears the OSTM1TE bit. */
mbed_official 430:d406b7919023 54 OSTM1CTL = 0x02; /* Free running timer mode. Interrupt disabled when star counter */
mbed_official 390:35c2c1cf29cd 55
mbed_official 430:d406b7919023 56 OSTM1TS = 0x1; /* Start the counter and sets the OSTM0TE bit. */
mbed_official 390:35c2c1cf29cd 57
mbed_official 390:35c2c1cf29cd 58 // INTC settings
mbed_official 430:d406b7919023 59 InterruptHandlerRegister(US_TICKER_TIMER_IRQn, (void (*)(uint32_t))us_ticker_interrupt);
mbed_official 430:d406b7919023 60 GIC_SetPriority(US_TICKER_TIMER_IRQn, 5);
mbed_official 430:d406b7919023 61 GIC_EnableIRQ(US_TICKER_TIMER_IRQn);
mbed_official 390:35c2c1cf29cd 62 }
mbed_official 390:35c2c1cf29cd 63
mbed_official 390:35c2c1cf29cd 64 uint32_t us_ticker_read() {
mbed_official 390:35c2c1cf29cd 65 uint32_t val;
mbed_official 437:0b72c0f86db6 66 uint64_t val64;
mbed_official 437:0b72c0f86db6 67
mbed_official 390:35c2c1cf29cd 68 if (!us_ticker_inited)
mbed_official 390:35c2c1cf29cd 69 us_ticker_init();
mbed_official 437:0b72c0f86db6 70
mbed_official 430:d406b7919023 71 /* read counter */
mbed_official 430:d406b7919023 72 val = OSTM1CNT;
mbed_official 437:0b72c0f86db6 73 if ( last_read > val ) {
mbed_official 437:0b72c0f86db6 74 wrap_arround++;
mbed_official 437:0b72c0f86db6 75 }
mbed_official 437:0b72c0f86db6 76 last_read = val;
mbed_official 437:0b72c0f86db6 77 val64 = ((uint64_t)wrap_arround << 32) + val;
mbed_official 437:0b72c0f86db6 78
mbed_official 430:d406b7919023 79 /* clock to us */
mbed_official 437:0b72c0f86db6 80 val = (uint32_t)(val64 / count_clock);
mbed_official 390:35c2c1cf29cd 81 return val;
mbed_official 390:35c2c1cf29cd 82 }
mbed_official 390:35c2c1cf29cd 83
mbed_official 390:35c2c1cf29cd 84 void us_ticker_set_interrupt(timestamp_t timestamp) {
mbed_official 390:35c2c1cf29cd 85 // set match value
mbed_official 430:d406b7919023 86 timestamp = (timestamp_t)(timestamp * count_clock);
mbed_official 430:d406b7919023 87 OSTM1CMP = (uint32_t)(timestamp & 0xffffffff);
mbed_official 430:d406b7919023 88 GIC_EnableIRQ(US_TICKER_TIMER_IRQn);
mbed_official 390:35c2c1cf29cd 89 }
mbed_official 390:35c2c1cf29cd 90
mbed_official 390:35c2c1cf29cd 91 void us_ticker_disable_interrupt(void) {
mbed_official 430:d406b7919023 92 GIC_DisableIRQ(US_TICKER_TIMER_IRQn);
mbed_official 390:35c2c1cf29cd 93 }
mbed_official 390:35c2c1cf29cd 94
mbed_official 390:35c2c1cf29cd 95 void us_ticker_clear_interrupt(void) {
mbed_official 430:d406b7919023 96 /* There are no Flags of OSTM1 to clear here */
mbed_official 430:d406b7919023 97 /* Do Nothing */
mbed_official 390:35c2c1cf29cd 98 }