sync with upstream
This commit is contained in:
@@ -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
|
||||
|
||||
+35
-21
@@ -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*/
|
||||
|
||||
+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
|
||||
|
||||
Reference in New Issue
Block a user