2014-10-24 02:05:17 +00:00
|
|
|
/* mbed Microcontroller Library
|
|
|
|
* Copyright (c) 2006-2013 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_assert.h"
|
|
|
|
#include "pwmout_api.h"
|
|
|
|
#include "cmsis.h"
|
Commonalize the files in "targets/TARGET_RENESAS/TARGET_RZ_A1XX" directory
I made be available in common whatever the board related to RZ_A1 in the below files.
- Since there are the table code of Pinmap differs for each board, I moved the code to "PeripheralPins" file for each board, and changed to include PeripheralPins.h.
analogin_api.c, can_api.c, gpio_irq_api.c, i2c_api.c, pinmap.c, port_api.c, pwmout_api.c, serial_api.c, spi_api.c and us_ticker.c
- Since there are some board-specific processes, I enclosed the processes with "#ifdef" and rearranged the functions to make be easier to enclose.
can_api.c, ethernet_api.c and serial_api.c
- Since there are the driver configuration values differs for each board, I added "mbed_drv_cfg.h" file for each board and defined macros for the values, and changed to refer to the macros.
can_api.c, gpio_api.c, pwmout_api.c and rtc_api.c
2018-01-09 09:20:50 +00:00
|
|
|
#include "PeripheralPins.h"
|
2014-12-12 05:26:33 +00:00
|
|
|
#include "RZ_A1_Init.h"
|
Commonalize the files in "targets/TARGET_RENESAS/TARGET_RZ_A1XX" directory
I made be available in common whatever the board related to RZ_A1 in the below files.
- Since there are the table code of Pinmap differs for each board, I moved the code to "PeripheralPins" file for each board, and changed to include PeripheralPins.h.
analogin_api.c, can_api.c, gpio_irq_api.c, i2c_api.c, pinmap.c, port_api.c, pwmout_api.c, serial_api.c, spi_api.c and us_ticker.c
- Since there are some board-specific processes, I enclosed the processes with "#ifdef" and rearranged the functions to make be easier to enclose.
can_api.c, ethernet_api.c and serial_api.c
- Since there are the driver configuration values differs for each board, I added "mbed_drv_cfg.h" file for each board and defined macros for the values, and changed to refer to the macros.
can_api.c, gpio_api.c, pwmout_api.c and rtc_api.c
2018-01-09 09:20:50 +00:00
|
|
|
#include "iodefine.h"
|
2015-08-26 03:58:32 +00:00
|
|
|
#include "gpio_addrdefine.h"
|
Commonalize the files in "targets/TARGET_RENESAS/TARGET_RZ_A1XX" directory
I made be available in common whatever the board related to RZ_A1 in the below files.
- Since there are the table code of Pinmap differs for each board, I moved the code to "PeripheralPins" file for each board, and changed to include PeripheralPins.h.
analogin_api.c, can_api.c, gpio_irq_api.c, i2c_api.c, pinmap.c, port_api.c, pwmout_api.c, serial_api.c, spi_api.c and us_ticker.c
- Since there are some board-specific processes, I enclosed the processes with "#ifdef" and rearranged the functions to make be easier to enclose.
can_api.c, ethernet_api.c and serial_api.c
- Since there are the driver configuration values differs for each board, I added "mbed_drv_cfg.h" file for each board and defined macros for the values, and changed to refer to the macros.
can_api.c, gpio_api.c, pwmout_api.c and rtc_api.c
2018-01-09 09:20:50 +00:00
|
|
|
#include "mbed_drv_cfg.h"
|
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
|
|
|
#include "mtu2.h"
|
2014-10-24 02:05:17 +00:00
|
|
|
|
2015-07-10 04:32:35 +00:00
|
|
|
#define MTU2_PWM_OFFSET 0x20
|
|
|
|
|
Commonalize the files in "targets/TARGET_RENESAS/TARGET_RZ_A1XX" directory
I made be available in common whatever the board related to RZ_A1 in the below files.
- Since there are the table code of Pinmap differs for each board, I moved the code to "PeripheralPins" file for each board, and changed to include PeripheralPins.h.
analogin_api.c, can_api.c, gpio_irq_api.c, i2c_api.c, pinmap.c, port_api.c, pwmout_api.c, serial_api.c, spi_api.c and us_ticker.c
- Since there are some board-specific processes, I enclosed the processes with "#ifdef" and rearranged the functions to make be easier to enclose.
can_api.c, ethernet_api.c and serial_api.c
- Since there are the driver configuration values differs for each board, I added "mbed_drv_cfg.h" file for each board and defined macros for the values, and changed to refer to the macros.
can_api.c, gpio_api.c, pwmout_api.c and rtc_api.c
2018-01-09 09:20:50 +00:00
|
|
|
#ifdef FUNC_MOTOR_CTL_PWM
|
|
|
|
typedef enum {
|
|
|
|
PWM1A = 0,
|
|
|
|
PWM1B,
|
|
|
|
PWM1C,
|
|
|
|
PWM1D,
|
|
|
|
PWM1E,
|
|
|
|
PWM1F,
|
|
|
|
PWM1G,
|
|
|
|
PWM1H,
|
|
|
|
PWM2A = 0x10,
|
|
|
|
PWM2B,
|
|
|
|
PWM2C,
|
|
|
|
PWM2D,
|
|
|
|
PWM2E,
|
|
|
|
PWM2F,
|
|
|
|
PWM2G,
|
|
|
|
PWM2H,
|
|
|
|
} PWMType;
|
2014-10-24 02:05:17 +00:00
|
|
|
|
2015-07-13 09:04:13 +00:00
|
|
|
static const PWMType PORT[] = {
|
Commonalize the files in "targets/TARGET_RENESAS/TARGET_RZ_A1XX" directory
I made be available in common whatever the board related to RZ_A1 in the below files.
- Since there are the table code of Pinmap differs for each board, I moved the code to "PeripheralPins" file for each board, and changed to include PeripheralPins.h.
analogin_api.c, can_api.c, gpio_irq_api.c, i2c_api.c, pinmap.c, port_api.c, pwmout_api.c, serial_api.c, spi_api.c and us_ticker.c
- Since there are some board-specific processes, I enclosed the processes with "#ifdef" and rearranged the functions to make be easier to enclose.
can_api.c, ethernet_api.c and serial_api.c
- Since there are the driver configuration values differs for each board, I added "mbed_drv_cfg.h" file for each board and defined macros for the values, and changed to refer to the macros.
can_api.c, gpio_api.c, pwmout_api.c and rtc_api.c
2018-01-09 09:20:50 +00:00
|
|
|
PWM1A, // PWM_PWM1A
|
|
|
|
PWM1B, // PWM_PWM1B
|
|
|
|
PWM1C, // PWM_PWM1C
|
|
|
|
PWM1D, // PWM_PWM1D
|
|
|
|
PWM1E, // PWM_PWM1E
|
|
|
|
PWM1F, // PWM_PWM1F
|
|
|
|
PWM1G, // PWM_PWM1G
|
|
|
|
PWM1H, // PWM_PWM1H
|
|
|
|
PWM2A, // PWM_PWM2A
|
|
|
|
PWM2B, // PWM_PWM2B
|
|
|
|
PWM2C, // PWM_PWM2C
|
|
|
|
PWM2D, // PWM_PWM2D
|
|
|
|
PWM2E, // PWM_PWM2E
|
|
|
|
PWM2F, // PWM_PWM2F
|
|
|
|
PWM2G, // PWM_PWM2G
|
|
|
|
PWM2H, // PWM_PWM2H
|
2014-10-24 02:05:17 +00:00
|
|
|
};
|
2014-12-12 05:26:33 +00:00
|
|
|
|
Commonalize the files in "targets/TARGET_RENESAS/TARGET_RZ_A1XX" directory
I made be available in common whatever the board related to RZ_A1 in the below files.
- Since there are the table code of Pinmap differs for each board, I moved the code to "PeripheralPins" file for each board, and changed to include PeripheralPins.h.
analogin_api.c, can_api.c, gpio_irq_api.c, i2c_api.c, pinmap.c, port_api.c, pwmout_api.c, serial_api.c, spi_api.c and us_ticker.c
- Since there are some board-specific processes, I enclosed the processes with "#ifdef" and rearranged the functions to make be easier to enclose.
can_api.c, ethernet_api.c and serial_api.c
- Since there are the driver configuration values differs for each board, I added "mbed_drv_cfg.h" file for each board and defined macros for the values, and changed to refer to the macros.
can_api.c, gpio_api.c, pwmout_api.c and rtc_api.c
2018-01-09 09:20:50 +00:00
|
|
|
static __IO uint16_t *PWM_MATCH[] = {
|
|
|
|
&PWMPWBFR_1A, // PWM_PWM1A
|
|
|
|
&PWMPWBFR_1A, // PWM_PWM1B
|
|
|
|
&PWMPWBFR_1C, // PWM_PWM1C
|
|
|
|
&PWMPWBFR_1C, // PWM_PWM1D
|
|
|
|
&PWMPWBFR_1E, // PWM_PWM1E
|
|
|
|
&PWMPWBFR_1E, // PWM_PWM1F
|
|
|
|
&PWMPWBFR_1G, // PWM_PWM1G
|
|
|
|
&PWMPWBFR_1G, // PWM_PWM1H
|
|
|
|
&PWMPWBFR_2A, // PWM_PWM2A
|
|
|
|
&PWMPWBFR_2A, // PWM_PWM2B
|
|
|
|
&PWMPWBFR_2C, // PWM_PWM2C
|
|
|
|
&PWMPWBFR_2C, // PWM_PWM2D
|
|
|
|
&PWMPWBFR_2E, // PWM_PWM2E
|
|
|
|
&PWMPWBFR_2E, // PWM_PWM2F
|
|
|
|
&PWMPWBFR_2G, // PWM_PWM2G
|
|
|
|
&PWMPWBFR_2G, // PWM_PWM2H
|
2015-07-10 04:32:35 +00:00
|
|
|
};
|
|
|
|
|
Commonalize the files in "targets/TARGET_RENESAS/TARGET_RZ_A1XX" directory
I made be available in common whatever the board related to RZ_A1 in the below files.
- Since there are the table code of Pinmap differs for each board, I moved the code to "PeripheralPins" file for each board, and changed to include PeripheralPins.h.
analogin_api.c, can_api.c, gpio_irq_api.c, i2c_api.c, pinmap.c, port_api.c, pwmout_api.c, serial_api.c, spi_api.c and us_ticker.c
- Since there are some board-specific processes, I enclosed the processes with "#ifdef" and rearranged the functions to make be easier to enclose.
can_api.c, ethernet_api.c and serial_api.c
- Since there are the driver configuration values differs for each board, I added "mbed_drv_cfg.h" file for each board and defined macros for the values, and changed to refer to the macros.
can_api.c, gpio_api.c, pwmout_api.c and rtc_api.c
2018-01-09 09:20:50 +00:00
|
|
|
static uint16_t init_period_ch1 = 0;
|
|
|
|
static uint16_t init_period_ch2 = 0;
|
|
|
|
static int32_t period_ch1 = 1;
|
|
|
|
static int32_t period_ch2 = 1;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef FUMC_MTU2_PWM
|
|
|
|
typedef enum {
|
|
|
|
TIOC0A = 0,
|
|
|
|
TIOC0B,
|
|
|
|
TIOC0C,
|
|
|
|
TIOC0D,
|
|
|
|
TIOC1A = 0x10,
|
|
|
|
TIOC1B,
|
|
|
|
TIOC2A = 0x20,
|
|
|
|
TIOC2B,
|
|
|
|
TIOC3A = 0x30,
|
|
|
|
TIOC3B,
|
|
|
|
TIOC3C,
|
|
|
|
TIOC3D,
|
|
|
|
TIOC4A = 0x40,
|
|
|
|
TIOC4B,
|
|
|
|
TIOC4C,
|
|
|
|
TIOC4D,
|
|
|
|
} MTU2_PWMType;
|
|
|
|
|
2019-03-07 03:00:57 +00:00
|
|
|
typedef struct {
|
|
|
|
MTU2_PWMType port;
|
|
|
|
__IO uint16_t * pulse1;
|
|
|
|
__IO uint16_t * pulse2;
|
|
|
|
__IO uint16_t * period1;
|
|
|
|
__IO uint8_t * tcr;
|
|
|
|
__IO uint8_t * tmdr;
|
|
|
|
int max_period;
|
|
|
|
} st_mtu2_ctrl_t;
|
|
|
|
|
|
|
|
static st_mtu2_ctrl_t mtu2_ctl[] = {
|
|
|
|
{ TIOC0A, &MTU2TGRA_0, &MTU2TGRC_0, &MTU2TGRB_0, &MTU2TCR_0, &MTU2TMDR_0, 125000 }, // PWM_TIOC0A
|
|
|
|
{ TIOC0C, &MTU2TGRC_0, &MTU2TGRA_0, &MTU2TGRD_0, &MTU2TCR_0, &MTU2TMDR_0, 125000 }, // PWM_TIOC0C
|
|
|
|
{ TIOC1A, &MTU2TGRA_1, NULL , &MTU2TGRB_1, &MTU2TCR_1, &MTU2TMDR_1, 503000 }, // PWM_TIOC1A
|
|
|
|
{ TIOC2A, &MTU2TGRA_2, NULL , &MTU2TGRB_2, &MTU2TCR_2, &MTU2TMDR_2, 2000000 }, // PWM_TIOC2A
|
|
|
|
{ TIOC3A, &MTU2TGRA_3, &MTU2TGRC_3, &MTU2TGRB_3, &MTU2TCR_3, &MTU2TMDR_3, 2000000 }, // PWM_TIOC3A
|
|
|
|
{ TIOC3C, &MTU2TGRC_3, &MTU2TGRA_3, &MTU2TGRD_3, &MTU2TCR_3, &MTU2TMDR_3, 2000000 }, // PWM_TIOC3C
|
|
|
|
{ TIOC4A, &MTU2TGRA_4, &MTU2TGRC_4, &MTU2TGRB_4, &MTU2TCR_4, &MTU2TMDR_4, 2000000 }, // PWM_TIOC4A
|
|
|
|
{ TIOC4C, &MTU2TGRC_4, &MTU2TGRA_4, &MTU2TGRD_4, &MTU2TCR_4, &MTU2TMDR_4, 2000000 }, // PWM_TIOC4C
|
2015-07-10 04:32:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static __IO uint8_t *TIORH_MATCH[] = {
|
|
|
|
&MTU2TIORH_0,
|
|
|
|
&MTU2TIOR_1,
|
|
|
|
&MTU2TIOR_2,
|
|
|
|
&MTU2TIORH_3,
|
|
|
|
&MTU2TIORH_4,
|
|
|
|
};
|
|
|
|
|
|
|
|
static __IO uint8_t *TIORL_MATCH[] = {
|
|
|
|
&MTU2TIORL_0,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
&MTU2TIORL_3,
|
|
|
|
&MTU2TIORL_4,
|
|
|
|
};
|
|
|
|
|
|
|
|
static uint16_t init_mtu2_period_ch[5] = {0};
|
|
|
|
static int32_t mtu2_period_ch[5] = {1, 1, 1, 1, 1};
|
Commonalize the files in "targets/TARGET_RENESAS/TARGET_RZ_A1XX" directory
I made be available in common whatever the board related to RZ_A1 in the below files.
- Since there are the table code of Pinmap differs for each board, I moved the code to "PeripheralPins" file for each board, and changed to include PeripheralPins.h.
analogin_api.c, can_api.c, gpio_irq_api.c, i2c_api.c, pinmap.c, port_api.c, pwmout_api.c, serial_api.c, spi_api.c and us_ticker.c
- Since there are some board-specific processes, I enclosed the processes with "#ifdef" and rearranged the functions to make be easier to enclose.
can_api.c, ethernet_api.c and serial_api.c
- Since there are the driver configuration values differs for each board, I added "mbed_drv_cfg.h" file for each board and defined macros for the values, and changed to refer to the macros.
can_api.c, gpio_api.c, pwmout_api.c and rtc_api.c
2018-01-09 09:20:50 +00:00
|
|
|
#endif
|
2014-10-24 02:05:17 +00:00
|
|
|
|
|
|
|
void pwmout_init(pwmout_t* obj, PinName pin) {
|
|
|
|
// determine the channel
|
|
|
|
PWMName pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
|
|
|
|
MBED_ASSERT(pwm != (PWMName)NC);
|
|
|
|
|
2015-07-10 04:32:35 +00:00
|
|
|
if (pwm >= MTU2_PWM_OFFSET) {
|
Commonalize the files in "targets/TARGET_RENESAS/TARGET_RZ_A1XX" directory
I made be available in common whatever the board related to RZ_A1 in the below files.
- Since there are the table code of Pinmap differs for each board, I moved the code to "PeripheralPins" file for each board, and changed to include PeripheralPins.h.
analogin_api.c, can_api.c, gpio_irq_api.c, i2c_api.c, pinmap.c, port_api.c, pwmout_api.c, serial_api.c, spi_api.c and us_ticker.c
- Since there are some board-specific processes, I enclosed the processes with "#ifdef" and rearranged the functions to make be easier to enclose.
can_api.c, ethernet_api.c and serial_api.c
- Since there are the driver configuration values differs for each board, I added "mbed_drv_cfg.h" file for each board and defined macros for the values, and changed to refer to the macros.
can_api.c, gpio_api.c, pwmout_api.c and rtc_api.c
2018-01-09 09:20:50 +00:00
|
|
|
#ifdef FUMC_MTU2_PWM
|
2015-07-10 04:32:35 +00:00
|
|
|
/* PWM by MTU2 */
|
|
|
|
// power on
|
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
|
|
|
mtu2_init();
|
2019-03-07 03:00:57 +00:00
|
|
|
|
2015-07-10 04:32:35 +00:00
|
|
|
obj->pwm = pwm;
|
2019-03-07 03:00:57 +00:00
|
|
|
st_mtu2_ctrl_t * p_mtu2_ctl = &mtu2_ctl[(int)(obj->pwm - MTU2_PWM_OFFSET)];
|
|
|
|
|
|
|
|
obj->ch = (uint8_t)(((uint32_t)p_mtu2_ctl->port & 0x000000F0) >> 4);
|
|
|
|
if (obj->ch == 4) {
|
2015-07-10 04:32:35 +00:00
|
|
|
MTU2TOER |= 0x36;
|
2019-03-07 03:00:57 +00:00
|
|
|
} else if (obj->ch == 3) {
|
2015-07-10 04:32:35 +00:00
|
|
|
MTU2TOER |= 0x09;
|
|
|
|
} else {
|
2019-03-07 03:00:57 +00:00
|
|
|
// do nothing
|
2015-07-10 04:32:35 +00:00
|
|
|
}
|
2019-03-07 03:00:57 +00:00
|
|
|
|
2015-07-10 04:32:35 +00:00
|
|
|
// Wire pinout
|
|
|
|
pinmap_pinout(pin, PinMap_PWM);
|
2015-08-26 03:58:32 +00:00
|
|
|
|
|
|
|
int bitmask = 1 << (pin & 0xf);
|
|
|
|
|
|
|
|
*PMSR(PINGROUP(pin)) = (bitmask << 16) | 0;
|
|
|
|
|
2015-07-10 04:32:35 +00:00
|
|
|
// default duty 0.0f
|
|
|
|
pwmout_write(obj, 0);
|
|
|
|
if (init_mtu2_period_ch[obj->ch] == 0) {
|
|
|
|
// default period 1ms
|
|
|
|
pwmout_period_us(obj, 1000);
|
|
|
|
init_mtu2_period_ch[obj->ch] = 1;
|
|
|
|
}
|
Commonalize the files in "targets/TARGET_RENESAS/TARGET_RZ_A1XX" directory
I made be available in common whatever the board related to RZ_A1 in the below files.
- Since there are the table code of Pinmap differs for each board, I moved the code to "PeripheralPins" file for each board, and changed to include PeripheralPins.h.
analogin_api.c, can_api.c, gpio_irq_api.c, i2c_api.c, pinmap.c, port_api.c, pwmout_api.c, serial_api.c, spi_api.c and us_ticker.c
- Since there are some board-specific processes, I enclosed the processes with "#ifdef" and rearranged the functions to make be easier to enclose.
can_api.c, ethernet_api.c and serial_api.c
- Since there are the driver configuration values differs for each board, I added "mbed_drv_cfg.h" file for each board and defined macros for the values, and changed to refer to the macros.
can_api.c, gpio_api.c, pwmout_api.c and rtc_api.c
2018-01-09 09:20:50 +00:00
|
|
|
#endif
|
2014-12-12 05:26:33 +00:00
|
|
|
} else {
|
Commonalize the files in "targets/TARGET_RENESAS/TARGET_RZ_A1XX" directory
I made be available in common whatever the board related to RZ_A1 in the below files.
- Since there are the table code of Pinmap differs for each board, I moved the code to "PeripheralPins" file for each board, and changed to include PeripheralPins.h.
analogin_api.c, can_api.c, gpio_irq_api.c, i2c_api.c, pinmap.c, port_api.c, pwmout_api.c, serial_api.c, spi_api.c and us_ticker.c
- Since there are some board-specific processes, I enclosed the processes with "#ifdef" and rearranged the functions to make be easier to enclose.
can_api.c, ethernet_api.c and serial_api.c
- Since there are the driver configuration values differs for each board, I added "mbed_drv_cfg.h" file for each board and defined macros for the values, and changed to refer to the macros.
can_api.c, gpio_api.c, pwmout_api.c and rtc_api.c
2018-01-09 09:20:50 +00:00
|
|
|
#ifdef FUNC_MOTOR_CTL_PWM
|
2015-07-10 04:32:35 +00:00
|
|
|
/* PWM */
|
|
|
|
// power on
|
|
|
|
CPGSTBCR3 &= ~(CPG_STBCR3_BIT_MSTP30);
|
|
|
|
|
|
|
|
obj->pwm = pwm;
|
|
|
|
if (((uint32_t)PORT[obj->pwm] & 0x00000010) == 0x00000010) {
|
|
|
|
obj->ch = 2;
|
2017-12-01 02:22:16 +00:00
|
|
|
PWMPWPR_2 = 0x00;
|
2015-07-10 04:32:35 +00:00
|
|
|
} else {
|
|
|
|
obj->ch = 1;
|
2017-12-01 02:22:16 +00:00
|
|
|
PWMPWPR_1 = 0x00;
|
2015-07-10 04:32:35 +00:00
|
|
|
}
|
2014-12-12 05:26:33 +00:00
|
|
|
|
2015-07-10 04:32:35 +00:00
|
|
|
// Wire pinout
|
|
|
|
pinmap_pinout(pin, PinMap_PWM);
|
2014-12-12 05:26:33 +00:00
|
|
|
|
2015-07-10 04:32:35 +00:00
|
|
|
// default to 491us: standard for servos, and fine for e.g. brightness control
|
|
|
|
pwmout_write(obj, 0);
|
|
|
|
if ((obj->ch == 2) && (init_period_ch2 == 0)) {
|
|
|
|
pwmout_period_us(obj, 491);
|
|
|
|
init_period_ch2 = 1;
|
|
|
|
}
|
|
|
|
if ((obj->ch == 1) && (init_period_ch1 == 0)) {
|
|
|
|
pwmout_period_us(obj, 491);
|
|
|
|
init_period_ch1 = 1;
|
|
|
|
}
|
Commonalize the files in "targets/TARGET_RENESAS/TARGET_RZ_A1XX" directory
I made be available in common whatever the board related to RZ_A1 in the below files.
- Since there are the table code of Pinmap differs for each board, I moved the code to "PeripheralPins" file for each board, and changed to include PeripheralPins.h.
analogin_api.c, can_api.c, gpio_irq_api.c, i2c_api.c, pinmap.c, port_api.c, pwmout_api.c, serial_api.c, spi_api.c and us_ticker.c
- Since there are some board-specific processes, I enclosed the processes with "#ifdef" and rearranged the functions to make be easier to enclose.
can_api.c, ethernet_api.c and serial_api.c
- Since there are the driver configuration values differs for each board, I added "mbed_drv_cfg.h" file for each board and defined macros for the values, and changed to refer to the macros.
can_api.c, gpio_api.c, pwmout_api.c and rtc_api.c
2018-01-09 09:20:50 +00:00
|
|
|
#endif
|
2014-12-12 05:26:33 +00:00
|
|
|
}
|
2014-10-24 02:05:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void pwmout_free(pwmout_t* obj) {
|
2014-12-12 05:26:33 +00:00
|
|
|
pwmout_write(obj, 0);
|
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
|
|
|
mtu2_free();
|
2014-10-24 02:05:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void pwmout_write(pwmout_t* obj, float value) {
|
2014-12-12 05:26:33 +00:00
|
|
|
uint32_t wk_cycle;
|
|
|
|
|
2016-09-23 05:43:06 +00:00
|
|
|
if (obj->pwm >= MTU2_PWM_OFFSET) {
|
Commonalize the files in "targets/TARGET_RENESAS/TARGET_RZ_A1XX" directory
I made be available in common whatever the board related to RZ_A1 in the below files.
- Since there are the table code of Pinmap differs for each board, I moved the code to "PeripheralPins" file for each board, and changed to include PeripheralPins.h.
analogin_api.c, can_api.c, gpio_irq_api.c, i2c_api.c, pinmap.c, port_api.c, pwmout_api.c, serial_api.c, spi_api.c and us_ticker.c
- Since there are some board-specific processes, I enclosed the processes with "#ifdef" and rearranged the functions to make be easier to enclose.
can_api.c, ethernet_api.c and serial_api.c
- Since there are the driver configuration values differs for each board, I added "mbed_drv_cfg.h" file for each board and defined macros for the values, and changed to refer to the macros.
can_api.c, gpio_api.c, pwmout_api.c and rtc_api.c
2018-01-09 09:20:50 +00:00
|
|
|
#ifdef FUMC_MTU2_PWM
|
2015-07-10 04:32:35 +00:00
|
|
|
/* PWM by MTU2 */
|
2019-03-07 03:00:57 +00:00
|
|
|
st_mtu2_ctrl_t * p_mtu2_ctl = &mtu2_ctl[(int)(obj->pwm - MTU2_PWM_OFFSET)];
|
Commonalize the files in "targets/TARGET_RENESAS/TARGET_RZ_A1XX" directory
I made be available in common whatever the board related to RZ_A1 in the below files.
- Since there are the table code of Pinmap differs for each board, I moved the code to "PeripheralPins" file for each board, and changed to include PeripheralPins.h.
analogin_api.c, can_api.c, gpio_irq_api.c, i2c_api.c, pinmap.c, port_api.c, pwmout_api.c, serial_api.c, spi_api.c and us_ticker.c
- Since there are some board-specific processes, I enclosed the processes with "#ifdef" and rearranged the functions to make be easier to enclose.
can_api.c, ethernet_api.c and serial_api.c
- Since there are the driver configuration values differs for each board, I added "mbed_drv_cfg.h" file for each board and defined macros for the values, and changed to refer to the macros.
can_api.c, gpio_api.c, pwmout_api.c and rtc_api.c
2018-01-09 09:20:50 +00:00
|
|
|
|
2015-07-10 04:32:35 +00:00
|
|
|
if (value < 0.0f) {
|
|
|
|
value = 0.0f;
|
|
|
|
} else if (value > 1.0f) {
|
|
|
|
value = 1.0f;
|
|
|
|
} else {
|
|
|
|
// Do Nothing
|
|
|
|
}
|
2019-03-07 03:00:57 +00:00
|
|
|
wk_cycle = (uint32_t)*p_mtu2_ctl->period1;
|
|
|
|
|
2015-07-10 04:32:35 +00:00
|
|
|
// set channel match to percentage
|
Commonalize the files in "targets/TARGET_RENESAS/TARGET_RZ_A1XX" directory
I made be available in common whatever the board related to RZ_A1 in the below files.
- Since there are the table code of Pinmap differs for each board, I moved the code to "PeripheralPins" file for each board, and changed to include PeripheralPins.h.
analogin_api.c, can_api.c, gpio_irq_api.c, i2c_api.c, pinmap.c, port_api.c, pwmout_api.c, serial_api.c, spi_api.c and us_ticker.c
- Since there are some board-specific processes, I enclosed the processes with "#ifdef" and rearranged the functions to make be easier to enclose.
can_api.c, ethernet_api.c and serial_api.c
- Since there are the driver configuration values differs for each board, I added "mbed_drv_cfg.h" file for each board and defined macros for the values, and changed to refer to the macros.
can_api.c, gpio_api.c, pwmout_api.c and rtc_api.c
2018-01-09 09:20:50 +00:00
|
|
|
if (value == 1.0f) {
|
2019-03-07 03:00:57 +00:00
|
|
|
*p_mtu2_ctl->pulse1 = (uint16_t)(wk_cycle - 1);
|
Commonalize the files in "targets/TARGET_RENESAS/TARGET_RZ_A1XX" directory
I made be available in common whatever the board related to RZ_A1 in the below files.
- Since there are the table code of Pinmap differs for each board, I moved the code to "PeripheralPins" file for each board, and changed to include PeripheralPins.h.
analogin_api.c, can_api.c, gpio_irq_api.c, i2c_api.c, pinmap.c, port_api.c, pwmout_api.c, serial_api.c, spi_api.c and us_ticker.c
- Since there are some board-specific processes, I enclosed the processes with "#ifdef" and rearranged the functions to make be easier to enclose.
can_api.c, ethernet_api.c and serial_api.c
- Since there are the driver configuration values differs for each board, I added "mbed_drv_cfg.h" file for each board and defined macros for the values, and changed to refer to the macros.
can_api.c, gpio_api.c, pwmout_api.c and rtc_api.c
2018-01-09 09:20:50 +00:00
|
|
|
} else {
|
2019-03-07 03:00:57 +00:00
|
|
|
*p_mtu2_ctl->pulse1 = (uint16_t)((float)wk_cycle * value);
|
Commonalize the files in "targets/TARGET_RENESAS/TARGET_RZ_A1XX" directory
I made be available in common whatever the board related to RZ_A1 in the below files.
- Since there are the table code of Pinmap differs for each board, I moved the code to "PeripheralPins" file for each board, and changed to include PeripheralPins.h.
analogin_api.c, can_api.c, gpio_irq_api.c, i2c_api.c, pinmap.c, port_api.c, pwmout_api.c, serial_api.c, spi_api.c and us_ticker.c
- Since there are some board-specific processes, I enclosed the processes with "#ifdef" and rearranged the functions to make be easier to enclose.
can_api.c, ethernet_api.c and serial_api.c
- Since there are the driver configuration values differs for each board, I added "mbed_drv_cfg.h" file for each board and defined macros for the values, and changed to refer to the macros.
can_api.c, gpio_api.c, pwmout_api.c and rtc_api.c
2018-01-09 09:20:50 +00:00
|
|
|
}
|
|
|
|
#endif
|
2014-12-12 05:26:33 +00:00
|
|
|
} else {
|
Commonalize the files in "targets/TARGET_RENESAS/TARGET_RZ_A1XX" directory
I made be available in common whatever the board related to RZ_A1 in the below files.
- Since there are the table code of Pinmap differs for each board, I moved the code to "PeripheralPins" file for each board, and changed to include PeripheralPins.h.
analogin_api.c, can_api.c, gpio_irq_api.c, i2c_api.c, pinmap.c, port_api.c, pwmout_api.c, serial_api.c, spi_api.c and us_ticker.c
- Since there are some board-specific processes, I enclosed the processes with "#ifdef" and rearranged the functions to make be easier to enclose.
can_api.c, ethernet_api.c and serial_api.c
- Since there are the driver configuration values differs for each board, I added "mbed_drv_cfg.h" file for each board and defined macros for the values, and changed to refer to the macros.
can_api.c, gpio_api.c, pwmout_api.c and rtc_api.c
2018-01-09 09:20:50 +00:00
|
|
|
#ifdef FUNC_MOTOR_CTL_PWM
|
|
|
|
uint16_t v;
|
|
|
|
|
2015-07-10 04:32:35 +00:00
|
|
|
/* PWM */
|
|
|
|
if (value < 0.0f) {
|
|
|
|
value = 0.0f;
|
|
|
|
} else if (value > 1.0f) {
|
|
|
|
value = 1.0f;
|
|
|
|
} else {
|
|
|
|
// Do Nothing
|
|
|
|
}
|
2014-12-12 05:26:33 +00:00
|
|
|
|
2015-07-10 04:32:35 +00:00
|
|
|
if (obj->ch == 2) {
|
|
|
|
wk_cycle = PWMPWCYR_2 & 0x03ff;
|
|
|
|
} else {
|
|
|
|
wk_cycle = PWMPWCYR_1 & 0x03ff;
|
|
|
|
}
|
2014-12-12 05:26:33 +00:00
|
|
|
|
2015-07-10 04:32:35 +00:00
|
|
|
// set channel match to percentage
|
|
|
|
v = (uint16_t)((float)wk_cycle * value);
|
|
|
|
*PWM_MATCH[obj->pwm] = (v | ((PORT[obj->pwm] & 1) << 12));
|
Commonalize the files in "targets/TARGET_RENESAS/TARGET_RZ_A1XX" directory
I made be available in common whatever the board related to RZ_A1 in the below files.
- Since there are the table code of Pinmap differs for each board, I moved the code to "PeripheralPins" file for each board, and changed to include PeripheralPins.h.
analogin_api.c, can_api.c, gpio_irq_api.c, i2c_api.c, pinmap.c, port_api.c, pwmout_api.c, serial_api.c, spi_api.c and us_ticker.c
- Since there are some board-specific processes, I enclosed the processes with "#ifdef" and rearranged the functions to make be easier to enclose.
can_api.c, ethernet_api.c and serial_api.c
- Since there are the driver configuration values differs for each board, I added "mbed_drv_cfg.h" file for each board and defined macros for the values, and changed to refer to the macros.
can_api.c, gpio_api.c, pwmout_api.c and rtc_api.c
2018-01-09 09:20:50 +00:00
|
|
|
#endif
|
2015-07-10 04:32:35 +00:00
|
|
|
}
|
2014-10-24 02:05:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
float pwmout_read(pwmout_t* obj) {
|
2014-12-12 05:26:33 +00:00
|
|
|
uint32_t wk_cycle;
|
|
|
|
float value;
|
|
|
|
|
2016-09-23 05:43:06 +00:00
|
|
|
if (obj->pwm >= MTU2_PWM_OFFSET) {
|
Commonalize the files in "targets/TARGET_RENESAS/TARGET_RZ_A1XX" directory
I made be available in common whatever the board related to RZ_A1 in the below files.
- Since there are the table code of Pinmap differs for each board, I moved the code to "PeripheralPins" file for each board, and changed to include PeripheralPins.h.
analogin_api.c, can_api.c, gpio_irq_api.c, i2c_api.c, pinmap.c, port_api.c, pwmout_api.c, serial_api.c, spi_api.c and us_ticker.c
- Since there are some board-specific processes, I enclosed the processes with "#ifdef" and rearranged the functions to make be easier to enclose.
can_api.c, ethernet_api.c and serial_api.c
- Since there are the driver configuration values differs for each board, I added "mbed_drv_cfg.h" file for each board and defined macros for the values, and changed to refer to the macros.
can_api.c, gpio_api.c, pwmout_api.c and rtc_api.c
2018-01-09 09:20:50 +00:00
|
|
|
#ifdef FUMC_MTU2_PWM
|
2015-07-10 04:32:35 +00:00
|
|
|
/* PWM by MTU2 */
|
|
|
|
uint32_t wk_pulse;
|
2019-03-07 03:00:57 +00:00
|
|
|
st_mtu2_ctrl_t * p_mtu2_ctl = &mtu2_ctl[(int)(obj->pwm - MTU2_PWM_OFFSET)];
|
|
|
|
|
|
|
|
wk_cycle = (uint32_t)*p_mtu2_ctl->period1;
|
|
|
|
wk_pulse = (uint32_t)*p_mtu2_ctl->pulse1;
|
2015-07-10 04:32:35 +00:00
|
|
|
value = ((float)wk_pulse / (float)wk_cycle);
|
Commonalize the files in "targets/TARGET_RENESAS/TARGET_RZ_A1XX" directory
I made be available in common whatever the board related to RZ_A1 in the below files.
- Since there are the table code of Pinmap differs for each board, I moved the code to "PeripheralPins" file for each board, and changed to include PeripheralPins.h.
analogin_api.c, can_api.c, gpio_irq_api.c, i2c_api.c, pinmap.c, port_api.c, pwmout_api.c, serial_api.c, spi_api.c and us_ticker.c
- Since there are some board-specific processes, I enclosed the processes with "#ifdef" and rearranged the functions to make be easier to enclose.
can_api.c, ethernet_api.c and serial_api.c
- Since there are the driver configuration values differs for each board, I added "mbed_drv_cfg.h" file for each board and defined macros for the values, and changed to refer to the macros.
can_api.c, gpio_api.c, pwmout_api.c and rtc_api.c
2018-01-09 09:20:50 +00:00
|
|
|
#endif
|
2014-12-12 05:26:33 +00:00
|
|
|
} else {
|
Commonalize the files in "targets/TARGET_RENESAS/TARGET_RZ_A1XX" directory
I made be available in common whatever the board related to RZ_A1 in the below files.
- Since there are the table code of Pinmap differs for each board, I moved the code to "PeripheralPins" file for each board, and changed to include PeripheralPins.h.
analogin_api.c, can_api.c, gpio_irq_api.c, i2c_api.c, pinmap.c, port_api.c, pwmout_api.c, serial_api.c, spi_api.c and us_ticker.c
- Since there are some board-specific processes, I enclosed the processes with "#ifdef" and rearranged the functions to make be easier to enclose.
can_api.c, ethernet_api.c and serial_api.c
- Since there are the driver configuration values differs for each board, I added "mbed_drv_cfg.h" file for each board and defined macros for the values, and changed to refer to the macros.
can_api.c, gpio_api.c, pwmout_api.c and rtc_api.c
2018-01-09 09:20:50 +00:00
|
|
|
#ifdef FUNC_MOTOR_CTL_PWM
|
2015-07-10 04:32:35 +00:00
|
|
|
/* PWM */
|
|
|
|
if (obj->ch == 2) {
|
|
|
|
wk_cycle = PWMPWCYR_2 & 0x03ff;
|
|
|
|
} else {
|
|
|
|
wk_cycle = PWMPWCYR_1 & 0x03ff;
|
|
|
|
}
|
|
|
|
value = ((float)(*PWM_MATCH[obj->pwm] & 0x03ff) / (float)wk_cycle);
|
Commonalize the files in "targets/TARGET_RENESAS/TARGET_RZ_A1XX" directory
I made be available in common whatever the board related to RZ_A1 in the below files.
- Since there are the table code of Pinmap differs for each board, I moved the code to "PeripheralPins" file for each board, and changed to include PeripheralPins.h.
analogin_api.c, can_api.c, gpio_irq_api.c, i2c_api.c, pinmap.c, port_api.c, pwmout_api.c, serial_api.c, spi_api.c and us_ticker.c
- Since there are some board-specific processes, I enclosed the processes with "#ifdef" and rearranged the functions to make be easier to enclose.
can_api.c, ethernet_api.c and serial_api.c
- Since there are the driver configuration values differs for each board, I added "mbed_drv_cfg.h" file for each board and defined macros for the values, and changed to refer to the macros.
can_api.c, gpio_api.c, pwmout_api.c and rtc_api.c
2018-01-09 09:20:50 +00:00
|
|
|
#endif
|
2014-12-12 05:26:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (value > 1.0f) ? (1.0f) : (value);
|
2014-10-24 02:05:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void pwmout_period(pwmout_t* obj, float seconds) {
|
|
|
|
pwmout_period_us(obj, seconds * 1000000.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
void pwmout_period_ms(pwmout_t* obj, int ms) {
|
|
|
|
pwmout_period_us(obj, ms * 1000);
|
|
|
|
}
|
|
|
|
|
Commonalize the files in "targets/TARGET_RENESAS/TARGET_RZ_A1XX" directory
I made be available in common whatever the board related to RZ_A1 in the below files.
- Since there are the table code of Pinmap differs for each board, I moved the code to "PeripheralPins" file for each board, and changed to include PeripheralPins.h.
analogin_api.c, can_api.c, gpio_irq_api.c, i2c_api.c, pinmap.c, port_api.c, pwmout_api.c, serial_api.c, spi_api.c and us_ticker.c
- Since there are some board-specific processes, I enclosed the processes with "#ifdef" and rearranged the functions to make be easier to enclose.
can_api.c, ethernet_api.c and serial_api.c
- Since there are the driver configuration values differs for each board, I added "mbed_drv_cfg.h" file for each board and defined macros for the values, and changed to refer to the macros.
can_api.c, gpio_api.c, pwmout_api.c and rtc_api.c
2018-01-09 09:20:50 +00:00
|
|
|
#ifdef FUNC_MOTOR_CTL_PWM
|
2014-12-12 05:26:33 +00:00
|
|
|
static void set_duty_again(__IO uint16_t *p_pwmpbfr, uint16_t last_cycle, uint16_t new_cycle){
|
|
|
|
uint16_t wk_pwmpbfr;
|
|
|
|
float value;
|
|
|
|
uint16_t v;
|
|
|
|
|
|
|
|
wk_pwmpbfr = *p_pwmpbfr;
|
|
|
|
value = ((float)(wk_pwmpbfr & 0x03ff) / (float)last_cycle);
|
|
|
|
v = (uint16_t)((float)new_cycle * value);
|
|
|
|
*p_pwmpbfr = (v | (wk_pwmpbfr & 0x1000));
|
|
|
|
}
|
Commonalize the files in "targets/TARGET_RENESAS/TARGET_RZ_A1XX" directory
I made be available in common whatever the board related to RZ_A1 in the below files.
- Since there are the table code of Pinmap differs for each board, I moved the code to "PeripheralPins" file for each board, and changed to include PeripheralPins.h.
analogin_api.c, can_api.c, gpio_irq_api.c, i2c_api.c, pinmap.c, port_api.c, pwmout_api.c, serial_api.c, spi_api.c and us_ticker.c
- Since there are some board-specific processes, I enclosed the processes with "#ifdef" and rearranged the functions to make be easier to enclose.
can_api.c, ethernet_api.c and serial_api.c
- Since there are the driver configuration values differs for each board, I added "mbed_drv_cfg.h" file for each board and defined macros for the values, and changed to refer to the macros.
can_api.c, gpio_api.c, pwmout_api.c and rtc_api.c
2018-01-09 09:20:50 +00:00
|
|
|
#endif
|
2014-12-12 05:26:33 +00:00
|
|
|
|
Commonalize the files in "targets/TARGET_RENESAS/TARGET_RZ_A1XX" directory
I made be available in common whatever the board related to RZ_A1 in the below files.
- Since there are the table code of Pinmap differs for each board, I moved the code to "PeripheralPins" file for each board, and changed to include PeripheralPins.h.
analogin_api.c, can_api.c, gpio_irq_api.c, i2c_api.c, pinmap.c, port_api.c, pwmout_api.c, serial_api.c, spi_api.c and us_ticker.c
- Since there are some board-specific processes, I enclosed the processes with "#ifdef" and rearranged the functions to make be easier to enclose.
can_api.c, ethernet_api.c and serial_api.c
- Since there are the driver configuration values differs for each board, I added "mbed_drv_cfg.h" file for each board and defined macros for the values, and changed to refer to the macros.
can_api.c, gpio_api.c, pwmout_api.c and rtc_api.c
2018-01-09 09:20:50 +00:00
|
|
|
#ifdef FUMC_MTU2_PWM
|
2015-07-10 04:32:35 +00:00
|
|
|
static void set_mtu2_duty_again(__IO uint16_t *p_pwmpbfr, uint16_t last_cycle, uint16_t new_cycle){
|
|
|
|
uint16_t wk_pwmpbfr;
|
|
|
|
float value;
|
|
|
|
|
|
|
|
wk_pwmpbfr = *p_pwmpbfr;
|
|
|
|
value = ((float)(wk_pwmpbfr & 0xffff) / (float)last_cycle);
|
|
|
|
*p_pwmpbfr = (uint16_t)((float)new_cycle * value);
|
|
|
|
}
|
Commonalize the files in "targets/TARGET_RENESAS/TARGET_RZ_A1XX" directory
I made be available in common whatever the board related to RZ_A1 in the below files.
- Since there are the table code of Pinmap differs for each board, I moved the code to "PeripheralPins" file for each board, and changed to include PeripheralPins.h.
analogin_api.c, can_api.c, gpio_irq_api.c, i2c_api.c, pinmap.c, port_api.c, pwmout_api.c, serial_api.c, spi_api.c and us_ticker.c
- Since there are some board-specific processes, I enclosed the processes with "#ifdef" and rearranged the functions to make be easier to enclose.
can_api.c, ethernet_api.c and serial_api.c
- Since there are the driver configuration values differs for each board, I added "mbed_drv_cfg.h" file for each board and defined macros for the values, and changed to refer to the macros.
can_api.c, gpio_api.c, pwmout_api.c and rtc_api.c
2018-01-09 09:20:50 +00:00
|
|
|
#endif
|
2015-07-10 04:32:35 +00:00
|
|
|
|
2014-10-24 02:05:17 +00:00
|
|
|
// Set the PWM period, keeping the duty cycle the same.
|
|
|
|
void pwmout_period_us(pwmout_t* obj, int us) {
|
2014-12-12 05:26:33 +00:00
|
|
|
uint32_t pclk_base;
|
|
|
|
uint32_t wk_cycle;
|
|
|
|
uint32_t wk_cks = 0;
|
2015-07-10 04:32:35 +00:00
|
|
|
uint16_t wk_last_cycle;
|
|
|
|
|
2016-09-23 05:43:06 +00:00
|
|
|
if (obj->pwm >= MTU2_PWM_OFFSET) {
|
Commonalize the files in "targets/TARGET_RENESAS/TARGET_RZ_A1XX" directory
I made be available in common whatever the board related to RZ_A1 in the below files.
- Since there are the table code of Pinmap differs for each board, I moved the code to "PeripheralPins" file for each board, and changed to include PeripheralPins.h.
analogin_api.c, can_api.c, gpio_irq_api.c, i2c_api.c, pinmap.c, port_api.c, pwmout_api.c, serial_api.c, spi_api.c and us_ticker.c
- Since there are some board-specific processes, I enclosed the processes with "#ifdef" and rearranged the functions to make be easier to enclose.
can_api.c, ethernet_api.c and serial_api.c
- Since there are the driver configuration values differs for each board, I added "mbed_drv_cfg.h" file for each board and defined macros for the values, and changed to refer to the macros.
can_api.c, gpio_api.c, pwmout_api.c and rtc_api.c
2018-01-09 09:20:50 +00:00
|
|
|
#ifdef FUMC_MTU2_PWM
|
|
|
|
uint64_t wk_cycle_mtu2;
|
|
|
|
int max_us = 0;
|
|
|
|
|
2015-07-10 04:32:35 +00:00
|
|
|
/* PWM by MTU2 */
|
2019-03-07 03:00:57 +00:00
|
|
|
st_mtu2_ctrl_t * p_mtu2_ctl = &mtu2_ctl[(int)(obj->pwm - MTU2_PWM_OFFSET)];
|
2015-07-10 04:32:35 +00:00
|
|
|
uint8_t tmp_tcr_up;
|
|
|
|
uint8_t tmp_tstr_st;
|
2019-03-07 03:00:57 +00:00
|
|
|
|
|
|
|
max_us = p_mtu2_ctl->max_period;
|
2015-07-10 04:32:35 +00:00
|
|
|
if (us > max_us) {
|
|
|
|
us = max_us;
|
|
|
|
} else if (us < 1) {
|
|
|
|
us = 1;
|
|
|
|
} else {
|
|
|
|
// Do Nothing
|
|
|
|
}
|
2014-12-12 05:26:33 +00:00
|
|
|
|
2015-07-10 04:32:35 +00:00
|
|
|
if (RZ_A1_IsClockMode0() == false) {
|
|
|
|
pclk_base = (uint32_t)CM1_RENESAS_RZ_A1_P0_CLK;
|
|
|
|
} else {
|
|
|
|
pclk_base = (uint32_t)CM0_RENESAS_RZ_A1_P0_CLK;
|
|
|
|
}
|
2014-12-12 05:26:33 +00:00
|
|
|
|
2015-07-10 04:32:35 +00:00
|
|
|
wk_cycle_mtu2 = (uint64_t)pclk_base * us;
|
|
|
|
while (wk_cycle_mtu2 >= 65535000000) {
|
|
|
|
if ((obj->ch == 1) && (wk_cks == 3)) {
|
|
|
|
wk_cks+=2;
|
|
|
|
} else if ((obj->ch == 2) && (wk_cks == 3)) {
|
|
|
|
wk_cycle_mtu2 >>= 2;
|
|
|
|
wk_cks+=3;
|
|
|
|
}
|
|
|
|
wk_cycle_mtu2 >>= 2;
|
|
|
|
wk_cks++;
|
|
|
|
}
|
|
|
|
wk_cycle = (uint32_t)(wk_cycle_mtu2 / 1000000);
|
Commonalize the files in "targets/TARGET_RENESAS/TARGET_RZ_A1XX" directory
I made be available in common whatever the board related to RZ_A1 in the below files.
- Since there are the table code of Pinmap differs for each board, I moved the code to "PeripheralPins" file for each board, and changed to include PeripheralPins.h.
analogin_api.c, can_api.c, gpio_irq_api.c, i2c_api.c, pinmap.c, port_api.c, pwmout_api.c, serial_api.c, spi_api.c and us_ticker.c
- Since there are some board-specific processes, I enclosed the processes with "#ifdef" and rearranged the functions to make be easier to enclose.
can_api.c, ethernet_api.c and serial_api.c
- Since there are the driver configuration values differs for each board, I added "mbed_drv_cfg.h" file for each board and defined macros for the values, and changed to refer to the macros.
can_api.c, gpio_api.c, pwmout_api.c and rtc_api.c
2018-01-09 09:20:50 +00:00
|
|
|
|
2019-03-07 03:00:57 +00:00
|
|
|
if (((uint8_t)p_mtu2_ctl->port & 0x0F) == 0x02) {
|
2015-07-10 04:32:35 +00:00
|
|
|
tmp_tcr_up = 0xC0;
|
|
|
|
} else {
|
|
|
|
tmp_tcr_up = 0x40;
|
|
|
|
}
|
|
|
|
if ((obj->ch == 4) || (obj->ch == 3)) {
|
|
|
|
tmp_tstr_st = (1 << (obj->ch + 3));
|
|
|
|
} else {
|
|
|
|
tmp_tstr_st = (1 << obj->ch);
|
|
|
|
}
|
2019-03-07 03:00:57 +00:00
|
|
|
|
2015-07-10 04:32:35 +00:00
|
|
|
// Counter Stop
|
2019-03-07 03:00:57 +00:00
|
|
|
MTU2TSTR &= ~tmp_tstr_st;
|
|
|
|
wk_last_cycle = *p_mtu2_ctl->period1;
|
|
|
|
*p_mtu2_ctl->tcr = tmp_tcr_up | wk_cks;
|
2015-07-10 04:32:35 +00:00
|
|
|
*TIORH_MATCH[obj->ch] = 0x21;
|
|
|
|
if ((obj->ch == 0) || (obj->ch == 3) || (obj->ch == 4)) {
|
|
|
|
*TIORL_MATCH[obj->ch] = 0x21;
|
|
|
|
}
|
2019-03-07 03:00:57 +00:00
|
|
|
// Set period
|
|
|
|
*p_mtu2_ctl->period1 = (uint16_t)wk_cycle;
|
|
|
|
// Set duty again
|
|
|
|
set_mtu2_duty_again(p_mtu2_ctl->pulse1, wk_last_cycle, wk_cycle);
|
|
|
|
if (p_mtu2_ctl->pulse2 != NULL) {
|
|
|
|
set_mtu2_duty_again(p_mtu2_ctl->pulse2, wk_last_cycle, wk_cycle);
|
2015-07-10 04:32:35 +00:00
|
|
|
}
|
2019-03-07 03:00:57 +00:00
|
|
|
// Set mode
|
|
|
|
*p_mtu2_ctl->tmdr = 0x02; // PWM mode 1
|
2014-12-12 05:26:33 +00:00
|
|
|
// Counter Start
|
2015-07-10 04:32:35 +00:00
|
|
|
MTU2TSTR |= tmp_tstr_st;
|
2014-12-18 09:40:44 +00:00
|
|
|
// Save for future use
|
2015-07-10 04:32:35 +00:00
|
|
|
mtu2_period_ch[obj->ch] = us;
|
Commonalize the files in "targets/TARGET_RENESAS/TARGET_RZ_A1XX" directory
I made be available in common whatever the board related to RZ_A1 in the below files.
- Since there are the table code of Pinmap differs for each board, I moved the code to "PeripheralPins" file for each board, and changed to include PeripheralPins.h.
analogin_api.c, can_api.c, gpio_irq_api.c, i2c_api.c, pinmap.c, port_api.c, pwmout_api.c, serial_api.c, spi_api.c and us_ticker.c
- Since there are some board-specific processes, I enclosed the processes with "#ifdef" and rearranged the functions to make be easier to enclose.
can_api.c, ethernet_api.c and serial_api.c
- Since there are the driver configuration values differs for each board, I added "mbed_drv_cfg.h" file for each board and defined macros for the values, and changed to refer to the macros.
can_api.c, gpio_api.c, pwmout_api.c and rtc_api.c
2018-01-09 09:20:50 +00:00
|
|
|
#endif
|
2014-12-12 05:26:33 +00:00
|
|
|
} else {
|
Commonalize the files in "targets/TARGET_RENESAS/TARGET_RZ_A1XX" directory
I made be available in common whatever the board related to RZ_A1 in the below files.
- Since there are the table code of Pinmap differs for each board, I moved the code to "PeripheralPins" file for each board, and changed to include PeripheralPins.h.
analogin_api.c, can_api.c, gpio_irq_api.c, i2c_api.c, pinmap.c, port_api.c, pwmout_api.c, serial_api.c, spi_api.c and us_ticker.c
- Since there are some board-specific processes, I enclosed the processes with "#ifdef" and rearranged the functions to make be easier to enclose.
can_api.c, ethernet_api.c and serial_api.c
- Since there are the driver configuration values differs for each board, I added "mbed_drv_cfg.h" file for each board and defined macros for the values, and changed to refer to the macros.
can_api.c, gpio_api.c, pwmout_api.c and rtc_api.c
2018-01-09 09:20:50 +00:00
|
|
|
#ifdef FUNC_MOTOR_CTL_PWM
|
2015-07-10 04:32:35 +00:00
|
|
|
/* PWM */
|
|
|
|
if (us > 491) {
|
|
|
|
us = 491;
|
|
|
|
} else if (us < 1) {
|
|
|
|
us = 1;
|
|
|
|
} else {
|
|
|
|
// Do Nothing
|
|
|
|
}
|
2014-12-12 05:26:33 +00:00
|
|
|
|
2015-07-10 04:32:35 +00:00
|
|
|
if (RZ_A1_IsClockMode0() == false) {
|
|
|
|
pclk_base = (uint32_t)CM1_RENESAS_RZ_A1_P0_CLK / 10000;
|
|
|
|
} else {
|
|
|
|
pclk_base = (uint32_t)CM0_RENESAS_RZ_A1_P0_CLK / 10000;
|
|
|
|
}
|
2014-10-24 02:05:17 +00:00
|
|
|
|
2015-07-10 04:32:35 +00:00
|
|
|
wk_cycle = pclk_base * us;
|
|
|
|
while (wk_cycle >= 102350) {
|
|
|
|
wk_cycle >>= 1;
|
|
|
|
wk_cks++;
|
|
|
|
}
|
|
|
|
wk_cycle = (wk_cycle + 50) / 100;
|
|
|
|
|
|
|
|
if (obj->ch == 2) {
|
|
|
|
wk_last_cycle = PWMPWCYR_2 & 0x03ff;
|
2017-12-01 02:22:16 +00:00
|
|
|
PWMPWCR_2 = 0xc0 | wk_cks;
|
2015-07-10 04:32:35 +00:00
|
|
|
PWMPWCYR_2 = (uint16_t)wk_cycle;
|
|
|
|
|
|
|
|
// Set duty again
|
|
|
|
set_duty_again(&PWMPWBFR_2A, wk_last_cycle, wk_cycle);
|
|
|
|
set_duty_again(&PWMPWBFR_2C, wk_last_cycle, wk_cycle);
|
|
|
|
set_duty_again(&PWMPWBFR_2E, wk_last_cycle, wk_cycle);
|
|
|
|
set_duty_again(&PWMPWBFR_2G, wk_last_cycle, wk_cycle);
|
|
|
|
|
|
|
|
// Counter Start
|
2017-12-01 02:22:16 +00:00
|
|
|
PWMPWCR_2 |= 0x08;
|
2015-07-10 04:32:35 +00:00
|
|
|
|
|
|
|
// Save for future use
|
|
|
|
period_ch2 = us;
|
|
|
|
} else {
|
|
|
|
wk_last_cycle = PWMPWCYR_1 & 0x03ff;
|
2017-12-01 02:22:16 +00:00
|
|
|
PWMPWCR_1 = 0xc0 | wk_cks;
|
2015-07-10 04:32:35 +00:00
|
|
|
PWMPWCYR_1 = (uint16_t)wk_cycle;
|
|
|
|
|
|
|
|
// Set duty again
|
|
|
|
set_duty_again(&PWMPWBFR_1A, wk_last_cycle, wk_cycle);
|
|
|
|
set_duty_again(&PWMPWBFR_1C, wk_last_cycle, wk_cycle);
|
|
|
|
set_duty_again(&PWMPWBFR_1E, wk_last_cycle, wk_cycle);
|
|
|
|
set_duty_again(&PWMPWBFR_1G, wk_last_cycle, wk_cycle);
|
|
|
|
|
|
|
|
// Counter Start
|
2017-12-01 02:22:16 +00:00
|
|
|
PWMPWCR_1 |= 0x08;
|
2015-07-10 04:32:35 +00:00
|
|
|
|
|
|
|
// Save for future use
|
|
|
|
period_ch1 = us;
|
|
|
|
}
|
Commonalize the files in "targets/TARGET_RENESAS/TARGET_RZ_A1XX" directory
I made be available in common whatever the board related to RZ_A1 in the below files.
- Since there are the table code of Pinmap differs for each board, I moved the code to "PeripheralPins" file for each board, and changed to include PeripheralPins.h.
analogin_api.c, can_api.c, gpio_irq_api.c, i2c_api.c, pinmap.c, port_api.c, pwmout_api.c, serial_api.c, spi_api.c and us_ticker.c
- Since there are some board-specific processes, I enclosed the processes with "#ifdef" and rearranged the functions to make be easier to enclose.
can_api.c, ethernet_api.c and serial_api.c
- Since there are the driver configuration values differs for each board, I added "mbed_drv_cfg.h" file for each board and defined macros for the values, and changed to refer to the macros.
can_api.c, gpio_api.c, pwmout_api.c and rtc_api.c
2018-01-09 09:20:50 +00:00
|
|
|
#endif
|
2014-12-18 09:40:44 +00:00
|
|
|
}
|
2014-10-24 02:05:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void pwmout_pulsewidth(pwmout_t* obj, float seconds) {
|
|
|
|
pwmout_pulsewidth_us(obj, seconds * 1000000.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
void pwmout_pulsewidth_ms(pwmout_t* obj, int ms) {
|
|
|
|
pwmout_pulsewidth_us(obj, ms * 1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
void pwmout_pulsewidth_us(pwmout_t* obj, int us) {
|
2014-12-18 09:40:44 +00:00
|
|
|
float value = 0;
|
|
|
|
|
2016-09-23 05:43:06 +00:00
|
|
|
if (obj->pwm >= MTU2_PWM_OFFSET) {
|
Commonalize the files in "targets/TARGET_RENESAS/TARGET_RZ_A1XX" directory
I made be available in common whatever the board related to RZ_A1 in the below files.
- Since there are the table code of Pinmap differs for each board, I moved the code to "PeripheralPins" file for each board, and changed to include PeripheralPins.h.
analogin_api.c, can_api.c, gpio_irq_api.c, i2c_api.c, pinmap.c, port_api.c, pwmout_api.c, serial_api.c, spi_api.c and us_ticker.c
- Since there are some board-specific processes, I enclosed the processes with "#ifdef" and rearranged the functions to make be easier to enclose.
can_api.c, ethernet_api.c and serial_api.c
- Since there are the driver configuration values differs for each board, I added "mbed_drv_cfg.h" file for each board and defined macros for the values, and changed to refer to the macros.
can_api.c, gpio_api.c, pwmout_api.c and rtc_api.c
2018-01-09 09:20:50 +00:00
|
|
|
#ifdef FUMC_MTU2_PWM
|
2015-07-10 04:32:35 +00:00
|
|
|
/* PWM by MTU2 */
|
|
|
|
if (mtu2_period_ch[obj->ch] != 0) {
|
|
|
|
value = (float)us / (float)mtu2_period_ch[obj->ch];
|
2014-12-18 09:40:44 +00:00
|
|
|
}
|
Commonalize the files in "targets/TARGET_RENESAS/TARGET_RZ_A1XX" directory
I made be available in common whatever the board related to RZ_A1 in the below files.
- Since there are the table code of Pinmap differs for each board, I moved the code to "PeripheralPins" file for each board, and changed to include PeripheralPins.h.
analogin_api.c, can_api.c, gpio_irq_api.c, i2c_api.c, pinmap.c, port_api.c, pwmout_api.c, serial_api.c, spi_api.c and us_ticker.c
- Since there are some board-specific processes, I enclosed the processes with "#ifdef" and rearranged the functions to make be easier to enclose.
can_api.c, ethernet_api.c and serial_api.c
- Since there are the driver configuration values differs for each board, I added "mbed_drv_cfg.h" file for each board and defined macros for the values, and changed to refer to the macros.
can_api.c, gpio_api.c, pwmout_api.c and rtc_api.c
2018-01-09 09:20:50 +00:00
|
|
|
#endif
|
2014-12-18 09:40:44 +00:00
|
|
|
} else {
|
Commonalize the files in "targets/TARGET_RENESAS/TARGET_RZ_A1XX" directory
I made be available in common whatever the board related to RZ_A1 in the below files.
- Since there are the table code of Pinmap differs for each board, I moved the code to "PeripheralPins" file for each board, and changed to include PeripheralPins.h.
analogin_api.c, can_api.c, gpio_irq_api.c, i2c_api.c, pinmap.c, port_api.c, pwmout_api.c, serial_api.c, spi_api.c and us_ticker.c
- Since there are some board-specific processes, I enclosed the processes with "#ifdef" and rearranged the functions to make be easier to enclose.
can_api.c, ethernet_api.c and serial_api.c
- Since there are the driver configuration values differs for each board, I added "mbed_drv_cfg.h" file for each board and defined macros for the values, and changed to refer to the macros.
can_api.c, gpio_api.c, pwmout_api.c and rtc_api.c
2018-01-09 09:20:50 +00:00
|
|
|
#ifdef FUNC_MOTOR_CTL_PWM
|
2015-07-10 04:32:35 +00:00
|
|
|
/* PWM */
|
|
|
|
if (obj->ch == 2) {
|
|
|
|
if (period_ch2 != 0) {
|
|
|
|
value = (float)us / (float)period_ch2;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (period_ch1 != 0) {
|
|
|
|
value = (float)us / (float)period_ch1;
|
|
|
|
}
|
2014-12-18 09:40:44 +00:00
|
|
|
}
|
Commonalize the files in "targets/TARGET_RENESAS/TARGET_RZ_A1XX" directory
I made be available in common whatever the board related to RZ_A1 in the below files.
- Since there are the table code of Pinmap differs for each board, I moved the code to "PeripheralPins" file for each board, and changed to include PeripheralPins.h.
analogin_api.c, can_api.c, gpio_irq_api.c, i2c_api.c, pinmap.c, port_api.c, pwmout_api.c, serial_api.c, spi_api.c and us_ticker.c
- Since there are some board-specific processes, I enclosed the processes with "#ifdef" and rearranged the functions to make be easier to enclose.
can_api.c, ethernet_api.c and serial_api.c
- Since there are the driver configuration values differs for each board, I added "mbed_drv_cfg.h" file for each board and defined macros for the values, and changed to refer to the macros.
can_api.c, gpio_api.c, pwmout_api.c and rtc_api.c
2018-01-09 09:20:50 +00:00
|
|
|
#endif
|
2015-07-10 04:32:35 +00:00
|
|
|
}
|
2016-10-04 01:41:34 +00:00
|
|
|
pwmout_write(obj, value);
|
2014-10-24 02:05:17 +00:00
|
|
|
}
|
2019-01-24 04:16:51 +00:00
|
|
|
|
|
|
|
const PinMap *pwmout_pinmap()
|
|
|
|
{
|
|
|
|
return PinMap_PWM;
|
|
|
|
}
|