forked from xuos/xiuos
Merge branch 'prepare_for_master' of https://git.trustie.net/xuos/xiuos into ch438
This commit is contained in:
commit
14a198fe5a
|
@ -0,0 +1,21 @@
|
||||||
|
import os
|
||||||
|
Import('RTT_ROOT')
|
||||||
|
Import('rtconfig')
|
||||||
|
from building import *
|
||||||
|
|
||||||
|
cwd = GetCurrentDir()
|
||||||
|
SOURCES = []
|
||||||
|
if GetDepend(['SUPPORT_CONNECTION_FRAMEWORK']):
|
||||||
|
SOURCES = ['adapter.c'] +['adapter_agent.c']+ SOURCES
|
||||||
|
path = [cwd]
|
||||||
|
objs = []
|
||||||
|
group = DefineGroup('connection', SOURCES, depend = [], CPPPATH = [cwd])
|
||||||
|
objs = objs + group
|
||||||
|
list = os.listdir(cwd)
|
||||||
|
if GetDepend(['SUPPORT_CONNECTION_FRAMEWORK']):
|
||||||
|
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(path, 'SConscript'))
|
||||||
|
|
||||||
|
Return('objs')
|
|
@ -21,9 +21,11 @@
|
||||||
#include <adapter.h>
|
#include <adapter.h>
|
||||||
|
|
||||||
static DoublelistType adapter_list;
|
static DoublelistType adapter_list;
|
||||||
|
#ifdef ADD_XIZI_FETURES
|
||||||
static int adapter_list_lock;
|
static int adapter_list_lock;
|
||||||
|
#else
|
||||||
|
static pthread_mutex_t adapter_list_lock;
|
||||||
|
#endif
|
||||||
/**
|
/**
|
||||||
* @description: Init adapter framework
|
* @description: Init adapter framework
|
||||||
* @return 0
|
* @return 0
|
||||||
|
@ -481,6 +483,7 @@ int AdapterDeviceDisconnect(struct Adapter *adapter, unsigned char *priv_net_gro
|
||||||
*/
|
*/
|
||||||
int AdapterDeviceSetUp(struct Adapter *adapter)
|
int AdapterDeviceSetUp(struct Adapter *adapter)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!adapter)
|
if (!adapter)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
@ -488,10 +491,10 @@ int AdapterDeviceSetUp(struct Adapter *adapter)
|
||||||
|
|
||||||
struct IpProtocolDone *ip_done = NULL;
|
struct IpProtocolDone *ip_done = NULL;
|
||||||
struct PrivProtocolDone *priv_done = NULL;
|
struct PrivProtocolDone *priv_done = NULL;
|
||||||
|
|
||||||
switch (adapter->net_protocol)
|
switch (adapter->net_protocol)
|
||||||
{
|
{
|
||||||
case PRIVATE_PROTOCOL:
|
case PRIVATE_PROTOCOL:
|
||||||
|
|
||||||
priv_done = (struct PrivProtocolDone *)adapter->done;
|
priv_done = (struct PrivProtocolDone *)adapter->done;
|
||||||
if (NULL == priv_done->setup)
|
if (NULL == priv_done->setup)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -515,6 +518,7 @@ int AdapterDeviceSetUp(struct Adapter *adapter)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
result = ip_done->setup(adapter);
|
result = ip_done->setup(adapter);
|
||||||
|
|
||||||
if (0 == result) {
|
if (0 == result) {
|
||||||
printf("Device %s setup success.\n", adapter->name);
|
printf("Device %s setup success.\n", adapter->name);
|
||||||
adapter->adapter_status = INSTALL;
|
adapter->adapter_status = INSTALL;
|
||||||
|
|
|
@ -29,7 +29,9 @@
|
||||||
#ifdef ADD_XIZI_FETURES
|
#ifdef ADD_XIZI_FETURES
|
||||||
# include <user_api.h>
|
# include <user_api.h>
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef ADD_RTTHREAD_FETURES
|
||||||
|
#include <rtthread.h>
|
||||||
|
#endif
|
||||||
#define AT_CMD_MAX_LEN 128
|
#define AT_CMD_MAX_LEN 128
|
||||||
#define AT_AGENT_MAX 2
|
#define AT_AGENT_MAX 2
|
||||||
static char send_buf[AT_CMD_MAX_LEN];
|
static char send_buf[AT_CMD_MAX_LEN];
|
||||||
|
@ -139,7 +141,7 @@ int ATOrderSend(ATAgentType agent, uint32_t timeout_s, ATReplyType reply, const
|
||||||
|
|
||||||
PrivMutexObtain(&agent->lock);
|
PrivMutexObtain(&agent->lock);
|
||||||
agent->receive_mode = AT_MODE;
|
agent->receive_mode = AT_MODE;
|
||||||
|
|
||||||
memset(agent->maintain_buffer, 0x00, agent->maintain_max);
|
memset(agent->maintain_buffer, 0x00, agent->maintain_max);
|
||||||
agent->maintain_len = 0;
|
agent->maintain_len = 0;
|
||||||
|
|
||||||
|
@ -300,7 +302,7 @@ int EntmRecv(ATAgentType agent, char *rev_buffer, int buffer_len, int timeout_s)
|
||||||
//PrivTaskDelay(1000);
|
//PrivTaskDelay(1000);
|
||||||
if (PrivSemaphoreObtainWait(&agent->entm_rx_notice, &abstime)) {
|
if (PrivSemaphoreObtainWait(&agent->entm_rx_notice, &abstime)) {
|
||||||
printf("wait sem[%d] timeout\n",agent->entm_rx_notice);
|
printf("wait sem[%d] timeout\n",agent->entm_rx_notice);
|
||||||
return -ERROR;
|
return -1;
|
||||||
}
|
}
|
||||||
PrivMutexObtain(&agent->lock);
|
PrivMutexObtain(&agent->lock);
|
||||||
|
|
||||||
|
@ -390,7 +392,7 @@ static int GetCompleteATReply(ATAgentType agent)
|
||||||
memset(agent->maintain_buffer, 0x00, agent->maintain_max);
|
memset(agent->maintain_buffer, 0x00, agent->maintain_max);
|
||||||
agent->maintain_len = 0;
|
agent->maintain_len = 0;
|
||||||
PrivMutexAbandon(&agent->lock);
|
PrivMutexAbandon(&agent->lock);
|
||||||
return -ERROR;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("GetCompleteATReply done\n");
|
printf("GetCompleteATReply done\n");
|
||||||
|
@ -437,6 +439,7 @@ int DeleteATAgent(ATAgentType agent)
|
||||||
printf("delete agent lock = %d\n",agent->lock.sem.semcount);
|
printf("delete agent lock = %d\n",agent->lock.sem.semcount);
|
||||||
PrivMutexDelete(&agent->lock);
|
PrivMutexDelete(&agent->lock);
|
||||||
}
|
}
|
||||||
|
#elif defined ADD_RTTHREAD_FETURES
|
||||||
#else
|
#else
|
||||||
if (agent->lock) {
|
if (agent->lock) {
|
||||||
printf("delete agent lock = %d\n",agent->lock);
|
printf("delete agent lock = %d\n",agent->lock);
|
||||||
|
@ -448,12 +451,12 @@ int DeleteATAgent(ATAgentType agent)
|
||||||
printf("delete agent entm_rx_notice = %d\n",agent->entm_rx_notice);
|
printf("delete agent entm_rx_notice = %d\n",agent->entm_rx_notice);
|
||||||
PrivSemaphoreDelete(&agent->entm_rx_notice);
|
PrivSemaphoreDelete(&agent->entm_rx_notice);
|
||||||
}
|
}
|
||||||
|
#ifdef ADD_XIZI_FETURES
|
||||||
if (agent->rsp_sem) {
|
if (agent->rsp_sem) {
|
||||||
printf("delete agent rsp_sem = %d\n",agent->rsp_sem);
|
printf("delete agent rsp_sem = %d\n",agent->rsp_sem);
|
||||||
PrivSemaphoreDelete(&agent->rsp_sem);
|
PrivSemaphoreDelete(&agent->rsp_sem);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
if (agent->maintain_buffer) {
|
if (agent->maintain_buffer) {
|
||||||
PrivFree(agent->maintain_buffer);
|
PrivFree(agent->maintain_buffer);
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,6 @@ struct ATReply
|
||||||
uint32 reply_len;
|
uint32 reply_len;
|
||||||
};
|
};
|
||||||
typedef struct ATReply *ATReplyType;
|
typedef struct ATReply *ATReplyType;
|
||||||
|
|
||||||
struct ATAgent
|
struct ATAgent
|
||||||
{
|
{
|
||||||
char agent_name[64];
|
char agent_name[64];
|
||||||
|
@ -53,10 +52,10 @@ struct ATAgent
|
||||||
uint32 maintain_len;
|
uint32 maintain_len;
|
||||||
uint32 maintain_max;
|
uint32 maintain_max;
|
||||||
|
|
||||||
#ifdef ADD_NUTTX_FETURES
|
#ifdef ADD_XIZI_FETURES
|
||||||
pthread_mutex_t lock;
|
|
||||||
#else
|
|
||||||
int lock;
|
int lock;
|
||||||
|
#else
|
||||||
|
pthread_mutex_t lock;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ATReplyType reply;
|
ATReplyType reply;
|
||||||
|
@ -64,8 +63,11 @@ struct ATAgent
|
||||||
char reply_end_last_char;
|
char reply_end_last_char;
|
||||||
char reply_end_char;
|
char reply_end_char;
|
||||||
uint32 reply_char_num;
|
uint32 reply_char_num;
|
||||||
int rsp_sem;
|
#ifdef ADD_XIZI_FETURES
|
||||||
|
int rsp_sem;
|
||||||
|
#else
|
||||||
|
sem_t rsp_sem;
|
||||||
|
#endif
|
||||||
pthread_t at_handler;
|
pthread_t at_handler;
|
||||||
|
|
||||||
#define ENTM_RECV_MAX 256
|
#define ENTM_RECV_MAX 256
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
import os
|
||||||
|
Import('RTT_ROOT')
|
||||||
|
from building import *
|
||||||
|
SOURCES = []
|
||||||
|
SOURCES = ['adapter_bluetooth.c'] + SOURCES
|
||||||
|
objs = []
|
||||||
|
cwd = GetCurrentDir()
|
||||||
|
path = [cwd]
|
||||||
|
group = DefineGroup('bluetooth', SOURCES, depend = [], CPPPATH = [cwd])
|
||||||
|
objs = objs + group
|
||||||
|
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(path, 'SConscript'))
|
||||||
|
|
||||||
|
Return('objs')
|
|
@ -78,13 +78,13 @@ int AdapterBlueToothInit(void)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************4G TEST*********************/
|
/******************BT TEST*********************/
|
||||||
int AdapterBlueToothTest(void)
|
int AdapterBlueToothTest(void)
|
||||||
{
|
{
|
||||||
const char *bluetooth_msg = "BT Adapter Test";
|
const char *bluetooth_msg = "BT Adapter Test";
|
||||||
char bluetooth_recv_msg[128];
|
char bluetooth_recv_msg[128];
|
||||||
int len;
|
int len;
|
||||||
int baud_rate = BAUD_RATE_115200;
|
int baud_rate = BAUD_RATE_9600;
|
||||||
|
|
||||||
struct Adapter *adapter = AdapterDeviceFindByName(ADAPTER_BLUETOOTH_NAME);
|
struct Adapter *adapter = AdapterDeviceFindByName(ADAPTER_BLUETOOTH_NAME);
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ int AdapterBlueToothTest(void)
|
||||||
printf("bluetooth_recv_msg %s\n", bluetooth_recv_msg);
|
printf("bluetooth_recv_msg %s\n", bluetooth_recv_msg);
|
||||||
AdapterDeviceSend(adapter, bluetooth_msg, len);
|
AdapterDeviceSend(adapter, bluetooth_msg, len);
|
||||||
printf("send %s after recv\n", bluetooth_msg);
|
printf("send %s after recv\n", bluetooth_msg);
|
||||||
PrivTaskDelay(100);
|
PrivTaskDelay(1000);
|
||||||
memset(bluetooth_recv_msg, 0, 128);
|
memset(bluetooth_recv_msg, 0, 128);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,4 +107,9 @@ int AdapterBlueToothTest(void)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, AdapterBlueToothTest, AdapterBlueToothTest, show adapter BT information);
|
#ifdef ADD_RTTHREAD_FETURES
|
||||||
|
MSH_CMD_EXPORT(AdapterBlueToothTest,a bt adpter sample);
|
||||||
|
#endif
|
||||||
|
#ifdef ADD_XIZI_FETURES
|
||||||
|
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, AdapterWifiTest, AdapterWifiTest, show adapter wifi information);
|
||||||
|
#endif
|
|
@ -36,5 +36,9 @@ if ADD_NUTTX_FETURES
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if ADD_RTTHREAD_FETURES
|
if ADD_RTTHREAD_FETURES
|
||||||
|
config ADAPTER_HC08_DRIVER
|
||||||
|
string "HC08 device uart driver path"
|
||||||
|
default "/dev/uart4"
|
||||||
|
config ADAPTER_HC08_WORK_ROLE
|
||||||
|
string "HC08 work role M(MASTER) or S(SLAVER)"
|
||||||
endif
|
endif
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
from building import *
|
||||||
|
import os
|
||||||
|
|
||||||
|
cwd = GetCurrentDir()
|
||||||
|
src = []
|
||||||
|
if GetDepend(['ADAPTER_HC08']):
|
||||||
|
src += ['hc08.c']
|
||||||
|
group = DefineGroup('connection bluetooth hc08', src, depend = [], CPPPATH = [cwd])
|
||||||
|
|
||||||
|
Return('group')
|
|
@ -92,7 +92,7 @@ static int Hc08AtConfigure(ATAgentType agent, enum Hc08AtCmd hc08_at_cmd, void *
|
||||||
ATReplyType reply = CreateATReply(64);
|
ATReplyType reply = CreateATReply(64);
|
||||||
if (NULL == reply) {
|
if (NULL == reply) {
|
||||||
printf("Hc08AtConfigure CreateATReply failed !\n");
|
printf("Hc08AtConfigure CreateATReply failed !\n");
|
||||||
return -ENOMEMORY;
|
return -5;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (hc08_at_cmd)
|
switch (hc08_at_cmd)
|
||||||
|
@ -152,20 +152,20 @@ static int Hc08AtConfigure(ATAgentType agent, enum Hc08AtCmd hc08_at_cmd, void *
|
||||||
ATOrderSend(agent, REPLY_TIME_OUT, reply, HC08_GET_ROLE_CMD);
|
ATOrderSend(agent, REPLY_TIME_OUT, reply, HC08_GET_ROLE_CMD);
|
||||||
reply_ok_flag = 0;
|
reply_ok_flag = 0;
|
||||||
break;
|
break;
|
||||||
// case HC08_AT_CMD_SET_ADDR:
|
case HC08_AT_CMD_SET_ADDR:
|
||||||
// ATOrderSend(agent, REPLY_TIME_OUT, reply, HC08_SET_ROLE_CMD);
|
ATOrderSend(agent, REPLY_TIME_OUT, reply, HC08_SET_ROLE_CMD);
|
||||||
// break;
|
break;
|
||||||
// case HC08_AT_CMD_GET_ADDR:
|
case HC08_AT_CMD_GET_ADDR:
|
||||||
// ATOrderSend(agent, REPLY_TIME_OUT, reply, HC08_GET_ROLE_CMD);
|
ATOrderSend(agent, REPLY_TIME_OUT, reply, HC08_GET_ROLE_CMD);
|
||||||
// reply_ok_flag = 0;
|
reply_ok_flag = 0;
|
||||||
// break;
|
break;
|
||||||
// case HC08_AT_CMD_SET_NAME:
|
case HC08_AT_CMD_SET_NAME:
|
||||||
// ATOrderSend(agent, REPLY_TIME_OUT, reply, HC08_SET_NAME_CMD);
|
ATOrderSend(agent, REPLY_TIME_OUT, reply, HC08_SET_NAME_CMD);
|
||||||
// break;
|
break;
|
||||||
// case HC08_AT_CMD_GET_NAME:
|
case HC08_AT_CMD_GET_NAME:
|
||||||
// ATOrderSend(agent, REPLY_TIME_OUT, reply, HC08_GET_NAME_CMD);
|
ATOrderSend(agent, REPLY_TIME_OUT, reply, HC08_GET_NAME_CMD);
|
||||||
// reply_ok_flag = 0;
|
reply_ok_flag = 0;
|
||||||
// break;
|
break;
|
||||||
default:
|
default:
|
||||||
printf("hc08 do not support no.%d cmd\n", hc08_at_cmd);
|
printf("hc08 do not support no.%d cmd\n", hc08_at_cmd);
|
||||||
DeleteATReply(reply);
|
DeleteATReply(reply);
|
||||||
|
@ -209,7 +209,7 @@ static int Hc08Open(struct Adapter *adapter)
|
||||||
if (!adapter->agent) {
|
if (!adapter->agent) {
|
||||||
char *agent_name = "bluetooth_uart_client";
|
char *agent_name = "bluetooth_uart_client";
|
||||||
printf("InitATAgent agent_name %s fd %u\n", agent_name, adapter->fd);
|
printf("InitATAgent agent_name %s fd %u\n", agent_name, adapter->fd);
|
||||||
if (EOK != InitATAgent(agent_name, adapter->fd, 512)) {
|
if (0 != InitATAgent(agent_name, adapter->fd, 512)) {
|
||||||
printf("at agent init failed !\n");
|
printf("at agent init failed !\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -343,7 +343,7 @@ static int Hc08Connect(struct Adapter *adapter, enum NetRoleType net_role, const
|
||||||
|
|
||||||
static int Hc08Send(struct Adapter *adapter, const void *buf, size_t len)
|
static int Hc08Send(struct Adapter *adapter, const void *buf, size_t len)
|
||||||
{
|
{
|
||||||
x_err_t result = EOK;
|
long result = 0;
|
||||||
if (adapter->agent) {
|
if (adapter->agent) {
|
||||||
EntmSend(adapter->agent, (const char *)buf, len);
|
EntmSend(adapter->agent, (const char *)buf, len);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
import os
|
||||||
|
Import('RTT_ROOT')
|
||||||
|
from building import *
|
||||||
|
SOURCES = []
|
||||||
|
SOURCES = ['adapter_wifi.c'] + SOURCES
|
||||||
|
objs = []
|
||||||
|
cwd = GetCurrentDir()
|
||||||
|
path = [cwd]
|
||||||
|
group = DefineGroup('wifi', SOURCES, depend = [], CPPPATH = [cwd])
|
||||||
|
objs = objs + group
|
||||||
|
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(path, 'SConscript'))
|
||||||
|
|
||||||
|
Return('objs')
|
|
@ -20,7 +20,9 @@
|
||||||
|
|
||||||
#include <adapter.h>
|
#include <adapter.h>
|
||||||
#include "adapter_wifi.h"
|
#include "adapter_wifi.h"
|
||||||
|
#ifdef ADD_XIZI_FETURES
|
||||||
#include <bus_pin.h>
|
#include <bus_pin.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef ADAPTER_HFA21_WIFI
|
#ifdef ADAPTER_HFA21_WIFI
|
||||||
extern AdapterProductInfoType Hfa21WifiAttach(struct Adapter *adapter);
|
extern AdapterProductInfoType Hfa21WifiAttach(struct Adapter *adapter);
|
||||||
|
@ -98,7 +100,7 @@ int AdapterWifiInit(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************wifi TEST*********************/
|
/******************wifi TEST*********************/
|
||||||
int AdapterwifiTest(void)
|
int AdapterWifiTest(void)
|
||||||
{
|
{
|
||||||
char cmd[64];
|
char cmd[64];
|
||||||
int baud_rate = BAUD_RATE_57600;
|
int baud_rate = BAUD_RATE_57600;
|
||||||
|
@ -107,30 +109,30 @@ int AdapterwifiTest(void)
|
||||||
|
|
||||||
|
|
||||||
#ifdef ADAPTER_HFA21_DRIVER_EXT_PORT
|
#ifdef ADAPTER_HFA21_DRIVER_EXT_PORT
|
||||||
// static BusType ch438_pin;
|
static BusType ch438_pin;
|
||||||
// ch438_pin = PinBusInitGet();
|
ch438_pin = PinBusInitGet();
|
||||||
// struct PinParam pin_cfg;
|
struct PinParam pin_cfg;
|
||||||
// int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
// struct BusConfigureInfo configure_info;
|
struct BusConfigureInfo configure_info;
|
||||||
// configure_info.configure_cmd = OPE_CFG;
|
configure_info.configure_cmd = OPE_CFG;
|
||||||
// configure_info.private_data = (void *)&pin_cfg;
|
configure_info.private_data = (void *)&pin_cfg;
|
||||||
|
|
||||||
// pin_cfg.cmd = GPIO_CONFIG_MODE;
|
pin_cfg.cmd = GPIO_CONFIG_MODE;
|
||||||
// pin_cfg.pin = 22;
|
pin_cfg.pin = 22;
|
||||||
// pin_cfg.mode = GPIO_CFG_OUTPUT;
|
pin_cfg.mode = GPIO_CFG_OUTPUT;
|
||||||
|
|
||||||
// ret = BusDrvConfigure(ch438_pin->owner_driver, &configure_info);
|
ret = BusDrvConfigure(ch438_pin->owner_driver, &configure_info);
|
||||||
|
|
||||||
// struct PinStat pin_stat;
|
struct PinStat pin_stat;
|
||||||
// struct BusBlockWriteParam write_param;
|
struct BusBlockWriteParam write_param;
|
||||||
// struct BusBlockReadParam read_param;
|
struct BusBlockReadParam read_param;
|
||||||
// write_param.buffer = (void *)&pin_stat;
|
write_param.buffer = (void *)&pin_stat;
|
||||||
|
|
||||||
// pin_stat.val = GPIO_HIGH;
|
pin_stat.val = GPIO_HIGH;
|
||||||
|
|
||||||
// pin_stat.pin = 22;
|
pin_stat.pin = 22;
|
||||||
// BusDevWriteData(ch438_pin->owner_haldev, &write_param);
|
BusDevWriteData(ch438_pin->owner_haldev, &write_param);
|
||||||
|
|
||||||
int pin_fd;
|
int pin_fd;
|
||||||
pin_fd = PrivOpen("/dev/pin_dev", O_RDWR);
|
pin_fd = PrivOpen("/dev/pin_dev", O_RDWR);
|
||||||
|
@ -168,7 +170,7 @@ int AdapterwifiTest(void)
|
||||||
enum IpType ip_type = IPV4;
|
enum IpType ip_type = IPV4;
|
||||||
AdapterDeviceConnect(adapter, net_role, ip, port, ip_type);
|
AdapterDeviceConnect(adapter, net_role, ip, port, ip_type);
|
||||||
|
|
||||||
const char *wifi_msg = "LiuKai Test";
|
const char *wifi_msg = "Wifi Test";
|
||||||
int len = strlen(wifi_msg);
|
int len = strlen(wifi_msg);
|
||||||
for(int i = 0;i < 10; ++i) {
|
for(int i = 0;i < 10; ++i) {
|
||||||
AdapterDeviceSend(adapter, wifi_msg, len);
|
AdapterDeviceSend(adapter, wifi_msg, len);
|
||||||
|
@ -176,12 +178,19 @@ int AdapterwifiTest(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
char wifi_recv_msg[128];
|
char wifi_recv_msg[128];
|
||||||
while (1) {
|
for(int j=0;j<10;++j){
|
||||||
AdapterDeviceRecv(adapter, wifi_recv_msg, 128);
|
AdapterDeviceRecv(adapter, wifi_recv_msg, 128);
|
||||||
|
PrivTaskDelay(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, AdapterwifiTest, AdapterwifiTest, show adapter wifi information);
|
|
||||||
|
#ifdef ADD_RTTHREAD_FETURES
|
||||||
|
MSH_CMD_EXPORT(AdapterWifiTest,a wifi adpter sample);
|
||||||
|
#endif
|
||||||
|
#ifdef ADD_XIZI_FETURES
|
||||||
|
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, AdapterWifiTest, AdapterWifiTest, show adapter wifi information);
|
||||||
|
#endif
|
||||||
|
|
||||||
int wifiopen(void)
|
int wifiopen(void)
|
||||||
{
|
{
|
||||||
|
@ -189,15 +198,18 @@ int wifiopen(void)
|
||||||
|
|
||||||
AdapterDeviceOpen(adapter);
|
AdapterDeviceOpen(adapter);
|
||||||
}
|
}
|
||||||
|
#ifdef ADD_XIZI_FETURES
|
||||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, wifiopen, wifiopen, open adapter wifi );
|
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, wifiopen, wifiopen, open adapter wifi );
|
||||||
|
#endif
|
||||||
int wificlose(void)
|
int wificlose(void)
|
||||||
{
|
{
|
||||||
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
|
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
|
||||||
|
|
||||||
AdapterDeviceClose(adapter);
|
AdapterDeviceClose(adapter);
|
||||||
}
|
}
|
||||||
|
#ifdef ADD_XIZI_FETURES
|
||||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, wificlose, wificlose, close adapter wifi );
|
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, wificlose, wificlose, close adapter wifi );
|
||||||
|
#endif
|
||||||
int wifisetup(int argc, char *argv[])
|
int wifisetup(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
|
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
|
||||||
|
@ -210,7 +222,9 @@ int wifisetup(int argc, char *argv[])
|
||||||
|
|
||||||
AdapterDeviceSetUp(adapter);
|
AdapterDeviceSetUp(adapter);
|
||||||
}
|
}
|
||||||
|
#ifdef ADD_XIZI_FETURES
|
||||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(3)|SHELL_CMD_DISABLE_RETURN, wifisetup, wifisetup, setup adapter wifi );
|
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(3)|SHELL_CMD_DISABLE_RETURN, wifisetup, wifisetup, setup adapter wifi );
|
||||||
|
#endif
|
||||||
int wifiaddrset(int argc, char *argv[])
|
int wifiaddrset(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
|
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
|
||||||
|
@ -222,16 +236,18 @@ int wifiaddrset(int argc, char *argv[])
|
||||||
AdapterDevicePing(adapter, "36.152.44.95");///< ping www.baidu.com
|
AdapterDevicePing(adapter, "36.152.44.95");///< ping www.baidu.com
|
||||||
AdapterDeviceNetstat(adapter);
|
AdapterDeviceNetstat(adapter);
|
||||||
}
|
}
|
||||||
|
#ifdef ADD_XIZI_FETURES
|
||||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(4)|SHELL_CMD_DISABLE_RETURN, wifiaddrset, wifiaddrset, addrset adapter wifi);
|
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(4)|SHELL_CMD_DISABLE_RETURN, wifiaddrset, wifiaddrset, addrset adapter wifi);
|
||||||
|
#endif
|
||||||
int wifiping(int argc, char *argv[])
|
int wifiping(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
|
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
|
||||||
printf("ping %s\n",argv[1]);
|
printf("ping %s\n",argv[1]);
|
||||||
AdapterDevicePing(adapter, argv[1]);
|
AdapterDevicePing(adapter, argv[1]);
|
||||||
}
|
}
|
||||||
|
#ifdef ADD_XIZI_FETURES
|
||||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(3), wifiping, wifiping, wifiping adapter );
|
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(3), wifiping, wifiping, wifiping adapter );
|
||||||
|
#endif
|
||||||
int wificonnect(int argc, char *argv[])
|
int wificonnect(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
|
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
|
||||||
|
@ -250,7 +266,9 @@ int wificonnect(int argc, char *argv[])
|
||||||
|
|
||||||
AdapterDeviceConnect(adapter, net_role, ip, port, ip_type);
|
AdapterDeviceConnect(adapter, net_role, ip, port, ip_type);
|
||||||
}
|
}
|
||||||
|
#ifdef ADD_XIZI_FETURES
|
||||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(4)|SHELL_CMD_DISABLE_RETURN, wificonnect, wificonnect, wificonnect adapter);
|
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(4)|SHELL_CMD_DISABLE_RETURN, wificonnect, wificonnect, wificonnect adapter);
|
||||||
|
#endif
|
||||||
int wifisend(int argc, char *argv[])
|
int wifisend(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
|
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
|
||||||
|
@ -262,7 +280,9 @@ int wifisend(int argc, char *argv[])
|
||||||
PrivTaskDelay(1000);
|
PrivTaskDelay(1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#ifdef ADD_XIZI_FETURES
|
||||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(3)|SHELL_CMD_DISABLE_RETURN, wifisend, wifisend, wifisend adapter wifi information);
|
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(3)|SHELL_CMD_DISABLE_RETURN, wifisend, wifisend, wifisend adapter wifi information);
|
||||||
|
#endif
|
||||||
int wifirecv(int argc, char *argv[])
|
int wifirecv(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
|
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
|
||||||
|
@ -274,4 +294,6 @@ int wifirecv(int argc, char *argv[])
|
||||||
printf("wifi recv [%s]\n",wifi_recv_msg);
|
printf("wifi recv [%s]\n",wifi_recv_msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#ifdef ADD_XIZI_FETURES
|
||||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(3)|SHELL_CMD_DISABLE_RETURN, wifirecv, wifirecv, wifirecv adapter wifi information);
|
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(3)|SHELL_CMD_DISABLE_RETURN, wifirecv, wifirecv, wifirecv adapter wifi information);
|
||||||
|
#endif
|
||||||
|
|
|
@ -29,5 +29,7 @@ if ADD_NUTTX_FETURES
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if ADD_RTTHREAD_FETURES
|
if ADD_RTTHREAD_FETURES
|
||||||
|
config ADAPTER_HFA21_DRIVER
|
||||||
|
string "HFA21 device uart driver path"
|
||||||
|
default "/dev/uart3"
|
||||||
endif
|
endif
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
from building import *
|
||||||
|
import os
|
||||||
|
|
||||||
|
cwd = GetCurrentDir()
|
||||||
|
src = []
|
||||||
|
if GetDepend(['ADAPTER_HFA21_WIFI']):
|
||||||
|
src += ['hfa21_wifi.c']
|
||||||
|
group = DefineGroup('connection wifi hfa21', src, depend = [], CPPPATH = [cwd])
|
||||||
|
|
||||||
|
Return('group')
|
|
@ -20,7 +20,8 @@
|
||||||
|
|
||||||
#include <adapter.h>
|
#include <adapter.h>
|
||||||
#include <at_agent.h>
|
#include <at_agent.h>
|
||||||
|
#include <transform.h>
|
||||||
|
#include <string.h>
|
||||||
#define LEN_PARA_BUF 128
|
#define LEN_PARA_BUF 128
|
||||||
|
|
||||||
static int Hfa21WifiSetDown(struct Adapter *adapter_at);
|
static int Hfa21WifiSetDown(struct Adapter *adapter_at);
|
||||||
|
@ -28,10 +29,11 @@ static int Hfa21WifiSetDown(struct Adapter *adapter_at);
|
||||||
/**
|
/**
|
||||||
* @description: enter AT command mode
|
* @description: enter AT command mode
|
||||||
* @param at_agent - wifi device agent pointer
|
* @param at_agent - wifi device agent pointer
|
||||||
* @return success: EOK
|
* @return success: 0
|
||||||
*/
|
*/
|
||||||
static int Hfa21WifiInitAtCmd(ATAgentType at_agent)
|
static int Hfa21WifiInitAtCmd(ATAgentType at_agent)
|
||||||
{
|
{
|
||||||
|
|
||||||
ATOrderSend(at_agent, REPLY_TIME_OUT, NULL, "+++");
|
ATOrderSend(at_agent, REPLY_TIME_OUT, NULL, "+++");
|
||||||
PrivTaskDelay(100);
|
PrivTaskDelay(100);
|
||||||
|
|
||||||
|
@ -44,7 +46,7 @@ static int Hfa21WifiInitAtCmd(ATAgentType at_agent)
|
||||||
/**
|
/**
|
||||||
* @description: Open wifi
|
* @description: Open wifi
|
||||||
* @param adapter - wifi device pointer
|
* @param adapter - wifi device pointer
|
||||||
* @return success: EOK, failure: ENOMEMORY
|
* @return success: 0, failure: 5
|
||||||
*/
|
*/
|
||||||
static int Hfa21WifiOpen(struct Adapter *adapter)
|
static int Hfa21WifiOpen(struct Adapter *adapter)
|
||||||
{
|
{
|
||||||
|
@ -58,7 +60,7 @@ static int Hfa21WifiOpen(struct Adapter *adapter)
|
||||||
/*step2: init AT agent*/
|
/*step2: init AT agent*/
|
||||||
if (!adapter->agent) {
|
if (!adapter->agent) {
|
||||||
char *agent_name = "wifi_uart_client";
|
char *agent_name = "wifi_uart_client";
|
||||||
if (EOK != InitATAgent(agent_name, adapter->fd, 512)) {
|
if (0 != InitATAgent(agent_name, adapter->fd, 512)) {
|
||||||
printf("at agent init failed !\n");
|
printf("at agent init failed !\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -75,7 +77,7 @@ static int Hfa21WifiOpen(struct Adapter *adapter)
|
||||||
/**
|
/**
|
||||||
* @description: Close wifi
|
* @description: Close wifi
|
||||||
* @param adapter - wifi device pointer
|
* @param adapter - wifi device pointer
|
||||||
* @return success: EOK
|
* @return success: 0
|
||||||
*/
|
*/
|
||||||
static int Hfa21WifiClose(struct Adapter *adapter)
|
static int Hfa21WifiClose(struct Adapter *adapter)
|
||||||
{
|
{
|
||||||
|
@ -87,11 +89,11 @@ static int Hfa21WifiClose(struct Adapter *adapter)
|
||||||
* @param adapter - wifi device pointer
|
* @param adapter - wifi device pointer
|
||||||
* @param data - data buffer
|
* @param data - data buffer
|
||||||
* @param data - data length
|
* @param data - data length
|
||||||
* @return success: EOK
|
* @return success: 0
|
||||||
*/
|
*/
|
||||||
static int Hfa21WifiSend(struct Adapter *adapter, const void *data, size_t len)
|
static int Hfa21WifiSend(struct Adapter *adapter, const void *data, size_t len)
|
||||||
{
|
{
|
||||||
x_err_t result = EOK;
|
long result = 0;
|
||||||
if (adapter->agent) {
|
if (adapter->agent) {
|
||||||
EntmSend(adapter->agent, (const char *)data, len);
|
EntmSend(adapter->agent, (const char *)data, len);
|
||||||
}else {
|
}else {
|
||||||
|
@ -108,11 +110,11 @@ __exit:
|
||||||
* @param adapter - wifi device pointer
|
* @param adapter - wifi device pointer
|
||||||
* @param data - data buffer
|
* @param data - data buffer
|
||||||
* @param data - data length
|
* @param data - data length
|
||||||
* @return success: EOK
|
* @return success: 0
|
||||||
*/
|
*/
|
||||||
static int Hfa21WifiReceive(struct Adapter *adapter, void *rev_buffer, size_t buffer_len)
|
static int Hfa21WifiReceive(struct Adapter *adapter, void *rev_buffer, size_t buffer_len)
|
||||||
{
|
{
|
||||||
x_err_t result = EOK;
|
long result = 0;
|
||||||
printf("hfa21 receive waiting ... \n");
|
printf("hfa21 receive waiting ... \n");
|
||||||
|
|
||||||
if (adapter->agent) {
|
if (adapter->agent) {
|
||||||
|
@ -129,20 +131,19 @@ __exit:
|
||||||
/**
|
/**
|
||||||
* @description: connnect wifi to internet
|
* @description: connnect wifi to internet
|
||||||
* @param adapter - wifi device pointer
|
* @param adapter - wifi device pointer
|
||||||
* @return success: EOK
|
* @return success: 0
|
||||||
*/
|
*/
|
||||||
static int Hfa21WifiSetUp(struct Adapter *adapter)
|
static int Hfa21WifiSetUp(struct Adapter *adapter)
|
||||||
{
|
{
|
||||||
uint8 wifi_ssid[LEN_PARA_BUF] = "AIIT-Guest";
|
uint8 wifi_ssid[LEN_PARA_BUF] = "AIIT-Guest";
|
||||||
uint8 wifi_pwd[LEN_PARA_BUF] = "";
|
uint8 wifi_pwd[LEN_PARA_BUF] = "";
|
||||||
char cmd[LEN_PARA_BUF];
|
char cmd[LEN_PARA_BUF];
|
||||||
|
|
||||||
struct ATAgent *agent = adapter->agent;
|
struct ATAgent *agent = adapter->agent;
|
||||||
|
|
||||||
/* wait hfa21 device startup finish */
|
/* wait hfa21 device startup finish */
|
||||||
PrivTaskDelay(5000);
|
PrivTaskDelay(5000);
|
||||||
|
Hfa21WifiInitAtCmd(agent);//err
|
||||||
Hfa21WifiInitAtCmd(agent);
|
|
||||||
|
|
||||||
memset(cmd,0,sizeof(cmd));
|
memset(cmd,0,sizeof(cmd));
|
||||||
strcpy(cmd,"AT+FCLR\r");
|
strcpy(cmd,"AT+FCLR\r");
|
||||||
|
@ -181,7 +182,7 @@ static int Hfa21WifiSetUp(struct Adapter *adapter)
|
||||||
/**
|
/**
|
||||||
* @description: disconnnect wifi from internet
|
* @description: disconnnect wifi from internet
|
||||||
* @param adapter - wifi device pointer
|
* @param adapter - wifi device pointer
|
||||||
* @return success: EOK
|
* @return success: 0
|
||||||
*/
|
*/
|
||||||
static int Hfa21WifiSetDown(struct Adapter *adapter)
|
static int Hfa21WifiSetDown(struct Adapter *adapter)
|
||||||
{
|
{
|
||||||
|
@ -199,7 +200,7 @@ static int Hfa21WifiSetDown(struct Adapter *adapter)
|
||||||
* @param ip - ip address
|
* @param ip - ip address
|
||||||
* @param gateway - gateway address
|
* @param gateway - gateway address
|
||||||
* @param netmask - netmask address
|
* @param netmask - netmask address
|
||||||
* @return success: EOK, failure: ENOMEMORY
|
* @return success: 0, failure: 5
|
||||||
*/
|
*/
|
||||||
static int Hfa21WifiSetAddr(struct Adapter *adapter, const char *ip, const char *gateway, const char *netmask)
|
static int Hfa21WifiSetAddr(struct Adapter *adapter, const char *ip, const char *gateway, const char *netmask)
|
||||||
{
|
{
|
||||||
|
@ -216,12 +217,12 @@ static int Hfa21WifiSetAddr(struct Adapter *adapter, const char *ip, const char
|
||||||
|
|
||||||
Hfa21WifiInitAtCmd(adapter->agent);
|
Hfa21WifiInitAtCmd(adapter->agent);
|
||||||
|
|
||||||
x_err_t result = EOK;
|
long result = 0;
|
||||||
|
|
||||||
ATReplyType reply = CreateATReply(64);
|
ATReplyType reply = CreateATReply(64);
|
||||||
if (NULL == reply) {
|
if (NULL == reply) {
|
||||||
printf("at_create_resp failed ! \n");
|
printf("at_create_resp failed ! \n");
|
||||||
result = ENOMEMORY;
|
result = 5;
|
||||||
goto __exit;
|
goto __exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,12 +254,12 @@ __exit:
|
||||||
* @description: wifi ping function
|
* @description: wifi ping function
|
||||||
* @param adapter - wifi device pointer
|
* @param adapter - wifi device pointer
|
||||||
* @param destination - domain name or ip address
|
* @param destination - domain name or ip address
|
||||||
* @return success: EOK, failure: ENOMEMORY
|
* @return success: 0, failure: 5
|
||||||
*/
|
*/
|
||||||
static int Hfa21WifiPing(struct Adapter *adapter, const char *destination)
|
static int Hfa21WifiPing(struct Adapter *adapter, const char *destination)
|
||||||
{
|
{
|
||||||
char *ping_result = NONE;
|
char *ping_result = (0);
|
||||||
char *dst = NONE;
|
char *dst = (0);
|
||||||
ping_result = (char *) PrivCalloc(1, 17);
|
ping_result = (char *) PrivCalloc(1, 17);
|
||||||
dst = (char *) PrivCalloc(1, 17);
|
dst = (char *) PrivCalloc(1, 17);
|
||||||
strcpy(dst, destination);
|
strcpy(dst, destination);
|
||||||
|
@ -266,12 +267,12 @@ static int Hfa21WifiPing(struct Adapter *adapter, const char *destination)
|
||||||
|
|
||||||
Hfa21WifiInitAtCmd(adapter->agent);
|
Hfa21WifiInitAtCmd(adapter->agent);
|
||||||
|
|
||||||
uint32 result = EOK;
|
uint32 result = 0;
|
||||||
|
|
||||||
ATReplyType reply = CreateATReply(64);
|
ATReplyType reply = CreateATReply(64);
|
||||||
if (NULL == reply) {
|
if (NULL == reply) {
|
||||||
printf("at_create_resp failed ! \n");
|
printf("at_create_resp failed ! \n");
|
||||||
result = ENOMEMORY;
|
result = 5;
|
||||||
goto __exit;
|
goto __exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -302,7 +303,7 @@ __exit:
|
||||||
/**
|
/**
|
||||||
* @description: display wifi network configuration
|
* @description: display wifi network configuration
|
||||||
* @param adapter - wifi device pointer
|
* @param adapter - wifi device pointer
|
||||||
* @return success: EOK, failure: ENOMEMORY
|
* @return success: 0, failure: 5
|
||||||
*/
|
*/
|
||||||
static int Hfa21WifiNetstat(struct Adapter *adapter)
|
static int Hfa21WifiNetstat(struct Adapter *adapter)
|
||||||
{
|
{
|
||||||
|
@ -334,7 +335,7 @@ static int Hfa21WifiNetstat(struct Adapter *adapter)
|
||||||
|
|
||||||
reply = CreateATReply(HFA21_NETSTAT_RESP_SIZE);
|
reply = CreateATReply(HFA21_NETSTAT_RESP_SIZE);
|
||||||
if (reply == NULL) {
|
if (reply == NULL) {
|
||||||
result = ENOMEMORY;
|
result = 5;
|
||||||
goto __exit;
|
goto __exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -384,7 +385,7 @@ static int Hfa21WifiNetstat(struct Adapter *adapter)
|
||||||
else
|
else
|
||||||
printf("local ip: %s\nnetmask: %s\n", local_ipaddr, netmask);
|
printf("local ip: %s\nnetmask: %s\n", local_ipaddr, netmask);
|
||||||
|
|
||||||
return EOK;
|
return 0;
|
||||||
|
|
||||||
__exit:
|
__exit:
|
||||||
if (reply)
|
if (reply)
|
||||||
|
@ -410,15 +411,15 @@ __exit:
|
||||||
*/
|
*/
|
||||||
static int Hfa21WifiConnect(struct Adapter *adapter, enum NetRoleType net_role, const char *ip, const char *port, enum IpType ip_type)
|
static int Hfa21WifiConnect(struct Adapter *adapter, enum NetRoleType net_role, const char *ip, const char *port, enum IpType ip_type)
|
||||||
{
|
{
|
||||||
int result = EOK;
|
int result = 0;
|
||||||
ATReplyType reply = NONE;
|
ATReplyType reply = (0);
|
||||||
char cmd[LEN_PARA_BUF];
|
char cmd[LEN_PARA_BUF];
|
||||||
struct ATAgent *agent = adapter->agent;
|
struct ATAgent *agent = adapter->agent;
|
||||||
|
|
||||||
reply = CreateATReply(64);
|
reply = CreateATReply(64);
|
||||||
if (reply == NONE) {
|
if (reply == (0)) {
|
||||||
printf("no memory for reply struct.");
|
printf("no memory for reply struct.");
|
||||||
return ENOMEMORY;
|
return 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
Hfa21WifiInitAtCmd(adapter->agent);
|
Hfa21WifiInitAtCmd(adapter->agent);
|
||||||
|
@ -505,7 +506,7 @@ static const struct IpProtocolDone hfa21_wifi_done =
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description: Register wifi device hfa21
|
* @description: Register wifi device hfa21
|
||||||
* @return success: EOK, failure: ERROR
|
* @return success: 0, failure: ERROR
|
||||||
*/
|
*/
|
||||||
AdapterProductInfoType Hfa21WifiAttach(struct Adapter *adapter)
|
AdapterProductInfoType Hfa21WifiAttach(struct Adapter *adapter)
|
||||||
{
|
{
|
||||||
|
|
|
@ -171,6 +171,7 @@ int PrivIoctl(int fd, int cmd, void *args)
|
||||||
break;
|
break;
|
||||||
case ADC_TYPE:
|
case ADC_TYPE:
|
||||||
case DAC_TYPE:
|
case DAC_TYPE:
|
||||||
|
case WDT_TYPE:
|
||||||
ret = ioctl(fd, cmd, ioctl_cfg->args);
|
ret = ioctl(fd, cmd, ioctl_cfg->args);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -35,6 +35,9 @@ extern "C" {
|
||||||
#define OPE_INT 0x0000
|
#define OPE_INT 0x0000
|
||||||
#define OPE_CFG 0x0001
|
#define OPE_CFG 0x0001
|
||||||
|
|
||||||
|
#define OPER_WDT_SET_TIMEOUT 0x0002
|
||||||
|
#define OPER_WDT_KEEPALIVE 0x0003
|
||||||
|
|
||||||
#define NAME_NUM_MAX 32
|
#define NAME_NUM_MAX 32
|
||||||
|
|
||||||
/*********************GPIO define*********************/
|
/*********************GPIO define*********************/
|
||||||
|
@ -142,6 +145,7 @@ enum IoctlDriverType
|
||||||
LCD_TYPE,
|
LCD_TYPE,
|
||||||
ADC_TYPE,
|
ADC_TYPE,
|
||||||
DAC_TYPE,
|
DAC_TYPE,
|
||||||
|
WDT_TYPE,
|
||||||
DEFAULT_TYPE,
|
DEFAULT_TYPE,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -285,8 +285,8 @@ CONFIG_BSP_USING_GPIO=y
|
||||||
CONFIG_BSP_USING_UART=y
|
CONFIG_BSP_USING_UART=y
|
||||||
CONFIG_BSP_USING_UART1=y
|
CONFIG_BSP_USING_UART1=y
|
||||||
# CONFIG_BSP_USING_UART2 is not set
|
# CONFIG_BSP_USING_UART2 is not set
|
||||||
# CONFIG_BSP_USING_UART3 is not set
|
CONFIG_BSP_USING_UART3=y
|
||||||
# CONFIG_BSP_USING_UART4 is not set
|
CONFIG_BSP_USING_UART4=y
|
||||||
# CONFIG_BSP_USING_I2C1 is not set
|
# CONFIG_BSP_USING_I2C1 is not set
|
||||||
# CONFIG_BSP_USING_SPI is not set
|
# CONFIG_BSP_USING_SPI is not set
|
||||||
# CONFIG_BSP_USING_CH438 is not set
|
# CONFIG_BSP_USING_CH438 is not set
|
||||||
|
@ -317,11 +317,27 @@ CONFIG_USB_DEVICE_NAME="usb_dev"
|
||||||
# Framework
|
# Framework
|
||||||
#
|
#
|
||||||
CONFIG_TRANSFORM_LAYER_ATTRIUBUTE=y
|
CONFIG_TRANSFORM_LAYER_ATTRIUBUTE=y
|
||||||
CONFIG_ADD_XIZI_FETURES=y
|
# CONFIG_ADD_XIZI_FETURES is not set
|
||||||
# CONFIG_ADD_NUTTX_FETURES is not set
|
# CONFIG_ADD_NUTTX_FETURES is not set
|
||||||
# CONFIG_ADD_RTTHREAD_FETURES is not set
|
CONFIG_ADD_RTTHREAD_FETURES=y
|
||||||
# CONFIG_SUPPORT_SENSOR_FRAMEWORK is not set
|
# CONFIG_SUPPORT_SENSOR_FRAMEWORK is not set
|
||||||
# CONFIG_SUPPORT_CONNECTION_FRAMEWORK is not set
|
CONFIG_SUPPORT_CONNECTION_FRAMEWORK=y
|
||||||
|
CONFIG_CONNECTION_FRAMEWORK_DEBUG=y
|
||||||
|
# CONFIG_CONNECTION_INDUSTRIAL_ETHERNET is not set
|
||||||
|
# CONFIG_CONNECTION_INDUSTRIAL_FIELDBUS is not set
|
||||||
|
# CONFIG_CONNECTION_INDUSTRIAL_WLAN is not set
|
||||||
|
# CONFIG_CONNECTION_ADAPTER_LORA is not set
|
||||||
|
# CONFIG_CONNECTION_ADAPTER_4G is not set
|
||||||
|
# CONFIG_CONNECTION_ADAPTER_NB is not set
|
||||||
|
# CONFIG_CONNECTION_ADAPTER_WIFI is not set
|
||||||
|
# CONFIG_CONNECTION_ADAPTER_ETHERNET is not set
|
||||||
|
CONFIG_CONNECTION_ADAPTER_BLUETOOTH=y
|
||||||
|
CONFIG_ADAPTER_HC08=y
|
||||||
|
CONFIG_ADAPTER_BLUETOOTH_HC08="hc08"
|
||||||
|
CONFIG_ADAPTER_HC08_WORK_ROLE="M"
|
||||||
|
CONFIG_ADAPTER_HC08_DRIVER="/dev/uart4"
|
||||||
|
# CONFIG_CONNECTION_ADAPTER_ZIGBEE is not set
|
||||||
|
# CONFIG_CONNECTION_ADAPTER_5G is not set
|
||||||
# CONFIG_SUPPORT_KNOWING_FRAMEWORK is not set
|
# CONFIG_SUPPORT_KNOWING_FRAMEWORK is not set
|
||||||
# CONFIG_SUPPORT_CONTROL_FRAMEWORK is not set
|
# CONFIG_SUPPORT_CONTROL_FRAMEWORK is not set
|
||||||
|
|
||||||
|
|
|
@ -174,6 +174,8 @@
|
||||||
#define BSP_USING_GPIO
|
#define BSP_USING_GPIO
|
||||||
#define BSP_USING_UART
|
#define BSP_USING_UART
|
||||||
#define BSP_USING_UART1
|
#define BSP_USING_UART1
|
||||||
|
#define BSP_USING_UART3
|
||||||
|
#define BSP_USING_UART4
|
||||||
#define BSP_USING_USB
|
#define BSP_USING_USB
|
||||||
#define BSP_USING_STM32_USBH
|
#define BSP_USING_STM32_USBH
|
||||||
#define USB_BUS_NAME "usb"
|
#define USB_BUS_NAME "usb"
|
||||||
|
@ -191,7 +193,14 @@
|
||||||
/* Framework */
|
/* Framework */
|
||||||
|
|
||||||
#define TRANSFORM_LAYER_ATTRIUBUTE
|
#define TRANSFORM_LAYER_ATTRIUBUTE
|
||||||
#define ADD_XIZI_FETURES
|
#define ADD_RTTHREAD_FETURES
|
||||||
|
#define SUPPORT_CONNECTION_FRAMEWORK
|
||||||
|
#define CONNECTION_FRAMEWORK_DEBUG
|
||||||
|
#define CONNECTION_ADAPTER_BLUETOOTH
|
||||||
|
#define ADAPTER_HC08
|
||||||
|
#define ADAPTER_BLUETOOTH_HC08 "hc08"
|
||||||
|
#define ADAPTER_HC08_WORK_ROLE "M"
|
||||||
|
#define ADAPTER_HC08_DRIVER "/dev/uart4"
|
||||||
|
|
||||||
/* Security */
|
/* Security */
|
||||||
|
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 265 KiB |
Binary file not shown.
After Width: | Height: | Size: 96 KiB |
|
@ -149,7 +149,7 @@ CONFIG_RT_DFS_ELM_MAX_SECTOR_SIZE=512
|
||||||
CONFIG_RT_DFS_ELM_REENTRANT=y
|
CONFIG_RT_DFS_ELM_REENTRANT=y
|
||||||
CONFIG_RT_DFS_ELM_MUTEX_TIMEOUT=3000
|
CONFIG_RT_DFS_ELM_MUTEX_TIMEOUT=3000
|
||||||
CONFIG_RT_USING_DFS_DEVFS=y
|
CONFIG_RT_USING_DFS_DEVFS=y
|
||||||
# CONFIG_RT_USING_DFS_ROMFS is not set
|
CONFIG_RT_USING_DFS_ROMFS=y
|
||||||
# CONFIG_RT_USING_DFS_RAMFS is not set
|
# CONFIG_RT_USING_DFS_RAMFS is not set
|
||||||
# CONFIG_RT_USING_DFS_NFS is not set
|
# CONFIG_RT_USING_DFS_NFS is not set
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,9 @@ if GetDepend('BSP_USING_PHY') and GetDepend('PHY_USING_8720A'):
|
||||||
src += ['./ports/LAN8720A.c']
|
src += ['./ports/LAN8720A.c']
|
||||||
if GetDepend('BSP_USING_SDCARD'):
|
if GetDepend('BSP_USING_SDCARD'):
|
||||||
src += ['./ports/sdcard_port.c']
|
src += ['./ports/sdcard_port.c']
|
||||||
|
if GetDepend(['RT_USING_DFS_ROMFS']):
|
||||||
|
src += ['ports/romfs.c']
|
||||||
|
src += ['ports/mnt_romfs.c']
|
||||||
group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES=CPPDEFINES)
|
group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES=CPPDEFINES)
|
||||||
|
|
||||||
Return('group')
|
Return('group')
|
||||||
|
|
|
@ -1093,3 +1093,10 @@ void rt_hw_us_delay(rt_uint32_t usec)
|
||||||
{
|
{
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int reboot(void)
|
||||||
|
{
|
||||||
|
NVIC_SystemReset();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
MSH_CMD_EXPORT(reboot, reboot system);
|
|
@ -226,7 +226,7 @@ SECTIONS
|
||||||
__noncachedata_init_end__ = .; /* create a global symbol at initialized ncache data end */
|
__noncachedata_init_end__ = .; /* create a global symbol at initialized ncache data end */
|
||||||
} > m_nocache
|
} > m_nocache
|
||||||
. = __noncachedata_init_end__;
|
. = __noncachedata_init_end__;
|
||||||
.ncache :
|
.ncache(NOLOAD):
|
||||||
{
|
{
|
||||||
*(NonCacheable)
|
*(NonCacheable)
|
||||||
. = ALIGN(4);
|
. = ALIGN(4);
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
#include <rtthread.h>
|
||||||
|
#if defined RT_USING_DFS && defined RT_USING_DFS_ROMFS
|
||||||
|
#include <dfs_fs.h>
|
||||||
|
#include "dfs_romfs.h"
|
||||||
|
|
||||||
|
int mnt_init(void)
|
||||||
|
{
|
||||||
|
if (dfs_mount(RT_NULL, "/", "rom", 0, &(romfs_root)) == 0)
|
||||||
|
{
|
||||||
|
rt_kprintf("ROM file system initializated!\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rt_kprintf("ROM file system initializate failed!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
INIT_ENV_EXPORT(mnt_init);
|
||||||
|
#endif
|
|
@ -0,0 +1,18 @@
|
||||||
|
/* Generated by mkromfs. Edit with caution. */
|
||||||
|
#include <rtthread.h>
|
||||||
|
#include <dfs_romfs.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static const rt_uint8_t _romfs_root_romfstest_txt[] = {
|
||||||
|
0x68,0x65,0x6c,0x6c,0x6f,0x20,0x78,0x69,0x64,0x61,0x74,0x6f,0x6e,0x67,0x0d,0x0a
|
||||||
|
};
|
||||||
|
|
||||||
|
static const struct romfs_dirent _romfs_root[] = {
|
||||||
|
{ROMFS_DIRENT_DIR, "SD", RT_NULL, 0},
|
||||||
|
{ROMFS_DIRENT_FILE, "romfstest.txt", (rt_uint8_t *)_romfs_root_romfstest_txt, sizeof(_romfs_root_romfstest_txt)/sizeof(_romfs_root_romfstest_txt[0])}
|
||||||
|
};
|
||||||
|
|
||||||
|
const struct romfs_dirent romfs_root = {
|
||||||
|
ROMFS_DIRENT_DIR, "/", (rt_uint8_t *)_romfs_root, sizeof(_romfs_root)/sizeof(_romfs_root[0])
|
||||||
|
};
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
#include <rtdevice.h>
|
#include <rtdevice.h>
|
||||||
#include <rtthread.h>
|
#include <rtthread.h>
|
||||||
#include "drv_gpio.h"
|
#include "drv_gpio.h"
|
||||||
|
@ -15,7 +14,11 @@ int sd_mount()
|
||||||
if (result == MMCSD_HOST_PLUGED)
|
if (result == MMCSD_HOST_PLUGED)
|
||||||
{
|
{
|
||||||
/* mount sd card fat partition 1 as root directory */
|
/* mount sd card fat partition 1 as root directory */
|
||||||
if (dfs_mount("sd0", "/", "elm", 0, 0) == 0)
|
#ifdef RT_USING_DFS_ROMFS
|
||||||
|
if(dfs_mount("sd0", "/SD", "elm", 0, 0) == 0)
|
||||||
|
#else
|
||||||
|
if(dfs_mount("sd0", "/", "elm", 0, 0) == 0)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
LOG_I("File System initialized!\n");
|
LOG_I("File System initialized!\n");
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
|
|
|
@ -101,6 +101,7 @@
|
||||||
#define RT_DFS_ELM_REENTRANT
|
#define RT_DFS_ELM_REENTRANT
|
||||||
#define RT_DFS_ELM_MUTEX_TIMEOUT 3000
|
#define RT_DFS_ELM_MUTEX_TIMEOUT 3000
|
||||||
#define RT_USING_DFS_DEVFS
|
#define RT_USING_DFS_DEVFS
|
||||||
|
#define RT_USING_DFS_ROMFS
|
||||||
|
|
||||||
/* Device Drivers */
|
/* Device Drivers */
|
||||||
|
|
||||||
|
|
|
@ -53,6 +53,9 @@ if PLATFORM == 'gcc':
|
||||||
CPATH = ''
|
CPATH = ''
|
||||||
LPATH = ''
|
LPATH = ''
|
||||||
|
|
||||||
|
AFLAGS += ' -D__STARTUP_INITIALIZE_NONCACHEDATA'
|
||||||
|
AFLAGS += ' -D__STARTUP_CLEAR_BSS'
|
||||||
|
|
||||||
if BUILD == 'debug':
|
if BUILD == 'debug':
|
||||||
CFLAGS += ' -gdwarf-2'
|
CFLAGS += ' -gdwarf-2'
|
||||||
AFLAGS += ' -gdwarf-2'
|
AFLAGS += ' -gdwarf-2'
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file connect_wdt.c
|
* @file connect_wdg.c
|
||||||
* @brief support aiit-arm32-board watchdog function and register to bus framework
|
* @brief support aiit-arm32-board watchdog function and register to bus framework
|
||||||
* @version 1.0
|
* @version 1.0
|
||||||
* @author AIIT XUOS Lab
|
* @author AIIT XUOS Lab
|
||||||
|
|
|
@ -52,6 +52,10 @@ Modification:
|
||||||
#include <connect_sdio.h>
|
#include <connect_sdio.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef BSP_USING_WDT
|
||||||
|
#include <connect_wdt.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef BSP_USING_SEMC
|
#ifdef BSP_USING_SEMC
|
||||||
extern status_t BOARD_InitSEMC(void);
|
extern status_t BOARD_InitSEMC(void);
|
||||||
#ifdef BSP_USING_EXTSRAM
|
#ifdef BSP_USING_EXTSRAM
|
||||||
|
@ -331,5 +335,8 @@ void InitBoardHardware()
|
||||||
Imxrt1052HwSdioInit();
|
Imxrt1052HwSdioInit();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef BSP_USING_WDT
|
||||||
|
Imxrt1052HwWdgInit();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,3 +48,11 @@ menuconfig BSP_USING_USB
|
||||||
if BSP_USING_USB
|
if BSP_USING_USB
|
||||||
source "$BSP_DIR/third_party_driver/usb/Kconfig"
|
source "$BSP_DIR/third_party_driver/usb/Kconfig"
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
menuconfig BSP_USING_WDT
|
||||||
|
bool "Using WATCHDOG TIMER device"
|
||||||
|
default n
|
||||||
|
select RESOURCES_WDT
|
||||||
|
if BSP_USING_WDT
|
||||||
|
source "$BSP_DIR/third_party_driver/wdt/Kconfig"
|
||||||
|
endif
|
||||||
|
|
|
@ -24,4 +24,8 @@ ifeq ($(CONFIG_BSP_USING_USB),y)
|
||||||
SRC_DIR += usb
|
SRC_DIR += usb
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_BSP_USING_WDT),y)
|
||||||
|
SRC_DIR += wdt
|
||||||
|
endif
|
||||||
|
|
||||||
include $(KERNEL_ROOT)/compiler.mk
|
include $(KERNEL_ROOT)/compiler.mk
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2020 AIIT XUOS Lab
|
||||||
|
* XiUOS is licensed under Mulan PSL v2.
|
||||||
|
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||||
|
* You may obtain a copy of Mulan PSL v2 at:
|
||||||
|
* http://license.coscl.org.cn/MulanPSL2
|
||||||
|
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||||
|
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||||
|
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the Mulan PSL v2 for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file connect_wdt.h
|
||||||
|
* @brief define imxrt1052-board watchdog function and struct
|
||||||
|
* @version 2.0
|
||||||
|
* @author AIIT XUOS Lab
|
||||||
|
* @date 2022-05-06
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef CONNECT_WDT_H
|
||||||
|
#define CONNECT_WDT_H
|
||||||
|
|
||||||
|
#include <device.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int Imxrt1052HwWdgInit(void);
|
||||||
|
|
||||||
|
int StartWatchdog(void);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,312 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2016, Freescale Semiconductor, Inc.
|
||||||
|
* Copyright 2016-2018 NXP
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
*/
|
||||||
|
#ifndef _FSL_WDOG_H_
|
||||||
|
#define _FSL_WDOG_H_
|
||||||
|
|
||||||
|
#include "fsl_common.h"
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @addtogroup wdog
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
* Definitions
|
||||||
|
*******************************************************************************/
|
||||||
|
/*! @name Driver version */
|
||||||
|
/*@{*/
|
||||||
|
/*! @brief Defines WDOG driver version */
|
||||||
|
#define FSL_WDOG_DRIVER_VERSION (MAKE_VERSION(2, 1, 0))
|
||||||
|
/*@}*/
|
||||||
|
/*! @name Refresh sequence */
|
||||||
|
/*@{*/
|
||||||
|
#define WDOG_REFRESH_KEY (0xAAAA5555U)
|
||||||
|
/*@}*/
|
||||||
|
|
||||||
|
/*! @brief Defines WDOG work mode. */
|
||||||
|
typedef struct _wdog_work_mode
|
||||||
|
{
|
||||||
|
bool enableWait; /*!< continue or suspend WDOG in wait mode */
|
||||||
|
bool enableStop; /*!< continue or suspend WDOG in stop mode */
|
||||||
|
bool enableDebug; /*!< continue or suspend WDOG in debug mode */
|
||||||
|
} wdog_work_mode_t;
|
||||||
|
|
||||||
|
/*! @brief Describes WDOG configuration structure. */
|
||||||
|
typedef struct _wdog_config
|
||||||
|
{
|
||||||
|
bool enableWdog; /*!< Enables or disables WDOG */
|
||||||
|
wdog_work_mode_t workMode; /*!< Configures WDOG work mode in debug stop and wait mode */
|
||||||
|
bool enableInterrupt; /*!< Enables or disables WDOG interrupt */
|
||||||
|
uint16_t timeoutValue; /*!< Timeout value */
|
||||||
|
uint16_t interruptTimeValue; /*!< Interrupt count timeout value */
|
||||||
|
bool softwareResetExtension; /*!< software reset extension */
|
||||||
|
bool enablePowerDown; /*!< power down enable bit */
|
||||||
|
bool enableTimeOutAssert; /*!< Enable WDOG_B timeout assertion. */
|
||||||
|
} wdog_config_t;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief WDOG interrupt configuration structure, default settings all disabled.
|
||||||
|
*
|
||||||
|
* This structure contains the settings for all of the WDOG interrupt configurations.
|
||||||
|
*/
|
||||||
|
enum _wdog_interrupt_enable
|
||||||
|
{
|
||||||
|
kWDOG_InterruptEnable = WDOG_WICR_WIE_MASK /*!< WDOG timeout generates an interrupt before reset*/
|
||||||
|
};
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief WDOG status flags.
|
||||||
|
*
|
||||||
|
* This structure contains the WDOG status flags for use in the WDOG functions.
|
||||||
|
*/
|
||||||
|
enum _wdog_status_flags
|
||||||
|
{
|
||||||
|
kWDOG_RunningFlag = WDOG_WCR_WDE_MASK, /*!< Running flag, set when WDOG is enabled*/
|
||||||
|
kWDOG_PowerOnResetFlag = WDOG_WRSR_POR_MASK, /*!< Power On flag, set when reset is the result of a powerOnReset*/
|
||||||
|
kWDOG_TimeoutResetFlag = WDOG_WRSR_TOUT_MASK, /*!< Timeout flag, set when reset is the result of a timeout*/
|
||||||
|
kWDOG_SoftwareResetFlag = WDOG_WRSR_SFTW_MASK, /*!< Software flag, set when reset is the result of a software*/
|
||||||
|
kWDOG_InterruptFlag = WDOG_WICR_WTIS_MASK /*!< interrupt flag,whether interrupt has occurred or not*/
|
||||||
|
};
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
* API
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
extern "C" {
|
||||||
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @name WDOG Initialization and De-initialization.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Initializes the WDOG configuration structure.
|
||||||
|
*
|
||||||
|
* This function initializes the WDOG configuration structure to default values. The default
|
||||||
|
* values are as follows.
|
||||||
|
* @code
|
||||||
|
* wdogConfig->enableWdog = true;
|
||||||
|
* wdogConfig->workMode.enableWait = true;
|
||||||
|
* wdogConfig->workMode.enableStop = false;
|
||||||
|
* wdogConfig->workMode.enableDebug = false;
|
||||||
|
* wdogConfig->enableInterrupt = false;
|
||||||
|
* wdogConfig->enablePowerdown = false;
|
||||||
|
* wdogConfig->resetExtension = flase;
|
||||||
|
* wdogConfig->timeoutValue = 0xFFU;
|
||||||
|
* wdogConfig->interruptTimeValue = 0x04u;
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @param config Pointer to the WDOG configuration structure.
|
||||||
|
* @see wdog_config_t
|
||||||
|
*/
|
||||||
|
void WDOG_GetDefaultConfig(wdog_config_t *config);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Initializes the WDOG.
|
||||||
|
*
|
||||||
|
* This function initializes the WDOG. When called, the WDOG runs according to the configuration.
|
||||||
|
*
|
||||||
|
* This is an example.
|
||||||
|
* @code
|
||||||
|
* wdog_config_t config;
|
||||||
|
* WDOG_GetDefaultConfig(&config);
|
||||||
|
* config.timeoutValue = 0xffU;
|
||||||
|
* config->interruptTimeValue = 0x04u;
|
||||||
|
* WDOG_Init(wdog_base,&config);
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @param base WDOG peripheral base address
|
||||||
|
* @param config The configuration of WDOG
|
||||||
|
*/
|
||||||
|
void WDOG_Init(WDOG_Type *base, const wdog_config_t *config);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Shuts down the WDOG.
|
||||||
|
*
|
||||||
|
* This function shuts down the WDOG.
|
||||||
|
* Watchdog Enable bit is a write one once only bit. It is not
|
||||||
|
* possible to clear this bit by a software write, once the bit is set.
|
||||||
|
* This bit(WDE) can be set/reset only in debug mode(exception).
|
||||||
|
*/
|
||||||
|
void WDOG_Deinit(WDOG_Type *base);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Enables the WDOG module.
|
||||||
|
*
|
||||||
|
* This function writes a value into the WDOG_WCR register to enable the WDOG.
|
||||||
|
* This is a write one once only bit. It is not possible to clear this bit by a software write,
|
||||||
|
* once the bit is set. only debug mode exception.
|
||||||
|
* @param base WDOG peripheral base address
|
||||||
|
*/
|
||||||
|
static inline void WDOG_Enable(WDOG_Type *base)
|
||||||
|
{
|
||||||
|
base->WCR |= WDOG_WCR_WDE_MASK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static inline void SET_WDOG_WDT(WDOG_Type *base)
|
||||||
|
{
|
||||||
|
base->WCR |= WDOG_WCR_WDT_MASK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Disables the WDOG module.
|
||||||
|
*
|
||||||
|
* This function writes a value into the WDOG_WCR register to disable the WDOG.
|
||||||
|
* This is a write one once only bit. It is not possible to clear this bit by a software write,once the bit is set.
|
||||||
|
* only debug mode exception
|
||||||
|
* @param base WDOG peripheral base address
|
||||||
|
*/
|
||||||
|
static inline void WDOG_Disable(WDOG_Type *base)
|
||||||
|
{
|
||||||
|
base->WCR &= ~WDOG_WCR_WDE_MASK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Trigger the system software reset.
|
||||||
|
*
|
||||||
|
* This function will write to the WCR[SRS] bit to trigger a software system reset.
|
||||||
|
* This bit will automatically resets to "1" after it has been asserted to "0".
|
||||||
|
* Note: Calling this API will reset the system right now, please using it with more attention.
|
||||||
|
*
|
||||||
|
* @param base WDOG peripheral base address
|
||||||
|
*/
|
||||||
|
static inline void WDOG_TriggerSystemSoftwareReset(WDOG_Type *base)
|
||||||
|
{
|
||||||
|
base->WCR &= ~WDOG_WCR_SRS_MASK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Trigger an output assertion.
|
||||||
|
*
|
||||||
|
* This function will write to the WCR[WDA] bit to trigger WDOG_B signal assertion.
|
||||||
|
* The WDOG_B signal can be routed to external pin of the chip, the output pin will turn to
|
||||||
|
* assertion along with WDOG_B signal.
|
||||||
|
* Note: The WDOG_B signal will remain assert until a power on reset occurred, so, please
|
||||||
|
* take more attention while calling it.
|
||||||
|
*
|
||||||
|
* @param base WDOG peripheral base address
|
||||||
|
*/
|
||||||
|
static inline void WDOG_TriggerSoftwareSignal(WDOG_Type *base)
|
||||||
|
{
|
||||||
|
base->WCR &= ~WDOG_WCR_WDA_MASK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Enables the WDOG interrupt.
|
||||||
|
*
|
||||||
|
*This bit is a write once only bit. Once the software does a write access to this bit, it will get
|
||||||
|
*locked and cannot be reprogrammed until the next system reset assertion
|
||||||
|
*
|
||||||
|
* @param base WDOG peripheral base address
|
||||||
|
* @param mask The interrupts to enable
|
||||||
|
* The parameter can be combination of the following source if defined.
|
||||||
|
* @arg kWDOG_InterruptEnable
|
||||||
|
*/
|
||||||
|
static inline void WDOG_EnableInterrupts(WDOG_Type *base, uint16_t mask)
|
||||||
|
{
|
||||||
|
base->WICR |= mask;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Gets the WDOG all reset status flags.
|
||||||
|
*
|
||||||
|
* This function gets all reset status flags.
|
||||||
|
*
|
||||||
|
* @code
|
||||||
|
* uint16_t status;
|
||||||
|
* status = WDOG_GetStatusFlags (wdog_base);
|
||||||
|
* @endcode
|
||||||
|
* @param base WDOG peripheral base address
|
||||||
|
* @return State of the status flag: asserted (true) or not-asserted (false).@see _wdog_status_flags
|
||||||
|
* - true: a related status flag has been set.
|
||||||
|
* - false: a related status flag is not set.
|
||||||
|
*/
|
||||||
|
uint16_t WDOG_GetStatusFlags(WDOG_Type *base);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Clears the WDOG flag.
|
||||||
|
*
|
||||||
|
* This function clears the WDOG status flag.
|
||||||
|
*
|
||||||
|
* This is an example for clearing the interrupt flag.
|
||||||
|
* @code
|
||||||
|
* WDOG_ClearStatusFlags(wdog_base,KWDOG_InterruptFlag);
|
||||||
|
* @endcode
|
||||||
|
* @param base WDOG peripheral base address
|
||||||
|
* @param mask The status flags to clear.
|
||||||
|
* The parameter could be any combination of the following values.
|
||||||
|
* kWDOG_TimeoutFlag
|
||||||
|
*/
|
||||||
|
void WDOG_ClearInterruptStatus(WDOG_Type *base, uint16_t mask);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Sets the WDOG timeout value.
|
||||||
|
*
|
||||||
|
* This function sets the timeout value.
|
||||||
|
* This function writes a value into WCR registers.
|
||||||
|
* The time-out value can be written at any point of time but it is loaded to the counter at the time
|
||||||
|
* when WDOG is enabled or after the service routine has been performed.
|
||||||
|
*
|
||||||
|
* @param base WDOG peripheral base address
|
||||||
|
* @param timeoutCount WDOG timeout value; count of WDOG clock tick.
|
||||||
|
*/
|
||||||
|
static inline void WDOG_SetTimeoutValue(WDOG_Type *base, uint16_t timeoutCount)
|
||||||
|
{
|
||||||
|
base->WCR = (base->WCR & ~WDOG_WCR_WT_MASK) | WDOG_WCR_WT(timeoutCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Sets the WDOG interrupt count timeout value.
|
||||||
|
*
|
||||||
|
* This function sets the interrupt count timeout value.
|
||||||
|
* This function writes a value into WIC registers which are wirte-once.
|
||||||
|
* This field is write once only. Once the software does a write access to this field, it will get locked
|
||||||
|
* and cannot be reprogrammed until the next system reset assertion.
|
||||||
|
* @param base WDOG peripheral base address
|
||||||
|
* @param timeoutCount WDOG timeout value; count of WDOG clock tick.
|
||||||
|
*/
|
||||||
|
static inline void WDOG_SetInterrputTimeoutValue(WDOG_Type *base, uint16_t timeoutCount)
|
||||||
|
{
|
||||||
|
base->WICR = (base->WICR & ~WDOG_WICR_WICT_MASK) | WDOG_WICR_WICT(timeoutCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Disable the WDOG power down enable bit.
|
||||||
|
*
|
||||||
|
* This function disable the WDOG power down enable(PDE).
|
||||||
|
* This function writes a value into WMCR registers which are wirte-once.
|
||||||
|
* This field is write once only. Once software sets this bit it cannot be reset until the next system reset.
|
||||||
|
* @param base WDOG peripheral base address
|
||||||
|
*/
|
||||||
|
static inline void WDOG_DisablePowerDownEnable(WDOG_Type *base)
|
||||||
|
{
|
||||||
|
base->WMCR &= ~WDOG_WMCR_PDE_MASK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Refreshes the WDOG timer.
|
||||||
|
*
|
||||||
|
* This function feeds the WDOG.
|
||||||
|
* This function should be called before the WDOG timer is in timeout. Otherwise, a reset is asserted.
|
||||||
|
*
|
||||||
|
* @param base WDOG peripheral base address
|
||||||
|
*/
|
||||||
|
void WDOG_Refresh(WDOG_Type *base);
|
||||||
|
/*@}*/
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
}
|
||||||
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
|
/*! @}*/
|
||||||
|
|
||||||
|
#endif /* _FSL_WDOG_H_ */
|
|
@ -0,0 +1,13 @@
|
||||||
|
if BSP_USING_WDT
|
||||||
|
config WDT_BUS_NAME
|
||||||
|
string "watchdog bus name"
|
||||||
|
default "wdt"
|
||||||
|
|
||||||
|
config WDT_DRIVER_NAME
|
||||||
|
string "watchdog driver name"
|
||||||
|
default "wdt_drv"
|
||||||
|
|
||||||
|
config WDT_DEVICE_NAME
|
||||||
|
string "watchdog device name"
|
||||||
|
default "wdt_dev"
|
||||||
|
endif
|
|
@ -0,0 +1,3 @@
|
||||||
|
SRC_FILES := connect_wdt.c fsl_wdog.c
|
||||||
|
|
||||||
|
include $(KERNEL_ROOT)/compiler.mk
|
|
@ -0,0 +1,182 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2020 AIIT XUOS Lab
|
||||||
|
* XiUOS is licensed under Mulan PSL v2.
|
||||||
|
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||||
|
* You may obtain a copy of Mulan PSL v2 at:
|
||||||
|
* http://license.coscl.org.cn/MulanPSL2
|
||||||
|
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||||
|
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||||
|
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the Mulan PSL v2 for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file connect_wdt.c
|
||||||
|
* @brief support imxrt1052-board watchdog(WDG1) function and register to bus framework
|
||||||
|
* @version 2.0
|
||||||
|
* @author AIIT XUOS Lab
|
||||||
|
* @date 2022-05-06
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <connect_wdt.h>
|
||||||
|
#include <fsl_wdog.h>
|
||||||
|
|
||||||
|
static BusType wdt;
|
||||||
|
static wdog_config_t wdog_config_t_param;
|
||||||
|
|
||||||
|
void WDOG1_IRQHandler(void)
|
||||||
|
{
|
||||||
|
WDOG_ClearInterruptStatus(WDOG1, kWDOG_InterruptFlag);
|
||||||
|
/* User code. User can do urgent case before timeout reset.
|
||||||
|
* IE. user can backup the ram data or ram log to flash.
|
||||||
|
* the period is set by config.interruptTimeValue, user need to
|
||||||
|
* check the period between interrupt and timeout.
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint32 Imxrt1052WdgOpen(void *dev)
|
||||||
|
{
|
||||||
|
return EOK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint32 Imxrt1052WdgClose(void *dev)
|
||||||
|
{
|
||||||
|
WDOG_Deinit(WDOG1);
|
||||||
|
|
||||||
|
return EOK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int Imxrt1052WdgInit(struct WdtHardwareDevice *dev, uint16_t timeout)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* wdogConfig->enableWdog = true;
|
||||||
|
* wdogConfig->workMode.enableWait = true;
|
||||||
|
* wdogConfig->workMode.enableStop = false;
|
||||||
|
* wdogConfig->workMode.enableDebug = false;
|
||||||
|
* wdogConfig->enableInterrupt = false;
|
||||||
|
* wdogConfig->enablePowerdown = false;
|
||||||
|
* wdogConfig->resetExtension = flase;
|
||||||
|
* wdogConfig->timeoutValue = 0xFFU;
|
||||||
|
* wdogConfig->interruptTimeValue = 0x04u;
|
||||||
|
*/
|
||||||
|
WDOG_GetDefaultConfig(&wdog_config_t_param);
|
||||||
|
wdog_config_t_param.timeoutValue = timeout; /* Timeout value is 1 sec / 6.4 num, 5s means 32. */
|
||||||
|
WDOG_Init(WDOG1, &wdog_config_t_param);
|
||||||
|
|
||||||
|
return EOK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint32 Imxrt1052WdgConfigure(void *drv, struct BusConfigureInfo *args)
|
||||||
|
{
|
||||||
|
struct WdtDriver *wdt_drv = (struct WdtDriver *)drv;
|
||||||
|
struct WdtHardwareDevice *wdt_dev = (struct WdtHardwareDevice *)wdt_drv->driver.owner_bus->owner_haldev;
|
||||||
|
|
||||||
|
uint16_t timeout;
|
||||||
|
|
||||||
|
switch(args->configure_cmd)
|
||||||
|
{
|
||||||
|
case OPER_WDT_SET_TIMEOUT:
|
||||||
|
timeout = *(uint16_t *)(args->private_data);
|
||||||
|
if (timeout) {
|
||||||
|
Imxrt1052WdgInit(wdt_dev, timeout);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case OPER_WDT_KEEPALIVE:
|
||||||
|
WDOG_Refresh(WDOG1);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return ERROR;
|
||||||
|
}
|
||||||
|
return EOK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct WdtDevDone dev_done =
|
||||||
|
{
|
||||||
|
Imxrt1052WdgOpen,
|
||||||
|
Imxrt1052WdgClose,
|
||||||
|
NONE,
|
||||||
|
NONE,
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: Feed watchdog task function
|
||||||
|
*/
|
||||||
|
static void FeedWatchdogTask(void)
|
||||||
|
{
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
/* keep watchdog alive in idle task */
|
||||||
|
struct BusConfigureInfo cfg;
|
||||||
|
cfg.configure_cmd = OPER_WDT_KEEPALIVE;
|
||||||
|
cfg.private_data = NONE;
|
||||||
|
BusDrvConfigure(wdt->owner_driver, &cfg);
|
||||||
|
MdelayKTask(500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: Watchdog function
|
||||||
|
* @return success: EOK, failure: other
|
||||||
|
*/
|
||||||
|
int StartWatchdog(void)
|
||||||
|
{
|
||||||
|
int ret = EOK;
|
||||||
|
uint16_t timeout = 32; /* timeout time 5s*/
|
||||||
|
|
||||||
|
wdt = BusFind(WDT_BUS_NAME);
|
||||||
|
wdt->owner_driver = BusFindDriver(wdt, WDT_DRIVER_NAME);
|
||||||
|
|
||||||
|
/* set watchdog timeout time */
|
||||||
|
struct BusConfigureInfo cfg;
|
||||||
|
cfg.configure_cmd = OPER_WDT_SET_TIMEOUT;
|
||||||
|
cfg.private_data = &timeout;
|
||||||
|
ret = BusDrvConfigure(wdt->owner_driver, &cfg);
|
||||||
|
|
||||||
|
int32 WdtTask = KTaskCreate("WdtTask", (void *)FeedWatchdogTask, NONE, 1024, 20);
|
||||||
|
StartupKTask(WdtTask);
|
||||||
|
|
||||||
|
return EOK;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Imxrt1052HwWdgInit(void)
|
||||||
|
{
|
||||||
|
x_err_t ret = EOK;
|
||||||
|
|
||||||
|
static struct WdtBus watch_dog_timer_bus;
|
||||||
|
static struct WdtDriver watch_dog_timer_drv;
|
||||||
|
static struct WdtHardwareDevice watch_dog_timer_dev;
|
||||||
|
|
||||||
|
ret = WdtBusInit(&watch_dog_timer_bus, WDT_BUS_NAME);
|
||||||
|
if (ret != EOK) {
|
||||||
|
KPrintf("Watchdog bus init error %d\n", ret);
|
||||||
|
return ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
watch_dog_timer_drv.configure = Imxrt1052WdgConfigure;
|
||||||
|
ret = WdtDriverInit(&watch_dog_timer_drv, WDT_DRIVER_NAME);
|
||||||
|
if (ret != EOK) {
|
||||||
|
KPrintf("Watchdog driver init error %d\n", ret);
|
||||||
|
return ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = WdtDriverAttachToBus(WDT_DRIVER_NAME, WDT_BUS_NAME);
|
||||||
|
if (ret != EOK) {
|
||||||
|
KPrintf("Watchdog driver attach error %d\n", ret);
|
||||||
|
return ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
watch_dog_timer_dev.dev_done = &dev_done;
|
||||||
|
|
||||||
|
ret = WdtDeviceRegister(&watch_dog_timer_dev, WDT_DEVICE_NAME);
|
||||||
|
if (ret != EOK) {
|
||||||
|
KPrintf("Watchdog device register error %d\n", ret);
|
||||||
|
return ERROR;
|
||||||
|
}
|
||||||
|
ret = WdtDeviceAttachToBus(WDT_DEVICE_NAME, WDT_BUS_NAME);
|
||||||
|
if (ret != EOK) {
|
||||||
|
KPrintf("Watchdog device register error %d\n", ret);
|
||||||
|
return ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
|
@ -0,0 +1,206 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2016, Freescale Semiconductor, Inc.
|
||||||
|
* Copyright 2016-2018 NXP
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "fsl_wdog.h"
|
||||||
|
|
||||||
|
/* Component ID definition, used by tools. */
|
||||||
|
#ifndef FSL_COMPONENT_ID
|
||||||
|
#define FSL_COMPONENT_ID "platform.drivers.wdog01"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
* Variables
|
||||||
|
******************************************************************************/
|
||||||
|
static WDOG_Type *const s_wdogBases[] = WDOG_BASE_PTRS;
|
||||||
|
#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
|
||||||
|
/* Array of WDOG clock name. */
|
||||||
|
static const clock_ip_name_t s_wdogClock[] = WDOG_CLOCKS;
|
||||||
|
#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
|
||||||
|
|
||||||
|
static const IRQn_Type s_wdogIRQ[] = WDOG_IRQS;
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
* Code
|
||||||
|
******************************************************************************/
|
||||||
|
static uint32_t WDOG_GetInstance(WDOG_Type *base)
|
||||||
|
{
|
||||||
|
uint32_t instance;
|
||||||
|
|
||||||
|
/* Find the instance index from base address mappings. */
|
||||||
|
for (instance = 0; instance < ARRAY_SIZE(s_wdogBases); instance++)
|
||||||
|
{
|
||||||
|
if (s_wdogBases[instance] == base)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(instance < ARRAY_SIZE(s_wdogBases));
|
||||||
|
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* brief Initializes the WDOG configuration structure.
|
||||||
|
*
|
||||||
|
* This function initializes the WDOG configuration structure to default values. The default
|
||||||
|
* values are as follows.
|
||||||
|
* code
|
||||||
|
* wdogConfig->enableWdog = true;
|
||||||
|
* wdogConfig->workMode.enableWait = true;
|
||||||
|
* wdogConfig->workMode.enableStop = false;
|
||||||
|
* wdogConfig->workMode.enableDebug = false;
|
||||||
|
* wdogConfig->enableInterrupt = false;
|
||||||
|
* wdogConfig->enablePowerdown = false;
|
||||||
|
* wdogConfig->resetExtension = flase;
|
||||||
|
* wdogConfig->timeoutValue = 0xFFU;
|
||||||
|
* wdogConfig->interruptTimeValue = 0x04u;
|
||||||
|
* endcode
|
||||||
|
*
|
||||||
|
* param config Pointer to the WDOG configuration structure.
|
||||||
|
* see wdog_config_t
|
||||||
|
*/
|
||||||
|
void WDOG_GetDefaultConfig(wdog_config_t *config)
|
||||||
|
{
|
||||||
|
assert(config);
|
||||||
|
|
||||||
|
/* Initializes the configure structure to zero. */
|
||||||
|
memset(config, 0, sizeof(*config));
|
||||||
|
|
||||||
|
config->enableWdog = true;
|
||||||
|
config->workMode.enableWait = false;
|
||||||
|
config->workMode.enableStop = false;
|
||||||
|
config->workMode.enableDebug = false;
|
||||||
|
config->enableInterrupt = false;
|
||||||
|
config->softwareResetExtension = false;
|
||||||
|
config->enablePowerDown = false;
|
||||||
|
config->timeoutValue = 0xffu;
|
||||||
|
config->interruptTimeValue = 0x04u;
|
||||||
|
config->enableTimeOutAssert = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* brief Initializes the WDOG.
|
||||||
|
*
|
||||||
|
* This function initializes the WDOG. When called, the WDOG runs according to the configuration.
|
||||||
|
*
|
||||||
|
* This is an example.
|
||||||
|
* code
|
||||||
|
* wdog_config_t config;
|
||||||
|
* WDOG_GetDefaultConfig(&config);
|
||||||
|
* config.timeoutValue = 0xffU;
|
||||||
|
* config->interruptTimeValue = 0x04u;
|
||||||
|
* WDOG_Init(wdog_base,&config);
|
||||||
|
* endcode
|
||||||
|
*
|
||||||
|
* param base WDOG peripheral base address
|
||||||
|
* param config The configuration of WDOG
|
||||||
|
*/
|
||||||
|
void WDOG_Init(WDOG_Type *base, const wdog_config_t *config)
|
||||||
|
{
|
||||||
|
assert(config);
|
||||||
|
|
||||||
|
uint16_t value = 0u;
|
||||||
|
|
||||||
|
value = WDOG_WCR_WDE(config->enableWdog) | WDOG_WCR_WDW(config->workMode.enableWait) |
|
||||||
|
WDOG_WCR_WDZST(config->workMode.enableStop) | WDOG_WCR_WDBG(config->workMode.enableDebug) |
|
||||||
|
WDOG_WCR_SRE(config->softwareResetExtension) | WDOG_WCR_WT(config->timeoutValue) |
|
||||||
|
WDOG_WCR_WDT(config->enableTimeOutAssert) | WDOG_WCR_SRS_MASK | WDOG_WCR_WDA_MASK;
|
||||||
|
|
||||||
|
#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
|
||||||
|
/* Set configuration */
|
||||||
|
CLOCK_EnableClock(s_wdogClock[WDOG_GetInstance(base)]);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
base->WICR = WDOG_WICR_WICT(config->interruptTimeValue) | WDOG_WICR_WIE(config->enableInterrupt);
|
||||||
|
base->WMCR = WDOG_WMCR_PDE(config->enablePowerDown);
|
||||||
|
base->WCR = value;
|
||||||
|
if (config->enableInterrupt)
|
||||||
|
{
|
||||||
|
EnableIRQ(s_wdogIRQ[WDOG_GetInstance(base)]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* brief Shuts down the WDOG.
|
||||||
|
*
|
||||||
|
* This function shuts down the WDOG.
|
||||||
|
* Watchdog Enable bit is a write one once only bit. It is not
|
||||||
|
* possible to clear this bit by a software write, once the bit is set.
|
||||||
|
* This bit(WDE) can be set/reset only in debug mode(exception).
|
||||||
|
*/
|
||||||
|
void WDOG_Deinit(WDOG_Type *base)
|
||||||
|
{
|
||||||
|
if (base->WCR & WDOG_WCR_WDBG_MASK)
|
||||||
|
{
|
||||||
|
WDOG_Disable(base);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* brief Gets the WDOG all reset status flags.
|
||||||
|
*
|
||||||
|
* This function gets all reset status flags.
|
||||||
|
*
|
||||||
|
* code
|
||||||
|
* uint16_t status;
|
||||||
|
* status = WDOG_GetStatusFlags (wdog_base);
|
||||||
|
* endcode
|
||||||
|
* param base WDOG peripheral base address
|
||||||
|
* return State of the status flag: asserted (true) or not-asserted (false).see _wdog_status_flags
|
||||||
|
* - true: a related status flag has been set.
|
||||||
|
* - false: a related status flag is not set.
|
||||||
|
*/
|
||||||
|
uint16_t WDOG_GetStatusFlags(WDOG_Type *base)
|
||||||
|
{
|
||||||
|
uint16_t status_flag = 0U;
|
||||||
|
|
||||||
|
status_flag |= (base->WCR & WDOG_WCR_WDE_MASK);
|
||||||
|
status_flag |= (base->WRSR & WDOG_WRSR_POR_MASK);
|
||||||
|
status_flag |= (base->WRSR & WDOG_WRSR_TOUT_MASK);
|
||||||
|
status_flag |= (base->WRSR & WDOG_WRSR_SFTW_MASK);
|
||||||
|
status_flag |= (base->WICR & WDOG_WICR_WTIS_MASK);
|
||||||
|
|
||||||
|
return status_flag;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* brief Clears the WDOG flag.
|
||||||
|
*
|
||||||
|
* This function clears the WDOG status flag.
|
||||||
|
*
|
||||||
|
* This is an example for clearing the interrupt flag.
|
||||||
|
* code
|
||||||
|
* WDOG_ClearStatusFlags(wdog_base,KWDOG_InterruptFlag);
|
||||||
|
* endcode
|
||||||
|
* param base WDOG peripheral base address
|
||||||
|
* param mask The status flags to clear.
|
||||||
|
* The parameter could be any combination of the following values.
|
||||||
|
* kWDOG_TimeoutFlag
|
||||||
|
*/
|
||||||
|
void WDOG_ClearInterruptStatus(WDOG_Type *base, uint16_t mask)
|
||||||
|
{
|
||||||
|
if (mask & kWDOG_InterruptFlag)
|
||||||
|
{
|
||||||
|
base->WICR |= WDOG_WICR_WTIS_MASK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* brief Refreshes the WDOG timer.
|
||||||
|
*
|
||||||
|
* This function feeds the WDOG.
|
||||||
|
* This function should be called before the WDOG timer is in timeout. Otherwise, a reset is asserted.
|
||||||
|
*
|
||||||
|
* param base WDOG peripheral base address
|
||||||
|
*/
|
||||||
|
void WDOG_Refresh(WDOG_Type *base)
|
||||||
|
{
|
||||||
|
base->WSR = WDOG_REFRESH_KEY & 0xFFFFU;
|
||||||
|
base->WSR = (WDOG_REFRESH_KEY >> 16U) & 0xFFFFU;
|
||||||
|
}
|
|
@ -28,14 +28,17 @@ static BusType wdt;
|
||||||
*/
|
*/
|
||||||
static void FeedWatchdog(void)
|
static void FeedWatchdog(void)
|
||||||
{
|
{
|
||||||
while (1)
|
int cnt = 0;
|
||||||
|
while (cnt < 20)
|
||||||
{
|
{
|
||||||
/* keep watchdog alive in idle task */
|
/* keep watchdog alive in idle task */
|
||||||
struct BusConfigureInfo cfg;
|
struct BusConfigureInfo cfg;
|
||||||
cfg.configure_cmd = OPER_WDT_KEEPALIVE;
|
cfg.configure_cmd = OPER_WDT_KEEPALIVE;
|
||||||
cfg.private_data = NONE;
|
cfg.private_data = NONE;
|
||||||
BusDrvConfigure(wdt->owner_driver, &cfg);
|
BusDrvConfigure(wdt->owner_driver, &cfg);
|
||||||
KPrintf("feed the dog!\n ");
|
KPrintf("feed the dog! cnt %u\n", cnt);
|
||||||
|
cnt++;
|
||||||
|
MdelayKTask(1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,18 +49,17 @@ static void FeedWatchdog(void)
|
||||||
int TestIwg(void)
|
int TestIwg(void)
|
||||||
{
|
{
|
||||||
x_err_t res = EOK;
|
x_err_t res = EOK;
|
||||||
uint32 timeout = 1000; /* timeout time */
|
uint16 timeout = 1000; /* timeout time */
|
||||||
|
|
||||||
wdt = BusFind(WDT_BUS_NAME_0);
|
wdt = BusFind(WDT_BUS_NAME);
|
||||||
wdt->owner_driver = BusFindDriver(wdt, WDT_DRIVER_NAME_0);
|
wdt->owner_driver = BusFindDriver(wdt, WDT_DRIVER_NAME);
|
||||||
wdt->owner_haldev = BusFindDevice(wdt, WDT_0_DEVICE_NAME_0);
|
wdt->owner_haldev = BusFindDevice(wdt, WDT_DEVICE_NAME);
|
||||||
|
|
||||||
/* set watchdog timeout time */
|
/* set watchdog timeout time */
|
||||||
struct BusConfigureInfo cfg;
|
struct BusConfigureInfo cfg;
|
||||||
cfg.configure_cmd = OPER_WDT_SET_TIMEOUT;
|
cfg.configure_cmd = OPER_WDT_SET_TIMEOUT;
|
||||||
cfg.private_data = &timeout;
|
cfg.private_data = &timeout;
|
||||||
res = BusDrvConfigure(wdt->owner_driver, &cfg);
|
res = BusDrvConfigure(wdt->owner_driver, &cfg);
|
||||||
KPrintf("feed the dog!\n");
|
|
||||||
|
|
||||||
int32 WdtTask = KTaskCreate("WdtTask", (void *)FeedWatchdog, NONE, 2048, 20);
|
int32 WdtTask = KTaskCreate("WdtTask", (void *)FeedWatchdog, NONE, 2048, 20);
|
||||||
res = StartupKTask(WdtTask);
|
res = StartupKTask(WdtTask);
|
||||||
|
|
|
@ -31,6 +31,10 @@
|
||||||
#include "connect_usb.h"
|
#include "connect_usb.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef BSP_USING_WDT
|
||||||
|
#include "connect_wdt.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef KERNEL_USER_MAIN
|
#ifdef KERNEL_USER_MAIN
|
||||||
#ifndef MAIN_KTASK_STACK_SIZE
|
#ifndef MAIN_KTASK_STACK_SIZE
|
||||||
#define MAIN_KTASK_STACK_SIZE 2048
|
#define MAIN_KTASK_STACK_SIZE 2048
|
||||||
|
@ -242,6 +246,10 @@ extern int InitUserspace(void);
|
||||||
HwLockSpinlock(&AssignSpinLock);
|
HwLockSpinlock(&AssignSpinLock);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef BSP_USING_WDT
|
||||||
|
StartWatchdog();
|
||||||
|
#endif
|
||||||
|
|
||||||
StartupOsAssign();
|
StartupOsAssign();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -27,11 +27,11 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define OPE_INT 0x0000
|
#define OPE_INT 0x0000
|
||||||
#define OPE_CFG 0x0001
|
#define OPE_CFG 0x0001
|
||||||
|
|
||||||
#define OPER_WDT_SET_TIMEOUT 0x0002
|
#define OPER_WDT_SET_TIMEOUT 0x0002
|
||||||
#define OPER_WDT_KEEPALIVE 0x0003
|
#define OPER_WDT_KEEPALIVE 0x0003
|
||||||
|
|
||||||
typedef struct Bus *BusType;
|
typedef struct Bus *BusType;
|
||||||
typedef struct HardwareDev *HardwareDevType;
|
typedef struct HardwareDev *HardwareDevType;
|
||||||
|
|
Loading…
Reference in New Issue