lora: Switch to new timeout API
Get rid of legacy timeout API and move to new timeout API for LoRa. This involves changes to API, SX1276 driver and sample application. Signed-off-by: Manivannan Sadhasivam <mani@kernel.org>
This commit is contained in:
parent
0f02adfb0e
commit
7be8debaab
4 changed files with 7 additions and 13 deletions
|
@ -9,7 +9,6 @@
|
||||||
menuconfig LORA
|
menuconfig LORA
|
||||||
bool "LoRa support [EXPERIMENTAL]"
|
bool "LoRa support [EXPERIMENTAL]"
|
||||||
depends on NEWLIB_LIBC
|
depends on NEWLIB_LIBC
|
||||||
select LEGACY_TIMEOUT_API
|
|
||||||
help
|
help
|
||||||
Include LoRa drivers in the system configuration.
|
Include LoRa drivers in the system configuration.
|
||||||
|
|
||||||
|
|
|
@ -138,7 +138,7 @@ static void timer_callback(struct k_timer *_timer)
|
||||||
|
|
||||||
void RtcSetAlarm(u32_t timeout)
|
void RtcSetAlarm(u32_t timeout)
|
||||||
{
|
{
|
||||||
k_timer_start(&dev_data.timer, timeout, K_NO_WAIT);
|
k_timer_start(&dev_data.timer, K_MSEC(timeout), K_NO_WAIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
u32_t RtcSetTimerContext(void)
|
u32_t RtcSetTimerContext(void)
|
||||||
|
@ -156,7 +156,7 @@ u32_t RtcGetTimerContext(void)
|
||||||
|
|
||||||
void DelayMsMcu(u32_t ms)
|
void DelayMsMcu(u32_t ms)
|
||||||
{
|
{
|
||||||
k_sleep(ms);
|
k_sleep(K_MSEC(ms));
|
||||||
}
|
}
|
||||||
|
|
||||||
u32_t RtcMs2Tick(uint32_t milliseconds)
|
u32_t RtcMs2Tick(uint32_t milliseconds)
|
||||||
|
@ -384,19 +384,14 @@ static void sx1276_rx_done(u8_t *payload, u16_t size, int16_t rssi, int8_t snr)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sx1276_lora_recv(struct device *dev, u8_t *data, u8_t size,
|
static int sx1276_lora_recv(struct device *dev, u8_t *data, u8_t size,
|
||||||
s32_t timeout, s16_t *rssi, s8_t *snr)
|
k_timeout_t timeout, s16_t *rssi, s8_t *snr)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
Radio.SetMaxPayloadLength(MODEM_LORA, 255);
|
Radio.SetMaxPayloadLength(MODEM_LORA, 255);
|
||||||
Radio.Rx(0);
|
Radio.Rx(0);
|
||||||
|
|
||||||
/*
|
ret = k_sem_take(&dev_data.data_sem, timeout);
|
||||||
* As per the API requirement, timeout value can be in ms/K_FOREVER/
|
|
||||||
* K_NO_WAIT. So, let's handle all cases.
|
|
||||||
*/
|
|
||||||
ret = k_sem_take(&dev_data.data_sem, timeout == K_FOREVER ? K_FOREVER :
|
|
||||||
timeout == K_NO_WAIT ? K_NO_WAIT : K_MSEC(timeout));
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
LOG_ERR("Receive timeout!");
|
LOG_ERR("Receive timeout!");
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -73,7 +73,7 @@ typedef int (*lora_api_send)(struct device *dev,
|
||||||
* @see lora_recv() for argument descriptions.
|
* @see lora_recv() for argument descriptions.
|
||||||
*/
|
*/
|
||||||
typedef int (*lora_api_recv)(struct device *dev, u8_t *data, u8_t size,
|
typedef int (*lora_api_recv)(struct device *dev, u8_t *data, u8_t size,
|
||||||
s32_t timeout, s16_t *rssi, s8_t *snr);
|
k_timeout_t timeout, s16_t *rssi, s8_t *snr);
|
||||||
|
|
||||||
struct lora_driver_api {
|
struct lora_driver_api {
|
||||||
lora_api_config config;
|
lora_api_config config;
|
||||||
|
@ -132,7 +132,7 @@ static inline int lora_send(struct device *dev,
|
||||||
* @return Length of the data received on success, negative on error
|
* @return Length of the data received on success, negative on error
|
||||||
*/
|
*/
|
||||||
static inline int lora_recv(struct device *dev, u8_t *data, u8_t size,
|
static inline int lora_recv(struct device *dev, u8_t *data, u8_t size,
|
||||||
s32_t timeout, s16_t *rssi, s8_t *snr)
|
k_timeout_t timeout, s16_t *rssi, s8_t *snr)
|
||||||
{
|
{
|
||||||
const struct lora_driver_api *api = dev->driver_api;
|
const struct lora_driver_api *api = dev->driver_api;
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ void main(void)
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
/* Block until data arrives */
|
/* Block until data arrives */
|
||||||
len = lora_recv(lora_dev, data, MAX_DATA_LEN, SYS_FOREVER_MS,
|
len = lora_recv(lora_dev, data, MAX_DATA_LEN, K_FOREVER,
|
||||||
&rssi, &snr);
|
&rssi, &snr);
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
LOG_ERR("LoRa receive failed");
|
LOG_ERR("LoRa receive failed");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue