/******************************************************************************* * 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_main.c * Version : 1.0 * Device(s) : R7F701007 RH850/F1L * Tool-Chain : IAR Embedded Workbench 1.30.1 * Description : This file is a main sample of the CSI function. * Operation : 1. Compile and download the sample code. Click ?eReset Go?f * : to start the software. ******************************************************************************* ******************************************************************************* * History : DD.MM.YYYY Version Description * : 20.03.2014 1.00 First Release ******************************************************************************/ /****************************************************************************** Includes , ?gProject Includes?h ******************************************************************************/ #include "r_typedefs.h" #include "iodefine.h" #ifdef __ghs__ #include "device.h" #endif #ifdef __IAR_SYSTEMS_ICC__ #include #endif #include "r_port.h" #include "r_csig.h" /****************************************************************************** Imported global variables and functions (from other files) ******************************************************************************/ extern void R_CLOCK_Init( void ); /****************************************************************************** Macro definitions ******************************************************************************/ enum { CSI_TRANSMISSION = 0, CSI_RECEPTION, CSI_RECEPTION_FLAG, CSI_TYPE_MAX }; #define CSI_DATA_MAX 4 #define CSI_RECEIVE_OK (1) #define CSI_RECEIVE_NG (0) /****************************************************************************** Exported global variables and functions (to be accessed by other files) ******************************************************************************/ /****************************************************************************** Private global variables and functions ******************************************************************************/ void main( void ); static volatile uint16_t uint16_master[CSI_TYPE_MAX][CSI_DATA_MAX]; static volatile uint16_t uint16_slave[CSI_TYPE_MAX][CSI_DATA_MAX]; void r_intr_main_csig0ic(void); void r_intr_main_csig0ir(void); void r_intr_main_csig0ire(void); void r_intr_main_csig1ic(void); void r_intr_main_csig1ir(void); void r_intr_main_csig1ire(void); /****************************************************************************** * Function Name : void main( void ) * Description : This function is sample main processing. * Argument : none * Return Value : none ******************************************************************************/ void main( void ) { uint8_t i,j; /**************************************************/ /* initialize */ /**************************************************/ /* clock setting */ R_CLOCK_Init(); /* port setting */ R_port_initialize_for_csig(); /**************************************************/ /* CSIG Communication */ /**************************************************/ for(i=0;i>> CSIG1(Slave mode) */ /* CSIG0: Transmission in Master mode */ /* CSIG1: Reception in Slave mode */ /**************************************************/ /* interrupt disable */ __DI(); /* CSIG slave setting */ R_csig1_slave_reception_initialize(); R_csig1_interrupt_callback( (CSIG_CALLBACK_POINTER)NULL, (CSIG_CALLBACK_POINTER)r_intr_main_csig1ir, (CSIG_CALLBACK_POINTER)r_intr_main_csig1ire ); /* CSIG master setting */ R_csig0_master_transmission_initialize(); R_csig0_interrupt_callback( (CSIG_CALLBACK_POINTER)r_intr_main_csig0ic, (CSIG_CALLBACK_POINTER)NULL, (CSIG_CALLBACK_POINTER)r_intr_main_csig0ire ); /* CSIG slave enable */ R_csig1_slave_reception_enable(); /* CSIG master enable */ R_csig0_master_transmission_enable(); /* interrupt enable */ __EI(); /* CSIG slave Reception */ R_csig1_slave_receive(); /* CSIG master Transmission */ R_csig0_master_transmit(uint16_master[CSI_TRANSMISSION][0]); /* wait for CSIG reception */ while(uint16_slave[CSI_RECEPTION_FLAG][0] == CSI_RECEIVE_NG) { #if !defined(__IAR_SYSTEMS_ICC__) __nop(); #endif #ifdef __IAR_SYSTEMS_ICC__ __asm( "nop"); #endif } /**************************************************/ /* CSIG0(Master mode) <<< CSIG1(Slave mode) */ /* CSIG0: Reception in Master mode */ /* CSIG1: Transmission in Slave mode */ /**************************************************/ /* interrupt disable */ __DI(); /* CSIG master setting */ R_csig0_master_reception_initialize(); R_csig0_interrupt_callback( (CSIG_CALLBACK_POINTER)NULL, (CSIG_CALLBACK_POINTER)r_intr_main_csig0ir, (CSIG_CALLBACK_POINTER)r_intr_main_csig0ire ); /* CSIG slave setting */ R_csig1_slave_transmission_initialize(); R_csig1_interrupt_callback( (CSIG_CALLBACK_POINTER)r_intr_main_csig1ic, (CSIG_CALLBACK_POINTER)NULL, (CSIG_CALLBACK_POINTER)r_intr_main_csig1ire ); /* CSIG master enable */ R_csig0_master_reception_enable(); /* CSIG slave enable */ R_csig1_slave_transmission_enable(); /* interrupt enable */ __EI(); /* CSIG master Reception */ R_csig0_master_receive(); /* CSIG slave Transmission */ R_csig1_slave_transmit(uint16_slave[CSI_TRANSMISSION][0]); /* wait for CSIG reception */ while(uint16_master[CSI_RECEPTION_FLAG][0] == CSI_RECEIVE_NG) { #if !defined(__IAR_SYSTEMS_ICC__) __nop(); #endif #ifdef __IAR_SYSTEMS_ICC__ __asm( "nop"); #endif } while (1U) { #if !defined(__IAR_SYSTEMS_ICC__) __nop(); #endif #ifdef __IAR_SYSTEMS_ICC__ __asm( "nop"); #endif } } /****************************************************************************** * Function Name : void r_intr_main_csig0ic( void ) * Description : This function is CSIG0 communication signal interrupt. * Argument : none * Return Value : none ******************************************************************************/ void r_intr_main_csig0ic(void) { } /****************************************************************************** * Function Name : void r_intr_main_csig0ir( void ) * Description : This function is CSIG0 reception signal interrupt. * Argument : none * Return Value : none ******************************************************************************/ void r_intr_main_csig0ir(void) { CSIG0.BCTL0.UINT8 = 0x00; /* get reception data */ uint16_master[CSI_RECEPTION][0] = CSIG0.RX0; /* set reception complete flag */ uint16_master[CSI_RECEPTION_FLAG][0] = CSI_RECEIVE_OK; } /****************************************************************************** * Function Name : void r_intr_main_csig0ire( void ) * Description : This function is CSIG0 reception error signal interrupt. * Argument : none * Return Value : none ******************************************************************************/ void r_intr_main_csig0ire(void) { } /****************************************************************************** * Function Name : void r_intr_main_csig1ic( void ) * Description : This function is CSIG1 communication signal interrupt. * Argument : none * Return Value : none ******************************************************************************/ void r_intr_main_csig1ic(void) { } /****************************************************************************** * Function Name : void r_intr_main_csig1ir( void ) * Description : This function is CSIG1 reception signal interrupt. * Argument : none * Return Value : none ******************************************************************************/ void r_intr_main_csig1ir(void) { uint16_t uint16_temp[5]; /* get reception data */ uint16_slave[CSI_RECEPTION][0] = CSIG1.RX0; /* transmission data caluculate*/ uint16_temp[0] = uint16_slave[CSI_RECEPTION][0]; uint16_temp[1] = uint16_temp[0] >> 8; uint16_temp[2] = uint16_temp[0] & 0x00FF; uint16_temp[3] = uint16_temp[1] + uint16_temp[2]; uint16_temp[4] = uint16_temp[1] - uint16_temp[2]; /* set transmission data */ uint16_slave[CSI_TRANSMISSION][0] = (uint16_temp[3] << 8) + uint16_temp[4]; /* set reception complete flag */ uint16_slave[CSI_RECEPTION_FLAG][0] = CSI_RECEIVE_OK; } /****************************************************************************** * Function Name : void r_intr_main_csig1ire( void ) * Description : This function is CSIG1 reception error signal interrupt. * Argument : none * Return Value : none ******************************************************************************/ void r_intr_main_csig1ire(void) { }