MCU driver/HAL for the Picocell Gateway concentrator board. The firmware implements either a USB CDC protocol or a UART protocol to bridge commands coming from host to the SX1308 SPI interface.

Committer:
dgabino
Date:
Wed Apr 11 14:42:47 2018 +0000
Revision:
0:c76361bd82e8
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dgabino 0:c76361bd82e8 1 /*
dgabino 0:c76361bd82e8 2 / _____) _ | |
dgabino 0:c76361bd82e8 3 ( (____ _____ ____ _| |_ _____ ____| |__
dgabino 0:c76361bd82e8 4 \____ \| ___ | (_ _) ___ |/ ___) _ \
dgabino 0:c76361bd82e8 5 _____) ) ____| | | || |_| ____( (___| | | |
dgabino 0:c76361bd82e8 6 (______/|_____)_|_|_| \__)_____)\____)_| |_|
dgabino 0:c76361bd82e8 7 (C)2017 Semtech
dgabino 0:c76361bd82e8 8
dgabino 0:c76361bd82e8 9 */
dgabino 0:c76361bd82e8 10
dgabino 0:c76361bd82e8 11 #include "cmdUSB.h"
dgabino 0:c76361bd82e8 12 #include "usb_device.h"
dgabino 0:c76361bd82e8 13 #include "usbd_cdc_if.h"
dgabino 0:c76361bd82e8 14 #include "loragw_hal.h"
dgabino 0:c76361bd82e8 15 #include "loragw_reg.h"
dgabino 0:c76361bd82e8 16 #include "mbed.h"
dgabino 0:c76361bd82e8 17 #include "board.h"
dgabino 0:c76361bd82e8 18
dgabino 0:c76361bd82e8 19 #define DELAY_COM_INIT 1000
dgabino 0:c76361bd82e8 20 #define DELAY_RESET 200
dgabino 0:c76361bd82e8 21
dgabino 0:c76361bd82e8 22 /*
dgabino 0:c76361bd82e8 23 /Class INTERFACE definition
dgabino 0:c76361bd82e8 24 */
dgabino 0:c76361bd82e8 25
dgabino 0:c76361bd82e8 26 INTERFACE::INTERFACE()
dgabino 0:c76361bd82e8 27 {
dgabino 0:c76361bd82e8 28 }
dgabino 0:c76361bd82e8 29
dgabino 0:c76361bd82e8 30 /*
dgabino 0:c76361bd82e8 31 /Class COMUSB definition
dgabino 0:c76361bd82e8 32 */
dgabino 0:c76361bd82e8 33
dgabino 0:c76361bd82e8 34 COMUSB::COMUSB() : INTERFACE()
dgabino 0:c76361bd82e8 35 {
dgabino 0:c76361bd82e8 36 }
dgabino 0:c76361bd82e8 37 void COMUSB::Init() {
dgabino 0:c76361bd82e8 38 __HAL_RCC_USB_OTG_FS_CLK_ENABLE();
dgabino 0:c76361bd82e8 39 MX_USB_DEVICE_Init();
dgabino 0:c76361bd82e8 40 }
dgabino 0:c76361bd82e8 41
dgabino 0:c76361bd82e8 42 void COMUSB::Receive(uint8_t * Buffer, uint32_t * size) {
dgabino 0:c76361bd82e8 43 CDC_Receive_FSP(Buffer,size);// wait interrrupt manage in HAL_PCD_DataOutStageCallback
dgabino 0:c76361bd82e8 44 }
dgabino 0:c76361bd82e8 45
dgabino 0:c76361bd82e8 46 void COMUSB::Transmit(uint8_t * Buffer, uint16_t size) {
dgabino 0:c76361bd82e8 47 if ((size % 64) == 0) { // for ZLP
dgabino 0:c76361bd82e8 48 size = size + 1;
dgabino 0:c76361bd82e8 49 } else {
dgabino 0:c76361bd82e8 50 size = size;
dgabino 0:c76361bd82e8 51 }
dgabino 0:c76361bd82e8 52 while (CDC_Transmit_FS(Buffer, size) != USBD_OK){
dgabino 0:c76361bd82e8 53 }
dgabino 0:c76361bd82e8 54 }
dgabino 0:c76361bd82e8 55
dgabino 0:c76361bd82e8 56 /*
dgabino 0:c76361bd82e8 57 /Class COMUART definition
dgabino 0:c76361bd82e8 58 */
dgabino 0:c76361bd82e8 59
dgabino 0:c76361bd82e8 60 COMUART::COMUART(PinName Tx, PinName Rx) : Serial(Tx, Rx), INTERFACE()
dgabino 0:c76361bd82e8 61 {
dgabino 0:c76361bd82e8 62 //do nothing
dgabino 0:c76361bd82e8 63 }
dgabino 0:c76361bd82e8 64
dgabino 0:c76361bd82e8 65 void COMUART::Init() {
dgabino 0:c76361bd82e8 66 baud(BAUDRATE);
dgabino 0:c76361bd82e8 67 }
dgabino 0:c76361bd82e8 68
dgabino 0:c76361bd82e8 69 void COMUART::Receive(uint8_t * Buffer, uint32_t * size) {
dgabino 0:c76361bd82e8 70 uint16_t localSize = 0;
dgabino 0:c76361bd82e8 71 uint16_t cmdLength = 0;
dgabino 0:c76361bd82e8 72
dgabino 0:c76361bd82e8 73 while (localSize < CMD_HEADER_RX_SIZE) {
dgabino 0:c76361bd82e8 74 if (readable() == true) {
dgabino 0:c76361bd82e8 75 Buffer[localSize]= getc();
dgabino 0:c76361bd82e8 76 localSize++;
dgabino 0:c76361bd82e8 77 }
dgabino 0:c76361bd82e8 78 }
dgabino 0:c76361bd82e8 79 localSize = 0;
dgabino 0:c76361bd82e8 80 cmdLength = (Buffer[CMD_LENGTH_MSB] << 8) + Buffer[CMD_LENGTH_LSB];
dgabino 0:c76361bd82e8 81 while (localSize < cmdLength){
dgabino 0:c76361bd82e8 82 if (readable() == true) {
dgabino 0:c76361bd82e8 83 Buffer[localSize + CMD_HEADER_RX_SIZE ]= getc();
dgabino 0:c76361bd82e8 84 localSize++;
dgabino 0:c76361bd82e8 85 }
dgabino 0:c76361bd82e8 86 }
dgabino 0:c76361bd82e8 87 *size = (uint32_t)(cmdLength + CMD_HEADER_RX_SIZE);
dgabino 0:c76361bd82e8 88 }
dgabino 0:c76361bd82e8 89
dgabino 0:c76361bd82e8 90 void COMUART::Transmit(uint8_t * Buffer, uint16_t size) {
dgabino 0:c76361bd82e8 91 if ((size % 64) == 0) { // for ZLP Keep the same way than for USB transfer
dgabino 0:c76361bd82e8 92 size = size + 1;
dgabino 0:c76361bd82e8 93 } else {
dgabino 0:c76361bd82e8 94 size = size;
dgabino 0:c76361bd82e8 95 }
dgabino 0:c76361bd82e8 96 for (int g = 0; g < size; g++){
dgabino 0:c76361bd82e8 97 putc(Buffer[g]);
dgabino 0:c76361bd82e8 98 }
dgabino 0:c76361bd82e8 99 }
dgabino 0:c76361bd82e8 100
dgabino 0:c76361bd82e8 101 #ifdef USE_UART
dgabino 0:c76361bd82e8 102 CMDMANAGER::CMDMANAGER(PinName Tx, PinName Rx)
dgabino 0:c76361bd82e8 103 {
dgabino 0:c76361bd82e8 104 kill = false;
dgabino 0:c76361bd82e8 105 ActiveInterface = (INTERFACE *) new COMUART (Tx, Rx);
dgabino 0:c76361bd82e8 106 ActiveCom = ISUARTINTERFACE;
dgabino 0:c76361bd82e8 107 }
dgabino 0:c76361bd82e8 108 #else
dgabino 0:c76361bd82e8 109 CMDMANAGER::CMDMANAGER(PinName Tx, PinName Rx)
dgabino 0:c76361bd82e8 110 {
dgabino 0:c76361bd82e8 111 kill = false;
dgabino 0:c76361bd82e8 112 ActiveInterface = (INTERFACE *) new COMUSB ();
dgabino 0:c76361bd82e8 113 ActiveCom = ISUSBINTERFACE;
dgabino 0:c76361bd82e8 114 }
dgabino 0:c76361bd82e8 115 #endif
dgabino 0:c76361bd82e8 116
dgabino 0:c76361bd82e8 117 void CMDMANAGER::InitBufFromHost() {
dgabino 0:c76361bd82e8 118 memset(BufFromHost, 0, sizeof BufFromHost);
dgabino 0:c76361bd82e8 119 memset(BufFromHostChunk, 0, sizeof BufFromHostChunk);
dgabino 0:c76361bd82e8 120 receivelength[0] = 0;
dgabino 0:c76361bd82e8 121 count = 1;
dgabino 0:c76361bd82e8 122 }
dgabino 0:c76361bd82e8 123
dgabino 0:c76361bd82e8 124 void CMDMANAGER::InitBufToHost() {
dgabino 0:c76361bd82e8 125 memset(BufToHost, 0, sizeof BufToHost);
dgabino 0:c76361bd82e8 126 }
dgabino 0:c76361bd82e8 127
dgabino 0:c76361bd82e8 128 void CMDMANAGER::Init() {
dgabino 0:c76361bd82e8 129 ActiveInterface->Init();
dgabino 0:c76361bd82e8 130 wait_ms(DELAY_COM_INIT);
dgabino 0:c76361bd82e8 131 }
dgabino 0:c76361bd82e8 132
dgabino 0:c76361bd82e8 133 void CMDMANAGER::ReceiveCmd (){
dgabino 0:c76361bd82e8 134 InitBufFromHost();
dgabino 0:c76361bd82e8 135 if (ActiveCom == ISUARTINTERFACE)
dgabino 0:c76361bd82e8 136 {
dgabino 0:c76361bd82e8 137 ActiveInterface->Receive(&BufFromHost[0], &receivelength[0]);
dgabino 0:c76361bd82e8 138 } else {
dgabino 0:c76361bd82e8 139 ActiveInterface->Receive(&BufFromHostChunk[0], &receivelength[0]);
dgabino 0:c76361bd82e8 140 count = 1;
dgabino 0:c76361bd82e8 141 while (count > 0) {// wait until receive cmd
dgabino 0:c76361bd82e8 142 }
dgabino 0:c76361bd82e8 143 count = 1;
dgabino 0:c76361bd82e8 144 }
dgabino 0:c76361bd82e8 145 InitBufToHost();
dgabino 0:c76361bd82e8 146 }
dgabino 0:c76361bd82e8 147
dgabino 0:c76361bd82e8 148 void CMDMANAGER::TransmitCmd (){
dgabino 0:c76361bd82e8 149 uint16_t size;
dgabino 0:c76361bd82e8 150 size = (uint16_t)((BufToHost[CMD_LENGTH_MSB] << 8) + BufToHost[CMD_LENGTH_LSB] + CMD_HEADER_TX_SIZE);
dgabino 0:c76361bd82e8 151 ActiveInterface->Transmit(BufToHost, size);
dgabino 0:c76361bd82e8 152 /* Check if a reset has been requested */
dgabino 0:c76361bd82e8 153 if (kill == true) {
dgabino 0:c76361bd82e8 154 wait_ms(DELAY_RESET);
dgabino 0:c76361bd82e8 155 NVIC_SystemReset();
dgabino 0:c76361bd82e8 156 }
dgabino 0:c76361bd82e8 157 }
dgabino 0:c76361bd82e8 158
dgabino 0:c76361bd82e8 159 /********************************************************/
dgabino 0:c76361bd82e8 160 /* cmd name | description */
dgabino 0:c76361bd82e8 161 /*------------------------------------------------------*/
dgabino 0:c76361bd82e8 162 /* r |Read register */
dgabino 0:c76361bd82e8 163 /* s |Read long burst First packet */
dgabino 0:c76361bd82e8 164 /* t |Read long burst Middle packet */
dgabino 0:c76361bd82e8 165 /* u |Read long burst End packet */
dgabino 0:c76361bd82e8 166 /* p |Read atomic burst packet */
dgabino 0:c76361bd82e8 167 /* w |Write register */
dgabino 0:c76361bd82e8 168 /* x |Write long burst First packet */
dgabino 0:c76361bd82e8 169 /* y |Write long burst Middle packet */
dgabino 0:c76361bd82e8 170 /* z |Write long burst End packet */
dgabino 0:c76361bd82e8 171 /* a |Write atomic burst packet */
dgabino 0:c76361bd82e8 172 /*------------------------------------------------------*/
dgabino 0:c76361bd82e8 173 /* b |lgw_receive cmd */
dgabino 0:c76361bd82e8 174 /* c |lgw_rxrf_setconf cmd */
dgabino 0:c76361bd82e8 175 /* d |int lgw_rxif_setconf_cmd */
dgabino 0:c76361bd82e8 176 /* f |int lgw_send cmd */
dgabino 0:c76361bd82e8 177 /* h |lgw_txgain_setconf */
dgabino 0:c76361bd82e8 178 /* q |lgw_get_trigcnt */
dgabino 0:c76361bd82e8 179 /* i |lgw_board_setconf */
dgabino 0:c76361bd82e8 180 /* j |lgw_mcu_commit_radio_calibration */
dgabino 0:c76361bd82e8 181 /* l |lgw_check_fw_version */
dgabino 0:c76361bd82e8 182 /* m |Reset SX1308 and STM32 */
dgabino 0:c76361bd82e8 183 /* n |Jump to bootloader */
dgabino 0:c76361bd82e8 184 /********************************************************/
dgabino 0:c76361bd82e8 185 int CMDMANAGER::DecodeCmd() {
dgabino 0:c76361bd82e8 186 int i = 0;
dgabino 0:c76361bd82e8 187 int adressreg;
dgabino 0:c76361bd82e8 188 int val;
dgabino 0:c76361bd82e8 189 int size;
dgabino 0:c76361bd82e8 190 int x;
dgabino 0:c76361bd82e8 191 CmdSettings_t cmdSettings_FromHost;
dgabino 0:c76361bd82e8 192
dgabino 0:c76361bd82e8 193 if (BufFromHost[0] == 0) {
dgabino 0:c76361bd82e8 194 return (CMD_ERROR);
dgabino 0:c76361bd82e8 195 }
dgabino 0:c76361bd82e8 196
dgabino 0:c76361bd82e8 197 cmdSettings_FromHost.id = BufFromHost[0];
dgabino 0:c76361bd82e8 198
dgabino 0:c76361bd82e8 199 if (CheckCmd(cmdSettings_FromHost.id) == false) {
dgabino 0:c76361bd82e8 200 BufToHost[0] = 'k';
dgabino 0:c76361bd82e8 201 BufToHost[1] = 0;
dgabino 0:c76361bd82e8 202 BufToHost[2] = 0;
dgabino 0:c76361bd82e8 203 BufToHost[3] = ACK_K0;
dgabino 0:c76361bd82e8 204 return(CMD_K0);
dgabino 0:c76361bd82e8 205 }
dgabino 0:c76361bd82e8 206
dgabino 0:c76361bd82e8 207 switch (cmdSettings_FromHost.id) {
dgabino 0:c76361bd82e8 208
dgabino 0:c76361bd82e8 209 case 'r': { // cmd Read register
dgabino 0:c76361bd82e8 210 cmdSettings_FromHost.len_msb = BufFromHost[1];
dgabino 0:c76361bd82e8 211 cmdSettings_FromHost.len_lsb = BufFromHost[2];
dgabino 0:c76361bd82e8 212 adressreg = BufFromHost[3];
dgabino 0:c76361bd82e8 213 for (i = 0; i < cmdSettings_FromHost.len_lsb + (cmdSettings_FromHost.len_msb << 8); i++) {
dgabino 0:c76361bd82e8 214 cmdSettings_FromHost.cmd_data[i] = BufFromHost[4 + i];
dgabino 0:c76361bd82e8 215 }
dgabino 0:c76361bd82e8 216 val = Sx1308.spiRead(adressreg);
dgabino 0:c76361bd82e8 217 BufToHost[0] = 'r';
dgabino 0:c76361bd82e8 218 BufToHost[1] = 0;
dgabino 0:c76361bd82e8 219 BufToHost[2] = 1;
dgabino 0:c76361bd82e8 220 BufToHost[3] = ACK_OK;
dgabino 0:c76361bd82e8 221 BufToHost[4] = val;
dgabino 0:c76361bd82e8 222 return(CMD_OK);
dgabino 0:c76361bd82e8 223 }
dgabino 0:c76361bd82e8 224 case 's': { // cmd Read burst register first
dgabino 0:c76361bd82e8 225 cmdSettings_FromHost.len_msb = BufFromHost[1];
dgabino 0:c76361bd82e8 226 cmdSettings_FromHost.len_lsb = BufFromHost[2];
dgabino 0:c76361bd82e8 227 adressreg = BufFromHost[3];
dgabino 0:c76361bd82e8 228 for (i = 0; i < cmdSettings_FromHost.len_lsb + (cmdSettings_FromHost.len_msb << 8); i++) {
dgabino 0:c76361bd82e8 229 cmdSettings_FromHost.cmd_data[i] = BufFromHost[4 + i];
dgabino 0:c76361bd82e8 230 }
dgabino 0:c76361bd82e8 231 size = (cmdSettings_FromHost.cmd_data[0] << 8) + cmdSettings_FromHost.cmd_data[1];
dgabino 0:c76361bd82e8 232 BufToHost[0] = 's';
dgabino 0:c76361bd82e8 233 BufToHost[1] = cmdSettings_FromHost.cmd_data[0];
dgabino 0:c76361bd82e8 234 BufToHost[2] = cmdSettings_FromHost.cmd_data[1];
dgabino 0:c76361bd82e8 235 BufToHost[3] = ACK_OK;
dgabino 0:c76361bd82e8 236 Sx1308.spiReadBurstF(adressreg, &BufToHost[4 + 0], size);
dgabino 0:c76361bd82e8 237 return(CMD_OK);
dgabino 0:c76361bd82e8 238 }
dgabino 0:c76361bd82e8 239 case 't': { // cmd Read burst register middle
dgabino 0:c76361bd82e8 240 cmdSettings_FromHost.len_msb = BufFromHost[1];
dgabino 0:c76361bd82e8 241 cmdSettings_FromHost.len_lsb = BufFromHost[2];
dgabino 0:c76361bd82e8 242 adressreg = BufFromHost[3];
dgabino 0:c76361bd82e8 243
dgabino 0:c76361bd82e8 244 for (i = 0; i < cmdSettings_FromHost.len_lsb + (cmdSettings_FromHost.len_msb << 8); i++) {
dgabino 0:c76361bd82e8 245 cmdSettings_FromHost.cmd_data[i] = BufFromHost[4 + i];
dgabino 0:c76361bd82e8 246 }
dgabino 0:c76361bd82e8 247 size = (cmdSettings_FromHost.cmd_data[0] << 8) + cmdSettings_FromHost.cmd_data[1];
dgabino 0:c76361bd82e8 248
dgabino 0:c76361bd82e8 249 BufToHost[0] = 't';
dgabino 0:c76361bd82e8 250 BufToHost[1] = cmdSettings_FromHost.cmd_data[0];
dgabino 0:c76361bd82e8 251 BufToHost[2] = cmdSettings_FromHost.cmd_data[1];
dgabino 0:c76361bd82e8 252 BufToHost[3] = ACK_OK;
dgabino 0:c76361bd82e8 253 Sx1308.spiReadBurstM(adressreg, &BufToHost[4 + 0], size);
dgabino 0:c76361bd82e8 254 return(CMD_OK);
dgabino 0:c76361bd82e8 255 }
dgabino 0:c76361bd82e8 256 case 'u': { // cmd Read burst register end
dgabino 0:c76361bd82e8 257 cmdSettings_FromHost.len_msb = BufFromHost[1];
dgabino 0:c76361bd82e8 258 cmdSettings_FromHost.len_lsb = BufFromHost[2];
dgabino 0:c76361bd82e8 259 adressreg = BufFromHost[3];
dgabino 0:c76361bd82e8 260 for (i = 0; i < cmdSettings_FromHost.len_lsb + (cmdSettings_FromHost.len_msb << 8); i++) {
dgabino 0:c76361bd82e8 261 cmdSettings_FromHost.cmd_data[i] = BufFromHost[4 + i];
dgabino 0:c76361bd82e8 262 }
dgabino 0:c76361bd82e8 263 size = (cmdSettings_FromHost.cmd_data[0] << 8) + cmdSettings_FromHost.cmd_data[1];
dgabino 0:c76361bd82e8 264 BufToHost[0] = 'u';
dgabino 0:c76361bd82e8 265 BufToHost[1] = cmdSettings_FromHost.cmd_data[0];
dgabino 0:c76361bd82e8 266 BufToHost[2] = cmdSettings_FromHost.cmd_data[1];
dgabino 0:c76361bd82e8 267 BufToHost[3] = ACK_OK;
dgabino 0:c76361bd82e8 268 Sx1308.spiReadBurstE(adressreg, &BufToHost[4 + 0], size);
dgabino 0:c76361bd82e8 269 return(CMD_OK);
dgabino 0:c76361bd82e8 270 }
dgabino 0:c76361bd82e8 271 case 'p': { // cmd Read burst register atomic
dgabino 0:c76361bd82e8 272 cmdSettings_FromHost.len_msb = BufFromHost[1];
dgabino 0:c76361bd82e8 273 cmdSettings_FromHost.len_lsb = BufFromHost[2];
dgabino 0:c76361bd82e8 274 adressreg = BufFromHost[3];
dgabino 0:c76361bd82e8 275 for (i = 0; i < cmdSettings_FromHost.len_lsb + (cmdSettings_FromHost.len_msb << 8); i++) {
dgabino 0:c76361bd82e8 276 cmdSettings_FromHost.cmd_data[i] = BufFromHost[4 + i];
dgabino 0:c76361bd82e8 277 }
dgabino 0:c76361bd82e8 278 size = (cmdSettings_FromHost.cmd_data[0] << 8) + cmdSettings_FromHost.cmd_data[1];
dgabino 0:c76361bd82e8 279 BufToHost[0] = 'p';
dgabino 0:c76361bd82e8 280 BufToHost[1] = cmdSettings_FromHost.cmd_data[0];
dgabino 0:c76361bd82e8 281 BufToHost[2] = cmdSettings_FromHost.cmd_data[1];
dgabino 0:c76361bd82e8 282 BufToHost[3] = ACK_OK;
dgabino 0:c76361bd82e8 283 Sx1308.spiReadBurst(adressreg, &BufToHost[4 + 0], size);
dgabino 0:c76361bd82e8 284 return(CMD_OK);
dgabino 0:c76361bd82e8 285 }
dgabino 0:c76361bd82e8 286 case 'w': { // cmd write register
dgabino 0:c76361bd82e8 287 cmdSettings_FromHost.len_msb = BufFromHost[1];
dgabino 0:c76361bd82e8 288 cmdSettings_FromHost.len_lsb = BufFromHost[2];
dgabino 0:c76361bd82e8 289 adressreg = BufFromHost[3];
dgabino 0:c76361bd82e8 290 for (i = 0; i < cmdSettings_FromHost.len_lsb + (cmdSettings_FromHost.len_msb << 8); i++) {
dgabino 0:c76361bd82e8 291 cmdSettings_FromHost.cmd_data[i] = BufFromHost[4 + i];
dgabino 0:c76361bd82e8 292 }
dgabino 0:c76361bd82e8 293 val = cmdSettings_FromHost.cmd_data[0];
dgabino 0:c76361bd82e8 294 Sx1308.spiWrite(adressreg, val);
dgabino 0:c76361bd82e8 295 BufToHost[0] = 'w';
dgabino 0:c76361bd82e8 296 BufToHost[1] = 0;
dgabino 0:c76361bd82e8 297 BufToHost[2] = 0;
dgabino 0:c76361bd82e8 298 BufToHost[3] = ACK_OK;
dgabino 0:c76361bd82e8 299 return(CMD_OK);
dgabino 0:c76361bd82e8 300 }
dgabino 0:c76361bd82e8 301 case 'x': { // cmd write burst register
dgabino 0:c76361bd82e8 302 cmdSettings_FromHost.len_msb = BufFromHost[1];
dgabino 0:c76361bd82e8 303 cmdSettings_FromHost.len_lsb = BufFromHost[2];
dgabino 0:c76361bd82e8 304 adressreg = BufFromHost[3];
dgabino 0:c76361bd82e8 305 size = cmdSettings_FromHost.len_lsb + (cmdSettings_FromHost.len_msb << 8);
dgabino 0:c76361bd82e8 306 for (i = 0; i < cmdSettings_FromHost.len_lsb + (cmdSettings_FromHost.len_msb << 8); i++) {
dgabino 0:c76361bd82e8 307 cmdSettings_FromHost.cmd_data[i] = BufFromHost[4 + i];
dgabino 0:c76361bd82e8 308 }
dgabino 0:c76361bd82e8 309 Sx1308.spiWriteBurstF(adressreg, &cmdSettings_FromHost.cmd_data[0], size);
dgabino 0:c76361bd82e8 310 BufToHost[0] = 'x';
dgabino 0:c76361bd82e8 311 BufToHost[1] = 0;
dgabino 0:c76361bd82e8 312 BufToHost[2] = 0;
dgabino 0:c76361bd82e8 313 BufToHost[3] = ACK_OK;
dgabino 0:c76361bd82e8 314 return(CMD_OK);
dgabino 0:c76361bd82e8 315 }
dgabino 0:c76361bd82e8 316 case 'y': { // cmd write burst register
dgabino 0:c76361bd82e8 317 cmdSettings_FromHost.len_msb = BufFromHost[1];
dgabino 0:c76361bd82e8 318 cmdSettings_FromHost.len_lsb = BufFromHost[2];
dgabino 0:c76361bd82e8 319 adressreg = BufFromHost[3];
dgabino 0:c76361bd82e8 320 size = cmdSettings_FromHost.len_lsb + (cmdSettings_FromHost.len_msb << 8);
dgabino 0:c76361bd82e8 321 for (i = 0; i < cmdSettings_FromHost.len_lsb + (cmdSettings_FromHost.len_msb << 8); i++) {
dgabino 0:c76361bd82e8 322 cmdSettings_FromHost.cmd_data[i] = BufFromHost[4 + i];
dgabino 0:c76361bd82e8 323 }
dgabino 0:c76361bd82e8 324 Sx1308.spiWriteBurstM(adressreg, &cmdSettings_FromHost.cmd_data[0], size);
dgabino 0:c76361bd82e8 325 BufToHost[0] = 'y';
dgabino 0:c76361bd82e8 326 BufToHost[1] = 0;
dgabino 0:c76361bd82e8 327 BufToHost[2] = 0;
dgabino 0:c76361bd82e8 328 BufToHost[3] = ACK_OK;
dgabino 0:c76361bd82e8 329 return(CMD_OK);
dgabino 0:c76361bd82e8 330 }
dgabino 0:c76361bd82e8 331 case 'z': { // cmd write burst register
dgabino 0:c76361bd82e8 332 cmdSettings_FromHost.len_msb = BufFromHost[1];
dgabino 0:c76361bd82e8 333 cmdSettings_FromHost.len_lsb = BufFromHost[2];
dgabino 0:c76361bd82e8 334 adressreg = BufFromHost[3];
dgabino 0:c76361bd82e8 335 size = cmdSettings_FromHost.len_lsb + (cmdSettings_FromHost.len_msb << 8);
dgabino 0:c76361bd82e8 336 for (i = 0; i < cmdSettings_FromHost.len_lsb + (cmdSettings_FromHost.len_msb << 8); i++) {
dgabino 0:c76361bd82e8 337 cmdSettings_FromHost.cmd_data[i] = BufFromHost[4 + i];
dgabino 0:c76361bd82e8 338 }
dgabino 0:c76361bd82e8 339 Sx1308.spiWriteBurstE(adressreg, &cmdSettings_FromHost.cmd_data[0], size);
dgabino 0:c76361bd82e8 340 BufToHost[0] = 'z';
dgabino 0:c76361bd82e8 341 BufToHost[1] = 0;
dgabino 0:c76361bd82e8 342 BufToHost[2] = 0;
dgabino 0:c76361bd82e8 343 BufToHost[3] = ACK_OK;
dgabino 0:c76361bd82e8 344 return(CMD_OK);
dgabino 0:c76361bd82e8 345 }
dgabino 0:c76361bd82e8 346 case 'a': { // cmd write burst atomic register
dgabino 0:c76361bd82e8 347 cmdSettings_FromHost.len_msb = BufFromHost[1];
dgabino 0:c76361bd82e8 348 cmdSettings_FromHost.len_lsb = BufFromHost[2];
dgabino 0:c76361bd82e8 349 adressreg = BufFromHost[3];
dgabino 0:c76361bd82e8 350 size = cmdSettings_FromHost.len_lsb + (cmdSettings_FromHost.len_msb << 8);
dgabino 0:c76361bd82e8 351 for (i = 0; i < cmdSettings_FromHost.len_lsb + (cmdSettings_FromHost.len_msb << 8); i++) {
dgabino 0:c76361bd82e8 352 cmdSettings_FromHost.cmd_data[i] = BufFromHost[4 + i];
dgabino 0:c76361bd82e8 353 }
dgabino 0:c76361bd82e8 354 Sx1308.spiWriteBurst(adressreg, &cmdSettings_FromHost.cmd_data[0], size);
dgabino 0:c76361bd82e8 355 BufToHost[0] = 'a';
dgabino 0:c76361bd82e8 356 BufToHost[1] = 0;
dgabino 0:c76361bd82e8 357 BufToHost[2] = 0;
dgabino 0:c76361bd82e8 358 BufToHost[3] = ACK_OK;
dgabino 0:c76361bd82e8 359 return(CMD_OK);
dgabino 0:c76361bd82e8 360 }
dgabino 0:c76361bd82e8 361 case 'b': { // lgw_receive
dgabino 0:c76361bd82e8 362 static struct lgw_pkt_rx_s pkt_data[16]; //16 max packets TBU
dgabino 0:c76361bd82e8 363 int nbpacket = 0;
dgabino 0:c76361bd82e8 364 int j = 0;
dgabino 0:c76361bd82e8 365 int sizeatomic = sizeof(lgw_pkt_rx_s) / sizeof(uint8_t);
dgabino 0:c76361bd82e8 366 int cptalc = 0;
dgabino 0:c76361bd82e8 367 int pt = 0;
dgabino 0:c76361bd82e8 368 cmdSettings_FromHost.len_msb = BufFromHost[1];
dgabino 0:c76361bd82e8 369 cmdSettings_FromHost.len_lsb = BufFromHost[2];
dgabino 0:c76361bd82e8 370 adressreg = BufFromHost[3];
dgabino 0:c76361bd82e8 371 for (i = 0; i < cmdSettings_FromHost.len_lsb + (cmdSettings_FromHost.len_msb << 8); i++) {
dgabino 0:c76361bd82e8 372 cmdSettings_FromHost.cmd_data[i] = BufFromHost[4 + i];
dgabino 0:c76361bd82e8 373 }
dgabino 0:c76361bd82e8 374 nbpacket = lgw_receive(cmdSettings_FromHost.cmd_data[0], &pkt_data[0]);
dgabino 0:c76361bd82e8 375 BufToHost[0] = 'b';
dgabino 0:c76361bd82e8 376 BufToHost[3] = ((nbpacket >= 0) ? ACK_OK : ACK_K0);
dgabino 0:c76361bd82e8 377 BufToHost[4] = nbpacket;
dgabino 0:c76361bd82e8 378 for (j = 0; j < nbpacket; j++) {
dgabino 0:c76361bd82e8 379 for (i = 0; i < (pkt_data[j].size + (sizeatomic - 256)); i++) {
dgabino 0:c76361bd82e8 380 BufToHost[5 + i + pt] = *((uint8_t *)(&pkt_data[j]) + i);
dgabino 0:c76361bd82e8 381 cptalc++;
dgabino 0:c76361bd82e8 382 }
dgabino 0:c76361bd82e8 383 pt = cptalc;
dgabino 0:c76361bd82e8 384 }
dgabino 0:c76361bd82e8 385 cptalc = cptalc + 1; // + 1 for nbpacket
dgabino 0:c76361bd82e8 386 BufToHost[1] = (uint8_t)((cptalc >> 8) & 0xFF);
dgabino 0:c76361bd82e8 387 BufToHost[2] = (uint8_t)((cptalc >> 0) & 0xFF);
dgabino 0:c76361bd82e8 388 return(CMD_OK);
dgabino 0:c76361bd82e8 389 }
dgabino 0:c76361bd82e8 390 case 'c': { // lgw_rxrf_setconf
dgabino 0:c76361bd82e8 391 uint8_t rf_chain;
dgabino 0:c76361bd82e8 392 uint8_t conf[20];
dgabino 0:c76361bd82e8 393 cmdSettings_FromHost.len_msb = BufFromHost[1];
dgabino 0:c76361bd82e8 394 cmdSettings_FromHost.len_lsb = BufFromHost[2];
dgabino 0:c76361bd82e8 395 rf_chain = BufFromHost[3];
dgabino 0:c76361bd82e8 396 for (i = 0; i < cmdSettings_FromHost.len_lsb + (cmdSettings_FromHost.len_msb << 8); i++) {
dgabino 0:c76361bd82e8 397 conf[i] = BufFromHost[4 + i];
dgabino 0:c76361bd82e8 398 }
dgabino 0:c76361bd82e8 399 x = lgw_rxrf_setconf(rf_chain, *(lgw_conf_rxrf_s *)conf);
dgabino 0:c76361bd82e8 400 BufToHost[0] = 'c';
dgabino 0:c76361bd82e8 401 BufToHost[1] = 0;
dgabino 0:c76361bd82e8 402 BufToHost[2] = 0;
dgabino 0:c76361bd82e8 403 BufToHost[3] = ((x == 0) ? ACK_OK : ACK_K0);
dgabino 0:c76361bd82e8 404 return(CMD_OK);
dgabino 0:c76361bd82e8 405 }
dgabino 0:c76361bd82e8 406 case 'h': { // lgw_txgain_setconf
dgabino 0:c76361bd82e8 407 uint8_t conf[(LGW_MULTI_NB * TX_GAIN_LUT_SIZE_MAX) + 4];
dgabino 0:c76361bd82e8 408 cmdSettings_FromHost.len_msb = BufFromHost[1];
dgabino 0:c76361bd82e8 409 cmdSettings_FromHost.len_lsb = BufFromHost[2];
dgabino 0:c76361bd82e8 410 for (i = 0; i < cmdSettings_FromHost.len_lsb + (cmdSettings_FromHost.len_msb << 8); i++) {
dgabino 0:c76361bd82e8 411 conf[i] = BufFromHost[4 + i];
dgabino 0:c76361bd82e8 412 }
dgabino 0:c76361bd82e8 413 x = lgw_txgain_setconf((lgw_tx_gain_lut_s *)conf);
dgabino 0:c76361bd82e8 414 BufToHost[0] = 'h';
dgabino 0:c76361bd82e8 415 BufToHost[1] = 0;
dgabino 0:c76361bd82e8 416 BufToHost[2] = 0;
dgabino 0:c76361bd82e8 417 BufToHost[3] = ((x == 0) ? ACK_OK : ACK_K0);
dgabino 0:c76361bd82e8 418 return(CMD_OK);
dgabino 0:c76361bd82e8 419 }
dgabino 0:c76361bd82e8 420 case 'd': { // lgw_rxif_setconf
dgabino 0:c76361bd82e8 421 uint8_t if_chain;
dgabino 0:c76361bd82e8 422 uint8_t conf[(sizeof(struct lgw_conf_rxif_s) / sizeof(uint8_t))];
dgabino 0:c76361bd82e8 423 cmdSettings_FromHost.len_msb = BufFromHost[1];
dgabino 0:c76361bd82e8 424 cmdSettings_FromHost.len_lsb = BufFromHost[2];
dgabino 0:c76361bd82e8 425 if_chain = BufFromHost[3];
dgabino 0:c76361bd82e8 426 for (i = 0; i < cmdSettings_FromHost.len_lsb + (cmdSettings_FromHost.len_msb << 8); i++) {
dgabino 0:c76361bd82e8 427 conf[i] = BufFromHost[4 + i];
dgabino 0:c76361bd82e8 428 }
dgabino 0:c76361bd82e8 429 x = lgw_rxif_setconf(if_chain, *(lgw_conf_rxif_s *)conf);
dgabino 0:c76361bd82e8 430 BufToHost[0] = 'd';
dgabino 0:c76361bd82e8 431 BufToHost[1] = 0;
dgabino 0:c76361bd82e8 432 BufToHost[2] = 0;
dgabino 0:c76361bd82e8 433 BufToHost[3] = ((x == 0) ? ACK_OK : ACK_K0);
dgabino 0:c76361bd82e8 434 return(CMD_OK);
dgabino 0:c76361bd82e8 435 }
dgabino 0:c76361bd82e8 436 case 'f': { // lgw_send
dgabino 0:c76361bd82e8 437 uint32_t count_us;
dgabino 0:c76361bd82e8 438 int32_t txcontinuous;
dgabino 0:c76361bd82e8 439 uint8_t conf[(sizeof(struct lgw_pkt_tx_s) / sizeof(uint8_t))];
dgabino 0:c76361bd82e8 440 Timer timer_tx_timeout;
dgabino 0:c76361bd82e8 441
dgabino 0:c76361bd82e8 442 cmdSettings_FromHost.len_msb = BufFromHost[1];
dgabino 0:c76361bd82e8 443 cmdSettings_FromHost.len_lsb = BufFromHost[2];
dgabino 0:c76361bd82e8 444 for (i = 0; i < cmdSettings_FromHost.len_lsb + (cmdSettings_FromHost.len_msb << 8); i++) {
dgabino 0:c76361bd82e8 445 conf[i] = BufFromHost[4 + i];
dgabino 0:c76361bd82e8 446 }
dgabino 0:c76361bd82e8 447
dgabino 0:c76361bd82e8 448 /* Switch off SX1308 correlators to reduce power consumption during transmit */
dgabino 0:c76361bd82e8 449 #ifdef V2
dgabino 0:c76361bd82e8 450 HSCLKEN = 0;
dgabino 0:c76361bd82e8 451 #else
dgabino 0:c76361bd82e8 452 lgw_reg_w(LGW_CLKHS_EN, 0);
dgabino 0:c76361bd82e8 453 #endif
dgabino 0:c76361bd82e8 454
dgabino 0:c76361bd82e8 455 /* Send packet */
dgabino 0:c76361bd82e8 456 Sx1308.txongoing = 1;
dgabino 0:c76361bd82e8 457 Sx1308.waittxend = 1;
dgabino 0:c76361bd82e8 458 x = lgw_send(*(lgw_pkt_tx_s *)conf);
dgabino 0:c76361bd82e8 459 if (x < 0) {
dgabino 0:c76361bd82e8 460 //pc.printf("lgw_send() failed\n");
dgabino 0:c76361bd82e8 461 }
dgabino 0:c76361bd82e8 462
dgabino 0:c76361bd82e8 463 /* In case of TX continuous, return the answer immediatly */
dgabino 0:c76361bd82e8 464 lgw_reg_r(LGW_TX_MODE, &txcontinuous); // to switch off the timeout in case of tx continuous
dgabino 0:c76361bd82e8 465 if (txcontinuous == 1) {
dgabino 0:c76361bd82e8 466 BufToHost[0] = 'f';
dgabino 0:c76361bd82e8 467 BufToHost[1] = 0;
dgabino 0:c76361bd82e8 468 BufToHost[2] = 0;
dgabino 0:c76361bd82e8 469 BufToHost[3] = ACK_OK;
dgabino 0:c76361bd82e8 470 return(CMD_OK);
dgabino 0:c76361bd82e8 471 }
dgabino 0:c76361bd82e8 472
dgabino 0:c76361bd82e8 473 /* Wait for TX_DONE interrupt, or 10 seconds timeout */
dgabino 0:c76361bd82e8 474 timer_tx_timeout.reset();
dgabino 0:c76361bd82e8 475 timer_tx_timeout.start();
dgabino 0:c76361bd82e8 476 while (Sx1308.waittxend && (timer_tx_timeout.read() < (float)10.0)) {
dgabino 0:c76361bd82e8 477 }
dgabino 0:c76361bd82e8 478 timer_tx_timeout.stop();
dgabino 0:c76361bd82e8 479
dgabino 0:c76361bd82e8 480 /* Align SX1308 internal counter and STM32 counter */
dgabino 0:c76361bd82e8 481 if (Sx1308.firsttx == true) {
dgabino 0:c76361bd82e8 482 lgw_get_trigcnt(&count_us);
dgabino 0:c76361bd82e8 483 Sx1308.offtmstpstm32ref = (Sx1308.timerstm32ref.read_us() - count_us) + 60;
dgabino 0:c76361bd82e8 484 Sx1308.firsttx = false;
dgabino 0:c76361bd82e8 485 }
dgabino 0:c76361bd82e8 486
dgabino 0:c76361bd82e8 487 /* reset Sx1308 */
dgabino 0:c76361bd82e8 488 Sx1308.dig_reset();
dgabino 0:c76361bd82e8 489
dgabino 0:c76361bd82e8 490 /* Switch SX1308 correlators back on */
dgabino 0:c76361bd82e8 491 #ifdef V2
dgabino 0:c76361bd82e8 492 HSCLKEN = 1;
dgabino 0:c76361bd82e8 493 #else
dgabino 0:c76361bd82e8 494 lgw_reg_w(LGW_CLKHS_EN, 1);
dgabino 0:c76361bd82e8 495 #endif
dgabino 0:c76361bd82e8 496
dgabino 0:c76361bd82e8 497 /* restart SX1308 */
dgabino 0:c76361bd82e8 498 x = lgw_start();
dgabino 0:c76361bd82e8 499 if (x < 0) {
dgabino 0:c76361bd82e8 500 //pc.printf("lgw_start() failed\n");
dgabino 0:c76361bd82e8 501 }
dgabino 0:c76361bd82e8 502
dgabino 0:c76361bd82e8 503 /* Send command answer */
dgabino 0:c76361bd82e8 504 BufToHost[0] = 'f';
dgabino 0:c76361bd82e8 505 BufToHost[1] = 0;
dgabino 0:c76361bd82e8 506 BufToHost[2] = 0;
dgabino 0:c76361bd82e8 507 BufToHost[3] = ((x == 0) ? ACK_OK : ACK_K0);
dgabino 0:c76361bd82e8 508
dgabino 0:c76361bd82e8 509 return(CMD_OK);
dgabino 0:c76361bd82e8 510 }
dgabino 0:c76361bd82e8 511 case 'q': { // lgw_get_trigcnt
dgabino 0:c76361bd82e8 512 uint32_t timestamp;
dgabino 0:c76361bd82e8 513 x = lgw_get_trigcnt(&timestamp);
dgabino 0:c76361bd82e8 514 timestamp += Sx1308.offtmstpstm32;
dgabino 0:c76361bd82e8 515 BufToHost[0] = 'q';
dgabino 0:c76361bd82e8 516 BufToHost[1] = 0;
dgabino 0:c76361bd82e8 517 BufToHost[2] = 4;
dgabino 0:c76361bd82e8 518 BufToHost[3] = ((x == 0) ? ACK_OK : ACK_K0);
dgabino 0:c76361bd82e8 519 BufToHost[4] = (uint8_t)(timestamp >> 24);
dgabino 0:c76361bd82e8 520 BufToHost[5] = (uint8_t)((timestamp & 0x00FF0000) >> 16);
dgabino 0:c76361bd82e8 521 BufToHost[6] = (uint8_t)((timestamp & 0x0000FF00) >> 8);
dgabino 0:c76361bd82e8 522 BufToHost[7] = (uint8_t)((timestamp & 0x000000FF));
dgabino 0:c76361bd82e8 523 return(CMD_OK);
dgabino 0:c76361bd82e8 524 }
dgabino 0:c76361bd82e8 525 case 'i': { // lgw_board_setconf
dgabino 0:c76361bd82e8 526 uint8_t conf[(sizeof(struct lgw_conf_board_s) / sizeof(uint8_t))];
dgabino 0:c76361bd82e8 527 cmdSettings_FromHost.len_msb = BufFromHost[1];
dgabino 0:c76361bd82e8 528 cmdSettings_FromHost.len_lsb = BufFromHost[2];
dgabino 0:c76361bd82e8 529 for (i = 0; i < cmdSettings_FromHost.len_lsb + (cmdSettings_FromHost.len_msb << 8); i++) {
dgabino 0:c76361bd82e8 530 conf[i] = BufFromHost[4 + i];
dgabino 0:c76361bd82e8 531 }
dgabino 0:c76361bd82e8 532
dgabino 0:c76361bd82e8 533 x = lgw_board_setconf(*(lgw_conf_board_s *)conf);
dgabino 0:c76361bd82e8 534 BufToHost[0] = 'i';
dgabino 0:c76361bd82e8 535 BufToHost[1] = 0;
dgabino 0:c76361bd82e8 536 BufToHost[2] = 0;
dgabino 0:c76361bd82e8 537 BufToHost[3] = ((x == 0) ? ACK_OK : ACK_K0);
dgabino 0:c76361bd82e8 538 return(CMD_OK);
dgabino 0:c76361bd82e8 539 }
dgabino 0:c76361bd82e8 540 case 'j': { // lgw_calibration_snapshot
dgabino 0:c76361bd82e8 541 lgw_calibration_offset_transfer(BufFromHost[4], BufFromHost[5]);
dgabino 0:c76361bd82e8 542 BufToHost[0] = 'j';
dgabino 0:c76361bd82e8 543 BufToHost[1] = 0;
dgabino 0:c76361bd82e8 544 BufToHost[2] = 0;
dgabino 0:c76361bd82e8 545 BufToHost[3] = ACK_OK;
dgabino 0:c76361bd82e8 546 return(CMD_OK);
dgabino 0:c76361bd82e8 547 }
dgabino 0:c76361bd82e8 548 case 'l': { // lgw_mcu_commit_radio_calibration
dgabino 0:c76361bd82e8 549 int fwfromhost;
dgabino 0:c76361bd82e8 550 cmdSettings_FromHost.len_msb = BufFromHost[1];
dgabino 0:c76361bd82e8 551 cmdSettings_FromHost.len_lsb = BufFromHost[2];
dgabino 0:c76361bd82e8 552 for (i = 0; i < cmdSettings_FromHost.len_lsb + (cmdSettings_FromHost.len_msb << 8); i++) {
dgabino 0:c76361bd82e8 553 cmdSettings_FromHost.cmd_data[i] = BufFromHost[4 + i];
dgabino 0:c76361bd82e8 554 }
dgabino 0:c76361bd82e8 555 fwfromhost = (BufFromHost[4] << 24) + (BufFromHost[5] << 16) + (BufFromHost[6] << 8) + (BufFromHost[7]);
dgabino 0:c76361bd82e8 556 BufToHost[0] = 'l';
dgabino 0:c76361bd82e8 557 BufToHost[1] = 0;
dgabino 0:c76361bd82e8 558 BufToHost[2] = 8;
dgabino 0:c76361bd82e8 559 if (fwfromhost == FWVERSION) {
dgabino 0:c76361bd82e8 560 BufToHost[3] = ACK_OK;
dgabino 0:c76361bd82e8 561 } else {
dgabino 0:c76361bd82e8 562 BufToHost[3] = ACK_K0;
dgabino 0:c76361bd82e8 563 }
dgabino 0:c76361bd82e8 564 BufToHost[4] = *(uint8_t *)0x1fff7a18; //unique STM32 register base adresse
dgabino 0:c76361bd82e8 565 BufToHost[5] = *(uint8_t *)0x1fff7a19;
dgabino 0:c76361bd82e8 566 BufToHost[6] = *(uint8_t *)0x1fff7a1a;
dgabino 0:c76361bd82e8 567 BufToHost[7] = *(uint8_t *)0x1fff7a1b;
dgabino 0:c76361bd82e8 568 BufToHost[8] = *(uint8_t *)0x1fff7a10;
dgabino 0:c76361bd82e8 569 BufToHost[9] = *(uint8_t *)0x1fff7a11;
dgabino 0:c76361bd82e8 570 BufToHost[10] = *(uint8_t *)0x1fff7a12;
dgabino 0:c76361bd82e8 571 BufToHost[11] = *(uint8_t *)0x1fff7a13;
dgabino 0:c76361bd82e8 572 return(CMD_OK);
dgabino 0:c76361bd82e8 573 }
dgabino 0:c76361bd82e8 574 case 'm': { // Reset SX1308 and STM32
dgabino 0:c76361bd82e8 575 /* reset SX1308 */
dgabino 0:c76361bd82e8 576 lgw_soft_reset();
dgabino 0:c76361bd82e8 577 /* Prepare command answer */
dgabino 0:c76361bd82e8 578 BufToHost[0] = 'm';
dgabino 0:c76361bd82e8 579 BufToHost[1] = 0;
dgabino 0:c76361bd82e8 580 BufToHost[2] = 0;
dgabino 0:c76361bd82e8 581 BufToHost[3] = ACK_OK;
dgabino 0:c76361bd82e8 582 /* Indicate that STM32 reset has to be triggered */
dgabino 0:c76361bd82e8 583 kill = true;
dgabino 0:c76361bd82e8 584 return(CMD_OK);
dgabino 0:c76361bd82e8 585 }
dgabino 0:c76361bd82e8 586 case 'n': { // Jump to bootloader to allow reflashing (DFU, UART bootloader...)
dgabino 0:c76361bd82e8 587 FLASH_Prog(DATA_EEPROM_BASE, GOTO_BOOTLOADER);
dgabino 0:c76361bd82e8 588 BufToHost[0] = 'n';
dgabino 0:c76361bd82e8 589 BufToHost[1] = 0;
dgabino 0:c76361bd82e8 590 BufToHost[2] = 0;
dgabino 0:c76361bd82e8 591 BufToHost[3] = ACK_OK;
dgabino 0:c76361bd82e8 592 kill = true;
dgabino 0:c76361bd82e8 593 return(CMD_OK);
dgabino 0:c76361bd82e8 594 }
dgabino 0:c76361bd82e8 595 default:
dgabino 0:c76361bd82e8 596 BufToHost[0] = 'k';
dgabino 0:c76361bd82e8 597 BufToHost[1] = 0;
dgabino 0:c76361bd82e8 598 BufToHost[2] = 0;
dgabino 0:c76361bd82e8 599 BufToHost[3] = ACK_K0;
dgabino 0:c76361bd82e8 600 return(CMD_K0);
dgabino 0:c76361bd82e8 601 }
dgabino 0:c76361bd82e8 602 }
dgabino 0:c76361bd82e8 603
dgabino 0:c76361bd82e8 604 bool CMDMANAGER::CheckCmd(char id) {
dgabino 0:c76361bd82e8 605 switch (id) {
dgabino 0:c76361bd82e8 606 case 'r': /* read register */
dgabino 0:c76361bd82e8 607 case 's': /* read burst - first chunk */
dgabino 0:c76361bd82e8 608 case 't': /* read burst - middle chunk */
dgabino 0:c76361bd82e8 609 case 'u': /* read burst - end chunk */
dgabino 0:c76361bd82e8 610 case 'p': /* read burst - atomic */
dgabino 0:c76361bd82e8 611 case 'w': /* write register */
dgabino 0:c76361bd82e8 612 case 'x': /* write burst - first chunk */
dgabino 0:c76361bd82e8 613 case 'y': /* write burst - middle chunk */
dgabino 0:c76361bd82e8 614 case 'z': /* write burst - end chunk */
dgabino 0:c76361bd82e8 615 case 'a': /* write burst - atomic */
dgabino 0:c76361bd82e8 616 case 'b': /* lgw_receive */
dgabino 0:c76361bd82e8 617 case 'c': /* lgw_rxrf_setconf */
dgabino 0:c76361bd82e8 618 case 'd': /* lgw_rxif_setconf */
dgabino 0:c76361bd82e8 619 case 'f': /* lgw_send */
dgabino 0:c76361bd82e8 620 case 'h': /* lgw_txgain_setconf */
dgabino 0:c76361bd82e8 621 case 'q': /* lgw_get_trigcnt */
dgabino 0:c76361bd82e8 622 case 'i': /* lgw_board_setconf */
dgabino 0:c76361bd82e8 623 case 'j': /* lgw_mcu_commit_radio_calibration */
dgabino 0:c76361bd82e8 624 case 'l': /* lgw_check_fw_version */
dgabino 0:c76361bd82e8 625 case 'm': /* reset STM32 */
dgabino 0:c76361bd82e8 626 case 'n': /* Go to Bootloader */
dgabino 0:c76361bd82e8 627 return true;
dgabino 0:c76361bd82e8 628 default:
dgabino 0:c76361bd82e8 629 return false;
dgabino 0:c76361bd82e8 630 }
dgabino 0:c76361bd82e8 631 }
dgabino 0:c76361bd82e8 632
dgabino 0:c76361bd82e8 633 int CMDMANAGER::Convert2charsToByte(uint8_t a, uint8_t b) {
dgabino 0:c76361bd82e8 634 if (a > 96) {
dgabino 0:c76361bd82e8 635 a = a - 87;
dgabino 0:c76361bd82e8 636 } else {
dgabino 0:c76361bd82e8 637 a = a - 48;
dgabino 0:c76361bd82e8 638 }
dgabino 0:c76361bd82e8 639 if (b > 96) {
dgabino 0:c76361bd82e8 640 b = b - 87;
dgabino 0:c76361bd82e8 641 } else {
dgabino 0:c76361bd82e8 642 b = b - 48;
dgabino 0:c76361bd82e8 643 }
dgabino 0:c76361bd82e8 644 return(b + (a << 4));
dgabino 0:c76361bd82e8 645 }