mbed-os/targets/TARGET_RENESAS/TARGET_RZ_A1XX/mtu2.c

44 lines
1.1 KiB
C
Raw Normal View History

Implementation of LPTICKER feature for Renesas mbed boards Although other venders implement this feature by using RTC, in my H/W(RZ_A1), I cannot use RTC because it does not satisfy the spec of LP Ticker (ms order and low frequency between 8 KHz and 64 KHz). Therefore I implemented this feature by creating 1024 division by MTU2(Multi function Timer pulse Unit 2) in order to satisfy this spec. As a result of investigating, the most unaffected channel among MTU2 placed on GR-PEACH and GR-LYCHEE was channel 3, so I use channel 3 for this feature. - mbed_drv_cfg.h I added a macro of MTU2 channel to this file for commonalizing code for GR-PEACH and GR-LYCHEE, and referenced it's macro at us_ticker.c. - targets.json I added a macro for enabling LP Ticker. - mtu2.c mtu2.h I defined fuction of MTU2's clock supply and stop. Because MTU2 is utilized by pwm driver too, those function were referenced at lp_ticker driver and pwm driver. - lp_ticker.c lp_ticker_init() In order to satisfy the LP Ticker spec, I implemented by creating 1024 division by MTU2. When an interrupt is required, it will be set with ticker_set_interrupt(). - lp_ticker.c lp_ticker_free() This function stops the counting and powerdown the lp_ticker. - lp_ticker.c lp_read() This function returns the timer counter of MTU2. - lp_ticker.c lp_ticker_set_interrupt() In order to satisfy specifications, I implemented lp_ticker_set_interrupt() function. - lp_ticker.c lp_ticker_fire_interrupt() In order to satisfy spec, I implemented lp_ticker_fire_interrupt() function. Also I added GIC_EnableIRQ for allowing the interrupt at end of function. - lp_ticker.c lp_ticker_get_info() To satisfy the spec, I implemented lp_ticker_get_info() function. The value of freq includes rounding off.
2018-07-19 10:57:13 +00:00
/* mbed Microcontroller Library
* Copyright (c) 2006-2017 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "mbed_drv_cfg.h"
#if (defined(FUMC_MTU2_PWM) || defined(DEVICE_LPTICKER))
#include "mtu2.h"
static int mtu2_used_cnt = 0;
void mtu2_init(void)
{
if (mtu2_used_cnt == 0) {
CPGSTBCR3 &= ~(CPG_STBCR3_BIT_MSTP33);
}
if (mtu2_used_cnt < 256) {
mtu2_used_cnt++;
}
}
void mtu2_free(void)
{
if (mtu2_used_cnt > 0) {
mtu2_used_cnt--;
}
if (mtu2_used_cnt == 0) {
CPGSTBCR3 |= (CPG_STBCR3_BIT_MSTP33);
}
}
#endif