mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-02-07 09:52:08 +08:00
[bsp][ls1c] add uart3 driver; fix net driver for lwip2.1.0; fix drv_t ouch driver; fix display driver; fix can driver.
This commit is contained in:
@@ -30,6 +30,9 @@ config RT_USING_UART2
|
||||
config RT_USING_UART1
|
||||
bool "Using RT_USING_UART1"
|
||||
default y
|
||||
config RT_USING_UART3
|
||||
bool "Using RT_USING_UART3"
|
||||
default n
|
||||
|
||||
config RT_UART_RX_BUFFER_SIZE
|
||||
int "The rx buffer size"
|
||||
|
||||
@@ -41,8 +41,12 @@ struct vga_struct vga_mode[] =
|
||||
{/*"1440x900_67.00"*/ 120280, 1440, 1528, 1680, 1920, 900, 901, 904, 935, },
|
||||
};
|
||||
|
||||
static volatile int fb_index = 0;
|
||||
|
||||
ALIGN(16)
|
||||
volatile rt_uint16_t _rt_framebuffer[FB_YSIZE][FB_XSIZE];
|
||||
volatile rt_uint16_t _rt_framebuffer0[FB_YSIZE][FB_XSIZE];
|
||||
volatile rt_uint16_t _rt_framebuffer1[FB_YSIZE][FB_XSIZE];
|
||||
static struct rt_device_graphic_info _dc_info;
|
||||
|
||||
static void pwminit(void)
|
||||
@@ -130,13 +134,11 @@ static rt_err_t rt_dc_init(rt_device_t dev)
|
||||
if (mode<0)
|
||||
{
|
||||
rt_kprintf("\n\n\nunsupported framebuffer resolution\n\n\n");
|
||||
return;
|
||||
return RT_ERROR;
|
||||
}
|
||||
|
||||
DC_FB_CONFIG = 0x0;
|
||||
DC_FB_CONFIG = 0x3; // // framebuffer configuration RGB565
|
||||
DC_FB_BUFFER_ADDR0 = (rt_uint32_t)_rt_framebuffer - 0x80000000;
|
||||
DC_FB_BUFFER_ADDR1 = (rt_uint32_t)_rt_framebuffer - 0x80000000;
|
||||
DC_DITHER_CONFIG = 0x0; //颜色抖动配置寄存器
|
||||
DC_DITHER_TABLE_LOW = 0x0; //颜色抖动查找表低位寄存器
|
||||
DC_DITHER_TABLE_HIGH = 0x0; //颜色抖动查找表高位寄存器
|
||||
@@ -175,7 +177,25 @@ static rt_err_t rt_dc_control(rt_device_t dev, int cmd, void *args)
|
||||
switch (cmd)
|
||||
{
|
||||
case RTGRAPHIC_CTRL_RECT_UPDATE:
|
||||
{
|
||||
if (fb_index == 0)
|
||||
{
|
||||
DC_FB_BUFFER_ADDR0 = (rt_uint32_t)_rt_framebuffer1 - 0x80000000;
|
||||
DC_FB_BUFFER_ADDR1 = (rt_uint32_t)_rt_framebuffer1 - 0x80000000;
|
||||
rt_memcpy((void *)_rt_framebuffer1, (const void *)_rt_framebuffer, sizeof(_rt_framebuffer));
|
||||
rt_memcpy((void *)_rt_framebuffer1, (const void *)_rt_framebuffer, sizeof(_rt_framebuffer));
|
||||
fb_index =1;
|
||||
}
|
||||
else
|
||||
{
|
||||
DC_FB_BUFFER_ADDR0 = (rt_uint32_t)_rt_framebuffer0 - 0x80000000;
|
||||
DC_FB_BUFFER_ADDR1 = (rt_uint32_t)_rt_framebuffer0 - 0x80000000;
|
||||
rt_memcpy((void *)_rt_framebuffer0, (const void *)_rt_framebuffer, sizeof(_rt_framebuffer));
|
||||
rt_memcpy((void *)_rt_framebuffer0, (const void *)_rt_framebuffer, sizeof(_rt_framebuffer));
|
||||
fb_index =0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case RTGRAPHIC_CTRL_POWERON:
|
||||
break;
|
||||
case RTGRAPHIC_CTRL_POWEROFF:
|
||||
@@ -200,7 +220,7 @@ void rt_hw_dc_init(void)
|
||||
}
|
||||
|
||||
_dc_info.bits_per_pixel = 16;
|
||||
_dc_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565P;
|
||||
_dc_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565;
|
||||
_dc_info.framebuffer = (rt_uint8_t*)HW_FB_ADDR;
|
||||
_dc_info.width = FB_XSIZE;
|
||||
_dc_info.height = FB_YSIZE;
|
||||
|
||||
@@ -229,10 +229,10 @@ static void bxcan0_hw_init(void)
|
||||
#ifdef USING_BXCAN1
|
||||
static void bxcan1_hw_init(void)
|
||||
{
|
||||
pin_set_purpose(56, PIN_PURPOSE_GPIO);
|
||||
pin_set_purpose(57, PIN_PURPOSE_GPIO);
|
||||
pin_set_remap(56, PIN_REMAP_DEFAULT);
|
||||
pin_set_remap(57, PIN_REMAP_DEFAULT);
|
||||
pin_set_purpose(56, PIN_PURPOSE_OTHER);
|
||||
pin_set_purpose(57, PIN_PURPOSE_OTHER);
|
||||
pin_set_remap(56, PIN_REMAP_THIRD);
|
||||
pin_set_remap(57, PIN_REMAP_THIRD);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -6,34 +6,41 @@
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2018-02-08 Zhangyihong the first version
|
||||
* 2018-10-29 XY
|
||||
* 2019-04-11 sundm75 modify for ls1c300 & RTGUI
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <drivers/pin.h>
|
||||
|
||||
#include <rthw.h>
|
||||
|
||||
#include "drv_touch.h"
|
||||
|
||||
#define TOUCH_I2C_NAME "i2c1"
|
||||
|
||||
#ifndef TOUCH_SAMPLE_HZ
|
||||
#define TOUCH_SAMPLE_HZ (50)
|
||||
#endif
|
||||
|
||||
#ifndef TOUCH_I2C_NAME
|
||||
#error "Please define touch i2c name!"
|
||||
#endif
|
||||
|
||||
#ifdef TINA_USING_TOUCH
|
||||
#if (defined PKG_USING_GUIENGINE) || (defined RT_USING_RTGUI)
|
||||
#include <rtgui/event.h>
|
||||
#include <rtgui/rtgui_server.h>
|
||||
#endif
|
||||
#define BSP_TOUCH_SAMPLE_HZ (50)
|
||||
static rt_list_t driver_list;
|
||||
|
||||
extern void touch_down(void);
|
||||
extern void touch_mo(void);
|
||||
extern void touch_up(void);
|
||||
#if 0
|
||||
#define TPDEBUG rt_kprintf
|
||||
#else
|
||||
#define TPDEBUG(...)
|
||||
#endif
|
||||
|
||||
void rt_touch_drivers_register(touch_drv_t drv)
|
||||
{
|
||||
rt_list_insert_before(&driver_list, &drv->list);
|
||||
}
|
||||
static rt_slist_t _driver_list;
|
||||
static struct rt_i2c_bus_device *i2c_bus = RT_NULL;
|
||||
|
||||
static void post_down_event(rt_uint16_t x, rt_uint16_t y, rt_tick_t ts)
|
||||
static void post_down_event(rt_uint16_t x, rt_uint16_t y, rt_uint32_t id)
|
||||
{
|
||||
#if (defined PKG_USING_GUIENGINE) || (defined RT_USING_RTGUI)
|
||||
rt_err_t result;
|
||||
struct rtgui_event_mouse emouse;
|
||||
|
||||
emouse.parent.sender = RT_NULL;
|
||||
@@ -45,15 +52,28 @@ static void post_down_event(rt_uint16_t x, rt_uint16_t y, rt_tick_t ts)
|
||||
emouse.y = y;
|
||||
#ifdef PKG_USING_GUIENGINE
|
||||
emouse.ts = rt_tick_get();
|
||||
emouse.id = ts;
|
||||
emouse.id = id;
|
||||
#endif
|
||||
|
||||
#ifdef PKG_USING_GUIENGINE
|
||||
do
|
||||
{
|
||||
result = rtgui_server_post_event(&emouse.parent, sizeof(emouse));
|
||||
if (result != RT_EOK)
|
||||
{
|
||||
rt_thread_delay(RT_TICK_PER_SECOND / TOUCH_SAMPLE_HZ);
|
||||
}
|
||||
}
|
||||
while (result != RT_EOK);
|
||||
#else
|
||||
rtgui_server_post_event(&emouse.parent, sizeof(emouse));
|
||||
rt_kprintf("touch down x:%d,y%d,id:%d\r\n", x, y, ts);
|
||||
touch_down();
|
||||
#endif
|
||||
|
||||
TPDEBUG("[TP] touch down [%d, %d]\n", emouse.x, emouse.y);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void post_motion_event(rt_uint16_t x, rt_uint16_t y, rt_tick_t ts)
|
||||
static void post_motion_event(rt_uint16_t x, rt_uint16_t y, rt_uint32_t id)
|
||||
{
|
||||
#if (defined PKG_USING_GUIENGINE) || (defined RT_USING_RTGUI)
|
||||
struct rtgui_event_mouse emouse;
|
||||
@@ -67,17 +87,17 @@ static void post_motion_event(rt_uint16_t x, rt_uint16_t y, rt_tick_t ts)
|
||||
emouse.y = y;
|
||||
#ifdef PKG_USING_GUIENGINE
|
||||
emouse.ts = rt_tick_get();
|
||||
emouse.id = ts;
|
||||
emouse.id = id;
|
||||
#endif
|
||||
rtgui_server_post_event(&emouse.parent, sizeof(emouse));
|
||||
rt_kprintf("touch motion x:%d,y%d,id:%d\r\n", x, y, ts);
|
||||
touch_mo();
|
||||
TPDEBUG("[TP] touch motion [%d, %d]\n", emouse.x, emouse.y);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void post_up_event(rt_uint16_t x, rt_uint16_t y, rt_tick_t ts)
|
||||
static void post_up_event(rt_uint16_t x, rt_uint16_t y, rt_uint32_t id)
|
||||
{
|
||||
#if (defined PKG_USING_GUIENGINE) || (defined RT_USING_RTGUI)
|
||||
rt_err_t result;
|
||||
struct rtgui_event_mouse emouse;
|
||||
|
||||
emouse.parent.sender = RT_NULL;
|
||||
@@ -89,114 +109,162 @@ static void post_up_event(rt_uint16_t x, rt_uint16_t y, rt_tick_t ts)
|
||||
emouse.y = y;
|
||||
#ifdef PKG_USING_GUIENGINE
|
||||
emouse.ts = rt_tick_get();
|
||||
emouse.id = ts;
|
||||
emouse.id = id;
|
||||
#endif
|
||||
|
||||
#ifdef PKG_USING_GUIENGINE
|
||||
do
|
||||
{
|
||||
result = rtgui_server_post_event(&emouse.parent, sizeof(emouse));
|
||||
if (result != RT_EOK)
|
||||
{
|
||||
rt_thread_delay(RT_TICK_PER_SECOND / TOUCH_SAMPLE_HZ);
|
||||
}
|
||||
}
|
||||
while (result != RT_EOK);
|
||||
#else
|
||||
rtgui_server_post_event(&emouse.parent, sizeof(emouse));
|
||||
rt_kprintf("touch up x:%d,y%d,id:%d\r\n", x, y, ts);
|
||||
touch_up();
|
||||
#endif
|
||||
|
||||
TPDEBUG("[TP] touch up [%d, %d]\n", emouse.x, emouse.y);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void touch_thread_entry(void *parameter)
|
||||
static void touch_run(void* parameter)
|
||||
{
|
||||
touch_drv_t touch = (touch_drv_t)parameter;
|
||||
struct touch_message msg;
|
||||
rt_tick_t emouse_id = 0;
|
||||
touch->ops->isr_enable(RT_TRUE);
|
||||
struct touch_message msg;
|
||||
rt_slist_t *driver_list = NULL;
|
||||
struct touch_driver *current_driver = RT_NULL;
|
||||
|
||||
i2c_bus = rt_i2c_bus_device_find(TOUCH_I2C_NAME);
|
||||
RT_ASSERT(i2c_bus);
|
||||
|
||||
if(rt_device_open(&i2c_bus->parent, RT_DEVICE_OFLAG_RDWR) != RT_EOK)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
rt_slist_for_each(driver_list, &_driver_list)
|
||||
{
|
||||
current_driver = (struct touch_driver *)driver_list;
|
||||
if(current_driver->probe(i2c_bus) == RT_TRUE)
|
||||
{
|
||||
break;
|
||||
}
|
||||
current_driver = RT_NULL;
|
||||
}
|
||||
|
||||
if(current_driver == RT_NULL)
|
||||
{
|
||||
rt_kprintf("[TP] No touch pad or driver.\n");
|
||||
rt_device_close((rt_device_t)i2c_bus);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
current_driver->ops->init(i2c_bus);
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (rt_sem_take(current_driver->isr_sem, RT_WAITING_FOREVER) != RT_EOK)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (rt_sem_take(touch->isr_sem, RT_WAITING_FOREVER) != RT_EOK)
|
||||
if (current_driver->ops->read_point(&msg) != RT_EOK)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (touch->ops->read_point(&msg) != RT_EOK)
|
||||
{
|
||||
touch->ops->isr_enable(RT_TRUE);
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (msg.event)
|
||||
{
|
||||
case TOUCH_EVENT_UP:
|
||||
post_up_event(msg.x, msg.y, emouse_id);
|
||||
case TOUCH_EVENT_MOVE:
|
||||
post_motion_event(msg.x, msg.y, emouse_id);
|
||||
break;
|
||||
|
||||
case TOUCH_EVENT_DOWN:
|
||||
emouse_id = rt_tick_get();
|
||||
post_down_event(msg.x, msg.y, emouse_id);
|
||||
break;
|
||||
case TOUCH_EVENT_MOVE:
|
||||
post_motion_event(msg.x, msg.y, emouse_id);
|
||||
|
||||
case TOUCH_EVENT_UP:
|
||||
post_up_event(msg.x, msg.y, emouse_id);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
rt_thread_delay(RT_TICK_PER_SECOND / BSP_TOUCH_SAMPLE_HZ);
|
||||
touch->ops->isr_enable(RT_TRUE);
|
||||
|
||||
rt_thread_delay(RT_TICK_PER_SECOND / TOUCH_SAMPLE_HZ);
|
||||
}
|
||||
}
|
||||
|
||||
int rt_touch_driver_init(void)
|
||||
rt_err_t rt_touch_drivers_register(touch_driver_t drv)
|
||||
{
|
||||
rt_kprintf("\r\n%s \r\n", __FUNCTION__);
|
||||
rt_list_init(&driver_list);
|
||||
return 0;
|
||||
}
|
||||
INIT_BOARD_EXPORT(rt_touch_driver_init);
|
||||
RT_ASSERT(drv != RT_NULL);
|
||||
RT_ASSERT(drv->ops != RT_NULL);
|
||||
RT_ASSERT(drv->probe != RT_NULL);
|
||||
|
||||
static struct rt_i2c_bus_device *i2c_bus = RT_NULL;
|
||||
static int rt_touch_thread_init(void)
|
||||
rt_slist_append(&_driver_list, &drv->list);
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
static int rt_touch_list_init(void)
|
||||
{
|
||||
rt_list_t *l;
|
||||
touch_drv_t current_driver;
|
||||
rt_thread_t tid = RT_NULL;
|
||||
i2c_bus = (struct rt_i2c_bus_device *)rt_device_find("i2c1");
|
||||
RT_ASSERT(i2c_bus);
|
||||
current_driver = RT_NULL;
|
||||
if (rt_device_open((rt_device_t)i2c_bus, RT_DEVICE_OFLAG_RDWR) != RT_EOK)
|
||||
return -1;
|
||||
for (l = driver_list.next; l != &driver_list; l = l->next)
|
||||
{
|
||||
if (rt_list_entry(l, struct touch_drivers, list)->probe(i2c_bus))
|
||||
{
|
||||
current_driver = rt_list_entry(l, struct touch_drivers, list);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (current_driver == RT_NULL)
|
||||
{
|
||||
rt_kprintf("no touch screen or do not have driver\r\n");
|
||||
rt_device_close((rt_device_t)i2c_bus);
|
||||
return -1;
|
||||
}
|
||||
current_driver->ops->init(i2c_bus);
|
||||
rt_kprintf("touch screen found driver\r\n");
|
||||
tid = rt_thread_create("touch", touch_thread_entry, current_driver, 2048, 27, 20);
|
||||
if (tid == RT_NULL)
|
||||
{
|
||||
current_driver->ops->deinit();
|
||||
rt_device_close((rt_device_t)i2c_bus);
|
||||
return -1;
|
||||
}
|
||||
rt_thread_startup(tid);
|
||||
return 0;
|
||||
}
|
||||
rt_slist_init(&_driver_list);
|
||||
|
||||
static void touch_init_thread_entry(void *parameter)
|
||||
return RT_EOK;
|
||||
}
|
||||
INIT_BOARD_EXPORT(rt_touch_list_init);
|
||||
|
||||
static int rt_touch_init(void)
|
||||
{
|
||||
rt_touch_thread_init();
|
||||
}
|
||||
static int touc_bg_init(void)
|
||||
{
|
||||
rt_thread_t tid = RT_NULL;
|
||||
tid = rt_thread_create("touchi", touch_init_thread_entry, RT_NULL, 2048, 28, 20);
|
||||
if (tid == RT_NULL)
|
||||
rt_thread_t thread = RT_NULL;
|
||||
|
||||
thread = rt_thread_create("touch", touch_run, RT_NULL, 2048, 28, 20);
|
||||
if(thread)
|
||||
{
|
||||
return -1;
|
||||
return rt_thread_startup(thread);
|
||||
}
|
||||
rt_thread_startup(tid);
|
||||
return 0;
|
||||
|
||||
return RT_ERROR;
|
||||
}
|
||||
INIT_APP_EXPORT(touc_bg_init);
|
||||
INIT_APP_EXPORT(rt_touch_init);
|
||||
|
||||
int rt_touch_read(rt_uint16_t addr, void *cmd_buf, size_t cmd_len, void *data_buf, size_t data_len)
|
||||
{
|
||||
struct rt_i2c_msg msgs[2];
|
||||
|
||||
msgs[0].addr = addr;
|
||||
msgs[0].flags = RT_I2C_WR;
|
||||
msgs[0].buf = cmd_buf;
|
||||
msgs[0].len = cmd_len;
|
||||
|
||||
msgs[1].addr = addr;
|
||||
msgs[1].flags = RT_I2C_RD;
|
||||
msgs[1].buf = data_buf;
|
||||
msgs[1].len = data_len;
|
||||
|
||||
if (rt_i2c_transfer(i2c_bus, msgs, 2) == 2)
|
||||
return 0;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
int rt_touch_write(rt_uint16_t addr, void *data_buf, size_t data_len)
|
||||
{
|
||||
struct rt_i2c_msg msgs[1];
|
||||
|
||||
msgs[0].addr = addr;
|
||||
msgs[0].flags = RT_I2C_WR;
|
||||
msgs[0].buf = data_buf;
|
||||
msgs[0].len = data_len;
|
||||
|
||||
if (rt_i2c_transfer(i2c_bus, msgs, 1) == 1)
|
||||
return 0;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -6,7 +6,9 @@
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2018-02-08 Zhangyihong the first version
|
||||
* 2018-10-29 XY
|
||||
*/
|
||||
|
||||
#ifndef __DRV_TOUCH_H__
|
||||
#define __DRV_TOUCH_H__
|
||||
|
||||
@@ -24,28 +26,29 @@ struct touch_message
|
||||
rt_uint16_t y;
|
||||
rt_uint8_t event;
|
||||
};
|
||||
typedef struct touch_message *touch_msg_t;
|
||||
typedef struct touch_message *touch_message_t;
|
||||
|
||||
struct touch_ops
|
||||
{
|
||||
void (* isr_enable)(rt_bool_t);
|
||||
rt_err_t (* read_point)(touch_msg_t);
|
||||
void (* init)(struct rt_i2c_bus_device *);
|
||||
void (* deinit)(void);
|
||||
void (*init)(struct rt_i2c_bus_device *);
|
||||
void (*deinit)(void);
|
||||
rt_err_t (*read_point)(touch_message_t);
|
||||
};
|
||||
typedef struct touch_ops *touch_ops_t;
|
||||
|
||||
struct touch_drivers
|
||||
struct touch_driver
|
||||
{
|
||||
rt_list_t list;
|
||||
unsigned char address;
|
||||
rt_slist_t list;
|
||||
rt_bool_t (*probe)(struct rt_i2c_bus_device *i2c_bus);
|
||||
rt_sem_t isr_sem;
|
||||
touch_ops_t ops;
|
||||
void *user_data;
|
||||
void *user_data;
|
||||
};
|
||||
typedef struct touch_drivers *touch_drv_t;
|
||||
typedef struct touch_driver *touch_driver_t;
|
||||
|
||||
extern void rt_touch_drivers_register(touch_drv_t drv);
|
||||
rt_err_t rt_touch_drivers_register(touch_driver_t drv);
|
||||
|
||||
int rt_touch_read(rt_uint16_t addr, void *cmd_buf, size_t cmd_len, void *data_buf, size_t data_len);
|
||||
int rt_touch_write(rt_uint16_t addr, void *data_buf, size_t data_len);
|
||||
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -143,6 +143,15 @@ struct rt_uart_ls1c uart1 =
|
||||
struct rt_serial_device serial1;
|
||||
#endif /* RT_USING_UART1 */
|
||||
|
||||
#if defined(RT_USING_UART3)
|
||||
struct rt_uart_ls1c uart3 =
|
||||
{
|
||||
LS1C_UART3,
|
||||
LS1C_UART3_IRQ,
|
||||
};
|
||||
struct rt_serial_device serial3;
|
||||
#endif /* RT_USING_UART3 */
|
||||
|
||||
void rt_hw_uart_init(void)
|
||||
{
|
||||
struct rt_uart_ls1c *uart;
|
||||
@@ -190,5 +199,26 @@ void rt_hw_uart_init(void)
|
||||
uart);
|
||||
#endif /* RT_USING_UART1 */
|
||||
|
||||
#ifdef RT_USING_UART3
|
||||
uart = &uart3;
|
||||
|
||||
serial3.ops = &ls1c_uart_ops;
|
||||
serial3.config = config;
|
||||
|
||||
pin_set_purpose(0, PIN_PURPOSE_OTHER);
|
||||
pin_set_purpose(1, PIN_PURPOSE_OTHER);
|
||||
pin_set_remap(0, PIN_REMAP_FOURTH);
|
||||
pin_set_remap(1, PIN_REMAP_FOURTH);
|
||||
|
||||
rt_hw_interrupt_install(uart->IRQ, uart_irq_handler, &serial3, "UART3");
|
||||
|
||||
/* register UART1 device */
|
||||
rt_hw_serial_register(&serial3,
|
||||
"uart3",
|
||||
//RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_DMA_RX,
|
||||
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX,
|
||||
uart);
|
||||
#endif /* RT_USING_UART3 */
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -572,47 +572,47 @@ struct pbuf *rt_eth_rx(rt_device_t device)
|
||||
}
|
||||
|
||||
/*Handle the Receive Descriptors*/
|
||||
// do{
|
||||
desc_index = synopGMAC_get_rx_qptr(gmacdev, &status, &dma_addr1, NULL, &data1, &dma_addr2, NULL, &data2);
|
||||
|
||||
if (desc_index >= 0 && data1 != 0)
|
||||
do
|
||||
{
|
||||
DEBUG_MES("Received Data at Rx Descriptor %d for skb 0x%08x whose status is %08x\n", desc_index, dma_addr1, status);
|
||||
desc_index = synopGMAC_get_rx_qptr(gmacdev, &status, &dma_addr1, NULL, &data1, &dma_addr2, NULL, &data2);
|
||||
|
||||
if (synopGMAC_is_rx_desc_valid(status) || SYNOP_PHY_LOOPBACK)
|
||||
if (desc_index >= 0 && data1 != 0)
|
||||
{
|
||||
pbuf = pbuf_alloc(PBUF_LINK, MAX_ETHERNET_PAYLOAD, PBUF_RAM);
|
||||
if (pbuf == 0) rt_kprintf("===error in pbuf_alloc\n");
|
||||
DEBUG_MES("Received Data at Rx Descriptor %d for skb 0x%08x whose status is %08x\n", desc_index, dma_addr1, status);
|
||||
|
||||
if (synopGMAC_is_rx_desc_valid(status) || SYNOP_PHY_LOOPBACK)
|
||||
{
|
||||
pbuf = pbuf_alloc(PBUF_LINK, MAX_ETHERNET_PAYLOAD, PBUF_RAM);
|
||||
if (pbuf == 0) rt_kprintf("===error in pbuf_alloc\n");
|
||||
|
||||
|
||||
dma_addr1 = plat_dma_map_single(gmacdev, (void *)data1, RX_BUF_SIZE);
|
||||
len = synopGMAC_get_rx_desc_frame_length(status); //Not interested in Ethernet CRC bytes
|
||||
rt_memcpy(pbuf->payload, (char *)data1, len);
|
||||
DEBUG_MES("==get pkg len: %d\n", len);
|
||||
dma_addr1 = plat_dma_map_single(gmacdev, (void *)data1, RX_BUF_SIZE);
|
||||
len = synopGMAC_get_rx_desc_frame_length(status); //Not interested in Ethernet CRC bytes
|
||||
rt_memcpy(pbuf->payload, (char *)data1, len);
|
||||
DEBUG_MES("==get pkg len: %d\n", len);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_kprintf("s: %08x\n", status);
|
||||
adapter->synopGMACNetStats.rx_errors++;
|
||||
adapter->synopGMACNetStats.collisions += synopGMAC_is_rx_frame_collision(status);
|
||||
adapter->synopGMACNetStats.rx_crc_errors += synopGMAC_is_rx_crc(status);
|
||||
adapter->synopGMACNetStats.rx_frame_errors += synopGMAC_is_frame_dribbling_errors(status);
|
||||
adapter->synopGMACNetStats.rx_length_errors += synopGMAC_is_rx_frame_length_errors(status);
|
||||
}
|
||||
|
||||
desc_index = synopGMAC_set_rx_qptr(gmacdev, dma_addr1, RX_BUF_SIZE, (u32)data1, 0, 0, 0);
|
||||
|
||||
if (desc_index < 0)
|
||||
{
|
||||
#if SYNOP_RX_DEBUG
|
||||
rt_kprintf("Cannot set Rx Descriptor for data1 %08x\n", (u32)data1);
|
||||
#endif
|
||||
plat_free_memory((void *)data1);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_kprintf("s: %08x\n", status);
|
||||
adapter->synopGMACNetStats.rx_errors++;
|
||||
adapter->synopGMACNetStats.collisions += synopGMAC_is_rx_frame_collision(status);
|
||||
adapter->synopGMACNetStats.rx_crc_errors += synopGMAC_is_rx_crc(status);
|
||||
adapter->synopGMACNetStats.rx_frame_errors += synopGMAC_is_frame_dribbling_errors(status);
|
||||
adapter->synopGMACNetStats.rx_length_errors += synopGMAC_is_rx_frame_length_errors(status);
|
||||
}
|
||||
|
||||
desc_index = synopGMAC_set_rx_qptr(gmacdev, dma_addr1, RX_BUF_SIZE, (u32)data1, 0, 0, 0);
|
||||
|
||||
if (desc_index < 0)
|
||||
{
|
||||
#if SYNOP_RX_DEBUG
|
||||
rt_kprintf("Cannot set Rx Descriptor for data1 %08x\n", (u32)data1);
|
||||
#endif
|
||||
plat_free_memory((void *)data1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// }while(desc_index >= 0);
|
||||
}while(desc_index >= 0);
|
||||
rt_sem_release(&sem_lock);
|
||||
DEBUG_MES("%s : before return \n", __FUNCTION__);
|
||||
return pbuf;
|
||||
@@ -965,6 +965,8 @@ int rt_hw_eth_init(void)
|
||||
|
||||
eth_device_init(&(eth_dev.parent), "e0");
|
||||
|
||||
eth_device_linkchange(ð_dev.parent, RT_TRUE); //linkup the e0 for lwip to check
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user