修改驱动程序

This commit is contained in:
2584532475@qq.com committed 2023-05-19 18:02:00 +08:00
1 parent 063c3fcc07
commit a69c1a58d6
39 files changed
+1627 -641

No files matched your search

+67 -18
View File
@@ -6,12 +6,42 @@
#include <stdio.h>
#include <rtthread.h>
#include <net-app.h>
#include <easyflash.h>
#include <string.h>
#include "usart-board.h"
ALIGN(RT_ALIGN_SIZE)
static char thread_stack[4096];
static struct rt_thread netapp_thread;
static rt_event_t gnetEvents;
#define EVENT_COMM_TX (1U << 0)
#define EVENT_COMM_RX (1U << 1) //
// case ssKHYSet:
// {
// vv = value*10;
// dbg_printf ("MbusSetValue vv:%d\r\n",vv);
// sendcmd[type][4] = ((vv >> 8) & 0xff);
// sendcmd[type][5] = (vv & 0xff);
// vv = bsp_crc_calc16((uint8_t *)sendcmd[type],6);
// sendcmd[type][7] = ((vv >> 8) & 0xff);
// sendcmd[type][6] = (vv & 0xff);
// for(int i = 0;i < 8;i++)
// {
// dbg_printf("%02X ",sendcmd[type][i]);
// }
// dbg_printf("\r\n");
// }
// {0x01, 0x03, 0x00, 0x00, 0x00, 0x06, 0xC5, 0xC8}, // 闸位计读取开度
// {0x01, 0x06, 0x00, 0x07, 0x00, 0x02, 0xE6, 0x69}, // 闸位计设置开度
// {0x01, 0x06, 0x00, 0x04, 0x01, 0x00, 0xC9, 0x9B}, // 启动闸位计
// {0x01, 0x06, 0x00, 0x04, 0x00, 0x00, 0xC8, 0x0B}, // 停止闸位计
static enum {
netDrvInit = 0, // 初始化网络驱动
@@ -22,45 +52,62 @@ static enum {
}eDrvStatus;
static netWorkInterface_t interface;
static void net_send_frame(void)
{
rt_event_send(gnetEvents,EVENT_COMM_TX) ;
}
// 网络链接成功
static void net_connected(void)
{
}
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) ;
// 读取网络驱动类型
char * drv = ef_get_env ("net_drv"); // 读取网络类型
if(strcmp("dtu",drv) == 0) // 驱动程序位DTU模式,就是不通过本地配置,直接透传
{
DTUThreadStart();
// 初始化串口驱动
// interface.Init = NULL;
// interface.IsConnected = NULL;
// interface.IsIdle = NULL;
// interface.IsReady = NULL;
// interface.ReadData = NULL;
// interface.ReSubTopic = NULL;
// interface.WriteData = NULL;
}
// 注册网络驱动
// 注册网络驱动
while (1)
{
switch (eDrvStatus)
// 发送数据
if( RT_EOK == rt_event_recv( gnetEvents, EVENT_COMM_TX,RT_EVENT_FLAG_AND | RT_EVENT_FLAG_CLEAR, RT_WAITING_NO, RT_NULL ))
{
case netDrvInit:
break;
case netDrvJoin:
break;
case netDrvSend:
break;
case netDrvRecv:
break;
case netDrvIdle:
break;
default :
break;
}
rt_thread_delay(10);
if ( RT_EOK == rt_event_recv( gnetEvents, EVENT_COMM_RX,RT_EVENT_FLAG_AND | RT_EVENT_FLAG_CLEAR, RT_WAITING_NO, RT_NULL ))
{
}
rt_thread_delay(10);
}
}
void NET_APPThreadStart(void )
{
/* 创建线程1,名称是thread1,入口是thread1_entry*/
/* 创建线程1,名称是thread1,入口是thread1_entry*/
rt_thread_init(&netapp_thread, "netapp_thread",
thread_entry, RT_NULL,
&thread_stack[0],
sizeof(thread_stack),
NET_APP_THREAD_PRIORITY, NET_APP_THREAD_TIMESLICE);
rt_thread_startup(&netapp_thread);
return ;
@@ -75,3 +122,5 @@ void NET_APPThreadStart(void )