openchronos-ng
opensource firmware for the ez430 chronos
|
00001 /* 00002 vti_as.h: accelerometer interface 00003 00004 Copyright (C) 2012 Paolo Di Prodi <paolo@robomotic.com> 00005 00006 This program is free software: you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation, either version 3 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program. If not, see <http://www.gnu.org/licenses/>. 00018 */ 00019 00020 00021 // ************************************************************************************************* 00022 // 00023 // Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ 00024 // 00025 // 00026 // Redistribution and use in source and binary forms, with or without 00027 // modification, are permitted provided that the following conditions 00028 // are met: 00029 // 00030 // Redistributions of source code must retain the above copyright 00031 // notice, this list of conditions and the following disclaimer. 00032 // 00033 // Redistributions in binary form must reproduce the above copyright 00034 // notice, this list of conditions and the following disclaimer in the 00035 // documentation and/or other materials provided with the 00036 // distribution. 00037 // 00038 // Neither the name of Texas Instruments Incorporated nor the names of 00039 // its contributors may be used to endorse or promote products derived 00040 // from this software without specific prior written permission. 00041 // 00042 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00043 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00044 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00045 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00046 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00047 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00048 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00049 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00050 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00051 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00052 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00053 // 00054 // ************************************************************************************************* 00055 00056 #ifndef VTI_AS_H_ 00057 #define VTI_AS_H_ 00058 00059 // ************************************************************************************************* 00060 // Include section 00061 00062 00063 // ************************************************************************************************* 00064 // Prototypes section 00065 #ifndef CONFIG_ACCELEROMETER 00066 extern void as_disconnect(void); 00067 #else 00068 extern void as_init(void); 00069 extern void as_start(uint8_t mode); 00070 extern void change_mode(uint8_t mode); 00071 extern void as_stop(void); 00072 extern uint8_t as_read_register(uint8_t bAddress); 00073 extern uint8_t as_write_register(uint8_t bAddress, uint8_t bData); 00074 extern void as_get_data(uint8_t * data); 00075 extern uint8_t as_get_x(void); 00076 extern uint8_t as_get_y(void); 00077 extern uint8_t as_get_z(void); 00078 extern uint8_t as_get_status(void); 00079 extern void write_MDTHR(uint8_t msec); 00080 extern void write_FFTMR(uint8_t mgrav); 00081 extern void write_MDTMR(uint8_t mgrav); 00082 extern void write_FFTHR(uint8_t mgrav); 00083 #endif 00084 00085 00086 // ************************************************************************************************* 00087 // Defines section 00088 00089 // Disconnect power supply for acceleration sensor when not used 00090 #define AS_DISCONNECT 00091 00092 // Port and pin resource for SPI interface to acceleration sensor 00093 // SDO=MOSI=P1.6, SDI=MISO=P1.5, SCK=P1.7 00094 #define AS_SPI_IN (P1IN) 00095 #define AS_SPI_OUT (P1OUT) 00096 #define AS_SPI_DIR (P1DIR) 00097 #define AS_SPI_SEL (P1SEL) 00098 #define AS_SPI_REN (P1REN) 00099 #define AS_SDO_PIN (BIT6) 00100 #define AS_SDI_PIN (BIT5) 00101 #define AS_SCK_PIN (BIT7) 00102 00103 // CSN=PJ.1 00104 #define AS_CSN_OUT (PJOUT) 00105 #define AS_CSN_DIR (PJDIR) 00106 #define AS_CSN_PIN (BIT1) 00107 00108 #define AS_TX_BUFFER (UCA0TXBUF) 00109 #define AS_RX_BUFFER (UCA0RXBUF) 00110 #define AS_TX_IFG (UCTXIFG) 00111 #define AS_RX_IFG (UCRXIFG) 00112 #define AS_IRQ_REG (UCA0IFG) 00113 #define AS_SPI_CTL0 (UCA0CTL0) 00114 #define AS_SPI_CTL1 (UCA0CTL1) 00115 #define AS_SPI_BR0 (UCA0BR0) 00116 #define AS_SPI_BR1 (UCA0BR1) 00117 00118 // Port and pin resource for power-up of acceleration sensor, VDD=PJ.0 00119 #define AS_PWR_OUT (PJOUT) 00120 #define AS_PWR_DIR (PJDIR) 00121 #define AS_PWR_PIN (BIT0) 00122 00123 // Port, pin and interrupt resource for interrupt from acceleration sensor, CMA_INT=P2.5 00124 #define AS_INT_IN (P2IN) 00125 #define AS_INT_OUT (P2OUT) 00126 #define AS_INT_DIR (P2DIR) 00127 #define AS_INT_IE (P2IE) 00128 #define AS_INT_IES (P2IES) 00129 #define AS_INT_IFG (P2IFG) 00130 #define AS_INT_PIN (BIT5) 00131 00132 // SPI timeout to detect sensor failure 00133 #define SPI_TIMEOUT (1000u) 00134 00135 00136 //register address: 00137 #define ADDR_CTRL (0x02) 00138 #define ADDR_INT_STATUS (0x05) 00139 #define ADDR_MDTHR (0x09) 00140 #define ADDR_MDFFTMR (0x0A) 00141 #define ADDR_FFTHR (0x0B) 00142 00143 //defines for sampling rate 00144 //The first one should be 400 but must fit u8 so divide by 10 00145 #define SAMPLING_400_HZ (40) 00146 #define SAMPLING_40_HZ (4) 00147 #define SAMPLING_100_HZ (10) 00148 #define SAMPLING_10_HZ (1) 00149 00150 // ************************************************************************************************* 00151 // Global Variable section 00152 00153 // Set of system flags 00154 typedef union 00155 { 00156 struct 00157 { 00158 uint8_t motiondet : 2; // MDET see AS_MOTION_STATUS 00159 uint8_t falldet : 1; // FFDET see AS_FALL_STATUS 00160 uint8_t reserved : 5; // reserved, initial value = 0h 00161 } int_status; 00162 uint8_t all_flags; // Shortcut to all display flags (for reset) 00163 } as_status_register_flags; 00164 extern volatile as_status_register_flags as_status; 00165 00166 volatile uint8_t as_last_interrupt; 00167 00168 // ************************************************************************************************* 00169 // Global Variable section 00170 struct As_Param 00171 { 00172 // configuration bits for motion and free fall 00173 uint8_t MDTHR; 00174 uint8_t MDFFTMR; 00175 uint8_t FFTHR; 00176 uint8_t sampling; 00177 uint8_t range; 00178 uint8_t mode; 00179 }; 00180 extern struct As_Param as_config; 00181 00182 00183 enum AS_MOTION_STATUS 00184 { 00185 AS_NO_MOTION =00, // motion not detected 00186 AS_TRIGGER_X =01, // motion trigger on x 00187 AS_TRIGGER_Y =10, // motion trigger on y 00188 AS_TRIGGER_Z =11 // motion trigger on z 00189 }; 00190 extern enum AS_MOTION_STATUS as_motion_bits; 00191 00192 enum AS_FALL_STATUS 00193 { 00194 AS_NOFALL = 0, // free fall not detected 00195 AS_FALL // free fall detected 00196 }; 00197 extern enum AS_FALL_STATUS as_fall_bit; 00198 00199 00200 #define FALL_MODE 0 00201 #define MEASUREMENT_MODE 1 00202 #define ACTIVITY_MODE 2 00203 00204 // when activity mode is configured you can set this flag 00205 // set 1 to remain in the motion detection mode 00206 // set 0 to switch at measurment mode at 400 Hz 00207 #define MDET_EXIT 1 00208 00209 // ************************************************************************************************* 00210 // Extern section 00211 00212 00213 #endif /*VTI_AS_H_*/