1 /*!
2 * \file RegionCN470A26.c
3 *
4 * \brief
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 Daniel Jaeckle ( STACKFORCE )
28 *
29 * \defgroup REGIONCN470
30 */
31 #include "RegionCN470.h"
32 #include "RegionBaseUS.h"
33 #include "RegionCN470A26.h"
34
RegionCN470A26GetDownlinkFrequency(uint8_t channel,uint8_t joinChannelIndex,bool isPingSlot)35 uint32_t RegionCN470A26GetDownlinkFrequency( uint8_t channel, uint8_t joinChannelIndex, bool isPingSlot )
36 {
37 return CN470_A26_BEACON_FREQ;
38 }
39
RegionCN470A26GetBeaconChannelOffset(uint8_t joinChannelIndex)40 uint8_t RegionCN470A26GetBeaconChannelOffset( uint8_t joinChannelIndex )
41 {
42 return 0;
43 }
44
RegionCN470A26LinkAdrChMaskUpdate(uint16_t * channelsMask,uint8_t chMaskCntl,uint16_t chanMask,ChannelParams_t * channels)45 uint8_t RegionCN470A26LinkAdrChMaskUpdate( uint16_t* channelsMask, uint8_t chMaskCntl,
46 uint16_t chanMask, ChannelParams_t* channels )
47 {
48 uint8_t status = 0x07;
49
50 if( ( chMaskCntl == 5 ) || ( chMaskCntl == 6 ) || ( chMaskCntl == 7 ) )
51 {
52 // RFU
53 status &= 0xFE; // Channel mask KO
54 }
55 else if( chMaskCntl == 3 )
56 {
57 // Enable all channels
58 channelsMask[0] = 0xFFFF;
59 channelsMask[1] = 0xFFFF;
60 channelsMask[2] = 0xFFFF;
61 channelsMask[3] = 0xFFFF;
62 channelsMask[4] = 0x0000;
63 channelsMask[5] = 0x0000;
64 }
65 else if( chMaskCntl == 4 )
66 {
67 // Disable all channels
68 channelsMask[0] = 0x0000;
69 channelsMask[1] = 0x0000;
70 channelsMask[2] = 0x0000;
71 channelsMask[3] = 0x0000;
72 channelsMask[4] = 0x0000;
73 channelsMask[5] = 0x0000;
74 }
75 else
76 {
77 // chMaskCntl 0 to 2
78 for( uint8_t i = 0; i < 16; i++ )
79 {
80 if( ( ( chanMask & ( 1 << i ) ) != 0 ) &&
81 ( channels[chMaskCntl * 16 + i].Frequency == 0 ) )
82 {// Trying to enable an undefined channel
83 status &= 0xFE; // Channel mask KO
84 }
85 }
86 channelsMask[chMaskCntl] = chanMask;
87 }
88 return status;
89 }
90
RegionCN470A26VerifyRfFreq(uint32_t freq)91 bool RegionCN470A26VerifyRfFreq( uint32_t freq )
92 {
93 // Downstream group 1
94 if( RegionBaseUSVerifyFrequencyGroup( freq, CN470_A26_FIRST_RX_CHANNEL,
95 CN470_A26_LAST_RX_CHANNEL,
96 CN470_A26_STEPWIDTH_RX_CHANNEL ) == false )
97 {
98 return false;
99 }
100 return true;
101 }
102
RegionCN470A26InitializeChannels(ChannelParams_t * channels)103 void RegionCN470A26InitializeChannels( ChannelParams_t* channels )
104 {
105 // Upstream group 1
106 for( uint8_t i = 0; i < 48; i++ )
107 {
108 channels[i].Frequency = CN470_A26_FIRST_TX_CHANNEL + i * CN470_A26_STEPWIDTH_RX_CHANNEL;
109 channels[i].DrRange.Value = ( CN470_TX_MAX_DATARATE << 4 ) | CN470_TX_MIN_DATARATE;
110 channels[i].Band = 0;
111 }
112 }
113
RegionCN470A26InitializeChannelsMask(uint16_t * channelsDefaultMask)114 void RegionCN470A26InitializeChannelsMask( uint16_t* channelsDefaultMask )
115 {
116 // Enable all possible channels
117 channelsDefaultMask[0] = 0xFFFF;
118 channelsDefaultMask[1] = 0xFFFF;
119 channelsDefaultMask[2] = 0xFFFF;
120 channelsDefaultMask[3] = 0x0000;
121 channelsDefaultMask[4] = 0x0000;
122 channelsDefaultMask[5] = 0x0000;
123 }
124
RegionCN470A26GetRx1Frequency(uint8_t channel)125 uint32_t RegionCN470A26GetRx1Frequency( uint8_t channel )
126 {
127 return ( CN470_A26_FIRST_RX_CHANNEL + ( ( channel % 24 ) * CN470_A26_STEPWIDTH_RX_CHANNEL ) );
128 }
129
RegionCN470A26GetRx2Frequency(uint8_t joinChannelIndex,bool isOtaaDevice)130 uint32_t RegionCN470A26GetRx2Frequency( uint8_t joinChannelIndex, bool isOtaaDevice )
131 {
132 return CN470_A26_RX_WND_2_FREQ;
133 }
134