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.
Fork of d7a_1x by
d7a_com.h
00001 #ifndef _D7A_COM_H_ 00002 #define _D7A_COM_H_ 00003 00004 #include "mbed.h" 00005 #include "rtos.h" 00006 #include "d7a_common.h" 00007 #include "d7a.h" 00008 00009 00010 typedef enum 00011 { 00012 HAL_ERROR_NONE = 0, 00013 HAL_ERROR_DEFAULT = -1, 00014 HAL_ERROR_MEM_FULL = -2, 00015 HAL_ERROR_MEM_EMPTY = -3, 00016 HAL_ERROR_MODULE_BUSY = -4, 00017 HAL_ERROR_MODULE_OFF = -5, 00018 HAL_ERROR_SERIAL_BAD_SYNC = -100, 00019 HAL_ERROR_SERIAL_BAD_SEQ = -101, 00020 HAL_ERROR_I2C_BAD_DEVID = -200, 00021 HAL_ERROR_I2C_NACK = -201, 00022 HAL_ERROR_I2C_ARB_LOST = -202, 00023 00024 } hal_error_t; 00025 00026 // +--------------+--------+--------+--------+---- - - - - - - - - - - --------+ 00027 // | SYNC | LEN | SEQ | ID | PAYLOAD | 00028 // +--------------+--------+--------+--------+---- - - - - - - - - - - --------+ 00029 // 00030 // 2 bytes 1 byte 1 byte 1 byte LEN bytes 00031 // |<------------>|<------>|<------>|<------>|<--- - - - - - - - - - - ------->| 00032 00033 00034 // first byte of the sync word 00035 // (ASCII start of heading) 00036 #define KAL_COM_SYNC_BYTE_0 0x01 00037 00038 // second byte of the sync word 00039 // (ASCII group separator) 00040 #define KAL_COM_SYNC_BYTE_1 0x1F 00041 00042 // message header length in byte 00043 #define KAL_COM_HEADER_LEN 5 00044 00045 00046 //====================================================================== 00047 // d7a_com_fid_t 00048 //---------------------------------------------------------------------- 00049 // Enumerator of serial Flow-ids 00050 //====================================================================== 00051 typedef enum 00052 { 00053 // Trace channel 00054 KAL_COM_FLOWID_TRC = 0, 00055 // General purpose Command channel 00056 KAL_COM_FLOWID_CMD, 00057 // ALP channel 00058 KAL_COM_FLOWID_ALP, 00059 // System notifications 00060 KAL_COM_FLOWID_SYS, 00061 // File System channel 00062 KAL_COM_FLOWID_FS, 00063 00064 KAL_COM_FLOWID_QTY 00065 00066 } d7a_com_fid_t; 00067 00068 #define KAL_COM_FLOW(fid,type) ((((fid)&0x7)<<4) | ((type)&0xF)) 00069 #define KAL_COM_FLOWID(id) (((id)>>4)&0x7) 00070 #define KAL_COM_FLOWID_REDIRECT 0x80 00071 00072 //====================================================================== 00073 // d7a_com_flow_t 00074 //---------------------------------------------------------------------- 00075 // Enumerator of serial flows 00076 //====================================================================== 00077 typedef enum 00078 { 00079 // Default printf type 00080 KAL_COM_FLOW_PRINTF = KAL_COM_FLOW(KAL_COM_FLOWID_TRC,0), 00081 // Substitute the string by a codeword 00082 // interpreted by the PC com tool 00083 KAL_COM_FLOW_PRINTF_COMPRESSED = KAL_COM_FLOW(KAL_COM_FLOWID_TRC,1), 00084 // Display the payload as hex data 00085 KAL_COM_FLOW_PRINT_HEX = KAL_COM_FLOW(KAL_COM_FLOWID_TRC,2), 00086 00087 // AT command 00088 KAL_COM_FLOW_AT_CMD = KAL_COM_FLOW(KAL_COM_FLOWID_ALP,0), 00089 // AT command response 00090 KAL_COM_FLOW_AT_RESP = KAL_COM_FLOW(KAL_COM_FLOWID_ALP,1), 00091 // AT unsolicited message 00092 KAL_COM_FLOW_AT_UNS = KAL_COM_FLOW(KAL_COM_FLOWID_ALP,2), 00093 // AT unsolicited error 00094 KAL_COM_FLOW_AT_ERR = KAL_COM_FLOW(KAL_COM_FLOWID_ALP,3), 00095 00096 // Remote Commands 00097 KAL_COM_FLOW_CMD = KAL_COM_FLOW(KAL_COM_FLOWID_CMD,0), 00098 00099 // Remote System reset 00100 KAL_COM_FLOW_SYS_RST = KAL_COM_FLOW(KAL_COM_FLOWID_SYS,0), 00101 // Button Emulator 00102 KAL_COM_FLOW_SYS_BUTTON = KAL_COM_FLOW(KAL_COM_FLOWID_SYS,1), 00103 // Dump Debug parameters 00104 KAL_COM_FLOW_SYS_INFO = KAL_COM_FLOW(KAL_COM_FLOWID_SYS,2), 00105 // CUP signalisation 00106 KAL_COM_FLOW_SYS_CUP = KAL_COM_FLOW(KAL_COM_FLOWID_SYS,3), 00107 // Ping distant COM 00108 KAL_COM_FLOW_SYS_PING = KAL_COM_FLOW(KAL_COM_FLOWID_SYS,4), 00109 // Pong from distant COM 00110 KAL_COM_FLOW_SYS_PONG = KAL_COM_FLOW(KAL_COM_FLOWID_SYS,5), 00111 // Enable system config from distant COM 00112 KAL_COM_FLOW_SYS_CFG = KAL_COM_FLOW(KAL_COM_FLOWID_SYS,6), 00113 // Configure Output Trace level from distant COM 00114 KAL_COM_FLOW_SYS_TLEV = KAL_COM_FLOW(KAL_COM_FLOWID_SYS,7), 00115 // Configure COM port redirection 00116 KAL_COM_FLOW_SYS_REDIR = KAL_COM_FLOW(KAL_COM_FLOWID_SYS,8), 00117 // Flow control signalling 00118 KAL_COM_FLOW_SYS_XON = KAL_COM_FLOW(KAL_COM_FLOWID_SYS,9), 00119 KAL_COM_FLOW_SYS_XOFF = KAL_COM_FLOW(KAL_COM_FLOWID_SYS,10), 00120 KAL_COM_FLOW_SYS_XACK = KAL_COM_FLOW(KAL_COM_FLOWID_SYS,11), 00121 00122 // File System Command/Response 00123 KAL_COM_FLOW_FS_CMD = KAL_COM_FLOW(KAL_COM_FLOWID_FS,0), 00124 KAL_COM_FLOW_FS_RESP = KAL_COM_FLOW(KAL_COM_FLOWID_FS,1), 00125 00126 } d7a_com_flow_t; 00127 00128 00129 //====================================================================== 00130 // d7a_com_tx_msg_t 00131 //---------------------------------------------------------------------- 00132 // Transmit message structure 00133 //====================================================================== 00134 typedef struct 00135 { 00136 // identifier d7a_com_flow_t 00137 uint8_t id; 00138 // length of the string buffer defined by a pointer 00139 uint8_t plen; 00140 // length of the allocated buffer 00141 uint8_t alen; 00142 // pointer to a string buffer that does not need to be freed 00143 uint8_t* pbuf; 00144 // pointer to argument that does not need to be freed 00145 uint8_t* abuf; 00146 00147 } d7a_com_tx_msg_t; 00148 00149 //====================================================================== 00150 // d7a_com_rx_msg_t 00151 //---------------------------------------------------------------------- 00152 // Receive message structure 00153 //====================================================================== 00154 typedef struct 00155 { 00156 // error message 00157 hal_error_t err; 00158 // length of the log (string) buffer 00159 uint8_t blen; 00160 // identifier d7a_com_flow_t 00161 uint8_t id; 00162 // Com port where the message came from 00163 uint8_t com_id; 00164 // pointer to the log buffer 00165 uint8_t buffer[1]; 00166 00167 } d7a_com_rx_msg_t; 00168 00169 00170 d7a_errors_t d7a_com_open( const d7a_com_config_t* config ); 00171 d7a_errors_t d7a_com_close(); 00172 void d7a_com_post_msg(d7a_com_tx_msg_t* msg); 00173 void d7a_com_dump(uint8_t* buf, uint8_t len, d7a_com_flow_t flow); 00174 d7a_com_rx_msg_t* d7a_com_wait_pkt(uint32_t millisec = osWaitForever); 00175 void d7a_com_start_rx(void); 00176 void d7a_com_stop_rx(void); 00177 void d7a_com_start_tx(void); 00178 void d7a_com_stop_tx(void); 00179 void d7a_com_restart(void); 00180 void d7a_com_print_stats(void); 00181 00182 #endif // _D7A_COM_H_
Generated on Sun Jul 17 2022 09:41:51 by
1.7.2
