biotac.h
Go to the documentation of this file.
00001 #ifndef BIOTAC_H_
00002 #define BIOTAC_H_
00003 
00004 #define MAX_BIOTACS_PER_CHEETAH                                                 3 // should be either 3 or 5
00005 
00006 //=========================================================================
00007 // DEFAULT CONSTANTS
00008 //=========================================================================
00009 #define BT_SPI_BITRATE_KHZ_DEFAULT                                              4400
00010 #define BT_AFTERSAMPLE_DELAY_DEFAULT                                    50000           /* Delay after sampling command */
00011 #define BT_INTERWORD_DELAY_DEFAULT                                              10000           /* Delay between words in communication */
00012 #define BT_SAMPLE_RATE_HZ_DEFAULT                                               4400
00013 #define BT_FRAMES_IN_BATCH_DEFAULT                                              5
00014 #define BT_BATCH_MS_DEFAULT                                                             50
00015 #define BT_FRAME_STRUCTURE_DEFAULT                                      {\
00016                                                                                                                 BT_E01_SAMPLING_COMMAND, BT_PAC_SAMPLING_COMMAND, BT_E02_SAMPLING_COMMAND, BT_PAC_SAMPLING_COMMAND, \
00017                                                                                                                 BT_E03_SAMPLING_COMMAND, BT_PAC_SAMPLING_COMMAND, BT_E04_SAMPLING_COMMAND, BT_PAC_SAMPLING_COMMAND, \
00018                                                                                                                 BT_E05_SAMPLING_COMMAND, BT_PAC_SAMPLING_COMMAND, BT_E06_SAMPLING_COMMAND, BT_PAC_SAMPLING_COMMAND, \
00019                                                                                                                 BT_E07_SAMPLING_COMMAND, BT_PAC_SAMPLING_COMMAND, BT_E08_SAMPLING_COMMAND, BT_PAC_SAMPLING_COMMAND, \
00020                                                                                                                 BT_E09_SAMPLING_COMMAND, BT_PAC_SAMPLING_COMMAND, BT_E10_SAMPLING_COMMAND, BT_PAC_SAMPLING_COMMAND, \
00021                                                                                                                 BT_E11_SAMPLING_COMMAND, BT_PAC_SAMPLING_COMMAND, BT_E12_SAMPLING_COMMAND, BT_PAC_SAMPLING_COMMAND, \
00022                                                                                                                 BT_E13_SAMPLING_COMMAND, BT_PAC_SAMPLING_COMMAND, BT_E14_SAMPLING_COMMAND, BT_PAC_SAMPLING_COMMAND, \
00023                                                                                                                 BT_E15_SAMPLING_COMMAND, BT_PAC_SAMPLING_COMMAND, BT_E16_SAMPLING_COMMAND, BT_PAC_SAMPLING_COMMAND, \
00024                                                                                                                 BT_E17_SAMPLING_COMMAND, BT_PAC_SAMPLING_COMMAND, BT_E18_SAMPLING_COMMAND, BT_PAC_SAMPLING_COMMAND, \
00025                                                                                                                 BT_E19_SAMPLING_COMMAND, BT_PAC_SAMPLING_COMMAND, BT_PDC_SAMPLING_COMMAND, BT_PAC_SAMPLING_COMMAND, \
00026                                                                                                                 BT_TAC_SAMPLING_COMMAND, BT_PAC_SAMPLING_COMMAND, BT_TDC_SAMPLING_COMMAND, BT_PAC_SAMPLING_COMMAND, '\0'}
00027 #ifndef BOOL
00028 typedef int                                                                                             BOOL;
00029 #endif
00030 #define PARITY_GOOD                                                                             (BOOL)0
00031 #define PARITY_BAD                                                                              (BOOL)!PARITY_GOOD
00032 
00033 
00034 //==================================================//
00035 // SPI Chip Select control signal //
00036 //==================================================//
00037 #define CS_ALL_BT                                                                               0x07                                    //0b00000111
00038 #define CS_NONE_BT                                                                              0x00                                    //0b00000000
00039 #define CS_BT1                                                                                  0x01                                    //0b00000001
00040 #define CS_BT2                                                                                  0x02                                    //0b00000010
00041 #define CS_BT3                                                                                  0x04                                    //0b00000100
00042 #if MAX_BIOTACS_PER_CHEETAH == 5
00043         #define CS_BT4                                                                          0x05                                    //0b00000101
00044         #define CS_BT5                                                                          0x06                                    //0b00000110
00045 #endif
00046 
00047 //==================================================//
00048 // SPI version 2 commands define //
00049 //==================================================//
00050 #define COMMAND_LENGTH_BYTE                                                             2
00051 // sampling command //
00052 #define SAMPLE_COMMAND                                                                  0x80                                    //0b10000000
00053 #define BT_PAC_SAMPLING                                                                 0                                               // // command index: 00
00054 #define BT_PDC_SAMPLING                                                                 1                                               // // command index: 01
00055 #define BT_TAC_SAMPLING                                                                 2                                               // // command index: 02
00056 #define BT_TDC_SAMPLING                                                                 3                                               // // command index: 03
00057 
00058 #define BT_E01_SAMPLING                                                                 17                                              // // command index: 17
00059 #define BT_E02_SAMPLING                                                                 18                                              // // command index: 18
00060 #define BT_E03_SAMPLING                                                                 19                                              // // command index: 19
00061 #define BT_E04_SAMPLING                                                                 20                                              // // command index: 20
00062 #define BT_E05_SAMPLING                                                                 21                                              // // command index: 21
00063 #define BT_E06_SAMPLING                                                                 22                                              // // command index: 22
00064 #define BT_E07_SAMPLING                                                                 23                                              // // command index: 23
00065 #define BT_E08_SAMPLING                                                                 24                                              // // command index: 24
00066 #define BT_E09_SAMPLING                                                                 25                                              // // command index: 25
00067 #define BT_E10_SAMPLING                                                                 26                                              // // command index: 26
00068 #define BT_E11_SAMPLING                                                                 27                                              // // command index: 27
00069 #define BT_E12_SAMPLING                                                                 28                                              // // command index: 28
00070 #define BT_E13_SAMPLING                                                                 29                                              // // command index: 29
00071 #define BT_E14_SAMPLING                                                                 30                                              // // command index: 30
00072 #define BT_E15_SAMPLING                                                                 31                                              // // command index: 31
00073 #define BT_E16_SAMPLING                                                                 32                                              // // command index: 32
00074 #define BT_E17_SAMPLING                                                                 33                                              // // command index: 33
00075 #define BT_E18_SAMPLING                                                                 34                                              // // command index: 34
00076 #define BT_E19_SAMPLING                                                                 35                                              // // command index: 35
00077 
00078 #define BT_PAC_SAMPLING_COMMAND                                                 0x80                                    //0b10000000                            // command index: 00
00079 #define BT_PDC_SAMPLING_COMMAND                                                 0x83                                    //0b10000011                            // command index: 01
00080 #define BT_TAC_SAMPLING_COMMAND                                                 0x85                                    //0b10000101                            // command index: 02
00081 #define BT_TDC_SAMPLING_COMMAND                                                 0x86                                    //0b10000110                            // command index: 03
00082 
00083 #define BT_HAL_SAMPLING_COMMAND                                                 0x9E                                    //0b10011110                            // command index: 15
00084 
00085 #define BT_E01_SAMPLING_COMMAND                                                 0xA2                                    //0b10100010                            // command index: 17
00086 #define BT_E02_SAMPLING_COMMAND                                                 0xA4                                    //0b10100100                            // command index: 18
00087 #define BT_E03_SAMPLING_COMMAND                                                 0xA7                                    //0b10100111                            // command index: 19
00088 #define BT_E04_SAMPLING_COMMAND                                                 0xA8                                    //0b10101000                            // command index: 20
00089 #define BT_E05_SAMPLING_COMMAND                                                 0xAB                                    //0b10101011                            // command index: 21
00090 #define BT_E06_SAMPLING_COMMAND                                                 0xAD                                    //0b10101101                            // command index: 22
00091 #define BT_E07_SAMPLING_COMMAND                                                 0xAE                                    //0b10101110                            // command index: 23
00092 #define BT_E08_SAMPLING_COMMAND                                                 0xB0                                    //0b10110000                            // command index: 24
00093 #define BT_E09_SAMPLING_COMMAND                                                 0xB3                                    //0b10110011                            // command index: 25
00094 #define BT_E10_SAMPLING_COMMAND                                                 0xB5                                    //0b10110101                            // command index: 26
00095 #define BT_E11_SAMPLING_COMMAND                                                 0xB6                                    //0b10110110                            // command index: 27
00096 #define BT_E12_SAMPLING_COMMAND                                                 0xB9                                    //0b10111001                            // command index: 28
00097 #define BT_E13_SAMPLING_COMMAND                                                 0xBA                                    //0b10111010                            // command index: 29
00098 #define BT_E14_SAMPLING_COMMAND                                                 0xBC                                    //0b10111100                            // command index: 30
00099 #define BT_E15_SAMPLING_COMMAND                                                 0xBF                                    //0b10111111                            // command index: 31
00100 #define BT_E16_SAMPLING_COMMAND                                                 0xC1                                    //0b11000001                            // command index: 32
00101 #define BT_E17_SAMPLING_COMMAND                                                 0xC2                                    //0b11000010                            // command index: 33
00102 #define BT_E18_SAMPLING_COMMAND                                                 0xC4                                    //0b11000100                            // command index: 34
00103 #define BT_E19_SAMPLING_COMMAND                                                 0xC7                                    //0b11000111                            // command index: 35
00104 
00105 // resend command //
00106 #define BT_RESEND_COMMAND                                                               0x20                                    //0b00100000
00107 
00108 // read command //
00109 #define BT_READ_COMMAND                                                                 0x61                                    //0b01100001
00110 
00111         #define BT_FLEX_VERSION_READ_COMMAND                            0x10                                    //0b00010000
00112         #define BT_FLEX_VERSIOM_READ_LENGTH                                     2
00113 
00114         #define BT_FIRMWARE_VERSION_READ_COMMAND                        0x13                                    //0b00010011
00115         #define BT_FIRMWARE_VERSION_READ_LENGTH                         4
00116 
00117         #define BT_SERIAL_NUMBER_READ_COMMAND                           0x15                                    //0b00010101
00118         #define BT_SERIAL_NUMBER_READ_LENGTH                            16
00119 
00120         #define BT_CPU_SPEED_READ_COMMAND                                       0x61                                    //0b01100001
00121         #define BT_CPU_SPEED_READ_LENGTH                                        2
00122 
00123         #define BT_SAMPLING_FREQUENCY_READ_COMMAND                      0x70                                    //0b01110000
00124         #define BT_SAMPLING_FREQUENCY_READ_LENGTH                       2
00125 
00126         #define BT_SAMPLING_PATTERN_READ_COMMAND                        0x73                                    //0b01110011
00127         #define BT_SAMPLING_PATTERN_READ_LENGTH                         44
00128 
00129 #define BT_READ_PROPERTY_COMMAND_ARRAY                                  {\
00130                                                         BT_FIRMWARE_VERSION_READ_COMMAND, \
00131                                                                                                                 BT_FLEX_VERSION_READ_COMMAND, \
00132                                                         BT_FIRMWARE_VERSION_READ_COMMAND, \
00133                                                                                                                 BT_SERIAL_NUMBER_READ_COMMAND,  \
00134                                                                                                                 BT_CPU_SPEED_READ_COMMAND}
00135 
00136 //==================================================//
00137 // SPI version 2 Error Code define //
00138 //==================================================//
00139 #define BT_ERROR_PARITY_CHECK                                                   0xA545                                  // 0b10100101 01000101, "EE"
00140 #define BT_ERROR_UNKNOWN_COMMAND                                                0xA53F                                  // 0b10100101 00111111, "E?"
00141 #define BT_ERROR_INSUFFICIENT_DELAY                                             0xA52E                                  // 0b10100101 00101110, "E."
00142 #define BT_ERROR_INSUFFICIENT_SAMPLING_DELAY                    0xA52D                                  // 0b10100101 00101101, "E-"
00143 #define BT_ERROR_CHANNEL_NOT_RECOGNIZED                                 0xA558                                  // 0b10100101 01011000, "EX"
00144 #define BT_ERROR_NO_DATA_TO_RESEND                                              0xA55F                                  // 0b10100101 01011111, "E_"
00145 #define BT_ERROR_PARAMETER_IS_READ_ONLY                                 0xA552                                  // 0b10100101 01010010, "ER"
00146 #define BT_ERROR_ERROR_WRITING_DATA                                             0xA557                                  // 0b10100101 01010111, "EW"
00147 
00148 
00149 #define BT_OK                                0
00150 #define BT_WRONG_NUMBER_ASSIGNED            -1
00151 #define BT_NO_BIOTAC_DETECTED               -2
00152 #define BT_WRONG_MAX_BIOTAC_NUMBER          -3
00153 #define BT_DATA_SIZE_TOO_SMALL              -4
00154 #define BT_NO_CHEETAH_DETECTED              -5
00155 #define BT_UNABLE_TO_OPEN_CHEETAH           -6
00156 #define BT_UNABLE_TO_OPEN_FILE              -7
00157 
00158 #define PRINT_ON                             0
00159 
00160 //================
00161 // Necessary Includes
00162 //================
00163 #include "cheetah.h"
00164 
00165 //==================================================//
00166 // Data structure definition //
00167 //==================================================//
00168 typedef int BioTac;
00169 
00170 typedef struct
00171 {
00172         int index;
00173         double time;
00174         double frame_index;
00175         double batch_index;
00176         u08 channel_id;
00177         union
00178         {
00179                 u16 word;
00180                 u08 byte[2];
00181         } d[MAX_BIOTACS_PER_CHEETAH];
00182         u08 bt_parity[MAX_BIOTACS_PER_CHEETAH];
00183 } bt_data;
00184 
00185 typedef struct
00186 {
00187     u08 flex_version[100];
00188         u08 firmware_version[100];
00189         u08 serial_number[100];
00190         union
00191         {
00192                 u16 value;
00193                 u08 byte[BT_CPU_SPEED_READ_LENGTH];
00194         } cpu_speed;
00195         BOOL bt_connected;
00196 } bt_property;
00197 
00198 typedef struct
00199 {
00200         int spi_clock_speed;
00201         int number_of_biotacs;
00202         int sample_rate_Hz;
00203         struct
00204         {
00205                 int frame_type;
00206                 int frame_size;
00207                 char frame_structure[100];
00208         } frame;
00209         struct
00210         {
00211                 int batch_frame_count;
00212                 int batch_ms;
00213         } batch;
00214 } bt_info;
00215 
00216 
00217 //==================================================//
00218 // Print Data Definitions //
00219 //==================================================//
00220 #define YES                     (BOOL)1
00221 #define NO                      (BOOL)0
00222 
00223 
00224 //==================================================//
00225 // Function Prototypes //
00226 //==================================================//
00227 BioTac  bt_cheetah_initialize(const bt_info *biotac, Cheetah *ch_handle);
00228 BioTac          bt_cheetah_get_properties(Cheetah ch_handle, int bt_select, bt_property *property);
00229 BioTac          bt_cheetah_configure_batch(Cheetah ch_handle, bt_info *biotac, int num_samples);
00230 bt_data*        bt_configure_save_buffer(int num_samples);
00231 void            bt_cheetah_collect_batch(Cheetah ch_handle, const bt_info *biotac, bt_data *data, BOOL print_flag);
00232 void            bt_display_errors(BioTac bt_err_code);
00233 BioTac  bt_save_buffer_data(const char *file_name, const bt_data *data, int num_samples);
00234 void            bt_cheetah_close(Cheetah ch_handle);
00235 
00236 #endif /* BIOTAC_H_ */


biotac_sensors
Author(s): Ian McMahon
autogenerated on Sun Oct 5 2014 22:30:25