1、support adapter_lora gateway and client state-machine-model;2、fix aiit-arm32-board usb compile error.

This commit is contained in:
Liu_Weichao 2021-11-17 17:37:04 +08:00
parent c631063b7a
commit 7a172fd136
17 changed files with 721 additions and 575 deletions

View File

@ -419,9 +419,10 @@ int AdapterDeviceJoin(struct Adapter *adapter, unsigned char *priv_net_group)
/** /**
* @description: Adapter disconnect from ip net or private net group * @description: Adapter disconnect from ip net or private net group
* @param adapter - adapter device pointer * @param adapter - adapter device pointer
* @param priv_net_group - private net group for PRIVATE_PROTOCOL quit function
* @return success: 0 , failure: other * @return success: 0 , failure: other
*/ */
int AdapterDeviceDisconnect(struct Adapter *adapter) int AdapterDeviceDisconnect(struct Adapter *adapter, unsigned char *priv_net_group)
{ {
if (!adapter) if (!adapter)
return -1; return -1;
@ -432,7 +433,7 @@ int AdapterDeviceDisconnect(struct Adapter *adapter)
if (NULL == priv_done->quit) if (NULL == priv_done->quit)
return -1; return -1;
return priv_done->quit(adapter); return priv_done->quit(adapter, priv_net_group);
} else if (IP_PROTOCOL == adapter->net_protocol) { } else if (IP_PROTOCOL == adapter->net_protocol) {
struct IpProtocolDone *ip_done = (struct IpProtocolDone *)adapter->done; struct IpProtocolDone *ip_done = (struct IpProtocolDone *)adapter->done;

View File

@ -151,7 +151,7 @@ struct PrivProtocolDone
int (*join)(struct Adapter *adapter, unsigned 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 (*send)(struct Adapter *adapter, const void *buf, size_t len);
int (*recv)(struct Adapter *adapter, 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 struct Adapter
@ -212,7 +212,7 @@ int AdapterDeviceConnect(struct Adapter *adapter, enum NetRoleType net_role, con
int AdapterDeviceJoin(struct Adapter *adapter, unsigned char *priv_net_group); int AdapterDeviceJoin(struct Adapter *adapter, unsigned char *priv_net_group);
/*Adapter disconnect from ip net or private 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*/ /*Set up to net*/
int AdapterDeviceSetUp(struct Adapter *adapter); int AdapterDeviceSetUp(struct Adapter *adapter);

View File

@ -37,6 +37,10 @@ extern AdapterProductInfoType Sx1278Attach(struct Adapter *adapter);
#define ADAPTER_LORA_DATA_TYPE_USERDATA 0x0E #define ADAPTER_LORA_DATA_TYPE_USERDATA 0x0E
#define ADAPTER_LORA_DATA_TYPE_CMD 0x0F #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 enum ClientState
{ {
CLIENT_DISCONNECT = 0, CLIENT_DISCONNECT = 0,
@ -51,12 +55,22 @@ enum DataType
LORA_USER_DATA, 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 struct LoraGatewayParam
{ {
uint8 gateway_id; uint8 gateway_id;
uint16 panid; uint16 panid;
uint8 client_id[ADAPTER_LORA_CLIENT_NUM]; uint8 client_id[ADAPTER_LORA_CLIENT_NUM];
int client_num; int client_num;
int receive_data_sem;
}; };
struct LoraClientParam struct LoraClientParam
@ -144,18 +158,30 @@ static int LoraCrc16Check(uint8 *data, uint16 length)
static int LoraGatewayReply(struct Adapter *adapter, struct LoraDataFormat *gateway_recv_data) static int LoraGatewayReply(struct Adapter *adapter, struct LoraDataFormat *gateway_recv_data)
{ {
int i; int i;
int client_join_flag = 0;
struct LoraGatewayParam *gateway = (struct LoraGatewayParam *)adapter->adapter_param; struct LoraGatewayParam *gateway = (struct LoraGatewayParam *)adapter->adapter_param;
struct LoraDataFormat gateway_reply_data; struct LoraDataFormat gateway_reply_data;
memset(&gateway_reply_data, 0, sizeof(struct LoraDataFormat)); memset(&gateway_reply_data, 0, sizeof(struct LoraDataFormat));
if (ADAPTER_LORA_DATA_TYPE_JOIN == gateway_recv_data->data_type) { 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) { if (gateway->client_num > 6) {
printf("Lora gateway only support 6(max) client\n"); printf("Lora gateway only support 6(max) client\n");
gateway->client_num = 0; gateway->client_num = 0;
} }
gateway->client_id[gateway->client_num] = gateway_recv_data->client_id; gateway->client_id[gateway->client_num] = gateway_recv_data->client_id;
gateway->client_num ++; gateway->client_num ++;
}
gateway_reply_data.flame_head = ADAPTER_LORA_DATA_HEAD; gateway_reply_data.flame_head = ADAPTER_LORA_DATA_HEAD;
gateway_reply_data.length = sizeof(struct LoraDataFormat); gateway_reply_data.length = sizeof(struct LoraDataFormat);
@ -232,7 +258,7 @@ static int LoraGatewaySendCmd(struct Adapter *adapter, unsigned char client_id,
*/ */
static int LoraGatewayHandleData(struct Adapter *adapter, struct LoraDataFormat *gateway_recv_data) static int LoraGatewayHandleData(struct Adapter *adapter, struct LoraDataFormat *gateway_recv_data)
{ {
/*User need to handle client data depends on the requirement*/ /*User needs to handle client data depends on the requirement*/
printf("Lora Gateway receive Client %d data:\n", gateway_recv_data->client_id); printf("Lora Gateway receive Client %d data:\n", gateway_recv_data->client_id);
printf("%s\n", gateway_recv_data->data); printf("%s\n", gateway_recv_data->data);
return 0; return 0;
@ -307,37 +333,27 @@ static int LoraClientSendData(struct Adapter *adapter, void *send_buf, int lengt
/** /**
* @description: Lora Gateway receive data analyzing * @description: Lora Gateway receive data analyzing
* @param adapter Lora adapter pointer * @param adapter Lora adapter pointer
* @param gateway_recv_data Lora gateway receive data pointer
*/ */
static int LoraGateWayDataAnalyze(struct Adapter *adapter) static int LoraGateWayDataAnalyze(struct Adapter *adapter, struct LoraDataFormat *gateway_recv_data)
{ {
int ret = 0; int ret = 0;
struct LoraDataFormat gateway_recv_data; if (LoraCrc16Check((uint8 *)gateway_recv_data, sizeof(struct LoraDataFormat)) < 0) {
memset(&gateway_recv_data, 0, sizeof(struct LoraDataFormat));
AdapterDeviceRecv(adapter, &gateway_recv_data, sizeof(struct LoraDataFormat));
// printf("gateway_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",
// gateway_recv_data->flame_head, gateway_recv_data->length, gateway_recv_data->panid, gateway_recv_data->data_type,
// gateway_recv_data->client_id, gateway_recv_data->gateway_id, gateway_recv_data->crc16);
if (LoraCrc16Check((uint8 *)&gateway_recv_data, sizeof(struct LoraDataFormat)) < 0) {
printf("LoraGateWayDataAnalyze CRC check error\n"); printf("LoraGateWayDataAnalyze CRC check error\n");
return -1; return -1;
} }
if ((ADAPTER_LORA_DATA_HEAD == gateway_recv_data.flame_head) && if ((ADAPTER_LORA_DATA_HEAD == gateway_recv_data->flame_head) &&
(ADAPTER_LORA_NET_PANID == gateway_recv_data.panid)) { (ADAPTER_LORA_NET_PANID == gateway_recv_data->panid)) {
switch (gateway_recv_data.data_type) switch (gateway_recv_data->data_type)
{ {
case ADAPTER_LORA_DATA_TYPE_JOIN : case ADAPTER_LORA_DATA_TYPE_JOIN :
case ADAPTER_LORA_DATA_TYPE_QUIT : case ADAPTER_LORA_DATA_TYPE_QUIT :
ret = LoraGatewayReply(adapter, &gateway_recv_data); ret = LoraGatewayReply(adapter, gateway_recv_data);
break; break;
case ADAPTER_LORA_DATA_TYPE_USERDATA : case ADAPTER_LORA_DATA_TYPE_USERDATA :
ret = LoraGatewayHandleData(adapter, &gateway_recv_data); ret = LoraGatewayHandleData(adapter, gateway_recv_data);
break; break;
default: default:
break; break;
@ -357,31 +373,37 @@ static int LoraClientDataAnalyze(struct Adapter *adapter, void *send_buf, int le
{ {
int ret = 0; int ret = 0;
struct LoraDataFormat client_recv_data; struct LoraDataFormat *client_recv_data = PrivMalloc(sizeof(struct LoraDataFormat));
memset(&client_recv_data, 0, sizeof(struct LoraDataFormat)); memset(client_recv_data, 0, sizeof(struct LoraDataFormat));
AdapterDeviceRecv(adapter, &client_recv_data, sizeof(struct LoraDataFormat)); ret = AdapterDeviceRecv(adapter, client_recv_data, sizeof(struct LoraDataFormat));
if (0 == ret) {
// printf("client_recv_data\n"); printf("LoraClientDataAnalyze recv error.Just return\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", PrivFree(client_recv_data);
// 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 (LoraCrc16Check((uint8 *)&client_recv_data, sizeof(struct LoraDataFormat)) < 0) {
printf("LoraClientDataAnalyze CRC check error\n");
return -1; return -1;
} }
if ((ADAPTER_LORA_DATA_HEAD == client_recv_data.flame_head) && printf("client_recv_data\n");
(ADAPTER_LORA_NET_PANID == client_recv_data.panid)) { 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 (client_recv_data.client_id == adapter->net_role_id) { if ((ADAPTER_LORA_DATA_HEAD == client_recv_data->flame_head) &&
switch (client_recv_data.data_type) (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_JOIN_REPLY :
case ADAPTER_LORA_DATA_TYPE_QUIT_REPLY : case ADAPTER_LORA_DATA_TYPE_QUIT_REPLY :
ret = LoraClientUpdate(adapter, &client_recv_data); ret = LoraClientUpdate(adapter, client_recv_data);
break; break;
case ADAPTER_LORA_DATA_TYPE_CMD : case ADAPTER_LORA_DATA_TYPE_CMD :
if (send_buf) { if (send_buf) {
@ -394,6 +416,7 @@ static int LoraClientDataAnalyze(struct Adapter *adapter, void *send_buf, int le
} }
} }
PrivFree(client_recv_data);
return ret; return ret;
} }
@ -422,6 +445,104 @@ static int LoraClientJoinNet(struct Adapter *adapter, unsigned short panid)
return 0; 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 * @description: Lora Gateway task
* @param parameter - Lora adapter pointer * @param parameter - Lora adapter pointer
@ -432,30 +553,10 @@ static void *LoraGatewayTask(void *parameter)
int ret = 0; int ret = 0;
struct Adapter *lora_adapter = (struct Adapter *)parameter; struct Adapter *lora_adapter = (struct Adapter *)parameter;
struct LoraGatewayParam *gateway = (struct LoraGatewayParam *)lora_adapter->adapter_param; struct LoraGatewayParam *gateway = (struct LoraGatewayParam *)lora_adapter->adapter_param;
struct LoraDataFormat gateway_recv_data;
while (1) { while (1) {
LoraGatewayProcess(lora_adapter, gateway, &gateway_recv_data);
ret = LoraGateWayDataAnalyze(lora_adapter);
if (ret < 0) {
printf("LoraGateWayDataAnalyze error\n");
PrivTaskDelay(500);
continue;
}
PrivTaskDelay(2000);
if (gateway->client_num > 0) {
for (i = 0; i < ADAPTER_LORA_CLIENT_NUM; i ++) {
if (gateway->client_id[i]) {
ret = LoraGatewaySendCmd(lora_adapter, gateway->client_id[i], ADAPTER_LORA_DATA_TYPE_CMD);
if (ret < 0) {
printf("LoraGatewaySendCmd client %d ID %d error\n", i, gateway->client_id[i]);
PrivTaskDelay(500);
continue;
}
}
}
}
} }
return 0; return 0;
@ -467,28 +568,29 @@ static void *LoraGatewayTask(void *parameter)
*/ */
static void *LoraClientDataTask(void *parameter) static void *LoraClientDataTask(void *parameter)
{ {
int ret = 0; int i, ret = 0;
int join_times = 10;
struct Adapter *lora_adapter = (struct Adapter *)parameter; struct Adapter *lora_adapter = (struct Adapter *)parameter;
struct LoraClientParam *client = (struct LoraClientParam *)lora_adapter->adapter_param; struct LoraClientParam *client = (struct LoraClientParam *)lora_adapter->adapter_param;
//set lora_send_buf for test
uint8 lora_send_buf[ADAPTER_LORA_DATA_LENGTH]; uint8 lora_send_buf[ADAPTER_LORA_DATA_LENGTH];
memset(lora_send_buf, 0, ADAPTER_LORA_DATA_LENGTH); memset(lora_send_buf, 0, ADAPTER_LORA_DATA_LENGTH);
sprintf(lora_send_buf, "Lora adapter test\n"); sprintf(lora_send_buf, "Lora client %d adapter test\n", client->client_id);
while (1) { while (1) {
PrivTaskDelay(100); PrivTaskDelay(100);
if (CLIENT_DISCONNECT == client->client_state) { if ((CLIENT_DISCONNECT == client->client_state) && (!g_adapter_lora_quit_flag)) {
ret = LoraClientJoinNet(lora_adapter, client->panid); ret = LoraClientJoinNet(lora_adapter, client->panid);
if (ret < 0) { if (ret < 0) {
printf("LoraClientJoinNet error panid 0x%x\n", client->panid); printf("LoraClientJoinNet error panid 0x%x\n", client->panid);
continue;
} }
ret = LoraClientDataAnalyze(lora_adapter, NULL, 0); ret = LoraClientDataAnalyze(lora_adapter, NULL, 0);
if (ret < 0) { if (ret < 0) {
printf("LoraClientDataAnalyze error\n"); printf("LoraClientDataAnalyze error, reconnect to gateway\n");
PrivTaskDelay(500); PrivTaskDelay(500);
continue; continue;
} }
@ -497,12 +599,46 @@ static void *LoraClientDataTask(void *parameter)
if (CLIENT_CONNECT == client->client_state) { if (CLIENT_CONNECT == client->client_state) {
ret = LoraClientDataAnalyze(lora_adapter, (void *)lora_send_buf, strlen(lora_send_buf)); ret = LoraClientDataAnalyze(lora_adapter, (void *)lora_send_buf, strlen(lora_send_buf));
if (ret < 0) { if (ret < 0) {
printf("LoraClientDataAnalyze error\n"); printf("LoraClientDataAnalyze error, wait for next data cmd\n");
PrivTaskDelay(500); PrivTaskDelay(500);
continue; 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********************/ /*******************LORA ADAPTER FUNCTION********************/
@ -607,6 +743,7 @@ int AdapterLoraInit(void)
static pthread_t lora_gateway_task; static pthread_t lora_gateway_task;
#else //AS_LORA_CLIENT_ROLE #else //AS_LORA_CLIENT_ROLE
static pthread_t lora_client_data_task; static pthread_t lora_client_data_task;
static pthread_t lora_client_quit_task;
#endif #endif
int AdapterLoraTest(void) int AdapterLoraTest(void)
@ -619,7 +756,7 @@ int AdapterLoraTest(void)
#ifdef AS_LORA_GATEWAY_ROLE #ifdef AS_LORA_GATEWAY_ROLE
pthread_attr_t lora_gateway_attr; pthread_attr_t lora_gateway_attr;
lora_gateway_attr.schedparam.sched_priority = 20; lora_gateway_attr.schedparam.sched_priority = 20;
lora_gateway_attr.stacksize = 4096; lora_gateway_attr.stacksize = 2048;
PrivTaskCreate(&lora_gateway_task, &lora_gateway_attr, &LoraGatewayTask, (void *)adapter); PrivTaskCreate(&lora_gateway_task, &lora_gateway_attr, &LoraGatewayTask, (void *)adapter);
PrivTaskStartup(&lora_gateway_task); PrivTaskStartup(&lora_gateway_task);
@ -628,10 +765,15 @@ int AdapterLoraTest(void)
//create lora client task //create lora client task
pthread_attr_t lora_client_attr; pthread_attr_t lora_client_attr;
lora_client_attr.schedparam.sched_priority = 20; lora_client_attr.schedparam.sched_priority = 20;
lora_client_attr.stacksize = 4096; lora_client_attr.stacksize = 2048;
PrivTaskCreate(&lora_client_data_task, &lora_client_attr, &LoraClientDataTask, (void *)adapter); PrivTaskCreate(&lora_client_data_task, &lora_client_attr, &LoraClientDataTask, (void *)adapter);
PrivTaskStartup(&lora_client_data_task); 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 #endif
return 0; return 0;

View File

@ -103,17 +103,18 @@ static int Sx1278Send(struct Adapter *adapter, const void *buf, size_t len)
*/ */
static int Sx1278Recv(struct Adapter *adapter, void *buf, size_t len) static int Sx1278Recv(struct Adapter *adapter, void *buf, size_t len)
{ {
return PrivRead(adapter->fd, buf, len);; return PrivRead(adapter->fd, buf, len);
} }
/** /**
* @description: SX1278 quit lora net group function * @description: SX1278 quit lora net group function
* @param adapter - Lora device pointer * @param adapter - Lora device pointer
* @param priv_net_group - priv_net_group params
* @return success: 0, failure: -1 * @return success: 0, failure: -1
*/ */
static int Sx1278Quit(struct Adapter *adapter) static int Sx1278Quit(struct Adapter *adapter, unsigned char *priv_net_group)
{ {
/*to do*/ PrivWrite(adapter->fd, (void *)priv_net_group, 144);
return 0; return 0;
} }

View File

@ -262,9 +262,6 @@ static uint32 SpiLoraWrite(void *dev, struct BusBlockWriteParam *write_param)
NULL_PARAM_CHECK(dev); NULL_PARAM_CHECK(dev);
NULL_PARAM_CHECK(write_param); NULL_PARAM_CHECK(write_param);
uint8 i;
char Msg[SPI_LORA_BUFFER_SIZE] = {0};
if (write_param->size > 256) { if (write_param->size > 256) {
KPrintf("SpiLoraWrite ERROR:The message is too long!\n"); KPrintf("SpiLoraWrite ERROR:The message is too long!\n");
return ERROR; return ERROR;
@ -290,14 +287,31 @@ static uint32 SpiLoraRead(void *dev, struct BusBlockReadParam *read_param)
NULL_PARAM_CHECK(dev); NULL_PARAM_CHECK(dev);
NULL_PARAM_CHECK(read_param); NULL_PARAM_CHECK(read_param);
int read_times = 100;
//Radio->StartRx(); //Radio->StartRx();
SX1276StartRx(); SX1276StartRx();
KPrintf("SpiLoraRead Ready!\n"); 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); //while(Radio->Process() != RF_RX_DONE);
//Radio->GetRxPacket(read_param->buffer, (uint16 *)&read_param->read_length); //Radio->GetRxPacket(read_param->buffer, (uint16 *)&read_param->read_length);
while(SX1276Process() != RF_RX_DONE); // while(SX1276Process() != RF_RX_DONE);
SX1276GetRxPacket(read_param->buffer, (uint16 *)&read_param->read_length); // SX1276GetRxPacket(read_param->buffer, (uint16 *)&read_param->read_length);
return read_param->read_length; return read_param->read_length;
} }
@ -479,7 +493,7 @@ int LoraSx12xxSpiDeviceInit(void)
return EOK; return EOK;
} }
#define LORA_TEST //#define LORA_TEST
#ifdef LORA_TEST #ifdef LORA_TEST
/*Just for lora test*/ /*Just for lora test*/
static struct Bus *bus; static struct Bus *bus;

View File

@ -92,14 +92,10 @@ Modification:
/** /**
* This function SPI device initialization * This function SPI device initialization
*
* @param SpiDrv SPI device structure pointer * @param SpiDrv SPI device structure pointer
*
* @param cfg SPI device operating mode configuration structure pointer * @param cfg SPI device operating mode configuration structure pointer
*
* @return if successful return EOK * @return if successful return EOK
*/ */
static x_err_t Stm32SpiInit(struct Stm32Spi *SpiDrv, struct SpiMasterParam *cfg) static x_err_t Stm32SpiInit(struct Stm32Spi *SpiDrv, struct SpiMasterParam *cfg)
{ {
NULL_PARAM_CHECK(SpiDrv); NULL_PARAM_CHECK(SpiDrv);
@ -248,20 +244,15 @@ static x_err_t Stm32SpiInit(struct Stm32Spi *SpiDrv, struct SpiMasterParam *cfg)
return EOK; return EOK;
} }
/** /**
* This function Use DMA during spi transfer * This function Use DMA during spi transfer
*
* @param spi_bus SPI bus handle * @param spi_bus SPI bus handle
*
* @param SettingLen Set data length * @param SettingLen Set data length
*
* @param RxBaseAddr Base address for receiving data * @param RxBaseAddr Base address for receiving data
*
* @param TxBaseAddr Base address for sending data * @param TxBaseAddr Base address for sending data
*
* @return none * @return none
*/ */
static void DmaSpiConfig(struct SpiBus *spi_bus, uint32_t setting_len, void *rx_base_addr, void *tx_base_addr) static void DmaSpiConfig(struct SpiBus *spi_bus, uint32_t setting_len, void *rx_base_addr, void *tx_base_addr)
{ {
struct Stm32Spi *spi = (struct Stm32Spi *)spi_bus->private_data; struct Stm32Spi *spi = (struct Stm32Spi *)spi_bus->private_data;
@ -350,9 +341,7 @@ static void DmaSpiConfig(struct SpiBus *spi_bus, uint32_t setting_len, void *rx_
/** /**
* This function DMA receiving completion interrupt * This function DMA receiving completion interrupt
*
* @param spi_bus SPI bus pointer * @param spi_bus SPI bus pointer
*
* @return none * @return none
*/ */
static void DmaRxDoneIsr(struct SpiBus *spi_bus) static void DmaRxDoneIsr(struct SpiBus *spi_bus)
@ -374,9 +363,7 @@ static void DmaRxDoneIsr(struct SpiBus *spi_bus)
/** /**
* This function DMA sending completion interrupt * This function DMA sending completion interrupt
*
* @param spi_bus SPI bus pointer * @param spi_bus SPI bus pointer
*
* @return none * @return none
*/ */
static void DmaTxDoneIsr(struct SpiBus *spi_bus) static void DmaTxDoneIsr(struct SpiBus *spi_bus)
@ -395,21 +382,15 @@ static void DmaTxDoneIsr(struct SpiBus *spi_bus)
DMA_ClearFlag(spi->dma.dma_tx.instance, spi->spi_dma_flag); DMA_ClearFlag(spi->dma.dma_tx.instance, spi->spi_dma_flag);
} }
} }
/** /**
* This function SPI wait timeout function * This function SPI wait timeout function
*
* @param SpiInit SPI Init structure definition * @param SpiInit SPI Init structure definition
*
* @param SpiInstance SPI control handle * @param SpiInstance SPI control handle
*
* @param Flag SPI Status flag * @param Flag SPI Status flag
*
* @param State SPI status * @param State SPI status
*
* @param Timeout Overflow time * @param Timeout Overflow time
*
* @param Tickstart Starting time * @param Tickstart Starting time
*
* @return if successful return EOK * @return if successful return EOK
*/ */
static int SpiWaitUntilTimeout(SPI_InitTypeDef SpiInit, SPI_TypeDef *SpiInstance, uint32_t Flag, uint32_t State, uint32_t Timeout, uint32_t Tickstart) static int SpiWaitUntilTimeout(SPI_InitTypeDef SpiInit, SPI_TypeDef *SpiInstance, uint32_t Flag, uint32_t State, uint32_t Timeout, uint32_t Tickstart)
@ -434,21 +415,15 @@ static int SpiWaitUntilTimeout(SPI_InitTypeDef SpiInit, SPI_TypeDef *SpiInstance
} }
return 0; return 0;
} }
/** /**
* This function SPI sends data through DMA * This function SPI sends data through DMA
*
* @param SpiInit SPI Init structure * @param SpiInit SPI Init structure
*
* @param SpiInstance SPI control handle * @param SpiInstance SPI control handle
*
* @param dma_init DMA Init structure * @param dma_init DMA Init structure
*
* @param dma_instance DMA Controller * @param dma_instance DMA Controller
*
* @param pData Send data buffer address * @param pData Send data buffer address
*
* @param Size Amount of data sent * @param Size Amount of data sent
*
* @return if successful return EOK * @return if successful return EOK
*/ */
int SpiTransmitDma(SPI_InitTypeDef SpiInit, SPI_TypeDef *SpiInstance, DMA_InitTypeDef dma_init, DMA_Stream_TypeDef *dma_instance, uint8_t *pData, uint16_t Size) int SpiTransmitDma(SPI_InitTypeDef SpiInit, SPI_TypeDef *SpiInstance, DMA_InitTypeDef dma_init, DMA_Stream_TypeDef *dma_instance, uint8_t *pData, uint16_t Size)
@ -520,27 +495,18 @@ int SpiTransmitDma(SPI_InitTypeDef SpiInit, SPI_TypeDef *SpiInstance, DMA_InitTy
error : error :
return errorcode; return errorcode;
} }
/** /**
* This function SPI carries out duplex communication through DMA * This function SPI carries out duplex communication through DMA
*
* @param SpiInit SPI Init structure * @param SpiInit SPI Init structure
*
* @param SpiInstance SPI control handle * @param SpiInstance SPI control handle
*
* @param dmarx_init DMA Init structure---Rx * @param dmarx_init DMA Init structure---Rx
*
* @param dmarx_instance DMA Controller * @param dmarx_instance DMA Controller
*
* @param dmatx_init DMA Init structure---Tx * @param dmatx_init DMA Init structure---Tx
*
* @param dmatx_instance DMA Controller * @param dmatx_instance DMA Controller
*
* @param pTxData Send data buffer address * @param pTxData Send data buffer address
*
* @param pRxData Receive data buffer address * @param pRxData Receive data buffer address
*
* @param Size Amount of data * @param Size Amount of data
*
* @return if successful return EOK * @return if successful return EOK
*/ */
int SpiTransmitreceiveDma(SPI_InitTypeDef SpiInit, SPI_TypeDef *SpiInstance, DMA_InitTypeDef dmarx_init, DMA_Stream_TypeDef *dmarx_instance, DMA_InitTypeDef dmatx_init, DMA_Stream_TypeDef *dmatx_instance, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size) int SpiTransmitreceiveDma(SPI_InitTypeDef SpiInit, SPI_TypeDef *SpiInstance, DMA_InitTypeDef dmarx_init, DMA_Stream_TypeDef *dmarx_instance, DMA_InitTypeDef dmatx_init, DMA_Stream_TypeDef *dmatx_instance, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size)
@ -653,25 +619,17 @@ int SpiTransmitreceiveDma(SPI_InitTypeDef SpiInit, SPI_TypeDef *SpiInstance, DMA
error : error :
return errorcode; return errorcode;
} }
/** /**
* This function SPI receives data through DMA * This function SPI receives data through DMA
*
* @param SpiInit SPI Init structure * @param SpiInit SPI Init structure
*
* @param SpiInstance SPI control handle * @param SpiInstance SPI control handle
*
* @param dmarx_init DMA Init structure---Rx * @param dmarx_init DMA Init structure---Rx
*
* @param dmarx_instance DMA Controller * @param dmarx_instance DMA Controller
*
* @param dmatx_init DMA Init structure---Tx * @param dmatx_init DMA Init structure---Tx
*
* @param dmatx_instance DMA Controller * @param dmatx_instance DMA Controller
*
* @param pData Receive data buffer address * @param pData Receive data buffer address
*
* @param Size Amount of data * @param Size Amount of data
*
* @return if successful return EOK * @return if successful return EOK
*/ */
int SpiReceiveDma(SPI_InitTypeDef SpiInit, SPI_TypeDef *SpiInstance, DMA_InitTypeDef dmarx_init, DMA_Stream_TypeDef *dmarx_instance, DMA_InitTypeDef dmatx_init, DMA_Stream_TypeDef *dmatx_instance, uint8_t *pData, uint16_t Size) int SpiReceiveDma(SPI_InitTypeDef SpiInit, SPI_TypeDef *SpiInstance, DMA_InitTypeDef dmarx_init, DMA_Stream_TypeDef *dmarx_instance, DMA_InitTypeDef dmatx_init, DMA_Stream_TypeDef *dmatx_instance, uint8_t *pData, uint16_t Size)
@ -748,19 +706,14 @@ int SpiReceiveDma(SPI_InitTypeDef SpiInit, SPI_TypeDef *SpiInstance, DMA_InitTyp
error: error:
return errorcode; return errorcode;
} }
/** /**
* This function SPI receives data * This function SPI receives data
*
* @param SpiInit SPI Init structure * @param SpiInit SPI Init structure
*
* @param SpiInstance SPI control handle * @param SpiInstance SPI control handle
*
* @param pData Transmit data buffer address * @param pData Transmit data buffer address
*
* @param Size Amount of data * @param Size Amount of data
*
* @param Timeout waiting time * @param Timeout waiting time
*
* @return if successful return EOK * @return if successful return EOK
*/ */
int SpiTransmit(SPI_InitTypeDef SpiInit, SPI_TypeDef *SpiInstance, uint8_t *pData, uint16_t Size, uint32_t Timeout) int SpiTransmit(SPI_InitTypeDef SpiInit, SPI_TypeDef *SpiInstance, uint8_t *pData, uint16_t Size, uint32_t Timeout)
@ -876,21 +829,15 @@ int SpiTransmit(SPI_InitTypeDef SpiInit, SPI_TypeDef *SpiInstance, uint8_t *pDat
error: error:
return errorcode; return errorcode;
} }
/** /**
* This function SPI Transmit and receive * This function SPI Transmit and receive
*
* @param SpiInit SPI Init structure * @param SpiInit SPI Init structure
*
* @param SpiInstance SPI control handle * @param SpiInstance SPI control handle
*
* @param pTxData Transmit data buffer address * @param pTxData Transmit data buffer address
*
* @param pRxData receive data buffer address * @param pRxData receive data buffer address
*
* @param Size Amount of data * @param Size Amount of data
*
* @param Timeout waiting time * @param Timeout waiting time
*
* @return if successful return EOK * @return if successful return EOK
*/ */
int SpiTransmitreceive(SPI_InitTypeDef SpiInit, SPI_TypeDef *SpiInstance, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size, uint32_t Timeout) int SpiTransmitreceive(SPI_InitTypeDef SpiInit, SPI_TypeDef *SpiInstance, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size, uint32_t Timeout)
@ -1029,19 +976,14 @@ int SpiTransmitreceive(SPI_InitTypeDef SpiInit, SPI_TypeDef *SpiInstance, uint8_
error : error :
return errorcode; return errorcode;
} }
/** /**
* This function SPI receive data * This function SPI receive data
*
* @param SpiInit SPI Init structure * @param SpiInit SPI Init structure
*
* @param SpiInstance SPI control handle * @param SpiInstance SPI control handle
*
* @param pData data buffer address * @param pData data buffer address
*
* @param Size Amount of data * @param Size Amount of data
*
* @param Timeout waiting time * @param Timeout waiting time
*
* @return if successful return EOK * @return if successful return EOK
*/ */
int SpiReceive(SPI_InitTypeDef SpiInit, SPI_TypeDef *SpiInstance, uint8_t *pData, uint16_t Size, uint32_t Timeout) int SpiReceive(SPI_InitTypeDef SpiInit, SPI_TypeDef *SpiInstance, uint8_t *pData, uint16_t Size, uint32_t Timeout)
@ -1141,16 +1083,13 @@ error :
/** /**
* This function SPI write data * This function SPI write data
*
* @param spi_dev SPI device structure handle * @param spi_dev SPI device structure handle
*
* @param spi_datacfg SPI device information structure handle * @param spi_datacfg SPI device information structure handle
*
* @return datacfg length * @return datacfg length
*/ */
static uint32 Stm32SpiWriteData(struct SpiHardwareDevice *spi_dev, struct SpiDataStandard *spi_datacfg) static uint32 Stm32SpiWriteData(struct SpiHardwareDevice *spi_dev, struct SpiDataStandard *spi_datacfg)
{ {
int state; int state = 0;
x_size_t message_length, already_send_length; x_size_t message_length, already_send_length;
uint16 send_length; uint16 send_length;
const uint8 *WriteBuf; const uint8 *WriteBuf;
@ -1163,7 +1102,7 @@ static uint32 Stm32SpiWriteData(struct SpiHardwareDevice *spi_dev, struct SpiDat
SPI_InitTypeDef *SpiInit = &StmSpi->init; SPI_InitTypeDef *SpiInit = &StmSpi->init;
struct Stm32HwSpiCs *cs = (struct Stm32HwSpiCs *)spi_dev->private_data; struct Stm32HwSpiCs *cs = (struct Stm32HwSpiCs *)spi_dev->private_data;
while(NONE != spi_datacfg) { while (NONE != spi_datacfg) {
if (spi_datacfg->spi_chip_select) { if (spi_datacfg->spi_chip_select) {
GPIO_WriteBit(cs->GPIOx, cs->GPIO_Pin, Bit_RESET); GPIO_WriteBit(cs->GPIOx, cs->GPIO_Pin, Bit_RESET);
} }
@ -1193,7 +1132,7 @@ static uint32 Stm32SpiWriteData(struct SpiHardwareDevice *spi_dev, struct SpiDat
} }
if (state != 0) { if (state != 0) {
KPrintf("spi transfer error : %d\n", state); KPrintf("spi write error : %d\n", state);
spi_datacfg->length = 0; spi_datacfg->length = 0;
} }
} }
@ -1205,35 +1144,32 @@ static uint32 Stm32SpiWriteData(struct SpiHardwareDevice *spi_dev, struct SpiDat
spi_datacfg = spi_datacfg->next; spi_datacfg = spi_datacfg->next;
} }
return spi_datacfg->length; return EOK;
} }
/** /**
* This function SPI read data * This function SPI read data
*
* @param spi_dev SPI device structure handle * @param spi_dev SPI device structure handle
*
* @param spi_datacfg SPI device information structure handle * @param spi_datacfg SPI device information structure handle
*
* @return datacfg length * @return datacfg length
*/ */
static uint32 Stm32SpiReadData(struct SpiHardwareDevice *spi_dev, struct SpiDataStandard *spi_datacfg) static uint32 Stm32SpiReadData(struct SpiHardwareDevice *spi_dev, struct SpiDataStandard *spi_datacfg)
{ {
int state;
x_size_t message_length, already_send_length;
uint16 read_length;
const uint8 *ReadBuf;
NULL_PARAM_CHECK(spi_dev); NULL_PARAM_CHECK(spi_dev);
NULL_PARAM_CHECK(spi_datacfg); NULL_PARAM_CHECK(spi_datacfg);
int state;
x_size_t message_length, already_send_length;
uint16 read_length, spi_read_length = 0;
uint8 *ReadBuf;
struct Stm32Spi *StmSpi = CONTAINER_OF(spi_dev->haldev.owner_bus, struct Stm32Spi, spi_bus); struct Stm32Spi *StmSpi = CONTAINER_OF(spi_dev->haldev.owner_bus, struct Stm32Spi, spi_bus);
SPI_TypeDef *SpiInstance = StmSpi->instance; SPI_TypeDef *SpiInstance = StmSpi->instance;
SPI_InitTypeDef *SpiInit = &StmSpi->init; SPI_InitTypeDef *SpiInit = &StmSpi->init;
struct Stm32HwSpiCs *cs = (struct Stm32HwSpiCs *)spi_dev->private_data; struct Stm32HwSpiCs *cs = (struct Stm32HwSpiCs *)spi_dev->private_data;
while(NONE != spi_datacfg) { while(NONE != spi_datacfg) {
if(spi_datacfg->spi_chip_select) { if (spi_datacfg->spi_chip_select) {
GPIO_WriteBit(cs->GPIOx, cs->GPIO_Pin, Bit_RESET); GPIO_WriteBit(cs->GPIOx, cs->GPIO_Pin, Bit_RESET);
} }
@ -1250,20 +1186,19 @@ static uint32 Stm32SpiReadData(struct SpiHardwareDevice *spi_dev, struct SpiData
/* calculate the start address */ /* calculate the start address */
already_send_length = spi_datacfg->length - read_length - message_length; already_send_length = spi_datacfg->length - read_length - message_length;
ReadBuf = (uint8 *)spi_datacfg->rx_buff + already_send_length; ReadBuf = spi_datacfg->rx_buff + already_send_length;
/* start once data exchange in DMA mode */ /* start once data exchange in DMA mode */
if (spi_datacfg->rx_buff) { if ((spi_datacfg->rx_buff) && (ReadBuf)) {
memset((uint8_t *)ReadBuf, 0xff, read_length); //memset(ReadBuf, 0, read_length);
if (StmSpi->spi_dma_flag & SPI_USING_RX_DMA_FLAG) { if (StmSpi->spi_dma_flag & SPI_USING_RX_DMA_FLAG) {
state = SpiReceiveDma(*SpiInit, SpiInstance, 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); state = SpiReceiveDma(*SpiInit, SpiInstance, 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 { } else {
state = SpiReceive(*SpiInit, SpiInstance, (uint8_t *)ReadBuf, read_length, 1000); state = SpiReceive(*SpiInit, SpiInstance, ReadBuf, read_length, 1000);
} }
} }
if (state != 0) { if (state != 0) {
KPrintf("spi transfer error : %d\n", state); KPrintf("spi read error : %d\n", state);
spi_datacfg->length = 0; spi_datacfg->length = 0;
} }
} }
@ -1272,17 +1207,16 @@ static uint32 Stm32SpiReadData(struct SpiHardwareDevice *spi_dev, struct SpiData
GPIO_WriteBit(cs->GPIOx, cs->GPIO_Pin, Bit_SET); GPIO_WriteBit(cs->GPIOx, cs->GPIO_Pin, Bit_SET);
} }
spi_read_length += spi_datacfg->length;
spi_datacfg = spi_datacfg->next; spi_datacfg = spi_datacfg->next;
} }
return spi_datacfg->length; return spi_read_length;
} }
/** /**
* This function SPI driver initialization function * This function SPI driver initialization function
*
* @param spi_drv SPI driver structure handle * @param spi_drv SPI driver structure handle
*
* @return if successful return EOK * @return if successful return EOK
*/ */
static uint32 SpiDrvInit(struct SpiDriver *spi_drv) static uint32 SpiDrvInit(struct SpiDriver *spi_drv)
@ -1298,11 +1232,8 @@ static uint32 SpiDrvInit(struct SpiDriver *spi_drv)
/** /**
* This function SPI driver configuration param * This function SPI driver configuration param
*
* @param spi_drv SPI driver structure handle * @param spi_drv SPI driver structure handle
*
* @param spi_param SPI master param structure handle * @param spi_param SPI master param structure handle
*
* @return if successful return EOK * @return if successful return EOK
*/ */
static uint32 SpiDrvConfigure(struct SpiDriver *spi_drv, struct SpiMasterParam *spi_param) static uint32 SpiDrvConfigure(struct SpiDriver *spi_drv, struct SpiMasterParam *spi_param)
@ -1354,7 +1285,7 @@ static const struct SpiDevDone spi_dev_done =
}; };
#if defined(BSP_USING_SPI1) #if defined(BSP_USING_SPI1)
struct Stm32Spi spi1; static struct Stm32Spi spi1;
#if defined(BSP_SPI1_TX_USING_DMA) #if defined(BSP_SPI1_TX_USING_DMA)
void DMA2_Stream3_IRQHandler(int irq_num, void *arg) void DMA2_Stream3_IRQHandler(int irq_num, void *arg)
{ {
@ -1373,7 +1304,7 @@ DECLARE_HW_IRQ(DMA2_Stream0_IRQn, DMA2_Stream0_IRQHandler, NONE);
#endif #endif
#if defined(BSP_USING_SPI2) #if defined(BSP_USING_SPI2)
struct Stm32Spi spi2; static struct Stm32Spi spi2;
#if defined(BSP_SPI2_TX_USING_DMA) #if defined(BSP_SPI2_TX_USING_DMA)
void DMA1_Stream4_IRQHandler(int irq_num, void *arg) void DMA1_Stream4_IRQHandler(int irq_num, void *arg)
{ {
@ -1392,7 +1323,7 @@ DECLARE_HW_IRQ(DMA1_Stream3_IRQn, DMA1_Stream3_IRQHandler, NONE);
#endif #endif
#if defined(BSP_USING_SPI3) #if defined(BSP_USING_SPI3)
struct Stm32Spi spi3; static struct Stm32Spi spi3;
#if defined(BSP_SPI3_TX_USING_DMA) #if defined(BSP_SPI3_TX_USING_DMA)
void DMA1_Stream7_IRQHandler(int irq_num, void *arg) void DMA1_Stream7_IRQHandler(int irq_num, void *arg)
{ {
@ -1417,7 +1348,6 @@ DECLARE_HW_IRQ(DMA1_Stream2_IRQn, DMA1_Stream2_IRQHandler, NONE);
/** /**
* This function RCC clock configuration function * This function RCC clock configuration function
*
* @return none * @return none
*/ */
static void RCCConfiguration(void) static void RCCConfiguration(void)
@ -1442,7 +1372,6 @@ static void RCCConfiguration(void)
} }
/** /**
* This function GPIO Configuration function * This function GPIO Configuration function
*
* @return none * @return none
*/ */
static void GPIOConfiguration(void) static void GPIOConfiguration(void)
@ -1499,11 +1428,8 @@ static void GPIOConfiguration(void)
/** /**
* This function Init the spi bus spi driver and attach to the bus * This function Init the spi bus spi driver and attach to the bus
*
* @param spi_bus Spi bus info pointer * @param spi_bus Spi bus info pointer
*
* @param spi_driver Spi driver info pointer * @param spi_driver Spi driver info pointer
*
* @return EOK * @return EOK
*/ */
static int BoardSpiBusInit(struct Stm32Spi *stm32spi_bus, struct SpiDriver *spi_driver, char* drv_name) static int BoardSpiBusInit(struct Stm32Spi *stm32spi_bus, struct SpiDriver *spi_driver, char* drv_name)
@ -1536,7 +1462,6 @@ static int BoardSpiBusInit(struct Stm32Spi *stm32spi_bus, struct SpiDriver *spi_
/** /**
* This function SPI bus initialization * This function SPI bus initialization
*
* @return EOK * @return EOK
*/ */
static int Stm32HwSpiBusInit(void) static int Stm32HwSpiBusInit(void)
@ -1548,6 +1473,7 @@ static int Stm32HwSpiBusInit(void)
GPIOConfiguration(); GPIOConfiguration();
#ifdef BSP_USING_SPI1 #ifdef BSP_USING_SPI1
memset(&spi1, 0, sizeof(struct Stm32Spi));
StmSpiBus = &spi1; StmSpiBus = &spi1;
StmSpiBus->instance = SPI1; StmSpiBus->instance = SPI1;
StmSpiBus->bus_name = SPI_BUS_NAME_1; StmSpiBus->bus_name = SPI_BUS_NAME_1;
@ -1567,6 +1493,7 @@ static int Stm32HwSpiBusInit(void)
#endif #endif
#ifdef BSP_USING_SPI2 #ifdef BSP_USING_SPI2
memset(&spi2, 0, sizeof(struct Stm32Spi));
StmSpiBus = &spi2; StmSpiBus = &spi2;
StmSpiBus->instance = SPI2; StmSpiBus->instance = SPI2;
StmSpiBus->bus_name = SPI_BUS_NAME_2; StmSpiBus->bus_name = SPI_BUS_NAME_2;
@ -1585,6 +1512,7 @@ static int Stm32HwSpiBusInit(void)
#endif #endif
#ifdef BSP_USING_SPI3 #ifdef BSP_USING_SPI3
memset(&spi3, 0, sizeof(struct Stm32Spi));
StmSpiBus = &spi3; StmSpiBus = &spi3;
StmSpiBus->instance = SPI3; StmSpiBus->instance = SPI3;
StmSpiBus->bus_name = SPI_BUS_NAME_3; StmSpiBus->bus_name = SPI_BUS_NAME_3;
@ -1607,15 +1535,10 @@ static int Stm32HwSpiBusInit(void)
/** /**
* This function Mount the spi device to the bus * This function Mount the spi device to the bus
*
* @param bus_name Bus Name * @param bus_name Bus Name
*
* @param device_name spi device name * @param device_name spi device name
*
* @param cs_gpiox GPIO pin configuration handle * @param cs_gpiox GPIO pin configuration handle
*
* @param cs_gpio_pin GPIO number * @param cs_gpio_pin GPIO number
*
* @return EOK * @return EOK
*/ */
x_err_t HwSpiDeviceAttach(const char *bus_name, const char *device_name, GPIO_TypeDef *cs_gpiox, uint16_t cs_gpio_pin) x_err_t HwSpiDeviceAttach(const char *bus_name, const char *device_name, GPIO_TypeDef *cs_gpiox, uint16_t cs_gpio_pin)
@ -1670,7 +1593,6 @@ x_err_t HwSpiDeviceAttach(const char *bus_name, const char *device_name, GPIO_Ty
/** /**
* This function Get DMA information * This function Get DMA information
*
* @return none * @return none
*/ */
static void Stm32GetDmaInfo(void) static void Stm32GetDmaInfo(void)
@ -1723,7 +1645,6 @@ static void Stm32GetDmaInfo(void)
/** /**
* This function hardware spi initialization * This function hardware spi initialization
*
* @return EOK * @return EOK
*/ */
int Stm32HwSpiInit(void) int Stm32HwSpiInit(void)

View File

@ -183,6 +183,7 @@ tSX1276LR* SX1276LR;
* Local RF buffer for communication support * Local RF buffer for communication support
*/ */
static uint8_t RFBuffer[RF_BUFFER_SIZE]; static uint8_t RFBuffer[RF_BUFFER_SIZE];
static uint8_t TFBuffer[RF_BUFFER_SIZE];
/*! /*!
* RF state machine variable * RF state machine variable
@ -401,7 +402,7 @@ void SX1276LoRaSetTxPacket( const void *buffer, uint16_t size )
{ {
TxPacketSize = 255; TxPacketSize = 255;
} }
memcpy( ( void * )RFBuffer, buffer, ( size_t )TxPacketSize ); memcpy( ( void * )TFBuffer, buffer, ( size_t )TxPacketSize );
RFLRState = RFLR_STATE_TX_INIT; RFLRState = RFLR_STATE_TX_INIT;
} }
@ -678,7 +679,7 @@ uint32_t SX1276LoRaProcess( void )
SX1276LR->RegFifoAddrPtr = SX1276LR->RegFifoTxBaseAddr; SX1276LR->RegFifoAddrPtr = SX1276LR->RegFifoTxBaseAddr;
SX1276Write( REG_LR_FIFOADDRPTR, SX1276LR->RegFifoAddrPtr ); SX1276Write( REG_LR_FIFOADDRPTR, SX1276LR->RegFifoAddrPtr );
// Write payload buffer to LORA modem // Write payload buffer to LORA modem
SX1276WriteFifo( RFBuffer, SX1276LR->RegPayloadLength ); SX1276WriteFifo( TFBuffer, SX1276LR->RegPayloadLength );
// TxDone RxTimeout FhssChangeChannel ValidHeader // TxDone RxTimeout FhssChangeChannel ValidHeader
SX1276LR->RegDioMapping1 = RFLR_DIOMAPPING1_DIO0_01 | RFLR_DIOMAPPING1_DIO1_00 | RFLR_DIOMAPPING1_DIO2_00 | RFLR_DIOMAPPING1_DIO3_01; SX1276LR->RegDioMapping1 = RFLR_DIOMAPPING1_DIO0_01 | RFLR_DIOMAPPING1_DIO1_00 | RFLR_DIOMAPPING1_DIO2_00 | RFLR_DIOMAPPING1_DIO3_01;
// PllLock Mode Ready // PllLock Mode Ready

View File

@ -241,8 +241,10 @@
#if defined ( __GNUC__ ) /* GNU Compiler */ #if defined ( __GNUC__ ) /* GNU Compiler */
#ifndef __packed
#define __packed __attribute__ ((__packed__)) #define __packed __attribute__ ((__packed__))
#endif #endif
#endif
/** /**
* @} * @}

View File

@ -280,14 +280,31 @@ static uint32 SpiLoraRead(void *dev, struct BusBlockReadParam *read_param)
NULL_PARAM_CHECK(dev); NULL_PARAM_CHECK(dev);
NULL_PARAM_CHECK(read_param); NULL_PARAM_CHECK(read_param);
int read_times = 1000;
//Radio->StartRx(); //Radio->StartRx();
SX1276StartRx(); SX1276StartRx();
KPrintf("SpiLoraRead Ready!\n"); 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); //while(Radio->Process() != RF_RX_DONE);
//Radio->GetRxPacket(read_param->buffer, (uint16 *)&read_param->read_length); //Radio->GetRxPacket(read_param->buffer, (uint16 *)&read_param->read_length);
while(SX1276Process() != RF_RX_DONE); // while(SX1276Process() != RF_RX_DONE);
SX1276GetRxPacket(read_param->buffer, (uint16 *)&read_param->read_length); // SX1276GetRxPacket(read_param->buffer, (uint16 *)&read_param->read_length);
return read_param->read_length; return read_param->read_length;
} }
@ -461,7 +478,7 @@ int LoraSx12xxSpiDeviceInit(void)
return EOK; return EOK;
} }
#define LORA_TEST //#define LORA_TEST
#ifdef LORA_TEST #ifdef LORA_TEST
/*Just for lora test*/ /*Just for lora test*/
static struct Bus *bus; static struct Bus *bus;

View File

@ -214,13 +214,14 @@ static uint32 SpiWriteData(struct SpiHardwareDevice *spi_dev, struct SpiDataStan
spi_datacfg = spi_datacfg->next; spi_datacfg = spi_datacfg->next;
} }
return spi_datacfg->length; return EOK;
} }
static uint32 SpiReadData(struct SpiHardwareDevice *spi_dev, struct SpiDataStandard *spi_datacfg) static uint32 SpiReadData(struct SpiHardwareDevice *spi_dev, struct SpiDataStandard *spi_datacfg)
{ {
SpiDeviceParam *dev_param = (SpiDeviceParam *)(spi_dev->haldev.private_data); 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_id = dev_param->spi_slave_param->spi_slave_id;
uint8 device_master_id = dev_param->spi_dma_param->spi_master_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; 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); gpiohs_set_pin(cs_gpio_pin, GPIO_PV_HIGH);
} }
spi_read_length += spi_datacfg->length;
spi_datacfg = spi_datacfg->next; spi_datacfg = spi_datacfg->next;
} }
return spi_datacfg->length; return spi_read_length;
} }
/*manage the spi device operations*/ /*manage the spi device operations*/

View File

@ -183,6 +183,7 @@ tSX1276LR* SX1276LR;
* Local RF buffer for communication support * Local RF buffer for communication support
*/ */
static uint8_t RFBuffer[RF_BUFFER_SIZE]; static uint8_t RFBuffer[RF_BUFFER_SIZE];
static uint8_t TFBuffer[RF_BUFFER_SIZE];
/*! /*!
* RF state machine variable * RF state machine variable
@ -401,7 +402,7 @@ void SX1276LoRaSetTxPacket( const void *buffer, uint16_t size )
{ {
TxPacketSize = 255; TxPacketSize = 255;
} }
memcpy( ( void * )RFBuffer, buffer, ( size_t )TxPacketSize ); memcpy( ( void * )TFBuffer, buffer, ( size_t )TxPacketSize );
RFLRState = RFLR_STATE_TX_INIT; RFLRState = RFLR_STATE_TX_INIT;
} }
@ -678,7 +679,7 @@ uint32_t SX1276LoRaProcess( void )
SX1276LR->RegFifoAddrPtr = SX1276LR->RegFifoTxBaseAddr; SX1276LR->RegFifoAddrPtr = SX1276LR->RegFifoTxBaseAddr;
SX1276Write( REG_LR_FIFOADDRPTR, SX1276LR->RegFifoAddrPtr ); SX1276Write( REG_LR_FIFOADDRPTR, SX1276LR->RegFifoAddrPtr );
// Write payload buffer to LORA modem // Write payload buffer to LORA modem
SX1276WriteFifo( RFBuffer, SX1276LR->RegPayloadLength ); SX1276WriteFifo( TFBuffer, SX1276LR->RegPayloadLength );
// TxDone RxTimeout FhssChangeChannel ValidHeader // TxDone RxTimeout FhssChangeChannel ValidHeader
SX1276LR->RegDioMapping1 = RFLR_DIOMAPPING1_DIO0_01 | RFLR_DIOMAPPING1_DIO1_00 | RFLR_DIOMAPPING1_DIO2_00 | RFLR_DIOMAPPING1_DIO3_01; SX1276LR->RegDioMapping1 = RFLR_DIOMAPPING1_DIO0_01 | RFLR_DIOMAPPING1_DIO1_00 | RFLR_DIOMAPPING1_DIO2_00 | RFLR_DIOMAPPING1_DIO3_01;
// PllLock Mode Ready // PllLock Mode Ready

View File

@ -215,13 +215,14 @@ static uint32 SpiWriteData(struct SpiHardwareDevice *spi_dev, struct SpiDataStan
spi_datacfg = spi_datacfg->next; spi_datacfg = spi_datacfg->next;
} }
return spi_datacfg->length; return EOK;
} }
static uint32 SpiReadData(struct SpiHardwareDevice *spi_dev, struct SpiDataStandard *spi_datacfg) static uint32 SpiReadData(struct SpiHardwareDevice *spi_dev, struct SpiDataStandard *spi_datacfg)
{ {
SpiDeviceParam *dev_param = (SpiDeviceParam *)(spi_dev->haldev.private_data); 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_id = dev_param->spi_slave_param->spi_slave_id;
uint8 device_master_id = dev_param->spi_dma_param->spi_master_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; 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); gpiohs_set_pin(cs_gpio_pin, GPIO_PV_HIGH);
} }
spi_read_length += spi_datacfg->length;
spi_datacfg = spi_datacfg->next; spi_datacfg = spi_datacfg->next;
} }
return spi_datacfg->length; return spi_read_length;
} }
/*manage the spi device operations*/ /*manage the spi device operations*/

View File

@ -1097,7 +1097,7 @@ static uint32 Stm32SpiWriteData(struct SpiHardwareDevice *spi_dev, struct SpiDat
} }
if (state != 0) { if (state != 0) {
KPrintf("spi transfer error : %d\n", state); KPrintf("spi write error : %d\n", state);
spi_datacfg->length = 0; spi_datacfg->length = 0;
} }
} }
@ -1109,7 +1109,7 @@ static uint32 Stm32SpiWriteData(struct SpiHardwareDevice *spi_dev, struct SpiDat
spi_datacfg = spi_datacfg->next; 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; int state;
x_size_t message_length, already_send_length; x_size_t message_length, already_send_length;
uint16 read_length; uint16 read_length, spi_read_length = 0;
const uint8 *ReadBuf; const uint8 *ReadBuf;
NULL_PARAM_CHECK(spi_dev); NULL_PARAM_CHECK(spi_dev);
@ -1158,7 +1158,7 @@ static uint32 Stm32SpiReadData(struct SpiHardwareDevice *spi_dev, struct SpiData
/* start once data exchange in DMA mode */ /* start once data exchange in DMA mode */
if (spi_datacfg->rx_buff) { if (spi_datacfg->rx_buff) {
memset((uint8_t *)ReadBuf, 0xff, read_length); //memset((uint8_t *)ReadBuf, 0xff, read_length);
if (StmSpi->spi_dma_flag & SPI_USING_RX_DMA_FLAG) { 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, read_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 { } else {
@ -1167,7 +1167,7 @@ static uint32 Stm32SpiReadData(struct SpiHardwareDevice *spi_dev, struct SpiData
} }
if (state != 0) { if (state != 0) {
KPrintf("spi transfer error : %d\n", state); KPrintf("spi read error : %d\n", state);
spi_datacfg->length = 0; 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); GPIO_WriteBit(cs->GPIOx, cs->GPIO_Pin, Bit_SET);
} }
spi_read_length += spi_datacfg->length;
spi_datacfg = spi_datacfg->next; spi_datacfg = spi_datacfg->next;
} }
return spi_datacfg->length; return spi_read_length;
} }
/** /**

View File

@ -58,7 +58,7 @@ struct SpiDataStandard
const uint8 *tx_buff; const uint8 *tx_buff;
uint32 tx_len; uint32 tx_len;
const uint8 *rx_buff; uint8 *rx_buff;
uint32 rx_len; uint32 rx_len;
uint32 length; uint32 length;

View File

@ -52,17 +52,30 @@ static uint32 SpiDeviceWrite(void *dev, struct BusBlockWriteParam *write_param)
NULL_PARAM_CHECK(dev); NULL_PARAM_CHECK(dev);
NULL_PARAM_CHECK(write_param); NULL_PARAM_CHECK(write_param);
int ret;
struct SpiHardwareDevice *spi_dev = (struct SpiHardwareDevice *)dev; 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 = (struct SpiDataStandard *)x_malloc(sizeof(struct SpiDataStandard));
spi_msg.rx_buff = NONE; if (NONE == spi_msg) {
spi_msg.length = write_param->size; KPrintf("SpiDeviceWrite x_malloc msg error\n");
spi_msg.spi_chip_select = 0; x_free(spi_msg);
spi_msg.spi_cs_release = 0; return ERROR;
spi_msg.next = NONE; }
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) 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(dev);
NULL_PARAM_CHECK(read_param); NULL_PARAM_CHECK(read_param);
int ret;
struct SpiHardwareDevice *spi_dev = (struct SpiHardwareDevice *)dev; struct SpiHardwareDevice *spi_dev = (struct SpiHardwareDevice *)dev;
struct SpiDataStandard spi_msg; struct SpiDataStandard *spi_msg;
spi_msg.tx_buff = NONE; spi_msg = (struct SpiDataStandard *)x_malloc(sizeof(struct SpiDataStandard));
spi_msg.rx_buff = (uint8 *)read_param->buffer; if (NONE == spi_msg) {
spi_msg.length = read_param->size; KPrintf("SpiDeviceRead x_malloc msg error\n");
spi_msg.spi_chip_select = 0; x_free(spi_msg);
spi_msg.spi_cs_release = 0; return ERROR;
spi_msg.next = NONE; }
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 = 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); NULL_PARAM_CHECK(dev);
int ret;
struct SpiHardwareDevice *spi_dev = (struct SpiHardwareDevice *)dev; struct SpiHardwareDevice *spi_dev = (struct SpiHardwareDevice *)dev;
struct SpiDataStandard msg; struct SpiDataStandard *msg;
memset(&msg, 0, sizeof(struct SpiDataStandard)); msg = (struct SpiDataStandard *)x_malloc(sizeof(struct SpiDataStandard));
msg.spi_chip_select = spi_chip_select; if (NONE == msg) {
msg.spi_cs_release = spi_cs_release; 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;
} }

View File

@ -491,14 +491,14 @@ x_err_t UsbhClearFeature(UinstPointer device, int endpoint, int feature)
x_err_t UsbhGetInterfaceDescriptor(UcfgDescPointer CfgDesc, int num, x_err_t UsbhGetInterfaceDescriptor(UcfgDescPointer CfgDesc, int num,
UintfDescPointer* IntfDesc) UintfDescPointer* IntfDesc)
{ {
uint64 ptr, depth = 0; uint32 ptr, depth = 0;
UdescPointer desc; UdescPointer desc;
NULL_PARAM_CHECK(CfgDesc); NULL_PARAM_CHECK(CfgDesc);
ptr = (uint64)CfgDesc + CfgDesc->bLength; ptr = (uint32)CfgDesc + CfgDesc->bLength;
while(ptr < (uint64)CfgDesc + CfgDesc->wTotalLength) while(ptr < (uint32)CfgDesc + CfgDesc->wTotalLength)
{ {
if(depth++ > 0x20) if(depth++ > 0x20)
{ {
@ -517,7 +517,7 @@ x_err_t UsbhGetInterfaceDescriptor(UcfgDescPointer CfgDesc, int num,
return EOK; return EOK;
} }
} }
ptr = (uint64)desc + desc->bLength; ptr = (uint32)desc + desc->bLength;
} }
KPrintf("usb_get_interface_descriptor %d failed\n", num); KPrintf("usb_get_interface_descriptor %d failed\n", num);
@ -538,7 +538,7 @@ x_err_t UsbhGetEndpointDescriptor(UintfDescPointer IntfDesc, int num,
UepDescPointer* EpDesc) UepDescPointer* EpDesc)
{ {
int count = 0, depth = 0; int count = 0, depth = 0;
uint64 ptr; uint32 ptr;
UdescPointer desc; UdescPointer desc;
@ -546,7 +546,7 @@ x_err_t UsbhGetEndpointDescriptor(UintfDescPointer IntfDesc, int num,
CHECK(num < IntfDesc->bNumEndpoints); CHECK(num < IntfDesc->bNumEndpoints);
*EpDesc = NONE; *EpDesc = NONE;
ptr = (uint64)IntfDesc + IntfDesc->bLength; ptr = (uint32)IntfDesc + IntfDesc->bLength;
while(count < IntfDesc->bNumEndpoints) while(count < IntfDesc->bNumEndpoints)
{ {
if(depth++ > 0x20) if(depth++ > 0x20)
@ -567,7 +567,7 @@ x_err_t UsbhGetEndpointDescriptor(UintfDescPointer IntfDesc, int num,
} }
else count++; else count++;
} }
ptr = (uint64)desc + desc->bLength; ptr = (uint32)desc + desc->bLength;
} }
KPrintf("usb_get_endpoint_descriptor %d failed\n", num); KPrintf("usb_get_endpoint_descriptor %d failed\n", num);

View File

@ -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); hcd->roothub->PortStatus[port-1] = (*(uint32 *)args);
break; break;
case RH_CLEAR_PORT_FEATURE: case RH_CLEAR_PORT_FEATURE:
switch(((uint64)args)) switch(((uint32)args))
{ {
case PORT_FEAT_C_CONNECTION: case PORT_FEAT_C_CONNECTION:
hcd->roothub->PortStatus[port-1] &= ~PORT_CCSC; 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; break;
case RH_SET_PORT_FEATURE: case RH_SET_PORT_FEATURE:
switch((uint64)args) switch((uint32)args)
{ {
case PORT_FEAT_CONNECTION: case PORT_FEAT_CONNECTION:
hcd->roothub->PortStatus[port-1] |= PORT_CCSC; hcd->roothub->PortStatus[port-1] |= PORT_CCSC;
@ -222,7 +222,7 @@ x_err_t UsbhHubClearPortFeature(UhubPointer hub, uint16 port, uint16 feature)
if(hub->IsRoothub) if(hub->IsRoothub)
{ {
RootHubCtrl(hub->hcd, port, RH_CLEAR_PORT_FEATURE, RootHubCtrl(hub->hcd, port, RH_CLEAR_PORT_FEATURE,
(void*)(uint64)feature); (void*)(uint32)feature);
return EOK; return EOK;
} }
@ -254,7 +254,7 @@ x_err_t UsbhHubSetPortFeature(UhubPointer hub, uint16 port,
if(hub->IsRoothub) if(hub->IsRoothub)
{ {
RootHubCtrl(hub->hcd, port, RH_SET_PORT_FEATURE, RootHubCtrl(hub->hcd, port, RH_SET_PORT_FEATURE,
(void*)(uint64)feature); (void*)(uint32)feature);
return EOK; return EOK;
} }