JunMo Hong / stm-spirit1-rf-driver_for_cubebite

Fork of EV-COG-AD3029LZ by JunMo Hong

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers spirit1.h Source File

spirit1.h

00001 /*
00002  * Copyright (c) 2012, STMicroelectronics.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the Institute nor the names of its contributors
00014  *    may be used to endorse or promote products derived from this software
00015  *    without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00027  * SUCH DAMAGE.
00028  *
00029  * This file is part of the Contiki operating system.
00030  *
00031  */
00032 /*---------------------------------------------------------------------------*/
00033 #ifndef __SPIRIT_H__
00034 #define __SPIRIT_H__
00035 /*---------------------------------------------------------------------------*/
00036 #include "radio.h"
00037 #include "SPIRIT_Config.h"
00038 #include "spirit1-config.h"
00039 //#include "spirit1_appli.h"
00040 #include "spirit1-const.h"
00041 /*---------------------------------------------------------------------------*/   
00042 extern const struct radio_driver spirit_radio_driver;
00043 void spirit1_interrupt_callback(void);
00044 
00045 /* exported from spirit1appli.h */
00046 
00047 #include "radio_shield_config.h"
00048 #include "MCU_Interface.h"
00049 #include "SPIRIT_Config.h"
00050 // betzw - WAS: #include "SPIRIT1_Util.h"
00051 
00052 
00053 #if defined(X_NUCLEO_IDS01A3)
00054      #define USE_SPIRIT1_433MHz
00055 #elif defined(X_NUCLEO_IDS01A4)
00056          #define USE_SPIRIT1_868MHz
00057 #elif defined(X_NUCLEO_IDS01A5)
00058          #define USE_SPIRIT1_915MHz
00059 #else
00060 #error SPIRIT1 Nucleo Shield undefined or unsupported
00061 #endif
00062 
00063 /*  Uncomment the Link Layer features to be used */
00064 // #define USE_AUTO_ACK
00065 // #define USE_AUTO_ACK_PIGGYBACKING
00066 // #define USE_AUTO_RETRANSMISSION
00067 
00068 #if defined(USE_AUTO_ACK)&& defined(USE_AUTO_ACK_PIGGYBACKING)&& defined(USE_AUTO_RETRANSMISSION)
00069 #define USE_STack_PROTOCOL
00070 
00071 /* LLP configuration parameters */
00072 #define EN_AUTOACK                      S_ENABLE
00073 #define EN_PIGGYBACKING                 S_ENABLE
00074 #define MAX_RETRANSMISSIONS             PKT_N_RETX_2
00075 
00076 #else
00077 #define USE_BASIC_PROTOCOL
00078 
00079 #endif
00080 
00081 /*  Uncomment the system Operating mode */
00082 //#define USE_LOW_POWER_MODE
00083 
00084 #if defined (USE_LOW_POWER_MODE)
00085 #define LPM_ENABLE
00086 #define MCU_STOP_MODE
00087 //#define MCU_SLEEP_MODE
00088 //#define RF_STANDBY
00089 #endif
00090 
00091 
00092 /* Exported constants --------------------------------------------------------*/
00093 
00094 /* Radio configuration parameters  */
00095 /* General Remarks:
00096  * Two SPSGRF modules will only communicate when both are having same frequency , same channel number,
00097  * same modulation scheme, same data rate, etc.
00098  * For example, the SPSGRF-915 module supports frequencies 902 to 928 MHz. User can select any frequency
00099  * between this band.
00100  */
00101 #define XTAL_OFFSET_PPM             0
00102 #define INFINITE_TIMEOUT            0.0
00103 
00104 #ifdef USE_SPIRIT1_433MHz
00105 #define BASE_FREQUENCY              433.4e6
00106 //#define BASE_FREQUENCY              433.3e6
00107 //#define BASE_FREQUENCY              433.2e6
00108 //#define BASE_FREQUENCY              433.1e6
00109 //#define BASE_FREQUENCY              433.0e6
00110 #endif
00111 
00112 #ifdef USE_SPIRIT1_868MHz
00113 #define BASE_FREQUENCY              868.0e6
00114 #endif
00115 
00116 #ifdef USE_SPIRIT1_915MHz
00117 #define BASE_FREQUENCY              915.0e6
00118 #endif
00119 
00120 
00121 /*  Addresses configuration parameters  */
00122 #define EN_FILT_MY_ADDRESS          S_DISABLE
00123 #define MY_ADDRESS                  0x24
00124 #define EN_FILT_MULTICAST_ADDRESS   S_DISABLE
00125 #define MULTICAST_ADDRESS           0xEE
00126 #define EN_FILT_BROADCAST_ADDRESS   S_DISABLE
00127 #define BROADCAST_ADDRESS           0xFF
00128 #define DESTINATION_ADDRESS         0x44
00129 #define EN_FILT_SOURCE_ADDRESS      S_DISABLE
00130 #define SOURCE_ADDR_MASK            0xf0
00131 #define SOURCE_ADDR_REF             0x37
00132 
00133 #define APPLI_CMD                       0x11
00134 #define NWK_CMD                         0x22
00135 #define LED_TOGGLE                      0xff
00136 #define ACK_OK                          0x01
00137 #define MAX_BUFFER_LEN                  96
00138 #define TIME_TO_EXIT_RX                 3000
00139 #define DELAY_RX_LED_TOGGLE             200
00140 #define DELAY_TX_LED_GLOW               1000
00141 #define LPM_WAKEUP_TIME                 100
00142 #define DATA_SEND_TIME                  30
00143 
00144 #define PREAMBLE_LENGTH             PKT_PREAMBLE_LENGTH_04BYTES
00145 #define SYNC_LENGTH                 PKT_SYNC_LENGTH_4BYTES
00146 #define CONTROL_LENGTH              PKT_CONTROL_LENGTH_0BYTES
00147 #define EN_ADDRESS                  S_DISABLE
00148 #define EN_FEC                      S_DISABLE
00149 #define CHANNEL_NUMBER              1 // betzw - WAS: 0
00150 #define LENGTH_TYPE                 PKT_LENGTH_VAR
00151 #define POWER_INDEX                 7
00152 #define RECEIVE_TIMEOUT             2000.0 /*change the value for required timeout period*/
00153 #define RSSI_THRESHOLD              -120
00154 
00155 
00156 
00157 #define POWER_DBM                   11.6
00158 
00159 
00160 /* 송,수신 성공 셋팅 값 */
00161 //------------915Mhz------------
00162 #ifdef  USE_SPIRIT1_915MHz
00163 #define CHANNEL_SPACE               20e3    //HJM : SPIRIT_Radio.h 참고, 디폴트 셋팅 값
00164 #define FREQ_DEVIATION              127e3
00165 #define BANDWIDTH                   540.0e3
00166 #define MODULATION_SELECT           GFSK_BT1
00167 #define DATARATE                    250000
00168 #endif  //USE_SPIRIT1_915MHz
00169 //------------915Mhz------------
00170 
00171 
00172 //------------433Mhz------------
00173 //작동 되는 셋팅 recv
00174 //#ifdef    USE_SPIRIT1_433MHz
00175 //#define CHANNEL_SPACE             20e3    //해봄
00176 //#define FREQ_DEVIATION              127e3 //해봄
00177 //#define BANDWIDTH                   540.0e3   //해봄
00178 //#define MODULATION_SELECT           GFSK_BT1
00179 //#define DATARATE                    250000
00180 ////#define DATARATE                    38400
00181 //#endif    //USE_SPIRIT1_433MHz
00182 //------------433Mhz------------
00183 
00184 //------------433Mhz------------
00185 //작동 되는 셋팅
00186 //#ifdef    USE_SPIRIT1_433MHz
00187 //#define CHANNEL_SPACE             20e3    //해봄
00188 //#define FREQ_DEVIATION              127e3 //recv
00189 ////#define FREQ_DEVIATION              50e3    //send
00190 ////#define BANDWIDTH                   50.0e3  
00191 ////#define BANDWIDTH                   70.0e3  //printf 다 끄니까 1000바이트정도 보내다가 뻗음
00192 ////#define BANDWIDTH                   100.0e3 //printf 다 끄니까 900바이트정도 보내다가 뻗음
00193 //#define BANDWIDTH                   100.5e3   //printf 다 끄니까 900바이트정도 보내다가 뻗음
00194 //
00195 ////#define BANDWIDTH                   540.0e3
00196 //#define MODULATION_SELECT           GFSK_BT1
00197 //#define DATARATE                    250000    //180326 HJM : 잘 됨
00198 ////#define DATARATE                    500000  //180326 HJM : 잘 안됨
00199 ////#define DATARATE                    300000  //180326 HJM : 잘 안됨
00200 ////#define DATARATE                    38400   
00201 //#endif    //USE_SPIRIT1_433MHz
00202 //------------433Mhz------------
00203 
00204 
00205 
00206 
00207 
00208 
00209 
00210 
00211 
00212 
00213 
00214 
00215 //------------433Mhz------------
00216 //HJM : 안테나 변경(방수 안테나)로 인한 셋팅 변경
00217 #ifdef  USE_SPIRIT1_433MHz
00218 
00219 // 기존 값
00220 //#define CHANNEL_SPACE               100e3
00221 //#define FREQ_DEVIATION              127e3
00222 //#define BANDWIDTH                   540.0e3
00223 ////#define MODULATION_SELECT           GFSK_BT1
00224 //#define MODULATION_SELECT           FSK
00225 //#define DATARATE                    250000
00226 
00227 //인터넷 검색 후 설정 값_1
00228 //#define FREQ_DEVIATION              4800
00229 //#define BANDWIDTH                   16000
00230 
00231 //인터넷 검색 후 설정 값_2
00232 //#define CHANNEL_SPACE               20e3
00233 //#define MODULATION_SELECT           FSK
00234 ////#define DATARATE                    38400
00235 ////#define DATARATE                    19200
00236 //#define DATARATE                    9600
00237 //#define FREQ_DEVIATION              20e3
00238 ////#define FREQ_DEVIATION              127e3
00239 //#define BANDWIDTH                   100E3
00240 
00241 
00242 #define CHANNEL_SPACE               20e3    //해봄
00243 //#define CHANNEL_SPACE               30e3
00244 #define FREQ_DEVIATION              127e3   //recv
00245 //#define FREQ_DEVIATION              50e3  //send
00246 //#define FREQ_DEVIATION              20e3  //send
00247 //#define FREQ_DEVIATION              70e3  //send
00248 #define BANDWIDTH                   50.0e3  
00249 //#define BANDWIDTH                   60.0e3    //printf 다 끄니까 1000바이트정도 보내다가 뻗음
00250 //#define BANDWIDTH                   70.0e3    //printf 다 끄니까 1000바이트정도 보내다가 뻗음
00251 //#define BANDWIDTH                   80.0e3    //printf 다 끄니까 1000바이트정도 보내다가 뻗음
00252 //#define BANDWIDTH                   90.0e3    
00253 //#define BANDWIDTH                   115.0e3   
00254 //#define BANDWIDTH                   200.0e3   
00255 //#define BANDWIDTH                   100.0e3   //printf 다 끄니까 900바이트정도 보내다가 뻗음
00256 //#define BANDWIDTH                   100.0e3   //printf 다 끄니까 900바이트정도 보내다가 뻗음
00257 //#define BANDWIDTH                   100.5e3   //printf 다 끄니까 900바이트정도 보내다가 뻗음
00258 //#define BANDWIDTH                   540.0e3
00259 
00260 //#define BANDWIDTH                   540.0e3
00261 //#define MODULATION_SELECT           GFSK_BT1
00262 #define MODULATION_SELECT           FSK
00263 //#define DATARATE                    250000    //180326 HJM : 잘 됨
00264 //#define DATARATE                    125000    //
00265 //#define DATARATE                    62500 //
00266 //#define DATARATE                    230400    //
00267 //#define DATARATE                    500000    //180326 HJM : 잘 안됨
00268 //#define DATARATE                    300000    //180326 HJM : 잘 안됨
00269 //#define DATARATE                    115200    //180326 HJM : 잘 안됨
00270 #define DATARATE                    57600   //180326 HJM : 잘 안됨
00271 //#define DATARATE                    38400 //180326 HJM : 잘 안됨
00272 //#define DATARATE                    38400 
00273 
00274 
00275 #endif  //USE_SPIRIT1_433MHz
00276 //------------433Mhz------------
00277 
00278 
00279 
00280 
00281 
00282 
00283 
00284 
00285 
00286 
00287 
00288 
00289 
00290 
00291 
00292 
00293 
00294 
00295 
00296 
00297 
00298 
00299 
00300 
00301 
00302 
00303 //#define CHANNEL_SPACE               100e3
00304 //#define FREQ_DEVIATION              127e3
00305 //#define BANDWIDTH                   540.0e3
00306 ////#define MODULATION_SELECT           GFSK_BT1
00307 //#define MODULATION_SELECT           FSK
00308 //#define DATARATE                    250000
00309 
00310 
00311 
00312 
00313 #define XTAL_OFFSET_PPM             0
00314 #define SYNC_WORD                   0x88888888
00315 #define LENGTH_WIDTH                8 // betzw - NOTE: only 255 bytes for payload!!!
00316 #define CRC_MODE                    PKT_CRC_MODE_16BITS_2
00317 #define EN_WHITENING                S_DISABLE
00318 #define INFINITE_TIMEOUT            0.0
00319 
00320 // extern volatile FlagStatus xRxDoneFlag, xTxDoneFlag;
00321 // extern volatile FlagStatus PushButtonStatusWakeup;
00322 extern uint16_t wakeupCounter;
00323 extern uint16_t dataSendCounter ;
00324 // extern volatile FlagStatus PushButtonStatusData, datasendFlag;
00325 
00326 typedef struct
00327 {
00328   uint8_t Cmdtag;
00329   uint8_t CmdType;
00330   uint8_t CmdLen;
00331   uint8_t Cmd;
00332   uint8_t DataLen;
00333   uint8_t* DataBuff;
00334 }AppliFrame_t;
00335 
00336 /*---------------------------------------------------------------------------*/
00337 #endif /* __SPIRIT_H__ */
00338 /*---------------------------------------------------------------------------*/