Merge branch 'prepare_for_master' of https://gitlink.org.cn/xuos/xiuos into prepare_for_master

This commit is contained in:
涂煜洋
2023-09-06 11:20:46 +08:00
20 changed files with 1489 additions and 412 deletions

View File

@@ -191,8 +191,8 @@ static uint32 SpiLoraWrite(void *dev, struct BusBlockWriteParam *write_param)
KPrintf("SpiLoraWrite ERROR:The message is too long!\n");
return ERROR;
} else {
SX1276SetTxPacket(write_param->buffer, write_param->size);
while(SX1276Process() != RF_TX_DONE);
SX1276SetTx(write_param->buffer, write_param->size);
KPrintf("SpiLoraWrite success!\n");
}
@@ -210,24 +210,12 @@ static uint32 SpiLoraRead(void *dev, struct BusBlockReadParam *read_param)
NULL_PARAM_CHECK(dev);
NULL_PARAM_CHECK(read_param);
int read_times = 100;
SX1276StartRx();
KPrintf("SpiLoraRead Ready!\n");
while (read_times) {
if (SX1276Process() != RF_RX_DONE) {
read_times --;
MdelayKTask(500);
} else {
break;
}
}
int ret = SX1276GetRx(read_param->buffer, (uint16 *)&read_param->read_length);
if (read_times > 0) {
SX1276GetRxPacket(read_param->buffer, (uint16 *)&read_param->read_length);
} else {
read_param->read_length = 0;
if (ret < 0) {
return 0;
}
return read_param->read_length;

View File

@@ -494,6 +494,7 @@ int HwSpiInit(void)
return ret;
}
#ifdef TEST_SPI
/*Just for lora test*/
static struct Bus *bus;
static struct HardwareDev *dev;
@@ -578,4 +579,4 @@ void TestLoraOpen(void)
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
TestLoraOpen, TestLoraOpen, open lora device and read parameters);
#endif

View File

@@ -50,6 +50,9 @@ uint8_t SX1276Regs[0x70];
static bool LoRaOn = true;
static bool LoRaOnState = false;
static int sx1276_tx_sem, sx1276_rx_sem;
static int sx1276_radio_task;
void SX1276Reset(void)
{
uint32_t startTick;
@@ -200,6 +203,20 @@ void SX1276GetRxPacket(void *buffer, uint16_t *size)
}
}
int SX1276GetRx(void *buffer, uint16_t *size)
{
int ret = -1;
SX1276StartRx();
//receive timeout 10s
ret = KSemaphoreObtain(sx1276_rx_sem, 10000);
if (0 == ret) {
SX1276LoRaSetRFState(RFLR_STATE_IDLE);
SX1276GetRxPacket(buffer, size);
}
return ret;
}
void SX1276SetTxPacket(const void *buffer, uint16_t size)
{
if(LoRaOn == false) {
@@ -209,6 +226,14 @@ void SX1276SetTxPacket(const void *buffer, uint16_t size)
}
}
void SX1276SetTx(const void *buffer, uint16_t size)
{
SX1276SetTxPacket(buffer, size);
KSemaphoreObtain(sx1276_tx_sem, WAITING_FOREVER);
SX1276StartRx();
}
uint8_t SX1276GetRFState(void)
{
if(LoRaOn == false) {
@@ -236,6 +261,20 @@ uint32_t SX1276Process(void)
}
}
static void Sx1276RadioEntry(void *parameter)
{
uint32_t result;
while(1) {
result = SX1276Process();
if (RF_RX_DONE == result) {
KSemaphoreAbandon(sx1276_rx_sem);
}
if (RF_TX_DONE == result) {
KSemaphoreAbandon(sx1276_tx_sem);
}
}
}
uint32_t SX1276ChannelEmpty(void)
{
if(LoRaOn == false) {
@@ -277,6 +316,12 @@ void SX1276Init(void)
SX1276_SetLoRaOn(LoRaOn);
SX1276LoRaInit();
#endif
sx1276_rx_sem = KSemaphoreCreate(0);
sx1276_tx_sem = KSemaphoreCreate(0);
sx1276_radio_task = KTaskCreate("radio", Sx1276RadioEntry , NONE, 2048, 20);
StartupKTask(sx1276_radio_task);
}
#endif

View File

@@ -80,8 +80,12 @@ void SX1276StartRx( void ); //开始接收
void SX1276GetRxPacket( void *buffer, uint16_t *size ); //得到接收的数据
int SX1276GetRx(void *buffer, uint16_t *size); //应用接收数据,无数据时阻塞
void SX1276SetTxPacket( const void *buffer, uint16_t size ); //发送数据
void SX1276SetTx( const void *buffer, uint16_t size ); //应用发送数据
uint8_t SX1276GetRFState( void ); //得到RFLRState状态
void SX1276SetRFState( uint8_t state ); //设置RFLRState状态RFLRState的值决定了下面的函数处理哪一步的代码

View File

@@ -493,3 +493,15 @@ DWORD GetFatTime(void)
return fat_time;
}
void FatfsPrintf(struct FileDescriptor *fdp, const void *src, size_t len)
{
int i = 0;
for (i = 0; i < len; i ++) {
f_printf(fdp->data, "%d,", ((uint8 *)src)[i]);
}
if (i == len) {
f_printf(fdp->data, "\r\n");
}
}

View File

@@ -33,7 +33,7 @@
/ 3: f_lseek() function is removed in addition to 2. */
#define FF_USE_STRFUNC 0
#define FF_USE_STRFUNC 1
/* This option switches string functions, f_gets(), f_putc(), f_puts() and f_printf().
/
/ 0: Disable string functions.

View File

@@ -16,7 +16,9 @@
time_t time(time_t *t)
{
NULL_PARAM_CHECK(t);
if (NULL == t) {
return 0;
}
time_t current = 0;
#ifdef RESOURCES_RTC

View File

@@ -125,7 +125,7 @@ void LwipTcpRecvTest(void)
{
uint8_t enet_port = 0; ///< test enet port 0
lwip_config_net(enet_port, lwip_ipaddr, lwip_netmask, lwip_gwaddr);
lwip_config_tcp(enet_port, lwip_ipaddr, lwip_netmask, lwip_gwaddr);
uint8_t* recv_data = NULL;
socklen_t sin_size;