]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/commitdiff
SCI - rpp_sci_vprintf(); header files updated (hw regs added); link change interrupt...
authorJan Dolezal <pm.jenik@gmail.com>
Wed, 14 Aug 2013 12:37:40 +0000 (14:37 +0200)
committerJan Dolezal <pm.jenik@gmail.com>
Wed, 14 Aug 2013 12:37:40 +0000 (14:37 +0200)
rpp/include/rpp/sci.h
rpp/include/sys/hw_emac_ctrl.h
rpp/include/sys/sys_vim.h
rpp/include/sys/ti_drv_emac.h
rpp/src/rpp/eth.c
rpp/src/rpp/sci.c
rpp/src/sys/notification.c
rpp/src/sys/sys_startup.c

index 9cca71238bb036f9f8247247aa7967f907f77390..6e2733e5126f7c1222ad5a9ef53f9a0936be72fb 100644 (file)
@@ -179,7 +179,7 @@ int8_t rpp_sci_flush(boolean_t buff);
  *          completely written.
  */
 int32_t rpp_sci_printf(const char* format, ...);
-int32_t __rpp_sci_printf(const char* format, va_list args);
+int32_t rpp_sci_vprintf(const char* format, va_list args);
 
 
 /**
index 43223b42d803645dbb2f3af1087856eaa22774ed..3851d75ca66928a46b3b2a5db28f0219c5109cc6 100644 (file)
@@ -44,6 +44,18 @@ extern "C" {
 * Field Definition Macros
 \**************************************************************************/
 
+#define EMAC_CTRL_MISC_STATPENDENB (0x00000008u)
+#define EMAC_CTRL_MISC_STATPENDENB_SHIFT (0x00000003u)
+
+#define EMAC_CTRL_MISC_HOSTPENDENB (0x00000004u)
+#define EMAC_CTRL_MISC_HOSTPENDENB_SHIFT (0x00000002u)
+
+#define EMAC_CTRL_MISC_LINKINT0ENB (0x00000002u)
+#define EMAC_CTRL_MISC_LINKINT0ENB_SHIFT (0x00000001u)
+
+#define EMAC_CTRL_MISC_USERINT0ENB (0x00000001u)
+#define EMAC_CTRL_MISC_USERINT0ENB_SHIFT (0x00000000u)
+
 #ifdef __cplusplus
 }
 #endif
index e07076594868b2a92fa8571bc61bfc6d704793f4..e9c9179f6d3084c4eebec2402e48a3c08f4b3f30 100644 (file)
@@ -61,6 +61,7 @@ extern void adc2Group1Interrupt(void);
 extern void spi4LowLevelInterrupt(void);
 extern void sciHighLevelInterrupt(void);
 extern void i2cInterrupt(void);
+//extern void MDIOMiscInt(void);
 extern void EMACCore0RxIsr(void);
 extern void EMACCore0TxIsr(void);
 
index 35c54cd3a857cdde64f2ae98f82995be9defb133..6857aa3343919531dac6bdae7e89acd3f4270e8c 100644 (file)
@@ -44,6 +44,13 @@ extern "C" {
 /* Address will be used to match incoming packets */
 #define EMAC_MACADDR_MATCH                    (0x00180000u)
 
+/*
+** Macros which can be passed as eoiFlag to EMACRxThreshIntAckToClear API
+*/
+#define EMAC_INT_CORE0_RX_THRSH               (0x0u)
+#define EMAC_INT_CORE1_RX_THRSH               (0x4u)
+#define EMAC_INT_CORE2_RX_THRSH               (0x8u)
+
 /*
 ** Macros which can be passed as eoiFlag to EMACRxIntAckToClear API
 */
@@ -58,6 +65,14 @@ extern "C" {
 #define EMAC_INT_CORE1_TX                     (0x6u)
 #define EMAC_INT_CORE2_TX                     (0xAu)
 
+/*
+** Macros which can be passed as eoiFlag to EMACMiscIntAckToClear API
+** STATPEND, HOSTPEND, MDIO LINKINT0, MDIO USERINT0
+*/
+#define EMAC_INT_CORE0_MISC                   (0x3u)
+#define EMAC_INT_CORE1_MISC                   (0x7u)
+#define EMAC_INT_CORE2_MISC                   (0xBu)
+
 /*****************************************************************************/
 /*
 ** Prototypes for the APIs
index 2f06aef209d6ea19c8bbf621d0b44d3ba8eea05c..a4f13bd3c183a57449b62db4425875993b0c2e62 100644 (file)
 #define NUM_OF_PHYs               32
 #define SIZE_OF_DESC              16 /* in bytes */
 #define CHANNEL                   0 /* channel number for everything - for rx, tx, unicast, broadcast or damaged frames ; there are different channels for rx and tx operations */
+#define PHY_LINK_MONITOR_INT      0 /* turn on handling interrupt risen when link status is changed (cable out or in) */
 
 #define MAX_TRANSFER_UNIT         1500 /* take in account oversized frames */
 #define PBUF_LEN_MAX              MAX_TRANSFER_UNIT
@@ -847,6 +848,15 @@ err_t rpp_eth_hw_init_postInit(struct netif *netif)
        return UNKN_DUPLEX_MODE;
     }
 
+    /* TODO: reorganize code for linkint handling and maybe add functions for it */
+#if PHY_LINK_MONITOR_INT
+    /* set PHY number which is monitored for link changes in MDIO and enable interrupt */
+    HWREG(hdkif->mdio_base + MDIO_USERPHYSEL0) = ((hdkif->phy_addr && 0x1f) | MDIO_USERPHYSEL0_LINKINTENB);
+
+    /* enable MISC interrupt for link monitoring in EMAC controle module */
+    HWREG(hdkif->emac_ctrl_base + EMAC_CTRL_CnMISCEN(0)) |= EMAC_CTRL_MISC_LINKINT0ENB;
+#endif
+
        /* enable EMAC's Media Independent Interface TX and RX */
        EMACMIIEnable(hdkif->emac_base);
        /* enable EMAC transmit */
@@ -1240,6 +1250,31 @@ void TxIntHandler(u32_t instNum)
 #endif
 }
 
+#if PHY_LINK_MONITOR_INT
+boolean_t LinkIntHandler(void)
+{
+       uint8_t index = MAX_EMAC_INSTANCE, phyFound = FALSE;
+
+       /* check each instance, whether this interrupt was meant for this function */
+       while(index--){
+       struct hdkif *hdkif = &hdkif_data[index];
+           if( hdkif->phy_addr == (HWREG(hdkif->mdio_base + MDIO_USERPHYSEL0) & 0x1f) && (HWREG(hdkif->emac_base + EMAC_MACINVECTOR) & EMAC_MACINVECTOR_LINKINT0) )phyFound = TRUE;
+       }
+    if(!phyFound)return FALSE
+
+    /* do whatever necessary for link status change here */
+
+       /* acknowledge MDIO module */
+       HWREG(hdkif->mdio_base + MDIO_LINKINTRAW) = MDIO_LINKINTMASKED_USERPHY0;
+       HWREG(hdkif->mdio_base + MDIO_LINKINTMASKED) = MDIO_LINKINTMASKED_USERPHY0;
+
+       /* acknowledge EMAC control module by writing appropriate key to MACEOIVECTOR */
+       EMACCoreIntAck(hdkif->emac_base, EMAC_INT_CORE0_MISC);
+
+       return TRUE;
+}
+#endif
+
 
 /*      --- EMAC DESCRIPTOR FORMAT ---
  *                                         bit fields
index 12e93a23df3941ac6599c9732f18193339c14ea7..e109d63b9ed35a11246ea230d94b8cd580181fb3 100644 (file)
@@ -187,39 +187,16 @@ int8_t rpp_sci_flush(boolean_t buff)
 
 int32_t rpp_sci_printf(const char* format, ...)
 {
-    char str[MAX_BUFFER_LEN];
-    int length = -1;
-
+       int length = -1;
     va_list argList;
     va_start(argList, format);
-
-    length = vsnprintf(str, sizeof(str), format, argList);
-
+    length = rpp_sci_vprintf(format, argList);
     va_end(argList);
 
-    if(length > 0) {
-        #if rppCONFIG_DRV == 1
-        // According to the C stdlib about vsnprintf:
-        // If the resulting string would be longer than n-1 characters, the
-        // remaining characters are discarded and not stored, but counted
-        // for the value returned by the function.
-        // In consequence we need to trim the value if larger than buffer.
-        if(length >= sizeof(str)) {
-            length = sizeof(str) - 1;
-        }
-        if(drv_sci_send(
-                        (uint32_t)length,
-                        (uint8_t*)str,
-                        portMAX_DELAY) != SUCCESS) {
-            return -1;
-        }
-        #endif
-    }
-
     return length;
 }
 
-int32_t __rpp_sci_printf(const char* format, va_list argList)
+int32_t rpp_sci_vprintf(const char* format, va_list argList)
 {
     char str[MAX_BUFFER_LEN];
     int length = -1;
index fd790f1142e57bbf23d645de41907a0a358b283d..23fead368ac06160b3ff110241a3d876573ac7f7 100644 (file)
@@ -260,6 +260,17 @@ void linNotification(linBASE_t *lin, uint32_t flags)
     }
 }
 
+#define PHY_LINK_MONITOR_INT 0
+
+#if PHY_LINK_MONITOR_INT
+extern boolean_t LinkIntHandler(void);
+#pragma INTERRUPT(MDIOMiscInt, IRQ)
+void MDIOMiscInt(void)
+{
+       if(LinkIntHandler())return;
+}
+#endif
+
 extern void RxIntHandler(uint32_t instNum);
 extern void TxIntHandler(uint32_t instNum);
 
@@ -295,6 +306,5 @@ void EMACCore0TxIsr(void)
     */
 }
 
-
 /* USER CODE BEGIN (38) */
 /* USER CODE END */
index b603d84f96ecec50d59f1b2d3e42ccab8015b488..593d545be94828669efb1e2178b5f0767be49970 100644 (file)
@@ -168,7 +168,7 @@ static const t_isrFuncPTR s_vim_init[] =
     &phantomInterrupt,
     &phantomInterrupt,
     &phantomInterrupt,      // 75
-    &phantomInterrupt,
+    &phantomInterrupt,      //MDIOMiscInt
     &EMACCore0TxIsr,
     &phantomInterrupt,
     &EMACCore0RxIsr,
@@ -783,7 +783,7 @@ void _c_int00()
                     | (SYS_IRQ << 9U)
                     | (SYS_IRQ << 10U)
                     | (SYS_IRQ << 11U)
-                    | (SYS_IRQ << 12U)
+                    | (SYS_IRQ << 12U)  // MDIOMiscInt
                     | (SYS_IRQ << 13U)  // EMAC
                     | (SYS_IRQ << 14U)
                     | (SYS_IRQ << 15U)  // EMAC
@@ -917,7 +917,7 @@ void _c_int00()
                         | (0U << 9U)
                         | (0U << 10U)
                         | (0U << 11U)
-                        | (0U << 12U)
+                        | (0U << 12U)       // MDIOMiscInt
                         | (1U << 13U)       // EMACCore0TxIsr
                         | (0U << 14U)
                         | (1U << 15U)       // EMACCore0RxIsr