Region.h 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697
  1. /*!
  2. * \file Region.h
  3. *
  4. * \brief Region implementation.
  5. *
  6. * \copyright Revised BSD License, see section \ref LICENSE.
  7. *
  8. * \code
  9. * ______ _
  10. * / _____) _ | |
  11. * ( (____ _____ ____ _| |_ _____ ____| |__
  12. * \____ \| ___ | (_ _) ___ |/ ___) _ \
  13. * _____) ) ____| | | || |_| ____( (___| | | |
  14. * (______/|_____)_|_|_| \__)_____)\____)_| |_|
  15. * (C)2013-2017 Semtech
  16. *
  17. * ___ _____ _ ___ _ _____ ___ ___ ___ ___
  18. * / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __|
  19. * \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _|
  20. * |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___|
  21. * embedded.connectivity.solutions===============
  22. *
  23. * \endcode
  24. *
  25. * \author Miguel Luis ( Semtech )
  26. *
  27. * \author Gregory Cristian ( Semtech )
  28. *
  29. * \author Daniel Jaeckle ( STACKFORCE )
  30. *
  31. * \defgroup REGION Region implementation
  32. * This is the common API to access the specific
  33. * regional implementations.
  34. *
  35. * Preprocessor options:
  36. * - LoRaWAN regions can be activated by defining the related preprocessor
  37. * definition. It is possible to define more than one region.
  38. * The following regions are supported:
  39. * - #define REGION_AS923
  40. * - #define REGION_AU915
  41. * - #define REGION_CN470
  42. * - #define REGION_CN779
  43. * - #define REGION_EU433
  44. * - #define REGION_EU868
  45. * - #define REGION_KR920
  46. * - #define REGION_IN865
  47. * - #define REGION_US915
  48. * - #define REGION_RU864
  49. *
  50. * \{
  51. */
  52. #ifndef __REGION_H__
  53. #define __REGION_H__
  54. #ifdef __cplusplus
  55. extern "C"
  56. {
  57. #endif
  58. #include <stdint.h>
  59. #include <stdbool.h>
  60. #include "utilities.h"
  61. #include "LoRaMac.h"
  62. #include "lora-radio-timer.h"
  63. /*!
  64. * Macro to compute bit of a channel index.
  65. */
  66. #define LC( channelIndex ) ( uint16_t )( 1 << ( channelIndex - 1 ) )
  67. /*!
  68. * Region | SF
  69. * ------------ | :-----:
  70. * AS923 | SF12 - BW125
  71. * AU915 | SF10 - BW125
  72. * CN470 | SF12 - BW125
  73. * CN779 | SF12 - BW125
  74. * EU433 | SF12 - BW125
  75. * EU868 | SF12 - BW125
  76. * IN865 | SF12 - BW125
  77. * KR920 | SF12 - BW125
  78. * US915 | SF10 - BW125
  79. * RU864 | SF12 - BW125
  80. */
  81. #define DR_0 0
  82. /*!
  83. * Region | SF
  84. * ------------ | :-----:
  85. * AS923 | SF11 - BW125
  86. * AU915 | SF9 - BW125
  87. * CN470 | SF11 - BW125
  88. * CN779 | SF11 - BW125
  89. * EU433 | SF11 - BW125
  90. * EU868 | SF11 - BW125
  91. * IN865 | SF11 - BW125
  92. * KR920 | SF11 - BW125
  93. * US915 | SF9 - BW125
  94. * RU864 | SF11 - BW125
  95. */
  96. #define DR_1 1
  97. /*!
  98. * Region | SF
  99. * ------------ | :-----:
  100. * AS923 | SF10 - BW125
  101. * AU915 | SF8 - BW125
  102. * CN470 | SF10 - BW125
  103. * CN779 | SF10 - BW125
  104. * EU433 | SF10 - BW125
  105. * EU868 | SF10 - BW125
  106. * IN865 | SF10 - BW125
  107. * KR920 | SF10 - BW125
  108. * US915 | SF8 - BW125
  109. * RU864 | SF10 - BW125
  110. */
  111. #define DR_2 2
  112. /*!
  113. * Region | SF
  114. * ------------ | :-----:
  115. * AS923 | SF9 - BW125
  116. * AU915 | SF7 - BW125
  117. * CN470 | SF9 - BW125
  118. * CN779 | SF9 - BW125
  119. * EU433 | SF9 - BW125
  120. * EU868 | SF9 - BW125
  121. * IN865 | SF9 - BW125
  122. * KR920 | SF9 - BW125
  123. * US915 | SF7 - BW125
  124. * RU864 | SF9 - BW125
  125. */
  126. #define DR_3 3
  127. /*!
  128. * Region | SF
  129. * ------------ | :-----:
  130. * AS923 | SF8 - BW125
  131. * AU915 | SF8 - BW500
  132. * CN470 | SF8 - BW125
  133. * CN779 | SF8 - BW125
  134. * EU433 | SF8 - BW125
  135. * EU868 | SF8 - BW125
  136. * IN865 | SF8 - BW125
  137. * KR920 | SF8 - BW125
  138. * US915 | SF8 - BW500
  139. * RU864 | SF8 - BW125
  140. */
  141. #define DR_4 4
  142. /*!
  143. * Region | SF
  144. * ------------ | :-----:
  145. * AS923 | SF7 - BW125
  146. * AU915 | RFU
  147. * CN470 | SF7 - BW125
  148. * CN779 | SF7 - BW125
  149. * EU433 | SF7 - BW125
  150. * EU868 | SF7 - BW125
  151. * IN865 | SF7 - BW125
  152. * KR920 | SF7 - BW125
  153. * US915 | RFU
  154. * RU864 | SF7 - BW125
  155. */
  156. #define DR_5 5
  157. /*!
  158. * Region | SF
  159. * ------------ | :-----:
  160. * AS923 | SF7 - BW250
  161. * AU915 | RFU
  162. * CN470 | SF12 - BW125
  163. * CN779 | SF7 - BW250
  164. * EU433 | SF7 - BW250
  165. * EU868 | SF7 - BW250
  166. * IN865 | SF7 - BW250
  167. * KR920 | RFU
  168. * US915 | RFU
  169. * RU864 | SF7 - BW250
  170. */
  171. #define DR_6 6
  172. /*!
  173. * Region | SF
  174. * ------------ | :-----:
  175. * AS923 | FSK
  176. * AU915 | RFU
  177. * CN470 | SF12 - BW125
  178. * CN779 | FSK
  179. * EU433 | FSK
  180. * EU868 | FSK
  181. * IN865 | FSK
  182. * KR920 | RFU
  183. * US915 | RFU
  184. * RU864 | FSK
  185. */
  186. #define DR_7 7
  187. /*!
  188. * Region | SF
  189. * ------------ | :-----:
  190. * AS923 | RFU
  191. * AU915 | SF12 - BW500
  192. * CN470 | RFU
  193. * CN779 | RFU
  194. * EU433 | RFU
  195. * EU868 | RFU
  196. * IN865 | RFU
  197. * KR920 | RFU
  198. * US915 | SF12 - BW500
  199. * RU864 | RFU
  200. */
  201. #define DR_8 8
  202. /*!
  203. * Region | SF
  204. * ------------ | :-----:
  205. * AS923 | RFU
  206. * AU915 | SF11 - BW500
  207. * CN470 | RFU
  208. * CN779 | RFU
  209. * EU433 | RFU
  210. * EU868 | RFU
  211. * IN865 | RFU
  212. * KR920 | RFU
  213. * US915 | SF11 - BW500
  214. * RU864 | RFU
  215. */
  216. #define DR_9 9
  217. /*!
  218. * Region | SF
  219. * ------------ | :-----:
  220. * AS923 | RFU
  221. * AU915 | SF10 - BW500
  222. * CN470 | RFU
  223. * CN779 | RFU
  224. * EU433 | RFU
  225. * EU868 | RFU
  226. * IN865 | RFU
  227. * KR920 | RFU
  228. * US915 | SF10 - BW500
  229. * RU864 | RFU
  230. */
  231. #define DR_10 10
  232. /*!
  233. * Region | SF
  234. * ------------ | :-----:
  235. * AS923 | RFU
  236. * AU915 | SF9 - BW500
  237. * CN470 | RFU
  238. * CN779 | RFU
  239. * EU433 | RFU
  240. * EU868 | RFU
  241. * IN865 | RFU
  242. * KR920 | RFU
  243. * US915 | SF9 - BW500
  244. * RU864 | RFU
  245. */
  246. #define DR_11 11
  247. /*!
  248. * Region | SF
  249. * ------------ | :-----:
  250. * AS923 | RFU
  251. * AU915 | SF8 - BW500
  252. * CN470 | RFU
  253. * CN779 | RFU
  254. * EU433 | RFU
  255. * EU868 | RFU
  256. * IN865 | RFU
  257. * KR920 | RFU
  258. * US915 | SF8 - BW500
  259. * RU864 | RFU
  260. */
  261. #define DR_12 12
  262. /*!
  263. * Region | SF
  264. * ------------ | :-----:
  265. * AS923 | RFU
  266. * AU915 | SF7 - BW500
  267. * CN470 | RFU
  268. * CN779 | RFU
  269. * EU433 | RFU
  270. * EU868 | RFU
  271. * IN865 | RFU
  272. * KR920 | RFU
  273. * US915 | SF7 - BW500
  274. * RU864 | RFU
  275. */
  276. #define DR_13 13
  277. /*!
  278. * Region | SF
  279. * ------------ | :-----:
  280. * AS923 | RFU
  281. * AU915 | RFU
  282. * CN470 | RFU
  283. * CN779 | RFU
  284. * EU433 | RFU
  285. * EU868 | RFU
  286. * IN865 | RFU
  287. * KR920 | RFU
  288. * US915 | RFU
  289. * RU864 | RFU
  290. */
  291. #define DR_14 14
  292. /*!
  293. * Region | SF
  294. * ------------ | :-----:
  295. * AS923 | RFU
  296. * AU915 | RFU
  297. * CN470 | RFU
  298. * CN779 | RFU
  299. * EU433 | RFU
  300. * EU868 | RFU
  301. * IN865 | RFU
  302. * KR920 | RFU
  303. * US915 | RFU
  304. * RU864 | RFU
  305. */
  306. #define DR_15 15
  307. /*!
  308. * Region | dBM
  309. * ------------ | :-----:
  310. * AS923 | Max EIRP
  311. * AU915 | Max EIRP
  312. * CN470 | Max EIRP
  313. * CN779 | Max EIRP
  314. * EU433 | Max EIRP
  315. * EU868 | Max EIRP
  316. * IN865 | Max EIRP
  317. * KR920 | Max EIRP
  318. * US915 | Max ERP
  319. * RU864 | Max EIRP
  320. */
  321. #define TX_POWER_0 0
  322. /*!
  323. * Region | dBM
  324. * ------------ | :-----:
  325. * AS923 | Max EIRP - 2
  326. * AU915 | Max EIRP - 2
  327. * CN470 | Max EIRP - 2
  328. * CN779 | Max EIRP - 2
  329. * EU433 | Max EIRP - 2
  330. * EU868 | Max EIRP - 2
  331. * IN865 | Max EIRP - 2
  332. * KR920 | Max EIRP - 2
  333. * US915 | Max ERP - 2
  334. * RU864 | Max EIRP - 2
  335. */
  336. #define TX_POWER_1 1
  337. /*!
  338. * Region | dBM
  339. * ------------ | :-----:
  340. * AS923 | Max EIRP - 4
  341. * AU915 | Max EIRP - 4
  342. * CN470 | Max EIRP - 4
  343. * CN779 | Max EIRP - 4
  344. * EU433 | Max EIRP - 4
  345. * EU868 | Max EIRP - 4
  346. * IN865 | Max EIRP - 4
  347. * KR920 | Max EIRP - 4
  348. * US915 | Max ERP - 4
  349. * RU864 | Max EIRP - 4
  350. */
  351. #define TX_POWER_2 2
  352. /*!
  353. * Region | dBM
  354. * ------------ | :-----:
  355. * AS923 | Max EIRP - 6
  356. * AU915 | Max EIRP - 6
  357. * CN470 | Max EIRP - 6
  358. * CN779 | Max EIRP - 6
  359. * EU433 | Max EIRP - 6
  360. * EU868 | Max EIRP - 6
  361. * IN865 | Max EIRP - 6
  362. * KR920 | Max EIRP - 6
  363. * US915 | Max ERP - 6
  364. * RU864 | Max EIRP - 6
  365. */
  366. #define TX_POWER_3 3
  367. /*!
  368. * Region | dBM
  369. * ------------ | :-----:
  370. * AS923 | Max EIRP - 8
  371. * AU915 | Max EIRP - 8
  372. * CN470 | Max EIRP - 8
  373. * CN779 | Max EIRP - 8
  374. * EU433 | Max EIRP - 8
  375. * EU868 | Max EIRP - 8
  376. * IN865 | Max EIRP - 8
  377. * KR920 | Max EIRP - 8
  378. * US915 | Max ERP - 8
  379. * RU864 | Max EIRP - 8
  380. */
  381. #define TX_POWER_4 4
  382. /*!
  383. * Region | dBM
  384. * ------------ | :-----:
  385. * AS923 | Max EIRP - 10
  386. * AU915 | Max EIRP - 10
  387. * CN470 | Max EIRP - 10
  388. * CN779 | Max EIRP - 10
  389. * EU433 | Max EIRP - 10
  390. * EU868 | Max EIRP - 10
  391. * IN865 | Max EIRP - 10
  392. * KR920 | Max EIRP - 10
  393. * US915 | Max ERP - 10
  394. * RU864 | Max EIRP - 10
  395. */
  396. #define TX_POWER_5 5
  397. /*!
  398. * Region | dBM
  399. * ------------ | :-----:
  400. * AS923 | Max EIRP - 12
  401. * AU915 | Max EIRP - 12
  402. * CN470 | Max EIRP - 12
  403. * CN779 | -
  404. * EU433 | -
  405. * EU868 | Max EIRP - 12
  406. * IN865 | Max EIRP - 12
  407. * KR920 | Max EIRP - 12
  408. * US915 | Max ERP - 12
  409. * RU864 | Max EIRP - 12
  410. */
  411. #define TX_POWER_6 6
  412. /*!
  413. * Region | dBM
  414. * ------------ | :-----:
  415. * AS923 | Max EIRP - 14
  416. * AU915 | Max EIRP - 14
  417. * CN470 | Max EIRP - 14
  418. * CN779 | -
  419. * EU433 | -
  420. * EU868 | Max EIRP - 14
  421. * IN865 | Max EIRP - 14
  422. * KR920 | Max EIRP - 14
  423. * US915 | Max ERP - 14
  424. * RU864 | Max EIRP - 14
  425. */
  426. #define TX_POWER_7 7
  427. /*!
  428. * Region | dBM
  429. * ------------ | :-----:
  430. * AS923 | -
  431. * AU915 | Max EIRP - 16
  432. * CN470 | -
  433. * CN779 | -
  434. * EU433 | -
  435. * EU868 | -
  436. * IN865 | Max EIRP - 16
  437. * KR920 | -
  438. * US915 | Max ERP - 16
  439. * RU864 | -
  440. */
  441. #define TX_POWER_8 8
  442. /*!
  443. * Region | dBM
  444. * ------------ | :-----:
  445. * AS923 | -
  446. * AU915 | Max EIRP - 18
  447. * CN470 | -
  448. * CN779 | -
  449. * EU433 | -
  450. * EU868 | -
  451. * IN865 | Max EIRP - 18
  452. * KR920 | -
  453. * US915 | Max ERP - 18
  454. * RU864 | -
  455. */
  456. #define TX_POWER_9 9
  457. /*!
  458. * Region | dBM
  459. * ------------ | :-----:
  460. * AS923 | -
  461. * AU915 | Max EIRP - 20
  462. * CN470 | -
  463. * CN779 | -
  464. * EU433 | -
  465. * EU868 | -
  466. * IN865 | Max EIRP - 20
  467. * KR920 | -
  468. * US915 | Max ERP - 20
  469. * RU864 | -
  470. */
  471. #define TX_POWER_10 10
  472. /*!
  473. * Region | dBM
  474. * ------------ | :-----:
  475. * AS923 | -
  476. * AU915 | Max EIRP - 22
  477. * CN470 | -
  478. * CN779 | -
  479. * EU433 | -
  480. * EU868 | -
  481. * IN865 | -
  482. * KR920 | -
  483. * US915 | Max ERP - 22
  484. * RU864 | -
  485. */
  486. #define TX_POWER_11 11
  487. /*!
  488. * Region | dBM
  489. * ------------ | :-----:
  490. * AS923 | -
  491. * AU915 | Max EIRP - 24
  492. * CN470 | -
  493. * CN779 | -
  494. * EU433 | -
  495. * EU868 | -
  496. * IN865 | -
  497. * KR920 | -
  498. * US915 | Max ERP - 24
  499. * RU864 | -
  500. */
  501. #define TX_POWER_12 12
  502. /*!
  503. * Region | dBM
  504. * ------------ | :-----:
  505. * AS923 | -
  506. * AU915 | Max EIRP - 26
  507. * CN470 | -
  508. * CN779 | -
  509. * EU433 | -
  510. * EU868 | -
  511. * IN865 | -
  512. * KR920 | -
  513. * US915 | Max ERP - 26
  514. * RU864 | -
  515. */
  516. #define TX_POWER_13 13
  517. /*!
  518. * Region | dBM
  519. * ------------ | :-----:
  520. * AS923 | -
  521. * AU915 | Max EIRP - 28
  522. * CN470 | -
  523. * CN779 | -
  524. * EU433 | -
  525. * EU868 | -
  526. * IN865 | -
  527. * KR920 | -
  528. * US915 | Max ERP - 28
  529. * RU864 | -
  530. */
  531. #define TX_POWER_14 14
  532. /*!
  533. * RFU
  534. */
  535. #define TX_POWER_15 15
  536. /*!
  537. * Enumeration of phy attributes.
  538. */
  539. typedef enum ePhyAttribute
  540. {
  541. /*!
  542. * Frequency. It is available
  543. * to perform a verification with RegionVerify().
  544. */
  545. PHY_FREQUENCY,
  546. /*!
  547. * Minimum RX datarate.
  548. */
  549. PHY_MIN_RX_DR,
  550. /*!
  551. * Minimum TX datarate.
  552. */
  553. PHY_MIN_TX_DR,
  554. /*!
  555. * Maximum RX datarate.
  556. */
  557. PHY_MAX_RX_DR,
  558. /*!
  559. * Maximum TX datarate.
  560. */
  561. PHY_MAX_TX_DR,
  562. /*!
  563. * TX datarate.
  564. * This is a parameter which can't be queried. It is available
  565. * to perform a verification with RegionVerify().
  566. */
  567. PHY_TX_DR,
  568. /*!
  569. * Default TX datarate.
  570. */
  571. PHY_DEF_TX_DR,
  572. /*!
  573. * RX datarate. It is available
  574. * to perform a verification with RegionVerify().
  575. */
  576. PHY_RX_DR,
  577. /*!
  578. * Maximum TX power.
  579. */
  580. PHY_MAX_TX_POWER,
  581. /*!
  582. * TX power. It is available
  583. * to perform a verification with RegionVerify().
  584. */
  585. PHY_TX_POWER,
  586. /*!
  587. * Default TX power.
  588. */
  589. PHY_DEF_TX_POWER,
  590. /*!
  591. * Default ADR_ACK_LIMIT value.
  592. */
  593. PHY_DEF_ADR_ACK_LIMIT,
  594. /*!
  595. * Default ADR_ACK_DELAY value.
  596. */
  597. PHY_DEF_ADR_ACK_DELAY,
  598. /*!
  599. * Maximum payload possible.
  600. */
  601. PHY_MAX_PAYLOAD,
  602. /*!
  603. * Maximum payload possible when repeater support is enabled.
  604. */
  605. PHY_MAX_PAYLOAD_REPEATER,
  606. /*!
  607. * Duty cycle.
  608. */
  609. PHY_DUTY_CYCLE,
  610. /*!
  611. * Maximum receive window duration.
  612. */
  613. PHY_MAX_RX_WINDOW,
  614. /*!
  615. * Receive delay for window 1.
  616. */
  617. PHY_RECEIVE_DELAY1,
  618. /*!
  619. * Receive delay for window 2.
  620. */
  621. PHY_RECEIVE_DELAY2,
  622. /*!
  623. * Join accept delay for window 1.
  624. */
  625. PHY_JOIN_ACCEPT_DELAY1,
  626. /*!
  627. * Join accept delay for window 2.
  628. */
  629. PHY_JOIN_ACCEPT_DELAY2,
  630. /*!
  631. * Maximum frame counter gap.
  632. */
  633. PHY_MAX_FCNT_GAP,
  634. /*!
  635. * Acknowledgement time out.
  636. */
  637. PHY_ACK_TIMEOUT,
  638. /*!
  639. * Default datarate offset for window 1.
  640. */
  641. PHY_DEF_DR1_OFFSET,
  642. /*!
  643. * Default receive window 2 frequency.
  644. */
  645. PHY_DEF_RX2_FREQUENCY,
  646. /*!
  647. * Default receive window 2 datarate.
  648. */
  649. PHY_DEF_RX2_DR,
  650. /*!
  651. * Channels mask.
  652. */
  653. PHY_CHANNELS_MASK,
  654. /*!
  655. * Channels default mask.
  656. */
  657. PHY_CHANNELS_DEFAULT_MASK,
  658. /*!
  659. * Maximum number of supported channels
  660. */
  661. PHY_MAX_NB_CHANNELS,
  662. /*!
  663. * Channels.
  664. */
  665. PHY_CHANNELS,
  666. /*!
  667. * Default value of the uplink dwell time.
  668. */
  669. PHY_DEF_UPLINK_DWELL_TIME,
  670. /*!
  671. * Default value of the downlink dwell time.
  672. */
  673. PHY_DEF_DOWNLINK_DWELL_TIME,
  674. /*!
  675. * Default value of the MaxEIRP.
  676. */
  677. PHY_DEF_MAX_EIRP,
  678. /*!
  679. * Default value of the antenna gain.
  680. */
  681. PHY_DEF_ANTENNA_GAIN,
  682. /*!
  683. * Next lower datarate.
  684. */
  685. PHY_NEXT_LOWER_TX_DR,
  686. /*!
  687. * Beacon interval in ms.
  688. */
  689. PHY_BEACON_INTERVAL,
  690. /*!
  691. * Beacon reserved time in ms.
  692. */
  693. PHY_BEACON_RESERVED,
  694. /*!
  695. * Beacon guard time in ms.
  696. */
  697. PHY_BEACON_GUARD,
  698. /*!
  699. * Beacon window time in ms.
  700. */
  701. PHY_BEACON_WINDOW,
  702. /*!
  703. * Beacon window time in numer of slots.
  704. */
  705. PHY_BEACON_WINDOW_SLOTS,
  706. /*!
  707. * Ping slot length time in ms.
  708. */
  709. PHY_PING_SLOT_WINDOW,
  710. /*!
  711. * Default symbol timeout for beacons and ping slot windows.
  712. */
  713. PHY_BEACON_SYMBOL_TO_DEFAULT,
  714. /*!
  715. * Maximum symbol timeout for beacons.
  716. */
  717. PHY_BEACON_SYMBOL_TO_EXPANSION_MAX,
  718. /*!
  719. * Maximum symbol timeout for ping slots.
  720. */
  721. PHY_PING_SLOT_SYMBOL_TO_EXPANSION_MAX,
  722. /*!
  723. * Symbol expansion value for beacon windows in case of beacon
  724. * loss in symbols.
  725. */
  726. PHY_BEACON_SYMBOL_TO_EXPANSION_FACTOR,
  727. /*!
  728. * Symbol expansion value for ping slot windows in case of beacon
  729. * loss in symbols.
  730. */
  731. PHY_PING_SLOT_SYMBOL_TO_EXPANSION_FACTOR,
  732. /*!
  733. * Maximum allowed beacon less time in ms.
  734. */
  735. PHY_MAX_BEACON_LESS_PERIOD,
  736. /*!
  737. * Delay time for the BeaconTimingAns in ms.
  738. */
  739. PHY_BEACON_DELAY_BEACON_TIMING_ANS,
  740. /*!
  741. * Beacon channel frequency.
  742. */
  743. PHY_BEACON_CHANNEL_FREQ,
  744. /*!
  745. * The format of the beacon.
  746. */
  747. PHY_BEACON_FORMAT,
  748. /*!
  749. * The beacon channel datarate.
  750. */
  751. PHY_BEACON_CHANNEL_DR,
  752. /*!
  753. * The frequency stepwidth between the beacon channels.
  754. */
  755. PHY_BEACON_CHANNEL_STEPWIDTH,
  756. /*!
  757. * The number of channels for the beacon reception.
  758. */
  759. PHY_BEACON_NB_CHANNELS,
  760. /*!
  761. * The datarate of a ping slot channel.
  762. */
  763. PHY_PING_SLOT_CHANNEL_DR
  764. }PhyAttribute_t;
  765. /*!
  766. * Enumeration of initialization types.
  767. */
  768. typedef enum eInitType
  769. {
  770. /*!
  771. * Initializes the region specific data to defaults, according to the
  772. * LoRaWAN specification.
  773. */
  774. INIT_TYPE_INIT,
  775. /*!
  776. * Restores default channels defined by the LoRaWAN specification only.
  777. */
  778. INIT_TYPE_RESTORE_DEFAULT_CHANNELS,
  779. /*!
  780. * Restores internal context from passed pointer.
  781. */
  782. INIT_TYPE_RESTORE_CTX
  783. }InitType_t;
  784. typedef enum eChannelsMask
  785. {
  786. /*!
  787. * The channels mask.
  788. */
  789. CHANNELS_MASK,
  790. /*!
  791. * The channels default mask.
  792. */
  793. CHANNELS_DEFAULT_MASK
  794. }ChannelsMask_t;
  795. /*!
  796. * Structure containing the beacon format
  797. */
  798. typedef struct sBeaconFormat
  799. {
  800. /*!
  801. * Size of the beacon
  802. */
  803. uint8_t BeaconSize;
  804. /*!
  805. * Size of the RFU 1 data field
  806. */
  807. uint8_t Rfu1Size;
  808. /*!
  809. * Size of the RFU 2 data field
  810. */
  811. uint8_t Rfu2Size;
  812. }BeaconFormat_t;
  813. /*!
  814. * Union for the structure uGetPhyParams
  815. */
  816. typedef union uPhyParam
  817. {
  818. /*!
  819. * A parameter value.
  820. */
  821. uint32_t Value;
  822. /*!
  823. * A floating point value.
  824. */
  825. float fValue;
  826. /*!
  827. * Pointer to the channels mask.
  828. */
  829. uint16_t* ChannelsMask;
  830. /*!
  831. * Pointer to the channels.
  832. */
  833. ChannelParams_t* Channels;
  834. /*!
  835. * Beacon format
  836. */
  837. BeaconFormat_t BeaconFormat;
  838. }PhyParam_t;
  839. /*!
  840. * Parameter structure for the function RegionGetPhyParam.
  841. */
  842. typedef struct sGetPhyParams
  843. {
  844. /*!
  845. * Setup the parameter to get.
  846. */
  847. PhyAttribute_t Attribute;
  848. /*!
  849. * Datarate.
  850. * The parameter is needed for the following queries:
  851. * PHY_MAX_PAYLOAD, PHY_MAX_PAYLOAD_REPEATER, PHY_NEXT_LOWER_TX_DR.
  852. */
  853. int8_t Datarate;
  854. /*!
  855. * Uplink dwell time. This parameter must be set to query:
  856. * PHY_MAX_PAYLOAD, PHY_MAX_PAYLOAD_REPEATER, PHY_MIN_TX_DR.
  857. * The parameter is needed for the following queries:
  858. * PHY_MIN_TX_DR, PHY_MAX_PAYLOAD, PHY_MAX_PAYLOAD_REPEATER, PHY_NEXT_LOWER_TX_DR.
  859. */
  860. uint8_t UplinkDwellTime;
  861. /*!
  862. * Downlink dwell time. This parameter must be set to query:
  863. * PHY_MAX_PAYLOAD, PHY_MAX_PAYLOAD_REPEATER, PHY_MIN_RX_DR.
  864. * The parameter is needed for the following queries:
  865. * PHY_MIN_RX_DR, PHY_MAX_PAYLOAD, PHY_MAX_PAYLOAD_REPEATER.
  866. */
  867. uint8_t DownlinkDwellTime;
  868. }GetPhyParams_t;
  869. /*!
  870. * Parameter structure for the function RegionSetBandTxDone.
  871. */
  872. typedef struct sSetBandTxDoneParams
  873. {
  874. /*!
  875. * Channel to update.
  876. */
  877. uint8_t Channel;
  878. /*!
  879. * Joined Set to true, if the node has joined the network
  880. */
  881. bool Joined;
  882. /*!
  883. * Last TX done time.
  884. */
  885. TimerTime_t LastTxDoneTime;
  886. }SetBandTxDoneParams_t;
  887. /*!
  888. * Parameter structure for the function RegionInitDefaults.
  889. */
  890. typedef struct sInitDefaultsParams
  891. {
  892. /*!
  893. * Pointer to region module context to be restored.
  894. */
  895. void* NvmCtx;
  896. /*!
  897. * Sets the initialization type.
  898. */
  899. InitType_t Type;
  900. }InitDefaultsParams_t;
  901. /*!
  902. * Parameter structure for the function RegionGetNvmCtx.
  903. */
  904. typedef struct sGetNvmCtxParams
  905. {
  906. /*!
  907. * Size of module context.
  908. */
  909. size_t nvmCtxSize;
  910. }GetNvmCtxParams_t;
  911. /*!
  912. * Parameter structure for the function RegionVerify.
  913. */
  914. typedef union uVerifyParams
  915. {
  916. /*!
  917. * Channel frequency to verify
  918. */
  919. uint32_t Frequency;
  920. /*!
  921. * TX power to verify.
  922. */
  923. int8_t TxPower;
  924. /*!
  925. * Set to true, if the duty cycle is enabled, otherwise false.
  926. */
  927. bool DutyCycle;
  928. /*!
  929. * Datarate to verify.
  930. */
  931. struct sDatarateParams
  932. {
  933. /*!
  934. * Datarate to verify.
  935. */
  936. int8_t Datarate;
  937. /*!
  938. * The downlink dwell time.
  939. */
  940. uint8_t DownlinkDwellTime;
  941. /*!
  942. * The up link dwell time.
  943. */
  944. uint8_t UplinkDwellTime;
  945. }DatarateParams;
  946. }VerifyParams_t;
  947. /*!
  948. * Parameter structure for the function RegionApplyCFList.
  949. */
  950. typedef struct sApplyCFListParams
  951. {
  952. /*!
  953. * Payload which contains the CF list.
  954. */
  955. uint8_t* Payload;
  956. /*!
  957. * Size of the payload.
  958. */
  959. uint8_t Size;
  960. }ApplyCFListParams_t;
  961. /*!
  962. * Parameter structure for the function RegionChanMaskSet.
  963. */
  964. typedef struct sChanMaskSetParams
  965. {
  966. /*!
  967. * Pointer to the channels mask which should be set.
  968. */
  969. uint16_t* ChannelsMaskIn;
  970. /*!
  971. * Pointer to the channels mask which should be set.
  972. */
  973. ChannelsMask_t ChannelsMaskType;
  974. }ChanMaskSetParams_t;
  975. /*!
  976. * Parameter structure for the function RegionRxConfig.
  977. */
  978. typedef struct sRxConfigParams
  979. {
  980. /*!
  981. * The RX channel.
  982. */
  983. uint8_t Channel;
  984. /*!
  985. * RX datarate.
  986. */
  987. int8_t Datarate;
  988. /*!
  989. * RX bandwidth.
  990. */
  991. uint8_t Bandwidth;
  992. /*!
  993. * RX datarate offset.
  994. */
  995. int8_t DrOffset;
  996. /*!
  997. * RX frequency.
  998. */
  999. uint32_t Frequency;
  1000. /*!
  1001. * RX window timeout
  1002. */
  1003. uint32_t WindowTimeout;
  1004. /*!
  1005. * RX window offset
  1006. */
  1007. int32_t WindowOffset;
  1008. /*!
  1009. * Downlink dwell time.
  1010. */
  1011. uint8_t DownlinkDwellTime;
  1012. /*!
  1013. * Set to true, if a repeater is supported.
  1014. */
  1015. bool RepeaterSupport;
  1016. /*!
  1017. * Set to true, if RX should be continuous.
  1018. */
  1019. bool RxContinuous;
  1020. /*!
  1021. * Sets the RX window.
  1022. */
  1023. LoRaMacRxSlot_t RxSlot;
  1024. }RxConfigParams_t;
  1025. /*!
  1026. * Parameter structure for the function RegionTxConfig.
  1027. */
  1028. typedef struct sTxConfigParams
  1029. {
  1030. /*!
  1031. * The TX channel.
  1032. */
  1033. uint8_t Channel;
  1034. /*!
  1035. * The TX datarate.
  1036. */
  1037. int8_t Datarate;
  1038. /*!
  1039. * The TX power.
  1040. */
  1041. int8_t TxPower;
  1042. /*!
  1043. * The Max EIRP, if applicable.
  1044. */
  1045. float MaxEirp;
  1046. /*!
  1047. * The antenna gain, if applicable.
  1048. */
  1049. float AntennaGain;
  1050. /*!
  1051. * Frame length to setup.
  1052. */
  1053. uint16_t PktLen;
  1054. }TxConfigParams_t;
  1055. /*!
  1056. * Parameter structure for the function RegionLinkAdrReq.
  1057. */
  1058. typedef struct sLinkAdrReqParams
  1059. {
  1060. /*!
  1061. * Current LoRaWAN Version
  1062. */
  1063. Version_t Version;
  1064. /*!
  1065. * Pointer to the payload which contains the MAC commands.
  1066. */
  1067. uint8_t* Payload;
  1068. /*!
  1069. * Size of the payload.
  1070. */
  1071. uint8_t PayloadSize;
  1072. /*!
  1073. * Uplink dwell time.
  1074. */
  1075. uint8_t UplinkDwellTime;
  1076. /*!
  1077. * Set to true, if ADR is enabled.
  1078. */
  1079. bool AdrEnabled;
  1080. /*!
  1081. * The current datarate.
  1082. */
  1083. int8_t CurrentDatarate;
  1084. /*!
  1085. * The current TX power.
  1086. */
  1087. int8_t CurrentTxPower;
  1088. /*!
  1089. * The current number of repetitions.
  1090. */
  1091. uint8_t CurrentNbRep;
  1092. }LinkAdrReqParams_t;
  1093. /*!
  1094. * Parameter structure for the function RegionRxParamSetupReq.
  1095. */
  1096. typedef struct sRxParamSetupReqParams
  1097. {
  1098. /*!
  1099. * The datarate to setup.
  1100. */
  1101. int8_t Datarate;
  1102. /*!
  1103. * Datarate offset.
  1104. */
  1105. int8_t DrOffset;
  1106. /*!
  1107. * The frequency to setup.
  1108. */
  1109. uint32_t Frequency;
  1110. }RxParamSetupReqParams_t;
  1111. /*!
  1112. * Parameter structure for the function RegionNewChannelReq.
  1113. */
  1114. typedef struct sNewChannelReqParams
  1115. {
  1116. /*!
  1117. * Pointer to the new channels.
  1118. */
  1119. ChannelParams_t* NewChannel;
  1120. /*!
  1121. * Channel id.
  1122. */
  1123. int8_t ChannelId;
  1124. }NewChannelReqParams_t;
  1125. /*!
  1126. * Parameter structure for the function RegionTxParamSetupReq.
  1127. */
  1128. typedef struct sTxParamSetupReqParams
  1129. {
  1130. /*!
  1131. * Uplink dwell time.
  1132. */
  1133. uint8_t UplinkDwellTime;
  1134. /*!
  1135. * Downlink dwell time.
  1136. */
  1137. uint8_t DownlinkDwellTime;
  1138. /*!
  1139. * Max EIRP.
  1140. */
  1141. uint8_t MaxEirp;
  1142. }TxParamSetupReqParams_t;
  1143. /*!
  1144. * Parameter structure for the function RegionDlChannelReq.
  1145. */
  1146. typedef struct sDlChannelReqParams
  1147. {
  1148. /*!
  1149. * Channel Id to add the frequency.
  1150. */
  1151. uint8_t ChannelId;
  1152. /*!
  1153. * Alternative frequency for the Rx1 window.
  1154. */
  1155. uint32_t Rx1Frequency;
  1156. }DlChannelReqParams_t;
  1157. /*!
  1158. * Enumeration of alternation type
  1159. */
  1160. typedef enum eAlternateDrType
  1161. {
  1162. /*!
  1163. * Type to use for an alternation
  1164. */
  1165. ALTERNATE_DR,
  1166. /*!
  1167. * Type to use to restore one alternation
  1168. */
  1169. ALTERNATE_DR_RESTORE
  1170. }AlternateDrType_t;
  1171. /*!
  1172. * Parameter structure for the function RegionCalcBackOff.
  1173. */
  1174. typedef struct sCalcBackOffParams
  1175. {
  1176. /*!
  1177. * Set to true, if the node has already joined a network, otherwise false.
  1178. */
  1179. bool Joined;
  1180. /*!
  1181. * Joined Set to true, if the last uplink was a join request
  1182. */
  1183. bool LastTxIsJoinRequest;
  1184. /*!
  1185. * Set to true, if the duty cycle is enabled, otherwise false.
  1186. */
  1187. bool DutyCycleEnabled;
  1188. /*!
  1189. * Current channel index.
  1190. */
  1191. uint8_t Channel;
  1192. /*!
  1193. * Elapsed time since the start of the node.
  1194. */
  1195. SysTime_t ElapsedTime;
  1196. /*!
  1197. * Time-on-air of the last transmission.
  1198. */
  1199. TimerTime_t TxTimeOnAir;
  1200. }CalcBackOffParams_t;
  1201. /*!
  1202. * Parameter structure for the function RegionNextChannel.
  1203. */
  1204. typedef struct sNextChanParams
  1205. {
  1206. /*!
  1207. * Aggregated time-off time.
  1208. */
  1209. TimerTime_t AggrTimeOff;
  1210. /*!
  1211. * Time of the last aggregated TX.
  1212. */
  1213. TimerTime_t LastAggrTx;
  1214. /*!
  1215. * Current datarate.
  1216. */
  1217. int8_t Datarate;
  1218. /*!
  1219. * Set to true, if the node has already joined a network, otherwise false.
  1220. */
  1221. bool Joined;
  1222. /*!
  1223. * Set to true, if the duty cycle is enabled, otherwise false.
  1224. */
  1225. bool DutyCycleEnabled;
  1226. }NextChanParams_t;
  1227. /*!
  1228. * Parameter structure for the function RegionChannelsAdd.
  1229. */
  1230. typedef struct sChannelAddParams
  1231. {
  1232. /*!
  1233. * Pointer to the new channel to add.
  1234. */
  1235. ChannelParams_t* NewChannel;
  1236. /*!
  1237. * Channel id to add.
  1238. */
  1239. uint8_t ChannelId;
  1240. }ChannelAddParams_t;
  1241. /*!
  1242. * Parameter structure for the function RegionChannelsRemove.
  1243. */
  1244. typedef struct sChannelRemoveParams
  1245. {
  1246. /*!
  1247. * Channel id to remove.
  1248. */
  1249. uint8_t ChannelId;
  1250. }ChannelRemoveParams_t;
  1251. /*!
  1252. * Parameter structure for the function RegionContinuousWave.
  1253. */
  1254. typedef struct sContinuousWaveParams
  1255. {
  1256. /*!
  1257. * Current channel index.
  1258. */
  1259. uint8_t Channel;
  1260. /*!
  1261. * Datarate. Used to limit the TX power.
  1262. */
  1263. int8_t Datarate;
  1264. /*!
  1265. * The TX power to setup.
  1266. */
  1267. int8_t TxPower;
  1268. /*!
  1269. * Max EIRP, if applicable.
  1270. */
  1271. float MaxEirp;
  1272. /*!
  1273. * The antenna gain, if applicable.
  1274. */
  1275. float AntennaGain;
  1276. /*!
  1277. * Specifies the time the radio will stay in CW mode.
  1278. */
  1279. uint16_t Timeout;
  1280. }ContinuousWaveParams_t;
  1281. /*!
  1282. * Parameter structure for the function RegionRxBeaconSetup
  1283. */
  1284. typedef struct sRxBeaconSetupParams
  1285. {
  1286. /*!
  1287. * Symbol timeout.
  1288. */
  1289. uint16_t SymbolTimeout;
  1290. /*!
  1291. * Receive time.
  1292. */
  1293. uint32_t RxTime;
  1294. /*!
  1295. * The frequency to setup.
  1296. */
  1297. uint32_t Frequency;
  1298. }RxBeaconSetup_t;
  1299. /*!
  1300. * \brief The function verifies if a region is active or not. If a region
  1301. * is not active, it cannot be used.
  1302. *
  1303. * \param [IN] region LoRaWAN region.
  1304. *
  1305. * \retval Return true, if the region is supported.
  1306. */
  1307. bool RegionIsActive( LoRaMacRegion_t region );
  1308. /*!
  1309. * \brief The function gets a value of a specific phy attribute.
  1310. *
  1311. * \param [IN] region LoRaWAN region.
  1312. *
  1313. * \param [IN] getPhy Pointer to the function parameters.
  1314. *
  1315. * \retval Returns a structure containing the PHY parameter.
  1316. */
  1317. PhyParam_t RegionGetPhyParam( LoRaMacRegion_t region, GetPhyParams_t* getPhy );
  1318. /*!
  1319. * \brief Updates the last TX done parameters of the current channel.
  1320. *
  1321. * \param [IN] region LoRaWAN region.
  1322. *
  1323. * \param [IN] txDone Pointer to the function parameters.
  1324. */
  1325. void RegionSetBandTxDone( LoRaMacRegion_t region, SetBandTxDoneParams_t* txDone );
  1326. /*!
  1327. * \brief Initializes the channels masks and the channels.
  1328. *
  1329. * \param [IN] region LoRaWAN region.
  1330. *
  1331. * \param [IN] params Pointer to the function parameters.
  1332. */
  1333. void RegionInitDefaults( LoRaMacRegion_t region, InitDefaultsParams_t* params );
  1334. /*!
  1335. * \brief Returns a pointer to the internal context and its size.
  1336. *
  1337. * \param [IN] region LoRaWAN region.
  1338. *
  1339. * \param [IN] params Pointer to the function parameters.
  1340. *
  1341. * \retval Points to a structure where the module store its non-volatile context.
  1342. */
  1343. void* RegionGetNvmCtx( LoRaMacRegion_t region, GetNvmCtxParams_t* params );
  1344. /*!
  1345. * \brief Verifies a parameter.
  1346. *
  1347. * \param [IN] region LoRaWAN region.
  1348. *
  1349. * \param [IN] verify Pointer to the function parameters.
  1350. *
  1351. * \param [IN] type Sets the initialization type.
  1352. *
  1353. * \retval Returns true, if the parameter is valid.
  1354. */
  1355. bool RegionVerify( LoRaMacRegion_t region, VerifyParams_t* verify, PhyAttribute_t phyAttribute );
  1356. /*!
  1357. * \brief The function parses the input buffer and sets up the channels of the
  1358. * CF list.
  1359. *
  1360. * \param [IN] region LoRaWAN region.
  1361. *
  1362. * \param [IN] applyCFList Pointer to the function parameters.
  1363. */
  1364. void RegionApplyCFList( LoRaMacRegion_t region, ApplyCFListParams_t* applyCFList );
  1365. /*!
  1366. * \brief Sets a channels mask.
  1367. *
  1368. * \param [IN] region LoRaWAN region.
  1369. *
  1370. * \param [IN] chanMaskSet Pointer to the function parameters.
  1371. *
  1372. * \retval Returns true, if the channels mask could be set.
  1373. */
  1374. bool RegionChanMaskSet( LoRaMacRegion_t region, ChanMaskSetParams_t* chanMaskSet );
  1375. /*!
  1376. * \brief Configuration of the RX windows.
  1377. *
  1378. * \param [IN] region LoRaWAN region.
  1379. *
  1380. * \param [IN] rxConfig Pointer to the function parameters.
  1381. *
  1382. * \param [OUT] datarate The datarate index which was set.
  1383. *
  1384. * \retval Returns true, if the configuration was applied successfully.
  1385. */
  1386. bool RegionRxConfig( LoRaMacRegion_t region, RxConfigParams_t* rxConfig, int8_t* datarate );
  1387. /*
  1388. * Rx window precise timing
  1389. *
  1390. * For more details please consult the following document, chapter 3.1.2.
  1391. * https://www.semtech.com/uploads/documents/SX1272_settings_for_LoRaWAN_v2.0.pdf
  1392. * or
  1393. * https://www.semtech.com/uploads/documents/SX1276_settings_for_LoRaWAN_v2.0.pdf
  1394. *
  1395. * Downlink start: T = Tx + 1s (+/- 20 us)
  1396. * |
  1397. * TRxEarly | TRxLate
  1398. * | | |
  1399. * | | +---+---+---+---+---+---+---+---+
  1400. * | | | Latest Rx window |
  1401. * | | +---+---+---+---+---+---+---+---+
  1402. * | | |
  1403. * +---+---+---+---+---+---+---+---+
  1404. * | Earliest Rx window |
  1405. * +---+---+---+---+---+---+---+---+
  1406. * |
  1407. * +---+---+---+---+---+---+---+---+
  1408. *Downlink preamble 8 symbols | | | | | | | | |
  1409. * +---+---+---+---+---+---+---+---+
  1410. *
  1411. * Worst case Rx window timings
  1412. *
  1413. * TRxLate = DEFAULT_MIN_RX_SYMBOLS * tSymbol - RADIO_WAKEUP_TIME
  1414. * TRxEarly = 8 - DEFAULT_MIN_RX_SYMBOLS * tSymbol - RxWindowTimeout - RADIO_WAKEUP_TIME
  1415. *
  1416. * TRxLate - TRxEarly = 2 * DEFAULT_SYSTEM_MAX_RX_ERROR
  1417. *
  1418. * RxOffset = ( TRxLate + TRxEarly ) / 2
  1419. *
  1420. * RxWindowTimeout = ( 2 * DEFAULT_MIN_RX_SYMBOLS - 8 ) * tSymbol + 2 * DEFAULT_SYSTEM_MAX_RX_ERROR
  1421. * RxOffset = 4 * tSymbol - RxWindowTimeout / 2 - RADIO_WAKE_UP_TIME
  1422. *
  1423. * Minimal value of RxWindowTimeout must be 5 symbols which implies that the system always tolerates at least an error of 1.5 * tSymbol
  1424. */
  1425. /*!
  1426. * Computes the Rx window timeout and offset.
  1427. *
  1428. * \param [IN] region LoRaWAN region.
  1429. *
  1430. * \param [IN] datarate Rx window datarate index to be used
  1431. *
  1432. * \param [IN] minRxSymbols Minimum required number of symbols to detect an Rx frame.
  1433. *
  1434. * \param [IN] rxError System maximum timing error of the receiver. In milliseconds
  1435. * The receiver will turn on in a [-rxError : +rxError] ms
  1436. * interval around RxOffset
  1437. *
  1438. * \param [OUT]rxConfigParams Returns updated WindowTimeout and WindowOffset fields.
  1439. */
  1440. void RegionComputeRxWindowParameters( LoRaMacRegion_t region, int8_t datarate, uint8_t minRxSymbols, uint32_t rxError, RxConfigParams_t *rxConfigParams );
  1441. /*!
  1442. * \brief TX configuration.
  1443. *
  1444. * \param [IN] region LoRaWAN region.
  1445. *
  1446. * \param [IN] txConfig Pointer to the function parameters.
  1447. *
  1448. * \param [OUT] txPower The tx power index which was set.
  1449. *
  1450. * \param [OUT] txTimeOnAir The time-on-air of the frame.
  1451. *
  1452. * \retval Returns true, if the configuration was applied successfully.
  1453. */
  1454. bool RegionTxConfig( LoRaMacRegion_t region, TxConfigParams_t* txConfig, int8_t* txPower, TimerTime_t* txTimeOnAir );
  1455. /*!
  1456. * \brief The function processes a Link ADR Request.
  1457. *
  1458. * \param [IN] region LoRaWAN region.
  1459. *
  1460. * \param [IN] linkAdrReq Pointer to the function parameters.
  1461. *
  1462. * \param [OUT] drOut The datarate which was applied.
  1463. *
  1464. * \param [OUT] txPowOut The TX power which was applied.
  1465. *
  1466. * \param [OUT] nbRepOut The number of repetitions to apply.
  1467. *
  1468. * \param [OUT] nbBytesParsed The number bytes which were parsed.
  1469. *
  1470. * \retval Returns the status of the operation, according to the LoRaMAC specification.
  1471. */
  1472. uint8_t RegionLinkAdrReq( LoRaMacRegion_t region, LinkAdrReqParams_t* linkAdrReq, int8_t* drOut, int8_t* txPowOut, uint8_t* nbRepOut, uint8_t* nbBytesParsed );
  1473. /*!
  1474. * \brief The function processes a RX Parameter Setup Request.
  1475. *
  1476. * \param [IN] region LoRaWAN region.
  1477. *
  1478. * \param [IN] rxParamSetupReq Pointer to the function parameters.
  1479. *
  1480. * \retval Returns the status of the operation, according to the LoRaMAC specification.
  1481. */
  1482. uint8_t RegionRxParamSetupReq( LoRaMacRegion_t region, RxParamSetupReqParams_t* rxParamSetupReq );
  1483. /*!
  1484. * \brief The function processes a New Channel Request.
  1485. *
  1486. * \param [IN] region LoRaWAN region.
  1487. *
  1488. * \param [IN] newChannelReq Pointer to the function parameters.
  1489. *
  1490. * \retval Returns the status of the operation, according to the LoRaMAC specification.
  1491. */
  1492. uint8_t RegionNewChannelReq( LoRaMacRegion_t region, NewChannelReqParams_t* newChannelReq );
  1493. /*!
  1494. * \brief The function processes a TX ParamSetup Request.
  1495. *
  1496. * \param [IN] region LoRaWAN region.
  1497. *
  1498. * \param [IN] txParamSetupReq Pointer to the function parameters.
  1499. *
  1500. * \retval Returns the status of the operation, according to the LoRaMAC specification.
  1501. * Returns -1, if the functionality is not implemented. In this case, the end node
  1502. * shall ignore the command.
  1503. */
  1504. int8_t RegionTxParamSetupReq( LoRaMacRegion_t region, TxParamSetupReqParams_t* txParamSetupReq );
  1505. /*!
  1506. * \brief The function processes a DlChannel Request.
  1507. *
  1508. * \param [IN] region LoRaWAN region.
  1509. *
  1510. * \param [IN] dlChannelReq Pointer to the function parameters.
  1511. *
  1512. * \retval Returns the status of the operation, according to the LoRaMAC specification.
  1513. */
  1514. uint8_t RegionDlChannelReq( LoRaMacRegion_t region, DlChannelReqParams_t* dlChannelReq );
  1515. /*!
  1516. * \brief Alternates the datarate of the channel for the join request.
  1517. *
  1518. * \param [IN] region LoRaWAN region.
  1519. *
  1520. * \param [IN] currentDr Current datarate.
  1521. *
  1522. * \param [IN] type Alternation type.
  1523. *
  1524. * \retval Datarate to apply.
  1525. */
  1526. int8_t RegionAlternateDr( LoRaMacRegion_t region, int8_t currentDr, AlternateDrType_t type );
  1527. /*!
  1528. * \brief Calculates the back-off time.
  1529. *
  1530. * \param [IN] region LoRaWAN region.
  1531. *
  1532. * \param [IN] calcBackOff Pointer to the function parameters.
  1533. */
  1534. void RegionCalcBackOff( LoRaMacRegion_t region, CalcBackOffParams_t* calcBackOff );
  1535. /*!
  1536. * \brief Searches and set the next random available channel
  1537. *
  1538. * \param [IN] region LoRaWAN region.
  1539. *
  1540. * \param [OUT] channel Next channel to use for TX.
  1541. *
  1542. * \param [OUT] time Time to wait for the next transmission according to the duty
  1543. * cycle.
  1544. *
  1545. * \param [OUT] aggregatedTimeOff Updates the aggregated time off.
  1546. *
  1547. * \retval Function status [1: OK, 0: Unable to find a channel on the current datarate].
  1548. */
  1549. LoRaMacStatus_t RegionNextChannel( LoRaMacRegion_t region, NextChanParams_t* nextChanParams, uint8_t* channel, TimerTime_t* time, TimerTime_t* aggregatedTimeOff );
  1550. /*!
  1551. * \brief Adds a channel.
  1552. *
  1553. * \param [IN] region LoRaWAN region.
  1554. *
  1555. * \param [IN] channelAdd Pointer to the function parameters.
  1556. *
  1557. * \retval Status of the operation.
  1558. */
  1559. LoRaMacStatus_t RegionChannelAdd( LoRaMacRegion_t region, ChannelAddParams_t* channelAdd );
  1560. /*!
  1561. * \brief Removes a channel.
  1562. *
  1563. * \param [IN] region LoRaWAN region.
  1564. *
  1565. * \param [IN] channelRemove Pointer to the function parameters.
  1566. *
  1567. * \retval Returns true, if the channel was removed successfully.
  1568. */
  1569. bool RegionChannelsRemove( LoRaMacRegion_t region, ChannelRemoveParams_t* channelRemove );
  1570. /*!
  1571. * \brief Sets the radio into continuous wave mode.
  1572. *
  1573. * \param [IN] region LoRaWAN region.
  1574. *
  1575. * \param [IN] continuousWave Pointer to the function parameters.
  1576. */
  1577. void RegionSetContinuousWave( LoRaMacRegion_t region, ContinuousWaveParams_t* continuousWave );
  1578. /*!
  1579. * \brief Computes new datarate according to the given offset
  1580. *
  1581. * \param [IN] downlinkDwellTime Downlink dwell time configuration. 0: No limit, 1: 400ms
  1582. *
  1583. * \param [IN] dr Current datarate
  1584. *
  1585. * \param [IN] drOffset Offset to be applied
  1586. *
  1587. * \retval newDr Computed datarate.
  1588. */
  1589. uint8_t RegionApplyDrOffset( LoRaMacRegion_t region, uint8_t downlinkDwellTime, int8_t dr, int8_t drOffset );
  1590. /*!
  1591. * \brief Sets the radio into beacon reception mode
  1592. *
  1593. * \param [IN] rxBeaconSetup Pointer to the function parameters
  1594. *
  1595. * \param [out] outDr Datarate used to receive the beacon
  1596. */
  1597. void RegionRxBeaconSetup( LoRaMacRegion_t region, RxBeaconSetup_t* rxBeaconSetup, uint8_t* outDr );
  1598. /*! \} defgroup REGION */
  1599. #ifdef __cplusplus
  1600. }
  1601. #endif
  1602. #endif // __REGION_H__