/******************************************************************************* * 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 * (c) 2014 Renesas Electronics Corporation All rights reserved. *******************************************************************************/ /****************************************************************************** * File Name : r_lps_Digital.c * Version : 1.0 * Device(s) : R7F701007 RH850/F1L * Tool-Chain : IAR Embedded Workbench 1.30.1 * Description : This file is a sample of the low power sampler (LPS Digital input mode) . * Operation : - ******************************************************************************* ******************************************************************************* * History : DD.MM.YYYY Version Description * : 20.03.2014 1.00 First Release ******************************************************************************/ /****************************************************************************** Includes ******************************************************************************/ #include "r_typedefs.h" #include "iodefine.h" #ifdef __ghs__ #include "device.h" #endif #ifdef __IAR_SYSTEMS_ICC__ #include #endif /****************************************************************************** Imported global variables and functions (from other files) ******************************************************************************/ /****************************************************************************** Macro definitions ******************************************************************************/ /****************************************************************************** Exported global variables and functions (to be accessed by other files) ******************************************************************************/ void R_LPS_Init( void ); void R_LPS_Start( void ); void R_LPS_Stop( void ); /****************************************************************************** Private global variables and functions ******************************************************************************/ /****************************************************************************** * Function Name : void R_LPS_Init( void ) * Description : This function initializes the LPS. * Argument : none * Return Value : none ******************************************************************************/ void R_LPS_Init( void ) { /* Set interrupt flags */ MKCWEND = 1U; RFCWEND = 0U; TBCWEND = 1U; /* DPIN3(P8_3) CN1D-93pin */ PFCE8 &= 0xFFF7U; PFC8 |= 0x0008U; PM8 |= 0x0008U; PMC8 |= 0x0008U; PU8 |= 0x0008U; /* DPO (P0_2) CN2B-36pin */ PFCAE0 |= 0x0004U; PFCE0 &= 0xFFFBU; PFC0 &= 0xFFFBU; PM0 &= 0xFFFBU; PMC0 |= 0x0004U; /* SELDP0 (P0_4) CN2B-41pin */ /* SELDP1 (P0_5) CN2B-42pin */ /* SELDP2 (P0_6) CN2C-73pin */ PFCAE0 &= 0xFF8FU; PFCE0 &= 0xFF9FU; PFCE0 |= 0x0010U; PFC0 &= 0xFFEFU; PFC0 |= 0x0060U; PM0 &= 0xFF8FU; PMC0 |= 0x0070U; /* Set the lead number of times and the trigger signal of the port in the digital input mode. SCTLR - LPS Control Registers b31:b 7 - Reserved set to 0 b 6:b 4 NUMDP - Set the number of times the port is read in digital input mode. - Eight times b 3:b 2 TJIS - Sequence Start Trigger Select - INTTAUJ0I0 b 1 ADEN - Analog input mode is stopped / enabled - Unused. Set to 0'b b 0 DPEN - Digital input mode is stopped / enabled - stopped */ SCTLR = 0x00000070UL; /* Crear compare data EVFR - Event Flag Register b31:b 1 - Reserved set to 0 b 0 DINEVF - Crear compare data. set to 0 */ EVFR = 0x00000000UL; /* Set intervaltimer function of TAUJ0. */ /* Set stabilization time CNTVAL - Count Value Register b15:b 8 CNT - set the stabilization time of the external circuit (analog signal source). - Unused. Set to 00H b 7:b 0 CNT - set the stabilization time of the external circuit (digital signal source). - 1 / fRH x 16 x 00H */ CNTVAL = 0x0000U; /* Set expectation by DPDSR0 register , DPDSRM register and DPDSRH register DPDSR0 - DPIN Data Set Register 0 b31:b24 - Reserved set to 0 b23:b 0 D0_n - Data to be compared with the first digital port input (DPINm) - Set to D0_3 */ DPDSR0 = 0x00000008UL; /* Set expectation by DPDSR0 register , DPDSRM register and DPDSRH register DPDSRM - DPIN Data Set Register M b31:b24 D4_n - Data to be compared with the fifth digital port input (DPINm) - Set to D4_3 b23:b16 D3_n - Data to be compared with the fourth digital port input (DPINm) - Set to D3_3 b15:b 8 D2_n - Data to be compared with the third digital port input (DPINm) - Set to D2_3 b 7:b 0 D1_n - Data to be compared with the second digital port input (DPINm) - Set to D1_3 */ DPDSRM = 0x08080808UL; /* Set expectation by DPDSR0 register , DPDSRM register and DPDSRH register DPDSRH - DPIN Data Set Register H b31:b24 - Reserved set to 0 b23:b16 D7_n - Data to be compared with the eighth digital port input (DPINm) - Set to D7_3 b15:b 8 D6_n - Data to be compared with the seventh digital port input (DPINm) - Set to D6_3 b 7:b 0 D5_n - Data to be compared with the sixth digital port input (DPINm) - Set to D5_3 */ DPDSRH = 0x00080808UL; /* Port to confirm is set by DPSELR0 register , DPSELRM register and DPSELRH register. DPSELR0 - DPIN Select Register 0 b31:b24 - Reserved set to 0 b23:b 0 D0EN_n - enable or disable comparison of the data (DPDIMR0) which acquired the first digital port input (DPINm) with the compare target data (DPDSR0). - Enable D0EN_3 */ DPSELR0 = 0x00000008UL; /* Port to confirm is set by DPSELR0 register , DPSELRM register and DPSELRH register. DPSELRM - DPIN Select Register M b31:b24 D0EN_n - enable or disable comparison of the data (DPDIMR4) which acquired the fifth digital port input (DPINm) with the compare target data (DPDSR4). - Enable D4EN_3 b23:b16 D0EN_n - enable or disable comparison of the data (DPDIMR3) which acquired the fifth digital port input (DPINm) with the compare target data (DPDSR3). - Enable D3EN_3 b15:b 8 D0EN_n - enable or disable comparison of the data (DPDIMR2) which acquired the fifth digital port input (DPINm) with the compare target data (DPDSR2). - Enable D2EN_3 b 7:b 0 D0EN_n - enable or disable comparison of the data (DPDIMR1) which acquired the fifth digital port input (DPINm) with the compare target data (DPDSR1). - Enable D1EN_3 */ DPSELRM = 0x08080808UL; /* Port to confirm is set by DPSELR0 register , DPSELRM register and DPSELRH register. DPSELRH - DPIN Select Register H b31:b24 - Reserved set to 0 b23:b16 D0EN_n - enable or disable comparison of the data (DPDIMR7) which acquired the fifth digital port input (DPINm) with the compare target data (DPDSR7). - Enable D7EN_3 b15:b 8 D0EN_n - enable or disable comparison of the data (DPDIMR6) which acquired the fifth digital port input (DPINm) with the compare target data (DPDSR6). - Enable D6EN_3 b 7:b 0 D0EN_n - enable or disable comparison of the data (DPDIMR5) which acquired the fifth digital port input (DPINm) with the compare target data (DPDSR5). - Enable D5EN_3 */ DPSELRH = 0x00080808UL; } /****************************************************************************** * Function Name : void R_LPS_Start( void ) * Description : This function start the LPS. * Argument : none * Return Value : none ******************************************************************************/ void R_LPS_Start( void ) { MKCWEND = 0U; /* Enable INTCWEND */ /* Set SCTLR.DPEN bit */ SCTLR |= 0x00000001UL; /* Digital input mode enable */ } /****************************************************************************** * Function Name : void R_LPS_Stop( void ) * Description : This function stop the LPS. * Argument : none * Return Value : none ******************************************************************************/ void R_LPS_Stop( void ) { MKCWEND = 1U; /* Disable INTCWEND */ RFCWEND = 0U; /* Clear INTCWEND interrupt flag */ TBCWEND = 1U; /* Set INTCWEND table refer */ /* Clear SCTLR.DPEN bit */ SCTLR &= 0xFFFFFFFEUL; /* Digital input mode disable */ /* confirm DPDIMR0-7 register as needed */ /* Unused by the sample program. */ /* The sampling data are stored by DPDIMR0-7 register. When check an incongruous port, Read DPDIMR0-7 register */ EVFR = 0x00000000UL; /* Clear a comparison result */ }