SX126xDevKit
Dependencies: mbed DmTftLibrary SX126xLib
Peripherals/Eeprom.cpp@1:b96176a4ccb8, 2018-03-09 (annotated)
- Committer:
- GregCr
- Date:
- Fri Mar 09 13:28:34 2018 +0000
- Revision:
- 1:b96176a4ccb8
- Parent:
- 0:e5420f1a8a1a
- Child:
- 2:8e1b4210df6b
V1.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
GregCr | 0:e5420f1a8a1a | 1 | /* |
GregCr | 0:e5420f1a8a1a | 2 | ______ _ |
GregCr | 0:e5420f1a8a1a | 3 | / _____) _ | | |
GregCr | 0:e5420f1a8a1a | 4 | ( (____ _____ ____ _| |_ _____ ____| |__ |
GregCr | 0:e5420f1a8a1a | 5 | \____ \| ___ | (_ _) ___ |/ ___) _ \ |
GregCr | 0:e5420f1a8a1a | 6 | _____) ) ____| | | || |_| ____( (___| | | | |
GregCr | 0:e5420f1a8a1a | 7 | (______/|_____)_|_|_| \__)_____)\____)_| |_| |
GregCr | 0:e5420f1a8a1a | 8 | (C)2016 Semtech |
GregCr | 0:e5420f1a8a1a | 9 | |
GregCr | 0:e5420f1a8a1a | 10 | Description: EEPROM routines |
GregCr | 0:e5420f1a8a1a | 11 | |
GregCr | 0:e5420f1a8a1a | 12 | Maintainer: Gregory Cristian & Gilbert Menth |
GregCr | 0:e5420f1a8a1a | 13 | */ |
GregCr | 0:e5420f1a8a1a | 14 | |
GregCr | 0:e5420f1a8a1a | 15 | #include "mbed.h" |
GregCr | 0:e5420f1a8a1a | 16 | #include "string.h" |
GregCr | 0:e5420f1a8a1a | 17 | #include "Eeprom.h" |
GregCr | 0:e5420f1a8a1a | 18 | #include "Menu.h" |
GregCr | 0:e5420f1a8a1a | 19 | #include "DemoApplication.h" |
GregCr | 0:e5420f1a8a1a | 20 | #include "sx126x.h" |
GregCr | 0:e5420f1a8a1a | 21 | #if defined( TARGET_NUCLEO_L476RG ) |
GregCr | 0:e5420f1a8a1a | 22 | #include "stm32l4xx_hal_flash.h" |
GregCr | 0:e5420f1a8a1a | 23 | #elif defined( TARGET_NUCLEO_L152RE ) |
GregCr | 0:e5420f1a8a1a | 24 | #include "stm32l1xx_hal_flash.h" |
GregCr | 0:e5420f1a8a1a | 25 | #else |
GregCr | 0:e5420f1a8a1a | 26 | #error "Please define include file" |
GregCr | 0:e5420f1a8a1a | 27 | #endif |
GregCr | 0:e5420f1a8a1a | 28 | |
GregCr | 0:e5420f1a8a1a | 29 | |
GregCr | 0:e5420f1a8a1a | 30 | |
GregCr | 0:e5420f1a8a1a | 31 | #include "DisplayDriver.h" |
GregCr | 0:e5420f1a8a1a | 32 | |
GregCr | 0:e5420f1a8a1a | 33 | |
GregCr | 0:e5420f1a8a1a | 34 | /*! |
GregCr | 0:e5420f1a8a1a | 35 | * \brief Define address of Emulated EEPROM (in fact region of Flash) |
GregCr | 0:e5420f1a8a1a | 36 | */ |
GregCr | 0:e5420f1a8a1a | 37 | #if defined( TARGET_NUCLEO_L476RG ) |
GregCr | 0:e5420f1a8a1a | 38 | #define DATA_EEPROM_BASE ( ( uint32_t )0x0807F800U ) |
GregCr | 0:e5420f1a8a1a | 39 | #define DATA_EEPROM_END ( ( uint32_t )DATA_EEPROM_BASE + 2048 ) |
GregCr | 0:e5420f1a8a1a | 40 | #elif defined( TARGET_NUCLEO_L152RE ) |
GregCr | 0:e5420f1a8a1a | 41 | #define DATA_EEPROM_BASE ( ( uint32_t )0x08080000U ) |
GregCr | 0:e5420f1a8a1a | 42 | #define DATA_EEPROM_END ( ( uint32_t )0x080807FFU ) |
GregCr | 0:e5420f1a8a1a | 43 | #else |
GregCr | 0:e5420f1a8a1a | 44 | #error "Please define EEPROM base address and size for your board " |
GregCr | 0:e5420f1a8a1a | 45 | #endif |
GregCr | 0:e5420f1a8a1a | 46 | |
GregCr | 0:e5420f1a8a1a | 47 | |
GregCr | 0:e5420f1a8a1a | 48 | /*! |
GregCr | 0:e5420f1a8a1a | 49 | * \brief CRC of EEPROM buffer and its valid status |
GregCr | 0:e5420f1a8a1a | 50 | */ |
GregCr | 0:e5420f1a8a1a | 51 | typedef struct |
GregCr | 0:e5420f1a8a1a | 52 | { |
GregCr | 0:e5420f1a8a1a | 53 | uint16_t Value; |
GregCr | 0:e5420f1a8a1a | 54 | bool Valid; |
GregCr | 0:e5420f1a8a1a | 55 | }MemTestStruct_t; |
GregCr | 0:e5420f1a8a1a | 56 | |
GregCr | 0:e5420f1a8a1a | 57 | /*! |
GregCr | 0:e5420f1a8a1a | 58 | * \brief Local copy of Eeprom. |
GregCr | 0:e5420f1a8a1a | 59 | */ |
GregCr | 0:e5420f1a8a1a | 60 | Eeprom_t Eeprom; |
GregCr | 0:e5420f1a8a1a | 61 | |
GregCr | 0:e5420f1a8a1a | 62 | |
GregCr | 0:e5420f1a8a1a | 63 | // Check CRC of local copy of Eeprom (Buffer). This update Valid & Value |
GregCr | 0:e5420f1a8a1a | 64 | static MemTestStruct_t EepromDataCheckSum( void ); |
GregCr | 0:e5420f1a8a1a | 65 | uint8_t EepromMcuWriteBuffer( uint16_t addr, uint8_t *buffer, uint16_t size ); |
GregCr | 0:e5420f1a8a1a | 66 | |
GregCr | 1:b96176a4ccb8 | 67 | void EepromInit( uint8_t deviceConnected, uint8_t matchingFreq ) |
GregCr | 0:e5420f1a8a1a | 68 | { |
GregCr | 0:e5420f1a8a1a | 69 | MemTestStruct_t memTestStruct; |
GregCr | 0:e5420f1a8a1a | 70 | |
GregCr | 0:e5420f1a8a1a | 71 | EepromMcuReadBuffer( 0, Eeprom.Buffer, EEPROM_BUFFER_SIZE ); |
GregCr | 0:e5420f1a8a1a | 72 | EepromLoadGeneralSettings( ); |
GregCr | 0:e5420f1a8a1a | 73 | |
GregCr | 0:e5420f1a8a1a | 74 | memTestStruct = EepromDataCheckSum( ); |
GregCr | 0:e5420f1a8a1a | 75 | if( !( memTestStruct.Valid ) || ( Eeprom.EepromData.DemoSettings.LastDeviceConnected != deviceConnected ) ) |
GregCr | 0:e5420f1a8a1a | 76 | { |
GregCr | 0:e5420f1a8a1a | 77 | #ifdef ADV_DEBUG |
GregCr | 0:e5420f1a8a1a | 78 | printf("EepromDataCheckSum failed\n\r"); |
GregCr | 0:e5420f1a8a1a | 79 | #endif |
GregCr | 1:b96176a4ccb8 | 80 | EepromSetDefaultSettings( deviceConnected, matchingFreq ); |
GregCr | 0:e5420f1a8a1a | 81 | } |
GregCr | 0:e5420f1a8a1a | 82 | EepromLoadSettings( ( RadioPacketTypes_t ) Eeprom.EepromData.DemoSettings.ModulationType ); |
GregCr | 0:e5420f1a8a1a | 83 | } |
GregCr | 0:e5420f1a8a1a | 84 | |
GregCr | 0:e5420f1a8a1a | 85 | void EepromSaveSettings( EepromDataSet_t dataSet) |
GregCr | 0:e5420f1a8a1a | 86 | { |
GregCr | 0:e5420f1a8a1a | 87 | MemTestStruct_t memTestStruct; |
GregCr | 0:e5420f1a8a1a | 88 | |
GregCr | 0:e5420f1a8a1a | 89 | switch( dataSet ) |
GregCr | 0:e5420f1a8a1a | 90 | { |
GregCr | 0:e5420f1a8a1a | 91 | case RADIO_LORA_PARAMS: |
GregCr | 0:e5420f1a8a1a | 92 | Eeprom.EepromData.ModulationParams.Params.LoRa.SpreadingFactor = ( RadioLoRaSpreadingFactors_t ) Eeprom.EepromData.DemoSettings.ModulationParam1; |
GregCr | 0:e5420f1a8a1a | 93 | Eeprom.EepromData.ModulationParams.Params.LoRa.Bandwidth = ( RadioLoRaBandwidths_t ) Eeprom.EepromData.DemoSettings.ModulationParam2; |
GregCr | 0:e5420f1a8a1a | 94 | Eeprom.EepromData.ModulationParams.Params.LoRa.CodingRate = ( RadioLoRaCodingRates_t ) Eeprom.EepromData.DemoSettings.ModulationParam3; |
GregCr | 0:e5420f1a8a1a | 95 | |
GregCr | 0:e5420f1a8a1a | 96 | Eeprom.EepromData.PacketParams.Params.LoRa.PreambleLength = Eeprom.EepromData.DemoSettings.PacketParam1; |
GregCr | 0:e5420f1a8a1a | 97 | Eeprom.EepromData.PacketParams.Params.LoRa.HeaderType = ( RadioLoRaPacketLengthsMode_t )Eeprom.EepromData.DemoSettings.PacketParam2; |
GregCr | 0:e5420f1a8a1a | 98 | Eeprom.EepromData.PacketParams.Params.LoRa.PayloadLength = Eeprom.EepromData.DemoSettings.PacketParam3; |
GregCr | 0:e5420f1a8a1a | 99 | Eeprom.EepromData.PacketParams.Params.LoRa.CrcMode = ( RadioLoRaCrcModes_t ) Eeprom.EepromData.DemoSettings.PacketParam4; |
GregCr | 0:e5420f1a8a1a | 100 | Eeprom.EepromData.PacketParams.Params.LoRa.InvertIQ = ( RadioLoRaIQModes_t ) Eeprom.EepromData.DemoSettings.PacketParam5; |
GregCr | 0:e5420f1a8a1a | 101 | |
GregCr | 0:e5420f1a8a1a | 102 | memcpy( Eeprom.Buffer + MOD_LORA_SPREADF_EEPROM_ADDR, &( Eeprom.EepromData.ModulationParams.Params.LoRa.SpreadingFactor ), 1 ); |
GregCr | 0:e5420f1a8a1a | 103 | memcpy( Eeprom.Buffer + MOD_LORA_BW_EEPROM_ADDR, &( Eeprom.EepromData.ModulationParams.Params.LoRa.Bandwidth ), 1 ); |
GregCr | 0:e5420f1a8a1a | 104 | memcpy( Eeprom.Buffer + MOD_LORA_CODERATE_EEPROM_ADDR, &( Eeprom.EepromData.ModulationParams.Params.LoRa.CodingRate ), 1 ); |
GregCr | 0:e5420f1a8a1a | 105 | memcpy( Eeprom.Buffer + PAK_LORA_PREAMBLE_LEN_EEPROM_ADDR, &( Eeprom.EepromData.PacketParams.Params.LoRa.PreambleLength ), 1 ); |
GregCr | 0:e5420f1a8a1a | 106 | memcpy( Eeprom.Buffer + PAK_LORA_HEADERTYPE_EEPROM_ADDR, &( Eeprom.EepromData.PacketParams.Params.LoRa.HeaderType ), 1 ); |
GregCr | 0:e5420f1a8a1a | 107 | memcpy( Eeprom.Buffer + PAK_LORA_PL_LEN_EEPROM_ADDR, &( Eeprom.EepromData.PacketParams.Params.LoRa.PayloadLength ), 1 ); |
GregCr | 0:e5420f1a8a1a | 108 | memcpy( Eeprom.Buffer + PAK_LORA_CRC_MODE_EEPROM_ADDR, &( Eeprom.EepromData.PacketParams.Params.LoRa.CrcMode ), 1 ); |
GregCr | 0:e5420f1a8a1a | 109 | memcpy( Eeprom.Buffer + PAK_LORA_IQ_INV_EEPROM_ADDR, &( Eeprom.EepromData.PacketParams.Params.LoRa.InvertIQ ), 1 ); |
GregCr | 0:e5420f1a8a1a | 110 | #ifdef ADV_DEBUG |
GregCr | 0:e5420f1a8a1a | 111 | printf("Saved RADIO_LoRa_PARAMS\n\r"); |
GregCr | 0:e5420f1a8a1a | 112 | #endif |
GregCr | 0:e5420f1a8a1a | 113 | break; |
GregCr | 0:e5420f1a8a1a | 114 | |
GregCr | 0:e5420f1a8a1a | 115 | case RADIO_GFSK_PARAMS: |
GregCr | 0:e5420f1a8a1a | 116 | Eeprom.EepromData.ModulationParams.Params.Gfsk.BitRate = Eeprom.EepromData.DemoSettings.ModulationParam1; |
GregCr | 0:e5420f1a8a1a | 117 | Eeprom.EepromData.ModulationParams.Params.Gfsk.Fdev = Eeprom.EepromData.DemoSettings.ModulationParam2; |
GregCr | 0:e5420f1a8a1a | 118 | Eeprom.EepromData.ModulationParams.Params.Gfsk.ModulationShaping = ( RadioModShapings_t ) Eeprom.EepromData.DemoSettings.ModulationParam3; |
GregCr | 0:e5420f1a8a1a | 119 | Eeprom.EepromData.ModulationParams.Params.Gfsk.Bandwidth = ( RadioRxBandwidth_t ) Eeprom.EepromData.DemoSettings.ModulationParam4; |
GregCr | 0:e5420f1a8a1a | 120 | Eeprom.EepromData.PacketParams.Params.Gfsk.PreambleLength = Eeprom.EepromData.DemoSettings.PacketParam1; |
GregCr | 0:e5420f1a8a1a | 121 | Eeprom.EepromData.PacketParams.Params.Gfsk.PreambleMinDetect = ( RadioPreambleDetection_t )Eeprom.EepromData.DemoSettings.PacketParam2; |
GregCr | 0:e5420f1a8a1a | 122 | Eeprom.EepromData.PacketParams.Params.Gfsk.SyncWordLength = Eeprom.EepromData.DemoSettings.PacketParam3; |
GregCr | 0:e5420f1a8a1a | 123 | Eeprom.EepromData.PacketParams.Params.Gfsk.AddrComp = ( RadioAddressComp_t ) Eeprom.EepromData.DemoSettings.PacketParam4; |
GregCr | 0:e5420f1a8a1a | 124 | Eeprom.EepromData.PacketParams.Params.Gfsk.HeaderType = ( RadioPacketLengthModes_t )Eeprom.EepromData.DemoSettings.PacketParam5; |
GregCr | 0:e5420f1a8a1a | 125 | Eeprom.EepromData.PacketParams.Params.Gfsk.PayloadLength = Eeprom.EepromData.DemoSettings.PacketParam6; |
GregCr | 0:e5420f1a8a1a | 126 | |
GregCr | 0:e5420f1a8a1a | 127 | Eeprom.EepromData.PacketParams.Params.Gfsk.CrcLength = ( RadioCrcTypes_t ) Eeprom.EepromData.DemoSettings.PacketParam7; |
GregCr | 0:e5420f1a8a1a | 128 | Eeprom.EepromData.PacketParams.Params.Gfsk.DcFree = ( RadioDcFree_t ) Eeprom.EepromData.DemoSettings.PacketParam8; |
GregCr | 0:e5420f1a8a1a | 129 | |
GregCr | 0:e5420f1a8a1a | 130 | memcpy( Eeprom.Buffer + MOD_GFSK_BR_EEPROM_ADDR, &( Eeprom.EepromData.ModulationParams.Params.Gfsk.BitRate ), 4 ); |
GregCr | 0:e5420f1a8a1a | 131 | memcpy( Eeprom.Buffer + MOD_GFSK_FDEV_EEPROM_ADDR, &( Eeprom.EepromData.ModulationParams.Params.Gfsk.Fdev ), 4 ); |
GregCr | 0:e5420f1a8a1a | 132 | memcpy( Eeprom.Buffer + MOD_GFSK_MOD_SHAPE_EEPROM_ADDR, &( Eeprom.EepromData.ModulationParams.Params.Gfsk.ModulationShaping ), 1 ); |
GregCr | 0:e5420f1a8a1a | 133 | memcpy( Eeprom.Buffer + MOD_GFSK_BW_EEPROM_ADDR, &( Eeprom.EepromData.ModulationParams.Params.Gfsk.Bandwidth ), 1 ); |
GregCr | 0:e5420f1a8a1a | 134 | memcpy( Eeprom.Buffer + PAK_GFSK_PREAMBLE_LEN_EEPROM_ADDR, &( Eeprom.EepromData.PacketParams.Params.Gfsk.PreambleLength ), 1 ); |
GregCr | 0:e5420f1a8a1a | 135 | memcpy( Eeprom.Buffer + PAK_GFSK_PR_MIN_DET_EEPROM_ADDR, &( Eeprom.EepromData.PacketParams.Params.Gfsk.PreambleMinDetect ), 1 ); |
GregCr | 0:e5420f1a8a1a | 136 | memcpy( Eeprom.Buffer + PAK_GFSK_SYNC_LEN_EEPROM_ADDR, &( Eeprom.EepromData.PacketParams.Params.Gfsk.SyncWordLength ), 1 ); |
GregCr | 0:e5420f1a8a1a | 137 | memcpy( Eeprom.Buffer + PAK_GFSK_HEADERTYPE_EEPROM_ADDR, &( Eeprom.EepromData.PacketParams.Params.Gfsk.HeaderType ), 1 ); |
GregCr | 0:e5420f1a8a1a | 138 | memcpy( Eeprom.Buffer + PAK_GFSK_PL_LEN_EEPROM_ADDR, &( Eeprom.EepromData.PacketParams.Params.Gfsk.PayloadLength ), 1 ); |
GregCr | 0:e5420f1a8a1a | 139 | memcpy( Eeprom.Buffer + PAK_GFSK_ADDR_COMP_EEPROM_ADDR, &( Eeprom.EepromData.PacketParams.Params.Gfsk.AddrComp ), 1 ); |
GregCr | 0:e5420f1a8a1a | 140 | memcpy( Eeprom.Buffer + PAK_GFSK_CRC_LEN_EEPROM_ADDR, &( Eeprom.EepromData.PacketParams.Params.Gfsk.CrcLength ), 1 ); |
GregCr | 0:e5420f1a8a1a | 141 | memcpy( Eeprom.Buffer + PAK_GFSK_DC_FREE_EEPROM_ADDR, &( Eeprom.EepromData.PacketParams.Params.Gfsk.DcFree ), 1 ); |
GregCr | 0:e5420f1a8a1a | 142 | |
GregCr | 0:e5420f1a8a1a | 143 | #ifdef ADV_DEBUG |
GregCr | 0:e5420f1a8a1a | 144 | printf("Saved RADIO_GFSK_PARAMS\n\r"); |
GregCr | 0:e5420f1a8a1a | 145 | #endif |
GregCr | 0:e5420f1a8a1a | 146 | break; |
GregCr | 0:e5420f1a8a1a | 147 | |
GregCr | 0:e5420f1a8a1a | 148 | case DEMO_SETTINGS: |
GregCr | 0:e5420f1a8a1a | 149 | memcpy( Eeprom.Buffer + APP_ENTITY_EEPROM_ADDR, &( Eeprom.EepromData.DemoSettings.Entity ), 1 ); |
GregCr | 0:e5420f1a8a1a | 150 | memcpy( Eeprom.Buffer + APP_RADIO_BOOSTED_RX_EEPROM_ADDR, &( Eeprom.EepromData.DemoSettings.BoostedRx ), 1 ); |
GregCr | 0:e5420f1a8a1a | 151 | memcpy( Eeprom.Buffer + APP_FREQ_EEPROM_ADDR, &( Eeprom.EepromData.DemoSettings.Frequency ), 4 ); |
GregCr | 0:e5420f1a8a1a | 152 | memcpy( Eeprom.Buffer + APP_TXPWR_EEPROM_ADDR, &( Eeprom.EepromData.DemoSettings.TxPower ), 1 ); |
GregCr | 0:e5420f1a8a1a | 153 | memcpy( Eeprom.Buffer + APP_MOD_TYPE_EEPROM_ADDR, &( Eeprom.EepromData.DemoSettings.ModulationType ), 1 ); |
GregCr | 0:e5420f1a8a1a | 154 | memcpy( Eeprom.Buffer + APP_PER_NPAK_MAX_EEPROM_ADDR, &( Eeprom.EepromData.DemoSettings.MaxNumPacket ), 4 ); |
GregCr | 0:e5420f1a8a1a | 155 | memcpy( Eeprom.Buffer + APP_RADIO_POWER_MODE_EEPROM_ADDR, &( Eeprom.EepromData.DemoSettings.RadioPowerMode ), 1 ); |
GregCr | 0:e5420f1a8a1a | 156 | memcpy( Eeprom.Buffer + MOD_PKET_TYPE_EEPROM_ADDR, &( Eeprom.EepromData.DemoSettings.ModulationType ), 1 ); |
GregCr | 0:e5420f1a8a1a | 157 | memcpy( Eeprom.Buffer + PAK_PKET_TYPE_EEPROM_ADDR, &( Eeprom.EepromData.DemoSettings.ModulationType ), 1 ); |
GregCr | 0:e5420f1a8a1a | 158 | memcpy( Eeprom.Buffer + EEPROM_LAST_DEVICE_CONNECTED, &( Eeprom.EepromData.DemoSettings.LastDeviceConnected ), 1 ); |
GregCr | 0:e5420f1a8a1a | 159 | |
GregCr | 0:e5420f1a8a1a | 160 | #ifdef ADV_DEBUG |
GregCr | 0:e5420f1a8a1a | 161 | printf("Saved DEMO_SETTINGS\n\r"); |
GregCr | 0:e5420f1a8a1a | 162 | #endif |
GregCr | 0:e5420f1a8a1a | 163 | break; |
GregCr | 0:e5420f1a8a1a | 164 | |
GregCr | 0:e5420f1a8a1a | 165 | case SCREEN_DATA: |
GregCr | 0:e5420f1a8a1a | 166 | memcpy( Eeprom.Buffer + SCR_CAL_FLAG_EEPROM_ADDR, &( Eeprom.EepromData.MenuSettings.ScreenCalibrated ), 1 ); |
GregCr | 0:e5420f1a8a1a | 167 | memcpy( Eeprom.Buffer + SCR_CAL_POSA_EEPROM_ADDR, &( Eeprom.EepromData.MenuSettings.Calibration.a ), 4 ); |
GregCr | 0:e5420f1a8a1a | 168 | memcpy( Eeprom.Buffer + SCR_CAL_POSB_EEPROM_ADDR, &( Eeprom.EepromData.MenuSettings.Calibration.b ), 4 ); |
GregCr | 0:e5420f1a8a1a | 169 | memcpy( Eeprom.Buffer + SCR_CAL_POSC_EEPROM_ADDR, &( Eeprom.EepromData.MenuSettings.Calibration.c ), 4 ); |
GregCr | 0:e5420f1a8a1a | 170 | memcpy( Eeprom.Buffer + SCR_CAL_POSD_EEPROM_ADDR, &( Eeprom.EepromData.MenuSettings.Calibration.d ), 4 ); |
GregCr | 0:e5420f1a8a1a | 171 | memcpy( Eeprom.Buffer + SCR_CAL_POSE_EEPROM_ADDR, &( Eeprom.EepromData.MenuSettings.Calibration.e ), 4 ); |
GregCr | 0:e5420f1a8a1a | 172 | memcpy( Eeprom.Buffer + SCR_CAL_POSF_EEPROM_ADDR, &( Eeprom.EepromData.MenuSettings.Calibration.f ), 4 ); |
GregCr | 0:e5420f1a8a1a | 173 | break; |
GregCr | 0:e5420f1a8a1a | 174 | |
GregCr | 0:e5420f1a8a1a | 175 | default: |
GregCr | 0:e5420f1a8a1a | 176 | #ifdef ADV_DEBUG |
GregCr | 0:e5420f1a8a1a | 177 | printf("data not saved\n\r"); |
GregCr | 0:e5420f1a8a1a | 178 | #endif |
GregCr | 0:e5420f1a8a1a | 179 | break; |
GregCr | 0:e5420f1a8a1a | 180 | } |
GregCr | 0:e5420f1a8a1a | 181 | |
GregCr | 0:e5420f1a8a1a | 182 | memTestStruct = EepromDataCheckSum( ); |
GregCr | 0:e5420f1a8a1a | 183 | memcpy( Eeprom.Buffer + EEPROM_CRC_EEPROM_ADDR, &( memTestStruct.Value ), 2 ); |
GregCr | 0:e5420f1a8a1a | 184 | |
GregCr | 0:e5420f1a8a1a | 185 | EepromMcuWriteBuffer( 0, Eeprom.Buffer, EEPROM_BUFFER_SIZE ); |
GregCr | 0:e5420f1a8a1a | 186 | } |
GregCr | 0:e5420f1a8a1a | 187 | |
GregCr | 0:e5420f1a8a1a | 188 | void EepromLoadGeneralSettings( void ) |
GregCr | 0:e5420f1a8a1a | 189 | { |
GregCr | 0:e5420f1a8a1a | 190 | printf("Load General Settings\n\r"); |
GregCr | 0:e5420f1a8a1a | 191 | memcpy( &( Eeprom.EepromData.MenuSettings.ScreenCalibrated ), Eeprom.Buffer + SCR_CAL_FLAG_EEPROM_ADDR, 1 ); |
GregCr | 0:e5420f1a8a1a | 192 | memcpy( &( Eeprom.EepromData.MenuSettings.Calibration.a ), Eeprom.Buffer + SCR_CAL_POSA_EEPROM_ADDR, 4 ); |
GregCr | 0:e5420f1a8a1a | 193 | memcpy( &( Eeprom.EepromData.MenuSettings.Calibration.b ), Eeprom.Buffer + SCR_CAL_POSB_EEPROM_ADDR, 4 ); |
GregCr | 0:e5420f1a8a1a | 194 | memcpy( &( Eeprom.EepromData.MenuSettings.Calibration.c ), Eeprom.Buffer + SCR_CAL_POSC_EEPROM_ADDR, 4 ); |
GregCr | 0:e5420f1a8a1a | 195 | memcpy( &( Eeprom.EepromData.MenuSettings.Calibration.d ), Eeprom.Buffer + SCR_CAL_POSD_EEPROM_ADDR, 4 ); |
GregCr | 0:e5420f1a8a1a | 196 | memcpy( &( Eeprom.EepromData.MenuSettings.Calibration.e ), Eeprom.Buffer + SCR_CAL_POSE_EEPROM_ADDR, 4 ); |
GregCr | 0:e5420f1a8a1a | 197 | memcpy( &( Eeprom.EepromData.MenuSettings.Calibration.f ), Eeprom.Buffer + SCR_CAL_POSF_EEPROM_ADDR, 4 ); |
GregCr | 0:e5420f1a8a1a | 198 | |
GregCr | 0:e5420f1a8a1a | 199 | memcpy( &( Eeprom.EepromData.DemoSettings.Entity ), Eeprom.Buffer + APP_ENTITY_EEPROM_ADDR, 1 ); |
GregCr | 0:e5420f1a8a1a | 200 | memcpy( &( Eeprom.EepromData.DemoSettings.BoostedRx ), Eeprom.Buffer + APP_RADIO_BOOSTED_RX_EEPROM_ADDR, 1 ); |
GregCr | 0:e5420f1a8a1a | 201 | memcpy( &( Eeprom.EepromData.DemoSettings.Frequency ), Eeprom.Buffer + APP_FREQ_EEPROM_ADDR, 4 ); |
GregCr | 0:e5420f1a8a1a | 202 | memcpy( &( Eeprom.EepromData.DemoSettings.RadioPowerMode ), Eeprom.Buffer + APP_RADIO_POWER_MODE_EEPROM_ADDR, 1 ); |
GregCr | 0:e5420f1a8a1a | 203 | memcpy( &( Eeprom.EepromData.DemoSettings.TxPower ), Eeprom.Buffer + APP_TXPWR_EEPROM_ADDR, 1 ); |
GregCr | 0:e5420f1a8a1a | 204 | memcpy( &( Eeprom.EepromData.DemoSettings.ModulationType ), Eeprom.Buffer + APP_MOD_TYPE_EEPROM_ADDR, 1 ); |
GregCr | 0:e5420f1a8a1a | 205 | memcpy( &( Eeprom.EepromData.DemoSettings.MaxNumPacket ), Eeprom.Buffer + APP_PER_NPAK_MAX_EEPROM_ADDR, 4 ); |
GregCr | 0:e5420f1a8a1a | 206 | memcpy( &( Eeprom.EepromData.DemoSettings.LastDeviceConnected ), Eeprom.Buffer + EEPROM_LAST_DEVICE_CONNECTED, 1 ); |
GregCr | 0:e5420f1a8a1a | 207 | |
GregCr | 0:e5420f1a8a1a | 208 | memcpy( &( Eeprom.EepromData.ModulationParams.PacketType ), Eeprom.Buffer + MOD_PKET_TYPE_EEPROM_ADDR, 1 ); |
GregCr | 0:e5420f1a8a1a | 209 | |
GregCr | 0:e5420f1a8a1a | 210 | memcpy( &( Eeprom.EepromData.ModulationParams.Params.Gfsk.BitRate ), Eeprom.Buffer + MOD_GFSK_BR_EEPROM_ADDR, 4 ); |
GregCr | 0:e5420f1a8a1a | 211 | memcpy( &( Eeprom.EepromData.ModulationParams.Params.Gfsk.Fdev ), Eeprom.Buffer + MOD_GFSK_FDEV_EEPROM_ADDR, 4 ); |
GregCr | 0:e5420f1a8a1a | 212 | memcpy( &( Eeprom.EepromData.ModulationParams.Params.Gfsk.ModulationShaping ), Eeprom.Buffer + MOD_GFSK_MOD_SHAPE_EEPROM_ADDR, 1 ); |
GregCr | 0:e5420f1a8a1a | 213 | memcpy( &( Eeprom.EepromData.ModulationParams.Params.Gfsk.Bandwidth ), Eeprom.Buffer + MOD_GFSK_BW_EEPROM_ADDR, 1 ); |
GregCr | 0:e5420f1a8a1a | 214 | |
GregCr | 0:e5420f1a8a1a | 215 | memcpy( &( Eeprom.EepromData.ModulationParams.Params.LoRa.SpreadingFactor ), Eeprom.Buffer + MOD_LORA_SPREADF_EEPROM_ADDR, 1 ); |
GregCr | 0:e5420f1a8a1a | 216 | memcpy( &( Eeprom.EepromData.ModulationParams.Params.LoRa.Bandwidth ), Eeprom.Buffer + MOD_LORA_BW_EEPROM_ADDR, 1 ); |
GregCr | 0:e5420f1a8a1a | 217 | memcpy( &( Eeprom.EepromData.ModulationParams.Params.LoRa.CodingRate ), Eeprom.Buffer + MOD_LORA_CODERATE_EEPROM_ADDR, 1 ); |
GregCr | 0:e5420f1a8a1a | 218 | |
GregCr | 0:e5420f1a8a1a | 219 | memcpy( &( Eeprom.EepromData.PacketParams.PacketType ), Eeprom.Buffer + PAK_PKET_TYPE_EEPROM_ADDR, 1 ); |
GregCr | 0:e5420f1a8a1a | 220 | memcpy( &( Eeprom.EepromData.PacketParams.Params.Gfsk.PreambleLength ), Eeprom.Buffer + PAK_GFSK_PREAMBLE_LEN_EEPROM_ADDR, 1 ); |
GregCr | 0:e5420f1a8a1a | 221 | memcpy( &( Eeprom.EepromData.PacketParams.Params.Gfsk.PreambleMinDetect ), Eeprom.Buffer + PAK_GFSK_PR_MIN_DET_EEPROM_ADDR, 1 ); |
GregCr | 0:e5420f1a8a1a | 222 | memcpy( &( Eeprom.EepromData.PacketParams.Params.Gfsk.SyncWordLength ), Eeprom.Buffer + PAK_GFSK_SYNC_LEN_EEPROM_ADDR, 1 ); |
GregCr | 0:e5420f1a8a1a | 223 | memcpy( &( Eeprom.EepromData.PacketParams.Params.Gfsk.HeaderType ), Eeprom.Buffer + PAK_GFSK_HEADERTYPE_EEPROM_ADDR, 1 ); |
GregCr | 0:e5420f1a8a1a | 224 | memcpy( &( Eeprom.EepromData.PacketParams.Params.Gfsk.PayloadLength ), Eeprom.Buffer + PAK_GFSK_PL_LEN_EEPROM_ADDR, 1 ); |
GregCr | 0:e5420f1a8a1a | 225 | memcpy( &( Eeprom.EepromData.PacketParams.Params.Gfsk.AddrComp ), Eeprom.Buffer + PAK_GFSK_ADDR_COMP_EEPROM_ADDR, 1 ); |
GregCr | 0:e5420f1a8a1a | 226 | memcpy( &( Eeprom.EepromData.PacketParams.Params.Gfsk.CrcLength ), Eeprom.Buffer + PAK_GFSK_CRC_LEN_EEPROM_ADDR, 1 ); |
GregCr | 0:e5420f1a8a1a | 227 | memcpy( &( Eeprom.EepromData.PacketParams.Params.Gfsk.DcFree ), Eeprom.Buffer + PAK_GFSK_DC_FREE_EEPROM_ADDR, 1 ); |
GregCr | 0:e5420f1a8a1a | 228 | |
GregCr | 0:e5420f1a8a1a | 229 | memcpy( &( Eeprom.EepromData.PacketParams.Params.LoRa.PreambleLength ), Eeprom.Buffer + PAK_LORA_PREAMBLE_LEN_EEPROM_ADDR, 1 ); |
GregCr | 0:e5420f1a8a1a | 230 | memcpy( &( Eeprom.EepromData.PacketParams.Params.LoRa.HeaderType ), Eeprom.Buffer + PAK_LORA_HEADERTYPE_EEPROM_ADDR, 1 ); |
GregCr | 0:e5420f1a8a1a | 231 | memcpy( &( Eeprom.EepromData.PacketParams.Params.LoRa.PayloadLength ), Eeprom.Buffer + PAK_LORA_PL_LEN_EEPROM_ADDR, 1 ); |
GregCr | 0:e5420f1a8a1a | 232 | memcpy( &( Eeprom.EepromData.PacketParams.Params.LoRa.CrcMode ), Eeprom.Buffer + PAK_LORA_CRC_MODE_EEPROM_ADDR, 1 ); |
GregCr | 0:e5420f1a8a1a | 233 | memcpy( &( Eeprom.EepromData.PacketParams.Params.LoRa.InvertIQ ), Eeprom.Buffer + PAK_LORA_IQ_INV_EEPROM_ADDR, 1 ); |
GregCr | 0:e5420f1a8a1a | 234 | } |
GregCr | 0:e5420f1a8a1a | 235 | |
GregCr | 0:e5420f1a8a1a | 236 | void EepromLoadSettings( RadioPacketTypes_t modulation ) |
GregCr | 0:e5420f1a8a1a | 237 | { |
GregCr | 0:e5420f1a8a1a | 238 | if( modulation == PACKET_TYPE_LORA ) |
GregCr | 0:e5420f1a8a1a | 239 | { |
GregCr | 0:e5420f1a8a1a | 240 | printf("Load Settings PACKET_TYPE_LORA\n\r"); |
GregCr | 0:e5420f1a8a1a | 241 | memcpy( &( Eeprom.EepromData.ModulationParams.Params.LoRa.SpreadingFactor ), Eeprom.Buffer + MOD_LORA_SPREADF_EEPROM_ADDR, 1 ); |
GregCr | 0:e5420f1a8a1a | 242 | memcpy( &( Eeprom.EepromData.ModulationParams.Params.LoRa.Bandwidth ), Eeprom.Buffer + MOD_LORA_BW_EEPROM_ADDR, 1 ); |
GregCr | 0:e5420f1a8a1a | 243 | memcpy( &( Eeprom.EepromData.ModulationParams.Params.LoRa.CodingRate ), Eeprom.Buffer + MOD_LORA_CODERATE_EEPROM_ADDR, 1 ); |
GregCr | 0:e5420f1a8a1a | 244 | memcpy( &( Eeprom.EepromData.PacketParams.Params.LoRa.PreambleLength ), Eeprom.Buffer + PAK_LORA_PREAMBLE_LEN_EEPROM_ADDR, 1 ); |
GregCr | 0:e5420f1a8a1a | 245 | memcpy( &( Eeprom.EepromData.PacketParams.Params.LoRa.HeaderType ), Eeprom.Buffer + PAK_LORA_HEADERTYPE_EEPROM_ADDR, 1 ); |
GregCr | 0:e5420f1a8a1a | 246 | memcpy( &( Eeprom.EepromData.PacketParams.Params.LoRa.PayloadLength ), Eeprom.Buffer + PAK_LORA_PL_LEN_EEPROM_ADDR, 1 ); |
GregCr | 0:e5420f1a8a1a | 247 | memcpy( &( Eeprom.EepromData.PacketParams.Params.LoRa.CrcMode ), Eeprom.Buffer + PAK_LORA_CRC_MODE_EEPROM_ADDR, 1 ); |
GregCr | 0:e5420f1a8a1a | 248 | memcpy( &( Eeprom.EepromData.PacketParams.Params.LoRa.InvertIQ ), Eeprom.Buffer + PAK_LORA_IQ_INV_EEPROM_ADDR, 1 ); |
GregCr | 0:e5420f1a8a1a | 249 | |
GregCr | 0:e5420f1a8a1a | 250 | Eeprom.EepromData.ModulationParams.PacketType = PACKET_TYPE_LORA; |
GregCr | 0:e5420f1a8a1a | 251 | Eeprom.EepromData.PacketParams.PacketType = PACKET_TYPE_LORA; |
GregCr | 0:e5420f1a8a1a | 252 | Eeprom.EepromData.DemoSettings.ModulationParam1 = Eeprom.EepromData.ModulationParams.Params.LoRa.SpreadingFactor; |
GregCr | 0:e5420f1a8a1a | 253 | Eeprom.EepromData.DemoSettings.ModulationParam2 = Eeprom.EepromData.ModulationParams.Params.LoRa.Bandwidth; |
GregCr | 0:e5420f1a8a1a | 254 | Eeprom.EepromData.DemoSettings.ModulationParam3 = Eeprom.EepromData.ModulationParams.Params.LoRa.CodingRate; |
GregCr | 0:e5420f1a8a1a | 255 | |
GregCr | 0:e5420f1a8a1a | 256 | Eeprom.EepromData.DemoSettings.PacketParam1 = Eeprom.EepromData.PacketParams.Params.LoRa.PreambleLength; |
GregCr | 0:e5420f1a8a1a | 257 | Eeprom.EepromData.DemoSettings.PacketParam2 = Eeprom.EepromData.PacketParams.Params.LoRa.HeaderType; |
GregCr | 0:e5420f1a8a1a | 258 | Eeprom.EepromData.DemoSettings.PacketParam3 = Eeprom.EepromData.PacketParams.Params.LoRa.PayloadLength; |
GregCr | 0:e5420f1a8a1a | 259 | Eeprom.EepromData.DemoSettings.PacketParam4 = Eeprom.EepromData.PacketParams.Params.LoRa.CrcMode; |
GregCr | 0:e5420f1a8a1a | 260 | Eeprom.EepromData.DemoSettings.PacketParam5 = Eeprom.EepromData.PacketParams.Params.LoRa.InvertIQ; |
GregCr | 0:e5420f1a8a1a | 261 | Eeprom.EepromData.DemoSettings.PacketParam6 = 0x00; |
GregCr | 0:e5420f1a8a1a | 262 | Eeprom.EepromData.DemoSettings.PacketParam7 = 0x00; |
GregCr | 0:e5420f1a8a1a | 263 | } |
GregCr | 0:e5420f1a8a1a | 264 | else// if( modulation == PACKET_TYPE_GFSK ) |
GregCr | 0:e5420f1a8a1a | 265 | { |
GregCr | 0:e5420f1a8a1a | 266 | printf("Load Settings PACKET_TYPE_GFSK\n\r"); |
GregCr | 0:e5420f1a8a1a | 267 | memcpy( &( Eeprom.EepromData.ModulationParams.Params.Gfsk.BitRate ), Eeprom.Buffer + MOD_GFSK_BR_EEPROM_ADDR, 4 ); |
GregCr | 0:e5420f1a8a1a | 268 | memcpy( &( Eeprom.EepromData.ModulationParams.Params.Gfsk.Fdev ), Eeprom.Buffer + MOD_GFSK_FDEV_EEPROM_ADDR, 4 ); |
GregCr | 0:e5420f1a8a1a | 269 | memcpy( &( Eeprom.EepromData.ModulationParams.Params.Gfsk.ModulationShaping ), Eeprom.Buffer + MOD_GFSK_MOD_SHAPE_EEPROM_ADDR, 1 ); |
GregCr | 0:e5420f1a8a1a | 270 | memcpy( &( Eeprom.EepromData.ModulationParams.Params.Gfsk.Bandwidth ), Eeprom.Buffer + MOD_GFSK_BW_EEPROM_ADDR, 1 ); |
GregCr | 0:e5420f1a8a1a | 271 | |
GregCr | 0:e5420f1a8a1a | 272 | memcpy( &( Eeprom.EepromData.PacketParams.Params.Gfsk.PreambleLength ), Eeprom.Buffer + PAK_GFSK_PREAMBLE_LEN_EEPROM_ADDR, 1 ); |
GregCr | 0:e5420f1a8a1a | 273 | memcpy( &( Eeprom.EepromData.PacketParams.Params.Gfsk.PreambleMinDetect ), Eeprom.Buffer + PAK_GFSK_PR_MIN_DET_EEPROM_ADDR, 1 ); |
GregCr | 0:e5420f1a8a1a | 274 | memcpy( &( Eeprom.EepromData.PacketParams.Params.Gfsk.SyncWordLength ), Eeprom.Buffer + PAK_GFSK_SYNC_LEN_EEPROM_ADDR, 1 ); |
GregCr | 0:e5420f1a8a1a | 275 | memcpy( &( Eeprom.EepromData.PacketParams.Params.Gfsk.HeaderType ), Eeprom.Buffer + PAK_GFSK_HEADERTYPE_EEPROM_ADDR, 1 ); |
GregCr | 0:e5420f1a8a1a | 276 | memcpy( &( Eeprom.EepromData.PacketParams.Params.Gfsk.PayloadLength ), Eeprom.Buffer + PAK_GFSK_PL_LEN_EEPROM_ADDR, 1 ); |
GregCr | 0:e5420f1a8a1a | 277 | memcpy( &( Eeprom.EepromData.PacketParams.Params.Gfsk.AddrComp ), Eeprom.Buffer + PAK_GFSK_ADDR_COMP_EEPROM_ADDR, 1 ); |
GregCr | 0:e5420f1a8a1a | 278 | memcpy( &( Eeprom.EepromData.PacketParams.Params.Gfsk.CrcLength ), Eeprom.Buffer + PAK_GFSK_CRC_LEN_EEPROM_ADDR, 1 ); |
GregCr | 0:e5420f1a8a1a | 279 | memcpy( &( Eeprom.EepromData.PacketParams.Params.Gfsk.DcFree ), Eeprom.Buffer + PAK_GFSK_DC_FREE_EEPROM_ADDR, 1 ); |
GregCr | 0:e5420f1a8a1a | 280 | |
GregCr | 0:e5420f1a8a1a | 281 | Eeprom.EepromData.ModulationParams.PacketType = PACKET_TYPE_GFSK; |
GregCr | 0:e5420f1a8a1a | 282 | Eeprom.EepromData.PacketParams.PacketType = PACKET_TYPE_GFSK; |
GregCr | 0:e5420f1a8a1a | 283 | Eeprom.EepromData.DemoSettings.ModulationParam1 = Eeprom.EepromData.ModulationParams.Params.Gfsk.BitRate; |
GregCr | 0:e5420f1a8a1a | 284 | Eeprom.EepromData.DemoSettings.ModulationParam2 = Eeprom.EepromData.ModulationParams.Params.Gfsk.Fdev; |
GregCr | 0:e5420f1a8a1a | 285 | Eeprom.EepromData.DemoSettings.ModulationParam3 = Eeprom.EepromData.ModulationParams.Params.Gfsk.ModulationShaping; |
GregCr | 0:e5420f1a8a1a | 286 | Eeprom.EepromData.DemoSettings.ModulationParam4 = Eeprom.EepromData.ModulationParams.Params.Gfsk.Bandwidth; |
GregCr | 0:e5420f1a8a1a | 287 | |
GregCr | 0:e5420f1a8a1a | 288 | Eeprom.EepromData.DemoSettings.PacketParam1 = Eeprom.EepromData.PacketParams.Params.Gfsk.PreambleLength; |
GregCr | 0:e5420f1a8a1a | 289 | Eeprom.EepromData.DemoSettings.PacketParam2 = Eeprom.EepromData.PacketParams.Params.Gfsk.PreambleMinDetect; |
GregCr | 0:e5420f1a8a1a | 290 | Eeprom.EepromData.DemoSettings.PacketParam3 = Eeprom.EepromData.PacketParams.Params.Gfsk.SyncWordLength; |
GregCr | 0:e5420f1a8a1a | 291 | Eeprom.EepromData.DemoSettings.PacketParam4 = Eeprom.EepromData.PacketParams.Params.Gfsk.AddrComp; |
GregCr | 0:e5420f1a8a1a | 292 | Eeprom.EepromData.DemoSettings.PacketParam5 = Eeprom.EepromData.PacketParams.Params.Gfsk.HeaderType; |
GregCr | 0:e5420f1a8a1a | 293 | Eeprom.EepromData.DemoSettings.PacketParam6 = Eeprom.EepromData.PacketParams.Params.Gfsk.PayloadLength; |
GregCr | 0:e5420f1a8a1a | 294 | |
GregCr | 0:e5420f1a8a1a | 295 | Eeprom.EepromData.DemoSettings.PacketParam7 = Eeprom.EepromData.PacketParams.Params.Gfsk.CrcLength; |
GregCr | 0:e5420f1a8a1a | 296 | Eeprom.EepromData.DemoSettings.PacketParam8 = Eeprom.EepromData.PacketParams.Params.Gfsk.DcFree; |
GregCr | 0:e5420f1a8a1a | 297 | } |
GregCr | 0:e5420f1a8a1a | 298 | |
GregCr | 0:e5420f1a8a1a | 299 | Eeprom.EepromData.DemoSettings.ModulationType = modulation; |
GregCr | 0:e5420f1a8a1a | 300 | } |
GregCr | 0:e5420f1a8a1a | 301 | |
GregCr | 1:b96176a4ccb8 | 302 | void EepromSetDefaultSettings( uint8_t deviceConnected, uint8_t matchingFreq ) |
GregCr | 0:e5420f1a8a1a | 303 | { |
GregCr | 0:e5420f1a8a1a | 304 | Eeprom.EepromData.MenuSettings.ScreenCalibrated = false; |
GregCr | 0:e5420f1a8a1a | 305 | |
GregCr | 0:e5420f1a8a1a | 306 | printf("Set Default Settings\n\r"); |
GregCr | 0:e5420f1a8a1a | 307 | EepromSaveSettings( SCREEN_DATA ); |
GregCr | 0:e5420f1a8a1a | 308 | |
GregCr | 0:e5420f1a8a1a | 309 | Eeprom.EepromData.DemoSettings.ModulationType = PACKET_TYPE_LORA; |
GregCr | 0:e5420f1a8a1a | 310 | Eeprom.EepromData.ModulationParams.PacketType = PACKET_TYPE_LORA; |
GregCr | 0:e5420f1a8a1a | 311 | Eeprom.EepromData.PacketParams.PacketType = PACKET_TYPE_LORA; |
GregCr | 0:e5420f1a8a1a | 312 | |
GregCr | 0:e5420f1a8a1a | 313 | Eeprom.EepromData.DemoSettings.ModulationParam1 = LORA_SF7; |
GregCr | 0:e5420f1a8a1a | 314 | Eeprom.EepromData.DemoSettings.ModulationParam2 = LORA_BW_500; |
GregCr | 0:e5420f1a8a1a | 315 | Eeprom.EepromData.DemoSettings.ModulationParam3 = LORA_CR_4_5; |
GregCr | 0:e5420f1a8a1a | 316 | Eeprom.EepromData.DemoSettings.ModulationParam4 = 0x00; |
GregCr | 0:e5420f1a8a1a | 317 | |
GregCr | 0:e5420f1a8a1a | 318 | Eeprom.EepromData.DemoSettings.PacketParam1 = 8; // PreambleLength |
GregCr | 0:e5420f1a8a1a | 319 | Eeprom.EepromData.DemoSettings.PacketParam2 = LORA_PACKET_VARIABLE_LENGTH; |
GregCr | 0:e5420f1a8a1a | 320 | Eeprom.EepromData.DemoSettings.PacketParam3 = 16; // PayloadLength |
GregCr | 0:e5420f1a8a1a | 321 | Eeprom.EepromData.DemoSettings.PacketParam4 = LORA_CRC_ON; |
GregCr | 0:e5420f1a8a1a | 322 | Eeprom.EepromData.DemoSettings.PacketParam5 = LORA_IQ_NORMAL; |
GregCr | 0:e5420f1a8a1a | 323 | |
GregCr | 0:e5420f1a8a1a | 324 | EepromSaveSettings( RADIO_LORA_PARAMS ); |
GregCr | 0:e5420f1a8a1a | 325 | |
GregCr | 0:e5420f1a8a1a | 326 | Eeprom.EepromData.DemoSettings.ModulationType = PACKET_TYPE_GFSK; |
GregCr | 0:e5420f1a8a1a | 327 | Eeprom.EepromData.ModulationParams.PacketType = PACKET_TYPE_GFSK; |
GregCr | 0:e5420f1a8a1a | 328 | Eeprom.EepromData.PacketParams.PacketType = PACKET_TYPE_GFSK; |
GregCr | 0:e5420f1a8a1a | 329 | |
GregCr | 0:e5420f1a8a1a | 330 | Eeprom.EepromData.DemoSettings.ModulationParam1 = 19200; |
GregCr | 0:e5420f1a8a1a | 331 | Eeprom.EepromData.DemoSettings.ModulationParam2 = 5000; |
GregCr | 0:e5420f1a8a1a | 332 | Eeprom.EepromData.DemoSettings.ModulationParam3 = MOD_SHAPING_G_BT_1; |
GregCr | 0:e5420f1a8a1a | 333 | Eeprom.EepromData.DemoSettings.ModulationParam4 = RX_BW_39000; |
GregCr | 0:e5420f1a8a1a | 334 | |
GregCr | 0:e5420f1a8a1a | 335 | Eeprom.EepromData.DemoSettings.PacketParam1 = 40; |
GregCr | 0:e5420f1a8a1a | 336 | Eeprom.EepromData.DemoSettings.PacketParam2 = RADIO_PREAMBLE_DETECTOR_08_BITS; |
GregCr | 0:e5420f1a8a1a | 337 | Eeprom.EepromData.DemoSettings.PacketParam3 = 4; |
GregCr | 0:e5420f1a8a1a | 338 | Eeprom.EepromData.DemoSettings.PacketParam4 = RADIO_ADDRESSCOMP_FILT_OFF; |
GregCr | 0:e5420f1a8a1a | 339 | Eeprom.EepromData.DemoSettings.PacketParam5 = RADIO_PACKET_VARIABLE_LENGTH; |
GregCr | 0:e5420f1a8a1a | 340 | Eeprom.EepromData.DemoSettings.PacketParam6 = 16; // PayloadLength |
GregCr | 0:e5420f1a8a1a | 341 | Eeprom.EepromData.DemoSettings.PacketParam7 = RADIO_CRC_2_BYTES_CCIT; |
GregCr | 0:e5420f1a8a1a | 342 | Eeprom.EepromData.DemoSettings.PacketParam8 = RADIO_DC_FREE_OFF; |
GregCr | 0:e5420f1a8a1a | 343 | |
GregCr | 0:e5420f1a8a1a | 344 | EepromSaveSettings( RADIO_GFSK_PARAMS ); |
GregCr | 0:e5420f1a8a1a | 345 | |
GregCr | 0:e5420f1a8a1a | 346 | Eeprom.EepromData.DemoSettings.Entity = SLAVE; |
GregCr | 1:b96176a4ccb8 | 347 | Eeprom.EepromData.DemoSettings.BoostedRx = true; |
GregCr | 0:e5420f1a8a1a | 348 | if( deviceConnected == SX1261 ) |
GregCr | 0:e5420f1a8a1a | 349 | { |
GregCr | 0:e5420f1a8a1a | 350 | Eeprom.EepromData.DemoSettings.LastDeviceConnected = deviceConnected; |
GregCr | 0:e5420f1a8a1a | 351 | Eeprom.EepromData.DemoSettings.RadioPowerMode = USE_DCDC; |
GregCr | 0:e5420f1a8a1a | 352 | Eeprom.EepromData.DemoSettings.TxPower = SX1261_POWER_TX_MAX; |
GregCr | 0:e5420f1a8a1a | 353 | } |
GregCr | 0:e5420f1a8a1a | 354 | else |
GregCr | 0:e5420f1a8a1a | 355 | { |
GregCr | 0:e5420f1a8a1a | 356 | Eeprom.EepromData.DemoSettings.LastDeviceConnected = deviceConnected; |
GregCr | 0:e5420f1a8a1a | 357 | Eeprom.EepromData.DemoSettings.RadioPowerMode = USE_LDO; |
GregCr | 0:e5420f1a8a1a | 358 | Eeprom.EepromData.DemoSettings.TxPower = SX1262_POWER_TX_MAX; |
GregCr | 0:e5420f1a8a1a | 359 | } |
GregCr | 1:b96176a4ccb8 | 360 | |
GregCr | 1:b96176a4ccb8 | 361 | if( matchingFreq == 1 ) |
GregCr | 1:b96176a4ccb8 | 362 | { |
GregCr | 1:b96176a4ccb8 | 363 | Eeprom.EepromData.DemoSettings.Frequency = DEMO_CENTRAL_FREQ_PRESET1; // 868 MHz |
GregCr | 1:b96176a4ccb8 | 364 | } |
GregCr | 1:b96176a4ccb8 | 365 | else |
GregCr | 1:b96176a4ccb8 | 366 | { |
GregCr | 1:b96176a4ccb8 | 367 | Eeprom.EepromData.DemoSettings.Frequency = DEMO_CENTRAL_FREQ_PRESET2; // 915 MHz |
GregCr | 1:b96176a4ccb8 | 368 | } |
GregCr | 1:b96176a4ccb8 | 369 | |
GregCr | 0:e5420f1a8a1a | 370 | Eeprom.EepromData.DemoSettings.MaxNumPacket = 0x00; |
GregCr | 0:e5420f1a8a1a | 371 | Eeprom.EepromData.DemoSettings.ModulationType = PACKET_TYPE_LORA; |
GregCr | 0:e5420f1a8a1a | 372 | |
GregCr | 0:e5420f1a8a1a | 373 | EepromSaveSettings( DEMO_SETTINGS ); |
GregCr | 0:e5420f1a8a1a | 374 | } |
GregCr | 0:e5420f1a8a1a | 375 | |
GregCr | 0:e5420f1a8a1a | 376 | /*! |
GregCr | 0:e5420f1a8a1a | 377 | * \brief Erase a page of Flash. Here used to Erase EEPROM region. |
GregCr | 0:e5420f1a8a1a | 378 | * |
GregCr | 0:e5420f1a8a1a | 379 | * \param [in] page address of page to erase |
GregCr | 0:e5420f1a8a1a | 380 | * \param [in] banks address of banks to erase |
GregCr | 0:e5420f1a8a1a | 381 | */ |
GregCr | 0:e5420f1a8a1a | 382 | void FlashPageErase( uint32_t page, uint32_t banks ) |
GregCr | 0:e5420f1a8a1a | 383 | { |
GregCr | 0:e5420f1a8a1a | 384 | // Check the parameters |
GregCr | 0:e5420f1a8a1a | 385 | assert_param( IS_FLASH_PAGE( page ) ); |
GregCr | 0:e5420f1a8a1a | 386 | assert_param( IS_FLASH_BANK_EXCLUSIVE( banks ) ); |
GregCr | 0:e5420f1a8a1a | 387 | |
GregCr | 0:e5420f1a8a1a | 388 | if( ( banks & FLASH_BANK_1 ) != RESET ) |
GregCr | 0:e5420f1a8a1a | 389 | { |
GregCr | 0:e5420f1a8a1a | 390 | CLEAR_BIT( FLASH->CR, FLASH_CR_BKER ); |
GregCr | 0:e5420f1a8a1a | 391 | } |
GregCr | 0:e5420f1a8a1a | 392 | else |
GregCr | 0:e5420f1a8a1a | 393 | { |
GregCr | 0:e5420f1a8a1a | 394 | SET_BIT( FLASH->CR, FLASH_CR_BKER ); |
GregCr | 0:e5420f1a8a1a | 395 | } |
GregCr | 0:e5420f1a8a1a | 396 | |
GregCr | 0:e5420f1a8a1a | 397 | // Proceed to erase the page |
GregCr | 0:e5420f1a8a1a | 398 | MODIFY_REG( FLASH->CR, FLASH_CR_PNB, ( page << 3 ) ); |
GregCr | 0:e5420f1a8a1a | 399 | SET_BIT( FLASH->CR, FLASH_CR_PER ); |
GregCr | 0:e5420f1a8a1a | 400 | SET_BIT( FLASH->CR, FLASH_CR_STRT ); |
GregCr | 0:e5420f1a8a1a | 401 | } |
GregCr | 0:e5420f1a8a1a | 402 | |
GregCr | 0:e5420f1a8a1a | 403 | /*! |
GregCr | 0:e5420f1a8a1a | 404 | * \brief Write Eeprom to emulated EEPROM (in fact in Flash " higher address). |
GregCr | 0:e5420f1a8a1a | 405 | * |
GregCr | 0:e5420f1a8a1a | 406 | * \param [in] addr address of data (EEPROM offset not to be include) |
GregCr | 0:e5420f1a8a1a | 407 | * \param [in] buffer buffer to use for copy |
GregCr | 0:e5420f1a8a1a | 408 | * \param [in] size size of data to copy |
GregCr | 0:e5420f1a8a1a | 409 | * |
GregCr | 0:e5420f1a8a1a | 410 | * \retval status Status of operation (SUCCESS, ..) |
GregCr | 0:e5420f1a8a1a | 411 | */ |
GregCr | 0:e5420f1a8a1a | 412 | uint8_t EepromMcuWriteBuffer( uint16_t addr, uint8_t *buffer, uint16_t size ) |
GregCr | 0:e5420f1a8a1a | 413 | { |
GregCr | 0:e5420f1a8a1a | 414 | uint64_t *flash = ( uint64_t* )buffer; |
GregCr | 0:e5420f1a8a1a | 415 | |
GregCr | 0:e5420f1a8a1a | 416 | // assert_param( addr >= DATA_EEPROM_BASE ); |
GregCr | 0:e5420f1a8a1a | 417 | assert_param( buffer != NULL ); |
GregCr | 0:e5420f1a8a1a | 418 | assert_param( size < ( DATA_EEPROM_END - DATA_EEPROM_BASE ) ); |
GregCr | 0:e5420f1a8a1a | 419 | |
GregCr | 0:e5420f1a8a1a | 420 | HAL_FLASH_Unlock( ); |
GregCr | 0:e5420f1a8a1a | 421 | |
GregCr | 0:e5420f1a8a1a | 422 | FlashPageErase( 255, 1 ); |
GregCr | 0:e5420f1a8a1a | 423 | |
GregCr | 0:e5420f1a8a1a | 424 | WRITE_REG( FLASH->CR, 0x40000000 ); |
GregCr | 0:e5420f1a8a1a | 425 | |
GregCr | 0:e5420f1a8a1a | 426 | for( uint32_t i = 0; i < size; i++ ) |
GregCr | 0:e5420f1a8a1a | 427 | { |
GregCr | 0:e5420f1a8a1a | 428 | HAL_FLASH_Program( FLASH_TYPEPROGRAM_DOUBLEWORD, DATA_EEPROM_BASE + \ |
GregCr | 0:e5420f1a8a1a | 429 | ( 8 * i ), flash[i] ); |
GregCr | 0:e5420f1a8a1a | 430 | } |
GregCr | 0:e5420f1a8a1a | 431 | |
GregCr | 0:e5420f1a8a1a | 432 | HAL_FLASH_Lock( ); |
GregCr | 0:e5420f1a8a1a | 433 | |
GregCr | 0:e5420f1a8a1a | 434 | return SUCCESS; |
GregCr | 0:e5420f1a8a1a | 435 | } |
GregCr | 0:e5420f1a8a1a | 436 | |
GregCr | 0:e5420f1a8a1a | 437 | uint8_t EepromMcuReadBuffer( uint16_t addr, uint8_t *buffer, uint16_t size ) |
GregCr | 0:e5420f1a8a1a | 438 | { |
GregCr | 0:e5420f1a8a1a | 439 | assert_param( buffer != NULL ); |
GregCr | 0:e5420f1a8a1a | 440 | |
GregCr | 0:e5420f1a8a1a | 441 | // assert_param( addr >= DATA_EEPROM_BASE ); |
GregCr | 0:e5420f1a8a1a | 442 | assert_param( buffer != NULL ); |
GregCr | 0:e5420f1a8a1a | 443 | assert_param( size < ( DATA_EEPROM_END - DATA_EEPROM_BASE ) ); |
GregCr | 0:e5420f1a8a1a | 444 | |
GregCr | 0:e5420f1a8a1a | 445 | memcpy( buffer, ( uint8_t* )DATA_EEPROM_BASE, size ); |
GregCr | 0:e5420f1a8a1a | 446 | return SUCCESS; |
GregCr | 0:e5420f1a8a1a | 447 | } |
GregCr | 0:e5420f1a8a1a | 448 | |
GregCr | 0:e5420f1a8a1a | 449 | static MemTestStruct_t EepromDataCheckSum( void ) |
GregCr | 0:e5420f1a8a1a | 450 | { |
GregCr | 0:e5420f1a8a1a | 451 | MemTestStruct_t memTestStruct; |
GregCr | 0:e5420f1a8a1a | 452 | uint8_t x; |
GregCr | 0:e5420f1a8a1a | 453 | uint8_t i; |
GregCr | 0:e5420f1a8a1a | 454 | uint16_t crcBuf; |
GregCr | 0:e5420f1a8a1a | 455 | memTestStruct.Value = 0xFFFF; |
GregCr | 0:e5420f1a8a1a | 456 | |
GregCr | 0:e5420f1a8a1a | 457 | for( i = 0; i < EEPROM_BUFFER_SIZE - sizeof( uint16_t ); i++ ) |
GregCr | 0:e5420f1a8a1a | 458 | { |
GregCr | 0:e5420f1a8a1a | 459 | x = memTestStruct.Value >> 8 ^ Eeprom.Buffer[i]; |
GregCr | 0:e5420f1a8a1a | 460 | x ^= x >> 4; |
GregCr | 0:e5420f1a8a1a | 461 | memTestStruct.Value = ( memTestStruct.Value << 8 ) ^ \ |
GregCr | 0:e5420f1a8a1a | 462 | ( ( uint16_t )( x << 12 ) ) ^ \ |
GregCr | 0:e5420f1a8a1a | 463 | ( ( uint16_t )( x << 5 ) ) ^ \ |
GregCr | 0:e5420f1a8a1a | 464 | ( ( uint16_t )x ); |
GregCr | 0:e5420f1a8a1a | 465 | } |
GregCr | 0:e5420f1a8a1a | 466 | memcpy( &crcBuf, Eeprom.Buffer + EEPROM_CRC_EEPROM_ADDR, 2 ); |
GregCr | 0:e5420f1a8a1a | 467 | memTestStruct.Valid = ( crcBuf == memTestStruct.Value ); |
GregCr | 0:e5420f1a8a1a | 468 | |
GregCr | 0:e5420f1a8a1a | 469 | return memTestStruct; |
GregCr | 0:e5420f1a8a1a | 470 | } |
GregCr | 1:b96176a4ccb8 | 471 | |
GregCr | 1:b96176a4ccb8 | 472 | void EepromEraseCheckSum( void ) |
GregCr | 1:b96176a4ccb8 | 473 | { |
GregCr | 1:b96176a4ccb8 | 474 | memset( Eeprom.Buffer, 0, sizeof( Eeprom.Buffer ) ); |
GregCr | 1:b96176a4ccb8 | 475 | EepromMcuWriteBuffer( 0, Eeprom.Buffer, EEPROM_BUFFER_SIZE ); |
GregCr | 1:b96176a4ccb8 | 476 | } |