forked from xuos/xiuos
support adapter_ethernet and adapter_lora function from Liu Weichao
it is OK
This commit is contained in:
commit
86b1d9c77d
|
@ -20,7 +20,9 @@ extern int Adapter4GInit(void);
|
|||
extern int AdapterNbiotInit(void);
|
||||
extern int AdapterBlueToothInit(void);
|
||||
extern int AdapterWifiInit(void);
|
||||
extern int AdapterEthernetInit(void);
|
||||
extern int AdapterZigbeeInit(void);
|
||||
extern int AdapterLoraInit(void);
|
||||
|
||||
extern int D124VoiceInit(void);
|
||||
extern int Hs300xTemperatureInit(void);
|
||||
|
@ -93,19 +95,25 @@ static struct InitDesc sensor_desc[] =
|
|||
static struct InitDesc connection_desc[] =
|
||||
{
|
||||
#ifdef CONNECTION_ADAPTER_4G
|
||||
{ "4G adpter", Adapter4GInit},
|
||||
{ "4G adapter", Adapter4GInit},
|
||||
#endif
|
||||
#ifdef CONNECTION_ADAPTER_NB
|
||||
{ "NB adpter", AdapterNbiotInit},
|
||||
#endif
|
||||
#ifdef CONNECTION_ADAPTER_ZIGBEE
|
||||
{ "zigbee adpter", AdapterZigbeeInit},
|
||||
{ "zigbee adapter", AdapterZigbeeInit},
|
||||
#endif
|
||||
#ifdef CONNECTION_ADAPTER_BLUETOOTH
|
||||
{ "BlueTooth adpter", AdapterBlueToothInit},
|
||||
{ "bluetooth adapter", AdapterBlueToothInit},
|
||||
#endif
|
||||
#ifdef CONNECTION_ADAPTER_WIFI
|
||||
{ "Wifi adpter", AdapterWifiInit},
|
||||
{ "wifi adapter", AdapterWifiInit},
|
||||
#endif
|
||||
#ifdef CONNECTION_ADAPTER_ETHERNET
|
||||
{ "ethernet adapter", AdapterEthernetInit},
|
||||
#endif
|
||||
#ifdef CONNECTION_ADAPTER_LORA
|
||||
{ "lora adapter", AdapterLoraInit},
|
||||
#endif
|
||||
{ "NULL", NULL },
|
||||
};
|
||||
|
|
|
@ -51,7 +51,7 @@ int Adapter4GInit(void)
|
|||
|
||||
struct Adapter *adapter = PrivMalloc(sizeof(struct Adapter));
|
||||
if (!adapter) {
|
||||
free(adapter);
|
||||
PrivFree(adapter);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -60,7 +60,7 @@ int Adapter4GInit(void)
|
|||
ret = Adapter4GRegister(adapter);
|
||||
if (ret < 0) {
|
||||
printf("Adapter4GInit register 4G adapter error\n");
|
||||
free(adapter);
|
||||
PrivFree(adapter);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,7 @@ int Adapter4GInit(void)
|
|||
AdapterProductInfoType product_info = Ec200tAttach(adapter);
|
||||
if (!product_info) {
|
||||
printf("Adapter4GInit ec200t attach error\n");
|
||||
free(adapter);
|
||||
PrivFree(adapter);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -395,7 +395,7 @@ int AdapterDeviceConnect(struct Adapter *adapter, enum NetRoleType net_role, con
|
|||
* @param priv_net_group - private net group
|
||||
* @return success: 0 , failure: other
|
||||
*/
|
||||
int AdapterDeviceJoin(struct Adapter *adapter, const char *priv_net_group)
|
||||
int AdapterDeviceJoin(struct Adapter *adapter, unsigned char *priv_net_group)
|
||||
{
|
||||
if (!adapter)
|
||||
return -1;
|
||||
|
@ -419,9 +419,10 @@ int AdapterDeviceJoin(struct Adapter *adapter, const char *priv_net_group)
|
|||
/**
|
||||
* @description: Adapter disconnect from ip net or private net group
|
||||
* @param adapter - adapter device pointer
|
||||
* @param priv_net_group - private net group for PRIVATE_PROTOCOL quit function
|
||||
* @return success: 0 , failure: other
|
||||
*/
|
||||
int AdapterDeviceDisconnect(struct Adapter *adapter)
|
||||
int AdapterDeviceDisconnect(struct Adapter *adapter, unsigned char *priv_net_group)
|
||||
{
|
||||
if (!adapter)
|
||||
return -1;
|
||||
|
@ -432,7 +433,7 @@ int AdapterDeviceDisconnect(struct Adapter *adapter)
|
|||
if (NULL == priv_done->quit)
|
||||
return -1;
|
||||
|
||||
return priv_done->quit(adapter);
|
||||
return priv_done->quit(adapter, priv_net_group);
|
||||
} else if (IP_PROTOCOL == adapter->net_protocol) {
|
||||
struct IpProtocolDone *ip_done = (struct IpProtocolDone *)adapter->done;
|
||||
|
||||
|
|
|
@ -90,6 +90,7 @@ enum NetRoleType
|
|||
COORDINATOR,
|
||||
ROUTER,
|
||||
END_DEVICE,
|
||||
GATEWAY,
|
||||
ROLE_NONE,
|
||||
};
|
||||
|
||||
|
@ -147,10 +148,10 @@ struct PrivProtocolDone
|
|||
int (*setdhcp)(struct Adapter *adapter, int enable);
|
||||
int (*ping)(struct Adapter *adapter, const char *destination);
|
||||
int (*netstat)(struct Adapter *adapter);
|
||||
int (*join)(struct Adapter *adapter, const char *priv_net_group);
|
||||
int (*join)(struct Adapter *adapter, unsigned char *priv_net_group);
|
||||
int (*send)(struct Adapter *adapter, const void *buf, size_t len);
|
||||
int (*recv)(struct Adapter *adapter, void *buf, size_t len);
|
||||
int (*quit)(struct Adapter *adapter);
|
||||
int (*quit)(struct Adapter *adapter, unsigned char *priv_net_group);
|
||||
};
|
||||
|
||||
struct Adapter
|
||||
|
@ -164,6 +165,7 @@ struct Adapter
|
|||
|
||||
struct Socket socket;
|
||||
|
||||
int net_role_id;
|
||||
enum NetProtocolType net_protocol;
|
||||
enum NetRoleType net_role;
|
||||
enum AdapterStatus adapter_status;
|
||||
|
@ -171,6 +173,7 @@ struct Adapter
|
|||
char buffer[ADAPTER_BUFFSIZE];
|
||||
|
||||
void *done;
|
||||
void *adapter_param;
|
||||
|
||||
struct DoublelistNode link;
|
||||
};
|
||||
|
@ -206,10 +209,10 @@ int AdapterDeviceControl(struct Adapter *adapter, int cmd, void *args);
|
|||
int AdapterDeviceConnect(struct Adapter *adapter, enum NetRoleType net_role, const char *ip, const char *port, enum IpType ip_type);
|
||||
|
||||
/*Join to a certain private net, only support PRIVATE_PROTOCOL*/
|
||||
int AdapterDeviceJoin(struct Adapter *adapter, const char *priv_net_group);
|
||||
int AdapterDeviceJoin(struct Adapter *adapter, unsigned char *priv_net_group);
|
||||
|
||||
/*Adapter disconnect from ip net or private net group*/
|
||||
int AdapterDeviceDisconnect(struct Adapter *adapter);
|
||||
int AdapterDeviceDisconnect(struct Adapter *adapter, unsigned char *priv_net_group);
|
||||
|
||||
/*Set up to net*/
|
||||
int AdapterDeviceSetUp(struct Adapter *adapter);
|
||||
|
@ -220,10 +223,10 @@ int AdapterDeviceSetDown(struct Adapter *adapter);
|
|||
/*Set ip/gateway/netmask address*/
|
||||
int AdapterDeviceSetAddr(struct Adapter *adapter, const char *ip, const char *gateway, const char *netmask);
|
||||
|
||||
/**/
|
||||
/*Set DNS function*/
|
||||
int AdapterDeviceSetDns(struct Adapter *adapter, const char *dns_addr, uint8 dns_count);
|
||||
|
||||
/**/
|
||||
/*Set DHCP function*/
|
||||
int AdapterDeviceSetDhcp(struct Adapter *adapter, int enable);
|
||||
|
||||
/*ping function*/
|
||||
|
|
|
@ -117,10 +117,10 @@ int ParseATReply(char *str, const char *format, ...)
|
|||
return counts;
|
||||
}
|
||||
|
||||
uint32 ATSprintf(int fd, const char *format, va_list params)
|
||||
void ATSprintf(int fd, const char *format, va_list params)
|
||||
{
|
||||
last_cmd_len = vsnprintf(send_buf, sizeof(send_buf), format, params);
|
||||
printf("ATSprintf send %s len %u\n",send_buf, last_cmd_len);
|
||||
printf("AT send %s len %u\n",send_buf, last_cmd_len);
|
||||
PrivWrite(fd, send_buf, last_cmd_len);
|
||||
}
|
||||
|
||||
|
@ -128,7 +128,7 @@ int ATOrderSend(ATAgentType agent, uint32 timeout_s, ATReplyType reply, const ch
|
|||
{
|
||||
if (agent == NULL) {
|
||||
printf("ATAgent is null");
|
||||
return -ERROR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct timespec abstime;
|
||||
|
@ -145,7 +145,7 @@ int ATOrderSend(ATAgentType agent, uint32 timeout_s, ATReplyType reply, const ch
|
|||
|
||||
va_list params;
|
||||
uint32 cmd_size = 0;
|
||||
uint32 result = EOK;
|
||||
uint32 result = 0;
|
||||
const char *cmd = NULL;
|
||||
PrivMutexObtain(&agent->lock);
|
||||
|
||||
|
@ -156,7 +156,7 @@ int ATOrderSend(ATAgentType agent, uint32 timeout_s, ATReplyType reply, const ch
|
|||
va_start(params, cmd_expr);
|
||||
ATSprintf(agent->fd, cmd_expr, params);
|
||||
va_end(params);
|
||||
if (PrivSemaphoreObtainWait(&agent->rsp_sem, &abstime) != EOK) {
|
||||
if (PrivSemaphoreObtainWait(&agent->rsp_sem, &abstime) != 0) {
|
||||
result = -ETIMEOUT;
|
||||
goto __out;
|
||||
}
|
||||
|
@ -220,35 +220,35 @@ char *GetReplyText(ATReplyType reply)
|
|||
int AtSetReplyLrEnd(ATAgentType agent, char enable)
|
||||
{
|
||||
if (!agent) {
|
||||
return -ERROR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
agent->reply_lr_end = enable;
|
||||
|
||||
return EOK;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int AtSetReplyEndChar(ATAgentType agent, char last_ch, char end_ch)
|
||||
{
|
||||
if (!agent) {
|
||||
return -ERROR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
agent->reply_end_last_char = last_ch;
|
||||
agent->reply_end_char = end_ch;
|
||||
|
||||
return EOK;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int AtSetReplyCharNum(ATAgentType agent, unsigned int num)
|
||||
{
|
||||
if (!agent) {
|
||||
return -ERROR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
agent->reply_char_num = num;
|
||||
|
||||
return EOK;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int EntmSend(ATAgentType agent, const char *data, int len)
|
||||
|
@ -262,7 +262,7 @@ int EntmSend(ATAgentType agent, const char *data, int len)
|
|||
|
||||
PrivWrite(agent->fd, send_buf, len + 2);
|
||||
|
||||
return EOK;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int EntmRecv(ATAgentType agent, char *rev_buffer, int buffer_len, int timeout_s)
|
||||
|
@ -276,13 +276,13 @@ int EntmRecv(ATAgentType agent, char *rev_buffer, int buffer_len, int timeout_s)
|
|||
PrivTaskDelay(1000);
|
||||
|
||||
if (PrivSemaphoreObtainWait(&agent->entm_rx_notice, &abstime)) {
|
||||
return -ERROR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
PrivMutexObtain(&agent->lock);
|
||||
|
||||
if (buffer_len < agent->entm_recv_len) {
|
||||
return -ERROR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("EntmRecv once len %u.\n", agent->entm_recv_len);
|
||||
|
@ -295,7 +295,7 @@ int EntmRecv(ATAgentType agent, char *rev_buffer, int buffer_len, int timeout_s)
|
|||
|
||||
PrivMutexAbandon(&agent->lock);
|
||||
|
||||
return EOK;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int GetCompleteATReply(ATAgentType agent)
|
||||
|
@ -347,7 +347,7 @@ static int GetCompleteATReply(ATAgentType agent)
|
|||
printf("read line failed. The line data length is out of buffer size(%d)!", agent->maintain_max);
|
||||
memset(agent->maintain_buffer, 0x00, agent->maintain_max);
|
||||
agent->maintain_len = 0;
|
||||
return -ERROR;
|
||||
return -1;
|
||||
}
|
||||
printf("GetCompleteATReply done\n");
|
||||
break;
|
||||
|
@ -371,7 +371,6 @@ ATAgentType GetATAgent(const char *agent_name)
|
|||
return result;
|
||||
}
|
||||
|
||||
|
||||
static int DeleteATAgent(ATAgentType agent)
|
||||
{
|
||||
if (agent->lock) {
|
||||
|
@ -426,13 +425,12 @@ static void *ATAgentReceiveProcess(void *param)
|
|||
|
||||
static int ATAgentInit(ATAgentType agent)
|
||||
{
|
||||
int result = EOK;
|
||||
UtaskType at_utask;
|
||||
int result = 0;
|
||||
|
||||
agent->maintain_len = 0;
|
||||
agent->maintain_buffer = (char *)PrivMalloc(agent->maintain_max);
|
||||
|
||||
if (agent->maintain_buffer == NONE) {
|
||||
if (agent->maintain_buffer == NULL) {
|
||||
printf("ATAgentInit malloc maintain_buffer error\n");
|
||||
goto __out;
|
||||
}
|
||||
|
@ -468,7 +466,7 @@ static int ATAgentInit(ATAgentType agent)
|
|||
|
||||
__out:
|
||||
DeleteATAgent(agent);
|
||||
result = -ERROR;
|
||||
result = -1;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -476,9 +474,9 @@ __out:
|
|||
int InitATAgent(const char *agent_name, int agent_fd, uint32 maintain_max)
|
||||
{
|
||||
int i = 0;
|
||||
int result = EOK;
|
||||
int open_result = EOK;
|
||||
struct ATAgent *agent = NONE;
|
||||
int result = 0;
|
||||
int open_result = 0;
|
||||
struct ATAgent *agent = NULL;
|
||||
|
||||
if (GetATAgent(agent_name) != NULL) {
|
||||
return result;
|
||||
|
@ -490,7 +488,7 @@ int InitATAgent(const char *agent_name, int agent_fd, uint32 maintain_max)
|
|||
|
||||
if (i >= AT_AGENT_MAX) {
|
||||
printf("agent buffer(%d) is full.", AT_AGENT_MAX);
|
||||
result = -ERROR;
|
||||
result = -1;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -503,7 +501,7 @@ int InitATAgent(const char *agent_name, int agent_fd, uint32 maintain_max)
|
|||
agent->maintain_max = maintain_max;
|
||||
|
||||
result = ATAgentInit(agent);
|
||||
if (result == EOK) {
|
||||
if (result == 0) {
|
||||
PrivTaskStartup(&agent->at_handler);
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
extern AdapterProductInfoType Hc08Attach(struct Adapter *adapter);
|
||||
#endif
|
||||
|
||||
#define ADAPTER_BLUETOOTH_NAME "BlueTooth"
|
||||
#define ADAPTER_BLUETOOTH_NAME "bluetooth"
|
||||
|
||||
static int AdapterBlueToothRegister(struct Adapter *adapter)
|
||||
{
|
||||
|
@ -50,7 +50,7 @@ int AdapterBlueToothInit(void)
|
|||
|
||||
struct Adapter *adapter = PrivMalloc(sizeof(struct Adapter));
|
||||
if (!adapter) {
|
||||
free(adapter);
|
||||
PrivFree(adapter);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,7 @@ int AdapterBlueToothInit(void)
|
|||
ret = AdapterBlueToothRegister(adapter);
|
||||
if (ret < 0) {
|
||||
printf("AdapterBlueToothInit register BT adapter error\n");
|
||||
free(adapter);
|
||||
PrivFree(adapter);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ int AdapterBlueToothInit(void)
|
|||
AdapterProductInfoType product_info = Hc08Attach(adapter);
|
||||
if (!product_info) {
|
||||
printf("AdapterBlueToothInit hc08 attach error\n");
|
||||
free(adapter);
|
||||
PrivFree(adapter);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
config ADAPTER_HFA21_ETHERNET
|
||||
help
|
||||
Please check HFA21 can only work for adapter_wifi or adapter_ethernet in the meantime!
|
||||
bool "Using ethernet adapter device HFA21"
|
||||
default n
|
||||
|
||||
if ADAPTER_HFA21_ETHERNET
|
||||
source "$APP_DIR/Framework/connection/ethernet/hfa21_ethernet/Kconfig"
|
||||
endif
|
|
@ -1,3 +1,7 @@
|
|||
SRC_FILES := adapter_ethernet.c
|
||||
|
||||
ifeq ($(CONFIG_ADAPTER_HFA21_ETHERNET),y)
|
||||
SRC_DIR += hfa21_ethernet
|
||||
endif
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
|
|
|
@ -15,5 +15,112 @@
|
|||
* @brief Implement the connection ethernet adapter function
|
||||
* @version 1.1
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.06.25
|
||||
* @date 2021.10.15
|
||||
*/
|
||||
|
||||
#include <adapter.h>
|
||||
|
||||
#ifdef ADAPTER_HFA21_ETHERNET
|
||||
extern AdapterProductInfoType Hfa21EthernetAttach(struct Adapter *adapter);
|
||||
#endif
|
||||
|
||||
#define ADAPTER_ETHERNET_NAME "ethernet"
|
||||
|
||||
static int AdapterEthernetRegister(struct Adapter *adapter)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
strncpy(adapter->name, ADAPTER_ETHERNET_NAME, NAME_NUM_MAX);
|
||||
|
||||
adapter->net_protocol = IP_PROTOCOL;
|
||||
adapter->adapter_status = UNREGISTERED;
|
||||
|
||||
ret = AdapterDeviceRegister(adapter);
|
||||
if (ret < 0) {
|
||||
printf("AdapterEthernet register error\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int AdapterEthernetInit(void)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
struct Adapter *adapter = PrivMalloc(sizeof(struct Adapter));
|
||||
if (!adapter) {
|
||||
printf("AdapterEthernetInit malloc error\n");
|
||||
PrivFree(adapter);
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(adapter, 0, sizeof(struct Adapter));
|
||||
|
||||
ret = AdapterEthernetRegister(adapter);
|
||||
if (ret < 0) {
|
||||
printf("AdapterEthernetInit register ethernet adapter error\n");
|
||||
PrivFree(adapter);
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef ADAPTER_HFA21_ETHERNET
|
||||
AdapterProductInfoType product_info = Hfa21EthernetAttach(adapter);
|
||||
if (!product_info) {
|
||||
printf("AdapterEthernetInit hfa21 attach error\n");
|
||||
PrivFree(adapter);
|
||||
return -1;
|
||||
}
|
||||
|
||||
adapter->product_info_flag = 1;
|
||||
adapter->info = product_info;
|
||||
adapter->done = product_info->model_done;
|
||||
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/******************ethernet TEST*********************/
|
||||
int AdapterEthernetTest(void)
|
||||
{
|
||||
int baud_rate = BAUD_RATE_57600;
|
||||
|
||||
struct Adapter *adapter = AdapterDeviceFindByName(ADAPTER_ETHERNET_NAME);
|
||||
|
||||
#ifdef ADAPTER_HFA21_ETHERNET
|
||||
|
||||
char ethernet_recv_msg[128] = {0};
|
||||
int i, len = 0;
|
||||
const char *ethernet_msg = "Adapter Ethernet Test";
|
||||
|
||||
AdapterDeviceOpen(adapter);
|
||||
AdapterDeviceControl(adapter, OPE_INT, &baud_rate);
|
||||
|
||||
AdapterDeviceSetUp(adapter);
|
||||
|
||||
const char *ip = "10.10.100.50";
|
||||
const char *port = "12345";
|
||||
enum NetRoleType net_role = SERVER;//CLIENT
|
||||
enum IpType ip_type = IPV4;
|
||||
AdapterDeviceConnect(adapter, net_role, ip, port, ip_type);
|
||||
|
||||
printf("ready to test data transfer\n");
|
||||
|
||||
len = strlen(ethernet_msg);
|
||||
for (i = 0;i < 10; i ++) {
|
||||
printf("AdapterEthernetTest send %s\n", ethernet_msg);
|
||||
AdapterDeviceSend(adapter, ethernet_msg, len);
|
||||
PrivTaskDelay(4000);
|
||||
}
|
||||
|
||||
while (1) {
|
||||
AdapterDeviceRecv(adapter, ethernet_recv_msg, 128);
|
||||
printf("AdapterEthernetTest recv %s\n", ethernet_recv_msg);
|
||||
memset(ethernet_recv_msg, 0, 128);
|
||||
}
|
||||
#endif
|
||||
|
||||
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, AdapterEthernetTest, AdapterEthernetTest, show adapter ethernet information);
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
config ADAPTER_ETHERNET_HFA21
|
||||
string "HFA21 ETHERNET adapter name"
|
||||
default "hfa21_ethernet"
|
||||
|
||||
if ADD_XIUOS_FETURES
|
||||
|
||||
config ADAPTER_HFA21_DRIVER_EXTUART
|
||||
bool "Using extra uart to support ethernet"
|
||||
default n
|
||||
|
||||
config ADAPTER_HFA21_DRIVER
|
||||
string "HFA21 device uart driver path"
|
||||
default "/dev/usart3_dev3"
|
||||
depends on !ADAPTER_HFA21_DRIVER_EXTUART
|
||||
|
||||
if ADAPTER_HFA21_DRIVER_EXTUART
|
||||
config ADAPTER_HFA21_DRIVER
|
||||
string "HFA21 device extra uart driver path"
|
||||
default "/dev/extuart_dev6"
|
||||
|
||||
config ADAPTER_HFA21_DRIVER_EXT_PORT
|
||||
int "if HFA21 device using extuart, choose port"
|
||||
default "6"
|
||||
endif
|
||||
endif
|
||||
|
||||
if ADD_NUTTX_FETURES
|
||||
|
||||
endif
|
||||
|
||||
if ADD_RTTHREAD_FETURES
|
||||
|
||||
endif
|
|
@ -0,0 +1,3 @@
|
|||
SRC_FILES := hfa21_ethernet.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
|
@ -0,0 +1,453 @@
|
|||
/*
|
||||
* 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 hfa21_ethernet.c
|
||||
* @brief Implement the connection ethernet adapter function, using HFA21 device
|
||||
* @version 1.1
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.10.15
|
||||
*/
|
||||
|
||||
#include <adapter.h>
|
||||
#include <at_agent.h>
|
||||
|
||||
#define HFA21_ETHERNET_AT_CMD "+++"
|
||||
#define HFA21_ETHERNET_AT_CONFIRM_CMD "a"
|
||||
#define HFA21_ETHERNET_AT_FCLR_CMD "AT+FCLR\r"
|
||||
#define HFA21_ETHERNET_AT_FEPHY_CMD "AT+FEPHY=on\r"
|
||||
#define HFA21_ETHERNET_AT_ENABLE_WANN_CMD "AT+FVEW=enable\r"
|
||||
#define HFA21_ETHERNET_AT_DISABLE_WANN_CMD "AT+FVEW=disable\r"
|
||||
#define HFA21_ETHERNET_AT_RELD_CMD "AT+RELD\r"
|
||||
#define HFA21_ETHERNET_AT_WMODE_CMD "AT+WMODE\r"
|
||||
#define HFA21_ETHERNET_AT_WANN_CMD "AT+WANN\r"
|
||||
#define HFA21_ETHERNET_AT_SET_WANN_CMD "AT+WANN=%s,%s,%s,%s\r"
|
||||
#define HFA21_ETHERNET_AT_PING_CMD "AT+PING=%s\r"
|
||||
#define HFA21_ETHERNET_AT_NETP_CMD "AT+NETP=%s,%s,%s,%s\r"
|
||||
#define HFA21_ETHERNET_AT_REBOOT_CMD "AT+Z\r"
|
||||
|
||||
#define HFA21_ETHERNET_OK_REPLY "+ok"
|
||||
|
||||
static int Hfa21EthernetSetDown(struct Adapter *adapter_at);
|
||||
|
||||
/**
|
||||
* @description: enter AT command mode
|
||||
* @param at_agent - ethernet device agent pointer
|
||||
* @return success: 0
|
||||
*/
|
||||
static int Hfa21EthernetInitAtCmd(ATAgentType at_agent)
|
||||
{
|
||||
ATOrderSend(at_agent, REPLY_TIME_OUT, NULL, HFA21_ETHERNET_AT_CMD);
|
||||
PrivTaskDelay(100);
|
||||
|
||||
ATOrderSend(at_agent, REPLY_TIME_OUT, NULL, HFA21_ETHERNET_AT_CONFIRM_CMD);
|
||||
PrivTaskDelay(500);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Open HFA21 uart function
|
||||
* @param adapter - ethernet device pointer
|
||||
* @return success: 0, failure: -1
|
||||
*/
|
||||
static int Hfa21EthernetOpen(struct Adapter *adapter)
|
||||
{
|
||||
/*step1: open hfa21 serial port*/
|
||||
adapter->fd = PrivOpen(ADAPTER_HFA21_DRIVER, O_RDWR);
|
||||
if (adapter->fd < 0) {
|
||||
printf("Hfa21EthernetOpen get serial %s fd error\n", ADAPTER_HFA21_DRIVER);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*step2: init AT agent*/
|
||||
if (!adapter->agent) {
|
||||
char *agent_name = "ethernet_uart_client";
|
||||
if (EOK != InitATAgent(agent_name, adapter->fd, 512)) {
|
||||
printf("at agent init failed !\n");
|
||||
return -1;
|
||||
}
|
||||
ATAgentType at_agent = GetATAgent(agent_name);
|
||||
|
||||
adapter->agent = at_agent;
|
||||
}
|
||||
|
||||
ADAPTER_DEBUG("Hfa21Ethernet open done\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Close HFA21 ethernet and uart function
|
||||
* @param adapter - ethernet device pointer
|
||||
* @return success: 0
|
||||
*/
|
||||
static int Hfa21EthernetClose(struct Adapter *adapter)
|
||||
{
|
||||
return Hfa21EthernetSetDown(adapter);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: send data to adapter
|
||||
* @param adapter - ethernet device pointer
|
||||
* @param data - data buffer
|
||||
* @param data - data length
|
||||
* @return success: 0
|
||||
*/
|
||||
static int Hfa21EthernetSend(struct Adapter *adapter, const void *data, size_t len)
|
||||
{
|
||||
int result = 0;
|
||||
if (adapter->agent) {
|
||||
EntmSend(adapter->agent, (const char *)data, len);
|
||||
}else {
|
||||
printf("Hfa21EthernetSend can not find agent!\n");
|
||||
}
|
||||
|
||||
__exit:
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: receive data from adapter
|
||||
* @param adapter - ethernet device pointer
|
||||
* @param data - data buffer
|
||||
* @param data - data length
|
||||
* @return success: 0
|
||||
*/
|
||||
static int Hfa21EthernetReceive(struct Adapter *adapter, void *rev_buffer, size_t buffer_len)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
if (adapter->agent) {
|
||||
return EntmRecv(adapter->agent, (char *)rev_buffer, buffer_len, 40000);
|
||||
} else {
|
||||
printf("Hfa21EthernetReceive can not find agent!\n");
|
||||
}
|
||||
|
||||
__exit:
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: connnect Ethernet to internet
|
||||
* @param adapter - Ethernet device pointer
|
||||
* @return success: 0
|
||||
*/
|
||||
static int Hfa21EthernetSetUp(struct Adapter *adapter)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
AtSetReplyLrEnd(adapter->agent, 1);
|
||||
|
||||
/* wait hfa21 device startup finish */
|
||||
PrivTaskDelay(5000);
|
||||
|
||||
/*Step1 : enter AT mode*/
|
||||
Hfa21EthernetInitAtCmd(adapter->agent);
|
||||
|
||||
PrivTaskDelay(1000);
|
||||
|
||||
/*Step2 : FCLR reboot*/
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, HFA21_ETHERNET_AT_FCLR_CMD, HFA21_ETHERNET_OK_REPLY);
|
||||
if (ret < 0) {
|
||||
goto __exit;
|
||||
}
|
||||
|
||||
PrivTaskDelay(10000);
|
||||
|
||||
Hfa21EthernetInitAtCmd(adapter->agent);
|
||||
|
||||
/*Step3 : FEPHY enable phy function*/
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, HFA21_ETHERNET_AT_FEPHY_CMD, HFA21_ETHERNET_OK_REPLY);
|
||||
if (ret < 0) {
|
||||
goto __exit;
|
||||
}
|
||||
|
||||
/*Step4 : FVEW disable WANN function, ethernet work at LANN mode*/
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, HFA21_ETHERNET_AT_DISABLE_WANN_CMD, HFA21_ETHERNET_OK_REPLY);
|
||||
if (ret < 0) {
|
||||
goto __exit;
|
||||
}
|
||||
|
||||
/*Step5 : RELD enable F-AT cmd*/
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, HFA21_ETHERNET_AT_RELD_CMD, HFA21_ETHERNET_OK_REPLY);
|
||||
if (ret < 0) {
|
||||
goto __exit;
|
||||
}
|
||||
|
||||
PrivTaskDelay(10000);
|
||||
|
||||
Hfa21EthernetInitAtCmd(adapter->agent);
|
||||
|
||||
/*Step6 : AT+WMODE check work mode, AP or STA*/
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, HFA21_ETHERNET_AT_WMODE_CMD, HFA21_ETHERNET_OK_REPLY);
|
||||
if (ret < 0) {
|
||||
goto __exit;
|
||||
}
|
||||
|
||||
/*Step7 : AT+WANN check if get ip、netmask、gateway*/
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, HFA21_ETHERNET_AT_WANN_CMD, HFA21_ETHERNET_OK_REPLY);
|
||||
if (ret < 0) {
|
||||
goto __exit;
|
||||
}
|
||||
|
||||
/*Step8 : AT+Z reboot hfa21 device*/
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, HFA21_ETHERNET_AT_REBOOT_CMD, HFA21_ETHERNET_OK_REPLY);
|
||||
if (ret < 0) {
|
||||
goto __exit;
|
||||
}
|
||||
|
||||
PrivTaskDelay(10000);
|
||||
|
||||
return ret;
|
||||
|
||||
__exit:
|
||||
Hfa21EthernetSetDown(adapter);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: disconnnect ethernet from internet
|
||||
* @param adapter - ethernet device pointer
|
||||
* @return success: 0
|
||||
*/
|
||||
static int Hfa21EthernetSetDown(struct Adapter *adapter)
|
||||
{
|
||||
Hfa21EthernetInitAtCmd(adapter->agent);
|
||||
|
||||
ATOrderSend(adapter->agent, REPLY_TIME_OUT, NULL, HFA21_ETHERNET_AT_FCLR_CMD);
|
||||
PrivTaskDelay(20000);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: set ethernet ip/gateway/netmask address(in sta mode) working at WANN mode
|
||||
* @param adapter - ethernet device pointer
|
||||
* @param ip - ip address
|
||||
* @param gateway - gateway address
|
||||
* @param netmask - netmask address
|
||||
* @return success: 0, failure: -ENOMEMORY or -1
|
||||
*/
|
||||
static int Hfa21EthernetSetAddr(struct Adapter *adapter, const char *ip, const char *gateway, const char *netmask)
|
||||
{
|
||||
int ret = 0;
|
||||
uint8_t hfa21_ethernet_cmd[64];
|
||||
|
||||
/*Step1 : enter AT mode*/
|
||||
Hfa21EthernetInitAtCmd(adapter->agent);
|
||||
|
||||
/*Step2 : set mode、ip、netmask and gateway*/
|
||||
memset(hfa21_ethernet_cmd, 0, sizeof(hfa21_ethernet_cmd));
|
||||
sprintf(hfa21_ethernet_cmd, HFA21_ETHERNET_AT_SET_WANN_CMD, "DHCP", ip, netmask, gateway);
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, hfa21_ethernet_cmd, HFA21_ETHERNET_OK_REPLY);
|
||||
if (ret < 0) {
|
||||
goto __exit;
|
||||
}
|
||||
|
||||
/*Step3 : AT+WANN check if set ip、netmask、gateway successfully*/
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, HFA21_ETHERNET_AT_WANN_CMD, HFA21_ETHERNET_OK_REPLY);
|
||||
if (ret < 0) {
|
||||
goto __exit;
|
||||
}
|
||||
|
||||
/*Step4 : AT+Z reboot hfa21 device*/
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, HFA21_ETHERNET_AT_REBOOT_CMD, HFA21_ETHERNET_OK_REPLY);
|
||||
if (ret < 0) {
|
||||
goto __exit;
|
||||
}
|
||||
|
||||
PrivTaskDelay(10000);
|
||||
|
||||
return ret;
|
||||
|
||||
__exit:
|
||||
Hfa21EthernetSetDown(adapter);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: ethernet ping function
|
||||
* @param adapter - ethernet device pointer
|
||||
* @param destination - domain name or ip address
|
||||
* @return success: 0, failure: -1
|
||||
*/
|
||||
static int Hfa21EthernetPing(struct Adapter *adapter, const char *destination)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
char *ping_result = (char *) PrivCalloc(1, 17);
|
||||
char *dst = (char *) PrivCalloc(1, 17);
|
||||
|
||||
strcpy(dst, destination);
|
||||
strcat(dst, "\r");
|
||||
|
||||
printf("Hfa21EthernetPing [%s]\n", dst);
|
||||
|
||||
/*Step1 : enter AT mode*/
|
||||
Hfa21EthernetInitAtCmd(adapter->agent);
|
||||
|
||||
/*Step2 : ping dst ip address*/
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, HFA21_ETHERNET_AT_PING_CMD, HFA21_ETHERNET_OK_REPLY);
|
||||
if (ret < 0) {
|
||||
goto __exit;
|
||||
}
|
||||
|
||||
/*Step3 : AT+Z reboot hfa21 device*/
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, HFA21_ETHERNET_AT_REBOOT_CMD, HFA21_ETHERNET_OK_REPLY);
|
||||
if (ret < 0) {
|
||||
goto __exit;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
__exit:
|
||||
Hfa21EthernetSetDown(adapter);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: ethernet connect function
|
||||
* @param adapter - ethernet device pointer
|
||||
* @param net_role - net role, CLIENT or SERVER
|
||||
* @param ip - ip address
|
||||
* @param port - port num
|
||||
* @param ip_type - ip type, IPV4 or IPV6
|
||||
* @return success: 0, failure: -1
|
||||
*/
|
||||
static int Hfa21EthernetConnect(struct Adapter *adapter, enum NetRoleType net_role, const char *ip, const char *port, enum IpType ip_type)
|
||||
{
|
||||
int ret = 0;
|
||||
char hfa21_ethernet_cmd[128];
|
||||
char net_role_string[6] = {0};
|
||||
|
||||
/*Step1 : enter AT mode*/
|
||||
Hfa21EthernetInitAtCmd(adapter->agent);
|
||||
|
||||
if (CLIENT == net_role) {
|
||||
strcpy(net_role_string, "CLIENT");
|
||||
} else if (SERVER == net_role) {
|
||||
strcpy(net_role_string, "SERVER");
|
||||
} else {
|
||||
printf("Hfa21EthernetConnect do not support %d net type\n", net_role);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (IPV4 == ip_type) {
|
||||
/*to do*/
|
||||
} else if (IPV6 == ip_type) {
|
||||
/*to do*/
|
||||
} else {
|
||||
printf("Hfa21EthernetConnect do not support %d ip type\n", ip_type);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*Step2 : create tcp connect*/
|
||||
memset(hfa21_ethernet_cmd, 0, sizeof(hfa21_ethernet_cmd));
|
||||
sprintf(hfa21_ethernet_cmd, HFA21_ETHERNET_AT_NETP_CMD, "TCP", net_role_string, port, ip);
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, hfa21_ethernet_cmd, HFA21_ETHERNET_OK_REPLY);
|
||||
if (ret < 0) {
|
||||
goto __exit;
|
||||
}
|
||||
|
||||
adapter->net_role = net_role;
|
||||
|
||||
/*Step3 : AT+Z reboot hfa21 device*/
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, HFA21_ETHERNET_AT_REBOOT_CMD, HFA21_ETHERNET_OK_REPLY);
|
||||
if (ret < 0) {
|
||||
goto __exit;
|
||||
}
|
||||
|
||||
PrivTaskDelay(10000);
|
||||
|
||||
return ret;
|
||||
|
||||
__exit:
|
||||
Hfa21EthernetSetDown(adapter);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int Hfa21EthernetIoctl(struct Adapter *adapter, int cmd, void *args)
|
||||
{
|
||||
if (OPE_INT != cmd) {
|
||||
printf("Hfa21EthernetIoctl only support OPE_INT, do not support %d\n", cmd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint32_t baud_rate = *((uint32_t *)args);
|
||||
|
||||
struct SerialDataCfg serial_cfg;
|
||||
memset(&serial_cfg, 0 ,sizeof(struct SerialDataCfg));
|
||||
serial_cfg.serial_baud_rate = baud_rate;
|
||||
serial_cfg.serial_data_bits = DATA_BITS_8;
|
||||
serial_cfg.serial_stop_bits = STOP_BITS_1;
|
||||
serial_cfg.serial_buffer_size = SERIAL_RB_BUFSZ;
|
||||
serial_cfg.serial_parity_mode = PARITY_NONE;
|
||||
serial_cfg.serial_bit_order = BIT_ORDER_LSB;
|
||||
serial_cfg.serial_invert_mode = NRZ_NORMAL;
|
||||
#ifdef ADAPTER_HFA21_DRIVER_EXT_PORT
|
||||
serial_cfg.ext_uart_no = ADAPTER_HFA21_DRIVER_EXT_PORT;
|
||||
serial_cfg.port_configure = PORT_CFG_INIT;
|
||||
#endif
|
||||
|
||||
struct PrivIoctlCfg ioctl_cfg;
|
||||
ioctl_cfg.ioctl_driver_type = SERIAL_TYPE;
|
||||
ioctl_cfg.args = &serial_cfg;
|
||||
PrivIoctl(adapter->fd, OPE_INT, &ioctl_cfg);
|
||||
|
||||
printf("Hfa21EthernetIoctl success\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct IpProtocolDone hfa21_ethernet_done =
|
||||
{
|
||||
.open = Hfa21EthernetOpen,
|
||||
.close = Hfa21EthernetClose,
|
||||
.ioctl = Hfa21EthernetIoctl,
|
||||
.setup = Hfa21EthernetSetUp,
|
||||
.setdown = Hfa21EthernetSetDown,
|
||||
.setaddr = Hfa21EthernetSetAddr,
|
||||
.setdns = NULL,
|
||||
.setdhcp = NULL,
|
||||
.ping = Hfa21EthernetPing,
|
||||
.netstat = NULL,
|
||||
.connect = Hfa21EthernetConnect,
|
||||
.send = Hfa21EthernetSend,
|
||||
.recv = Hfa21EthernetReceive,
|
||||
.disconnect = NULL,
|
||||
};
|
||||
|
||||
/**
|
||||
* @description: Register ethernet device hfa21
|
||||
* @return success: product_info, failure: NULL
|
||||
*/
|
||||
AdapterProductInfoType Hfa21EthernetAttach(struct Adapter *adapter)
|
||||
{
|
||||
struct AdapterProductInfo *product_info = PrivMalloc(sizeof(struct AdapterProductInfo));
|
||||
if (!product_info) {
|
||||
printf("Hfa21EthernetAttach Attach malloc product_info error\n");
|
||||
PrivFree(product_info);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
strcpy(product_info->model_name, ADAPTER_ETHERNET_HFA21);
|
||||
|
||||
product_info->model_done = (void *)&hfa21_ethernet_done;
|
||||
|
||||
return product_info;
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
config ADAPTER_SX1278
|
||||
bool "Using lora adapter device SX1278"
|
||||
default y
|
||||
|
||||
choice
|
||||
prompt "Lora device adapter select net role type "
|
||||
default AS_LORA_CLIENT_ROLE
|
||||
|
||||
config AS_LORA_GATEWAY_ROLE
|
||||
bool "config as a gateway"
|
||||
|
||||
config AS_LORA_CLIENT_ROLE
|
||||
bool "config as a client"
|
||||
endchoice
|
||||
|
||||
if AS_LORA_GATEWAY_ROLE
|
||||
config ADAPTER_LORA_NET_ROLE_ID
|
||||
hex "if Lora device config as a gateway, set gateway net id"
|
||||
default "0x10"
|
||||
endif
|
||||
|
||||
if AS_LORA_CLIENT_ROLE
|
||||
config ADAPTER_LORA_NET_ROLE_ID
|
||||
hex "if Lora device config as a client, set client net id"
|
||||
default "0x01"
|
||||
endif
|
||||
|
||||
if ADAPTER_SX1278
|
||||
source "$APP_DIR/Framework/connection/lora/sx1278/Kconfig"
|
||||
endif
|
|
@ -1,3 +1,7 @@
|
|||
SRC_FILES := adapter_lora.c
|
||||
|
||||
ifeq ($(CONFIG_ADAPTER_SX1278),y)
|
||||
SRC_DIR += sx1278
|
||||
endif
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
|
|
|
@ -15,5 +15,767 @@
|
|||
* @brief Implement the connection lora adapter function
|
||||
* @version 1.1
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.06.25
|
||||
* @date 2021.10.20
|
||||
*/
|
||||
|
||||
#include <adapter.h>
|
||||
|
||||
#ifdef ADAPTER_SX1278
|
||||
extern AdapterProductInfoType Sx1278Attach(struct Adapter *adapter);
|
||||
#endif
|
||||
|
||||
#define ADAPTER_LORA_NAME "lora"
|
||||
#define ADAPTER_LORA_CLIENT_NUM 6
|
||||
#define ADAPTER_LORA_DATA_LENGTH 128
|
||||
|
||||
#define ADAPTER_LORA_DATA_HEAD 0x3C
|
||||
#define ADAPTER_LORA_NET_PANID 0x0102
|
||||
#define ADAPTER_LORA_DATA_TYPE_JOIN 0x0A
|
||||
#define ADAPTER_LORA_DATA_TYPE_QUIT 0x0B
|
||||
#define ADAPTER_LORA_DATA_TYPE_JOIN_REPLY 0x0C
|
||||
#define ADAPTER_LORA_DATA_TYPE_QUIT_REPLY 0x0D
|
||||
#define ADAPTER_LORA_DATA_TYPE_USERDATA 0x0E
|
||||
#define ADAPTER_LORA_DATA_TYPE_CMD 0x0F
|
||||
|
||||
//need to change status if the lora client wants to quit the net when timeout or a certain event
|
||||
//eg.can also use sem to trigger quit function
|
||||
static int g_adapter_lora_quit_flag = 0;
|
||||
|
||||
enum ClientState
|
||||
{
|
||||
CLIENT_DISCONNECT = 0,
|
||||
CLIENT_CONNECT,
|
||||
CLIENT_DEFAULT,
|
||||
};
|
||||
|
||||
enum DataType
|
||||
{
|
||||
LORA_CLIENT_ACCESS = 0,
|
||||
LORA_GATEWAY_REPLY,
|
||||
LORA_USER_DATA,
|
||||
};
|
||||
|
||||
enum LoraGatewayState {
|
||||
LORA_STATE_IDLE = 0,
|
||||
LORA_JOIN_NET,
|
||||
LORA_QUIT_NET,
|
||||
LORA_RECV_DATA,
|
||||
};
|
||||
|
||||
static uint8 LoraGatewayState = LORA_STATE_IDLE;
|
||||
|
||||
struct LoraGatewayParam
|
||||
{
|
||||
uint8 gateway_id;
|
||||
uint16 panid;
|
||||
uint8 client_id[ADAPTER_LORA_CLIENT_NUM];
|
||||
int client_num;
|
||||
int receive_data_sem;
|
||||
};
|
||||
|
||||
struct LoraClientParam
|
||||
{
|
||||
uint8 client_id;
|
||||
uint16 panid;
|
||||
enum ClientState client_state;
|
||||
|
||||
uint8 gateway_id;
|
||||
};
|
||||
|
||||
/*LoraDataFormat:
|
||||
**flame_head : 0x3C
|
||||
**length : sizeof(struct LoraDataFormat)
|
||||
**panid : 0x0102
|
||||
**client_id : 0x01、0x02、0x03...
|
||||
**gateway_id : 0x11、0x12、0x13...
|
||||
**data_type : 0x0A(join net, client->gateway)、0x0B(join net reply, gateway->client)、
|
||||
0x0C(user data, client->gateway)、0x0D(user data cmd, gateway->client)
|
||||
**data : user data
|
||||
**crc16 : CRC 16 check data
|
||||
*/
|
||||
struct LoraDataFormat
|
||||
{
|
||||
uint8 flame_head;
|
||||
uint32 length;
|
||||
uint16 panid;
|
||||
uint8 client_id;
|
||||
uint8 gateway_id;
|
||||
|
||||
uint8 data_type;
|
||||
uint8 data[ADAPTER_LORA_DATA_LENGTH];
|
||||
|
||||
uint16 crc16;
|
||||
};
|
||||
|
||||
/*******************LORA MESH FUNCTION***********************/
|
||||
|
||||
/**
|
||||
* @description: create CRC16 data
|
||||
* @param data input data buffer
|
||||
* @param length input data buffer minus check code
|
||||
*/
|
||||
static uint16 LoraCrc16(uint8 *data, uint16 length)
|
||||
{
|
||||
int j;
|
||||
uint16 crc_data = 0xFFFF;
|
||||
|
||||
while (length--) {
|
||||
crc_data ^= *data++;
|
||||
for( j = 0 ; j < 8 ; j ++) {
|
||||
if(crc_data & 0x01) /* LSB(b0)=1 */
|
||||
crc_data = crc_data >> 1 ^ 0xA001;
|
||||
else
|
||||
crc_data = crc_data >> 1;
|
||||
}
|
||||
}
|
||||
|
||||
return crc_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: CRC16 check
|
||||
* @param data input data buffer
|
||||
* @param length input data buffer minus check code
|
||||
*/
|
||||
static int LoraCrc16Check(uint8 *data, uint16 length)
|
||||
{
|
||||
uint16 crc_data;
|
||||
uint16 input_data = (((uint16)data[length - 1] << 8) & 0xFF00) | ((uint16)data[length - 2] & 0x00FF);
|
||||
|
||||
crc_data = LoraCrc16(data, length - 2);
|
||||
|
||||
if (crc_data == input_data)
|
||||
return 0;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Lora Gateway reply connect request to Client
|
||||
* @param adapter Lora adapter pointer
|
||||
* @param gateway_recv_data Lora Client connect data
|
||||
*/
|
||||
static int LoraGatewayReply(struct Adapter *adapter, struct LoraDataFormat *gateway_recv_data)
|
||||
{
|
||||
int i;
|
||||
int client_join_flag = 0;
|
||||
struct LoraGatewayParam *gateway = (struct LoraGatewayParam *)adapter->adapter_param;
|
||||
struct LoraDataFormat gateway_reply_data;
|
||||
|
||||
memset(&gateway_reply_data, 0, sizeof(struct LoraDataFormat));
|
||||
|
||||
if (ADAPTER_LORA_DATA_TYPE_JOIN == gateway_recv_data->data_type) {
|
||||
|
||||
for (i = 0; i < gateway->client_num; i ++) {
|
||||
if (gateway_recv_data->client_id == gateway->client_id[i]) {
|
||||
printf("Lora client_%d 0x%x has already join net 0x%x\n", i, gateway_recv_data->client_id, gateway->gateway_id);
|
||||
client_join_flag = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!client_join_flag) {
|
||||
if (gateway->client_num > 6) {
|
||||
printf("Lora gateway only support 6(max) client\n");
|
||||
gateway->client_num = 0;
|
||||
}
|
||||
gateway->client_id[gateway->client_num] = gateway_recv_data->client_id;
|
||||
gateway->client_num ++;
|
||||
}
|
||||
|
||||
gateway_reply_data.flame_head = ADAPTER_LORA_DATA_HEAD;
|
||||
gateway_reply_data.length = sizeof(struct LoraDataFormat);
|
||||
gateway_reply_data.panid = gateway->panid;
|
||||
gateway_reply_data.data_type = ADAPTER_LORA_DATA_TYPE_JOIN_REPLY;
|
||||
gateway_reply_data.client_id = gateway_recv_data->client_id;
|
||||
gateway_reply_data.gateway_id = gateway->gateway_id;
|
||||
gateway_reply_data.crc16 = LoraCrc16((uint8 *)&gateway_reply_data, sizeof(struct LoraDataFormat) - 2);
|
||||
|
||||
if (AdapterDeviceSend(adapter, (uint8 *)&gateway_reply_data, gateway_reply_data.length) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("Lora gateway 0x%x accept client 0x%x <join request>\n", gateway->gateway_id, gateway_recv_data->client_id);
|
||||
} else if (ADAPTER_LORA_DATA_TYPE_QUIT == gateway_recv_data->data_type) {
|
||||
for (i = 0; i < gateway->client_num; i ++) {
|
||||
if (gateway->client_id[i] == gateway_recv_data->client_id) {
|
||||
gateway->client_id[i] = 0;
|
||||
gateway->client_num --;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
gateway_reply_data.flame_head = ADAPTER_LORA_DATA_HEAD;
|
||||
gateway_reply_data.length = sizeof(struct LoraDataFormat);
|
||||
gateway_reply_data.panid = gateway->panid;
|
||||
gateway_reply_data.data_type = ADAPTER_LORA_DATA_TYPE_QUIT_REPLY;
|
||||
gateway_reply_data.client_id = gateway_recv_data->client_id;
|
||||
gateway_reply_data.gateway_id = gateway->gateway_id;
|
||||
gateway_reply_data.crc16 = LoraCrc16((uint8 *)&gateway_reply_data, sizeof(struct LoraDataFormat) - 2);
|
||||
|
||||
if (AdapterDeviceSend(adapter, (uint8 *)&gateway_reply_data, gateway_reply_data.length) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("Lora gateway 0x%x accept client 0x%x <quit request>\n", gateway->gateway_id, gateway_recv_data->client_id);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Lora Gateway send cmd to Client
|
||||
* @param adapter Lora adapter pointer
|
||||
* @param client_id Lora Client id
|
||||
* @param cmd Lora cmd
|
||||
*/
|
||||
static int LoraGatewaySendCmd(struct Adapter *adapter, unsigned char client_id, int cmd)
|
||||
{
|
||||
struct LoraGatewayParam *gateway = (struct LoraGatewayParam *)adapter->adapter_param;
|
||||
struct LoraDataFormat gateway_cmd_data;
|
||||
|
||||
memset(&gateway_cmd_data, 0, sizeof(struct LoraDataFormat));
|
||||
|
||||
gateway_cmd_data.flame_head = ADAPTER_LORA_DATA_HEAD;
|
||||
gateway_cmd_data.length = sizeof(struct LoraDataFormat);
|
||||
gateway_cmd_data.panid = gateway->panid;
|
||||
gateway_cmd_data.data_type = cmd;
|
||||
gateway_cmd_data.client_id = client_id;
|
||||
gateway_cmd_data.gateway_id = gateway->gateway_id;
|
||||
gateway_cmd_data.crc16 = LoraCrc16((uint8 *)&gateway_cmd_data, sizeof(struct LoraDataFormat) - 2);
|
||||
|
||||
if (AdapterDeviceSend(adapter, (uint8 *)&gateway_cmd_data, gateway_cmd_data.length) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Lora Gateway handle the user data from the client
|
||||
* @param adapter Lora adapter pointer
|
||||
* @param gateway_recv_data Lora Client user data
|
||||
*/
|
||||
static int LoraGatewayHandleData(struct Adapter *adapter, struct LoraDataFormat *gateway_recv_data)
|
||||
{
|
||||
/*User needs to handle client data depends on the requirement*/
|
||||
printf("Lora Gateway receive Client %d data:\n", gateway_recv_data->client_id);
|
||||
printf("%s\n", gateway_recv_data->data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Lora Client update status after join the net
|
||||
* @param adapter Lora adapter pointer
|
||||
* @param client_recv_data Lora Client recv data from Lora Gateway
|
||||
*/
|
||||
static int LoraClientUpdate(struct Adapter *adapter, struct LoraDataFormat *client_recv_data)
|
||||
{
|
||||
struct LoraClientParam *client = (struct LoraClientParam *)adapter->adapter_param;
|
||||
|
||||
if (ADAPTER_LORA_DATA_TYPE_JOIN_REPLY == client_recv_data->data_type) {
|
||||
client->gateway_id = client_recv_data->gateway_id;
|
||||
client->panid = client_recv_data->panid;
|
||||
client->client_state = CLIENT_CONNECT;
|
||||
printf("LoraClientUpdate client join panid 0x%x successfully\n", client->panid);
|
||||
} else if (ADAPTER_LORA_DATA_TYPE_QUIT_REPLY == client_recv_data->data_type) {
|
||||
client->gateway_id = 0;
|
||||
client->panid = 0;
|
||||
client->client_state = CLIENT_DISCONNECT;
|
||||
printf("LoraClientUpdate client quit panid 0x%x successfully\n", client->panid);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Lora Client send the user data to the gateway
|
||||
* @param adapter Lora adapter pointer
|
||||
* @param send_buf Lora Client send user data buf
|
||||
* @param length user data length (max size is ADAPTER_LORA_DATA_LENGTH)
|
||||
*/
|
||||
static int LoraClientSendData(struct Adapter *adapter, void *send_buf, int length)
|
||||
{
|
||||
struct LoraClientParam *client = (struct LoraClientParam *)adapter->adapter_param;
|
||||
|
||||
if (client->client_state != CLIENT_CONNECT) {
|
||||
printf("Lora client %d do not connect to Lora gateway\n", client->client_id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (length > ADAPTER_LORA_DATA_LENGTH) {
|
||||
printf("Lora client %d send data %d larger than max %d \n", client->client_id, length, ADAPTER_LORA_DATA_LENGTH);
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct LoraDataFormat client_user_data;
|
||||
|
||||
memset(&client_user_data, 0, sizeof(struct LoraDataFormat));
|
||||
|
||||
client_user_data.flame_head = ADAPTER_LORA_DATA_HEAD;
|
||||
client_user_data.length = sizeof(struct LoraDataFormat);
|
||||
client_user_data.panid = client->panid;
|
||||
client_user_data.data_type = ADAPTER_LORA_DATA_TYPE_USERDATA;
|
||||
client_user_data.client_id = client->client_id;
|
||||
client_user_data.gateway_id = client->gateway_id;
|
||||
|
||||
memcpy(client_user_data.data, (uint8 *)send_buf, length);
|
||||
|
||||
client_user_data.crc16 = LoraCrc16((uint8 *)&client_user_data, sizeof(struct LoraDataFormat) - 2);
|
||||
|
||||
if (AdapterDeviceSend(adapter, (uint8 *)&client_user_data, client_user_data.length) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Lora Gateway receive data analyzing
|
||||
* @param adapter Lora adapter pointer
|
||||
* @param gateway_recv_data Lora gateway receive data pointer
|
||||
*/
|
||||
static int LoraGateWayDataAnalyze(struct Adapter *adapter, struct LoraDataFormat *gateway_recv_data)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if (LoraCrc16Check((uint8 *)gateway_recv_data, sizeof(struct LoraDataFormat)) < 0) {
|
||||
printf("LoraGateWayDataAnalyze CRC check error\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((ADAPTER_LORA_DATA_HEAD == gateway_recv_data->flame_head) &&
|
||||
(ADAPTER_LORA_NET_PANID == gateway_recv_data->panid)) {
|
||||
switch (gateway_recv_data->data_type)
|
||||
{
|
||||
case ADAPTER_LORA_DATA_TYPE_JOIN :
|
||||
case ADAPTER_LORA_DATA_TYPE_QUIT :
|
||||
ret = LoraGatewayReply(adapter, gateway_recv_data);
|
||||
break;
|
||||
case ADAPTER_LORA_DATA_TYPE_USERDATA :
|
||||
ret = LoraGatewayHandleData(adapter, gateway_recv_data);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Lora Client receive data analyzing
|
||||
* @param adapter Lora adapter pointer
|
||||
* @param send_buf Lora Client send user data buf
|
||||
* @param length user data length (max size is ADAPTER_LORA_DATA_LENGTH)
|
||||
*/
|
||||
static int LoraClientDataAnalyze(struct Adapter *adapter, void *send_buf, int length)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
struct LoraDataFormat *client_recv_data = PrivMalloc(sizeof(struct LoraDataFormat));
|
||||
|
||||
memset(client_recv_data, 0, sizeof(struct LoraDataFormat));
|
||||
|
||||
ret = AdapterDeviceRecv(adapter, client_recv_data, sizeof(struct LoraDataFormat));
|
||||
if (0 == ret) {
|
||||
printf("LoraClientDataAnalyze recv error.Just return\n");
|
||||
PrivFree(client_recv_data);
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("client_recv_data\n");
|
||||
printf("head 0x%x length %d panid 0x%x data_type 0x%x client_id 0x%x gateway_id 0x%x crc 0x%x\n",
|
||||
client_recv_data->flame_head, client_recv_data->length, client_recv_data->panid, client_recv_data->data_type,
|
||||
client_recv_data->client_id, client_recv_data->gateway_id, client_recv_data->crc16);
|
||||
|
||||
if ((ADAPTER_LORA_DATA_HEAD == client_recv_data->flame_head) &&
|
||||
(ADAPTER_LORA_NET_PANID == client_recv_data->panid)) {
|
||||
if (LoraCrc16Check((uint8 *)client_recv_data, sizeof(struct LoraDataFormat)) < 0) {
|
||||
printf("LoraClientDataAnalyze CRC check error\n");
|
||||
PrivFree(client_recv_data);
|
||||
return -1;
|
||||
}
|
||||
|
||||
//only handle this client_id information from gateway
|
||||
if (client_recv_data->client_id == adapter->net_role_id) {
|
||||
switch (client_recv_data->data_type)
|
||||
{
|
||||
case ADAPTER_LORA_DATA_TYPE_JOIN_REPLY :
|
||||
case ADAPTER_LORA_DATA_TYPE_QUIT_REPLY :
|
||||
ret = LoraClientUpdate(adapter, client_recv_data);
|
||||
break;
|
||||
case ADAPTER_LORA_DATA_TYPE_CMD :
|
||||
if (send_buf) {
|
||||
ret = LoraClientSendData(adapter, send_buf, length);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PrivFree(client_recv_data);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Lora Client join net function
|
||||
* @param adapter Lora adapter pointer
|
||||
* @param panid Lora net panid
|
||||
*/
|
||||
static int LoraClientJoinNet(struct Adapter *adapter, unsigned short panid)
|
||||
{
|
||||
struct LoraDataFormat client_join_data;
|
||||
|
||||
memset(&client_join_data, 0, sizeof(struct LoraDataFormat));
|
||||
|
||||
client_join_data.flame_head = ADAPTER_LORA_DATA_HEAD;
|
||||
client_join_data.length = sizeof(struct LoraDataFormat);
|
||||
client_join_data.panid = panid;
|
||||
client_join_data.data_type = ADAPTER_LORA_DATA_TYPE_JOIN;
|
||||
client_join_data.client_id = adapter->net_role_id;
|
||||
client_join_data.crc16 = LoraCrc16((uint8 *)&client_join_data, sizeof(struct LoraDataFormat) - 2);
|
||||
|
||||
if (AdapterDeviceJoin(adapter, (uint8 *)&client_join_data) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Lora Client quit net function
|
||||
* @param adapter Lora adapter pointer
|
||||
* @param panid Lora net panid
|
||||
*/
|
||||
static int LoraClientQuitNet(struct Adapter *adapter, unsigned short panid)
|
||||
{
|
||||
struct LoraDataFormat client_join_data;
|
||||
|
||||
memset(&client_join_data, 0, sizeof(struct LoraDataFormat));
|
||||
|
||||
client_join_data.flame_head = ADAPTER_LORA_DATA_HEAD;
|
||||
client_join_data.length = sizeof(struct LoraDataFormat);
|
||||
client_join_data.panid = panid;
|
||||
client_join_data.data_type = ADAPTER_LORA_DATA_TYPE_QUIT;
|
||||
client_join_data.client_id = adapter->net_role_id;
|
||||
client_join_data.crc16 = LoraCrc16((uint8 *)&client_join_data, sizeof(struct LoraDataFormat) - 2);
|
||||
|
||||
if (AdapterDeviceDisconnect(adapter, (uint8 *)&client_join_data) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Lora Gateway Process function
|
||||
* @param lora_adapter Lora adapter pointer
|
||||
* @param gateway Lora gateway pointer
|
||||
* @param gateway_recv_data Lora gateway receive data pointer
|
||||
*/
|
||||
int LoraGatewayProcess(struct Adapter *lora_adapter, struct LoraGatewayParam *gateway, struct LoraDataFormat *gateway_recv_data)
|
||||
{
|
||||
int i, ret = 0;
|
||||
switch (LoraGatewayState)
|
||||
{
|
||||
case LORA_STATE_IDLE:
|
||||
ret = AdapterDeviceRecv(lora_adapter, gateway_recv_data, sizeof(struct LoraDataFormat));
|
||||
if (0 == ret) {
|
||||
printf("LoraGatewayProcess IDLE recv error.Just return\n");
|
||||
break;
|
||||
}
|
||||
|
||||
if (ADAPTER_LORA_DATA_TYPE_JOIN == gateway_recv_data->data_type) {
|
||||
LoraGatewayState = LORA_JOIN_NET;
|
||||
} else if (ADAPTER_LORA_DATA_TYPE_QUIT == gateway_recv_data->data_type) {
|
||||
LoraGatewayState = LORA_QUIT_NET;
|
||||
} else {
|
||||
LoraGatewayState = LORA_STATE_IDLE;
|
||||
}
|
||||
break;
|
||||
case LORA_JOIN_NET:
|
||||
case LORA_QUIT_NET:
|
||||
ret = LoraGateWayDataAnalyze(lora_adapter, gateway_recv_data);
|
||||
if (ret < 0) {
|
||||
printf("LoraGateWayDataAnalyze state %d error, re-send data cmd to client\n", LoraGatewayState);
|
||||
PrivTaskDelay(500);
|
||||
}
|
||||
LoraGatewayState = LORA_RECV_DATA;
|
||||
break;
|
||||
case LORA_RECV_DATA:
|
||||
for (i = 0; i < gateway->client_num; i ++) {
|
||||
if (gateway->client_id[i]) {
|
||||
printf("LoraGatewayProcess send to client %d for data\n", gateway->client_id[i]);
|
||||
ret = LoraGatewaySendCmd(lora_adapter, gateway->client_id[i], ADAPTER_LORA_DATA_TYPE_CMD);
|
||||
if (ret < 0) {
|
||||
printf("LoraGatewaySendCmd client ID %d error\n", gateway->client_id[i]);
|
||||
PrivTaskDelay(500);
|
||||
continue;
|
||||
}
|
||||
|
||||
ret = AdapterDeviceRecv(lora_adapter, gateway_recv_data, sizeof(struct LoraDataFormat));
|
||||
if (0 == ret) {
|
||||
printf("LoraGatewayProcess recv error.Just return\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ADAPTER_LORA_DATA_TYPE_JOIN == gateway_recv_data->data_type) {
|
||||
LoraGatewayState = LORA_JOIN_NET;
|
||||
} else if (ADAPTER_LORA_DATA_TYPE_QUIT == gateway_recv_data->data_type) {
|
||||
LoraGatewayState = LORA_QUIT_NET;
|
||||
} else {
|
||||
ret = LoraGateWayDataAnalyze(lora_adapter, gateway_recv_data);
|
||||
if (ret < 0) {
|
||||
printf("LoraGateWayDataAnalyze error, re-send data cmd to client\n");
|
||||
PrivTaskDelay(500);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Lora Gateway task
|
||||
* @param parameter - Lora adapter pointer
|
||||
*/
|
||||
static void *LoraGatewayTask(void *parameter)
|
||||
{
|
||||
int i;
|
||||
int ret = 0;
|
||||
struct Adapter *lora_adapter = (struct Adapter *)parameter;
|
||||
struct LoraGatewayParam *gateway = (struct LoraGatewayParam *)lora_adapter->adapter_param;
|
||||
struct LoraDataFormat gateway_recv_data;
|
||||
|
||||
while (1) {
|
||||
LoraGatewayProcess(lora_adapter, gateway, &gateway_recv_data);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Lora Client data upload task
|
||||
* @param parameter - Lora adapter pointer
|
||||
*/
|
||||
static void *LoraClientDataTask(void *parameter)
|
||||
{
|
||||
int i, ret = 0;
|
||||
int join_times = 10;
|
||||
struct Adapter *lora_adapter = (struct Adapter *)parameter;
|
||||
struct LoraClientParam *client = (struct LoraClientParam *)lora_adapter->adapter_param;
|
||||
|
||||
//set lora_send_buf for test
|
||||
uint8 lora_send_buf[ADAPTER_LORA_DATA_LENGTH];
|
||||
memset(lora_send_buf, 0, ADAPTER_LORA_DATA_LENGTH);
|
||||
sprintf(lora_send_buf, "Lora client %d adapter test\n", client->client_id);
|
||||
|
||||
while (1) {
|
||||
|
||||
PrivTaskDelay(100);
|
||||
|
||||
if ((CLIENT_DISCONNECT == client->client_state) && (!g_adapter_lora_quit_flag)) {
|
||||
ret = LoraClientJoinNet(lora_adapter, client->panid);
|
||||
if (ret < 0) {
|
||||
printf("LoraClientJoinNet error panid 0x%x\n", client->panid);
|
||||
}
|
||||
|
||||
ret = LoraClientDataAnalyze(lora_adapter, NULL, 0);
|
||||
if (ret < 0) {
|
||||
printf("LoraClientDataAnalyze error, reconnect to gateway\n");
|
||||
PrivTaskDelay(500);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (CLIENT_CONNECT == client->client_state) {
|
||||
ret = LoraClientDataAnalyze(lora_adapter, (void *)lora_send_buf, strlen(lora_send_buf));
|
||||
if (ret < 0) {
|
||||
printf("LoraClientDataAnalyze error, wait for next data cmd\n");
|
||||
PrivTaskDelay(500);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Lora Client quit task
|
||||
* @param parameter - Lora adapter pointer
|
||||
*/
|
||||
static void *LoraClientQuitTask(void *parameter)
|
||||
{
|
||||
int ret = 0;
|
||||
struct Adapter *lora_adapter = (struct Adapter *)parameter;
|
||||
struct LoraClientParam *client = (struct LoraClientParam *)lora_adapter->adapter_param;
|
||||
|
||||
while (1) {
|
||||
PrivTaskDelay(100);
|
||||
|
||||
if ((CLIENT_CONNECT == client->client_state) && (g_adapter_lora_quit_flag)) {
|
||||
ret = LoraClientQuitNet(lora_adapter, client->panid);
|
||||
if (ret < 0) {
|
||||
printf("LoraClientQuitNet error panid 0x%x, re-quit net\n", client->panid);
|
||||
continue;
|
||||
}
|
||||
|
||||
ret = LoraClientDataAnalyze(lora_adapter, NULL, 0);
|
||||
if (ret < 0) {
|
||||
printf("LoraClientQuitTask LoraClientDataAnalyze error\n");
|
||||
PrivTaskDelay(500);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*******************LORA ADAPTER FUNCTION********************/
|
||||
|
||||
static int AdapterLoraRegister(struct Adapter *adapter)
|
||||
{
|
||||
int ret = 0;
|
||||
struct LoraGatewayParam *lora_gateway;
|
||||
struct LoraClientParam *lora_client;
|
||||
|
||||
strncpy(adapter->name, ADAPTER_LORA_NAME, NAME_NUM_MAX);
|
||||
|
||||
adapter->net_protocol = PRIVATE_PROTOCOL;
|
||||
|
||||
#ifdef AS_LORA_GATEWAY_ROLE
|
||||
lora_gateway = PrivMalloc(sizeof(struct LoraGatewayParam));
|
||||
if (!lora_gateway) {
|
||||
PrivFree(lora_gateway);
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(lora_gateway, 0, sizeof(struct LoraGatewayParam));
|
||||
|
||||
lora_gateway->gateway_id = ADAPTER_LORA_NET_ROLE_ID;
|
||||
lora_gateway->panid = ADAPTER_LORA_NET_PANID;
|
||||
|
||||
adapter->net_role = GATEWAY;
|
||||
adapter->adapter_param = (void *)lora_gateway;
|
||||
#else //AS_LORA_CLIENT_ROLE
|
||||
lora_client = PrivMalloc(sizeof(struct LoraClientParam));
|
||||
if (!lora_client) {
|
||||
PrivFree(lora_client);
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(lora_client, 0, sizeof(struct LoraClientParam));
|
||||
|
||||
lora_client->client_id = ADAPTER_LORA_NET_ROLE_ID;
|
||||
lora_client->client_state = CLIENT_DISCONNECT;
|
||||
lora_client->panid = ADAPTER_LORA_NET_PANID;
|
||||
|
||||
adapter->net_role = CLIENT;
|
||||
adapter->adapter_param = (void *)lora_client;
|
||||
#endif
|
||||
|
||||
adapter->net_role_id = ADAPTER_LORA_NET_ROLE_ID;
|
||||
|
||||
adapter->adapter_status = UNREGISTERED;
|
||||
|
||||
ret = AdapterDeviceRegister(adapter);
|
||||
if (ret < 0) {
|
||||
printf("Adapter4G register error\n");
|
||||
if (lora_gateway)
|
||||
PrivFree(lora_gateway);
|
||||
if (lora_client)
|
||||
PrivFree(lora_client);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int AdapterLoraInit(void)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
struct Adapter *adapter = PrivMalloc(sizeof(struct Adapter));
|
||||
if (!adapter) {
|
||||
PrivFree(adapter);
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(adapter, 0, sizeof(struct Adapter));
|
||||
|
||||
ret = AdapterLoraRegister(adapter);
|
||||
if (ret < 0) {
|
||||
printf("AdapterLoraInit register lora adapter error\n");
|
||||
PrivFree(adapter);
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef ADAPTER_SX1278
|
||||
AdapterProductInfoType product_info = Sx1278Attach(adapter);
|
||||
if (!product_info) {
|
||||
printf("AdapterLoraInit sx1278 attach error\n");
|
||||
PrivFree(adapter);
|
||||
return -1;
|
||||
}
|
||||
|
||||
adapter->product_info_flag = 1;
|
||||
adapter->info = product_info;
|
||||
adapter->done = product_info->model_done;
|
||||
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/******************Lora TEST*********************/
|
||||
#ifdef AS_LORA_GATEWAY_ROLE
|
||||
static pthread_t lora_gateway_task;
|
||||
#else //AS_LORA_CLIENT_ROLE
|
||||
static pthread_t lora_client_data_task;
|
||||
static pthread_t lora_client_quit_task;
|
||||
#endif
|
||||
|
||||
int AdapterLoraTest(void)
|
||||
{
|
||||
struct Adapter *adapter = AdapterDeviceFindByName(ADAPTER_LORA_NAME);
|
||||
|
||||
AdapterDeviceOpen(adapter);
|
||||
|
||||
//create lora gateway task
|
||||
#ifdef AS_LORA_GATEWAY_ROLE
|
||||
pthread_attr_t lora_gateway_attr;
|
||||
lora_gateway_attr.schedparam.sched_priority = 20;
|
||||
lora_gateway_attr.stacksize = 2048;
|
||||
|
||||
PrivTaskCreate(&lora_gateway_task, &lora_gateway_attr, &LoraGatewayTask, (void *)adapter);
|
||||
PrivTaskStartup(&lora_gateway_task);
|
||||
|
||||
#else //AS_LORA_CLIENT_ROLE
|
||||
//create lora client task
|
||||
pthread_attr_t lora_client_attr;
|
||||
lora_client_attr.schedparam.sched_priority = 20;
|
||||
lora_client_attr.stacksize = 2048;
|
||||
|
||||
PrivTaskCreate(&lora_client_data_task, &lora_client_attr, &LoraClientDataTask, (void *)adapter);
|
||||
PrivTaskStartup(&lora_client_data_task);
|
||||
|
||||
lora_client_attr.stacksize = 1024;
|
||||
|
||||
PrivTaskCreate(&lora_client_quit_task, &lora_client_attr, &LoraClientQuitTask, (void *)adapter);
|
||||
PrivTaskStartup(&lora_client_quit_task);
|
||||
#endif
|
||||
|
||||
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, AdapterLoraTest, AdapterLoraTest, show adapter lora information);
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
config ADAPTER_LORA_SX1278
|
||||
string "SX1278 adapter name"
|
||||
default "sx1278"
|
||||
|
||||
if ADD_XIUOS_FETURES
|
||||
config ADAPTER_SX1278_DRIVER
|
||||
string "SX1278 device spi driver path"
|
||||
default "/dev/spi2_lora"
|
||||
endif
|
||||
|
||||
if ADD_NUTTX_FETURES
|
||||
|
||||
endif
|
||||
|
||||
if ADD_RTTHREAD_FETURES
|
||||
|
||||
endif
|
|
@ -0,0 +1,3 @@
|
|||
SRC_FILES := sx1278.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
|
@ -0,0 +1,152 @@
|
|||
/*
|
||||
* 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 sx1278.c
|
||||
* @brief Implement the connection lora adapter function
|
||||
* @version 1.1
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.10.20
|
||||
*/
|
||||
|
||||
#include <adapter.h>
|
||||
|
||||
/**
|
||||
* @description: Open SX1278 spi function
|
||||
* @param adapter - Lora device pointer
|
||||
* @return success: 0, failure: -1
|
||||
*/
|
||||
static int Sx1278Open(struct Adapter *adapter)
|
||||
{
|
||||
/*step1: open sx1278 spi port*/
|
||||
adapter->fd = PrivOpen(ADAPTER_SX1278_DRIVER, O_RDWR);
|
||||
if (adapter->fd < 0) {
|
||||
printf("Sx1278Open get spi %s fd error\n", ADAPTER_SX1278_DRIVER);
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("Sx1278Open done\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Close SX1278 spi function
|
||||
* @param adapter - Lora device pointer
|
||||
* @return success: 0, failure: -1
|
||||
*/
|
||||
static int Sx1278Close(struct Adapter *adapter)
|
||||
{
|
||||
/*step1: close sx1278 spi port*/
|
||||
PrivClose(adapter->fd);
|
||||
|
||||
ADAPTER_DEBUG("Sx1278Close done\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: SX1278 ioctl function
|
||||
* @param adapter - Lora device pointer
|
||||
* @param cmd - ioctl cmd
|
||||
* @param args - iotl params
|
||||
* @return success: 0, failure: -1
|
||||
*/
|
||||
static int Sx1278Ioctl(struct Adapter *adapter, int cmd, void *args)
|
||||
{
|
||||
/*to do*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: SX1278 join lora net group function
|
||||
* @param adapter - Lora device pointer
|
||||
* @param priv_net_group - priv_net_group params
|
||||
* @return success: 0, failure: -1
|
||||
*/
|
||||
static int Sx1278Join(struct Adapter *adapter, unsigned char *priv_net_group)
|
||||
{
|
||||
|
||||
PrivWrite(adapter->fd, (void *)priv_net_group, 144);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: SX1278 send data function
|
||||
* @param adapter - Lora device pointer
|
||||
* @param buf - data buffers
|
||||
* @param len - data len
|
||||
* @return success: 0, failure: -1
|
||||
*/
|
||||
static int Sx1278Send(struct Adapter *adapter, const void *buf, size_t len)
|
||||
{
|
||||
PrivWrite(adapter->fd, buf, len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: SX1278 receive data function
|
||||
* @param adapter - Lora device pointer
|
||||
* @param buf - data buffers
|
||||
* @param len - data len
|
||||
* @return success: 0, failure: -1
|
||||
*/
|
||||
static int Sx1278Recv(struct Adapter *adapter, void *buf, size_t len)
|
||||
{
|
||||
return PrivRead(adapter->fd, buf, len);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: SX1278 quit lora net group function
|
||||
* @param adapter - Lora device pointer
|
||||
* @param priv_net_group - priv_net_group params
|
||||
* @return success: 0, failure: -1
|
||||
*/
|
||||
static int Sx1278Quit(struct Adapter *adapter, unsigned char *priv_net_group)
|
||||
{
|
||||
PrivWrite(adapter->fd, (void *)priv_net_group, 144);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct PrivProtocolDone sx1278_done =
|
||||
{
|
||||
.open = Sx1278Open,
|
||||
.close = Sx1278Close,
|
||||
.ioctl = Sx1278Ioctl,
|
||||
.setup = NULL,
|
||||
.setdown = NULL,
|
||||
.setaddr = NULL,
|
||||
.setdns = NULL,
|
||||
.setdhcp = NULL,
|
||||
.ping = NULL,
|
||||
.netstat = NULL,
|
||||
.join = Sx1278Join,
|
||||
.send = Sx1278Send,
|
||||
.recv = Sx1278Recv,
|
||||
.quit = Sx1278Quit,
|
||||
};
|
||||
|
||||
AdapterProductInfoType Sx1278Attach(struct Adapter *adapter)
|
||||
{
|
||||
struct AdapterProductInfo *product_info = malloc(sizeof(struct AdapterProductInfo));
|
||||
if (!product_info) {
|
||||
printf("Sx1278Attach malloc product_info error\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
strncpy(product_info->model_name, ADAPTER_LORA_SX1278,sizeof(product_info->model_name));
|
||||
product_info->model_done = (void *)&sx1278_done;
|
||||
|
||||
return product_info;
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
config ADAPTER_HFA21_WIFI
|
||||
help
|
||||
Please check HFA21 can only work for adapter_wifi or adapter_ethernet in the meantime!
|
||||
bool "Using wifi adapter device HFA21"
|
||||
default y
|
||||
default n
|
||||
|
||||
if ADAPTER_HFA21_WIFI
|
||||
source "$APP_DIR/Framework/connection/wifi/hfa21_wifi/Kconfig"
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
#include <bus_pin.h>
|
||||
|
||||
#ifdef ADAPTER_HFA21_WIFI
|
||||
extern AdapterProductInfoType Hfa21Attach(struct Adapter *adapter);
|
||||
extern AdapterProductInfoType Hfa21WifiAttach(struct Adapter *adapter);
|
||||
#endif
|
||||
|
||||
#define ADAPTER_WIFI_NAME "wifi"
|
||||
|
@ -52,7 +52,7 @@ int AdapterWifiInit(void)
|
|||
struct Adapter *adapter = PrivMalloc(sizeof(struct Adapter));
|
||||
if (!adapter) {
|
||||
printf("AdapterWifiInit malloc error\n");
|
||||
free(adapter);
|
||||
PrivFree(adapter);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -61,15 +61,15 @@ int AdapterWifiInit(void)
|
|||
ret = AdapterWifiRegister(adapter);
|
||||
if (ret < 0) {
|
||||
printf("AdapterWifiInit register wifi adapter error\n");
|
||||
free(adapter);
|
||||
PrivFree(adapter);
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef ADAPTER_HFA21_WIFI
|
||||
AdapterProductInfoType product_info = Hfa21Attach(adapter);
|
||||
AdapterProductInfoType product_info = Hfa21WifiAttach(adapter);
|
||||
if (!product_info) {
|
||||
printf("AdapterWifiInit hfa21 attach error\n");
|
||||
free(adapter);
|
||||
PrivFree(adapter);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -167,7 +167,3 @@ int AdapterWifiTest(void)
|
|||
|
||||
}
|
||||
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);
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* @file hfa21.c
|
||||
* @file hfa21_wifi.c
|
||||
* @brief Implement the connection wifi adapter function, using HFA21 device
|
||||
* @version 1.1
|
||||
* @author AIIT XUOS Lab
|
||||
|
@ -23,14 +23,14 @@
|
|||
|
||||
#define LEN_PARA_BUF 128
|
||||
|
||||
static int Hfa21SetDown(struct Adapter *adapter_at);
|
||||
static int Hfa21WifiSetDown(struct Adapter *adapter_at);
|
||||
|
||||
/**
|
||||
* @description: enter AT command mode
|
||||
* @param at_agent - wifi device agent pointer
|
||||
* @return success: EOK
|
||||
*/
|
||||
static int Hfa21InitAtCmd(ATAgentType at_agent)
|
||||
static int Hfa21WifiInitAtCmd(ATAgentType at_agent)
|
||||
{
|
||||
ATOrderSend(at_agent, REPLY_TIME_OUT, NULL, "+++");
|
||||
PrivTaskDelay(100);
|
||||
|
@ -46,12 +46,12 @@ static int Hfa21InitAtCmd(ATAgentType at_agent)
|
|||
* @param adapter - wifi device pointer
|
||||
* @return success: EOK, failure: ENOMEMORY
|
||||
*/
|
||||
static int Hfa21Open(struct Adapter *adapter)
|
||||
static int Hfa21WifiOpen(struct Adapter *adapter)
|
||||
{
|
||||
/*step1: open ec200t serial port*/
|
||||
/*step1: open hfa21 serial port*/
|
||||
adapter->fd = PrivOpen(ADAPTER_HFA21_DRIVER, O_RDWR);
|
||||
if (adapter->fd < 0) {
|
||||
printf("Hfa21Open get serial %s fd error\n", ADAPTER_HFA21_DRIVER);
|
||||
printf("Hfa21WifiOpen get serial %s fd error\n", ADAPTER_HFA21_DRIVER);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ static int Hfa21Open(struct Adapter *adapter)
|
|||
adapter->agent = at_agent;
|
||||
}
|
||||
|
||||
ADAPTER_DEBUG("Hfa21 open done\n");
|
||||
ADAPTER_DEBUG("Hfa21Wifi open done\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -77,25 +77,25 @@ static int Hfa21Open(struct Adapter *adapter)
|
|||
* @param adapter - wifi device pointer
|
||||
* @return success: EOK
|
||||
*/
|
||||
static int Hfa21Close(struct Adapter *adapter)
|
||||
static int Hfa21WifiClose(struct Adapter *adapter)
|
||||
{
|
||||
return Hfa21SetDown(adapter);
|
||||
return Hfa21WifiSetDown(adapter);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: send data to adapter
|
||||
* @param adapter - wifi device pointer
|
||||
* @param data - data bufferd
|
||||
* @param data - data buffer
|
||||
* @param data - data length
|
||||
* @return success: EOK
|
||||
*/
|
||||
static int Hfa21Send(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;
|
||||
if (adapter->agent) {
|
||||
EntmSend(adapter->agent, (const char *)data, len);
|
||||
}else {
|
||||
printf("Can not find agent \n");
|
||||
printf("Hfa21WifiSend can not find agent!\n");
|
||||
}
|
||||
|
||||
__exit:
|
||||
|
@ -106,11 +106,11 @@ __exit:
|
|||
/**
|
||||
* @description: receive data from adapter
|
||||
* @param adapter - wifi device pointer
|
||||
* @param data - data bufferd
|
||||
* @param data - data buffer
|
||||
* @param data - data length
|
||||
* @return success: EOK
|
||||
*/
|
||||
static int Hfa21Receive(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;
|
||||
printf("hfa21 receive waiting ... \n");
|
||||
|
@ -118,7 +118,7 @@ static int Hfa21Receive(struct Adapter *adapter, void *rev_buffer, size_t buffer
|
|||
if (adapter->agent) {
|
||||
return EntmRecv(adapter->agent, (char *)rev_buffer, buffer_len, 40);
|
||||
} else {
|
||||
printf("Can not find agent \n");
|
||||
printf("Hfa21WifiReceive can not find agent!\n");
|
||||
}
|
||||
|
||||
__exit:
|
||||
|
@ -131,26 +131,25 @@ __exit:
|
|||
* @param adapter - wifi device pointer
|
||||
* @return success: EOK
|
||||
*/
|
||||
static int Hfa21SetUp(struct Adapter *adapter)
|
||||
static int Hfa21WifiSetUp(struct Adapter *adapter)
|
||||
{
|
||||
uint8 wifi_ssid[LEN_PARA_BUF] = "AIIT-Guest";
|
||||
uint8 wifi_pwd[LEN_PARA_BUF] = "";
|
||||
char cmd[LEN_PARA_BUF];
|
||||
|
||||
//struct at_device_esp8266 *esp8266 = (struct at_device_esp8266 *) device->UserData;
|
||||
struct ATAgent *agent = adapter->agent;
|
||||
|
||||
/* wait hfa21 device startup finish */
|
||||
PrivTaskDelay(5000);
|
||||
|
||||
Hfa21InitAtCmd(agent);
|
||||
Hfa21WifiInitAtCmd(agent);
|
||||
|
||||
memset(cmd,0,sizeof(cmd));
|
||||
strcpy(cmd,"AT+FCLR\r");
|
||||
ATOrderSend(agent, REPLY_TIME_OUT, NULL, cmd);
|
||||
PrivTaskDelay(20000);
|
||||
|
||||
Hfa21InitAtCmd(agent);
|
||||
Hfa21WifiInitAtCmd(agent);
|
||||
|
||||
memset(cmd,0,sizeof(cmd));
|
||||
strcpy(cmd,"AT+WSSSID=");
|
||||
|
@ -184,9 +183,9 @@ static int Hfa21SetUp(struct Adapter *adapter)
|
|||
* @param adapter - wifi device pointer
|
||||
* @return success: EOK
|
||||
*/
|
||||
static int Hfa21SetDown(struct Adapter *adapter)
|
||||
static int Hfa21WifiSetDown(struct Adapter *adapter)
|
||||
{
|
||||
Hfa21InitAtCmd(adapter->agent);
|
||||
Hfa21WifiInitAtCmd(adapter->agent);
|
||||
|
||||
ATOrderSend(adapter->agent, REPLY_TIME_OUT, NULL, "AT+FCLR\r");
|
||||
PrivTaskDelay(20000);
|
||||
|
@ -202,7 +201,7 @@ static int Hfa21SetDown(struct Adapter *adapter)
|
|||
* @param netmask - netmask address
|
||||
* @return success: EOK, failure: ENOMEMORY
|
||||
*/
|
||||
static int Hfa21SetAddr(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)
|
||||
{
|
||||
#define HFA21_SET_ADDR_EXPRESSION "+ok=%[^,],%[^,],%[^,],%[^,]\r"
|
||||
char *dhcp_mode =NULL;
|
||||
|
@ -215,7 +214,7 @@ static int Hfa21SetAddr(struct Adapter *adapter, const char *ip, const char *gat
|
|||
gw_str = (char *) PrivCalloc(1, 17);
|
||||
mask_str = (char *) PrivCalloc(1, 17);
|
||||
|
||||
Hfa21InitAtCmd(adapter->agent);
|
||||
Hfa21WifiInitAtCmd(adapter->agent);
|
||||
|
||||
x_err_t result = EOK;
|
||||
|
||||
|
@ -251,12 +250,12 @@ __exit:
|
|||
}
|
||||
|
||||
/**
|
||||
* @description: ping
|
||||
* @description: wifi ping function
|
||||
* @param adapter - wifi device pointer
|
||||
* @param destination - domain name or ip address
|
||||
* @return success: EOK, failure: ENOMEMORY
|
||||
*/
|
||||
static int Hfa21Ping(struct Adapter *adapter, const char *destination)
|
||||
static int Hfa21WifiPing(struct Adapter *adapter, const char *destination)
|
||||
{
|
||||
char *ping_result = NONE;
|
||||
char *dst = NONE;
|
||||
|
@ -265,7 +264,7 @@ static int Hfa21Ping(struct Adapter *adapter, const char *destination)
|
|||
strcpy(dst, destination);
|
||||
strcat(dst, "\r");
|
||||
|
||||
Hfa21InitAtCmd(adapter->agent);
|
||||
Hfa21WifiInitAtCmd(adapter->agent);
|
||||
|
||||
uint32 result = EOK;
|
||||
|
||||
|
@ -301,11 +300,11 @@ __exit:
|
|||
}
|
||||
|
||||
/**
|
||||
* @description: display network configuration
|
||||
* @description: display wifi network configuration
|
||||
* @param adapter - wifi device pointer
|
||||
* @return success: EOK, failure: ENOMEMORY
|
||||
*/
|
||||
static int Hfa21Netstat(struct Adapter *adapter)
|
||||
static int Hfa21WifiNetstat(struct Adapter *adapter)
|
||||
{
|
||||
#define HFA21_NETSTAT_RESP_SIZE 320
|
||||
#define HFA21_NETSTAT_TYPE_SIZE 10
|
||||
|
@ -400,7 +399,16 @@ __exit:
|
|||
PrivFree(work_mode);
|
||||
}
|
||||
|
||||
static int Hfa21Connect(struct Adapter *adapter, enum NetRoleType net_role, const char *ip, const char *port, enum IpType ip_type)
|
||||
/**
|
||||
* @description: wifi connect function
|
||||
* @param adapter - wifi device pointer
|
||||
* @param net_role - net role, CLIENT or SERVER
|
||||
* @param ip - ip address
|
||||
* @param port - port num
|
||||
* @param ip_type - ip type, IPV4 or IPV6
|
||||
* @return success: 0, failure: -1
|
||||
*/
|
||||
static int Hfa21WifiConnect(struct Adapter *adapter, enum NetRoleType net_role, const char *ip, const char *port, enum IpType ip_type)
|
||||
{
|
||||
int result = EOK;
|
||||
ATReplyType reply = NONE;
|
||||
|
@ -413,7 +421,7 @@ static int Hfa21Connect(struct Adapter *adapter, enum NetRoleType net_role, cons
|
|||
return ENOMEMORY;
|
||||
}
|
||||
|
||||
Hfa21InitAtCmd(adapter->agent);
|
||||
Hfa21WifiInitAtCmd(adapter->agent);
|
||||
|
||||
memset(cmd,0,sizeof(cmd));
|
||||
strcpy(cmd,"AT+NETP=TCP,");
|
||||
|
@ -446,10 +454,10 @@ __exit:
|
|||
return result;
|
||||
}
|
||||
|
||||
static int Hfa21Ioctl(struct Adapter *adapter, int cmd, void *args)
|
||||
static int Hfa21WifiIoctl(struct Adapter *adapter, int cmd, void *args)
|
||||
{
|
||||
if (OPE_INT != cmd) {
|
||||
printf("Hfa21Ioctl only support OPE_INT, do not support %d\n", cmd);
|
||||
printf("Hfa21WifiIoctl only support OPE_INT, do not support %d\n", cmd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -473,25 +481,25 @@ static int Hfa21Ioctl(struct Adapter *adapter, int cmd, void *args)
|
|||
ioctl_cfg.ioctl_driver_type = SERIAL_TYPE;
|
||||
ioctl_cfg.args = &serial_cfg;
|
||||
PrivIoctl(adapter->fd, OPE_INT, &ioctl_cfg);
|
||||
printf("Hfa21Ioctl success\n");
|
||||
printf("Hfa21WifiIoctl success\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct IpProtocolDone hfa21_done =
|
||||
static const struct IpProtocolDone hfa21_wifi_done =
|
||||
{
|
||||
.open = Hfa21Open,
|
||||
.close = Hfa21Close,
|
||||
.ioctl = Hfa21Ioctl,
|
||||
.setup = Hfa21SetUp,
|
||||
.setdown = Hfa21SetDown,
|
||||
.setaddr = Hfa21SetAddr,
|
||||
.open = Hfa21WifiOpen,
|
||||
.close = Hfa21WifiClose,
|
||||
.ioctl = Hfa21WifiIoctl,
|
||||
.setup = Hfa21WifiSetUp,
|
||||
.setdown = Hfa21WifiSetDown,
|
||||
.setaddr = Hfa21WifiSetAddr,
|
||||
.setdns = NULL,
|
||||
.setdhcp = NULL,
|
||||
.ping = Hfa21Ping,
|
||||
.netstat = Hfa21Netstat,
|
||||
.connect = Hfa21Connect,
|
||||
.send = Hfa21Send,
|
||||
.recv = Hfa21Receive,
|
||||
.ping = Hfa21WifiPing,
|
||||
.netstat = Hfa21WifiNetstat,
|
||||
.connect = Hfa21WifiConnect,
|
||||
.send = Hfa21WifiSend,
|
||||
.recv = Hfa21WifiReceive,
|
||||
.disconnect = NULL,
|
||||
};
|
||||
|
||||
|
@ -499,18 +507,18 @@ static const struct IpProtocolDone hfa21_done =
|
|||
* @description: Register wifi device hfa21
|
||||
* @return success: EOK, failure: ERROR
|
||||
*/
|
||||
AdapterProductInfoType Hfa21Attach(struct Adapter *adapter)
|
||||
AdapterProductInfoType Hfa21WifiAttach(struct Adapter *adapter)
|
||||
{
|
||||
struct AdapterProductInfo *product_info = PrivMalloc(sizeof(struct AdapterProductInfo));
|
||||
if (!product_info) {
|
||||
printf("Hfa21Attach Attach malloc product_info error\n");
|
||||
printf("Hfa21WifiAttach Attach malloc product_info error\n");
|
||||
PrivFree(product_info);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
strcpy(product_info->model_name, ADAPTER_WIFI_HFA21);
|
||||
|
||||
product_info->model_done = (void *)&hfa21_done;
|
||||
product_info->model_done = (void *)&hfa21_wifi_done;
|
||||
|
||||
return product_info;
|
||||
}
|
|
@ -72,14 +72,14 @@ int AdapterZigbeeInit(void)
|
|||
ret = AdapterZigbeeRegister(adapter);
|
||||
if (ret < 0) {
|
||||
printf("AdapterZigbeeRegister register zigbee adapter error\n");
|
||||
free(adapter);
|
||||
PrivFree(adapter);
|
||||
return -1;
|
||||
}
|
||||
#ifdef ADAPTER_E18
|
||||
AdapterProductInfoType product_info = E18Attach(adapter);
|
||||
if (!product_info) {
|
||||
printf("AdapterZigbeeRegister e18 attach error\n");
|
||||
free(adapter);
|
||||
PrivFree(adapter);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -257,7 +257,7 @@ static int E18Ioctl(struct Adapter *adapter, int cmd, void *args)
|
|||
return ret;
|
||||
}
|
||||
|
||||
static int E18Join(struct Adapter *adapter, const char *priv_net_group)
|
||||
static int E18Join(struct Adapter *adapter, unsigned char *priv_net_group)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
|
|
|
@ -22,42 +22,42 @@ if BSP_USING_SPI2
|
|||
config SPI_2_DRV_NAME
|
||||
string "spi bus 2 driver name"
|
||||
default "spi2_drv"
|
||||
menuconfig CONNECTION_COMMUNICATION_LORA_USING_SX1278
|
||||
bool "Using spi lora SX1278"
|
||||
menuconfig RESOURCES_SPI_LORA
|
||||
bool "Using spi lora function"
|
||||
default n
|
||||
if CONNECTION_COMMUNICATION_LORA_USING_SX1278
|
||||
if RESOURCES_SPI_LORA
|
||||
config SX12XX_SPI_DEVICE_NAME
|
||||
string "SX1278 device spi name"
|
||||
string "SX1278 lora device spi name"
|
||||
default "spi2_dev0"
|
||||
config SX12XX_DEVICE_NAME
|
||||
string "SX1278 device name"
|
||||
string "SX1278 lora device name"
|
||||
default "spi2_lora"
|
||||
|
||||
config CONNECTION_COMMUNICATION_LORA_SX12XX_RST_PIN
|
||||
config SX12XX_DEVICE_RST_PIN
|
||||
int
|
||||
default 10
|
||||
|
||||
config CONNECTION_COMMUNICATION_LORA_SX12XX_DO0_PIN
|
||||
config SX12XX_DEVICE_DO0_PIN
|
||||
int
|
||||
default 10
|
||||
|
||||
config CONNECTION_COMMUNICATION_LORA_SX12XX_DO1_PIN
|
||||
config SX12XX_DEVICE_DO1_PIN
|
||||
int
|
||||
default 10
|
||||
|
||||
config CONNECTION_COMMUNICATION_LORA_SX12XX_DO2_PIN
|
||||
config SX12XX_DEVICE_DO2_PIN
|
||||
int
|
||||
default 10
|
||||
|
||||
config CONNECTION_COMMUNICATION_LORA_SX12XX_DO3_PIN
|
||||
config SX12XX_DEVICE_DO3_PIN
|
||||
int
|
||||
default 10
|
||||
|
||||
config CONNECTION_COMMUNICATION_LORA_SX12XX_DO4_PIN
|
||||
config SX12XX_DEVICE_DO4_PIN
|
||||
int
|
||||
default 10
|
||||
|
||||
config CONNECTION_COMMUNICATION_LORA_SX12XX_DO5_PIN
|
||||
config SX12XX_DEVICE_DO5_PIN
|
||||
int
|
||||
default 10
|
||||
endif
|
||||
|
|
|
@ -4,7 +4,7 @@ ifeq ($(CONFIG_RESOURCES_SPI_SFUD),y)
|
|||
SRC_FILES += connect_flash_spi.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_CONNECTION_COMMUNICATION_LORA_USING_SX1278),y)
|
||||
ifeq ($(CONFIG_RESOURCES_SPI_LORA),y)
|
||||
SRC_DIR += third_party_spi_lora
|
||||
SRC_FILES += connect_lora_spi.c
|
||||
endif
|
||||
|
|
|
@ -38,17 +38,17 @@ void SX1276InitIo(void)
|
|||
buspin = PinBusInitGet();
|
||||
|
||||
PinCfg.cmd = GPIO_CONFIG_MODE;
|
||||
PinCfg.pin = CONNECTION_COMMUNICATION_LORA_SX12XX_DO0_PIN;
|
||||
PinCfg.pin = SX12XX_DEVICE_DO0_PIN;
|
||||
PinCfg.mode = GPIO_CFG_INPUT;
|
||||
BusDrvConfigure(buspin->owner_driver, &configure_info);
|
||||
|
||||
PinCfg.cmd = GPIO_CONFIG_MODE;
|
||||
PinCfg.pin = CONNECTION_COMMUNICATION_LORA_SX12XX_DO1_PIN;
|
||||
PinCfg.pin = SX12XX_DEVICE_DO1_PIN;
|
||||
PinCfg.mode = GPIO_CFG_INPUT;
|
||||
BusDrvConfigure(buspin->owner_driver, &configure_info);
|
||||
|
||||
PinCfg.cmd = GPIO_CONFIG_MODE;
|
||||
PinCfg.pin = CONNECTION_COMMUNICATION_LORA_SX12XX_DO2_PIN;
|
||||
PinCfg.pin = SX12XX_DEVICE_DO2_PIN;
|
||||
PinCfg.mode = GPIO_CFG_INPUT;
|
||||
BusDrvConfigure(buspin->owner_driver, &configure_info);
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ inline uint8_t SX1276ReadDio0(void)
|
|||
struct BusBlockReadParam read_param;
|
||||
read_param.buffer = (void *)&PinStat;
|
||||
|
||||
PinStat.pin = CONNECTION_COMMUNICATION_LORA_SX12XX_DO0_PIN;
|
||||
PinStat.pin = SX12XX_DEVICE_DO0_PIN;
|
||||
|
||||
return BusDevReadData(buspin->owner_haldev, &read_param);
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ inline uint8_t SX1276ReadDio1(void)
|
|||
struct BusBlockReadParam read_param;
|
||||
read_param.buffer = (void *)&PinStat;
|
||||
|
||||
PinStat.pin = CONNECTION_COMMUNICATION_LORA_SX12XX_DO1_PIN;
|
||||
PinStat.pin = SX12XX_DEVICE_DO1_PIN;
|
||||
|
||||
return BusDevReadData(buspin->owner_haldev, &read_param);
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ inline uint8_t SX1276ReadDio2(void)
|
|||
struct BusBlockReadParam read_param;
|
||||
read_param.buffer = (void *)&PinStat;
|
||||
|
||||
PinStat.pin = CONNECTION_COMMUNICATION_LORA_SX12XX_DO2_PIN;
|
||||
PinStat.pin = SX12XX_DEVICE_DO2_PIN;
|
||||
|
||||
return BusDevReadData(buspin->owner_haldev, &read_param);
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ inline uint8_t SX1276ReadDio3(void)
|
|||
struct BusBlockReadParam read_param;
|
||||
read_param.buffer = (void *)&PinStat;
|
||||
|
||||
PinStat.pin = CONNECTION_COMMUNICATION_LORA_SX12XX_DO3_PIN;
|
||||
PinStat.pin = SX12XX_DEVICE_DO3_PIN;
|
||||
|
||||
return BusDevReadData(buspin->owner_haldev, &read_param);
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ inline uint8_t SX1276ReadDio4(void)
|
|||
struct BusBlockReadParam read_param;
|
||||
read_param.buffer = (void *)&PinStat;
|
||||
|
||||
PinStat.pin = CONNECTION_COMMUNICATION_LORA_SX12XX_DO4_PIN;
|
||||
PinStat.pin = SX12XX_DEVICE_DO4_PIN;
|
||||
|
||||
return BusDevReadData(buspin->owner_haldev, &read_param);
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ inline uint8_t SX1276ReadDio5(void)
|
|||
struct BusBlockReadParam read_param;
|
||||
read_param.buffer = (void *)&PinStat;
|
||||
|
||||
PinStat.pin = CONNECTION_COMMUNICATION_LORA_SX12XX_DO5_PIN;
|
||||
PinStat.pin = SX12XX_DEVICE_DO5_PIN;
|
||||
|
||||
return BusDevReadData(buspin->owner_haldev, &read_param);
|
||||
}
|
||||
|
@ -129,11 +129,11 @@ inline void SX1276WriteRxTx(uint8_t txEnable)
|
|||
{
|
||||
if (txEnable != 0)
|
||||
{
|
||||
|
||||
/*to do*/
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/*to do*/
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -152,18 +152,18 @@ void SX1276SetReset(uint8_t state)
|
|||
if (state == RADIO_RESET_ON)
|
||||
{
|
||||
PinCfg.cmd = GPIO_CONFIG_MODE;
|
||||
PinCfg.pin = CONNECTION_COMMUNICATION_LORA_SX12XX_RST_PIN;
|
||||
PinCfg.pin = SX12XX_DEVICE_RST_PIN;
|
||||
PinCfg.mode = GPIO_CFG_OUTPUT;
|
||||
BusDrvConfigure(buspin->owner_driver, &configure_info);
|
||||
|
||||
PinStat.val = GPIO_LOW;
|
||||
PinStat.pin = CONNECTION_COMMUNICATION_LORA_SX12XX_RST_PIN;
|
||||
PinStat.pin = SX12XX_DEVICE_RST_PIN;
|
||||
BusDevWriteData(buspin->owner_haldev, &write_param);
|
||||
}
|
||||
else
|
||||
{
|
||||
PinCfg.cmd = GPIO_CONFIG_MODE;
|
||||
PinCfg.pin = CONNECTION_COMMUNICATION_LORA_SX12XX_RST_PIN;
|
||||
PinCfg.pin = SX12XX_DEVICE_RST_PIN;
|
||||
PinCfg.mode = GPIO_CFG_INPUT;
|
||||
BusDrvConfigure(buspin->owner_driver, &configure_info);
|
||||
}
|
||||
|
@ -262,10 +262,7 @@ static uint32 SpiLoraWrite(void *dev, struct BusBlockWriteParam *write_param)
|
|||
NULL_PARAM_CHECK(dev);
|
||||
NULL_PARAM_CHECK(write_param);
|
||||
|
||||
uint8 i;
|
||||
char Msg[SPI_LORA_BUFFER_SIZE] = {0};
|
||||
|
||||
if (write_param->size > 120) {
|
||||
if (write_param->size > 256) {
|
||||
KPrintf("SpiLoraWrite ERROR:The message is too long!\n");
|
||||
return ERROR;
|
||||
} else {
|
||||
|
@ -289,18 +286,34 @@ static uint32 SpiLoraRead(void *dev, struct BusBlockReadParam *read_param)
|
|||
{
|
||||
NULL_PARAM_CHECK(dev);
|
||||
NULL_PARAM_CHECK(read_param);
|
||||
|
||||
int read_times = 100;
|
||||
|
||||
//Radio->StartRx();
|
||||
SX1276StartRx();
|
||||
KPrintf("SpiLoraRead Ready!\n");
|
||||
|
||||
while (read_times) {
|
||||
if (SX1276Process() != RF_RX_DONE) {
|
||||
read_times --;
|
||||
MdelayKTask(500);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (read_times > 0) {
|
||||
SX1276GetRxPacket(read_param->buffer, (uint16 *)&read_param->read_length);
|
||||
} else {
|
||||
read_param->read_length = 0;
|
||||
}
|
||||
|
||||
//while(Radio->Process() != RF_RX_DONE);
|
||||
//Radio->GetRxPacket(read_param->buffer, (uint16 *)&read_param->read_length);
|
||||
while(SX1276Process() != RF_RX_DONE);
|
||||
SX1276GetRxPacket(read_param->buffer, (uint16 *)&read_param->read_length);
|
||||
KPrintf("SpiLoraRead : %s\n", read_param->buffer);
|
||||
// while(SX1276Process() != RF_RX_DONE);
|
||||
// SX1276GetRxPacket(read_param->buffer, (uint16 *)&read_param->read_length);
|
||||
|
||||
return EOK;
|
||||
return read_param->read_length;
|
||||
}
|
||||
|
||||
static uint32 SpiLoraOpen(void *dev)
|
||||
|
@ -354,7 +367,7 @@ static uint32 SpiLoraOpen(void *dev)
|
|||
KPrintf("LoRa check failed!\n!");
|
||||
} else {
|
||||
Radio = RadioDriverInit();
|
||||
KPrintf("LoRa check ok!\nNote: The length of the message that can be sent in a single time is 120 characters\n");
|
||||
KPrintf("LoRa check ok!\nNote: The length of the message that can be sent in a single time is 256 characters\n");
|
||||
}
|
||||
|
||||
lora_init_status = RET_TRUE;
|
||||
|
@ -480,6 +493,7 @@ int LoraSx12xxSpiDeviceInit(void)
|
|||
return EOK;
|
||||
}
|
||||
|
||||
//#define LORA_TEST
|
||||
#ifdef LORA_TEST
|
||||
/*Just for lora test*/
|
||||
static struct Bus *bus;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -183,6 +183,7 @@ tSX1276LR* SX1276LR;
|
|||
* Local RF buffer for communication support
|
||||
*/
|
||||
static uint8_t RFBuffer[RF_BUFFER_SIZE];
|
||||
static uint8_t TFBuffer[RF_BUFFER_SIZE];
|
||||
|
||||
/*!
|
||||
* RF state machine variable
|
||||
|
@ -401,7 +402,7 @@ void SX1276LoRaSetTxPacket( const void *buffer, uint16_t size )
|
|||
{
|
||||
TxPacketSize = 255;
|
||||
}
|
||||
memcpy( ( void * )RFBuffer, buffer, ( size_t )TxPacketSize );
|
||||
memcpy( ( void * )TFBuffer, buffer, ( size_t )TxPacketSize );
|
||||
|
||||
RFLRState = RFLR_STATE_TX_INIT;
|
||||
}
|
||||
|
@ -678,7 +679,7 @@ uint32_t SX1276LoRaProcess( void )
|
|||
SX1276LR->RegFifoAddrPtr = SX1276LR->RegFifoTxBaseAddr;
|
||||
SX1276Write( REG_LR_FIFOADDRPTR, SX1276LR->RegFifoAddrPtr );
|
||||
// Write payload buffer to LORA modem
|
||||
SX1276WriteFifo( RFBuffer, SX1276LR->RegPayloadLength );
|
||||
SX1276WriteFifo( TFBuffer, SX1276LR->RegPayloadLength );
|
||||
// TxDone RxTimeout FhssChangeChannel ValidHeader
|
||||
SX1276LR->RegDioMapping1 = RFLR_DIOMAPPING1_DIO0_01 | RFLR_DIOMAPPING1_DIO1_00 | RFLR_DIOMAPPING1_DIO2_00 | RFLR_DIOMAPPING1_DIO3_01;
|
||||
// PllLock Mode Ready
|
||||
|
|
|
@ -240,8 +240,10 @@
|
|||
#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
|
||||
|
||||
|
||||
#if defined ( __GNUC__ ) /* GNU Compiler */
|
||||
#if defined ( __GNUC__ ) /* GNU Compiler */
|
||||
#ifndef __packed
|
||||
#define __packed __attribute__ ((__packed__))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
|
|
@ -29,38 +29,38 @@ if BSP_USING_SPI1
|
|||
config BSP_SPI1_SS0_PIN
|
||||
int "spi1 ss0 pin number"
|
||||
default 9
|
||||
menuconfig CONNECTION_COMMUNICATION_LORA_USING_SX1278
|
||||
bool "Using spi lora SX1278"
|
||||
menuconfig RESOURCES_SPI_LORA
|
||||
bool "Using spi lora function"
|
||||
default n
|
||||
if CONNECTION_COMMUNICATION_LORA_USING_SX1278
|
||||
if RESOURCES_SPI_LORA
|
||||
config SX12XX_DEVICE_NAME
|
||||
string "SX1278 device name"
|
||||
string "SX1278 lora device name"
|
||||
default "spi1_lora"
|
||||
config CONNECTION_COMMUNICATION_LORA_SX12XX_RST_PIN
|
||||
config SX12XX_DEVICE_RST_PIN
|
||||
int
|
||||
default 10
|
||||
|
||||
config CONNECTION_COMMUNICATION_LORA_SX12XX_DO0_PIN
|
||||
config SX12XX_DEVICE_DO0_PIN
|
||||
int
|
||||
default 10
|
||||
|
||||
config CONNECTION_COMMUNICATION_LORA_SX12XX_DO1_PIN
|
||||
config SX12XX_DEVICE_DO1_PIN
|
||||
int
|
||||
default 10
|
||||
|
||||
config CONNECTION_COMMUNICATION_LORA_SX12XX_DO2_PIN
|
||||
config SX12XX_DEVICE_DO2_PIN
|
||||
int
|
||||
default 10
|
||||
|
||||
config CONNECTION_COMMUNICATION_LORA_SX12XX_DO3_PIN
|
||||
config SX12XX_DEVICE_DO3_PIN
|
||||
int
|
||||
default 10
|
||||
|
||||
config CONNECTION_COMMUNICATION_LORA_SX12XX_DO4_PIN
|
||||
config SX12XX_DEVICE_DO4_PIN
|
||||
int
|
||||
default 10
|
||||
|
||||
config CONNECTION_COMMUNICATION_LORA_SX12XX_DO5_PIN
|
||||
config SX12XX_DEVICE_DO5_PIN
|
||||
int
|
||||
default 10
|
||||
endif
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
SRC_FILES := connect_spi.c hardware_spi.c
|
||||
|
||||
|
||||
ifeq ($(CONFIG_CONNECTION_COMMUNICATION_LORA_USING_SX1278),y)
|
||||
ifeq ($(CONFIG_RESOURCES_SPI_LORA),y)
|
||||
SRC_DIR += third_party_spi_lora
|
||||
SRC_FILES += connect_lora_spi.c
|
||||
endif
|
||||
|
|
|
@ -38,17 +38,17 @@ void SX1276InitIo(void)
|
|||
buspin = PinBusInitGet();
|
||||
|
||||
PinCfg.cmd = GPIO_CONFIG_MODE;
|
||||
PinCfg.pin = CONNECTION_COMMUNICATION_LORA_SX12XX_DO0_PIN;
|
||||
PinCfg.pin = SX12XX_DEVICE_DO0_PIN;
|
||||
PinCfg.mode = GPIO_CFG_INPUT;
|
||||
BusDrvConfigure(buspin->owner_driver, &configure_info);
|
||||
|
||||
PinCfg.cmd = GPIO_CONFIG_MODE;
|
||||
PinCfg.pin = CONNECTION_COMMUNICATION_LORA_SX12XX_DO1_PIN;
|
||||
PinCfg.pin = SX12XX_DEVICE_DO1_PIN;
|
||||
PinCfg.mode = GPIO_CFG_INPUT;
|
||||
BusDrvConfigure(buspin->owner_driver, &configure_info);
|
||||
|
||||
PinCfg.cmd = GPIO_CONFIG_MODE;
|
||||
PinCfg.pin = CONNECTION_COMMUNICATION_LORA_SX12XX_DO2_PIN;
|
||||
PinCfg.pin = SX12XX_DEVICE_DO2_PIN;
|
||||
PinCfg.mode = GPIO_CFG_INPUT;
|
||||
BusDrvConfigure(buspin->owner_driver, &configure_info);
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ inline uint8_t SX1276ReadDio0(void)
|
|||
struct BusBlockReadParam read_param;
|
||||
read_param.buffer = (void *)&PinStat;
|
||||
|
||||
PinStat.pin = CONNECTION_COMMUNICATION_LORA_SX12XX_DO0_PIN;
|
||||
PinStat.pin = SX12XX_DEVICE_DO0_PIN;
|
||||
|
||||
return BusDevReadData(buspin->owner_haldev, &read_param);
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ inline uint8_t SX1276ReadDio1(void)
|
|||
struct BusBlockReadParam read_param;
|
||||
read_param.buffer = (void *)&PinStat;
|
||||
|
||||
PinStat.pin = CONNECTION_COMMUNICATION_LORA_SX12XX_DO1_PIN;
|
||||
PinStat.pin = SX12XX_DEVICE_DO1_PIN;
|
||||
|
||||
return BusDevReadData(buspin->owner_haldev, &read_param);
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ inline uint8_t SX1276ReadDio2(void)
|
|||
struct BusBlockReadParam read_param;
|
||||
read_param.buffer = (void *)&PinStat;
|
||||
|
||||
PinStat.pin = CONNECTION_COMMUNICATION_LORA_SX12XX_DO2_PIN;
|
||||
PinStat.pin = SX12XX_DEVICE_DO2_PIN;
|
||||
|
||||
return BusDevReadData(buspin->owner_haldev, &read_param);
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ inline uint8_t SX1276ReadDio3(void)
|
|||
struct BusBlockReadParam read_param;
|
||||
read_param.buffer = (void *)&PinStat;
|
||||
|
||||
PinStat.pin = CONNECTION_COMMUNICATION_LORA_SX12XX_DO3_PIN;
|
||||
PinStat.pin = SX12XX_DEVICE_DO3_PIN;
|
||||
|
||||
return BusDevReadData(buspin->owner_haldev, &read_param);
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ inline uint8_t SX1276ReadDio4(void)
|
|||
struct BusBlockReadParam read_param;
|
||||
read_param.buffer = (void *)&PinStat;
|
||||
|
||||
PinStat.pin = CONNECTION_COMMUNICATION_LORA_SX12XX_DO4_PIN;
|
||||
PinStat.pin = SX12XX_DEVICE_DO4_PIN;
|
||||
|
||||
return BusDevReadData(buspin->owner_haldev, &read_param);
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ inline uint8_t SX1276ReadDio5(void)
|
|||
struct BusBlockReadParam read_param;
|
||||
read_param.buffer = (void *)&PinStat;
|
||||
|
||||
PinStat.pin = CONNECTION_COMMUNICATION_LORA_SX12XX_DO5_PIN;
|
||||
PinStat.pin = SX12XX_DEVICE_DO5_PIN;
|
||||
|
||||
return BusDevReadData(buspin->owner_haldev, &read_param);
|
||||
}
|
||||
|
@ -145,18 +145,18 @@ void SX1276SetReset(uint8_t state)
|
|||
if (state == RADIO_RESET_ON)
|
||||
{
|
||||
PinCfg.cmd = GPIO_CONFIG_MODE;
|
||||
PinCfg.pin = CONNECTION_COMMUNICATION_LORA_SX12XX_RST_PIN;
|
||||
PinCfg.pin = SX12XX_DEVICE_RST_PIN;
|
||||
PinCfg.mode = GPIO_CFG_OUTPUT;
|
||||
BusDrvConfigure(buspin->owner_driver, &configure_info);
|
||||
|
||||
PinStat.val = GPIO_LOW;
|
||||
PinStat.pin = CONNECTION_COMMUNICATION_LORA_SX12XX_RST_PIN;
|
||||
PinStat.pin = SX12XX_DEVICE_RST_PIN;
|
||||
BusDevWriteData(buspin->owner_haldev, &write_param);
|
||||
}
|
||||
else
|
||||
{
|
||||
PinCfg.cmd = GPIO_CONFIG_MODE;
|
||||
PinCfg.pin = CONNECTION_COMMUNICATION_LORA_SX12XX_RST_PIN;
|
||||
PinCfg.pin = SX12XX_DEVICE_RST_PIN;
|
||||
PinCfg.mode = GPIO_CFG_INPUT;
|
||||
BusDrvConfigure(buspin->owner_driver, &configure_info);
|
||||
}
|
||||
|
@ -255,10 +255,7 @@ static uint32 SpiLoraWrite(void *dev, struct BusBlockWriteParam *write_param)
|
|||
NULL_PARAM_CHECK(dev);
|
||||
NULL_PARAM_CHECK(write_param);
|
||||
|
||||
uint8 i;
|
||||
char Msg[SPI_LORA_BUFFER_SIZE] = {0};
|
||||
|
||||
if (write_param->size > 120) {
|
||||
if (write_param->size > 256) {
|
||||
KPrintf("SpiLoraWrite ERROR:The message is too long!\n");
|
||||
return ERROR;
|
||||
} else {
|
||||
|
@ -282,18 +279,34 @@ static uint32 SpiLoraRead(void *dev, struct BusBlockReadParam *read_param)
|
|||
{
|
||||
NULL_PARAM_CHECK(dev);
|
||||
NULL_PARAM_CHECK(read_param);
|
||||
|
||||
int read_times = 1000;
|
||||
|
||||
//Radio->StartRx();
|
||||
SX1276StartRx();
|
||||
KPrintf("SpiLoraRead Ready!\n");
|
||||
|
||||
while (read_times) {
|
||||
if (SX1276Process() != RF_RX_DONE) {
|
||||
read_times --;
|
||||
MdelayKTask(500);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (read_times > 0) {
|
||||
SX1276GetRxPacket(read_param->buffer, (uint16 *)&read_param->read_length);
|
||||
} else {
|
||||
read_param->read_length = 0;
|
||||
}
|
||||
|
||||
//while(Radio->Process() != RF_RX_DONE);
|
||||
//Radio->GetRxPacket(read_param->buffer, (uint16 *)&read_param->read_length);
|
||||
while(SX1276Process() != RF_RX_DONE);
|
||||
SX1276GetRxPacket(read_param->buffer, (uint16 *)&read_param->read_length);
|
||||
KPrintf("SpiLoraRead : %s\n", read_param->buffer);
|
||||
// while(SX1276Process() != RF_RX_DONE);
|
||||
// SX1276GetRxPacket(read_param->buffer, (uint16 *)&read_param->read_length);
|
||||
|
||||
return EOK;
|
||||
return read_param->read_length;
|
||||
}
|
||||
|
||||
static uint32 SpiLoraOpen(void *dev)
|
||||
|
@ -347,7 +360,7 @@ static uint32 SpiLoraOpen(void *dev)
|
|||
KPrintf("LoRa check failed!\n!");
|
||||
} else {
|
||||
Radio = RadioDriverInit();
|
||||
KPrintf("LoRa check ok!\nNote: The length of the message that can be sent in a single time is 120 characters\n");
|
||||
KPrintf("LoRa check ok!\nNote: The length of the message that can be sent in a single time is 256 characters\n");
|
||||
}
|
||||
|
||||
lora_init_status = RET_TRUE;
|
||||
|
@ -465,6 +478,7 @@ int LoraSx12xxSpiDeviceInit(void)
|
|||
return EOK;
|
||||
}
|
||||
|
||||
//#define LORA_TEST
|
||||
#ifdef LORA_TEST
|
||||
/*Just for lora test*/
|
||||
static struct Bus *bus;
|
||||
|
|
|
@ -214,13 +214,14 @@ static uint32 SpiWriteData(struct SpiHardwareDevice *spi_dev, struct SpiDataStan
|
|||
spi_datacfg = spi_datacfg->next;
|
||||
}
|
||||
|
||||
return spi_datacfg->length;
|
||||
return EOK;
|
||||
}
|
||||
|
||||
static uint32 SpiReadData(struct SpiHardwareDevice *spi_dev, struct SpiDataStandard *spi_datacfg)
|
||||
{
|
||||
SpiDeviceParam *dev_param = (SpiDeviceParam *)(spi_dev->haldev.private_data);
|
||||
|
||||
uint32 spi_read_length = 0;;
|
||||
uint8 device_id = dev_param->spi_slave_param->spi_slave_id;
|
||||
uint8 device_master_id = dev_param->spi_dma_param->spi_master_id;
|
||||
uint8 cs_gpio_pin = dev_param->spi_slave_param->spi_cs_gpio_pin;
|
||||
|
@ -282,10 +283,11 @@ static uint32 SpiReadData(struct SpiHardwareDevice *spi_dev, struct SpiDataStand
|
|||
gpiohs_set_pin(cs_gpio_pin, GPIO_PV_HIGH);
|
||||
}
|
||||
|
||||
spi_read_length += spi_datacfg->length;
|
||||
spi_datacfg = spi_datacfg->next;
|
||||
}
|
||||
|
||||
return spi_datacfg->length;
|
||||
return spi_read_length;
|
||||
}
|
||||
|
||||
/*manage the spi device operations*/
|
||||
|
|
|
@ -183,6 +183,7 @@ tSX1276LR* SX1276LR;
|
|||
* Local RF buffer for communication support
|
||||
*/
|
||||
static uint8_t RFBuffer[RF_BUFFER_SIZE];
|
||||
static uint8_t TFBuffer[RF_BUFFER_SIZE];
|
||||
|
||||
/*!
|
||||
* RF state machine variable
|
||||
|
@ -401,7 +402,7 @@ void SX1276LoRaSetTxPacket( const void *buffer, uint16_t size )
|
|||
{
|
||||
TxPacketSize = 255;
|
||||
}
|
||||
memcpy( ( void * )RFBuffer, buffer, ( size_t )TxPacketSize );
|
||||
memcpy( ( void * )TFBuffer, buffer, ( size_t )TxPacketSize );
|
||||
|
||||
RFLRState = RFLR_STATE_TX_INIT;
|
||||
}
|
||||
|
@ -678,7 +679,7 @@ uint32_t SX1276LoRaProcess( void )
|
|||
SX1276LR->RegFifoAddrPtr = SX1276LR->RegFifoTxBaseAddr;
|
||||
SX1276Write( REG_LR_FIFOADDRPTR, SX1276LR->RegFifoAddrPtr );
|
||||
// Write payload buffer to LORA modem
|
||||
SX1276WriteFifo( RFBuffer, SX1276LR->RegPayloadLength );
|
||||
SX1276WriteFifo( TFBuffer, SX1276LR->RegPayloadLength );
|
||||
// TxDone RxTimeout FhssChangeChannel ValidHeader
|
||||
SX1276LR->RegDioMapping1 = RFLR_DIOMAPPING1_DIO0_01 | RFLR_DIOMAPPING1_DIO1_00 | RFLR_DIOMAPPING1_DIO2_00 | RFLR_DIOMAPPING1_DIO3_01;
|
||||
// PllLock Mode Ready
|
||||
|
|
|
@ -215,13 +215,14 @@ static uint32 SpiWriteData(struct SpiHardwareDevice *spi_dev, struct SpiDataStan
|
|||
spi_datacfg = spi_datacfg->next;
|
||||
}
|
||||
|
||||
return spi_datacfg->length;
|
||||
return EOK;
|
||||
}
|
||||
|
||||
static uint32 SpiReadData(struct SpiHardwareDevice *spi_dev, struct SpiDataStandard *spi_datacfg)
|
||||
{
|
||||
SpiDeviceParam *dev_param = (SpiDeviceParam *)(spi_dev->haldev.private_data);
|
||||
|
||||
uint32 spi_read_length = 0;
|
||||
uint8 device_id = dev_param->spi_slave_param->spi_slave_id;
|
||||
uint8 device_master_id = dev_param->spi_dma_param->spi_master_id;
|
||||
uint8 cs_gpio_pin = dev_param->spi_slave_param->spi_cs_gpio_pin;
|
||||
|
@ -281,10 +282,11 @@ static uint32 SpiReadData(struct SpiHardwareDevice *spi_dev, struct SpiDataStand
|
|||
gpiohs_set_pin(cs_gpio_pin, GPIO_PV_HIGH);
|
||||
}
|
||||
|
||||
spi_read_length += spi_datacfg->length;
|
||||
spi_datacfg = spi_datacfg->next;
|
||||
}
|
||||
|
||||
return spi_datacfg->length;
|
||||
return spi_read_length;
|
||||
}
|
||||
|
||||
/*manage the spi device operations*/
|
||||
|
|
|
@ -1097,7 +1097,7 @@ static uint32 Stm32SpiWriteData(struct SpiHardwareDevice *spi_dev, struct SpiDat
|
|||
}
|
||||
|
||||
if (state != 0) {
|
||||
KPrintf("spi transfer error : %d\n", state);
|
||||
KPrintf("spi write error : %d\n", state);
|
||||
spi_datacfg->length = 0;
|
||||
}
|
||||
}
|
||||
|
@ -1109,7 +1109,7 @@ static uint32 Stm32SpiWriteData(struct SpiHardwareDevice *spi_dev, struct SpiDat
|
|||
spi_datacfg = spi_datacfg->next;
|
||||
}
|
||||
|
||||
return spi_datacfg->length;
|
||||
return EOK;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1125,7 +1125,7 @@ static uint32 Stm32SpiReadData(struct SpiHardwareDevice *spi_dev, struct SpiData
|
|||
{
|
||||
int state;
|
||||
x_size_t message_length, already_send_length;
|
||||
uint16 send_length;
|
||||
uint16 read_length, spi_read_length = 0;
|
||||
const uint8 *ReadBuf;
|
||||
|
||||
NULL_PARAM_CHECK(spi_dev);
|
||||
|
@ -1145,29 +1145,29 @@ static uint32 Stm32SpiReadData(struct SpiHardwareDevice *spi_dev, struct SpiData
|
|||
ReadBuf = spi_datacfg->rx_buff;
|
||||
while (message_length) {
|
||||
if (message_length > 65535) {
|
||||
send_length = 65535;
|
||||
read_length = 65535;
|
||||
message_length = message_length - 65535;
|
||||
} else {
|
||||
send_length = message_length;
|
||||
read_length = message_length;
|
||||
message_length = 0;
|
||||
}
|
||||
|
||||
/* calculate the start address */
|
||||
already_send_length = spi_datacfg->length - send_length - message_length;
|
||||
already_send_length = spi_datacfg->length - read_length - message_length;
|
||||
ReadBuf = (uint8 *)spi_datacfg->rx_buff + already_send_length;
|
||||
|
||||
/* start once data exchange in DMA mode */
|
||||
if (spi_datacfg->rx_buff) {
|
||||
memset((uint8_t *)ReadBuf, 0xff, send_length);
|
||||
//memset((uint8_t *)ReadBuf, 0xff, read_length);
|
||||
if (StmSpi->spi_dma_flag & SPI_USING_RX_DMA_FLAG) {
|
||||
state = SpiReceiveDma(*spi_init, spi_instance, StmSpi->dma.dma_rx.init, StmSpi->dma.dma_rx.instance, StmSpi->dma.dma_tx.init, StmSpi->dma.dma_tx.instance, (uint8_t *)ReadBuf, send_length);
|
||||
state = SpiReceiveDma(*spi_init, spi_instance, StmSpi->dma.dma_rx.init, StmSpi->dma.dma_rx.instance, StmSpi->dma.dma_tx.init, StmSpi->dma.dma_tx.instance, (uint8_t *)ReadBuf, read_length);
|
||||
} else {
|
||||
state = SpiReceive(*spi_init, spi_instance, (uint8_t *)ReadBuf, send_length, 1000);
|
||||
state = SpiReceive(*spi_init, spi_instance, (uint8_t *)ReadBuf, read_length, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
if (state != 0) {
|
||||
KPrintf("spi transfer error : %d\n", state);
|
||||
KPrintf("spi read error : %d\n", state);
|
||||
spi_datacfg->length = 0;
|
||||
}
|
||||
}
|
||||
|
@ -1176,10 +1176,11 @@ static uint32 Stm32SpiReadData(struct SpiHardwareDevice *spi_dev, struct SpiData
|
|||
GPIO_WriteBit(cs->GPIOx, cs->GPIO_Pin, Bit_SET);
|
||||
}
|
||||
|
||||
spi_read_length += spi_datacfg->length;
|
||||
spi_datacfg = spi_datacfg->next;
|
||||
}
|
||||
|
||||
return spi_datacfg->length;
|
||||
return spi_read_length;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -37,6 +37,7 @@ void InitCmpts(void);
|
|||
extern int VfsInit(void);
|
||||
extern int WorkSysWorkQueueInit(void);
|
||||
extern int FlashW25qxxSpiDeviceInit(void);
|
||||
extern int LoraSx12xxSpiDeviceInit(void);
|
||||
extern int FatfsInit(void);
|
||||
extern int Ch376fsInit(void);
|
||||
extern int LibcSystemInit(void);
|
||||
|
|
|
@ -81,6 +81,10 @@ struct InitSequenceDesc device_init[] =
|
|||
#ifdef RESOURCES_SPI_SFUD
|
||||
{ "W25Qxx_spi", FlashW25qxxSpiDeviceInit},
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef RESOURCES_SPI_LORA
|
||||
{"LORA_spi", LoraSx12xxSpiDeviceInit},
|
||||
#endif
|
||||
{ " NONE ", NONE },
|
||||
};
|
||||
|
|
|
@ -58,7 +58,7 @@ struct SpiDataStandard
|
|||
const uint8 *tx_buff;
|
||||
uint32 tx_len;
|
||||
|
||||
const uint8 *rx_buff;
|
||||
uint8 *rx_buff;
|
||||
uint32 rx_len;
|
||||
|
||||
uint32 length;
|
||||
|
|
|
@ -52,17 +52,30 @@ static uint32 SpiDeviceWrite(void *dev, struct BusBlockWriteParam *write_param)
|
|||
NULL_PARAM_CHECK(dev);
|
||||
NULL_PARAM_CHECK(write_param);
|
||||
|
||||
int ret;
|
||||
struct SpiHardwareDevice *spi_dev = (struct SpiHardwareDevice *)dev;
|
||||
struct SpiDataStandard spi_msg;
|
||||
struct SpiDataStandard *spi_msg;
|
||||
|
||||
spi_msg.tx_buff = (uint8 *)write_param->buffer;
|
||||
spi_msg.rx_buff = NONE;
|
||||
spi_msg.length = write_param->size;
|
||||
spi_msg.spi_chip_select = 0;
|
||||
spi_msg.spi_cs_release = 0;
|
||||
spi_msg.next = NONE;
|
||||
spi_msg = (struct SpiDataStandard *)x_malloc(sizeof(struct SpiDataStandard));
|
||||
if (NONE == spi_msg) {
|
||||
KPrintf("SpiDeviceWrite x_malloc msg error\n");
|
||||
x_free(spi_msg);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
return spi_dev->spi_dev_done->dev_write(spi_dev, &spi_msg);
|
||||
//memset(spi_msg, 0, sizeof(struct SpiDataStandard));
|
||||
|
||||
spi_msg->tx_buff = (uint8 *)write_param->buffer;
|
||||
spi_msg->rx_buff = NONE;
|
||||
spi_msg->length = write_param->size;
|
||||
spi_msg->spi_chip_select = 0;
|
||||
spi_msg->spi_cs_release = 0;
|
||||
spi_msg->next = NONE;
|
||||
|
||||
ret = spi_dev->spi_dev_done->dev_write(spi_dev, spi_msg);
|
||||
x_free(spi_msg);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static uint32 SpiDeviceRead(void *dev, struct BusBlockReadParam *read_param)
|
||||
|
@ -70,17 +83,30 @@ static uint32 SpiDeviceRead(void *dev, struct BusBlockReadParam *read_param)
|
|||
NULL_PARAM_CHECK(dev);
|
||||
NULL_PARAM_CHECK(read_param);
|
||||
|
||||
int ret;
|
||||
struct SpiHardwareDevice *spi_dev = (struct SpiHardwareDevice *)dev;
|
||||
struct SpiDataStandard spi_msg;
|
||||
struct SpiDataStandard *spi_msg;
|
||||
|
||||
spi_msg.tx_buff = NONE;
|
||||
spi_msg.rx_buff = (uint8 *)read_param->buffer;
|
||||
spi_msg.length = read_param->size;
|
||||
spi_msg.spi_chip_select = 0;
|
||||
spi_msg.spi_cs_release = 0;
|
||||
spi_msg.next = NONE;
|
||||
spi_msg = (struct SpiDataStandard *)x_malloc(sizeof(struct SpiDataStandard));
|
||||
if (NONE == spi_msg) {
|
||||
KPrintf("SpiDeviceRead x_malloc msg error\n");
|
||||
x_free(spi_msg);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
return spi_dev->spi_dev_done->dev_read(spi_dev, &spi_msg);
|
||||
//memset(spi_msg, 0, sizeof(struct SpiDataStandard));
|
||||
|
||||
spi_msg->tx_buff = NONE;
|
||||
spi_msg->rx_buff = (uint8 *)read_param->buffer;
|
||||
spi_msg->length = read_param->size;
|
||||
spi_msg->spi_chip_select = 0;
|
||||
spi_msg->spi_cs_release = 0;
|
||||
spi_msg->next = NONE;
|
||||
|
||||
ret = spi_dev->spi_dev_done->dev_read(spi_dev, spi_msg);
|
||||
x_free(spi_msg);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const struct HalDevDone dev_done =
|
||||
|
@ -183,12 +209,27 @@ int SpiDevConfigureCs(struct HardwareDev *dev, uint8 spi_chip_select, uint8 spi_
|
|||
{
|
||||
NULL_PARAM_CHECK(dev);
|
||||
|
||||
int ret;
|
||||
struct SpiHardwareDevice *spi_dev = (struct SpiHardwareDevice *)dev;
|
||||
struct SpiDataStandard msg;
|
||||
struct SpiDataStandard *msg;
|
||||
|
||||
memset(&msg, 0, sizeof(struct SpiDataStandard));
|
||||
msg.spi_chip_select = spi_chip_select;
|
||||
msg.spi_cs_release = spi_cs_release;
|
||||
msg = (struct SpiDataStandard *)x_malloc(sizeof(struct SpiDataStandard));
|
||||
if (NONE == msg) {
|
||||
KPrintf("SpiDevConfigureCs x_malloc msg error\n");
|
||||
x_free(msg);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
return spi_dev->spi_dev_done->dev_write(spi_dev, &msg);
|
||||
//memset(msg, 0, sizeof(struct SpiDataStandard));
|
||||
msg->length = 0;
|
||||
msg->rx_buff = NONE;
|
||||
msg->tx_buff = NONE;
|
||||
msg->next = NONE;
|
||||
msg->spi_chip_select = spi_chip_select;
|
||||
msg->spi_cs_release = spi_cs_release;
|
||||
|
||||
ret = spi_dev->spi_dev_done->dev_write(spi_dev, msg);
|
||||
|
||||
x_free(msg);
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -491,14 +491,14 @@ x_err_t UsbhClearFeature(UinstPointer device, int endpoint, int feature)
|
|||
x_err_t UsbhGetInterfaceDescriptor(UcfgDescPointer CfgDesc, int num,
|
||||
UintfDescPointer* IntfDesc)
|
||||
{
|
||||
uint64 ptr, depth = 0;
|
||||
uint32 ptr, depth = 0;
|
||||
UdescPointer desc;
|
||||
|
||||
|
||||
NULL_PARAM_CHECK(CfgDesc);
|
||||
|
||||
ptr = (uint64)CfgDesc + CfgDesc->bLength;
|
||||
while(ptr < (uint64)CfgDesc + CfgDesc->wTotalLength)
|
||||
ptr = (uint32)CfgDesc + CfgDesc->bLength;
|
||||
while(ptr < (uint32)CfgDesc + CfgDesc->wTotalLength)
|
||||
{
|
||||
if(depth++ > 0x20)
|
||||
{
|
||||
|
@ -517,7 +517,7 @@ x_err_t UsbhGetInterfaceDescriptor(UcfgDescPointer CfgDesc, int num,
|
|||
return EOK;
|
||||
}
|
||||
}
|
||||
ptr = (uint64)desc + desc->bLength;
|
||||
ptr = (uint32)desc + desc->bLength;
|
||||
}
|
||||
|
||||
KPrintf("usb_get_interface_descriptor %d failed\n", num);
|
||||
|
@ -538,7 +538,7 @@ x_err_t UsbhGetEndpointDescriptor(UintfDescPointer IntfDesc, int num,
|
|||
UepDescPointer* EpDesc)
|
||||
{
|
||||
int count = 0, depth = 0;
|
||||
uint64 ptr;
|
||||
uint32 ptr;
|
||||
UdescPointer desc;
|
||||
|
||||
|
||||
|
@ -546,7 +546,7 @@ x_err_t UsbhGetEndpointDescriptor(UintfDescPointer IntfDesc, int num,
|
|||
CHECK(num < IntfDesc->bNumEndpoints);
|
||||
*EpDesc = NONE;
|
||||
|
||||
ptr = (uint64)IntfDesc + IntfDesc->bLength;
|
||||
ptr = (uint32)IntfDesc + IntfDesc->bLength;
|
||||
while(count < IntfDesc->bNumEndpoints)
|
||||
{
|
||||
if(depth++ > 0x20)
|
||||
|
@ -567,7 +567,7 @@ x_err_t UsbhGetEndpointDescriptor(UintfDescPointer IntfDesc, int num,
|
|||
}
|
||||
else count++;
|
||||
}
|
||||
ptr = (uint64)desc + desc->bLength;
|
||||
ptr = (uint32)desc + desc->bLength;
|
||||
}
|
||||
|
||||
KPrintf("usb_get_endpoint_descriptor %d failed\n", num);
|
||||
|
|
|
@ -49,7 +49,7 @@ static x_err_t RootHubCtrl(struct uhcd *hcd, uint16 port, uint8 cmd, void *args)
|
|||
hcd->roothub->PortStatus[port-1] = (*(uint32 *)args);
|
||||
break;
|
||||
case RH_CLEAR_PORT_FEATURE:
|
||||
switch(((uint64)args))
|
||||
switch(((uint32)args))
|
||||
{
|
||||
case PORT_FEAT_C_CONNECTION:
|
||||
hcd->roothub->PortStatus[port-1] &= ~PORT_CCSC;
|
||||
|
@ -69,7 +69,7 @@ static x_err_t RootHubCtrl(struct uhcd *hcd, uint16 port, uint8 cmd, void *args)
|
|||
}
|
||||
break;
|
||||
case RH_SET_PORT_FEATURE:
|
||||
switch((uint64)args)
|
||||
switch((uint32)args)
|
||||
{
|
||||
case PORT_FEAT_CONNECTION:
|
||||
hcd->roothub->PortStatus[port-1] |= PORT_CCSC;
|
||||
|
@ -222,7 +222,7 @@ x_err_t UsbhHubClearPortFeature(UhubPointer hub, uint16 port, uint16 feature)
|
|||
if(hub->IsRoothub)
|
||||
{
|
||||
RootHubCtrl(hub->hcd, port, RH_CLEAR_PORT_FEATURE,
|
||||
(void*)(uint64)feature);
|
||||
(void*)(uint32)feature);
|
||||
return EOK;
|
||||
}
|
||||
|
||||
|
@ -254,7 +254,7 @@ x_err_t UsbhHubSetPortFeature(UhubPointer hub, uint16 port,
|
|||
if(hub->IsRoothub)
|
||||
{
|
||||
RootHubCtrl(hub->hcd, port, RH_SET_PORT_FEATURE,
|
||||
(void*)(uint64)feature);
|
||||
(void*)(uint32)feature);
|
||||
return EOK;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue