forked from xuos/xiuos
sync with upstream
This commit is contained in:
@@ -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
+3
-2
@@ -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
|
||||
|
||||
+3
-1
@@ -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
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user