102 lines
1.9 KiB
C
102 lines
1.9 KiB
C
|
||
#include "main.h"
|
||
|
||
#include "os-app.h"
|
||
|
||
#include <stdio.h>
|
||
#include <rtthread.h>
|
||
#include <string.h>
|
||
#include "usart-board.h"
|
||
|
||
|
||
|
||
#if !defined(LOG_TAG)
|
||
#define LOG_TAG "dtu"
|
||
#endif
|
||
#include <elog.h>
|
||
|
||
ALIGN (RT_ALIGN_SIZE)
|
||
static char thread_stack[2048];
|
||
static struct rt_thread dtu_thread;
|
||
|
||
static struct
|
||
{
|
||
uint32_t isConnected; // 连接成功
|
||
|
||
} g_dtuDrv ;
|
||
|
||
|
||
|
||
static enum
|
||
{
|
||
netDrvInit = 0, // 初始化网络驱动
|
||
netDrvJoin = 1, // 等待网络注册成功
|
||
netDrvSend = 2, // 发送数据
|
||
netDrvRecv = 3, // 读取数据
|
||
netDrvIdle = 4, // 读取数据
|
||
} eDrvStatus;
|
||
|
||
|
||
|
||
static void net_data_rxdone(void)
|
||
{
|
||
rt_event_send(gUartEvents,EVENT_UART_ETH1_RX);
|
||
//rt_kprintf("net_data_rxdone\r\n");
|
||
}
|
||
|
||
|
||
static void thread_entry (void * argument)
|
||
{
|
||
// eDrvStatus = netDrvInit;
|
||
rt_kprintf ("%s was start!\r\n", __FILE__);
|
||
// gnetEvents = rt_event_create("gnetEvents", RT_IPC_FLAG_FIFO) ;
|
||
|
||
/*Configure GPIO pin Output Level */
|
||
|
||
HAL_GPIO_WritePin(ETH_RST_GPIO_Port, ETH_RST_Pin, GPIO_PIN_SET);
|
||
HAL_GPIO_WritePin(ETH_PW_GPIO_Port, ETH_PW_Pin, GPIO_PIN_SET);
|
||
g_ETH1Drv.rxdone = net_data_rxdone;
|
||
MX_UART_Init(&g_ETH1Drv);
|
||
|
||
// // 注册网络驱动
|
||
// 注册网络驱动
|
||
while (1)
|
||
{
|
||
//MX_UART_PutBuffer(&g_ETH1Drv,"20140524",8);
|
||
if( RT_EOK == rt_event_recv( gUartEvents, EVENT_UART_ETH1_RX,RT_EVENT_FLAG_AND | RT_EVENT_FLAG_CLEAR, RT_WAITING_NO, RT_NULL ))
|
||
{
|
||
rt_kprintf("<<<<<<<<<<<<<<<<<<<<rx1:\r\n");
|
||
for(int i =0; i < g_ETH1Drv.rx_size;i++)
|
||
{
|
||
rt_kprintf("%02X ",g_ETH1Drv.rx_buffer[i]);
|
||
}
|
||
rt_kprintf("\r\n");
|
||
MX_UART_Clear(&g_ETH1Drv);
|
||
}
|
||
|
||
|
||
rt_thread_delay (100);
|
||
}
|
||
}
|
||
|
||
void DTUThreadStart (void)
|
||
{
|
||
/* 创建线程1,名称是thread1,入口是thread1_entry*/
|
||
rt_thread_init (&dtu_thread, "dtu_thread",
|
||
thread_entry, RT_NULL,
|
||
&thread_stack[0],
|
||
sizeof (thread_stack),
|
||
DTU_THREAD_PRIORITY, DTU_THREAD_TIMESLICE);
|
||
rt_thread_startup (&dtu_thread);
|
||
|
||
return ;
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|