Working version. ADXL355 data saved to microSD.

Committer:
DUR
Date:
Fri Sep 29 12:53:50 2017 +0000
Revision:
0:e2579e8d9b13
Working version.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DUR 0:e2579e8d9b13 1 /*****************************************************************************
DUR 0:e2579e8d9b13 2 * Includes
DUR 0:e2579e8d9b13 3 *****************************************************************************/
DUR 0:e2579e8d9b13 4 #include "utility.h"
DUR 0:e2579e8d9b13 5
DUR 0:e2579e8d9b13 6
DUR 0:e2579e8d9b13 7 /*****************************************************************************
DUR 0:e2579e8d9b13 8 * Global Variables
DUR 0:e2579e8d9b13 9 *****************************************************************************/
DUR 0:e2579e8d9b13 10 extern bool volatile button_int_f;/* Flag pulsante pigiato */
DUR 0:e2579e8d9b13 11 extern DigitalOut GREENpin;
DUR 0:e2579e8d9b13 12 extern DigitalOut BLUpin;
DUR 0:e2579e8d9b13 13 extern DigitalOut VIOLApin;
DUR 0:e2579e8d9b13 14 //extern uint8_t buffer1;
DUR 0:e2579e8d9b13 15 //extern uint8_t buffer2;
DUR 0:e2579e8d9b13 16 extern uint16_t volatile dataInBuffer;
DUR 0:e2579e8d9b13 17 extern uint8_t *activeBuffer;
DUR 0:e2579e8d9b13 18 extern adxl355_handler adxl355_config;
DUR 0:e2579e8d9b13 19 extern bool volatile buf_overflow;//Overflow del buffer
DUR 0:e2579e8d9b13 20 extern SPI spiHandler;
DUR 0:e2579e8d9b13 21 extern DigitalOut spiADXL355cs;
DUR 0:e2579e8d9b13 22 //extern Serial sdCard;
DUR 0:e2579e8d9b13 23 //extern FILE *fp;
DUR 0:e2579e8d9b13 24 extern volatile bool start_writing;
DUR 0:e2579e8d9b13 25 //extern DigitalOut sdSyncro;
DUR 0:e2579e8d9b13 26
DUR 0:e2579e8d9b13 27
DUR 0:e2579e8d9b13 28 /*****************************************************************************
DUR 0:e2579e8d9b13 29 * Static Variables
DUR 0:e2579e8d9b13 30 *****************************************************************************/
DUR 0:e2579e8d9b13 31 /* ONLY FOR TEST*/
DUR 0:e2579e8d9b13 32 //static uint32_t file_random_num_24b;
DUR 0:e2579e8d9b13 33 //static uint32_t file_random_num_20b;
DUR 0:e2579e8d9b13 34 //static uint32_t file_random_num_12b;
DUR 0:e2579e8d9b13 35
DUR 0:e2579e8d9b13 36 /* Dati del singolo record */
DUR 0:e2579e8d9b13 37 //static uint32_t record_index = 1;
DUR 0:e2579e8d9b13 38
DUR 0:e2579e8d9b13 39
DUR 0:e2579e8d9b13 40 /* Record per la acquisizione dei dati */
DUR 0:e2579e8d9b13 41 //static record acquisition_record = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
DUR 0:e2579e8d9b13 42 /* Record per la scrittura dei dati su SD card */
DUR 0:e2579e8d9b13 43 //static record sdWriting_record = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
DUR 0:e2579e8d9b13 44
DUR 0:e2579e8d9b13 45 /*****************************************************************************
DUR 0:e2579e8d9b13 46 * Functions
DUR 0:e2579e8d9b13 47 *****************************************************************************/
DUR 0:e2579e8d9b13 48 /* Funzione per generare i numeri random che andranno scritti sul file */
DUR 0:e2579e8d9b13 49 /*static uint32_t myRand(uint32_t low, uint32_t high)
DUR 0:e2579e8d9b13 50 {
DUR 0:e2579e8d9b13 51 static uint32_t seed = 0;
DUR 0:e2579e8d9b13 52
DUR 0:e2579e8d9b13 53 seed++;
DUR 0:e2579e8d9b13 54 srand(seed);
DUR 0:e2579e8d9b13 55 return rand() % (high - low + 1) + low;
DUR 0:e2579e8d9b13 56 }*/
DUR 0:e2579e8d9b13 57 /*
DUR 0:e2579e8d9b13 58 static uint32_t swap_uint32( uint32_t val )
DUR 0:e2579e8d9b13 59 {
DUR 0:e2579e8d9b13 60 val = ((val << 8) & 0xFF00FF00 ) | ((val >> 8) & 0xFF00FF );
DUR 0:e2579e8d9b13 61 return (val << 16) | (val >> 16);
DUR 0:e2579e8d9b13 62 }
DUR 0:e2579e8d9b13 63 */
DUR 0:e2579e8d9b13 64
DUR 0:e2579e8d9b13 65 /* Funzione di gestione interrupt pulsante */
DUR 0:e2579e8d9b13 66 /*void pressed(void)
DUR 0:e2579e8d9b13 67 {
DUR 0:e2579e8d9b13 68 button_int_f = true;
DUR 0:e2579e8d9b13 69 }*/
DUR 0:e2579e8d9b13 70
DUR 0:e2579e8d9b13 71
DUR 0:e2579e8d9b13 72 /* Funzione di gestione dell'interrupt dell'ADXL355 */
DUR 0:e2579e8d9b13 73 /*void adxl355_int_handler(void)
DUR 0:e2579e8d9b13 74 {
DUR 0:e2579e8d9b13 75
DUR 0:e2579e8d9b13 76 }*/
DUR 0:e2579e8d9b13 77
DUR 0:e2579e8d9b13 78 /* Funzione di trasferimento su bus SPI */
DUR 0:e2579e8d9b13 79 uint16_t adxl355_spi_transfer(uint8_t * rbuffer, uint32_t rlen)
DUR 0:e2579e8d9b13 80 {
DUR 0:e2579e8d9b13 81 uint16_t ads_spi_transfer_error = 0u;
DUR 0:e2579e8d9b13 82 uint8_t ads_spi_transfer_data[MAX_LENGTH_SPI_TRANSFER];
DUR 0:e2579e8d9b13 83 uint8_t ads_spi_transfer_index;
DUR 0:e2579e8d9b13 84
DUR 0:e2579e8d9b13 85 if(rlen > MAX_LENGTH_SPI_TRANSFER)
DUR 0:e2579e8d9b13 86 {
DUR 0:e2579e8d9b13 87 ads_spi_transfer_error = (uint16_t)__LINE__;// TROPPI BYTE DA INVIARE !!!
DUR 0:e2579e8d9b13 88 }
DUR 0:e2579e8d9b13 89 else
DUR 0:e2579e8d9b13 90 {
DUR 0:e2579e8d9b13 91 memcpy(ads_spi_transfer_data, rbuffer, rlen);
DUR 0:e2579e8d9b13 92 spiADXL355cs = 0;
DUR 0:e2579e8d9b13 93
DUR 0:e2579e8d9b13 94 for(ads_spi_transfer_index = 0; ads_spi_transfer_index < rlen; ads_spi_transfer_index++)
DUR 0:e2579e8d9b13 95 {
DUR 0:e2579e8d9b13 96 rbuffer[ads_spi_transfer_index] = spiHandler.write(ads_spi_transfer_data[ads_spi_transfer_index]);
DUR 0:e2579e8d9b13 97 }
DUR 0:e2579e8d9b13 98
DUR 0:e2579e8d9b13 99 spiADXL355cs = 1;
DUR 0:e2579e8d9b13 100 }
DUR 0:e2579e8d9b13 101
DUR 0:e2579e8d9b13 102 return ads_spi_transfer_error;
DUR 0:e2579e8d9b13 103 };
DUR 0:e2579e8d9b13 104
DUR 0:e2579e8d9b13 105
DUR 0:e2579e8d9b13 106 /* Funzione di salvataggio su SD Card */
DUR 0:e2579e8d9b13 107 /*void save_data_SD_card(uint8_t* data2save, uint16_t length)
DUR 0:e2579e8d9b13 108 {
DUR 0:e2579e8d9b13 109
DUR 0:e2579e8d9b13 110 }*/
DUR 0:e2579e8d9b13 111
DUR 0:e2579e8d9b13 112
DUR 0:e2579e8d9b13 113
DUR 0:e2579e8d9b13 114
DUR 0:e2579e8d9b13 115