Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
cmdUSB.h
00001 /* 00002 / _____) _ | | 00003 ( (____ _____ ____ _| |_ _____ ____| |__ 00004 \____ \| ___ | (_ _) ___ |/ ___) _ \ 00005 _____) ) ____| | | || |_| ____( (___| | | | 00006 (______/|_____)_|_|_| \__)_____)\____)_| |_| 00007 (C)2017 Semtech 00008 */ 00009 00010 #ifndef USBMANAGER_H 00011 #define USBMANAGER_H 00012 00013 #include "mbed.h" 00014 #include "SX1308.h" 00015 00016 #define ATOMICTX 900 00017 #define ATOMICRX 600 00018 00019 #define CMD_HEADER_RX_SIZE 4 /* id + len_msb + len_lsb + address */ 00020 #define CMD_HEADER_TX_SIZE 4 /* id + len_msb + len_lsb + status */ 00021 00022 #define CMD_DATA_RX_SIZE ATOMICRX 00023 #define CMD_DATA_TX_SIZE (1024 + 16 * 44) /* MAX_FIFO + 16 * METADATA_SIZE_ALIGNED */ 00024 #define CMD_LENGTH_MSB 1 00025 #define CMD_LENGTH_LSB 2 00026 00027 #define CMD_ERROR 0 00028 #define CMD_OK 1 00029 #define CMD_K0 0 00030 #define ACK_OK 1 00031 #define ACK_K0 0 00032 #define FWVERSION 0x010a0006 00033 #define ISUARTINTERFACE 1 00034 #define ISUSBINTERFACE 0 00035 00036 #define BAUDRATE 115200 00037 00038 typedef struct { 00039 char id; 00040 uint8_t len_msb; 00041 uint8_t len_lsb; 00042 uint8_t address; 00043 uint8_t cmd_data[CMD_DATA_RX_SIZE]; 00044 } CmdSettings_t; 00045 00046 00047 class INTERFACE { 00048 00049 public: 00050 INTERFACE(); 00051 virtual void Init() =0; 00052 virtual void Receive(uint8_t* Buffer, uint32_t* size) = 0; 00053 virtual void Transmit(uint8_t* Buffer, uint16_t size) = 0; 00054 private: 00055 00056 }; 00057 00058 class COMUSB : INTERFACE { 00059 public: 00060 // public methods 00061 COMUSB(); 00062 virtual void Init(); 00063 virtual void Receive(uint8_t* Buffer, uint32_t* size); 00064 virtual void Transmit(uint8_t* Buffer, uint16_t size); 00065 private: 00066 // private methods 00067 }; 00068 00069 class COMUART : public Serial, public INTERFACE{ 00070 00071 public: 00072 // public members 00073 COMUART(PinName Tx, PinName Rx); 00074 virtual void Init(); 00075 virtual void Receive(uint8_t* Buffer, uint32_t* size); 00076 virtual void Transmit(uint8_t* Buffer, uint16_t size); 00077 private: 00078 // private methods 00079 }; 00080 00081 class CMDMANAGER { 00082 00083 public: 00084 // public members 00085 uint8_t BufFromHost[CMD_DATA_RX_SIZE + CMD_HEADER_RX_SIZE]; 00086 uint8_t BufFromHostChunk[64]; 00087 uint8_t BufToHost[CMD_DATA_TX_SIZE + CMD_HEADER_TX_SIZE]; 00088 uint32_t receivelength[5]; 00089 volatile uint32_t count; 00090 int ActiveCom; 00091 bool kill; 00092 INTERFACE * ActiveInterface; 00093 00094 // public methods 00095 CMDMANAGER(PinName Tx, PinName Rx); 00096 void Init(); 00097 void ReceiveCmd(); 00098 void TransmitCmd(); 00099 void InitBufFromHost(); 00100 void InitBufToHost(); 00101 int DecodeCmd(); 00102 bool CheckCmd(char id); 00103 00104 private: 00105 // private methods 00106 int Convert2charsToByte(uint8_t a, uint8_t b); 00107 }; 00108 00109 extern CMDMANAGER CmdManager; 00110 #endif
Generated on Tue Jul 12 2022 22:19:20 by
