/*
* Copyright (C) 2020-2021 Suzhou Tiancheng Software Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*/
/*
* ls1x_gmac.c
*
* Loongson1x GMAC driver
* GMAC work with MII, support 10/100M, fullduplex/halfduplex mode.
*
* created: 2013/07/01
* author: Bian
*
*/
#include "bsp.h"
#if defined(BSP_USE_GMAC0) || defined(BSP_USE_GMAC1)
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#if defined(LS1B)
#include "ls1b.h"
#include "ls1b_irq.h"
#elif defined(LS1C)
#include "ls1c.h"
#include "ls1c_irq.h"
#else
#error "No Loongson1x SoC defined!"
#endif
#if defined(OS_RTTHREAD)
#include "rtthread.h"
#elif defined(OS_UCOS)
#include "os.h"
#elif defined(OS_FREERTOS)
#include "FreeRTOS.h"
#include "event_groups.h"
#endif
#include "cpu.h"
#include "mii.h"
#include "ls1x_io.h"
#include "drv_os_priority.h"
#include "ls1x_gmac_hw.h"
#include "ls1x_gmac.h"
//***************************************************************************************
#define GMAC_DEBUG 0 // 调试
#define GMAC_TRACE_INFO 1 // print some message
//***************************************************************************************
#define LS1x_K0_CACHED 1
#ifdef LS1x_K0_CACHED
#define VA_TO_PHYS(x) K1_TO_PHYS(x)
#else
#define VA_TO_PHYS(x) K0_TO_PHYS(x)
#endif
#define GMAC_BUF_CACHED 1 // buffer cached
#ifndef ETHER_MAX_LEN
#define ETHER_MAX_LEN 1518 // should defined by tcp/ip stack
#endif
#define MAX_BUF_SIZE 1536 // 48*32, reference by ETHER_MAX_LEN=1518
#define DMA_DESC_SIZE 32
#define NUM_TX_DMA_DESC 4 // TX 描述符个数, 和 TX 缓冲区个数一致
#define NUM_RX_DMA_DESC 4 // RX 描述符个数, 和 RX 缓冲区个数一致
#define TX_BUF_SIZE MAX_BUF_SIZE // TX 缓冲区大小
#define RX_BUF_SIZE MAX_BUF_SIZE // RX 缓冲区大小
#define MII_WR_TIMEOUT 0x0200 // mii write timeout
#define MII_RD_TIMEOUT 0x0200 // mii read timeout
#define GDMA_RESET_TIMEOUT 0x0200 // gdma reset timeout
//***************************************************************************************
// Hardware-specific storage, 驱动专用硬件相关的控制结构
//***************************************************************************************
typedef struct
{
LS1x_gmac_regs_t *hwGMAC; /* GMAC Hardware */
LS1x_gdma_regs_t *hwGDMA;
unsigned int phyAddr; /* PHY Address */
unsigned int gmacVersion; /* 设备版本号 */
unsigned int vector; /* GMAC Interrupt Registers */
unsigned int int_ctrlr;
unsigned int int_mask;
int unitNumber; /* 设备号 */
int acceptBroadcast; /* Indicates configuration */
int autoNegotiation; /* 是否自动协商 */
int autoNegoTimeout; /* 自动协商超时 ms */
unsigned int LinkState; /* Link status as reported by the Phy */
unsigned int DuplexMode; /* Duplex mode of the Phy */
unsigned int Speed; /* Speed of the Phy */
unsigned int descmode; /* DMA Desc Mode chain or ring */
LS1x_rxdesc_t *rx_desc[NUM_RX_DMA_DESC]; /* RX 描述符指针数组 */
LS1x_txdesc_t *tx_desc[NUM_TX_DMA_DESC]; /* TX 描述符指针数组 */
int rx_head;
int rx_tail;
int tx_head;
int tx_tail;
unsigned char *rx_buf[NUM_RX_DMA_DESC]; /* RX 缓冲区指针数组 */
unsigned char *tx_buf[NUM_TX_DMA_DESC]; /* TX 缓冲区指针数组 */
#if defined(OS_RTTHREAD)
rt_event_t gmac_event;
#elif defined(OS_UCOS)
OS_FLAG_GRP *gmac_event;
#elif defined(OS_FREERTOS)
EventGroupHandle_t gmac_event;
#endif
unsigned int interrupts; /* Statistics 统计数 */
unsigned int dma_normal_intrs;
unsigned int dma_abnormal_intrs;
unsigned int dma_fatal_err;
unsigned int rx_interrupts;
unsigned int tx_interrupts;
unsigned int rx_pkts;
unsigned int rx_buffer_unavailable;
unsigned int rx_stopped;
unsigned int rx_errors;
unsigned int rx_length_err;
unsigned int rx_dribit_err;
unsigned int rx_dropped;
unsigned int tx_pkts;
unsigned int tx_buffer_unavailable;
unsigned int tx_stopped;
unsigned int tx_errors;
unsigned int tx_ipheader_err;
unsigned int tx_playload_err;
unsigned int tx_defered;
unsigned int tx_collsions;
unsigned int tx_underflow;
int timeout; /* 收发超时 */
int initialized; /* 是否初始化 */
int started; /* 是否启动 */
char dev_name[16]; /* 设备名称 */
} GMAC_t;
//***************************************************************************************
// ls1x gmac device and buffer
//***************************************************************************************
#define __ALIGN(x) __attribute__((aligned(x)))
#if defined(BSP_USE_GMAC0)
static GMAC_t ls1x_GMAC0 =
{
#if defined(LS1B)
.hwGMAC = (LS1x_gmac_regs_t *)LS1B_GMAC0_BASE,
.hwGDMA = (LS1x_gdma_regs_t *)LS1x_GDMA0_BASE,
.int_ctrlr = LS1B_INTC1_BASE,
.int_mask = INTC1_GMAC0_BIT,
.vector = LS1B_GMAC0_IRQ,
#elif defined(LS1C)
.hwGMAC = (LS1x_gmac_regs_t *)LS1C_MAC_BASE,
.hwGDMA = (LS1x_gdma_regs_t *)LS1x_GDMA0_BASE,
.int_ctrlr = LS1C_INTC1_BASE,
.int_mask = INTC1_MAC_BIT,
.vector = LS1C_MAC_IRQ,
#endif
.unitNumber = 0,
.descmode = CHAINMODE, // XXX This is important
.timeout = 0,
.started = 0,
.initialized = 0,
.dev_name = "gmac0",
.acceptBroadcast = 0,
.autoNegotiation = 1,
.autoNegoTimeout = 3000,
};
void *devGMAC0 = (void *)&ls1x_GMAC0;
static unsigned char tx_desc_0[(NUM_TX_DMA_DESC*DMA_DESC_SIZE)] __ALIGN(32);
static unsigned char rx_desc_0[(NUM_RX_DMA_DESC*DMA_DESC_SIZE)] __ALIGN(32);
static unsigned char tx_buf_0[(NUM_TX_DMA_DESC*TX_BUF_SIZE)] __ALIGN(32);
static unsigned char rx_buf_0[(NUM_RX_DMA_DESC*RX_BUF_SIZE)] __ALIGN(32);
#endif
#if defined(BSP_USE_GMAC1)
static GMAC_t ls1x_GMAC1 =
{
.hwGMAC = (LS1x_gmac_regs_t *)LS1B_GMAC1_BASE,
.hwGDMA = (LS1x_gdma_regs_t *)LS1B_GDMA1_BASE,
.int_ctrlr = LS1B_INTC1_BASE,
.int_mask = INTC1_GMAC1_BIT,
.vector = LS1B_GMAC1_IRQ,
.unitNumber = 1,
.descmode = CHAINMODE, // XXX This is important
.timeout = 0,
.started = 0,
.initialized = 0,
.dev_name = "gmac1",
.acceptBroadcast = 0,
.autoNegotiation = 1,
.autoNegoTimeout = 3000,
};
void *devGMAC1 = (void *)&ls1x_GMAC1;
static unsigned char tx_desc_1[(NUM_TX_DMA_DESC*DMA_DESC_SIZE)] __ALIGN(32);
static unsigned char rx_desc_1[(NUM_RX_DMA_DESC*DMA_DESC_SIZE)] __ALIGN(32);
static unsigned char tx_buf_1[(NUM_TX_DMA_DESC*TX_BUF_SIZE)] __ALIGN(32);
static unsigned char rx_buf_1[(NUM_RX_DMA_DESC*RX_BUF_SIZE)] __ALIGN(32);
#endif
//***************************************************************************************
// function prototypes
//***************************************************************************************
static int LS1x_init_tx_desc_queue(GMAC_t *pMAC);
static int LS1x_init_rx_desc_queue(GMAC_t *pMAC);
static void LS1x_GMAC_init_hw(GMAC_t *pMAC, unsigned char *macAddr);
static void LS1x_GMAC_irq_handler(int vector, void *arg);
static void LS1x_GMAC_do_reset(GMAC_t *pMAC);
//***************************************************************************************
// functions for gdma desc
//***************************************************************************************
static inline void GDMA_INIT_RXDESC(GMAC_t *pMAC)
{
LS1x_init_rx_desc_queue(pMAC);
pMAC->rx_head = 0;
pMAC->rx_tail = 0;
}
static inline void GDMA_INIT_TXDESC(GMAC_t *p
没有合适的资源?快使用搜索试试~ 我知道了~
龙芯ls1b-pwm-Led
共366个文件
d:87个
o:87个
c:82个
0 下载量 5 浏览量
2024-01-19
16:13:21
上传
评论
收藏 861KB ZIP 举报
温馨提示
龙芯ls1b-pwm-Led
资源推荐
资源详情
资源评论
收起资源包目录
龙芯ls1b-pwm-Led (366个子文件)
ls1b_PWM_LED.bin 83KB
ls1x_gmac.c 60KB
lwmem.c 43KB
ls1x_ac97.c 42KB
ls1x_can.c 37KB
ns16550.c 36KB
printf.c 35KB
ls1x_fb_utils.c 30KB
ls1x_nand.c 26KB
ls1x_rtc.c 25KB
w25x40.c 23KB
ls1x_fb.c 22KB
touch_utils.c 22KB
font_desc.c 20KB
ls1x_pwm.c 16KB
rx8010.c 13KB
ls1x_spi_bus.c 13KB
ads1015.c 12KB
sscanf.c 11KB
gt1151.c 11KB
strerror.c 11KB
ls1x_i2c_bus.c 10KB
pca9557.c 9KB
xpt2046.c 8KB
mcp4725.c 8KB
strftime.c 7KB
strtod.c 6KB
irq.c 6KB
ls1x_drv_init.c 6KB
tm_utils.c 6KB
ls1x_gpio.c 5KB
mktime.c 5KB
localtime.c 4KB
qsort.c 3KB
gmtime.c 3KB
ls1x_watchdog.c 3KB
tick.c 3KB
exception.c 3KB
strtol.c 3KB
gp7101.c 2KB
install_3th_libraries.c 2KB
main.c 2KB
strtoul.c 2KB
console.c 1KB
ctype.c 1KB
bsp_start.c 1KB
aligned_malloc.c 1KB
pwm.c 1KB
key.c 973B
print_hex.c 651B
led.c 611B
aligned_malloc.c 581B
memmove.c 532B
fls.c 505B
touch.c 503B
strncasecmp.c 491B
strcasecmp.c 474B
time.c 451B
putchar.c 421B
strncpy.c 369B
memcmp.c 365B
strncmp.c 350B
memchr.c 339B
div.c 329B
strncat.c 288B
strchr.c 283B
strdup.c 259B
memcpy.c 256B
strcmp.c 245B
inittlb.c 241B
strcat.c 222B
calloc.c 211B
realloc.c 207B
strnlen.c 203B
malloc.c 188B
strlen.c 184B
memset.c 181B
strcpy.c 179B
free.c 171B
aligned_free.c 144B
atoi.c 117B
errno.c 116B
atol.c 102B
ns16550.d 711B
ls1x_pwm.d 625B
console.d 624B
pwm.d 479B
main.d 470B
ls1x_drv_init.d 452B
ls1x_gpio.d 395B
key.d 361B
bsp_start.d 346B
tick.d 331B
led.d 277B
irq_s.d 274B
mips_timer.d 243B
irq.d 236B
start.d 224B
cache.d 224B
tlb.d 218B
共 366 条
- 1
- 2
- 3
- 4
资源评论
海绵宝宝爱喝奶茶
- 粉丝: 79
- 资源: 17
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功