Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.

Let's Have an IEEE 802.15.4 over LoRa Linux Device Driver for IoT

2 385 vues

Publié le

Video: https://www.youtube.com/watch?v=_lGN-LDyl2I

在萬物聯網的時代,透過通訊技術將量測到的物理量傳送到遠端伺服器是很一般的作法。但要這「通訊」如何達到低成本、符合使用情境的條件,仍然是個經典的問題。
特別是在需要長距離、低功耗與長生命週期的需求下,或許以 Low-Power Wide-Area Network (LPWAN) 為基礎的 LoRa 通訊技術是個不錯的選擇。
若是在程式底層的部份,將此基礎建設的通訊技術寫成個 LoRa 的 Linux Device Driver,一般使用者就可以單純專注在應用層面的開發、降低進入門檻。
這次將介紹如何寫出這 IEEE 802.15.4 MAC over LoRa PHY 的 Linux Device Driver。
期望經由此 driver 合併 IEEE 802.15.4 MAC 的 Cluster Tree Network topology 與 LoRa PHY 的 link budget 優勢,達到超大範圍的通訊覆蓋面積,以達到相關需求。
In the Internet of Things' era, transferring the measured physical values to the servers through the communication technology is the popular usage template. However, finding the lowest cost method that fulfills the usage scenarios, power issues and the real time requirements still is a classic engineering problem.
Under the long range and low power consumption for longer life cycle conditions, LoRa which is based on Low-Power Wide-Area Network (LPWAN) might be one of the good choices. Moreover, if it goes with a LoRa Linux device driver, general users can focus on the development of related upper layer applications.
This time, I will introduce how to write an IEEE 802.15.4 MAC over LoRa PHY Linux device driver and its architecture. Hope this approach will gain more benefits by combining both advantages: Cluster Tree Network of IEEE 802.15.4 MAC and the good link budget of LoRa PHY.

Publié dans : Technologie
  • DOWNLOAD FULL BOOKS, INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/yxufevpm } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/yxufevpm } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/yxufevpm } ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/yxufevpm } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/yxufevpm } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/yxufevpm } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Répondre 
    Voulez-vous vraiment ?  Oui  Non
    Votre message apparaîtra ici
  • DOWNLOAD FULL BOOKS, INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Répondre 
    Voulez-vous vraiment ?  Oui  Non
    Votre message apparaîtra ici
  • DOWNLOAD FULL eBOOK INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL. PDF eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. doc eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. PDF eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. doc eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, CookeBOOK Crime, eeBOOK Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Répondre 
    Voulez-vous vraiment ?  Oui  Non
    Votre message apparaîtra ici
  • DOWNLOAD FULL eBOOK INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL. PDF eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. doc eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. PDF eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. doc eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, CookeBOOK Crime, eeBOOK Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Répondre 
    Voulez-vous vraiment ?  Oui  Non
    Votre message apparaîtra ici
  • DOWNLOAD FULL eBOOK INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL. PDF eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. doc eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. PDF eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. doc eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, CookeBOOK Crime, eeBOOK Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Répondre 
    Voulez-vous vraiment ?  Oui  Non
    Votre message apparaîtra ici

Let's Have an IEEE 802.15.4 over LoRa Linux Device Driver for IoT

  1. 1. Let's Have an IEEE 802.15.4 over LoRa Linux Device Driver for IoT SX1278 Transceiver in LoRa Mode for Example Jian-Hong Pan (StarNight) @ 2017.11.28 Taiwan Linux Kernel Hackers
  2. 2. Outline ● History ● OSI 7 Layers ○ LoRa / LoRaWAN ○ IEEE 802.15.4 ● Hardware ○ LoRa Transceiver ■ State Machine ■ FIFO Data Buffer ● Approaches ○ File Operations ○ IEEE 802.15.4 ● Driver Implementaion ○ Used APIs in Driver ○ The Driver Introduction ○ Device Tree & Tests ● Summary
  3. 3. Who am I 潘建宏 / Jian-Hong Pan (StarNight) I come from Taiwan ! You can find me at ~ http://www.slideshare.net/chienhungpan/ GitHub : starnight Facebook : Jian-Hong Pan Email : starnight [AT] g.ncu.edu.tw
  4. 4. History ● The Physics of the IoT ○ by David Mikolas @ Taipei.py 2016.06.30 ○ https://www.youtube.com/watch?v=iVlXt6RbgCE#t=18m30s ● 科技農夫陳幸延──農田裡的開源自造者 ○ The Scientific Farmer, Yan -- A Maker in the Farm ○ by 顏理謙, BUSINESS NEXT - 2016.06.10 ● Location Aware Sensor System (LASS) ○ LASS環境感測網路系統 http://lass-net.org/ ● 【科技農夫共創微氣候新農耕模式】年輕小農靠開源翻轉傳 統農業 ○ [Scientific farmers creates the new farming methods and utensils] Young farmers strengthen traditional agriculture with Open Source ○ by 何維涓, iThome - 2017.08.19
  5. 5. Wireless Technology ● Features ○ Long distance (coverage) ○ Short data message ○ Power consumption issue ● Low-Rate Wireless Personal Area Networks (LR-WPANs) ○ IEEE 802.15.4 ● Low-Power Wide-Area Network (LPWAN) ○ LoRa ○ Ultra Narrow Band: ■ Sigfox, NB-IoT ... Gateway or Edge Internet End-Device End-Device End-Device Outdoor Wireless measurement / control
  6. 6. From LPWAN - The Benefits of LPWAN Technology vs Other IoT Connectivity Options, written by Calum McClelland on iotforall.com Bandwidth - Range of Wireless LoRa
  7. 7. OSI 7 Layers Reference: Wikipedia OSI model https://en.wikipedia.org/wiki/OSI_model Physical Data Link Network Transport Session Presentation Application HTTP Sockets HTML HTTP Web API TCP IP Link neighbors Controlled by Application Controlled by OS Electrics, Lines / Radio Socket APIs
  8. 8. LoRa LoRa is the physical (PHY) layer or the wireless modulation utilized to create the long range communication link. ● Chirp spread spectrum (CSS) radio modulation ● Good link budget ● Low data rate ● Could be quite low power consumption ● Radio frequency should be used according to regional laws Reference: LoRaWAN™ 101 – A Technical Introduction by LoRa Alliance - November, 2015 What is LoRa? by LINK LABS - February 14, 2015
  9. 9. Link Budget dbm TX Power RX Power TX Antenna RX Antenna Connector Connector Free Space distance
  10. 10. LoRaWAN LoRaWAN is a media access control (MAC) layer protocol for managing communication between LPWAN gateways and end-node devices, maintained by the LoRa Alliance. ● Star topology ● Uplink - Downlink ● Over LoRa or FSK Reference: Wikipedia LPWAN https://en.wikipedia.org/wiki/LPWAN LoRaWAN™ Specification V1.0.2 by LoRa Alliance - July, 2016, P.12 ● Classes ○ Class A: Base line ○ Class B: Beacon ○ Class C: Continuous
  11. 11. LoRa Physical Message Formats Preamble PHDR PHDR_CRC PHYPayload CRC Preamble PHDR PHDR_CRC PHYPayload Uplink Message: Downlink Message: Preamble, PHDR, PHDR_CRC and CRC are inserted by the radio transceiver Reference: LoRaWAN™ Specification V1.0.2 by LoRa Alliance - July, 2016, P.11
  12. 12. IEEE 802.15.4 IEEE 802.15.4 is a technical standard which defines the operation of low-rate wireless personal area networks (LR-WPANs). It specifies the physical (PHY) layer and media access control (MAC) for LR-WPANs. Reference: Wikipedia IEEE 802.15.4 https://en.wikipedia.org/wiki/IEEE_802.15.4 Cluster tree networkStar topology Peer to peer topology PAN Coordinator Full-Function Device (FFD) Reduced-Function Device (RFD)
  13. 13. Comparison LoRaWAN Star Topology LoRa Good Link Budget IEEE 802.15.4 MAC Cluster Tree Network IEEE 802.15.4 PHY Normal Link Budget Application Presentation Session Transport Network MAC Layer PHY Layer LR-WPAN LPWAN
  14. 14. Combine Both Advantages Application Presentation Session Transport Network MAC Layer IEEE 802.15.4 MAC Cluster Tree Network PHY Layer LoRa Good Link Budget TCP/UDP 6LoWPAN Socket APIs LoRa acts as an IEEE 802.15.4 PHY
  15. 15. Cluster Tree Network & Good Link Budget Internet PAN Coordinator Full-Function Device (FFD) Reduced-Function Device (FFD) LoRa Each node can have a IPv6 address, if it has 6LoWPAN
  16. 16. LoRa Transceiver Hardware SX127X SPI Main Board Raspberry Pi SPI_CE1 SPI BUS LoRa Transceiver SX127X SPI Main Board Raspberry Pi SPI_CE1 SPI BUS
  17. 17. One of LoRa Transceiver Semtech - SX1276/77/78/79 for example http://www.semtech.com/images/datasheet/sx1276.pdf ● 168 dB maximum link budget ● High sensitivity: down to -148 dBm ● LoRa and FSK/OOK mode ● SPI interface Part Number Frequency Range Spreading Factor Bandwidth Effective Bitrate Est. Sensitivity SX1276 137 - 1020 MHz 6 - 12 7.8 - 500 kHz .018 - 37.5 kbps -111 to -148 dBm SX1277 137 - 1020 MHz 6 - 9 7.8 - 500 kHz .011 - 37.5 kbps -111 to -139 dBm SX1278 137 - 525 MHz 6 - 12 7.8 - 500 kHz .018 - 37.5 kbps -111 to -148 dBm SX1279 137 - 960MHz 6 - 12 7.8 - 500 kHz .018 - 37.5 kbps -111 to -148 dBm
  18. 18. State Machine of SX127X Transceiver SLEEP STANDBY TX RXSINGLE Set by command Set by command TX is completed / Set by command RX is completed / RX timeout / RX CRC error / Set by command Only focus on used states
  19. 19. SX127X Transceiver’s IRQ Flags Bit Flag 7 RxTimeout 6 RxDone 5 PayloadCrcError 4 ValidHeader 3 TxDone 2 CadDone 1 FhssChangeChannel 0 CadDetected Reference: Semtech SX1276/77/78/79 datasheet, P.111, Figure 8. LoRaTM Mode Register Map RegIrqFlags (0x12)
  20. 20. SX127X Transceiver Linux Device Driver ● File Operation Interface ○ https://github.com/starnight/LoRa/tree/file-ops ○ File + SPI ○ As a character device node: /dev/loraSPIX.X ○ read/write from/to the FIFO data buffer, ioctl sets transceiver’s parameter ● IEEE 802.15.4 Interface ○ https://github.com/starnight/LoRa ○ IEEE 802.15.4 MAC + SPI ○ As a WPAN network interface ○ socket with 6LoWPAN over IEEE 802.15.4 MAC
  21. 21. Used APIs in Driver ● SPI ○ The communication bus with SX127X transceiver ● regmap ○ The common wrapper of low rate buses, like SPI, I2 C ... ● IEEE 802.15.4 ○ The LR-WPAN module in kernel ● Timer & Interrupt ○ Used for polling the state of the transciver periodically ● workqueue ○ The work scheduled by timer interrupt service routine ○ The work should check and do some things according to the state of transceiver ● Spin lock ○ Lock the state flags in the driver of the transceiver ● Device Tree ○ Set parameters with the configuration in device tree, if Open Firmware is enabled
  22. 22. Flow Charts of Driver Module Init & Exit module_init register SX1278 as an SPI driver End unregister SX1278 SPI driver End module_exit
  23. 23. Register SX1278 as SPI Protocol Driver /* The SPI driver which acts as a protocol driver in this kernel module. */ static struct spi_driver sx1278_spi_driver = { .driver = { .name = __DRIVER_NAME, .owner = THIS_MODULE, #ifdef CONFIG_OF .of_match_table = of_match_ptr(sx1278_dt_ids), #endif #ifdef CONFIG_ACPI .acpi_match_table = ACPI_PTR(sx1278_acpi_ids), #endif }, .probe = sx1278_spi_probe, .remove = sx1278_spi_remove, .id_table = sx1278_spi_ids, }; /* Register SX1278 kernel module. */ module_spi_driver(sx1278_spi_driver); Note: spi_match_device Matched by Open Firmware Matched by ACPI Matched by SPI Bus Device Tree Macro
  24. 24. of, acpi, id _match_table /* The compatible chip array. */ #ifdef CONFIG_OF static const struct of_device_id sx1278_dt_ids[] = { { .compatible = "semtech,sx1276" }, { .compatible = "semtech,sx1277" }, { .compatible = "semtech,sx1278" }, { .compatible = "semtech,sx1279" }, { .compatible = "sx1278" }, {}, }; MODULE_DEVICE_TABLE(of, sx1278_dt_ids); #endif /* The compatible ACPI device array. */ #ifdef CONFIG_ACPI static const struct acpi_device_id sx1278_acpi_ids[] = { { .id = "sx1278" }, {}, }; MODULE_DEVICE_TABLE(acpi, sx1278_acpi_ids); #endif /* The compatible SPI device id array. */ static const struct spi_device_id sx1278_spi_ids[] = { { .name = "sx1278" }, {}, }; MODULE_DEVICE_TABLE(spi, sx1278_spi_ids);
  25. 25. Flow Chart of Probing an SPI Device Have a block of memory to hold the IEEE 802.15.4 compatible hardware Set the LoRa PHY as SPI deivce’s privata data End Probe an SPI device Have a regmap wrapper for the SPI bus to transceiver Set the RF channels & output power Set the IEEE 802.15.4 address Register the LoRa PHY as an IEEE 802.15.4 hardware Set the timer interrupt & the work going to be scheduled Initial the LoRa PHY sx1278_ieee_add_one
  26. 26. SPI Probe Device Callback Function static int sx1278_spi_probe(struct spi_device *spi) { struct ieee802154_hw *hw; struct sx1278_phy *phy; int err; hw = ieee802154_alloc_hw(sizeof(*phy), &sx1278_ops); ... phy = hw->priv; phy->hw = hw; hw->parent = &spi->dev; phy->map = devm_regmap_init_spi(spi, &sx1278_regmap_config); /* Set the SPI device's driver data for later usage. */ spi_set_drvdata(spi, phy); err = sx1278_ieee_add_one(phy); ... } Allocate a block of memory to hold the data of IEEE 802.15.4 compatible hardware
  27. 27. static const struct ieee802154_ops sx1278_ops = { .owner = THIS_MODULE, .xmit_async = sx1278_ieee_xmit, .ed = sx1278_ieee_ed, .set_channel = sx1278_ieee_set_channel, .set_txpower = sx1278_ieee_set_txpower, .start = sx1278_ieee_start, .stop = sx1278_ieee_stop, .set_promiscuous_mode = sx1278_ieee_set_promiscuous_mode, }; The entry points of IEEE 802.15.4 actions IEEE 802.15.4 Ops. of SX1278 Driver
  28. 28. struct sx1278_phy phy cfg802154_registered_device Block Memory of IEEE 802.15.4 Device struct wpan_phy wpan_phy struct ieee802154_local *local = wpan_phy.priv struct wpan_phy *phy ieee802154_ops *ops struct ieee802154_hw hw struct wpan_phy *phy void *priv struct device *parent struct regmap *map struct ieee802154_hw *hw sx1278_ops regmap device of SPI pointed by IEEE 802.15.4 module ieee802154_alloc_hw pointed by SX1278 driver sx1278_spi_probe
  29. 29. SPI Probe Device Callback Function static int sx1278_spi_probe(struct spi_device *spi) { struct ieee802154_hw *hw; struct sx1278_phy *phy; int err; hw = ieee802154_alloc_hw(sizeof(*phy), &sx1278_ops); ... phy = hw->priv; phy->hw = hw; hw->parent = &spi->dev; phy->map = devm_regmap_init_spi(spi, &sx1278_regmap_config); /* Set the SPI device's driver data for later usage. */ spi_set_drvdata(spi, phy); err = sx1278_ieee_add_one(phy); ... } Allocate a block of memory to hold the data of IEEE 802.15.4 compatible hardware Have a regmap wrapping the SPI bus to the transceiver Set the phy as the driver data of the SPI device
  30. 30. struct sx1278_phy struct sx1278_phy { struct ieee802154_hw *hw; struct regmap *map; bool suspended; u8 opmode; struct timer_list timer; struct work_struct irqwork; /* Lock the RX and TX actions. */ spinlock_t buf_lock; struct sk_buff *tx_buf; u8 tx_delay; bool one_to_be_sent; bool post_tx_done; bool is_busy; };
  31. 31. Register SX1278 as IEEE 802.15.4 PHY static int sx1278_ieee_add_one(struct sx1278_phy *phy) { struct ieee802154_hw *hw = phy->hw; int err; /* Define channels could be used. */ hw->phy->supported.channels[0] = sx1278_ieee_channel_mask(hw); /* SX1278 phy channel 11 as default */ hw->phy->current_channel = 11; /* Define RF power. */ hw->phy->supported.tx_powers = sx1278_powers; hw->phy->supported.tx_powers_size = ARRAY_SIZE(sx1278_powers); hw->phy->transmit_power = sx1278_powers[12]; ieee802154_random_extended_addr(&hw->phy->perm_extended_addr); ... Set usable RF channels of the SX127X transceiver Set usable RF output powers of the SX127X transceiver Generates a random extended address of IEEE 802.15.4 MAC
  32. 32. Register SX1278 as IEEE 802.15.4 PHY Continue ... hw->flags = IEEE802154_HW_TX_OMIT_CKSUM | IEEE802154_HW_RX_OMIT_CKSUM | IEEE802154_HW_PROMISCUOUS; err = ieee802154_register_hw(hw); ... INIT_WORK(&phy->irqwork, sx1278_timer_irqwork); init_timer(&phy->timer); phy->timer.expires = jiffies_64 + HZ; phy->timer.function = sx1278_timer_isr; phy->timer.data = (unsigned long)phy; spin_lock_init(&phy->buf_lock); err = init_sx127x(phy->map); ... } Do/Not do generate frame check sum Register SX1278 as an IEEE 802.15.4 PHY Bind the function to the work which is going to be scheduled by the timer ISR Initial settings of the timer including the timer ISR The argument phy going to be passed into timer ISR
  33. 33. Flow Chart of Probing an SPI Device Have the LoRa PHY from SPI device’s privata data End Remove an SPI device Delete and stop the timer Flush the work scheduled by timer ISR Unregister the IEEE 802.15.4 hardware Free the IEEE 802.15.4 hardware sx1278_ieee_delete
  34. 34. SPI Remove Device Callback Function static int sx1278_spi_remove(struct spi_device *spi) { struct sx1278_phy *phy = spi_get_drvdata(spi); sx1278_ieee_del(phy); return 0; } static void sx1278_ieee_del(struct sx1278_phy *phy) { if (!phy) return; del_timer(&phy->timer); flush_work(&phy->irqwork); ieee802154_unregister_hw(phy->hw); ieee802154_free_hw(phy->hw); } Get the phy from the SPI device’s driver data Stop timing and delete the timer Wait for irqwork to finish executing the last queueing instance Unregister and free the IEEE 802.15.4 compatible device
  35. 35. Polling the State of SX127X Periodically SLEEP STANDBY TX RXSINGLE Set by command Set by command TX is completed / Set by command RX is completed / RX timeout / RX CRC error / Set by command Polling when Timer Interrupted !!!
  36. 36. Polling when Timer Interrupted 1. When to start the timer? a. The IEEE 802.15.4 interface is becoming up. 2. When to stop the timer? a. The IEEE 802.15.4 interface is becoming down. 3. Timer interrupt is an interrupt, so there should not be any long time block in the interrupt service routine. a. Polling the SX127X transceiver’s state will need SPI transferring. b. SPI locks the system when it is transfering the SPI message synchronously. c. Schedule a work to workqueue in timer’s interrupt service routine!!!
  37. 37. IEEE 802.15.4 Interface Up & Down static const struct ieee802154_ops sx1278_ops = { .owner = THIS_MODULE, .xmit_async = sx1278_ieee_xmit, .ed = sx1278_ieee_ed, .set_channel = sx1278_ieee_set_channel, .set_txpower = sx1278_ieee_set_txpower, .start = sx1278_ieee_start, .stop = sx1278_ieee_stop, .set_promiscuous_mode = sx1278_ieee_set_promiscuous_mode, }; ip link set <interface> up ip link set <interface> down
  38. 38. IEEE 802.15.4 Interface Up static int sx1278_ieee_start(struct ieee802154_hw *hw) { struct sx1278_phy *phy = hw->priv; dev_dbg(regmap_get_device(phy->map), "interface upn"); sx1278_ieee_set_channel(hw, 0, hw->phy->current_channel); phy->suspended = false; sx127X_start_loramode(phy->map); phy->opmode = sx127X_get_mode(phy->map); add_timer(&phy->timer); return 0; } Set the RF using channel and frequency Set the SX127X transceiver in LoRa mode Get the SX127X transceiver operating mode Enable timer
  39. 39. IEEE 802.15.4 Interface Down static void sx1278_ieee_stop(struct ieee802154_hw *hw) { struct sx1278_phy *phy = hw->priv; dev_dbg(regmap_get_device(phy->map), "interface downn"); phy->suspended = true; del_timer(&phy->timer); sx127X_set_state(phy->map, SX127X_SLEEP_MODE); } Disable timer Make the SX127X transceiver go to sleep
  40. 40. Schedule a work into workqueue in ISR static void sx1278_timer_isr(unsigned long arg) { struct sx1278_phy *phy = (struct sx1278_phy *)arg; schedule_work(&phy->irqwork); } Push the work into workqueue static void sx1278_timer_irqwork(struct work_struct *work) { struct sx1278_phy *phy; phy = container_of(work, struct sx1278_phy, irqwork); sx1278_ieee_statemachine(phy->hw); } Get container structure of work Do polling the SX127X’s state When the work is scheduled to be executing
  41. 41. Do Polling SX127X Transceiver’s State SLEEP TX RXSINGLE Set by command Set by command: sx1278_ieee_xmit register one new frame going to be sent TX is completed / Set by command RX is completed / RX timeout / RX CRC error / Set by command Set by command: sx1278_ieee_rx tries to receive a new frame STANDBY
  42. 42. Do Polling SX127X Transceiver’s State void sx1278_ieee_statemachine(struct ieee802154_hw *hw) { struct sx1278_phy *phy = hw->priv; u8 flags; u8 state; bool do_next_rx = false; flags = sx127X_get_loraallflag(phy->map); state = sx127X_get_state(phy->map); Should be one or composed of: ● SX127X_FLAG_RXTIMEOUT ● SX127X_FLAG_PAYLOADCRCERROR ● SX127X_FLAG_RXDONE ● SX127X_FLAG_TXDONE Should be one of: ● SX127X_SLEEP_MODE ● SX127X_STANDBY_MODE ● SX127X_TX_MODE ● SX127X_RXSINGLE_MODE
  43. 43. if (flags & (SX127X_FLAG_RXTIMEOUT | SX127X_FLAG_PAYLOADCRCERROR)) { sx127X_clear_loraflag(phy->map, SX127X_FLAG_RXTIMEOUT | SX127X_FLAG_PAYLOADCRCERROR | SX127X_FLAG_RXDONE); spin_lock(&phy->buf_lock); phy->is_busy = false; spin_unlock(&phy->buf_lock); do_next_rx = true; } else if (flags & SX127X_FLAG_RXDONE) { sx1278_ieee_rx_complete(phy->hw); sx127X_clear_loraflag(phy->map, SX127X_FLAG_RXDONE); do_next_rx = true; } Check the SX127X transceiver is receiving time out or CRC error Check the SX127X transceiver is already received a new frame
  44. 44. if (flags & SX127X_FLAG_TXDONE) { sx1278_ieee_tx_complete(phy->hw); sx127X_clear_loraflag(phy->map, SX127X_FLAG_TXDONE); phy->tx_delay = 10; do_next_rx = true; } if (phy->one_to_be_sent && (state == SX127X_STANDBY_MODE) && (phy->tx_delay == 0)) { if (!sx1278_ieee_tx(phy->hw)) do_next_rx = false; } Check the SX127X transceiver is already transmit a frame out Check the SX127X transceiver 1. Have a new frame going to be transmit 2. Can try to transmit the new frame a. Is not busy → standby b. Transmit delay is enough
  45. 45. if (do_next_rx) sx1278_ieee_rx(phy->hw); if (phy->tx_delay > 0) phy->tx_delay -= 1; if (!phy->suspended) { phy->timer.expires = jiffies_64 + 1; add_timer(&phy->timer); } } Ask transceiver try to do receiving again, if it is not busy Enable the timer again, if the interface is still enabled Wait for polling SX127X transceiver’s state next time Decrease the counter of transmission delay
  46. 46. Do Polling SX127X Transceiver’s State SLEEP TX RXSINGLE Set by command Set by command in sx1278_ieee_statemachine TX is completed / Set by command RX is completed / RX timeout / RX CRC error / Set by command Set by command: sx1278_ieee_rx tries to receive a new frame STANDBY sx1278_ieee_xmit register a new frame going to be sent
  47. 47. IEEE 802.15.4 Xmit static const struct ieee802154_ops sx1278_ops = { .owner = THIS_MODULE, .xmit_async = sx1278_ieee_xmit, .ed = sx1278_ieee_ed, .set_channel = sx1278_ieee_set_channel, .set_txpower = sx1278_ieee_set_txpower, .start = sx1278_ieee_start, .stop = sx1278_ieee_stop, .set_promiscuous_mode = sx1278_ieee_set_promiscuous_mode, }; ieee802154_tx in IEEE 802.15.4 module
  48. 48. Register a New Frame going to be Sent static int sx1278_ieee_xmit(struct ieee802154_hw *hw, struct sk_buff *skb) { struct sx1278_phy *phy = hw->priv; int ret; ... spin_lock(&phy->buf_lock); if (phy->tx_buf) { ret = -EBUSY; } else { phy->tx_buf = skb; phy->one_to_be_sent = true; phy->post_tx_done = false; ret = 0; } spin_unlock(&phy->buf_lock); return ret; } Check no pending frame going to be sent Register the new frame going to be sent
  49. 49. void sx1278_ieee_statemachine(struct ieee802154_hw *hw) { ... if (flags & SX127X_FLAG_TXDONE) { sx1278_ieee_tx_complete(phy->hw); sx127X_clear_loraflag(phy->map, SX127X_FLAG_TXDONE); phy->tx_delay = 10; do_next_rx = true; } if (phy->one_to_be_sent && (state == SX127X_STANDBY_MODE) && (phy->tx_delay == 0)) { if (!sx1278_ieee_tx(phy->hw)) do_next_rx = false; } ... } Do Xmit a Frame during Polling State
  50. 50. Do Xmit a Frame int sx1278_ieee_tx(struct ieee802154_hw *hw) { struct sx1278_phy *phy = hw->priv; struct sk_buff *tx_buf = phy->tx_buf; bool do_tx = false; … if (!phy->post_tx_done) { sx127X_sendloradata(phy->map, tx_buf->data, tx_buf->len); phy->post_tx_done = true; } Prepare and write the new frame’s data to SX127X transceiver’s TX FIFO
  51. 51. Xmit a Frame after Fill SX127X TX FIFO spin_lock(&phy->buf_lock); if (!phy->is_busy) { phy->is_busy = true; do_tx = true; phy->one_to_be_sent = false; } spin_unlock(&phy->buf_lock); if (do_tx) { /* Set chip as TX state and transfer the data in FIFO. */ phy->opmode = (phy->opmode & 0xF8) | SX127X_TX_MODE; regmap_write_async(phy->map, SX127X_REG_OP_MODE, phy->opmode); return 0; } else { … return -EBUSY; } } Change the SX127X transceiver to TX state and start TX action
  52. 52. TX FIFO of SX127X Transceiver PayloadLength Reference: Semtech SX1276/77/78/79 datasheet, P.34, Figure 8. LoRaTM Data Buffer FifoTxBaseAddr SPI Read/WriteFifoAddrPtr 256 bytes FIFO
  53. 53. Filling SX127X Transceiver’s TX FIFO size_t sx127X_sendloradata(struct regmap *map, u8 *buf, size_t len) { u8 base_adr; u8 blen; /* Set chip FIFO pointer to FIFO TX base. */ base_adr = SX127X_FIFO_TX_BASE_ADDRESS; regmap_raw_write(map, SX127X_REG_FIFO_ADDR_PTR, &base_adr, 1); /* Write payload synchronously to fill the FIFO of the chip. */ blen = (len <= IEEE802154_MTU) ? len : IEEE802154_MTU; regmap_raw_write(map, SX127X_REG_FIFO, buf, blen); /* Set the FIFO payload length. */ regmap_raw_write(map, SX127X_REG_PAYLOAD_LENGTH, &blen, 1); return blen; } Set FIFO address going to write start with Fill TX payload in to FIFO Set TX payload length
  54. 54. void sx1278_ieee_statemachine(struct ieee802154_hw *hw) { ... if (flags & SX127X_FLAG_TXDONE) { sx1278_ieee_tx_complete(phy->hw); sx127X_clear_loraflag(phy->map, SX127X_FLAG_TXDONE); phy->tx_delay = 10; do_next_rx = true; } if (phy->one_to_be_sent && (state == SX127X_STANDBY_MODE) && (phy->tx_delay == 0)) { if (!sx1278_ieee_tx(phy->hw)) do_next_rx = false; } ... } Xmit Finished during Polling State
  55. 55. Response Xmit a Frame is Finished static int sx1278_ieee_tx_complete(struct ieee802154_hw *hw) { struct sx1278_phy *phy = hw->priv; struct sk_buff *skb = phy->tx_buf; dev_dbg(regmap_get_device(phy->map), "%sn", __func__); ieee802154_xmit_complete(hw, skb, false); spin_lock(&phy->buf_lock); phy->is_busy = false; phy->tx_buf = NULL; spin_unlock(&phy->buf_lock); return 0; } Response to IEEE 802.15.4 module that the new frame is already sent
  56. 56. After transmits, transceiver also receives
  57. 57. Do Polling SX127X Transceiver’s State SLEEP TX RXSINGLE Set by command Set by command: sx1278_ieee_xmit register one new frame going to be sent TX is completed / Set by command RX is completed / RX timeout / RX CRC error / Set by command Set by command: sx1278_ieee_rx tries to receive a new frame STANDBY
  58. 58. void sx1278_ieee_statemachine(struct ieee802154_hw *hw) { … if (do_next_rx) sx1278_ieee_rx(phy->hw); ... } Try to Receive during Polling State
  59. 59. Change SX127X to RX Mode int sx1278_ieee_rx(struct ieee802154_hw *hw) { … spin_lock(&phy->buf_lock); if (!phy->is_busy) { phy->is_busy = true; do_rx = true; } else { do_rx = false; } spin_unlock(&phy->buf_lock); if (do_rx) { sx127X_set_state(phy->map, SX127X_RXSINGLE_MODE); return 0; } else { … return -EBUSY; } } Change the SX127X transceiver to RX state and try to receive only one frame
  60. 60. Do Receive during Polling State void sx1278_ieee_statemachine(struct ieee802154_hw *hw) { … if (flags & (SX127X_FLAG_RXTIMEOUT | SX127X_FLAG_PAYLOADCRCERROR)) { ... } else if (flags & SX127X_FLAG_RXDONE) { sx1278_ieee_rx_complete(phy->hw); sx127X_clear_loraflag(phy->map, SX127X_FLAG_RXDONE); do_next_rx = true; } ... }
  61. 61. RX FIFO of SX127X Transceiver LoRa Modem RegFifoRxCurrentAddr FifoRxBytesNb PayloadLength FifoRxBaseAddr Reference: Semtech SX1276/77/78/79 datasheet, P.34, Figure 8. LoRaTM Data Buffer FifoTxBaseAddr SPI Read/Write FifoAddrPtr 256 bytes FIFO
  62. 62. Do Receive a New Incoming Frame static int sx1278_ieee_rx_complete(struct ieee802154_hw *hw) { struct sx1278_phy *phy = hw->priv; struct sk_buff *skb; … s32 rssi; s32 range = SX1278_IEEE_ENERGY_RANGE; … skb = dev_alloc_skb(IEEE802154_MTU); … len = sx127X_get_loralastpktpayloadlen(phy->map); sx127X_readloradata(phy->map, skb_put(skb, len), len); /* LQI: IEEE 802.15.4-2011 8.2.6 Link quality indicator. */ rssi = sx127X_get_loralastpktrssi(phy->map); rssi = (rssi > 0) ? 0 : rssi; lqi = ((s32)255 * (rssi + range) / range) % 255; ieee802154_rx_irqsafe(hw, skb, lqi); ... } Allocate a sk_buff to hold a new coming frame Get last packet’s payload length Read last RX packet as the new coming frame Calculate the link quality indicator Tell IEEE 802.15.4 module that there is a new incoming frame
  63. 63. Reading SX127X Transceiver’s RX FIFO ssize_t sx127X_readloradata(struct regmap *map, u8 *buf, size_t len) { u8 start_adr; int ret; /* Set chip FIFO pointer to FIFO last packet address. */ start_adr = SX127X_FIFO_RX_BASE_ADDRESS; regmap_raw_write(map, SX127X_REG_FIFO_ADDR_PTR, &start_adr, 1); /* Read LoRa packet payload. */ len = (len <= IEEE802154_MTU) ? len : IEEE802154_MTU; ret = regmap_raw_read(map, SX127X_REG_FIFO, buf, len); return (ret >= 0) ? len : ret; } Set FIFO address going to read start with Read a received payload from RX FIFO
  64. 64. Do Polling SX127X Transceiver’s State SLEEP TX RXSINGLE Set by command Set by command: sx1278_ieee_xmit register one new frame going to be sent TX is completed / Set by command RX is completed / RX timeout / RX CRC error / Set by command Set by command: sx1278_ieee_rx tries to receive a new frame STANDBY
  65. 65. Load SX1278 as an SPI protocol driver with Device Tree configuration
  66. 66. Device Tree Overlay Example sx1278@0 { compatible = "semtech,sx1278"; spi-max-frequency = <15200>; reg = <0>; clock-frequency = <32000000>; center-carrier-frq = <434000000>; minimal-RF-channel = /bits/ 8 <11>; maximum-RF-channel = /bits/ 8 <11>; };
  67. 67. SX1278 Device Tree Properties ● Required properties: ○ compatible: should be "semtech,sx1276", "semtech,sx1277", "semtech,sx1278" or "semtech,sx1279" depends on your transceiver board ○ spi-max-frequency: maximal bus speed, should be set something under or equal 10000000 Hz ○ reg: the chipselect index ○ clock-frequency: the external crystal oscillator frequency in Hz of the transceiver ○ center-carrier-frq: the RF center carrier frequency in Hz ● Optional properties: ○ rf-bandwidth: the RF bandwidth in Hz ○ minimal-RF-channel: the minimal RF channel number ○ maximum-RF-channel: the maximum RF channel number ○ spreading-factor: the spreading factor of Chirp Spread Spectrum modulation
  68. 68. Have test applications over 6LoWPAN over SX1278
  69. 69. Client - Server Test Application These applications communicate through UDP/IPv6 socket in simple client-server model. Client Server Client send a data string to server Server send the capitalized data string to client Capitalized data string
  70. 70. 6LoWPAN module & SX1278 driver Application ClientPresentation Session Transport UDP Network IPv6 MAC Layer IEEE 802.15.4 MAC PHY Layer LoRa Server UDP IPv6 IEEE 802.15.4 MAC LoRa SX1278 driver 6LoWPAN module socket
  71. 71. Have lowpan interface from wpan # Private Area Network ID panid="0xbeef" # Index of the wpan interface i=0 # Set the PANID of the wpan interface iwpan dev wpan${i} set pan_id $panid # Create a lowpan interface over the wpan interface ip link add link wpan${i} name lowpan${i} type lowpan # Bring up the wpan and lowpan interfaces ip link set wpan${i} up ip link set lowpan${i} up linux-wpan/wpan-tools: Userspace tools for Linux IEEE 802.15.4 stack iwpan: based on the wireless iw tool.
  72. 72. ● Server ○ server <listening IPv6 address> <listening port> ● Client ○ client <src IPv6 address> <dst IPv6 address> <dst port> <data string>
  73. 73. Hardware for Demo LoRa Transceiver SX1276 SPI LoRa Transceiver SX1276 SPI Main Board Raspberry Pi SPI_CE0 SPI_CE1 SPI BUS
  74. 74. Summary ● LoRa is a Low Power Wide Area Network(LPWAN) communitcation technology. ● Here is an IEEE 802.15.4 MAC over LoRa PHY Linux device driver. ● Pros ○ 6LoWPAN support for IEEE 802.15.4 → IPv6 for each node ○ Extending the coverage area by cluster tree network with the LoRa long communication distance of each edge is possible ● Cons ○ Extremely low data rate ○ As an external kernel module, because it is not LoRaWAN over LoRa
  75. 75. Reference ● LoRaWAN™ What is it? ● LoRaWAN™ Specification V1.0.2 from LoRa™ Alliance ● Wikipedia - LPWAN ● IEEE Std 802.15.4-2015 from IEEE ● Wikipedia - IEEE 802.15.4 ● Semtech SX1276/77/78/79 datasheet ● Linux IEEE 802.15.4 Documentation ● Loopback IEEE 802.15.4 interface: fakelb.c
  76. 76. Thank you ~ Q & A

×