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:
Tue Dec 09 14:30:09 2014 +0000
Revision:
430:d406b7919023
Parent:
390:35c2c1cf29cd
Child:
437:0b72c0f86db6
Synchronized with git revision 0f2b2cdf092ac0325f6003d3e903308446f2da6f

Full URL: https://github.com/mbedmicro/mbed/commit/0f2b2cdf092ac0325f6003d3e903308446f2da6f/

Targets: RZ_A1H - Fix some bugs about I2C, SPI, Interruptin and add terminal definition of user button.

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 390:35c2c1cf29cd 31
mbed_official 390:35c2c1cf29cd 32 void us_ticker_interrupt(void) {
mbed_official 390:35c2c1cf29cd 33 us_ticker_irq_handler();
mbed_official 390:35c2c1cf29cd 34 }
mbed_official 390:35c2c1cf29cd 35
mbed_official 390:35c2c1cf29cd 36 void us_ticker_init(void) {
mbed_official 390:35c2c1cf29cd 37 if (us_ticker_inited) return;
mbed_official 390:35c2c1cf29cd 38 us_ticker_inited = 1;
mbed_official 390:35c2c1cf29cd 39
mbed_official 430:d406b7919023 40 /* set Counter Clock(us) */
mbed_official 430:d406b7919023 41 if (false == RZ_A1_IsClockMode0()) {
mbed_official 430:d406b7919023 42 count_clock = (double)(CM1_RENESAS_RZ_A1_P0_CLK / US_TICKER_CLOCK_US_DEV);
mbed_official 430:d406b7919023 43 } else {
mbed_official 430:d406b7919023 44 count_clock = (double)(CM0_RENESAS_RZ_A1_P0_CLK / US_TICKER_CLOCK_US_DEV);
mbed_official 430:d406b7919023 45 }
mbed_official 430:d406b7919023 46
mbed_official 390:35c2c1cf29cd 47 /* Power Control for Peripherals */
mbed_official 430:d406b7919023 48 CPGSTBCR5 &= ~(CPG_STBCR5_BIT_MSTP50); /* enable OSTM1 clock */
mbed_official 390:35c2c1cf29cd 49
mbed_official 390:35c2c1cf29cd 50 // timer settings
mbed_official 430:d406b7919023 51 OSTM1TT = 0x01; /* Stop the counter and clears the OSTM1TE bit. */
mbed_official 430:d406b7919023 52 OSTM1CTL = 0x02; /* Free running timer mode. Interrupt disabled when star counter */
mbed_official 390:35c2c1cf29cd 53
mbed_official 430:d406b7919023 54 OSTM1TS = 0x1; /* Start the counter and sets the OSTM0TE bit. */
mbed_official 390:35c2c1cf29cd 55
mbed_official 390:35c2c1cf29cd 56 // INTC settings
mbed_official 430:d406b7919023 57 InterruptHandlerRegister(US_TICKER_TIMER_IRQn, (void (*)(uint32_t))us_ticker_interrupt);
mbed_official 430:d406b7919023 58 GIC_SetPriority(US_TICKER_TIMER_IRQn, 5);
mbed_official 430:d406b7919023 59 GIC_EnableIRQ(US_TICKER_TIMER_IRQn);
mbed_official 390:35c2c1cf29cd 60 }
mbed_official 390:35c2c1cf29cd 61
mbed_official 390:35c2c1cf29cd 62 uint32_t us_ticker_read() {
mbed_official 390:35c2c1cf29cd 63 uint32_t val;
mbed_official 390:35c2c1cf29cd 64 if (!us_ticker_inited)
mbed_official 390:35c2c1cf29cd 65 us_ticker_init();
mbed_official 390:35c2c1cf29cd 66
mbed_official 430:d406b7919023 67 /* read counter */
mbed_official 430:d406b7919023 68 val = OSTM1CNT;
mbed_official 430:d406b7919023 69
mbed_official 430:d406b7919023 70 /* clock to us */
mbed_official 430:d406b7919023 71 val = (uint32_t)(val / count_clock);
mbed_official 390:35c2c1cf29cd 72 return val;
mbed_official 390:35c2c1cf29cd 73 }
mbed_official 390:35c2c1cf29cd 74
mbed_official 390:35c2c1cf29cd 75 void us_ticker_set_interrupt(timestamp_t timestamp) {
mbed_official 390:35c2c1cf29cd 76 // set match value
mbed_official 430:d406b7919023 77 timestamp = (timestamp_t)(timestamp * count_clock);
mbed_official 430:d406b7919023 78 OSTM1CMP = (uint32_t)(timestamp & 0xffffffff);
mbed_official 430:d406b7919023 79 GIC_EnableIRQ(US_TICKER_TIMER_IRQn);
mbed_official 390:35c2c1cf29cd 80 }
mbed_official 390:35c2c1cf29cd 81
mbed_official 390:35c2c1cf29cd 82 void us_ticker_disable_interrupt(void) {
mbed_official 430:d406b7919023 83 GIC_DisableIRQ(US_TICKER_TIMER_IRQn);
mbed_official 390:35c2c1cf29cd 84 }
mbed_official 390:35c2c1cf29cd 85
mbed_official 390:35c2c1cf29cd 86 void us_ticker_clear_interrupt(void) {
mbed_official 430:d406b7919023 87 /* There are no Flags of OSTM1 to clear here */
mbed_official 430:d406b7919023 88 /* Do Nothing */
mbed_official 390:35c2c1cf29cd 89 }