Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 67 additions & 6 deletions LoRa/lora.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ file_open(struct inode *inode, struct file *filp)
int status = -ENXIO;

pr_debug("lora: open file\n");

mutex_lock(&device_list_lock);
/* Find the lora data in device_entry with matched dev_t in inode. */
list_for_each_entry(lrdata, &device_list, device_entry) {
Expand Down Expand Up @@ -123,17 +123,17 @@ static int
file_close(struct inode *inode, struct file *filp)
{
struct lora_struct *lrdata;

pr_debug("lora: close file\n");

lrdata = filp->private_data;

mutex_lock(&device_list_lock);
filp->private_data = NULL;

if (lrdata->users > 0)
lrdata->users--;

/* Last close */
if (lrdata->users == 0) {
kfree(lrdata->rx_buf);
Expand Down Expand Up @@ -218,6 +218,29 @@ file_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
if (lrdata->ops->getPower != NULL)
ret = lrdata->ops->getPower(lrdata, pval);
break;
/* Set high power +20 dBm capability on PA_BOOST pin. */
case LORA_SET_PMAX20DBM:
if (lrdata->ops->setPmax20dBm != NULL)
ret = lrdata->ops->setPmax20dBm(lrdata, pval);
break;
/* Set & get the RF power rise/fall time of ramp up/down. */
case LORA_SET_PARAMP:
if (lrdata->ops->setPaRamp != NULL)
ret = lrdata->ops->setPaRamp(lrdata, pval);
break;
case LORA_GET_PARAMP:
if (lrdata->ops->getPaRamp != NULL)
ret = lrdata->ops->getPaRamp(lrdata, pval);
break;
/* Set & get the RF max current of overload current protection (OCP) for PA. */
case LORA_SET_OCPIMAX:
if (lrdata->ops->setOcpImax != NULL)
ret = lrdata->ops->setOcpImax(lrdata, pval);
break;
case LORA_GET_OCPIMAX:
if (lrdata->ops->getOcpImax != NULL)
ret = lrdata->ops->getOcpImax(lrdata, pval);
break;
/* Set & get the LNA gain. */
case LORA_SET_LNA:
if (lrdata->ops->setLNA != NULL)
Expand All @@ -232,6 +255,11 @@ file_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
if (lrdata->ops->setLNAAGC != NULL)
ret = lrdata->ops->setLNAAGC(lrdata, pval);
break;
/* Set RF low noise amplifier (LNA) boost in High Frequency (RFI_HF) to 150% LNA current. */
case LORA_SET_LNABOOSTHF:
if (lrdata->ops->setLnaBoostHf != NULL)
ret = lrdata->ops->setLnaBoostHf(lrdata, pval);
break;
/* Set & get the RF spreading factor. */
case LORA_SET_SPRFACTOR:
if (lrdata->ops->setSPRFactor != NULL)
Expand Down Expand Up @@ -260,6 +288,39 @@ file_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
if (lrdata->ops->getSNR != NULL)
ret = lrdata->ops->getSNR(lrdata, pval);
break;
/* Enable CRC generation and check on received payload. */
case LORA_SET_CRC:
if (lrdata->ops->setCRC != NULL)
ret = lrdata->ops->setCRC(lrdata, pval);
break;
/* Set & get LoRa package's coding rate. */
case LORA_SET_CODINGRATE:
if (lrdata->ops->setCodingRate != NULL)
ret = lrdata->ops->setCodingRate(lrdata, pval);
break;
case LORA_GET_CODINGRATE:
if (lrdata->ops->getCodingRate != NULL)
ret = lrdata->ops->getCodingRate(lrdata, pval);
break;
/* Set LoRa packages in Explicit / Implicit Header Mode. */
case LORA_SET_IMPLICIT:
if (lrdata->ops->setImplicit != NULL)
ret = lrdata->ops->setImplicit(lrdata, pval);
break;
/* Set RF low data rate optimize. */
case LORA_SET_LDRO:
if (lrdata->ops->setLDRO != NULL)
ret = lrdata->ops->setLDRO(lrdata, pval);
break;
/* Set & get LoRa preamble length. */
case LORA_SET_PREAMBLE:
if (lrdata->ops->setPreambleLen != NULL)
ret = lrdata->ops->setPreambleLen(lrdata, pval);
break;
case LORA_GET_PREAMBLE:
if (lrdata->ops->getPreambleLen != NULL)
ret = lrdata->ops->getPreambleLen(lrdata, pval);
break;
default:
ret = -ENOTTY;
}
Expand Down Expand Up @@ -405,7 +466,7 @@ int
lora_unregister_driver(struct lora_driver *driver)
{
dev_t dev = MKDEV(driver->major, driver->minor_start);

pr_debug("lora: unregister %s\n", driver->name);
/* Delete device class. */
class_destroy(driver->lora_class);
Expand Down
37 changes: 36 additions & 1 deletion LoRa/lora.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,26 @@
#define LORA_GET_POWER (_IOR(LORA_IOC_MAGIC, 5, int))
#define LORA_SET_LNA (_IOW(LORA_IOC_MAGIC, 6, int))
#define LORA_GET_LNA (_IOR(LORA_IOC_MAGIC, 7, int))
#define LORA_SET_LNAAGC (_IOR(LORA_IOC_MAGIC, 8, int))
#define LORA_SET_LNAAGC (_IOW(LORA_IOC_MAGIC, 8, int))
#define LORA_SET_SPRFACTOR (_IOW(LORA_IOC_MAGIC, 9, int))
#define LORA_GET_SPRFACTOR (_IOR(LORA_IOC_MAGIC, 10, int))
#define LORA_SET_BANDWIDTH (_IOW(LORA_IOC_MAGIC, 11, int))
#define LORA_GET_BANDWIDTH (_IOR(LORA_IOC_MAGIC, 12, int))
#define LORA_GET_RSSI (_IOR(LORA_IOC_MAGIC, 13, int))
#define LORA_GET_SNR (_IOR(LORA_IOC_MAGIC, 14, int))
#define LORA_SET_CRC (_IOW(LORA_IOC_MAGIC, 15, int))
#define LORA_SET_CODINGRATE (_IOW(LORA_IOC_MAGIC, 16, int))
#define LORA_GET_CODINGRATE (_IOR(LORA_IOC_MAGIC, 17, int))
#define LORA_SET_IMPLICIT (_IOW(LORA_IOC_MAGIC, 18, int))
#define LORA_SET_LDRO (_IOW(LORA_IOC_MAGIC, 19, int))
#define LORA_SET_PREAMBLE (_IOW(LORA_IOC_MAGIC, 20, int))
#define LORA_GET_PREAMBLE (_IOR(LORA_IOC_MAGIC, 21, int))
#define LORA_SET_PARAMP (_IOW(LORA_IOC_MAGIC, 22, int))
#define LORA_GET_PARAMP (_IOR(LORA_IOC_MAGIC, 23, int))
#define LORA_SET_OCPIMAX (_IOW(LORA_IOC_MAGIC, 24, int))
#define LORA_GET_OCPIMAX (_IOR(LORA_IOC_MAGIC, 25, int))
#define LORA_SET_LNABOOSTHF (_IOW(LORA_IOC_MAGIC, 26, int))
#define LORA_SET_PMAX20DBM (_IOW(LORA_IOC_MAGIC, 27, int))

/* List the state of the LoRa device. */
#define LORA_STATE_SLEEP 0
Expand All @@ -83,11 +96,21 @@ struct lora_operations {
/* Set & get the PA power. */
long (*setPower)(struct lora_struct *, void __user *);
long (*getPower)(struct lora_struct *, void __user *);
/* Set high power +20 dBm capability on PA_BOOST pin. */
long (*setPmax20dBm)(struct lora_struct *, void __user *);
/* Set & get the RF power rise/fall time of ramp up/down. */
long (*setPaRamp)(struct lora_struct *, void __user *);
long (*getPaRamp)(struct lora_struct *, void __user *);
/* Set & get the RF max current of overload current protection (OCP) for PA. */
long (*setOcpImax)(struct lora_struct *, void __user *);
long (*getOcpImax)(struct lora_struct *, void __user *);
/* Set & get the LNA gain. */
long (*setLNA)(struct lora_struct *, void __user *);
long (*getLNA)(struct lora_struct *, void __user *);
/* Set LNA be auto gain control or manual. */
long (*setLNAAGC)(struct lora_struct *, void __user *);
/* Set low noise amplifier (LNA) boost in High Frequency (RFI_HF) to 150% LNA current. */
long (*setLnaBoostHf)(struct lora_struct *, void __user *);
/* Set & get the RF spreading factor. */
long (*setSPRFactor)(struct lora_struct *, void __user *);
long (*getSPRFactor)(struct lora_struct *, void __user *);
Expand All @@ -98,6 +121,18 @@ struct lora_operations {
long (*getRSSI)(struct lora_struct *, void __user *);
/* Get last packet's SNR. */
long (*getSNR)(struct lora_struct *, void __user *);
/* Enable CRC generation and check on received payload. */
long (*setCRC)(struct lora_struct *, void __user *);
/* Set & get LoRa package's coding rate. */
long (*setCodingRate)(struct lora_struct *, void __user *);
long (*getCodingRate)(struct lora_struct *, void __user *);
/* Set LoRa packages in Explicit / Implicit Header Mode. */
long (*setImplicit)(struct lora_struct *, void __user *);
/* Set RF low data rate optimize. */
long (*setLDRO)(struct lora_struct *, void __user *);
/* Set & get LoRa preamble length. */
long (*setPreambleLen)(struct lora_struct *, void __user *);
long (*getPreambleLen)(struct lora_struct *, void __user *);
/* Read from the LoRa device's communication. */
ssize_t (*read)(struct lora_struct *, const char __user *, size_t);
/* Write to the LoRa device's communication. */
Expand Down
Loading