You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

531 lines
22 KiB

3 weeks ago
/***********************************************************************************************************************
* DISCLAIMER
* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products.
* No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
* applicable laws, including copyright laws.
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY
* LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT,
* INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR
* ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability
* of this software. By using this software, you agree to the additional terms and conditions found by accessing the
* following link:
* http://www.renesas.com/disclaimer
*
* Copyright (C) 2012, 2021 Renesas Electronics Corporation. All rights reserved.
***********************************************************************************************************************/
/***********************************************************************************************************************
* File Name : r_cg_serial.c
* Version : CodeGenerator for RL78/F14 V2.03.07.02 [08 Nov 2021]
* Device(s) : R5F10PPJ
* Tool-Chain : CCRL
* Description : This file implements device driver for Serial module.
1 week ago
* Creation Date: 2026-01-21
3 weeks ago
***********************************************************************************************************************/
/***********************************************************************************************************************
Includes
***********************************************************************************************************************/
#include "r_cg_macrodriver.h"
#include "r_cg_serial.h"
/* Start user code for include. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */
#include "r_cg_userdefine.h"
/***********************************************************************************************************************
Pragma directive
***********************************************************************************************************************/
/* Start user code for pragma. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */
/***********************************************************************************************************************
Global variables and functions
***********************************************************************************************************************/
volatile uint8_t * gp_uart0_tx_address; /* uart0 transmit buffer address */
volatile uint16_t g_uart0_tx_count; /* uart0 transmit data number */
volatile uint8_t * gp_uart0_rx_address; /* uart0 receive buffer address */
volatile uint16_t g_uart0_rx_count; /* uart0 receive data number */
volatile uint16_t g_uart0_rx_length; /* uart0 receive data length */
volatile uint8_t * gp_uart1_tx_address; /* uart1 transmit buffer address */
volatile uint16_t g_uart1_tx_count; /* uart1 transmit data number */
volatile uint8_t * gp_uart1_rx_address; /* uart1 receive buffer address */
volatile uint16_t g_uart1_rx_count; /* uart1 receive data number */
volatile uint16_t g_uart1_rx_length; /* uart1 receive data length */
2 weeks ago
volatile uint8_t g_iica0_master_status_flag; /* iica0 master flag */
volatile uint8_t g_iica0_slave_status_flag; /* iica0 slave flag */
volatile uint8_t * gp_iica0_rx_address; /* iica0 receive buffer address */
volatile uint16_t g_iica0_rx_len; /* iica0 receive data length */
volatile uint16_t g_iica0_rx_cnt; /* iica0 receive data count */
volatile uint8_t * gp_iica0_tx_address; /* iica0 send buffer address */
volatile uint16_t g_iica0_tx_cnt; /* iica0 send data count */
3 weeks ago
/* Start user code for global. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */
/***********************************************************************************************************************
* Function Name: R_SAU0_Create
* Description : This function initializes the SAU0 module.
* Arguments : None
* Return Value : None
***********************************************************************************************************************/
void R_SAU0_Create(void)
{
SAU0EN = 1U; /* supply SAU0 clock */
NOP();
NOP();
NOP();
NOP();
2 weeks ago
SPS0 = _0000_SAU_CK00_FCLK_0 | _0000_SAU_CK01_FCLK_0;
3 weeks ago
R_UART0_Create();
}
/***********************************************************************************************************************
* Function Name: R_UART0_Create
* Description : This function initializes the UART0 module.
* Arguments : None
* Return Value : None
***********************************************************************************************************************/
void R_UART0_Create(void)
{
ST0 |= _0002_SAU_CH1_STOP_TRG_ON | _0001_SAU_CH0_STOP_TRG_ON; /* disable UART0 receive and transmit */
STMK0 = 1U; /* disable INTST0 interrupt */
STIF0 = 0U; /* clear INTST0 interrupt flag */
SRMK0 = 1U; /* disable INTSR0 interrupt */
SRIF0 = 0U; /* clear INTSR0 interrupt flag */
/* Set INTST0 low priority */
STPR10 = 1U;
STPR00 = 1U;
/* Set INTSR0 low priority */
SRPR10 = 1U;
SRPR00 = 1U;
2 weeks ago
SMR00 = _0020_SAU_SMRMN_INITIALVALUE | _0000_SAU_CLOCK_SELECT_CK00 | _0000_SAU_TRIGGER_SOFTWARE |
3 weeks ago
_0002_SAU_MODE_UART | _0000_SAU_TRANSFER_END;
SCR00 = _8000_SAU_TRANSMISSION | _0000_SAU_PARITY_NONE | _0080_SAU_LSB | _0010_SAU_STOP_1 | _0007_SAU_LENGTH_8;
2 weeks ago
SDR00 = _4400_UART0_TRANSMIT_DIVISOR;
3 weeks ago
NFEN0 |= _01_SAU_RXD0_FILTER_ON;
SIR01 = _0004_SAU_SIRMN_FECTMN | _0002_SAU_SIRMN_PECTMN | _0001_SAU_SIRMN_OVCTMN; /* clear error flag */
SMR01 = _0020_SAU_SMRMN_INITIALVALUE | _0000_SAU_CLOCK_SELECT_CK00 | _0100_SAU_TRIGGER_RXD | _0000_SAU_EDGE_FALL |
_0002_SAU_MODE_UART | _0000_SAU_TRANSFER_END;
SCR01 = _4000_SAU_RECEPTION | _0000_SAU_PARITY_NONE | _0080_SAU_LSB | _0010_SAU_STOP_1 | _0007_SAU_LENGTH_8;
2 weeks ago
SDR01 = _4400_UART0_RECEIVE_DIVISOR;
3 weeks ago
SO0 |= _0001_SAU_CH0_DATA_OUTPUT_1;
SOL0 |= _0000_SAU_CHANNEL0_NORMAL; /* output level normal */
SOE0 |= _0001_SAU_CH0_OUTPUT_ENABLE; /* enable UART0 output */
/* Set RxD0 pin */
PM1 |= 0x40U;
/* Set TxD0 pin */
P1 |= 0x20U;
PM1 &= 0xDFU;
}
/***********************************************************************************************************************
* Function Name: R_UART0_Start
* Description : This function starts the UART0 module operation.
* Arguments : None
* Return Value : None
***********************************************************************************************************************/
void R_UART0_Start(void)
{
SO0 |= _0001_SAU_CH0_DATA_OUTPUT_1; /* output level normal */
SOE0 |= _0001_SAU_CH0_OUTPUT_ENABLE; /* enable UART0 output */
SS0 |= _0002_SAU_CH1_START_TRG_ON | _0001_SAU_CH0_START_TRG_ON; /* enable UART0 receive and transmit */
STIF0 = 0U; /* clear INTST0 interrupt flag */
SRIF0 = 0U; /* clear INTSR0 interrupt flag */
STMK0 = 0U; /* enable INTST0 interrupt */
SRMK0 = 0U; /* enable INTSR0 interrupt */
}
/***********************************************************************************************************************
* Function Name: R_UART0_Stop
* Description : This function stops the UART0 module operation.
* Arguments : None
* Return Value : None
***********************************************************************************************************************/
void R_UART0_Stop(void)
{
STMK0 = 1U; /* disable INTST0 interrupt */
SRMK0 = 1U; /* disable INTSR0 interrupt */
ST0 |= _0002_SAU_CH1_STOP_TRG_ON | _0001_SAU_CH0_STOP_TRG_ON; /* disable UART0 receive and transmit */
SOE0 &= ~_0001_SAU_CH0_OUTPUT_ENABLE; /* disable UART0 output */
STIF0 = 0U; /* clear INTST0 interrupt flag */
SRIF0 = 0U; /* clear INTSR0 interrupt flag */
}
/***********************************************************************************************************************
* Function Name: R_UART0_Receive
* Description : This function receives UART0 data.
* Arguments : rx_buf -
* receive buffer pointer
* rx_num -
* buffer size
* Return Value : status -
* MD_OK or MD_ARGERROR
***********************************************************************************************************************/
MD_STATUS R_UART0_Receive(uint8_t * const rx_buf, uint16_t rx_num)
{
MD_STATUS status = MD_OK;
if (rx_num < 1U)
{
status = MD_ARGERROR;
}
else
{
g_uart0_rx_count = 0U;
g_uart0_rx_length = rx_num;
gp_uart0_rx_address = rx_buf;
}
return (status);
}
/***********************************************************************************************************************
* Function Name: R_UART0_Send
* Description : This function sends UART0 data.
* Arguments : tx_buf -
* transfer buffer pointer
* tx_num -
* buffer size
* Return Value : status -
* MD_OK or MD_ARGERROR
***********************************************************************************************************************/
MD_STATUS R_UART0_Send(uint8_t * const tx_buf, uint16_t tx_num)
{
MD_STATUS status = MD_OK;
if (tx_num < 1U)
{
status = MD_ARGERROR;
}
else
{
gp_uart0_tx_address = tx_buf;
g_uart0_tx_count = tx_num;
STMK0 = 1U; /* disable INTST0 interrupt */
SDR00L = *gp_uart0_tx_address;
gp_uart0_tx_address++;
g_uart0_tx_count--;
STMK0 = 0U; /* enable INTST0 interrupt */
}
return (status);
}
/***********************************************************************************************************************
* Function Name: R_SAU1_Create
* Description : This function initializes the SAU1 module.
* Arguments : None
* Return Value : None
***********************************************************************************************************************/
void R_SAU1_Create(void)
{
SAU1EN = 1U; /* supply SAU1 clock */
NOP();
NOP();
NOP();
NOP();
2 weeks ago
SPS1 = _0000_SAU_CK00_FCLK_0 | _0000_SAU_CK01_FCLK_0;
3 weeks ago
R_UART1_Create();
}
/***********************************************************************************************************************
* Function Name: R_UART1_Create
* Description : This function initializes the UART1 module.
* Arguments : None
* Return Value : None
***********************************************************************************************************************/
void R_UART1_Create(void)
{
ST1 |= _0002_SAU_CH1_STOP_TRG_ON | _0001_SAU_CH0_STOP_TRG_ON; /* disable UART1 receive and transmit */
STMK1 = 1U; /* disable INTST1 interrupt */
STIF1 = 0U; /* clear INTST1 interrupt flag */
SRMK1 = 1U; /* disable INTSR1 interrupt */
SRIF1 = 0U; /* clear INTSR1 interrupt flag */
/* Set INTST1 low priority */
STPR11 = 1U;
STPR01 = 1U;
/* Set INTSR1 low priority */
SRPR11 = 1U;
SRPR01 = 1U;
SMR10 = _0020_SAU_SMRMN_INITIALVALUE | _0000_SAU_CLOCK_SELECT_CK00 | _0000_SAU_TRIGGER_SOFTWARE |
_0002_SAU_MODE_UART | _0000_SAU_TRANSFER_END;
SCR10 = _8000_SAU_TRANSMISSION | _0000_SAU_PARITY_NONE | _0080_SAU_LSB | _0010_SAU_STOP_1 | _0007_SAU_LENGTH_8;
2 weeks ago
SDR10 = _4400_UART1_TRANSMIT_DIVISOR;
3 weeks ago
NFEN0 |= _04_SAU_RXD1_FILTER_ON;
SIR11 = _0004_SAU_SIRMN_FECTMN | _0002_SAU_SIRMN_PECTMN | _0001_SAU_SIRMN_OVCTMN; /* clear error flag */
SMR11 = _0020_SAU_SMRMN_INITIALVALUE | _0000_SAU_CLOCK_SELECT_CK00 | _0100_SAU_TRIGGER_RXD | _0000_SAU_EDGE_FALL |
_0002_SAU_MODE_UART | _0000_SAU_TRANSFER_END;
SCR11 = _4000_SAU_RECEPTION | _0000_SAU_PARITY_NONE | _0080_SAU_LSB | _0010_SAU_STOP_1 | _0007_SAU_LENGTH_8;
2 weeks ago
SDR11 = _4400_UART1_RECEIVE_DIVISOR;
3 weeks ago
SO1 |= _0001_SAU_CH0_DATA_OUTPUT_1;
SOL1 |= _0000_SAU_CHANNEL0_NORMAL; /* output level normal */
SOE1 |= _0001_SAU_CH0_OUTPUT_ENABLE; /* enable UART1 output */
/* Set RxD1 pin */
PM1 |= 0x02U;
/* Set TxD1 pin */
P1 |= 0x04U;
PM1 &= 0xFBU;
}
/***********************************************************************************************************************
* Function Name: R_UART1_Start
* Description : This function starts the UART1 module operation.
* Arguments : None
* Return Value : None
***********************************************************************************************************************/
void R_UART1_Start(void)
{
SO1 |= _0001_SAU_CH0_DATA_OUTPUT_1; /* output level normal */
SOE1 |= _0001_SAU_CH0_OUTPUT_ENABLE; /* enable UART1 output */
SS1 |= _0002_SAU_CH1_START_TRG_ON | _0001_SAU_CH0_START_TRG_ON; /* enable UART1 receive and transmit */
STIF1 = 0U; /* clear INTST1 interrupt flag */
SRIF1 = 0U; /* clear INTSR1 interrupt flag */
STMK1 = 0U; /* enable INTST1 interrupt */
SRMK1 = 0U; /* enable INTSR1 interrupt */
}
/***********************************************************************************************************************
* Function Name: R_UART1_Stop
* Description : This function stops the UART1 module operation.
* Arguments : None
* Return Value : None
***********************************************************************************************************************/
void R_UART1_Stop(void)
{
STMK1 = 1U; /* disable INTST1 interrupt */
SRMK1 = 1U; /* disable INTSR1 interrupt */
ST1 |= _0002_SAU_CH1_STOP_TRG_ON | _0001_SAU_CH0_STOP_TRG_ON; /* disable UART1 receive and transmit */
SOE1 &= ~_0001_SAU_CH0_OUTPUT_ENABLE; /* disable UART1 output */
STIF1 = 0U; /* clear INTST1 interrupt flag */
SRIF1 = 0U; /* clear INTSR1 interrupt flag */
}
/***********************************************************************************************************************
* Function Name: R_UART1_Receive
* Description : This function receives UART1 data.
* Arguments : rx_buf -
* receive buffer pointer
* rx_num -
* buffer size
* Return Value : status -
* MD_OK or MD_ARGERROR
***********************************************************************************************************************/
MD_STATUS R_UART1_Receive(uint8_t * const rx_buf, uint16_t rx_num)
{
MD_STATUS status = MD_OK;
if (rx_num < 1U)
{
status = MD_ARGERROR;
}
else
{
g_uart1_rx_count = 0U;
g_uart1_rx_length = rx_num;
gp_uart1_rx_address = rx_buf;
}
return (status);
}
/***********************************************************************************************************************
* Function Name: R_UART1_Send
* Description : This function sends UART1 data.
* Arguments : tx_buf -
* transfer buffer pointer
* tx_num -
* buffer size
* Return Value : status -
* MD_OK or MD_ARGERROR
***********************************************************************************************************************/
MD_STATUS R_UART1_Send(uint8_t * const tx_buf, uint16_t tx_num)
{
MD_STATUS status = MD_OK;
if (tx_num < 1U)
{
status = MD_ARGERROR;
}
else
{
gp_uart1_tx_address = tx_buf;
g_uart1_tx_count = tx_num;
STMK1 = 1U; /* disable INTST1 interrupt */
SDR10L = *gp_uart1_tx_address;
gp_uart1_tx_address++;
g_uart1_tx_count--;
STMK1 = 0U; /* enable INTST1 interrupt */
}
return (status);
}
2 weeks ago
/***********************************************************************************************************************
* Function Name: R_IICA0_Create
* Description : This function initializes the IICA0 module.
* Arguments : None
* Return Value : None
***********************************************************************************************************************/
void R_IICA0_Create(void)
{
IICA0EN = 1U; /* supply IICA0 clock */
IICE0 = 0U; /* disable IICA0 operation */
IICAMK0 = 1U; /* disable INTIICA0 interrupt */
IICAIF0 = 0U; /* clear INTIICA0 interrupt flag */
/* Set INTIICA0 low priority */
IICAPR10 = 1U;
IICAPR00 = 1U;
/* Set SCLA0, SDAA0 pin */
P6 &= 0xF3U;
PM6 |= 0x0CU;
SMC0 = 0U;
IICWL0 = _4C_IICA0_IICWL_VALUE;
IICWH0 = _55_IICA0_IICWH_VALUE;
IICCTL01 |= _01_IICA_fCLK_HALF;
SVA0 = _10_IICA0_MASTERADDRESS;
STCEN0 = 1U;
IICRSV0 = 1U;
SPIE0 = 0U;
WTIM0 = 1U;
ACKE0 = 1U;
IICAMK0 = 0U;
IICE0 = 1U;
LREL0 = 1U;
/* Set SCLA0, SDAA0 pin */
PM6 &= 0xF3U;
}
/***********************************************************************************************************************
* Function Name: R_IICA0_Stop
* Description : This function stops IICA0 module operation.
* Arguments : None
* Return Value : None
***********************************************************************************************************************/
void R_IICA0_Stop(void)
{
IICE0 = 0U; /* disable IICA0 operation */
}
/***********************************************************************************************************************
* Function Name: R_IICA0_StopCondition
* Description : This function sets IICA0 stop condition flag.
* Arguments : None
* Return Value : None
***********************************************************************************************************************/
void R_IICA0_StopCondition(void)
{
SPT0 = 1U; /* set stop condition flag */
}
/***********************************************************************************************************************
* Function Name: R_IICA0_Master_Send
* Description : This function starts to send data as master mode.
* Arguments : adr -
* send address
* tx_buf -
* transfer buffer pointer
* tx_num -
* buffer size
* wait -
* wait for start condition
* Return Value : status -
* MD_OK or MD_ERROR1 or MD_ERROR2
***********************************************************************************************************************/
MD_STATUS R_IICA0_Master_Send(uint8_t adr, uint8_t * const tx_buf, uint16_t tx_num, uint8_t wait)
{
MD_STATUS status = MD_OK;
IICAMK0 = 1U; /* disable INTIICA0 interrupt */
if ((1U == IICBSY0) && (0U == MSTS0))
{
/* Check bus busy */
IICAMK0 = 0U; /* enable INTIICA0 interrupt */
status = MD_ERROR1;
}
else
{
STT0 = 1U; /* send IICA0 start condition */
IICAMK0 = 0U; /* enable INTIICA0 interrupt */
/* Wait */
while (wait--)
{
;
}
if (0U == STD0)
{
status = MD_ERROR2;
}
/* Set parameter */
g_iica0_tx_cnt = tx_num;
gp_iica0_tx_address = tx_buf;
g_iica0_master_status_flag = _00_IICA_MASTER_FLAG_CLEAR;
adr &= (uint8_t)~0x01U; /* set send mode */
IICA0 = adr; /* send address */
}
return (status);
}
/***********************************************************************************************************************
* Function Name: R_IICA0_Master_Receive
* Description : This function starts to receive IICA0 data as master mode.
* Arguments : adr -
* receive address
* rx_buf -
* receive buffer pointer
* rx_num -
* buffer size
* wait -
* wait for start condition
* Return Value : status -
* MD_OK or MD_ERROR1 or MD_ERROR2
***********************************************************************************************************************/
MD_STATUS R_IICA0_Master_Receive(uint8_t adr, uint8_t * const rx_buf, uint16_t rx_num, uint8_t wait)
{
MD_STATUS status = MD_OK;
IICAMK0 = 1U; /* disable INTIIA0 interrupt */
if ((1U == IICBSY0) && (0U == MSTS0))
{
/* Check bus busy */
IICAMK0 = 0U; /* enable INTIIA0 interrupt */
status = MD_ERROR1;
}
else
{
STT0 = 1U; /* set IICA0 start condition */
IICAMK0 = 0U; /* enable INTIIA0 interrupt */
/* Wait */
while (wait--)
{
;
}
if (0U == STD0)
{
status = MD_ERROR2;
}
/* Set parameter */
g_iica0_rx_len = rx_num;
g_iica0_rx_cnt = 0U;
gp_iica0_rx_address = rx_buf;
g_iica0_master_status_flag = _00_IICA_MASTER_FLAG_CLEAR;
adr |= 0x01U; /* set receive mode */
IICA0 = adr; /* receive address */
}
return (status);
}
3 weeks ago
/* Start user code for adding. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */