]> rtime.felk.cvut.cz Git - pes-rpp/rpp-test-sw.git/blobdiff - rpp-test-sw/commands/cmd_emac.c
Guard tms570_rpp-specific code with #ifdef
[pes-rpp/rpp-test-sw.git] / rpp-test-sw / commands / cmd_emac.c
index a5b52cb849b1adac302c01c44c60f7b6e7294f63..c7edb82d7c454f8c5b9e1a8842fb2e460350fe65 100644 (file)
@@ -6,18 +6,10 @@
  * Authors:
  *     - Rostislav LisovĂ˝
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ * This document contains proprietary information belonging to Czech
+ * Technical University in Prague. Passing on and copying of this
+ * document, and communication of its contents is not permitted
+ * without prior written authorization.
  *
  * File : cmd_emac.c
  *
 /*   Emac frame buffer related stuff                 */
 /* ************************************************* */
 typedef struct _EMAC_Desc {
-       struct _EMAC_Desc *pNext;       /* Pointer to next descriptor in chain */
-       uint8_t *pBuffer;                       /* Pointer to data buffer */
-       uint32_t BufOffLen;             /* Buffer Offset(MSW) and Length(LSW) */
-       uint32_t PktFlgLen;             /* Packet Flags(MSW) and Length(LSW) */
+       struct _EMAC_Desc *pNext;   /* Pointer to next descriptor in chain */
+       uint8_t *pBuffer;           /* Pointer to data buffer */
+       uint32_t BufOffLen;         /* Buffer Offset(MSW) and Length(LSW) */
+       uint32_t PktFlgLen;         /* Packet Flags(MSW) and Length(LSW) */
 } EMAC_Desc;
 
 /* Packet Flags */
-#define EMAC_DSC_FLAG_SOP                      0x80000000u
-#define EMAC_DSC_FLAG_EOP                      0x40000000u
-#define EMAC_DSC_FLAG_OWNER            0x20000000u
-#define EMAC_DSC_FLAG_EOQ                      0x10000000u
-#define EMAC_DSC_FLAG_TDOWNCMPLT       0x08000000u
-#define EMAC_DSC_FLAG_PASSCRC          0x04000000u
+#define EMAC_DSC_FLAG_SOP           0x80000000u
+#define EMAC_DSC_FLAG_EOP           0x40000000u
+#define EMAC_DSC_FLAG_OWNER         0x20000000u
+#define EMAC_DSC_FLAG_EOQ           0x10000000u
+#define EMAC_DSC_FLAG_TDOWNCMPLT    0x08000000u
+#define EMAC_DSC_FLAG_PASSCRC       0x04000000u
 
 /* ************************************************* */
 /*   Ethernet frame                                  */
 /* ************************************************* */
 typedef struct {
-       uint8_t  destination[6];
-       uint8_t  source[6];
+       uint8_t destination[6];
+       uint8_t source[6];
        uint16_t len;
-       uint8_t  data[50];
+       uint8_t data[50];
        uint32_t fcs;
 } eth_frame_t;
 
@@ -67,10 +59,10 @@ typedef struct {
 
 
 
-unsigned int emacCtrlBase      = EMAC_CTRL_BASE;
-unsigned int emacBase          = EMAC_BASE;
-unsigned int emacCtrlRamBase   = EMAC_CTRL_RAM_BASE;
-unsigned int mdioBase          = MDIO_BASE;
+unsigned int emacCtrlBase   = EMAC_CTRL_BASE;
+unsigned int emacBase       = EMAC_BASE;
+unsigned int emacCtrlRamBase    = EMAC_CTRL_RAM_BASE;
+unsigned int mdioBase       = MDIO_BASE;
 
 int rx_irq_cnt; /* Interrupt counters */
 int tx_irq_cnt;
@@ -81,31 +73,31 @@ unsigned int phylink;
 unsigned int intvect;
 unsigned int intvectraw;
 
-uint8_t emacAddress[6]         = {0x12, 0x34, 0x56, 0x78, 0x90, 0xab};
-uint32_t emacPhyAddress = 0x1; /* Address of PHY on "MDIO bus"
-                                  (depends on PHY configuration) */
-int channel = 0;       /* Emac has 8 RX and TX channels; we use only one */
+uint8_t emacAddress[6]  = {0x12, 0x34, 0x56, 0x78, 0x90, 0xab};
+uint32_t emacPhyAddress = 0x1;  /* Address of PHY on "MDIO bus"
+                                   (depends on PHY configuration) */
+int channel = 0;    /* Emac has 8 RX and TX channels; we use only one */
 
-EMAC_Desc fr1 __attribute__((aligned(4)));     /* Frame descriptor of Ethernet frame to be sent */
+EMAC_Desc fr1 __attribute__((aligned(4)));  /* Frame descriptor of Ethernet frame to be sent */
 
 /* Frame descriptor used for receiving frames --
    it might be placed in normal RAM or in CPPI ram of EMAC */
 //EMAC_Desc rx_desc __attribute__((aligned(4)));
-volatile EMAC_Desc *rx_desc = ((EMAC_Desc*) EMAC_CTRL_RAM_BASE);
+volatile EMAC_Desc *rx_desc = ((EMAC_Desc *)EMAC_CTRL_RAM_BASE);
 
 
-#define BUFF_SIZE      2048
+#define BUFF_SIZE   2048
 uint8_t rx_buff[BUFF_SIZE]; /* Buffer for data reception */
 
-eth_frame_t efr1;      /* Buffer for TX -- Before sending some data we have to
-                          prepare it in "Ethernet frame" format */
+eth_frame_t efr1;   /* Buffer for TX -- Before sending some data we have to
+                       prepare it in "Ethernet frame" format */
 
 
 void dummy_wait()
 {
        volatile int i;
 
-       for (i = 0; i < 65555; i ++)
+       for (i = 0; i < 65555; i++)
                ;
 }
 
@@ -117,6 +109,7 @@ int emac_test(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
        unsigned short data;
        int j;
 
+#ifdef TARGET_TMS570_RPP
        /* Deactivate reset pin of PHY */
        dmmREG->PC4 = (1 << DMM_CLK); /* Set to H */
        dummy_wait();
@@ -124,6 +117,7 @@ int emac_test(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
        dummy_wait();
        dmmREG->PC4 = (1 << DMM_CLK); /* Set to H */
        dummy_wait();
+#endif
 
        /* Prepare RX Packet buffer descriptor */
        rx_desc->pBuffer = rx_buff;
@@ -155,7 +149,7 @@ int emac_test(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
 
        EMACInit(emacCtrlBase, emacBase);
        MDIOInit(mdioBase, 0x0, 0x0);
-       dummy_wait();   // FIXME
+       dummy_wait();   // FIXME
 
        EMACMACSrcAddrSet(emacBase, emacAddress);
        /*  Be sure to program all eight MAC address registers -
@@ -184,13 +178,14 @@ int emac_test(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
        if (data & PHY_100BASETXDUPL_m) {
                EMACDuplexSet(emacBase, EMAC_DUPLEX_FULL);
                dummy_wait();
-       } else if (data & PHY_100BASETX_m) {
+       }
+       else if (data & PHY_100BASETX_m) {
                EMACDuplexSet(emacBase, EMAC_DUPLEX_HALF);
                dummy_wait();
-       } else {
-               while(1)
-                       ;
        }
+       else
+               while (1)
+                       ;
 
        for (chan = 0; chan < 8; chan++) {
                EMACTxHdrDescPtrWrite(emacBase, 0, chan);
@@ -224,17 +219,15 @@ int emac_test(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
        /* TX */
        for (j = 0; j < 8; j++) {
                fr1.pNext = NULL;
-               fr1.pBuffer = (uint8_t*)&efr1;
+               fr1.pBuffer = (uint8_t *)&efr1;
                fr1.BufOffLen = 65;
                fr1.PktFlgLen = (EMAC_DSC_FLAG_SOP | EMAC_DSC_FLAG_EOP | EMAC_DSC_FLAG_OWNER | 65);
 
                EMACTxHdrDescPtrWrite(emacBase, (unsigned int)&fr1, channel);
                rpp_sci_printf("Packet sent\r\n");
-               while(fr1.PktFlgLen == EMAC_DSC_FLAG_OWNER){
-                       if(rpp_sci_read_nb(1, &input) == SUCCESS){
+               while (fr1.PktFlgLen == EMAC_DSC_FLAG_OWNER)
+                       if (rpp_sci_read_nb(1, &input) == SUCCESS)
                                return -1;
-                       }
-               }
                dummy_wait();
                intvect = EMACIntVectorGet(emacBase);
                intvectraw = EMACIntVectorRawGet(emacBase);
@@ -250,10 +243,10 @@ int emac_test(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
 
                for (j = 0; j < 8; j++) {
                        while (!(rx_desc->PktFlgLen & EMAC_DSC_FLAG_SOP))
-                               if(rpp_sci_read_nb(1, &input) == SUCCESS){
+                               if (rpp_sci_read_nb(1, &input) == SUCCESS)
                                        return -1;
-                               }
-                               ;
+
+                       ;
 
                        rpp_sci_printf("Received packet:\r\n");
                        rpp_sci_printf("Length: %d\r\n", rx_desc->PktFlgLen & 0xffff);
@@ -282,24 +275,24 @@ int emac_test(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
        return 0;
 }
 
-#endif /* DOCGEN */
-
-cmd_des_t const cmd_des_test_ethernet={
-    0, 0,
-    "ethernet", "Temporary command to test Ethernet communication",
-    "### Command syntax ###\n"
-    "\n"
-    "    ethernet\n"
-    "\n"
-    "### Description ###\n"
-    "\n"
-    "Command tries to send a few ethernet frames. No real connection or\n"
-    "meaningful packets are sent. This only tests, if Ethernet is just\n"
-    "working.\n",
-    CMD_HANDLER(emac_test), (void *)&cmd_list_emac
+#endif  /* DOCGEN */
+
+cmd_des_t const cmd_des_test_ethernet = {
+       0, 0,
+       "ethernet", "Temporary command to test Ethernet communication",
+       "### Command syntax ###\n"
+       "\n"
+       "    ethernet\n"
+       "\n"
+       "### Description ###\n"
+       "\n"
+       "Command tries to send a few ethernet frames. No real connection or\n"
+       "meaningful packets are sent. This only tests, if Ethernet is just\n"
+       "working.\n",
+       CMD_HANDLER(emac_test), (void *)&cmd_list_emac
 };
 
-cmd_des_t const *cmd_list_emac[]={
-  &cmd_des_test_ethernet,
-  NULL
+cmd_des_t const *cmd_list_emac[] = {
+       &cmd_des_test_ethernet,
+       NULL
 };