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 #ifndef USBMANAGER_H
dgabino 0:c76361bd82e8 11 #define USBMANAGER_H
dgabino 0:c76361bd82e8 12
dgabino 0:c76361bd82e8 13 #include "mbed.h"
dgabino 0:c76361bd82e8 14 #include "SX1308.h"
dgabino 0:c76361bd82e8 15
dgabino 0:c76361bd82e8 16 #define ATOMICTX 900
dgabino 0:c76361bd82e8 17 #define ATOMICRX 600
dgabino 0:c76361bd82e8 18
dgabino 0:c76361bd82e8 19 #define CMD_HEADER_RX_SIZE 4 /* id + len_msb + len_lsb + address */
dgabino 0:c76361bd82e8 20 #define CMD_HEADER_TX_SIZE 4 /* id + len_msb + len_lsb + status */
dgabino 0:c76361bd82e8 21
dgabino 0:c76361bd82e8 22 #define CMD_DATA_RX_SIZE ATOMICRX
dgabino 0:c76361bd82e8 23 #define CMD_DATA_TX_SIZE (1024 + 16 * 44) /* MAX_FIFO + 16 * METADATA_SIZE_ALIGNED */
dgabino 0:c76361bd82e8 24 #define CMD_LENGTH_MSB 1
dgabino 0:c76361bd82e8 25 #define CMD_LENGTH_LSB 2
dgabino 0:c76361bd82e8 26
dgabino 0:c76361bd82e8 27 #define CMD_ERROR 0
dgabino 0:c76361bd82e8 28 #define CMD_OK 1
dgabino 0:c76361bd82e8 29 #define CMD_K0 0
dgabino 0:c76361bd82e8 30 #define ACK_OK 1
dgabino 0:c76361bd82e8 31 #define ACK_K0 0
dgabino 0:c76361bd82e8 32 #define FWVERSION 0x010a0006
dgabino 0:c76361bd82e8 33 #define ISUARTINTERFACE 1
dgabino 0:c76361bd82e8 34 #define ISUSBINTERFACE 0
dgabino 0:c76361bd82e8 35
dgabino 0:c76361bd82e8 36 #define BAUDRATE 115200
dgabino 0:c76361bd82e8 37
dgabino 0:c76361bd82e8 38 typedef struct {
dgabino 0:c76361bd82e8 39 char id;
dgabino 0:c76361bd82e8 40 uint8_t len_msb;
dgabino 0:c76361bd82e8 41 uint8_t len_lsb;
dgabino 0:c76361bd82e8 42 uint8_t address;
dgabino 0:c76361bd82e8 43 uint8_t cmd_data[CMD_DATA_RX_SIZE];
dgabino 0:c76361bd82e8 44 } CmdSettings_t;
dgabino 0:c76361bd82e8 45
dgabino 0:c76361bd82e8 46
dgabino 0:c76361bd82e8 47 class INTERFACE {
dgabino 0:c76361bd82e8 48
dgabino 0:c76361bd82e8 49 public:
dgabino 0:c76361bd82e8 50 INTERFACE();
dgabino 0:c76361bd82e8 51 virtual void Init() =0;
dgabino 0:c76361bd82e8 52 virtual void Receive(uint8_t* Buffer, uint32_t* size) = 0;
dgabino 0:c76361bd82e8 53 virtual void Transmit(uint8_t* Buffer, uint16_t size) = 0;
dgabino 0:c76361bd82e8 54 private:
dgabino 0:c76361bd82e8 55
dgabino 0:c76361bd82e8 56 };
dgabino 0:c76361bd82e8 57
dgabino 0:c76361bd82e8 58 class COMUSB : INTERFACE {
dgabino 0:c76361bd82e8 59 public:
dgabino 0:c76361bd82e8 60 // public methods
dgabino 0:c76361bd82e8 61 COMUSB();
dgabino 0:c76361bd82e8 62 virtual void Init();
dgabino 0:c76361bd82e8 63 virtual void Receive(uint8_t* Buffer, uint32_t* size);
dgabino 0:c76361bd82e8 64 virtual void Transmit(uint8_t* Buffer, uint16_t size);
dgabino 0:c76361bd82e8 65 private:
dgabino 0:c76361bd82e8 66 // private methods
dgabino 0:c76361bd82e8 67 };
dgabino 0:c76361bd82e8 68
dgabino 0:c76361bd82e8 69 class COMUART : public Serial, public INTERFACE{
dgabino 0:c76361bd82e8 70
dgabino 0:c76361bd82e8 71 public:
dgabino 0:c76361bd82e8 72 // public members
dgabino 0:c76361bd82e8 73 COMUART(PinName Tx, PinName Rx);
dgabino 0:c76361bd82e8 74 virtual void Init();
dgabino 0:c76361bd82e8 75 virtual void Receive(uint8_t* Buffer, uint32_t* size);
dgabino 0:c76361bd82e8 76 virtual void Transmit(uint8_t* Buffer, uint16_t size);
dgabino 0:c76361bd82e8 77 private:
dgabino 0:c76361bd82e8 78 // private methods
dgabino 0:c76361bd82e8 79 };
dgabino 0:c76361bd82e8 80
dgabino 0:c76361bd82e8 81 class CMDMANAGER {
dgabino 0:c76361bd82e8 82
dgabino 0:c76361bd82e8 83 public:
dgabino 0:c76361bd82e8 84 // public members
dgabino 0:c76361bd82e8 85 uint8_t BufFromHost[CMD_DATA_RX_SIZE + CMD_HEADER_RX_SIZE];
dgabino 0:c76361bd82e8 86 uint8_t BufFromHostChunk[64];
dgabino 0:c76361bd82e8 87 uint8_t BufToHost[CMD_DATA_TX_SIZE + CMD_HEADER_TX_SIZE];
dgabino 0:c76361bd82e8 88 uint32_t receivelength[5];
dgabino 0:c76361bd82e8 89 volatile uint32_t count;
dgabino 0:c76361bd82e8 90 int ActiveCom;
dgabino 0:c76361bd82e8 91 bool kill;
dgabino 0:c76361bd82e8 92 INTERFACE * ActiveInterface;
dgabino 0:c76361bd82e8 93
dgabino 0:c76361bd82e8 94 // public methods
dgabino 0:c76361bd82e8 95 CMDMANAGER(PinName Tx, PinName Rx);
dgabino 0:c76361bd82e8 96 void Init();
dgabino 0:c76361bd82e8 97 void ReceiveCmd();
dgabino 0:c76361bd82e8 98 void TransmitCmd();
dgabino 0:c76361bd82e8 99 void InitBufFromHost();
dgabino 0:c76361bd82e8 100 void InitBufToHost();
dgabino 0:c76361bd82e8 101 int DecodeCmd();
dgabino 0:c76361bd82e8 102 bool CheckCmd(char id);
dgabino 0:c76361bd82e8 103
dgabino 0:c76361bd82e8 104 private:
dgabino 0:c76361bd82e8 105 // private methods
dgabino 0:c76361bd82e8 106 int Convert2charsToByte(uint8_t a, uint8_t b);
dgabino 0:c76361bd82e8 107 };
dgabino 0:c76361bd82e8 108
dgabino 0:c76361bd82e8 109 extern CMDMANAGER CmdManager;
dgabino 0:c76361bd82e8 110 #endif