Timothy Mulrooney / Mbed 2 deprecated frdm_i2c_test

Dependencies:   PinDetect libmDot mbed-rtos mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers common.h Source File

common.h

Go to the documentation of this file.
00001 /* ========================================
00002  * Filename: common.h
00003  *
00004  * Description: common defintions and structures
00005  *
00006  * Copyright J-Factor Embedded Technologies 2015
00007  * Copyright TJM Embedded Software 2015
00008  * All Rights Reserved
00009  * UNPUBLISHED, LICENSED SOFTWARE.
00010  *
00011  * CONFIDENTIAL AND PROPRIETARY INFORMATION
00012  * WHICH IS THE PROPERTY OF J-Factor Embedded Technologies.
00013  *
00014  * ========================================
00015 */
00016 /** \file
00017  * \brief contains constants and prototypes needed by other files.
00018  */
00019 #ifndef COMMON_H
00020 #define COMMON_H
00021  
00022 #include <time.h>
00023 #include "mbed.h"
00024  
00025 /* Project Defines */
00026 #define FALSE  0
00027 #define TRUE   1
00028 #define TRANSMIT_BUFFER_SIZE  80    //!< maximum number of characters to write to console
00029 #define LINE_SIZE  80               //!< maximum number of characters to read from console
00030 #define NUM_LINES 10                //!< number of command lines to save       
00031 
00032 /* version history */
00033 /*
00034 Version Author  Date        Description
00035 0.1     TJM     01/24/15    Initial Draft
00036 0.2     TJM     01/24/166   first with CLI interface
00037 */
00038  
00039 #define VERSION_MAJOR 0
00040 #define VERSION_MINOR 2
00041 #define VERSION_DATE "01/26/16"
00042 
00043 typedef unsigned char uint8;
00044 typedef signed char int8;
00045 typedef unsigned short uint16;
00046 typedef signed short int16;
00047 typedef unsigned long uint32;
00048 typedef signed long int32;
00049 typedef unsigned int uint;
00050   
00051 /* parameter type */
00052 #define BINARY  0
00053 #define DIGITAL 1
00054 #define REGISTER 2
00055 #define ANALOG  3
00056 
00057 /* command defintions */
00058 #define HELP        0
00059 #define VERSION     1
00060 #define READ        2
00061 #define READ_REG    3
00062 #define WRITE       4
00063 #define WRITE_REG   5
00064 #define INFO        6
00065 #define FIND        7
00066 #define RUN         8
00067 #define STOP        9
00068 #define DATE        10
00069 #define HVSTATE     11
00070 
00071 /* mode */
00072 #define READONLY    0
00073 #define WRITEONLY   1
00074 #define READWRITE   2
00075 
00076 #define MAX_REGISTER_DATA 128
00077 
00078 /* parameter names */
00079 enum 
00080 {
00081      spi,
00082      i2c,
00083 } ;    
00084      
00085 typedef   uint8 (*Read)(void);                                          //!< read function template to return 8 bit unsigned int
00086 typedef   uint16 (*ReadRegLength)(uint16 regAddress, uint8 *regData, uint16 length);  //!< read function template to return 8 bit unsigned int
00087 typedef   void (*Write8)(uint8 value);      //!< write function template to write 8 bit unsigned value
00088 typedef   void (*WriteReg8)(uint16 regAddress, uint8 *regData);      //!< write function template to write 8 bit unsigned value
00089 typedef   void (*Write16)(uint16 value);    //!< write function template to write 16 bit unsigned value
00090 typedef   void (*WriteAnalog)(float fltValue);    //!< write function template to write analog value
00091 
00092 /* paramater structure */
00093 struct parameterInfo                        //!< paramter information structure
00094 {
00095     char *name;                             //!< paramter name
00096     char *port;                             //!< port location (if applicable) on device
00097     char *connector;                        //!< connector location (if applicable) on board
00098     char *description;                      //!< brief parameter function and use
00099     uint8 type;                             //!< binary, digital, or analog
00100     char *uints;                            //!< parameter units (if applicable)
00101     uint8 mode;                             //!< read only, write only, read write
00102     uint16 initialInt;                      //!< initial value if binary or digital
00103     uint16 minInt;                          //!< minimum value if binary or digital
00104     uint16 maxInt;                          //!< maximum value if binary or digital
00105     float initialFloat;                     //!< initial value if analog
00106     float minFloat;                         //!< minimum value if analog
00107     float maxFloat;                         //!< maximum value if analog
00108     Read ptrRead;                           //!< read function needed for this parameter  (null if not needed)
00109     ReadRegLength ptrReadRegLength;         //!< read function needed for this parameter  (null if not needed)
00110     Write8 ptrWrite8;                       //!< 8 bit write function needed for this paramater (null if not needed) 
00111     WriteReg8 ptrWriteReg8;                 //!< 8 bit write function needed for this paramater (null if not needed) 
00112     Write16 ptrWrite16;                     //!< 16 bit write function needed for this paramater (null if not needed) 
00113     WriteAnalog ptrWriteAnalog;             //!< analog write function needed for this paramater (null if not needed) 
00114 };
00115 
00116 
00117 /* function prototypes */
00118 void printVersion();
00119 uint8 getLine(); 
00120 void executeCmd();
00121 int8 getCmd();
00122 void setDate(char *str);
00123 void date(void);
00124 int8 getParameter(char *param);
00125 int8 findParameter(char *string);
00126 uint8 readParam(uint8 paramNum);
00127 void writeParam(uint8 paramNum,uint8 *value);
00128 float strtofloat (char *str);
00129 uint16 power(uint8 num, uint8 pow);
00130 void displayParameter(uint8 num);
00131 uint8 tolower(uint8 c);
00132 uint16 readSPIReg(uint16 regAddress, uint8 *regData, uint16 length);
00133 void writeSPIReg(uint16 regAddress, uint8 *regData);
00134 void SPIRead(uint16 addr, uint8 *data, int length);
00135 void SPIWrite(uint16 addr, uint8 *data, int length);
00136 uint16 readI2CReg(uint16 regAddress, uint8 *regData, uint16 length);
00137 void writeI2CReg(uint16 regAddress, uint8 *regData);
00138 void I2CRead(uint16 addr, uint8 *data, int length);
00139 void I2CWrite(uint16 addr, uint8 *data, int length);
00140 
00141 /* externals */
00142 extern Serial pc;
00143 extern char* c_time_string;
00144 extern char time_string[];
00145 extern char TransmitBuffer[TRANSMIT_BUFFER_SIZE];
00146 extern time_t epoch;
00147 extern struct parameterInfo parameters[];
00148 extern uint16 bytesRead;
00149 
00150 #endif
00151 /* [] END OF FILE */