Created
December 9, 2015 00:27
-
-
Save YuuichiAkagawa/10d0384bb90e90a23624 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void USB::initialise() | |
{ | |
/* Configure the USB0 host pins(USB0_OVRCURA and USB0_VBUSEN) needed */ | |
// protection got turned off in hardware setup | |
// MPC.PWPR.BIT.B0WI = 0; // Enable write to PFSWE bit | |
// MPC.PWPR.BIT.PFSWE = 1; // Disable write protection to PFS registers | |
/* Use this for GR-Sakura and RSK */ | |
PORT1.PDR.BIT.B6 = 1; // P16 is an output pin | |
PORT1.PCR.BIT.B6 = 1; // P16 is an output pin | |
MPC.P16PFS.BIT.PSEL = 0x12; // Configure as USB0_VBUSEN pin | |
PORT1.PMR.BIT.B6 = 1; // Link the port pin to the peripheral | |
/* Use this for GR-Sakura */ | |
//Added 2015.12.08 Yuuichi Akagawa | |
/* Disable USB0_DPUPE */ | |
MPC.P14PFS.BIT.PSEL = 0; // Configure as GPIO pin | |
PORT1.PMR.BIT.B4 = 0; | |
PORT1.PDR.BIT.B4 = 0; | |
PORT1.PODR.BIT.B4 = 0; | |
/* Short J12 and J14 on the sakura board. Following code will | |
* enable the pull down resistor lines */ | |
PORT2.PDR.BIT.B2 = 1; //required?(When Short J13 and J15) | |
PORT2.PODR.BIT.B2 = 0; //required?(When Short J13 and J15) | |
PORT2.PDR.BIT.B5 = 1; //required?(When Short J13 and J15) | |
PORT2.PODR.BIT.B5 = 0; //required?(When Short J13 and J15) | |
// protection got turned off in hardware setup | |
// MPC.PWPR.BIT.PFSWE = 0; // Enable write protection to PFS registers | |
// MPC.PWPR.BIT.B0WI = 0; // Disable write to PFSWE bit | |
/* Disable register protection */ | |
// SYSTEM.PRCR.WORD = 0xA50B; // protection got turned off in hardware setup | |
/* Enable the clock to the USB module */ | |
MSTP(USB0) = 0; | |
USBC.DPUSR0R.BIT.FIXPHY0 = 0; // USB0 The outputs are fixed in normal mode and on return from deep software standby mode | |
/* Enable USB0 */ | |
// USB0.SYSCFG.WORD = 0x0041; | |
USB0.SYSCFG.WORD = 0; //It temporarily disabled. Enable at R_USBH_Initialise() | |
/* Enable register protection */ | |
// SYSTEM.PRCR.WORD = 0xA500; // protection got turned off in hardware setup | |
#if defined(TESTING) | |
/* Open the host driver */ | |
usbhOpen(&gUsbHc0); | |
/* Add the root ports to the driver */ | |
usbhAddRootPort(&gUsbHc0, (PUSBPC)&gcRootPort0); | |
#endif | |
/* Initialize the USB hardware */ | |
R_USBH_Initialise(&USB0); | |
#if !defined(TESTING) | |
/* Start the enumeration timer. (Starts on construction) */ | |
if(enumTimer==NULL) | |
{ | |
enumTimer = new System_Timer(1,(void(*)(void*))enumRun,NULL,TIMER_RELOAD); | |
} | |
#endif | |
//Added 2015.12.08 Yuuichi Akagawa | |
/* Clear all USB interrupts */ | |
USB0.INTSTS0.WORD = 0; | |
USB0.INTSTS1.WORD = 0; | |
/* Set USB interrupt priority */ | |
IPR(USB,USBR0) = 14; | |
IPR(USB0,D0FIFO0) = 14; | |
IPR(USB0,D1FIFO0) = 14; | |
IPR(USB0,USBI0) = 14; | |
/* Enable the attach interrupts for each root port*/ | |
IEN(USB0, USBI0) = 1; | |
IEN(USB, USBR0) = 1; | |
IEN(USB0, D0FIFO0) = 1; | |
IEN(USB0, D1FIFO0) = 1; | |
USB0.INTENB1.WORD |= BIT_11; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment