/******************************************************************************\r
Private global variables and functions\r
******************************************************************************/\r
+void io_set_cpg(void);\r
+void ConfigurePortPins(void);\r
+void EnablePeripheralModules(void);\r
\r
/******************************************************************************\r
* Function Name: HardwareSetup\r
* Description : This function does initial setting for CPG port pins used in\r
-* : the Demo including the MII pins of the Ethernet PHY connection.\r
-* Arguments : none\r
+* : the Demo including the MII pins of the Ethernet PHY connection.\r
+* Arguments : none\r
* Return Value : none\r
******************************************************************************/\r
void HardwareSetup(void)\r
{\r
+ /* CPG setting */\r
+ io_set_cpg();\r
+\r
+ /* Setup the port pins */\r
+ ConfigurePortPins();\r
+\r
+ /* Enables peripherals */\r
+ EnablePeripheralModules();\r
+\r
+#if INCLUDE_LCD == 1\r
+ /* Initialize display */\r
+ InitialiseDisplay();\r
+#endif\r
+}\r
+\r
+/******************************************************************************\r
+* Function Name: EnablePeripheralModules\r
+* Description : Enables Peripheral Modules before use\r
+* Arguments : none\r
+* Return Value : none\r
+******************************************************************************/\r
+void EnablePeripheralModules(void)\r
+{\r
+ /* Module standby clear */\r
+ SYSTEM.MSTPCRB.BIT.MSTPB15 = 0; /* EtherC, EDMAC */\r
+ SYSTEM.MSTPCRA.BIT.MSTPA15 = 0; /* CMT0 */\r
+}\r
+\r
+/******************************************************************************\r
+* Function Name: ConfigurePortPins\r
+* Description : Configures port pins.\r
+* Arguments : none\r
+* Return Value : none\r
+******************************************************************************/\r
+void ConfigurePortPins(void)\r
+{\r
+/* Port pins default to inputs. To ensure safe initialisation set the pin states\r
+before changing the data direction registers. This will avoid any unintentional\r
+state changes on the external ports.\r
+Many peripheral modules will override the setting of the port registers. Ensure\r
+that the state is safe for external devices if the internal peripheral module is\r
+disabled or powered down. */\r
+\r
+ /* ==== MII/RMII Pins setting ==== */\r
+ /*--------------------------------------*/\r
+ /* Port Function Control Register */\r
+ /*--------------------------------------*/\r
+#if ETH_MODE_SEL == ETH_MII_MODE\r
+ /* EE=1, PHYMODE=1, ENETE3=1, ENETE2=0, ENETE1=1, ENETE0=0 (Ethernet) */\r
+ IOPORT.PFENET.BYTE = 0x9A;\r
+#else /* ETH_MODE_SEL */\r
+ /* EE=1, PHYMODE=0, ENETE3=0, ENETE2=0, ENETE1=1, ENETE0=0 (Ethernet) */\r
+ IOPORT.PFENET.BYTE = 0x82;\r
+#endif /* ETH_MODE_SEL */\r
+ /*-------------------------------------------*/\r
+ /* Input Buffer Control Register (ICR) */\r
+ /*-------------------------------------------*/\r
+#if ETH_MODE_SEL == ETH_MII_MODE\r
+ /* P54=1 Set ET_LINKSTA input */\r
+ PORT5.ICR.BIT.B4 = 1;\r
+ /* P71=1 Set ET_MDIO input */\r
+ PORT7.ICR.BIT.B1 = 1;\r
+ /* P74=1 Set ET_ERXD1 input */\r
+ PORT7.ICR.BIT.B4 = 1;\r
+ /* P75=1 Set ET_ERXD0 input */\r
+ PORT7.ICR.BIT.B5 = 1;\r
+ /* P76=1 Set ET_RX_CLK input */\r
+ PORT7.ICR.BIT.B6 = 1;\r
+ /* P77=1 Set ET_RX_ER input */\r
+ PORT7.ICR.BIT.B7 = 1;\r
+ /* P83=1 Set ET_CRS input */\r
+ PORT8.ICR.BIT.B3 = 1;\r
+ /* PC0=1 Set ET_ERXD3 input */\r
+ PORTC.ICR.BIT.B0 = 1;\r
+ /* PC1=1 Set ET_ERXD2 input */\r
+ PORTC.ICR.BIT.B1 = 1;\r
+ /* PC2=1 Set ET_RX_DV input */\r
+ PORTC.ICR.BIT.B2 = 1;\r
+ /* PC4=1 Set EX_TX_CLK input */\r
+ PORTC.ICR.BIT.B4 = 1;\r
+ /* PC7=1 Set ET_COL input */\r
+ PORTC.ICR.BIT.B7 = 1;\r
+#else /* ETH_MODE_SEL */\r
+ /* P54=1 Set ET_LINKSTA input */\r
+ PORT5.ICR.BIT.B4 = 1;\r
+ /* P71=1 Set ET_MDIO input */\r
+ PORT7.ICR.BIT.B1 = 1;\r
+ /* P74=1 Set RMII_RXD1 input */\r
+ PORT7.ICR.BIT.B4 = 1;\r
+ /* P75=1 Set RMII_RXD0 input */\r
+ PORT7.ICR.BIT.B5 = 1;\r
+ /* P76=1 Set REF50CLK input */\r
+ PORT7.ICR.BIT.B6 = 1;\r
+ /* P77=1 Set RMII_RX_ER input */\r
+ PORT7.ICR.BIT.B7 = 1;\r
+ /* P83=1 Set RMII_CRS_DV input */\r
+ PORT8.ICR.BIT.B3 = 1;\r
+#endif /* ETH_MODE_SEL */\r
+\r
+ /* Configure LED 0-5 pin settings */\r
+ PORT0.DR.BIT.B2 = 1; \r
+ PORT0.DR.BIT.B3 = 1;\r
+ PORT0.DR.BIT.B5 = 1;\r
+ PORT3.DR.BIT.B4 = 1;\r
+ PORT6.DR.BIT.B0 = 1;\r
+ PORT7.DR.BIT.B3 = 1;\r
+ PORT0.DDR.BIT.B2 = 1; \r
+ PORT0.DDR.BIT.B3 = 1;\r
+ PORT0.DDR.BIT.B5 = 1;\r
+ PORT3.DDR.BIT.B4 = 1;\r
+ PORT6.DDR.BIT.B0 = 1;\r
+ PORT7.DDR.BIT.B3 = 1;\r
+\r
+ /* Configure SW 1-3 pin settings */\r
+ PORT0.DDR.BIT.B0 = 0;\r
+ PORT0.DDR.BIT.B1 = 0;\r
+ PORT0.DDR.BIT.B7 = 0;\r
+ PORT0.ICR.BIT.B0 = 1;\r
+ PORT0.ICR.BIT.B1 = 1;\r
+ PORT0.ICR.BIT.B7 = 1;\r
+\r
+#if INCLUDE_LCD == 1\r
+ /* Set LCD pins as outputs */\r
+ /* LCD-RS */\r
+ PORT8.DDR.BIT.B4 = 1;\r
+ /* LCD-EN */\r
+ PORT8.DDR.BIT.B5 = 1;\r
+ /*LCD-data */\r
+ PORT9.DDR.BYTE = 0xF0;\r
+#endif\r
+}\r
+\r
+/******************************************************************************\r
+* Function Name: io_set_cpg\r
+* Description : Sets up operating speed\r
+* Arguments : none\r
+* Return Value : none\r
+******************************************************************************/\r
+void io_set_cpg(void)\r
+{\r
+/* Set CPU PLL operating frequencies. Changes to the peripheral clock will require\r
+changes to the debugger and flash kernel BRR settings. */\r
+\r
+ /* ==== CPG setting ==== */\r
+ SYSTEM.SCKCR.LONG = 0x00020100; /* Clockin = 12MHz */\r
+ /* I Clock = 96MHz, B Clock = 24MHz, */\r
+ /* P Clock = 48MHz */\r
\r
- unsigned long sckcr = 0;\r
-\r
- /* Configure system clocks based on header */\r
- sckcr += (ICLK_MUL==8) ? (0ul << 24) : (ICLK_MUL==4) ? (1ul << 24) : (ICLK_MUL==2) ? (2ul << 24) : (3ul << 24);\r
- sckcr += (BCLK_MUL==8) ? (0ul << 16) : (BCLK_MUL==4) ? (1ul << 16) : (BCLK_MUL==2) ? (2ul << 16) : (3ul << 16);\r
- sckcr += (PCLK_MUL==8) ? (0ul << 8) : (PCLK_MUL==4) ? (1ul << 8) : (PCLK_MUL==2) ? (2ul << 8) : (3ul << 8);\r
- SYSTEM.SCKCR.LONG = sckcr;\r
-\r
- /* Configure LED 0-5 pins as outputs */\r
- LED0 = LED_OFF; \r
- LED1 = LED_OFF;\r
- LED2 = LED_OFF;\r
- LED3 = LED_OFF;\r
- LED4 = LED_OFF;\r
- LED5 = LED_OFF;\r
- LED0_DDR = 1; \r
- LED1_DDR = 1;\r
- LED2_DDR = 1;\r
- LED3_DDR = 1;\r
- LED4_DDR = 1;\r
- LED5_DDR = 1;\r
-\r
- /* Configure SW 1-3 pins as inputs */\r
- SW1_DDR = 0;\r
- SW2_DDR = 0;\r
- SW3_DDR = 0;\r
- SW1_ICR = 1;\r
- SW2_ICR = 1;\r
- SW3_ICR = 1;\r
-\r
- \r
- /* Configure LCD pins as outputs - uncomment this if an LCD is present.\r
- LCD_RS_DDR = 1;\r
- LCD_EN_DDR = 1;\r
- LCD_DATA_DDR = 0xF0; */\r
-\r
- /* Initialize display - uncomment this if an LCD is present.\r
- InitialiseDisplay(); */\r
}\r
\r