]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/mcsdk-tools.git/blob - post/src/gmacsl.c
updated the CCS projects for updated PDK/XDC/BIOS/CGT
[keystone-rtos/mcsdk-tools.git] / post / src / gmacsl.c
1 /******************************************************************************************
2  * FILE PURPOSE: Mac sliver driver
3  ******************************************************************************************
4  * FILE NAME: gmacsl.c
5  *
6  * DESCRIPTION: The cpgmac sliver driver
7  ******************************************************************************************/
8 #include "types.h"
9 #include "platform.h"
10 #include "cpmacdrv.h"
11 #include "gmacsl_loc.h"
12 #include "gmacsl_api.h"
13 #include "target.h"
16 /********************************************************************************************
17  * FUNCTION PURPOSE: Reset the the gmac sliver
18  ********************************************************************************************
19  * DESCRIPTION: Soft reset is set and polled until clear, or until a timeout occurs
20  ********************************************************************************************/
21 int16_t hwGmacSlReset (uint16_t port)
22 {
23     uint32_t i;
24     uint32_t v;
26     if (port >= DEVICE_N_GMACSL_PORTS)
27         return (GMACSL_RET_INVALID_PORT);
29     /* Set the soft reset bit */
30     DEVICE_REG32_W (DEVICE_EMACSL_BASE(port) + CPGMACSL_REG_RESET, CPGMAC_REG_RESET_VAL_RESET);
32     /* Wait for the bit to clear */
33     for (i = 0; i < DEVICE_EMACSL_RESET_POLL_COUNT; i++)  {
35         v = DEVICE_REG32_R (DEVICE_EMACSL_BASE(port) + CPGMACSL_REG_RESET);
36         if ( (v & CPGMAC_REG_RESET_VAL_RESET_MASK) != CPGMAC_REG_RESET_VAL_RESET)
37             return (GMACSL_RET_OK);
39     }
41     /* Timeout on the reset */
42     return (GMACSL_RET_WARN_RESET_INCOMPLETE);
44 } /* hwGmacSlReset */
47 /*******************************************************************************************
48  * FUNCTION PURPOSE: Configure the gmac sliver
49  *******************************************************************************************
50  * DESCRIPTION: The emac sliver is configured.
51  *******************************************************************************************/
52 int16_t hwGmacSlConfig (uint16_t port, hwGmacSlCfg_t *cfg)
53 {
54     uint32_t v;
55     uint32_t i;
56     int16_t ret = GMACSL_RET_OK;
59     if (port >= DEVICE_N_GMACSL_PORTS)
60         return (GMACSL_RET_INVALID_PORT);
62     if (cfg->maxRxLen > CPGMAC_REG_MAXLEN_LEN)  {
63         cfg->maxRxLen = CPGMAC_REG_MAXLEN_LEN;
64         ret = GMACSL_RET_WARN_MAXLEN_TOO_BIG;
65     }
67     /* Must wait if the device is undergoing reset */
68     for (i = 0; i < DEVICE_EMACSL_RESET_POLL_COUNT; i++)  {
70         v = DEVICE_REG32_R (DEVICE_EMACSL_BASE(port) + CPGMACSL_REG_RESET);
71         if ( (v & CPGMAC_REG_RESET_VAL_RESET_MASK) != CPGMAC_REG_RESET_VAL_RESET)
72             break;
74     }
76     if (i == DEVICE_EMACSL_RESET_POLL_COUNT)
77         return (GMACSL_RET_CONFIG_FAIL_RESET_ACTIVE);
82     DEVICE_REG32_W(DEVICE_EMACSL_BASE(port) + CPGMACSL_REG_MAXLEN, cfg->maxRxLen);
84     DEVICE_REG32_W(DEVICE_EMACSL_BASE(port) + CPGMACSL_REG_CTL, cfg->ctl);
86     return (ret);
88 } /* hwGmacSlConfig */
92 int32_t cpmac_drv_start (NET_DRV_DEVICE* ptr_device)
93 {
94     int32_t         i;
95     hwGmacSlCfg_t cfg;
98     cfg.maxRxLen = MAX_SIZE_STREAM_BUFFER;
99     cfg.ctl      = GMACSL_ENABLE | GMACSL_RX_ENABLE_EXT_CTL;
101     if (ptr_device->port_num == (uint32_t)(-2))  {
103         for (i = 0; i < TARGET_EMAC_N_PORTS; i++)  {
104             hwGmacSlReset  (i);
105             hwGmacSlConfig (i, &cfg);
106         }
108     }  else  {
110         hwGmacSlReset (ptr_device->port_num);
111         hwGmacSlConfig (ptr_device->port_num, &cfg);
113     }
115     return (0);
119 int32_t cpmac_drv_send (NET_DRV_DEVICE* ptr_device, uint8_t* buffer, int num_bytes)
121     return (targetMacSend ((void *)ptr_device, buffer, num_bytes));
126 int32_t cpmac_drv_receive (NET_DRV_DEVICE* ptr_device, uint8_t* buffer)
128    return (targetMacRcv ((void *)ptr_device, buffer));
133 int32_t cpmac_drv_stop (NET_DRV_DEVICE* ptr_device)
136     hwGmacSlReset (ptr_device->port_num);
137     return (0);