]> rtime.felk.cvut.cz Git - rpp-test-sw.git/blobdiff - rpp-test-sw/commands/cmd_emac.c
Change license to MIT
[rpp-test-sw.git] / rpp-test-sw / commands / cmd_emac.c
index f9ae1b7b3a8a7536900c01f8a3aa585c7040c553..210876678cfeaf67aae0ed5a114e45f97edc3680 100644 (file)
@@ -6,18 +6,26 @@
  * 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.
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
  *
  * 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 +75,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 +89,36 @@ 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 */
+/* 
+ * Emac address is used only in this debugging tool. During emac_test is't called rpp_init().
+ * MAC address defined in eth.h have no efect in this test file.
+ */
+uint8_t emacAddress[6]  = {0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc};
+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 +130,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 +138,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 +170,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 +199,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 +240,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 +264,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 +296,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
 };