少し前に別スレッドでRL78/G1CのUSB PCDCドライバのエコーバックサンプルプログラムを見ることがあり、それがきっかけで幾つかUSB PCDCドライバのエコーバックサンプルプログラムのソースコードを見比べたのですが、この際ですので見てみたものを並べておこうと思いました。(1) an_r01an2238jj0121 : FIT USBモジュール版 (RX63N等)(2) an_r01an0273jj0230 : (非FIT) USBモジュール版 (RX62N等)(3) an_r01an0555jj0215 : (非FIT) MINI USBモジュール版 (RL78/G1C等)(4) an_r01an0273jj0210 : (FIT以前) USBモジュール版 (RX62N,RX63N等)なお、ルネサス社のUSB PCDCドライバのアプリケーションノートは(4)が源流のようですが、MINI版の(3)の枝分かれが出て、後継としてのFIT版の(1)が出た後、いつの間にかFIT版の(1)と同等な(2)への置き換えが行われたようです。つまり、USB PCDCドライバのソースとしては(1)と(2)は大差無く、FIT対応のRXマイコンであるかどうかという点で(1)と(2)は別管理となっているだけのようです。以下、それぞれのエコーバックサンプルプログラムのソースコードです。(1) an_r01an2238jj0121 : FIT USBモジュール版 (RX63N等)r_usb_pcdc_echo_apl.c (端子設定関数省略) (省略無しはこちら)
/*********************************************************************************************************************** * 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) 2014(2016) Renesas Electronics Corporation. All rights reserved. ***********************************************************************************************************************/ /******************************************************************************* * File Name : r_usb_pcdc_apl.c * Description : USB Peripheral Communications Devices Class Sample Code ******************************************************************************* * History : DD.MM.YYYY Version Description * : 08.01.2014 1.00 First Release * : 26.12.2014 1.10 RX71M is added * : 30.09.2015 1.11 RX63N/RX631 is added. * : 30.09.2016 1.20 RX65N/RX651 is added. ******************************************************************************/ /****************************************************************************** Includes <System Includes> , "Project Includes" ******************************************************************************/ #include "r_usb_pcdc_apl.h" #if OPERATION_MODE == USB_ECHO /****************************************************************************** Macro definitions ***************************************************************************#***/ /****************************************************************************** Private global variables and functions ******************************************************************************/ static void usb_pin_setting (void); static uint8_t g_buf[DATA_LEN]; const static usb_descriptor_t usb_descriptor = { g_apl_device, /* Pointer to the device descriptor */ g_apl_configuration, /* Pointer to the configuration descriptor for Full-speed */ USB_NULL, /* Pointer to the configuration descriptor for Hi-speed */ USB_NULL, /* Pointer to the qualifier descriptor */ g_apl_string_table /* Pointer to the string descriptor table */ }; /****************************************************************************** Renesas Peripheral Communications Devices Class Sample Code functions ******************************************************************************/ /****************************************************************************** Function Name : usb_main Description : Peripheral CDC application main process Arguments : none Return value : none ******************************************************************************/ void usb_main (void) { usb_ctrl_t ctrl; usb_cfg_t cfg; usb_pin_setting(); /* USB MCU pin setting */ ctrl.module = USE_USBIP; ctrl.type = USB_PCDC; cfg.usb_speed = USB_SUPPORT_SPEED; /* USB_HS/USB_FS */ cfg.usb_mode = USB_PERI; cfg.p_usb_reg = (usb_descriptor_t *)&usb_descriptor; R_USB_Open(&ctrl, &cfg); /* Initializes the USB module */ /* Loop back between PC(TerminalSoft) and USB MCU */ while (1) { switch (R_USB_GetEvent(&ctrl)) { case USB_STS_CONFIGURED : case USB_STS_WRITE_COMPLETE : ctrl.type = USB_PCDC; R_USB_Read(&ctrl, g_buf, DATA_LEN); break; case USB_STS_READ_COMPLETE : R_USB_Write(&ctrl, g_buf, ctrl.size); break; case USB_STS_SUSPEND : case USB_STS_DETACH : #if defined(USE_LPW) low_power_mcu(); #endif /* defined(USE_LPW) */ break; default : break; } } } /* End of function usb_main() */ /****************************************************************************** Function Name : usb_pin_setting Description : USB Pin Setting Arguments : none Return value : none ******************************************************************************/ /*---CUT---CUT---CUT---CUT---CUT---CUT---CUT---CUT---CUT---CUT---CUT---CUT---*/ #endif /* OPERATION_MODE == USB_ECHO */ /****************************************************************************** End Of File ******************************************************************************/
/********************************************************************************************************************** * 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) 2014(2016) Renesas Electronics Corporation. All rights reserved. *********************************************************************************************************************/ /********************************************************************************************************************** * File Name : main.c * Description : main process *********************************************************************************************************************/ /********************************************************************************************************************** * History : DD.MM.YYYY Version Description * : 08.01.2014 1.00 First Release * : 26.12.2014 1.10 RX71M is added * : 30.09.2015 1.11 RX63N/RX631 is added. * : 30.09.2016 1.20 RX65N/RX651 is added. *********************************************************************************************************************/ /****************************************************************************** Includes <System Includes> , "Project Includes" ******************************************************************************/ /****************************************************************************** Exported global variables ******************************************************************************/ extern void usb_main(void); /****************************************************************************** Function Name : main Description : Main task Arguments : none Return value : none ******************************************************************************/ void main (void) { usb_main(); /* USB sample application */ } /****************************************************************************** End of function main() ******************************************************************************/ /****************************************************************************** End Of File ******************************************************************************/
/*********************************************************************************************************************** * 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) 2015(2016) Renesas Electronics Corporation. All rights reserved. ***********************************************************************************************************************/ /******************************************************************************* * File Name : r_usb_pcdc_echo_apl.c * Description : USB Peripheral Communications Devices Class Sample Code ******************************************************************************* * History : DD.MM.YYYY Version Description * : 30.09.2015 2.20 First Release * : 30.09.2016 2.30 Using new USB API. ******************************************************************************/ /****************************************************************************** Includes <System Includes> , "Project Includes" ******************************************************************************/ #include "r_usb_pcdc_apl.h" #if OPERATION_MODE == USB_ECHO /****************************************************************************** Macro definitions ***************************************************************************#***/ /****************************************************************************** Private global variables and functions ******************************************************************************/ static void usb_pin_setting (void); static uint8_t g_buf[DATA_LEN]; const static usb_descriptor_t usb_descriptor = { g_apl_device, /* Pointer to the device descriptor */ g_apl_configuration, /* Pointer to the configuration descriptor for Full-speed */ USB_NULL, /* Pointer to the configuration descriptor for Hi-speed */ USB_NULL, /* Pointer to the qualifier descriptor */ g_apl_string_table /* Pointer to the string descriptor table */ }; /****************************************************************************** Renesas Peripheral Communications Devices Class Sample Code functions ******************************************************************************/ /****************************************************************************** Function Name : usb_main Description : Peripheral CDC application main process Arguments : none Return value : none ******************************************************************************/ void usb_main (void) { usb_ctrl_t ctrl; usb_cfg_t cfg; usb_pin_setting(); /* USB MCU pin setting */ ctrl.module = USE_USBIP; ctrl.type = USB_PCDC; cfg.usb_speed = USB_SUPPORT_SPEED; /* USB_HS/USB_FS */ cfg.usb_mode = USB_PERI; cfg.p_usb_reg = (usb_descriptor_t *)&usb_descriptor; R_USB_Open(&ctrl, &cfg); /* Initializes the USB module */ /* Loop back between PC(TerminalSoft) and USB MCU */ while (1) { switch (R_USB_GetEvent(&ctrl)) { case USB_STS_CONFIGURED : case USB_STS_WRITE_COMPLETE : ctrl.type = USB_PCDC; R_USB_Read(&ctrl, g_buf, DATA_LEN); break; case USB_STS_READ_COMPLETE : R_USB_Write(&ctrl, g_buf, ctrl.size); break; case USB_STS_SUSPEND : case USB_STS_DETACH : #if defined(USE_LPW) low_power_mcu(); #endif /* defined(USE_LPW) */ break; default : break; } } } /* End of function usb_main() */ /****************************************************************************** Function Name : usb_pin_setting Description : USB Pin Setting Arguments : none Return value : none ******************************************************************************/ /*---CUT---CUT---CUT---CUT---CUT---CUT---CUT---CUT---CUT---CUT---CUT---CUT---*/ #endif /* OPERATION_MODE == USB_ECHO */ /****************************************************************************** End Of File ******************************************************************************/
/********************************************************************************************************************** * 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) 2015 Renesas Electronics Corporation. All rights reserved. *********************************************************************************************************************/ /********************************************************************************************************************** * File Name : main.c * Description : main process *********************************************************************************************************************/ /********************************************************************************************************************** * History : DD.MM.YYYY Version Description * : 30.09.2015 2.20 First Release *********************************************************************************************************************/ /****************************************************************************** Includes <System Includes> , "Project Includes" ******************************************************************************/ /****************************************************************************** Exported global variables ******************************************************************************/ extern void usb_main(void); /****************************************************************************** Function Name : main Description : Main task Arguments : none Return value : none ******************************************************************************/ void main (void) { usb_main(); /* USB sample application */ } /****************************************************************************** End of function main() ******************************************************************************/ /****************************************************************************** End Of File ******************************************************************************/
/******************************************************************************* * 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) 2013 Renesas Electronics Corporation. All rights reserved. *******************************************************************************/ /******************************************************************************* * File Name : r_usb_pcdc_echo_apl.c * Version : 2.11 * Description : USB Peripheral Sample Code ******************************************************************************* * History : DD.MM.YYYY Version Description * : 30.11.2012 2.00 Basic FW mini Ver2.00(MP Version) * : 01.08.2013 2.10 Basic Mini FW Ver2.10 Release * : 30.08.2013 2.11 Basic Mini FW Ver2.11 Release * - GNU/e2studio & IAR EW Version release * - Use macro for g_usb_pipe_toggle declaration ******************************************************************************/ /****************************************************************************** Section <Section Difinition> , "Project Sections" ******************************************************************************/ #ifdef R8CUSB #pragma section program P_smpl #pragma section bss B_smpl #pragma section data R_smpl #pragma section rom C_smpl #endif #ifdef RX_USB #endif #ifdef RL78USB #endif #ifdef RL78USB_SECTION #pragma section @@CODE P_SMP #pragma section @@BASE T_SMP #pragma section @@CNST C_SMP #pragma section @@R_INIT D_SMP #pragma section @@DATA B_SMP #pragma section @@INIT R_SMP #endif /****************************************************************************** Includes <System Includes> , "Project Includes" ******************************************************************************/ #include "r_usb_ctypedef.h" /* Type define */ #include "r_usb_ckernelid.h" /* Kernel ID definition */ #include "r_usb_cdefusbip.h" /* USB-FW Library Header */ #include "r_usb_usrconfig.h" /* System definition, USB-FW Library Header */ #include "r_usb_api.h" /* USB API public function header */ #include "hw_resource.h" #include "r_usb_pcdc_driver.h" #include "r_usb_pcdc_define.h" #include "r_usb_pcdc_api.h" /****************************************************************************** Constant macro definitions ******************************************************************************/ /* CDC Host data receive size */ /* FS:64 HS:512 */ #define USB_PCDC_APL_RX_SIZE 64 /* Comm Port data receive size */ #define USB_PCDC_APL_SRX_SIZE 64 /****** Line Coding Define *******/ /* Line Coding bps */ #define USB_PCDC_SPEED_9600 ((uint32_t)9600) #define USB_PCDC_SPEED_19200 ((uint32_t)19200) /* Line Coding 8Data bits */ #define USB_PCDC_DATA_BIT_8 ((uint8_t)8) /* Line Coding 1Stop bits */ #define USB_PCDC_STOP_BIT_1 ((uint8_t)0) /* Line Coding None Parity */ #define USB_PCDC_PARITY_BIT_NONE ((uint8_t)0u) #define TASK_LOOPS_BETWEEN_INSTRUCTIONS 0x00050000 /***************************************************************************** Enumerated Types ******************************************************************************/ /* Peripheral CDC Sample application message command */ typedef enum { /* Data receive from Host cdc */ USB_PCDC_RX_COMP, /* Data send for Host cdc */ USB_PCDC_TX_COMP } USB_PCDC_APL_COMMAND; /* Peripheral CDC Sample application message command */ typedef enum { APP_STATE_IDLE, APP_STATE_RUNNING_INTRO, APP_STATE_INTRO_MSG0, APP_STATE_INTRO_MSG1, APP_STATE_INTRO_MSG2, APP_STATE_ECHO_MODE } USB_PCDC_APL_STATE; /****************************************************************************** External variables and functions ******************************************************************************/ extern uint16_t usb_gpcdc_EpTbl1[ 0x14u ]; extern uint8_t usb_gpcdc_DeviceDescriptor[ 0x12u ]; extern uint8_t usb_gpcdc_ConfigrationF1[ 0x09u + 0x09u + 0x05u + 0x04u + 0x05u + 0x05u + 0x07u + 0x09u + 0x07u + 0x07u ]; extern uint8_t *usb_gpcdc_StrPtr[ 0x07u ]; extern volatile uint16_t g_usb_pipe_toggle[USB_MAX_PIPE_NO + 1]; extern void usb_cpu_suspend_sleep( void ); extern void usb_cpu_detach_sleep(void); extern void usb_smpl_set_suspend_flag(uint8_t data); extern uint8_t usb_smpl_get_suspend_flag(void); #ifdef USB_LCD_ENABLE extern void usb_cpu_LcdDisp(uint8_t pos, uint8_t *str); #endif /* USB_LCD_ENABLE */ /****************************************************************************** Private global variables and functions ******************************************************************************/ uint8_t g_usb_psmpl_receive_data[USB_PCDC_APL_RX_SIZE + 4]; uint8_t g_usb_psmpl_send_data[USB_PCDC_APL_RX_SIZE + 4]; static USB_PCDC_APL_STATE app_state; void usb_cstd_task_start( void ); void usb_pcdc_task_start( void ); void usb_apl_task_switch( void ); void usb_psmpl_driver_registration( void ); usb_er_t usb_psmpl_change_device_state( uint16_t data, uint16_t state ); void usb_psmpl_open( uint16_t data1, uint16_t data2 ); void usb_psmpl_close( uint16_t data1, uint16_t data2 ); uint16_t usb_psmpl_GetRcvDataCnt( usb_utr_t *mess ); void usb_psmpl_MainTask( void ); void usb_psmpl_ReceiveDataStart( void ); void usb_psmpl_RxCB( usb_utr_t *mess ); void usb_psmpl_TxCB( usb_utr_t *mess ); void usb_psmpl_LineCodingInitial( void ); void usb_psmpl_DummyFunc( usb_utr_t * ); /****************************************************************************** Renesas Peripheral Communications Devices Class Sample Code functions ******************************************************************************/ /****************************************************************************** Function Name : usb_cstd_task_start Description : Start task CSTD; "common" basic USB low level task. Arguments : void Return value : void ******************************************************************************/ void usb_cstd_task_start( void ) { usb_pcdc_task_start(); /* Start Peripheral USB driver */ usb_apl_task_switch(); /* Switch task for nonOS */ } /* eof usb_cstd_task_start() */ /****************************************************************************** Function Name : usb_phid_task_start Description : Set peripheral application task start conditions. Arguments : void Return value : void ******************************************************************************/ void usb_pcdc_task_start( void ) { #ifdef USB_LCD_ENABLE /* Display Debug LCD */ usb_cpu_LcdDisp( LCD_POS_U0, (uint8_t *)"USB CDC "); usb_cpu_LcdDisp( LCD_POS_D0, (uint8_t *)"Appstart"); #endif /* USB_LCD_ENABLE */ usb_psmpl_LineCodingInitial(); usb_psmpl_driver_registration(); /* Peripheral Application Registration */ R_usb_pstd_PcdChangeDeviceState( USB_DO_SETHWFUNCTION ); } /* eof usb_pcdc_task_start() */ /****************************************************************************** Function Name : usb_apl_task_switch Description : Task switch loop for nonOS version. Argument : void Return : void ******************************************************************************/ void usb_apl_task_switch( void ) { uint32_t i = 0; while( 1 ) { /* This if-statement is run only if user has not yet entered any characters into the virtual serial COM port. * is Added to send instructions for demo. */ if (app_state != APP_STATE_ECHO_MODE) { if (i++ == TASK_LOOPS_BETWEEN_INSTRUCTIONS) { i = 0; app_state = APP_STATE_INTRO_MSG0; R_usb_pcdc_SendData((uint8_t *)"PCDC. ", 6, (usb_cbinfo_t)usb_psmpl_TxCB); } } /* Task schedule request check. */ if( USB_FLGSET == R_usb_cstd_Scheduler() ) { R_usb_pstd_PcdTask(); /* PCD Task */ R_usb_pcdc_Task(); /* Peripheral PCDC Task */ usb_psmpl_MainTask(); /* Peripheral PCDC demo sample application Task */ } if ( usb_smpl_get_suspend_flag() == USB_YES ) { usb_cpu_suspend_sleep(); } } } /* eof usb_apl_task_switch */ /****************************************************************************** Function Name : usb_psmpl_driver_registration Description : Peripheral Sample Driver Registration Argument : void Return : void ******************************************************************************/ void usb_psmpl_driver_registration( void ) { usb_pcdreg_t driver; /* Pipe Define Table address */ driver.pipetbl = &usb_gpcdc_EpTbl1[0]; /* Device descriptor Table address */ driver.devicetbl = (uint8_t*)&usb_gpcdc_DeviceDescriptor[0]; /* Configuration descriptor Table address */ driver.configtbl = &usb_gpcdc_ConfigrationF1[0]; /* String descriptor Table address */ driver.stringtbl = (uint8_t**)&usb_gpcdc_StrPtr[0]; /* Device statediagram */ driver.statediagram = (usb_cbinfo_t)&usb_psmpl_change_device_state; /* Control Transfer */ driver.ctrltrans = &R_usb_pcdc_ClassRequest; R_usb_pcdc_Registration( &driver ); usb_gpcdc_AplCB = (usb_cb_t)usb_psmpl_DummyFunc; } /* eof usb_psmpl_driver_registration */ /****************************************************************************** Function Name : usb_apl_change_device_state Description : Device State CallBack Check Arguments : uint16_t state Return value : uint16_t data ******************************************************************************/ usb_er_t usb_psmpl_change_device_state( uint16_t data, uint16_t state ) { switch( state ) { case USB_STS_DETACH: usb_psmpl_close( data, state ); usb_smpl_set_suspend_flag(USB_NO); #ifdef USB_STOP_MODE_ENABLE #ifdef __RX usb_cpu_detach_sleep(); #endif /* __RX */ #endif /* USB_STOP_MODE_ENABLE */ break; case USB_STS_DEFAULT: usb_smpl_set_suspend_flag(USB_NO); break; case USB_STS_ADDRESS: break; case USB_STS_CONFIGURED: usb_psmpl_open( data, state ); usb_smpl_set_suspend_flag(USB_NO); break; case USB_STS_SUSPEND: usb_smpl_set_suspend_flag(USB_YES); break; case USB_STS_RESUME: usb_smpl_set_suspend_flag(USB_NO); break; default: break; } return ( USB_E_OK ); } /* eof usb_psmpl_driver_registration */ /****************************************************************************** Function Name : usb_psmpl_open Description : Sample Open Argument : uint16_t data1 : Not Use : uint16_t data2 : Not Use Return : void ******************************************************************************/ void usb_psmpl_open( uint16_t data1, uint16_t data2 ) { uint8_t index; for ( index = 0; index < (USB_MAX_PIPE_NO + 1); index++ ) { g_usb_pipe_toggle[index] = USB_NULL; } usb_psmpl_ReceiveDataStart(); } /* eof usb_psmpl_open */ /****************************************************************************** Function Name : usb_psmpl_close Description : Sample Close Argument : uint16_t data1 : Not Use : uint16_t data2 : Not Use Return : void ******************************************************************************/ void usb_psmpl_close( uint16_t data1, uint16_t data2 ) { R_usb_pstd_TransferEnd( USB_PIPE1, USB_DATA_STOP ); R_usb_pstd_TransferEnd( USB_PIPE2, USB_DATA_STOP ); R_usb_pstd_TransferEnd( USB_PIPE8, USB_DATA_STOP ); } /* eof usb_psmpl_close */ /****************************************************************************** Function Name : usb_psmpl_GetRcvDataCnt Description : Get USB Receive Data count Arguments : usb_utr_t Return value : USB receive data count ******************************************************************************/ uint16_t usb_psmpl_GetRcvDataCnt( usb_utr_t *mess ) { /* Receive Data Count for USB Host */ uint16_t rcv_cnt; /*----------------------------------*/ /* Data receive from Host cdc */ /*----------------------------------*/ if(mess->status == USB_DATA_OK) { /* Receive size = Request size */ rcv_cnt = USB_PCDC_APL_RX_SIZE; } else if(mess->status == USB_DATA_SHT) { /* Receive size < Request size */ rcv_cnt = USB_PCDC_APL_RX_SIZE - mess->tranlen; } else { rcv_cnt = 0; } return rcv_cnt; } /* eof usb_psmpl_GetRcvDataCnt */ /****************************************************************************** Function Name : usb_psmpl_MainTask Description : Main Task Argument : void Return : void ******************************************************************************/ void usb_psmpl_MainTask( void ) { usb_utr_t *mess; usb_er_t err = 0l; /* Receive Data Count for USB Host */ uint16_t rcv_cnt; usb_leng_t snd_cnt; uint16_t index; err = R_USB_RCV_MSG( USB_PSMP_MBX, (usb_msg_t**)&mess ); if( err != USB_E_OK ) { return; } switch ( mess->msginfo ) { case USB_PCDC_RX_COMP: /*----------------------------------*/ /* Data receive from Host cdc */ /*----------------------------------*/ /* ==== If USB can receive new data ==== */ /* Check the number of data which USB should receive. */ rcv_cnt = usb_psmpl_GetRcvDataCnt(mess); /* For first received character, stop the introduction text going to virtual COM port. */ if (app_state != APP_STATE_ECHO_MODE) { app_state = APP_STATE_ECHO_MODE; /* Send e.g. Vertical Tab (0x0C), Bell (0x07), New Line. */ R_usb_pcdc_SendData((uint8_t *)"Echo mode.\x0B\x07\n\r", 14, (usb_cbinfo_t)&usb_psmpl_TxCB); } /* In echo mode. Use R_usb_pcdc_SendData to return the received data. */ else if (rcv_cnt != 0) { for ( index = 0; index < rcv_cnt; index++ ) { g_usb_psmpl_send_data[ index ] = g_usb_psmpl_receive_data[ index ]; } snd_cnt = rcv_cnt; /* Send the data back to user over USB. The Tx callback will trigger to notify that data is transmitted. */ R_usb_pcdc_SendData( &g_usb_psmpl_send_data[0], snd_cnt, (usb_cbinfo_t)&usb_psmpl_TxCB ); } else { usb_psmpl_ReceiveDataStart(); } break; case USB_PCDC_TX_COMP: /* Tell app process to send next user intro message. */ if (app_state == APP_STATE_INTRO_MSG0) { R_usb_pcdc_SendData((uint8_t *)"Virtual serial COM port. Type characters into terminal.\n\r", 58, (usb_cbinfo_t)&usb_psmpl_TxCB ); app_state = APP_STATE_INTRO_MSG1; } else if (app_state == APP_STATE_INTRO_MSG1) { R_usb_pcdc_SendData((uint8_t *)"The target will receive the characters over USB CDC, then copy them to a USB transmit buffer to be echoed back over USB.\n\n\r", 123, (usb_cbinfo_t)&usb_psmpl_TxCB ); app_state = APP_STATE_INTRO_MSG2; } else if (app_state != APP_STATE_INTRO_MSG2) /* Not in intro message mode. All transmitted data should trigger this 'else'. */ { ; } /*----------------------------------*/ /* Data send to Host cdc */ /*----------------------------------*/ usb_psmpl_ReceiveDataStart(); break; default: /*----------------------------------*/ /* Undefine message */ /*----------------------------------*/ break; } } /* eof usb_psmpl_MainTask */ /****************************************************************************** Function Name : usb_psmpl_ReceiveDataStart Description : Start Data Receive request for Host Arguments : void Return value : void ******************************************************************************/ void usb_psmpl_ReceiveDataStart( void ) { R_usb_pcdc_ReceiveData( (uint8_t *)&g_usb_psmpl_receive_data[0], (uint32_t)USB_PCDC_APL_RX_SIZE, (usb_cbinfo_t)&usb_psmpl_RxCB); } /* eof usb_psmpl_ReceiveDataStart */ /****************************************************************************** Function Name : usb_psmpl_RxCB Description : CDC Host Rx complete Callback Argument : usb_utr_t *mess : message Return : void ******************************************************************************/ void usb_psmpl_RxCB( usb_utr_t *mess ) { usb_er_t err; mess->msginfo = USB_PCDC_RX_COMP; /* Send message */ err = R_USB_SND_MSG(USB_PSMP_MBX, (usb_msg_t*)mess); if( err != USB_E_OK ) { /* Send Message failure */ USB_DEBUG_HOOK(USB_DEBUG_HOOK_APL | USB_DEBUG_HOOK_CODE1); } } /* eof usb_psmpl_RxCB */ /****************************************************************************** Function Name : usb_psmpl_TxCB Description : CDC Host Tx complete Callback Argument : usb_utr_t *mess : message Return : void ******************************************************************************/ void usb_psmpl_TxCB( usb_utr_t *mess ) { usb_er_t err; mess->msginfo = USB_PCDC_TX_COMP; /* Send message */ err = R_USB_SND_MSG(USB_PSMP_MBX, (usb_msg_t*)mess); if( err != USB_E_OK ) { /* Send Message failure */ USB_DEBUG_HOOK(USB_DEBUG_HOOK_APL | USB_DEBUG_HOOK_CODE2); } } /* eof usb_psmpl_TxCB */ /****************************************************************************** Function Name : usb_psmpl_LineCodingInitial Description : Line coding initial Arguments : void Return value : void ******************************************************************************/ void usb_psmpl_LineCodingInitial( void ) { usb_pcdc_LineCoding_t linecoding; linecoding.dwDTERate = USB_PCDC_SPEED_19200; linecoding.bCharFormat = USB_PCDC_STOP_BIT_1; linecoding.bParityType = USB_PCDC_PARITY_BIT_NONE; linecoding.bDataBits = USB_PCDC_DATA_BIT_8; linecoding.rsv = (uint8_t)0; R_usb_pcdc_LineCodingInitial( &linecoding ); } /* eof usb_psmpl_LineCodingInitial */ /****************************************************************************** Function Name : usb_psmpl_DummyFunc Description : Arguments : void Return value : void ******************************************************************************/ void usb_psmpl_DummyFunc( usb_utr_t *mess ) { } /* usb_psmpl_DummyFunc */ /****************************************************************************** End Of File ******************************************************************************/
/******************************************************************************* * 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) 2013 Renesas Electronics Corporation. All rights reserved. *******************************************************************************/ /******************************************************************************* * File Name : main.c * Version : 2.10 * Description : USB Host vendor class driver function code. *******************************************************************************/ /******************************************************************************* * History : DD.MM.YYYY Version Description * : 31.03.2012 1.80 Basic FW mini Ver2.00(ES Version) * : 30.11.2012 2.00 Basic FW mini Ver2.00(MP Version) * : 01.08.2013 2.10 Basic Mini FW Ver2.10 Release *******************************************************************************/ /****************************************************************************** Section definitions ******************************************************************************/ //#pragma SFR #ifdef R8CUSB #pragma section program P_smpl #pragma section bss B_smpl #pragma section data R_smpl #pragma section rom C_smpl #endif #ifdef RX_USB //#pragma section _smpl #endif #ifdef RL78USB #endif #ifdef RL78USB_SECTION #pragma section @@CODE P_SMP #pragma section @@BASE T_SMP #pragma section @@CNST C_SMP #pragma section @@R_INIT D_SMP #pragma section @@DATA B_SMP #pragma section @@INIT R_SMP #endif /****************************************************************************** Includes <System Includes> , "Project Includes" ******************************************************************************/ #include "r_usb_ctypedef.h" /* Type define */ #include "r_usb_ckernelid.h" /* Kernel ID definition */ #include "r_usb_usrconfig.h" /* System definition */ #include "r_usb_cdefusbip.h" /* USB-FW Library Header */ #include "r_usb_usrconfig.h" /* System definition, USB-FW Library Header */ #include "r_usb_api.h" /* USB API public function header */ #include "hw_resource.h" #include "r_usb_pcdc_driver.h" #include "r_usb_pcdc_define.h" #include "r_usb_pcdc_api.h" /****************************************************************************** Macro definitions ******************************************************************************/ /* There is no macro definition. */ /****************************************************************************** Typedef definitions ******************************************************************************/ /* There is no typedef definition. */ /****************************************************************************** Private global variables and functions ******************************************************************************/ /* variables */ /****************************************************************************** Exported global variables and functions (to be accessed by other files) ******************************************************************************/ /* variables */ USB_STATIC volatile uint8_t g_usb_suspend_flag; USB_STATIC volatile uint8_t g_usb_int_key_flag; /* functions */ void main(void); void usb_smpl_set_suspend_flag(uint8_t data); uint8_t usb_smpl_get_suspend_flag(void); void usb_smpl_set_intkey(uint8_t data); uint8_t usb_smpl_get_intkey(void); /****************************************************************************** Imported global variables and functions (from other files) ******************************************************************************/ /* variables */ /* functions */ extern void usb_cpu_target_init(void); extern void usb_cstd_task_start(void); /****************************************************************************** Renesas PCDC Sample ******************************************************************************/ /****************************************************************************** Function Name: main Description: Main Task Arguments : none Return value : none ******************************************************************************/ void main(void) { usb_cpu_target_init(); usb_smpl_set_suspend_flag( USB_NO ); R_usb_pstd_PcdChangeDeviceState( USB_DO_INITHWFUNCTION ); R_usb_pstd_PcdOpen(); usb_cstd_task_start(); } /* eof main() */ /****************************************************************************** Function Name : usb_smpl_set_suspend_flag Description : Set resume interruptt flag Arguments : uint8_t data Return value : none ******************************************************************************/ void usb_smpl_set_suspend_flag(uint8_t data) { g_usb_suspend_flag = data; } /* eof usb_smpl_set_suspend_flag() */ /****************************************************************************** Function Name : usb_smpl_get_suspend_flag Description : Get resume interruptt flag Arguments : none Return value : g_usb_suspend_flag ******************************************************************************/ uint8_t usb_smpl_get_suspend_flag(void) { return g_usb_suspend_flag; } /* eof usb_smpl_get_suspend_flag() */ /****************************************************************************** Function Name : usb_smpl_set_intkey Description : Set external key interruptt flag Arguments : uint8_t data Return value : none ******************************************************************************/ void usb_smpl_set_intkey(uint8_t data) { g_usb_int_key_flag = data; } /* eof usb_smpl_set_intkey() */ /****************************************************************************** Function Name : usb_smpl_get_intkey Description : Get external key interruptt flag Arguments : none Return value : g_usb_int_key_flag ******************************************************************************/ uint8_t usb_smpl_get_intkey(void) { return g_usb_int_key_flag; } /* eof usb_smpl_get_intkey() */ /****************************************************************************** End Of File ******************************************************************************/
/****************************************************************************** * 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) 2010(2011) Renesas Electronics Corpration * and Renesas Solutions Corp. All rights reserved. ******************************************************************************* * File Name : r_usb_PCDC_apl.c * Version : 1.10 * Device(s) : Renesas SH-Series, RX-Series * Tool-Chain : Renesas SuperH RISC engine Standard Toolchain * : Renesas RX Standard Toolchain * OS : Common to None and uITRON 4.0 Spec * H/W Platform : Independent * Description : USB Peripheral Communications Devices Class Sample Code ******************************************************************************* * History : DD.MM.YYYY Version Description * : 06.08.2010 0.91 First Release * : 31.08.2010 0.92 PCDC Updated * : 30.09.2010 0.93 PCDC Updated * : 02.12.2010 0.96 Message Output Timming adjustment * : 02.12.2010 0.96 Spelling modification * : 01.06.2011 1.10 Version 1.10 Release ******************************************************************************/ /****************************************************************************** Includes <System Includes> , "Project Includes" ******************************************************************************/ #include <string.h> #include "r_usb_cTypedef.h" /* Type define */ #include "r_usb_usrconfig.h" #include "r_usb_cDefUSBIP.h" /* USB-FW Library Header */ #include "r_usb_cMacPrint.h" /* Standard IO macro */ #include "r_usb_cKernelId.h" /* Kernel ID definition */ #include "r_usb_cMacSystemcall.h" /* uITRON system call macro */ #include "r_usb_cExtern.h" /* USB-FW global define */ #include "r_usb_ansi.h" #include "r_usb_control.h" #include "r_usb_cusb_bitdefine.h" #include "r_usb_api.h" #include "r_usb_pcdc_define.h" #include "r_usb_pcdc_extern.h" #include "r_usb_pcdc_api.h" #include "hw_resource.h" /****************************************************************************** Constant macro definitions ******************************************************************************/ #define USB_PCDC_SW1_ON 1 #define USB_PCDC_SW2_ON 2 #define USB_PCDC_SW3_ON 4 #define USB_PCDC_MSG_TIMING 41317 #define USB_PCDC_APL_INST_SEQ_START 3 #define USB_PCDC_APL_INST_SEQ_END 8 /* CDC Host data receive size */ /* FS:64 HS:512 */ /* Condition compilation by the difference of user define */ #if USB_SPEEDSEL_PP == USB_HS_PP #define USB_PCDC_APL_RX_SIZE 512 #else /* USB_SPEEDSEL_PP == USB_HS_PP */ #define USB_PCDC_APL_RX_SIZE 64 #endif /* USB_SPEEDSEL_PP == USB_HS_PP */ /* Comm Port data receive size */ #define USB_PCDC_APL_SRX_SIZE 64 /* setup packet table size (uint16_t * 5) */ #define USB_CDC_SETUP_TBL_BSIZE 10 /***************************************************************************** Enumerated Types ******************************************************************************/ /* Peripheral CDC Sample application message command */ typedef enum { USB_PCDC_OPEN, /* Periodic processing */ USB_PCDC_PERIODIC_PROCESS, /* Data receive from Host cdc */ USB_PCDC_RX_COMP, /* Data send for Host cdc */ USB_PCDC_TX_COMP, /* Notification */ USB_PCDC_STATUS_TX_COMP, USB_PCDC_CLOSE } USB_PCDC_APL_COMMAND; /****************************************************************************** External variables and functions ******************************************************************************/ /* Serial Port driver functions */ extern void usb_cpu_Sci_DataSend(uint16_t mode, void *tranadr, uint16_t length); extern uint16_t usb_cpu_Sci_DataReceive(uint8_t *tranadr, uint16_t receive_length); extern uint16_t usb_cpu_Sci_StxBuffStatus(void); extern void usb_cpu_Sci_Buffer_init(void); extern uint16_t usb_cpu_Sci_CopyData_for_Echo(void); extern uint16_t usb_cpu_Sci_GetSerialState(uint16_t *serial_state); #ifdef USB_UART_ENABLE extern void usb_cpu_Sci_HW_init(void); extern void usb_cpu_Sci_enable(void); extern void usb_cpu_Sci_disable(void); #endif /* USB_UART_ENABLE */ /* SW input driver functions */ #ifdef USB_KEY_ENABLE extern uint16_t usb_cpu_GetKeyNo(void); #endif /* USB_KEY_ENABLE */ #ifdef USB_LCD_ENABLE extern void usb_cpu_LcdDisp(uint8_t position, uint8_t *string); #endif /* USB_LCD_ENABLE */ /****************************************************************************** Section <Section Definition> , "Data Sections" ******************************************************************************/ /* Condition compilation by the difference of hardware reference */ #ifdef USB_SDRAM_USE_PP #pragma section _sdram #else /* USB_SDRAM_USE_PP */ #pragma section _apl #endif /* USB_SDRAM_USE_PP */ /****************************************************************************** Private global variables and functions ******************************************************************************/ /* Abstract Control Model Notification - SerialState */ uint8_t usb_gpcdc_SerialState_Table[USB_CDC_SETUP_TBL_BSIZE] = { 0xA1, /* bmRequestType */ 0x20, /* bNotification:SERIAL_STATE */ 0x00,0x00, /* wValue:Zero */ 0x00,0x00, /* wIndex:Interface */ 0x02,0x00, /* wLength:2 */ 0x00,0x00 }; /* Data:UART State bitmap */ /* Peri CDC application enable */ uint16_t usb_gcdc_connected; void usb_pcdc_main_task(USB_VP_INT_t); uint16_t usb_pcdc_is_connected(void); void usb_pcdc_pr_apl_title(void); /****************************************************************************** Static variables and functions ******************************************************************************/ #if USB_ANSIIO_PP == USB_ANSIIO_USE_PP /*---CUT---CUT---CUT---CUT---CUT---CUT---CUT---CUT---CUT---CUT---CUT---CUT---*/ #else /* USB_ANSIIO_PP == USB_ANSIIO_USE_PP */ static uint16_t usb_pcdc_get_rcv_data_cnt(USB_UTR_t *mess); #endif /* USB_ANSIIO_PP == USB_ANSIIO_USE_PP */ static void usb_pcdc_rx_notification(USB_UTR_t *mess); static void usb_pcdc_tx_notification(USB_UTR_t *mess); static void usb_pcdc_state_notification(USB_UTR_t *mess); static void usb_pcdc_apl_msg_out(USB_UTR_t *ptr, uint16_t message_no); static void usb_pcdc_apl_init(USB_UTR_t *ptr); static void usb_pcdc_smpl_message_send( USB_UTR_t *ptr, uint16_t msginfo); static void usb_apl_task_switch(void); static void usb_pcdc_task_start( void ); static void usb_papl_task_start( USB_UTR_t *ptr ); static void usb_pcdc_registration(USB_UTR_t *ptr); /*Main menu text*/ //static const uint8_t szWelcomeMsg[9][64] = uint8_t szWelcomeMsg[9][64] = { { "\r\nRenesas USB CDC Sample, Press Switch SW2\r\n" }, { "\r\nStarting Echo:-\r\n" }, { "\r\nFinished Echo.\r\n" }, { "\r\n[Renesas Serial-USB converter.]\r\n\r\n " }, { "Connect serial terminal (e.g. PC COM1) DB9 cable to PC and RSK," }, { "\r\n and USB cable to PC and to mini-B on RSK.\r\n " }, { " Support COM Speed 1200bps-115200bps\r\n" }, { "\r\nSw2 - Show instructions\r\n" }, { "\r\nSw3 - Start Echo of everthing typed <-> Stop Echo\r\n" }, }; /* USB TX Data */ static uint8_t usb_gpcdc_send_data[USB_PCDC_APL_SRX_SIZE + 4]; /* USB RX Data */ static uint8_t usb_gpcdc_receive_data[USB_PCDC_APL_RX_SIZE + 4]; /* Instructions output line sequence */ static uint16_t usb_gpcdc_explain_seq; /* HOST Send wait flag */ static uint16_t usb_gpcdc_tx_wait_flag; /* Notification Serial State sending flag */ static uint16_t usb_gpcdc_serial_state_tx; /* Notification Serial State sending status */ static uint16_t usb_gpcdc_serial_state; /* echo mode flag */ static uint16_t usb_gpcdc_echo_mode; static uint16_t usb_gpcdc_sw2push; /* Switch1 Push Request Message Output Timing Counter */ static uint32_t usb_gpcdc_msg_timing_cnt; /* Receive flow control flag */ static uint16_t usb_gpcdc_stx_wait; /* CDC Peripheral Active flag */ static uint16_t usb_gpcdc_active; /****************************************************************************** Section <Section Difinition> , "Project Sections" ******************************************************************************/ #pragma section _apl /****************************************************************************** Renesas Peripheral Communications Devices Class Sample Code functions ******************************************************************************/ /****************************************************************************** Function Name : usb_papl_task_start Description : Set peripheral application task start conditions. Arguments : none Return value : none ******************************************************************************/ void usb_papl_task_start( USB_UTR_t *ptr ) { /* PCDC demo sample application task priority set */ R_usb_cstd_SetTaskPri(USB_PCDCSMP_TSK, USB_PRI_6); #ifdef USB_UART_ENABLE /* ComPort Hw Initialize */ usb_cpu_Sci_HW_init(); #endif /* USB_UART_ENABLE */ /* Application data Initialize and Periodic process request */ usb_pcdc_apl_init(ptr); } /****************************************************************************** End of function usb_papl_task_start() ******************************************************************************/ /****************************************************************************** Function Name : usb_cstd_task_start Description : Start task CSTD; "common" basic USB low level task. Arguments : USB_UTR_t *ptr : USB system internal structure. Return value : none ******************************************************************************/ void usb_cstd_task_start( void ) { usb_cstd_IdleTaskStart(); /* Idle Task Start */ usb_pcdc_task_start(); /* Start Peripheral USB driver */ usb_apl_task_switch(); /* Switch task for nonOS */ } /****************************************************************************** End of function usb_cstd_task_start() ******************************************************************************/ /****************************************************************************** Function Name : usb_pstd_task_start Description : Set peripheral application task start conditions. Arguments : none Return value : none ******************************************************************************/ void usb_pcdc_task_start( void ) { USB_UTR_t utr; USB_UTR_t *ptr; #ifdef USB_LCD_ENABLE /* Display Debug LCD */ usb_cpu_LcdDisp( LCD_POS_U0, "USB CDC "); usb_cpu_LcdDisp( LCD_POS_D0, "Appstart"); #endif /* USB_LCD_ENABLE */ ptr = &utr; /* Set USB IP no. and USB IP base address store pointer */ ptr->ip = USB_PERI_USBIP_NUM; /* IP number(0or1) */ if( USB_NOUSE_PP != ptr->ip ) /* USB IP number check */ { ptr->ipp = R_usb_cstd_GetUsbIpAdr( ptr->ip ); /* IP Address(USB0orUSB1) */ usb_pcdc_registration( ptr ); /* Peripheral Application Registration */ usb_papl_task_start( ptr ); /* Peripheral Application Task Start Setting */ R_usb_pcdc_driver_start(); /* Peripheral Class Driver Task Start Setting */ R_usb_pstd_usbdriver_start( ptr ); /* Peripheral USB Driver Start Setting */ /* Initialize USB IP */ R_usb_cstd_UsbIpInit( ptr, USB_PERI_PP ); } } /****************************************************************************** End of function usb_pstd_task_start() ******************************************************************************/ /****************************************************************************** Function Name : usb_pcdc_registration Description : Registration of peripheral Communications Devices Driver Arguments : USB_UTR_t *ptr : USB system internal structure. Return value : none ******************************************************************************/ void usb_pcdc_registration(USB_UTR_t *ptr) { USB_PCDREG_t driver; /* Driver registration */ /* Pipe Define Table address */ driver.pipetbl = &usb_gpcdc_EpPtr[0]; /* Device descriptor Table address */ driver.devicetbl = (uint8_t*)&usb_gpcdc_DeviceDescriptor; /* Qualifier descriptor Table address */ driver.qualitbl = (uint8_t*)&usb_gpcdc_QualifierDescriptor; /* Configuration descriptor Table address */ driver.configtbl = (uint8_t**)&usb_gpcdc_ConPtr; /* Other configuration descriptor Table address */ driver.othertbl = (uint8_t**)&usb_gpcdc_ConPtrOther; /* String descriptor Table address */ driver.stringtbl = (uint8_t**)&usb_gpcdc_StrPtr; /* Driver init */ driver.classinit = &usb_cstd_DummyFunction; /* Device default */ driver.devdefault = &R_usb_pcdc_descriptor_change; /* Device configuered */ driver.devconfig = (USB_CB_INFO_t)&usb_pcdc_open; /* Device detach */ driver.devdetach = (USB_CB_INFO_t)&usb_pcdc_close; /* Device suspend */ driver.devsuspend = &usb_cstd_DummyFunction; /* Device resume */ driver.devresume = &usb_cstd_DummyFunction; /* Interfaced change */ driver.interface = &R_usb_pcdc_set_interface; /* Control Transfer */ driver.ctrltrans = (USB_CB_TRN_t)&R_usb_pcdc_usr_ctrl_trans_function; /* PCDC class driver registration */ R_usb_pstd_DriverRegistration(ptr, &driver); } /* eof usb_pcdc_registration() */ /****************************************************************************** Function Name : usb_apl_task_switch Description : Task switch loop for nonOS version. Argument : none Return : none ******************************************************************************/ void usb_apl_task_switch(void) { while( 1 ) { /* Scheduler */ R_usb_cstd_Scheduler(); /* Task schedule request check. */ if( USB_FLGSET == R_usb_cstd_CheckSchedule() ) { #ifdef USB_PERI_MODE_PP R_usb_pstd_PcdTask((USB_VP_INT)0); /* PCD Task */ /* Peripheral Communications Devices Class Task */ R_usb_pcdc_task(0); /* Peripheral Communications Class Application Task */ usb_pcdc_main_task(0); #endif /* USB_PERI_MODE_PP */ /* Idle Task (sleep sample) */ R_usb_cstd_IdleTask(0); } } } /* eof usb_apl_task_switch() */ /****************************************************************************** Function Name : usb_pcdc_pr_apl_title Description : Output Title Argument : none Return : none ******************************************************************************/ void usb_pcdc_pr_apl_title(void) { #ifdef USB_LCD_ENABLE usb_cpu_TargetLcdClear(); #endif /* USB_LCD_ENABLE */ USB_PRINTF0("\n"); USB_PRINTF0("+++++++++++++++++++++++++++++++++++++\n"); USB_PRINTF0("+ PERI CDC FW SAMPLE +\n"); USB_PRINTF0("+ +\n"); USB_PRINTF0("+ RENESAS ELECTRONICS CORP. +\n"); USB_PRINTF0("+ RENESAS SOLUTIONS CORP. +\n"); USB_PRINTF0("+++++++++++++++++++++++++++++++++++++\n"); USB_PRINTF1(" DATE [%s] \n", __DATE__); USB_PRINTF1(" TIME [%s] \n", __TIME__); } /* eof usb_pcdc_pr_apl_title() */ /****************************************************************************** Function Name : usb_pcdc_sw_process Description : Switch Push Management process : - After connect,SW2 push Message output. Message stop by RSK SW2 push. : - SW2 : Transfer operate description Message : - SW3 : Echo mode On/Off change : ( When Echo mode Off, to USB serial converter) Arguments : USB_UTR_t *ptr : USB system internal structure. Return value : none ******************************************************************************/ void usb_pcdc_sw_process(USB_UTR_t *ptr) { uint16_t key_data; /* SW1-3 Polling */ /*----------------------------------*/ /* Initial message SW2Input request */ /*----------------------------------*/ /* Send Complete wait flag check */ if((usb_gpcdc_tx_wait_flag == USB_OFF) && (usb_gpcdc_sw2push == USB_OFF)) { /* Message output timming check */ usb_gpcdc_msg_timing_cnt++; if(usb_gpcdc_msg_timing_cnt >= USB_PCDC_MSG_TIMING) { usb_gpcdc_msg_timing_cnt = 0; /* Show instructions Start */ usb_pcdc_apl_msg_out(ptr, 0); } } /*----------------------------------*/ /* SW Polling process */ /*----------------------------------*/ /* Send Complete wait flag check */ if(usb_gpcdc_tx_wait_flag == USB_OFF) { /* Switch Input */ #ifdef USB_KEY_ENABLE key_data = usb_cpu_GetKeyNo(); #else /* USB_KEY_ENABLE */ key_data = USB_OFF; #endif /* USB_KEY_ENABLE */ switch(key_data) { case USB_PCDC_SW1_ON: break; case USB_PCDC_SW2_ON: /* SW2 ON */ usb_gpcdc_sw2push = USB_ON; /* Set Operate description Message start no. */ usb_gpcdc_explain_seq = USB_PCDC_APL_INST_SEQ_START; /* Show instructions Start */ usb_pcdc_apl_msg_out(ptr, usb_gpcdc_explain_seq); break; case USB_PCDC_SW3_ON: /* Change Echo mode /USB serial conversion mode */ if( usb_gpcdc_echo_mode == USB_OFF ) { /* Show instructions Start */ usb_pcdc_apl_msg_out(ptr, 1); /* Start Echo */ usb_gpcdc_echo_mode = USB_ON; #ifdef USB_UART_ENABLE /* Serial port disable */ usb_cpu_Sci_disable(); #endif /* USB_UART_ENABLE */ } else { /* Peri CDC Application Tx Rx data clear */ usb_cpu_Sci_Buffer_init(); /* Show instructions Start */ usb_pcdc_apl_msg_out(ptr, 2); /* Stop Echo */ usb_gpcdc_echo_mode = USB_OFF; #ifdef USB_UART_ENABLE /* Serial port enable */ usb_cpu_Sci_enable(); #endif /* USB_UART_ENABLE */ } break; default: /* No switch push */ /* Show instructions Continue */ if(( usb_gpcdc_explain_seq >= USB_PCDC_APL_INST_SEQ_START ) && (usb_gpcdc_explain_seq < USB_PCDC_APL_INST_SEQ_END)) { /* Next operate description Message no. update */ usb_gpcdc_explain_seq++; /* Show instructions Start */ usb_pcdc_apl_msg_out(ptr, usb_gpcdc_explain_seq); } break; } } } /* eof usb_pcdc_sw_process() */ /****************************************************************************** Function Name : usb_pcdc_serial_state_process Description : Serial error process : Transfer Class Notification SerialState when UART(SCI) error detection : ( Parity error / Framing error / Over run error ) Arguments : USB_UTR_t *ptr : USB system internal structure. Return value : none ******************************************************************************/ void usb_pcdc_serial_state_process(USB_UTR_t *ptr) { /* SerialState(CDC PSTN Subclass UART State bitmap) */ uint16_t serial_stat; /* Serial error detect */ uint16_t serial_error; #if USB_ANSIIO_PP == USB_ANSIIO_USE_PP /*---CUT---CUT---CUT---CUT---CUT---CUT---CUT---CUT---CUT---CUT---CUT---CUT---*/ #endif /* USB_ANSIIO_PP == USB_ANSIIO_USE_PP */ /*----------------------------------*/ /* Communications Port Error check */ /*----------------------------------*/ /* Serial State Notification send flag check */ if(usb_gpcdc_serial_state_tx == USB_OFF) { /* Serial error status read */ serial_error = usb_cpu_Sci_GetSerialState(&serial_stat); if(serial_error) { /* SerialState notification when different error type to last notification error type */ if(serial_stat != usb_gpcdc_serial_state) { /* Notifications Serial State */ #if USB_ANSIIO_PP == USB_ANSIIO_USE_PP /*---CUT---CUT---CUT---CUT---CUT---CUT---CUT---CUT---CUT---CUT---CUT---CUT---*/ #else /* USB_ANSIIO_PP == USB_ANSIIO_USE_PP */ /* Transfer Class Notification SerialState */ R_usb_pcdc_SerialStateNotification(ptr, serial_stat, (USB_CB_t)&usb_pcdc_state_notification); #endif /* USB_ANSIIO_PP == USB_ANSIIO_USE_PP */ /* Serial State Notification send flag set */ usb_gpcdc_serial_state_tx = USB_ON; /* Serial Erros State Store */ usb_gpcdc_serial_state = serial_stat; } } else { /* Serial Erros State Clear */ usb_gpcdc_serial_state = 0; } } } /* eof usb_pcdc_serial_state_process() */ #if USB_ANSIIO_PP == USB_ANSIIO_USE_PP /*---CUT---CUT---CUT---CUT---CUT---CUT---CUT---CUT---CUT---CUT---CUT---CUT---*/ #else /* USB_ANSIIO_PP == USB_ANSIIO_USE_PP */ /****************************************************************************** Function Name : usb_pcdc_main_task Description : Peri CDC Sample Application Argument : USB_VP_INT_t Return : none ******************************************************************************/ void usb_pcdc_main_task(USB_VP_INT_t start_code) { USB_UTR_t *mess; USB_ER_t err = 0l; /* Receive Data Count for Comm Port */ uint16_t srcv_cnt; /* Receive Data Count for USB Host */ int32_t data_cnt; /* Recive message for message box of PCDC demo sample application. */ err = R_USB_TRCV_MSG(USB_PCDCSMP_MBX,(USB_MSG_t**)&mess,(uint16_t)3000); if( err == USB_E_OK ) { /* Branch by message infomation. */ switch(mess->msginfo) { case USB_PCDC_PERIODIC_PROCESS: /* Host CDC Connect check */ if( usb_pcdc_is_connected() == USB_OFF ) { /* Peri CDC Not Active set */ usb_gpcdc_active = USB_OFF; } else { /* Sw polling repetition */ usb_pcdc_smpl_message_send( mess, USB_PCDC_PERIODIC_PROCESS ); } if( usb_gpcdc_active == USB_OFF ) { /* Peri CDC Active set */ usb_gpcdc_active = USB_ON; /* Host CDC Data receive start */ usb_gpcdc_stx_wait = USB_ON; } /*----------------------------------*/ /* Switch Push Management process */ /*----------------------------------*/ usb_pcdc_sw_process(mess); /* Input RSK SW & Transfer SW push request Message */ /*----------------------------------*/ /* Serial error process */ /*----------------------------------*/ usb_pcdc_serial_state_process(mess); /* UART(SCI) error check & SerialState transfer. */ /*----------------------------------*/ /* Communications Port receive check */ /*----------------------------------*/ /* Send Complete wait flag check */ if(usb_gpcdc_tx_wait_flag == USB_OFF) { /* Echo mode Data copy */ if(usb_gpcdc_echo_mode) { /* Echo mode data copy Serial TX -> Serial RX */ usb_cpu_Sci_CopyData_for_Echo(); } /* Comm port data receive */ srcv_cnt = usb_cpu_Sci_DataReceive( usb_gpcdc_send_data, USB_PCDC_APL_SRX_SIZE ); if( srcv_cnt != 0 ) { /* Comm port receive data -> CDC Host send */ R_usb_pcdc_SendData(mess, usb_gpcdc_send_data, srcv_cnt, (USB_CB_t)&usb_pcdc_tx_notification); /* Send Complete wait flag on */ usb_gpcdc_tx_wait_flag = USB_ON; } } /*----------------------------------*/ /* CDC Host Bulk In Request */ /*----------------------------------*/ if(usb_gpcdc_stx_wait) /* Check flow control flag */ { /* Check UART transfer buffer condition. */ if( usb_cpu_Sci_StxBuffStatus() == 0) { /* Common Read(BULK OUT) */ R_usb_pcdc_ReceiveData(mess, (uint8_t *)&usb_gpcdc_receive_data, USB_PCDC_APL_RX_SIZE, (USB_CB_t)&usb_pcdc_rx_notification); /* Receive flow control flag off */ usb_gpcdc_stx_wait = USB_OFF; } } /* Release the memory block for the sample application */ err = R_USB_REL_BLK(USB_PCDCSMP_MPL,(USB_MH_t)mess); if( err != USB_OK ) { /* error */ USB_PRINTF0("### USB PeripheralSampleClass rel_blk error\n"); } break; case USB_PCDC_RX_COMP: /*----------------------------------*/ /* Get USB Receive Data count */ /*----------------------------------*/ data_cnt = usb_pcdc_get_rcv_data_cnt(mess); /*----------------------------------*/ /* CDC Host Bulk In receive check */ /*----------------------------------*/ if(data_cnt > 0) { /* Communications Port Data Send Process */ usb_cpu_Sci_DataSend(usb_gpcdc_echo_mode, &usb_gpcdc_receive_data , data_cnt); } /*----------------------------------*/ /* CDC Host Bulk In Request */ /*----------------------------------*/ if( usb_cpu_Sci_StxBuffStatus() == 0) { /* Common Read(BULK OUT) */ R_usb_pcdc_ReceiveData(mess, (uint8_t *)&usb_gpcdc_receive_data, USB_PCDC_APL_RX_SIZE, (USB_CB_t)&usb_pcdc_rx_notification); } else { /* Receive flow control flag on */ usb_gpcdc_stx_wait = USB_ON; } break; case USB_PCDC_TX_COMP: /*----------------------------------*/ /* Data send for Host cdc */ /*----------------------------------*/ /* Send Complete wait flag off */ usb_gpcdc_tx_wait_flag = USB_OFF; break; case USB_PCDC_STATUS_TX_COMP: /*------------------------------------------*/ /* Serial State Notification send complete */ /*------------------------------------------*/ /* Serial State Notification send flag clear */ usb_gpcdc_serial_state_tx = USB_OFF; break; case USB_PCDC_CLOSE: /* Application data Initialize and Periodic process request */ usb_pcdc_apl_init(mess); /* Release the memory block for the sample application */ err = R_USB_REL_BLK(USB_PCDCSMP_MPL,(USB_MH_t)mess); if( err != USB_OK ) { /* error */ USB_PRINTF0("### USB PeripheralSampleClass rel_blk error\n"); } break; default: /*----------------------------------*/ /* Undefine message */ /*----------------------------------*/ USB_PRINTF1("### Undefine message:%02x\n",mess->msginfo); /* Release the memory block for the sample application */ err = R_USB_REL_BLK(USB_PCDCSMP_MPL,(USB_MH_t)mess); if( err != USB_OK ) { /* error */ USB_PRINTF0("### USB PeripheralSampleClass rel_blk error\n"); } break; } } } /* eof usb_pcdc_main_task() */ /****************************************************************************** Function Name : usb_pcdc_get_rcv_data_cnt Description : Get USB Receive Data count Arguments : USBC_UTR_t Return value : USB receive data count ******************************************************************************/ uint16_t usb_pcdc_get_rcv_data_cnt(USB_UTR_t *mess) { /* Receive Data Count for USB Host */ uint16_t rcv_cnt; /*----------------------------------*/ /* Data receive from Host cdc */ /*----------------------------------*/ if(mess->status == USB_DATA_OK) { /* Receive size = Request size */ rcv_cnt = USB_PCDC_APL_RX_SIZE; } else if(mess->status == USB_DATA_SHT) { /* Receive size < Request size */ rcv_cnt = USB_PCDC_APL_RX_SIZE - mess->tranlen; } else { rcv_cnt = 0; } return rcv_cnt; } /* eof usb_pcdc_get_rcv_data_cnt() */ #endif /* USB_ANSIIO_PP == USB_ANSIIO_USE_PP */ /****************************************************************************** Function Name : usb_pcdc_rx_notification Description : CDC Host Rx complete Callback Argument : USB_UTR_t *mess : message Return : none ******************************************************************************/ void usb_pcdc_rx_notification(USB_UTR_t *mess) { USB_ER_t err; /* Set USB receive complete for APL notification message. */ mess->msginfo = USB_PCDC_RX_COMP; /* Send message */ err = R_USB_SND_MSG(USB_PCDCSMP_MBX, (USB_MSG_t*)mess); if( err != USB_E_OK ) { /* Send Message failure */ USB_PRINTF1("### usb_pcdc_rx_notification snd_msg error (%ld)\n", err); } } /* eof usb_pcdc_rx_notification() */ /****************************************************************************** Function Name : usb_pcdc_tx_notification Description : CDC Host Tx complete Callback Argument : USB_UTR_t *mess : message Return : none ******************************************************************************/ void usb_pcdc_tx_notification(USB_UTR_t *mess) { USB_ER_t err; /* Set USB transfer complete for APL notification message. */ mess->msginfo = USB_PCDC_TX_COMP; /* Send message */ err = R_USB_SND_MSG(USB_PCDCSMP_MBX, (USB_MSG_t*)mess); if( err != USB_E_OK ) { /* Send Message failure */ USB_PRINTF1("### usb_pcdc_tx_notification snd_msg error (%ld)\n", err); } } /* eof usb_pcdc_tx_notification() */ /****************************************************************************** Function Name : usb_pcdc_SerialStatusTxCB Description : CDC Host Tx complete Callback Argument : USB_UTR_t *mess : message Return : none ******************************************************************************/ void usb_pcdc_state_notification(USB_UTR_t *mess) { USB_ER_t err; /* Set SerialState transfer complete for APL notification message type. */ mess->msginfo = USB_PCDC_STATUS_TX_COMP; /* Send message */ err = R_USB_SND_MSG(USB_PCDCSMP_MBX, (USB_MSG_t*)mess); if( err != USB_E_OK ) { /* Send Message failure */ USB_PRINTF1("### usb_pcdc_state_notification snd_msg error (%ld)\n", err); } } /* eof usb_pcdc_state_notification() */ /****************************************************************************** Function Name : usb_pcdc_apl_init Description : Peri CDC Application memory clear Argument : USB_UTR_t *ptr : USB system internal structure. Return : none ******************************************************************************/ void usb_pcdc_apl_init(USB_UTR_t *ptr) { /* echo mode flag clear */ usb_gpcdc_echo_mode = USB_OFF; /* Clear SW2 push flag */ usb_gpcdc_sw2push = 0; /* Clear SW2 push request Message transfer timming counter */ usb_gpcdc_msg_timing_cnt = 0; /* Peri CDC Not Active set */ usb_gpcdc_active = USB_OFF; /* Clear data for USB TX and RX */ memset(usb_gpcdc_send_data,0,USB_PCDC_APL_SRX_SIZE); memset(usb_gpcdc_receive_data,0,USB_PCDC_APL_RX_SIZE); /* Instructions output line sequence */ usb_gpcdc_explain_seq = 0; /* HOST Send wait flag */ usb_gpcdc_tx_wait_flag = 0; /* Peri CDC Application Tx Rx data clear */ usb_cpu_Sci_Buffer_init(); #if USB_ANSIIO_PP == USB_ANSIIO_USE_PP /*---CUT---CUT---CUT---CUT---CUT---CUT---CUT---CUT---CUT---CUT---CUT---CUT---*/ #endif /* USB_ANSIIO_PP == USB_ANSIIO_USE_PP */ } /* eof usb_pcdc_apl_init() */ /****************************************************************************** Function Name : usb_pcdc_apl_msg_out Description : Terminal Output message send for Host CDC Argument : USB_UTR_t *ptr : USB system internal structure. : uint16_t message_no : Terminal Output message No. Return : none ******************************************************************************/ void usb_pcdc_apl_msg_out(USB_UTR_t *ptr, uint16_t message_no) { uint16_t len; /* Message length get */ len = strlen((char*)szWelcomeMsg[message_no]); /* Message send for Host CDC */ #if USB_ANSIIO_PP == USB_ANSIIO_USE_PP /*---CUT---CUT---CUT---CUT---CUT---CUT---CUT---CUT---CUT---CUT---CUT---CUT---*/ #else /* USB_ANSIIO_PP == USB_ANSIIO_USE_PP */ R_usb_pcdc_SendData(ptr, (uint8_t *)&szWelcomeMsg[message_no], len, (USB_CB_INFO_t)&usb_pcdc_tx_notification); #endif /* USB_ANSIIO_PP == USB_ANSIIO_USE_PP */ /* Host CDC Send complete wait flag on */ usb_gpcdc_tx_wait_flag = USB_ON; } /* eof usb_pcdc_apl_msg_out() */ /****************************************************************************** Function Name : usb_pcdc_smpl_message_send Description : Transfer message for Message BOX of demo sample application Argument : USB_UTR_t *ptr : IP Information(Mode,IP No.,Reg Address) : uint16_t msginfo : Message Information Kind Return : none ******************************************************************************/ void usb_pcdc_smpl_message_send( USB_UTR_t *ptr, uint16_t msginfo) { USB_MH_t p_blf; USB_ER_t err; USB_CLSINFO_t *cp; /* Get mem pool blk */ if( R_USB_PGET_BLK(USB_PCDCSMP_MPL, &p_blf) == USB_E_OK ) { cp = (USB_CLSINFO_t*)p_blf; cp->msginfo = msginfo; cp->ipp = ptr->ipp; cp->ip = ptr->ip; cp->msghead = (USB_MH_t)NULL; /* Send message */ err = R_USB_SND_MSG( USB_PCDCSMP_MBX, (USB_MSG_t*)cp ); if( err != USB_E_OK ) { /* error */ err = R_USB_REL_BLK(USB_PCDCSMP_MPL,(USB_MH_t)p_blf); USB_PRINTF0("### usb_pcdc_smpl_message_send function snd_msg error\n"); } } else { /* error */ USB_PRINTF0("### usb_pcdc_smpl_message_send function pget_blk error\n"); while( 1 ); } } /* eof usb_pcdc_smpl_message_send() */ /****************************************************************************** Function Name : usb_pcdc_open Description : Peripheral Communications Devices Class open function Arguments : USB_UTR_t *ptr : IP Information(Mode,IP No.,Reg Address) : uint16_t data1 : Not use : uint16_t data2 : Not use Return value : USB_ER_t : USB_E_OK etc ******************************************************************************/ USB_ER_t usb_pcdc_open(USB_UTR_t *ptr, uint16_t data1, uint16_t data2) { /* Peri CDC Application process enable */ usb_gcdc_connected = USB_ON; #if USB_ANSIIO_PP != USB_ANSIIO_USE_PP /* Sample class attach */ usb_pcdc_smpl_message_send( ptr, USB_PCDC_PERIODIC_PROCESS ); #endif /* USB_ANSIIO_PP != USB_ANSIIO_USE_PP */ return USB_E_OK; } /* eof usb_pcdc_open() */ /****************************************************************************** Function Name : usb_pcdc_close Description : Peripheral Communications Devices Class close function Arguments : USB_UTR_t *ptr : IP Information(Mode,IP No.,Reg Address) : uint16_t data1 : Not use : uint16_t data2 : Not use Return value : USB_ER_t : USB_E_OK etc ******************************************************************************/ USB_ER_t usb_pcdc_close(USB_UTR_t *ptr, uint16_t data1, uint16_t data2) { /* Sample class detatch */ usb_pcdc_smpl_message_send( ptr, USB_PCDC_CLOSE ); /* Peri CDC Application process disable */ usb_gcdc_connected = USB_OFF; return USB_E_OK; } /* eof usb_pcdc_close() */ /****************************************************************************** Function Name : usb_pcdc_is_connected Description : Get the USB cable connected state. Arguments : none Return value : USB_ON = Connected, USB_OFF = Disconnected. ******************************************************************************/ uint16_t usb_pcdc_is_connected(void) { return usb_gcdc_connected; } /* eof usb_pcdc_is_connected() */ /****************************************************************************** End Of File ******************************************************************************/
/****************************************************************************** * 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) 2010(2011,2012) Renesas Electronics Corpration * and Renesas Solutions Corp. All rights reserved. ******************************************************************************* * File Name : main.c * Version : 2.00 * Device(s) : Renesas SH-Series, RX-Series * Tool-Chain : Renesas SuperH RISC engine Standard Toolchain * : Renesas RX Standard Toolchain * OS : Common to None and uITRON 4.0 Spec * H/W Platform : Independent * Description : main process ****************************************************************************** * History : DD.MM.YYYY Version Description * : 29.07.2011 0.50 First Release ******************************************************************************/ /* $Id: main.c 143 2012-05-07 09:16:46Z tmura $ */ /****************************************************************************** Includes <System Includes> , "Project Includes" ******************************************************************************/ #include <machine.h> #include "r_usb_ctypedef.h" /* Type define */ #include "r_usb_usrconfig.h" #include "r_usb_ckernelid.h" /* Kernel ID definition */ #include "r_usb_cmacsystemcall.h" /* uITRON system call macro */ #include "r_usb_cmacprint.h" /* Standard IO macro */ #include "r_usb_cdefusbip.h" /* USB-FW Library Header */ #include "r_usb_cextern.h" #include "hw_resource.h" #include "r_usb_cusb_bitdefine.h" /****************************************************************************** Section <Section Definition> , "Project Sections" ******************************************************************************/ #pragma section _usb /****************************************************************************** External variables and functions ******************************************************************************/ extern void usb_cstd_task_start( void ); extern void usb_pcdc_pr_apl_title(void); extern uint8_t usb_cpu_GetDPSRSTF(void); extern void R_usb_cstd_SetTaskPri(uint8_t tasknum, uint8_t pri); extern void R_usb_pstd_DeviceInformation(USB_UTR_t *ptr, uint16_t *tbl); extern void usb_cpu_GoLpwrDeepStby(USB_UTR_t *ptr); extern void usb_cpu_GoLpwrSleep(USB_UTR_t *ptr); /* Condition compilation by the difference of the devices */ #if (USB_CPU_LPW_PP == USB_LPWR_USE_PP) extern uint16_t usb_gcpu_RemoteProcess; #endif /* (USB_CPU_LPW_PP == USB_LPWR_USE_PP) */ /****************************************************************************** Private global variables and functions ******************************************************************************/ void usb_cstd_IdleTaskStart(void); void usb_cstd_PrintKernelSysdwnInfo(signed long w, signed long er, signed long i1, signed long i2); /****************************************************************************** Function Name : usb_cstd_PrintKernelSysdwnInfo Description : System down Information print Arguments : signed long w : error kind : signed long er : error code : signed long i1 : system down information 1 : signed long i2 : system down information 2 Return value : none ******************************************************************************/ void usb_cstd_PrintKernelSysdwnInfo(signed long w, signed long er, signed long i1, signed long i2) { USB_PRINTF0("\nkernel_sysdwn ==========\n"); USB_PRINTF4(" %ld,%ld,%lx,%lx\n", w, er, i1, i2); USB_PRINTF0("========================\n"); } /* eof usb_cstd_PrintKernelSysdwnInfo() */ /****************************************************************************** Function Name : usb_cstd_PrAplTitle Description : Output Title on LCD or UART Argument : none Return : none ******************************************************************************/ void usb_cstd_PrAplTitle(void) { #ifdef USB_LCD_ENABLE usb_cpu_TargetLcdClear(); #endif /* USB_LCD_ENABLE */ USB_PRINTF0("\n"); USB_PRINTF0("+++++++++++++++++++++++++++++++++++++\n"); #if USB_FUNCSEL_USBIP0_PP == USB_HOST_PP || USB_FUNCSEL_USBIP1_PP == USB_HOST_PP USB_PRINTF0("+ HOST STANDARD FW SAMPLE +\n"); #endif /* USB_FUNCSEL_USBIP0_PP == USB_HOST_PP || USB_FUNCSEL_USBIP1_PP == USB_HOST_PP */ #if USB_FUNCSEL_USBIP0_PP == USB_PERI_PP || USB_FUNCSEL_USBIP1_PP == USB_PERI_PP USB_PRINTF0("+ PERI STANDARD FW SAMPLE +\n"); #endif /* USB_FUNCSEL_USBIP0_PP == USB_PERI_PP || USB_FUNCSEL_USBIP1_PP == USB_PERI_PP */ USB_PRINTF0("+ +\n"); USB_PRINTF0("+ RENESAS ELECTRONICS CORP. +\n"); USB_PRINTF0("+ RENESAS SOLUTIONS CORP. +\n"); USB_PRINTF0("+++++++++++++++++++++++++++++++++++++\n"); USB_PRINTF1(" DATE [%s] \n", __DATE__); USB_PRINTF1(" TIME [%s] \n", __TIME__); } /****************************************************************************** End of function usb_cstd_PrAplTitle() ******************************************************************************/ /****************************************************************************** Function Name : usb_cstd_main_task Description : main task process Arguments : USB_VP_INT stacd : task start code(not use) Return value : none ******************************************************************************/ void usb_cstd_main_task(USB_VP_INT stacd) { usb_cpu_target_init(); usb_pcdc_pr_apl_title(); usb_cstd_task_start(); } /****************************************************************************** End of function usb_cstd_main_task() ******************************************************************************/ /****************************************************************************** Function Name : usb_cstd_IdleTaskStart Description : Idle Task Start process Arguments : none Return value : none ******************************************************************************/ void usb_cstd_IdleTaskStart(void) { /* Condition compilation by the difference of the devices */ #if (USB_CPU_LPW_PP == USB_LPWR_USE_PP) R_usb_cstd_SetTaskPri(USB_IDL_TSK, USB_PRI_6); USB_SND_MSG(USB_IDL_MBX, 0); #endif /* (USB_CPU_LPW_PP == USB_LPWR_USE_PP) */ } /****************************************************************************** End of function usb_cstd_IdleTaskStart() ******************************************************************************/ /****************************************************************************** Function Name : usb_cstd_IdleTask Description : Idle Task (sleep sample) Arguments : USB_VP_INT stacd : task start code(not use) Return value : none ******************************************************************************/ void usb_cstd_IdleTask(USB_VP_INT stacd) { /* Condition compilation by the difference of USB function */ #if USB_FUNCSEL_USBIP0_PP == USB_HOST_PP || USB_FUNCSEL_USBIP1_PP == USB_HOST_PP /* nothing */ #else /* USB_FUNCSEL_USBIP0_PP == USB_HOST_PP || USB_FUNCSEL_USBIP1_PP == USB_HOST_PP */ /* Condition compilation by the difference of the devices */ #if (USB_CPU_LPW_PP == USB_LPWR_USE_PP) void usb_cpu_GoLpwrSleepMode(void); void usb_cpu_GoDeepStbyMode(ptr); uint16_t res[8], sts0; uint8_t stby; USB_UTR_t utr0, *ptr0; USB_UTR_t *mess; USB_ER_t err; uint16_t usb_idle; usb_idle = USB_OFF; ptr0 = (USB_UTR_t *)&utr0; ptr0->ip = USB_PERI_USBIP_NUM; ptr0->ipp = usb_cstd_GetUsbIpAdr( ptr0->ip ); /* Idle Task message receive (port0) */ err = USB_TRCV_MSG(USB_IDL_MBX, (USB_MSG_t**)&mess, (USB_TM_t)0); if( (err != USB_E_OK) && (err != USB_E_TMOUT) ) { /* USB_PRINTF1("### IdleTask rcv_msg error %ld\n", err); */ } else { /* Send message to IDL_TSK */ usb_idle = USB_ON; USB_SND_MSG(USB_IDL_MBX, 0); } if( usb_idle == USB_ON ) { /* Condition compilation by the difference of USB function */ #if USB_FUNCSEL_USBIP0_PP == USB_PERI_PP || USB_FUNCSEL_USBIP1_PP == USB_PERI_PP R_usb_pstd_DeviceInformation(ptr0, (uint16_t *)res); #endif /* USB_FUNCSEL_USBIP0_PP == USB_PERI_PP || USB_FUNCSEL_USBIP1_PP == USB_PERI_PP */ /* Condition compilation by the difference of USB function */ sts0 = res[0]; if( (sts0 & USB_VBSTS) == 0 ) { sts0 = USB_DETACHED; /* Port0 detach */ } else if( (sts0 & USB_DS_SPD_CNFG) == USB_DS_SPD_CNFG ) { sts0 = USB_SUSPENDED; /* Port0 suspend */ } else { sts0 = USB_PORTOFF; } if( sts0 == USB_DETACHED ) { /* Detach */ usb_gcpu_RemoteProcess = USB_OFF; /* Get Deep Software Standby Reset Flag */ stby = usb_cpu_GetDPSRSTF(); if( stby == 0 ) { /* Deep Standby shift */ usb_cpu_GoLpwrDeepStby(ptr0); } } else if( sts0 == USB_SUSPENDED ) { /* Suspend */ usb_cpu_GoLpwrSleep(ptr0); } else { usb_gcpu_RemoteProcess = USB_OFF; } } #else /* (USB_CPU_LPW_PP == USB_LPWR_USE_PP) */ #endif /* (USB_CPU_LPW_PP == USB_LPWR_USE_PP) */ #endif /* USB_FUNCSEL_USBIP0_PP == USB_HOST_PP || USB_FUNCSEL_USBIP1_PP == USB_HOST_PP */ } /****************************************************************************** End of function usb_cstd_IdleTask() ******************************************************************************/ /****************************************************************************** Function Name : R_usb_cstd_IdleTask Description : Call Idle Task (sleep sample) Arguments : USB_VP_INT stacd : task start code(not use) Return value : none ******************************************************************************/ void R_usb_cstd_IdleTask(USB_VP_INT stacd) { usb_cstd_IdleTask( stacd ); } /****************************************************************************** End of function R_usb_cstd_IdleTask() ******************************************************************************/ /****************************************************************************** End Of File ******************************************************************************/