mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-11-09 20:45:41 +08:00
Merge pull request #827 from caogos/master
[BSP] Add EMAC driver in loongson1C (ported by chinesebear, https://github.com/chinesebear/rtt-net)
This commit is contained in:
commit
b9ebd183ae
17 files changed
+7613
-9
No files matched your search
@@ -16,11 +16,16 @@
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <components.h>
|
||||
#include "net/synopGMAC.h"
|
||||
#include <lwip/api.h>
|
||||
|
||||
void rt_init_thread_entry(void *parameter)
|
||||
{
|
||||
/* initialization RT-Thread Components */
|
||||
rt_components_init();
|
||||
|
||||
// Íø¿ÚEMAC³õʼ»¯
|
||||
rt_hw_eth_init();
|
||||
}
|
||||
|
||||
int rt_application_init(void)
|
||||
|
||||
@@ -7,4 +7,14 @@ CPPPATH = [cwd]
|
||||
|
||||
group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH)
|
||||
|
||||
objs = []
|
||||
list = os.listdir(cwd)
|
||||
|
||||
for d in list:
|
||||
path = os.path.join(cwd, d)
|
||||
if os.path.isfile(os.path.join(path, 'SConscript')):
|
||||
objs = objs + SConscript(os.path.join(d, 'SConscript'))
|
||||
|
||||
group = group + objs
|
||||
|
||||
Return('group')
|
||||
@@ -0,0 +1,11 @@
|
||||
from building import *
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
src = Glob('*.c')
|
||||
|
||||
CPPPATH = [cwd]
|
||||
|
||||
group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH)
|
||||
|
||||
|
||||
Return('group')
|
||||
@@ -0,0 +1,150 @@
|
||||
/*
|
||||
* File : mii.c
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) chinesebear
|
||||
*
|
||||
* 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, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2017-08-24 chinesebear first version
|
||||
*/
|
||||
|
||||
|
||||
#include "mii.h"
|
||||
|
||||
|
||||
static inline unsigned int mii_nway_result (unsigned int negotiated)
|
||||
{
|
||||
unsigned int ret;
|
||||
|
||||
if (negotiated & LPA_100FULL)
|
||||
ret = LPA_100FULL;
|
||||
else if (negotiated & LPA_100BASE4)
|
||||
ret = LPA_100BASE4;
|
||||
else if (negotiated & LPA_100HALF)
|
||||
ret = LPA_100HALF;
|
||||
else if (negotiated & LPA_10FULL)
|
||||
ret = LPA_10FULL;
|
||||
else
|
||||
ret = LPA_10HALF;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int mii_check_gmii_support(struct mii_if_info *mii)
|
||||
{
|
||||
int reg;
|
||||
|
||||
reg = mii->mdio_read(mii->dev, mii->phy_id, MII_BMSR);
|
||||
if (reg & BMSR_ESTATEN) {
|
||||
reg = mii->mdio_read(mii->dev, mii->phy_id, MII_ESTATUS);
|
||||
if (reg & (ESTATUS_1000_TFULL | ESTATUS_1000_THALF))
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int mii_ethtool_gset(struct mii_if_info *mii, struct ethtool_cmd *ecmd)
|
||||
{
|
||||
struct synopGMACNetworkAdapter * dev = mii->dev;
|
||||
u32 advert, bmcr, lpa, nego;
|
||||
u32 advert2 = 0, bmcr2 = 0, lpa2 = 0;
|
||||
|
||||
ecmd->supported =
|
||||
(SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full |
|
||||
SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full |
|
||||
SUPPORTED_Autoneg | SUPPORTED_TP | SUPPORTED_MII);
|
||||
if (mii->supports_gmii)
|
||||
ecmd->supported |= SUPPORTED_1000baseT_Half |
|
||||
SUPPORTED_1000baseT_Full;
|
||||
|
||||
/* only supports twisted-pair */
|
||||
ecmd->port = PORT_MII;
|
||||
|
||||
/* only supports internal transceiver */
|
||||
ecmd->transceiver = XCVR_INTERNAL;
|
||||
|
||||
/* this isn't fully supported at higher layers */
|
||||
ecmd->phy_address = mii->phy_id;
|
||||
|
||||
ecmd->advertising = ADVERTISED_TP | ADVERTISED_MII;
|
||||
advert = mii->mdio_read(dev, mii->phy_id, MII_ADVERTISE);
|
||||
if (mii->supports_gmii)
|
||||
advert2 = mii->mdio_read(dev, mii->phy_id, MII_CTRL1000);
|
||||
|
||||
if (advert & ADVERTISE_10HALF)
|
||||
ecmd->advertising |= ADVERTISED_10baseT_Half;
|
||||
if (advert & ADVERTISE_10FULL)
|
||||
ecmd->advertising |= ADVERTISED_10baseT_Full;
|
||||
if (advert & ADVERTISE_100HALF)
|
||||
ecmd->advertising |= ADVERTISED_100baseT_Half;
|
||||
if (advert & ADVERTISE_100FULL)
|
||||
ecmd->advertising |= ADVERTISED_100baseT_Full;
|
||||
if (advert2 & ADVERTISE_1000HALF)
|
||||
ecmd->advertising |= ADVERTISED_1000baseT_Half;
|
||||
if (advert2 & ADVERTISE_1000FULL)
|
||||
ecmd->advertising |= ADVERTISED_1000baseT_Full;
|
||||
|
||||
bmcr = mii->mdio_read(dev, mii->phy_id, MII_BMCR);
|
||||
lpa = mii->mdio_read(dev, mii->phy_id, MII_LPA);
|
||||
if (mii->supports_gmii) {
|
||||
bmcr2 = mii->mdio_read(dev, mii->phy_id, MII_CTRL1000);
|
||||
lpa2 = mii->mdio_read(dev, mii->phy_id, MII_STAT1000);
|
||||
}
|
||||
if (bmcr & BMCR_ANENABLE) {
|
||||
ecmd->advertising |= ADVERTISED_Autoneg;
|
||||
ecmd->autoneg = AUTONEG_ENABLE;
|
||||
|
||||
nego = mii_nway_result(advert & lpa);
|
||||
if ((bmcr2 & (ADVERTISE_1000HALF | ADVERTISE_1000FULL)) &
|
||||
(lpa2 >> 2))
|
||||
ecmd->speed = SPEED_1000;
|
||||
else if (nego == LPA_100FULL || nego == LPA_100HALF)
|
||||
ecmd->speed = SPEED_100;
|
||||
else
|
||||
ecmd->speed = SPEED_10;
|
||||
if ((lpa2 & LPA_1000FULL) || nego == LPA_100FULL ||
|
||||
nego == LPA_10FULL) {
|
||||
ecmd->duplex = DUPLEX_FULL;
|
||||
mii->full_duplex = 1;
|
||||
} else {
|
||||
ecmd->duplex = DUPLEX_HALF;
|
||||
mii->full_duplex = 0;
|
||||
}
|
||||
} else {
|
||||
ecmd->autoneg = AUTONEG_DISABLE;
|
||||
|
||||
ecmd->speed = ((bmcr & BMCR_SPEED1000 &&
|
||||
(bmcr & BMCR_SPEED100) == 0) ? SPEED_1000 :
|
||||
(bmcr & BMCR_SPEED100) ? SPEED_100 : SPEED_10);
|
||||
ecmd->duplex = (bmcr & BMCR_FULLDPLX) ? DUPLEX_FULL : DUPLEX_HALF;
|
||||
}
|
||||
|
||||
/* ignore maxtxpkt, maxrxpkt for now */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int mii_link_ok (struct mii_if_info *mii)
|
||||
{
|
||||
/* first, a dummy read, needed to latch some MII phys */
|
||||
mii->mdio_read(mii->dev, mii->phy_id, MII_BMSR);
|
||||
if (mii->mdio_read(mii->dev, mii->phy_id, MII_BMSR) & BMSR_LSTATUS)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* File : synopGMAC.h
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) chinesebear
|
||||
*
|
||||
* 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, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2017-08-24 chinesebear first version
|
||||
*/
|
||||
|
||||
#ifndef __SYNOPGMAC__H
|
||||
#define __SYNOPGMAC__H
|
||||
|
||||
#include "synopGMAC_network_interface.h"
|
||||
#include "synopGMAC_Host.h"
|
||||
#include "synopGMAC_Dev.h"
|
||||
#include "synopGMAC_plat.h"
|
||||
#include "mii.h"
|
||||
#include "synopGMAC_types.h"
|
||||
|
||||
void rt_hw_eth_init(void);
|
||||
|
||||
#endif /*__SYNOPGMAC__H*/
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* File : synopGMAC_Host.h
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) chinesebear
|
||||
*
|
||||
* 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, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2017-08-24 chinesebear first version
|
||||
*/
|
||||
|
||||
|
||||
#ifndef SYNOP_GMAC_HOST_H
|
||||
#define SYNOP_GMAC_HOST_H 1
|
||||
|
||||
|
||||
#include "synopGMAC_plat.h"
|
||||
#include "synopGMAC_Dev.h"
|
||||
#include "mii.h"
|
||||
|
||||
|
||||
|
||||
struct net_device_stats
|
||||
{
|
||||
unsigned long rx_packets; /* total packets received */
|
||||
unsigned long tx_packets; /* total packets transmitted */
|
||||
unsigned long rx_bytes; /* total bytes received */
|
||||
unsigned long tx_bytes; /* total bytes transmitted */
|
||||
unsigned long rx_errors; /* bad packets received */
|
||||
unsigned long tx_errors; /* packet transmit problems */
|
||||
unsigned long rx_dropped; /* no space in linux buffers */
|
||||
unsigned long tx_dropped; /* no space available in linux */
|
||||
unsigned long multicast; /* multicast packets received */
|
||||
unsigned long collisions;
|
||||
|
||||
/* detailed rx_errors: */
|
||||
unsigned long rx_length_errors;
|
||||
unsigned long rx_over_errors; /* receiver ring buff overflow */
|
||||
unsigned long rx_crc_errors; /* recved pkt with crc error */
|
||||
unsigned long rx_frame_errors; /* recv'd frame alignment error */
|
||||
unsigned long rx_fifo_errors; /* recv'r fifo overrun */
|
||||
unsigned long rx_missed_errors; /* receiver missed packet */
|
||||
|
||||
/* detailed tx_errors */
|
||||
unsigned long tx_aborted_errors;
|
||||
unsigned long tx_carrier_errors;
|
||||
unsigned long tx_fifo_errors;
|
||||
unsigned long tx_heartbeat_errors;
|
||||
unsigned long tx_window_errors;
|
||||
|
||||
/* for cslip etc */
|
||||
unsigned long rx_compressed;
|
||||
unsigned long tx_compressed;
|
||||
};
|
||||
|
||||
|
||||
|
||||
typedef struct synopGMACNetworkAdapter{
|
||||
|
||||
/*Device Dependent Data structur*/
|
||||
synopGMACdevice * synopGMACdev;
|
||||
|
||||
|
||||
struct net_device_stats synopGMACNetStats;
|
||||
|
||||
|
||||
struct mii_if_info mii;
|
||||
} synopGMACPciNetworkAdapter;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* File : synopGMAC_debug.h
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) chinesebear
|
||||
*
|
||||
* 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, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2017-08-24 chinesebear first version
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __DEBUG_H__
|
||||
#define __DEBUG_H__
|
||||
|
||||
//#define GMAC_DEBUG
|
||||
#include <rtthread.h>
|
||||
#ifdef GMAC_DEBUG
|
||||
#define DEBUG_MES rt_kprintf
|
||||
#else
|
||||
#define DEBUG_MES(...)
|
||||
#endif
|
||||
|
||||
#endif /*__DEBUG_H__*/
|
||||
@@ -0,0 +1,98 @@
|
||||
/** \file
|
||||
* Header file for the nework dependent functionality.
|
||||
* The function prototype listed here are linux dependent.
|
||||
*
|
||||
* \internal
|
||||
* ---------------------------REVISION HISTORY-------------------
|
||||
* Synopsys 01/Aug/2007 Created
|
||||
*/
|
||||
|
||||
/*
|
||||
* File : synopGMAC_network_interface.h
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) chinesebear
|
||||
*
|
||||
* 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, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2017-08-24 chinesebear first version
|
||||
*/
|
||||
|
||||
|
||||
#ifndef SYNOP_GMAC_NETWORK_INTERFACE_H
|
||||
#define SYNOP_GMAC_NETWORK_INTERFACE_H 1
|
||||
|
||||
#include "synopGMAC_plat.h"
|
||||
#include "synopGMAC_Host.h"
|
||||
#include "synopGMAC_Dev.h"
|
||||
|
||||
//#include <common.h>
|
||||
//#include <net.h>
|
||||
//#include <linux/stddef.h>
|
||||
|
||||
|
||||
#define NET_IF_TIMEOUT (10*HZ)
|
||||
#define CHECK_TIME (HZ)
|
||||
|
||||
s32 synopGMAC_init_network_interface(char* xname,u64 synopGMACMappedAddr);
|
||||
void synopGMAC_exit_network_interface(void);
|
||||
|
||||
s32 synopGMAC_linux_open(struct eth_device *);
|
||||
s32 synopGMAC_linux_close(struct eth_device *);
|
||||
//s32 synopGMAC_linux_xmit_frames(struct ifnet *);
|
||||
struct net_device_stats * synopGMAC_linux_get_stats(struct synopGMACNetworkAdapter *);
|
||||
//void synopGMAC_linux_set_multicast_list(struct net_device *);
|
||||
//s32 synopGMAC_linux_set_mac_address(struct synopGMACNetwokrAdapter*,void *);
|
||||
//s32 synopGMAC_linux_change_mtu(struct net_device *,s32);
|
||||
//s32 synopGMAC_linux_do_ioctl(struct ifnet *,struct ifreq *,s32);
|
||||
//void synopGMAC_linux_tx_timeout(struct net_device *);
|
||||
|
||||
s32 synopGMAC_test(synopGMACdevice * gmacdev_0,synopGMACdevice * gmacdev_1);
|
||||
|
||||
void dumpreg(u64 );
|
||||
void dumpphyreg();
|
||||
|
||||
/*
|
||||
* gethex(vp,p,n)
|
||||
* convert n hex digits from p to binary, result in vp,
|
||||
* rtn 1 on success
|
||||
*/
|
||||
static int gethex(u8 *vp, char *p, int n)
|
||||
{
|
||||
u8 v;
|
||||
int digit;
|
||||
|
||||
for (v = 0; n > 0; n--) {
|
||||
if (*p == 0)
|
||||
return (0);
|
||||
if (*p >= '0' && *p <= '9')
|
||||
digit = *p - '0';
|
||||
else if (*p >= 'a' && *p <= 'f')
|
||||
digit = *p - 'a' + 10;
|
||||
else if (*p >= 'A' && *p <= 'F')
|
||||
digit = *p - 'A' + 10;
|
||||
else
|
||||
return (0);
|
||||
|
||||
v <<= 4;
|
||||
v |= digit;
|
||||
p++;
|
||||
}
|
||||
*vp = v;
|
||||
return (1);
|
||||
}
|
||||
|
||||
#endif /* End of file */
|
||||
@@ -0,0 +1,150 @@
|
||||
/**\file
|
||||
* This file defines the wrapper for the platform/OS related functions
|
||||
* The function definitions needs to be modified according to the platform
|
||||
* and the Operating system used.
|
||||
* This file should be handled with greatest care while porting the driver
|
||||
* to a different platform running different operating system other than
|
||||
* Linux 2.6.xx.
|
||||
* \internal
|
||||
* ----------------------------REVISION HISTORY-----------------------------
|
||||
* Synopsys 01/Aug/2007 Created
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* File : synopGMAC_plat.c
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) chinesebear
|
||||
*
|
||||
* 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, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2017-08-24 chinesebear first version
|
||||
*/
|
||||
|
||||
|
||||
#include "synopGMAC_plat.h"
|
||||
#include "synopGMAC_Dev.h"
|
||||
#include <rthw.h>
|
||||
#include <rtthread.h>
|
||||
extern void flush_cache(unsigned long start_addr, unsigned long size);
|
||||
dma_addr_t __attribute__((weak)) gmac_dmamap(unsigned long va,u32 size)
|
||||
{
|
||||
return VA_TO_PA (va);
|
||||
//return UNCACHED_TO_PHYS(va);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This is a wrapper function for Memory allocation routine. In linux Kernel
|
||||
* it it kmalloc function
|
||||
* @param[in] bytes in bytes to allocate
|
||||
*/
|
||||
|
||||
void *plat_alloc_memory(u32 bytes)
|
||||
{
|
||||
//return (void*)malloc((size_t)bytes, M_DEVBUF, M_DONTWAIT);
|
||||
void *buf = (void*)rt_malloc((u32)bytes);
|
||||
|
||||
flush_cache((unsigned long)buf, bytes);
|
||||
return buf;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a wrapper function for consistent dma-able Memory allocation routine.
|
||||
* In linux Kernel, it depends on pci dev structure
|
||||
* @param[in] bytes in bytes to allocate
|
||||
*/
|
||||
|
||||
//void *plat_alloc_consistent_dmaable_memory(struct synopGMACdevice *dev, u32 size, u32 *addr)
|
||||
void *plat_alloc_consistent_dmaable_memory(synopGMACdevice *pcidev, u32 size, u32 *addr)
|
||||
{
|
||||
void *buf;
|
||||
buf = (void*)rt_malloc((u32)(size+16));
|
||||
//CPU_IOFlushDCache( buf,size, SYNC_W);
|
||||
unsigned long i = (unsigned long)buf;
|
||||
// rt_kprintf("size = %d\n", size);
|
||||
// rt_kprintf("bufaddr = %p\n", buf);
|
||||
// rt_kprintf("i%%16 == %d\n", i%16);
|
||||
if(i%16 == 8){
|
||||
i += 8;
|
||||
}
|
||||
else if(i%16 == 4){
|
||||
i += 12;
|
||||
}
|
||||
else if(i%16 == 12){
|
||||
i += 4;
|
||||
}
|
||||
|
||||
flush_cache(i, size);
|
||||
*addr =gmac_dmamap(i, size);
|
||||
buf = (unsigned char *)CACHED_TO_UNCACHED(i);
|
||||
// rt_kprintf("bufaddr = %p\n", buf);
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This is a wrapper function for freeing consistent dma-able Memory.
|
||||
* In linux Kernel, it depends on pci dev structure
|
||||
* @param[in] bytes in bytes to allocate
|
||||
*/
|
||||
|
||||
|
||||
//void plat_free_consistent_dmaable_memory(void * addr)
|
||||
void plat_free_consistent_dmaable_memory(synopGMACdevice *pcidev, u32 size, void * addr,u32 dma_addr)
|
||||
{
|
||||
rt_free((void*)PHYS_TO_CACHED(UNCACHED_TO_PHYS(addr)));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This is a wrapper function for Memory free routine. In linux Kernel
|
||||
* it it kfree function
|
||||
* @param[in] buffer pointer to be freed
|
||||
*/
|
||||
void plat_free_memory(void *buffer)
|
||||
{
|
||||
rt_free(buffer);
|
||||
return ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
dma_addr_t plat_dma_map_single(void *hwdev, void *ptr,
|
||||
u32 size)
|
||||
{
|
||||
unsigned long addr = (unsigned long) ptr;
|
||||
//CPU_IOFlushDCache(addr,size, direction);
|
||||
flush_cache(addr, size);
|
||||
return gmac_dmamap(addr, size);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a wrapper function for platform dependent delay
|
||||
* Take care while passing the argument to this function
|
||||
* @param[in] buffer pointer to be freed
|
||||
*/
|
||||
void plat_delay(u32 delay)
|
||||
{
|
||||
while (delay--);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* File : synopGMAC_types.h
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) chinesebear
|
||||
*
|
||||
* 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, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2017-08-24 chinesebear first version
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef __TYPES__H
|
||||
#define __TYPES__H
|
||||
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned long long u64;
|
||||
typedef unsigned int u32;
|
||||
typedef unsigned short u16;
|
||||
typedef unsigned char u8;
|
||||
typedef signed int s32;
|
||||
|
||||
typedef u32 dma_addr_t;
|
||||
|
||||
#endif /*__TYPES__H*/
|
||||
+16
-9
@@ -131,15 +131,21 @@
|
||||
// <bool name="RT_USING_DFS_NFS" description="Using NFS v3 client file system" default="false" />
|
||||
// #define RT_USING_DFS_NFS
|
||||
// <string name="RT_NFS_HOST_EXPORT" description="NFSv3 host export" default="192.168.1.5:/" />
|
||||
#define RT_NFS_HOST_EXPORT "192.168.3.108:/"
|
||||
#define RT_NFS_HOST_EXPORT "192.168.1.254:/"
|
||||
// </section>
|
||||
|
||||
// <section name="RT_USING_LWIP" description="lwip, a lightweight TCP/IP protocol stack" default="true" >
|
||||
// #define RT_USING_LWIP
|
||||
#define RT_USING_LWIP
|
||||
#define RT_USING_GMAC_INT_MODE
|
||||
#define RT_USING_LWIP141
|
||||
//#define RT_LWIP_DEBUG
|
||||
#define RT_LWIP_USING_RT_MEM
|
||||
|
||||
|
||||
// <bool name="RT_LWIP_ICMP" description="Enable ICMP protocol" default="true" />
|
||||
#define RT_LWIP_ICMP
|
||||
// <bool name="RT_LWIP_IGMP" description="Enable IGMP protocol" default="false" />
|
||||
// #define RT_LWIP_IGMP
|
||||
#define RT_LWIP_IGMP
|
||||
// <bool name="RT_LWIP_UDP" description="Enable UDP protocol" default="true" />
|
||||
#define RT_LWIP_UDP
|
||||
// <bool name="RT_LWIP_TCP" description="Enable TCP protocol" default="true" />
|
||||
@@ -148,10 +154,11 @@
|
||||
#define RT_LWIP_DNS
|
||||
// <integer name="RT_LWIP_PBUF_NUM" description="Maximal number of buffers in the pbuf pool" default="4" />
|
||||
#define RT_LWIP_PBUF_NUM 4
|
||||
#define RT_LWIP_PBUF_POOL_BUFSIZE 2048
|
||||
// <integer name="RT_LWIP_TCP_PCB_NUM" description="Maximal number of simultaneously active TCP connections" default="5" />
|
||||
#define RT_LWIP_TCP_PCB_NUM 3
|
||||
// <integer name="RT_LWIP_TCP_SND_BUF" description="TCP sender buffer size" default="8192" />
|
||||
#define RT_LWIP_TCP_SND_BUF 2048
|
||||
#define RT_LWIP_TCP_SND_BUF 4096
|
||||
// <integer name="RT_LWIP_TCP_WND" description="TCP receive window" default="8192" />
|
||||
#define RT_LWIP_TCP_WND 2048
|
||||
// <bool name="RT_LWIP_SNMP" description="Enable SNMP protocol" default="false" />
|
||||
@@ -159,7 +166,7 @@
|
||||
// <bool name="RT_LWIP_DHCP" description="Enable DHCP client to get IP address" default="false" />
|
||||
// #define RT_LWIP_DHCP
|
||||
// <integer name="RT_LWIP_TCP_SEG_NUM" description="the number of simultaneously queued TCP" default="4" />
|
||||
#define RT_LWIP_TCP_SEG_NUM 4
|
||||
#define RT_LWIP_TCP_SEG_NUM 40
|
||||
// <integer name="RT_LWIP_TCPTHREAD_PRIORITY" description="the thread priority of TCP thread" default="128" />
|
||||
#define RT_LWIP_TCPTHREAD_PRIORITY 12
|
||||
// <integer name="RT_LWIP_TCPTHREAD_MBOX_SIZE" description="the mail box size of TCP thread to wait for" default="32" />
|
||||
@@ -175,13 +182,13 @@
|
||||
// <ipaddr name="RT_LWIP_IPADDR" description="IP address of device" default="192.168.1.30" />
|
||||
#define RT_LWIP_IPADDR0 192
|
||||
#define RT_LWIP_IPADDR1 168
|
||||
#define RT_LWIP_IPADDR2 3
|
||||
#define RT_LWIP_IPADDR3 108
|
||||
#define RT_LWIP_IPADDR2 1
|
||||
#define RT_LWIP_IPADDR3 254
|
||||
// <ipaddr name="RT_LWIP_GWADDR" description="Gateway address of device" default="192.168.1.1" />
|
||||
#define RT_LWIP_GWADDR0 192
|
||||
#define RT_LWIP_GWADDR1 168
|
||||
#define RT_LWIP_GWADDR2 3
|
||||
#define RT_LWIP_GWADDR3 1
|
||||
#define RT_LWIP_GWADDR2 1
|
||||
#define RT_LWIP_GWADDR3 3
|
||||
// <ipaddr name="RT_LWIP_MSKADDR" description="Mask address of device" default="255.255.255.0" />
|
||||
#define RT_LWIP_MSKADDR0 255
|
||||
#define RT_LWIP_MSKADDR1 255
|
||||
|
||||
@@ -121,5 +121,41 @@ rt_uint8_t *rt_hw_stack_init(void *tentry, void *parameter, rt_uint8_t *stack_ad
|
||||
return (rt_uint8_t *)stk;
|
||||
}
|
||||
|
||||
#define cache_op(op,addr) \
|
||||
__asm__ __volatile__( \
|
||||
" .set push \n" \
|
||||
" .set noreorder \n" \
|
||||
" .set mips3\n\t \n" \
|
||||
" cache %0, %1 \n" \
|
||||
" .set pop \n" \
|
||||
: \
|
||||
: "i" (op), "R" (*(unsigned char *)(addr)))
|
||||
|
||||
#if defined(CONFIG_CPU_LOONGSON2)
|
||||
#define Hit_Invalidate_I 0x00
|
||||
#else
|
||||
#define Hit_Invalidate_I 0x10
|
||||
#endif
|
||||
#define Hit_Invalidate_D 0x11
|
||||
#define CONFIG_SYS_CACHELINE_SIZE 32
|
||||
#define Hit_Writeback_Inv_D 0x15
|
||||
|
||||
|
||||
void flush_cache(unsigned long start_addr, unsigned long size)
|
||||
{
|
||||
unsigned long lsize = CONFIG_SYS_CACHELINE_SIZE;
|
||||
unsigned long addr = start_addr & ~(lsize - 1);
|
||||
unsigned long aend = (start_addr + size - 1) & ~(lsize - 1);
|
||||
|
||||
while (1) {
|
||||
cache_op(Hit_Writeback_Inv_D, addr);
|
||||
cache_op(Hit_Invalidate_I, addr);
|
||||
if (addr == aend)
|
||||
break;
|
||||
addr += lsize;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*@}*/
|
||||
|
||||
Reference in new issue
Block a user