Davide Urbano
/
microSDreader
Working version. ADXL355 data saved to microSD.
utility.cpp
- Committer:
- DUR
- Date:
- 2017-09-29
- Revision:
- 0:e2579e8d9b13
File content as of revision 0:e2579e8d9b13:
/***************************************************************************** * Includes *****************************************************************************/ #include "utility.h" /***************************************************************************** * Global Variables *****************************************************************************/ extern bool volatile button_int_f;/* Flag pulsante pigiato */ extern DigitalOut GREENpin; extern DigitalOut BLUpin; extern DigitalOut VIOLApin; //extern uint8_t buffer1; //extern uint8_t buffer2; extern uint16_t volatile dataInBuffer; extern uint8_t *activeBuffer; extern adxl355_handler adxl355_config; extern bool volatile buf_overflow;//Overflow del buffer extern SPI spiHandler; extern DigitalOut spiADXL355cs; //extern Serial sdCard; //extern FILE *fp; extern volatile bool start_writing; //extern DigitalOut sdSyncro; /***************************************************************************** * Static Variables *****************************************************************************/ /* ONLY FOR TEST*/ //static uint32_t file_random_num_24b; //static uint32_t file_random_num_20b; //static uint32_t file_random_num_12b; /* Dati del singolo record */ //static uint32_t record_index = 1; /* Record per la acquisizione dei dati */ //static record acquisition_record = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; /* Record per la scrittura dei dati su SD card */ //static record sdWriting_record = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; /***************************************************************************** * Functions *****************************************************************************/ /* Funzione per generare i numeri random che andranno scritti sul file */ /*static uint32_t myRand(uint32_t low, uint32_t high) { static uint32_t seed = 0; seed++; srand(seed); return rand() % (high - low + 1) + low; }*/ /* static uint32_t swap_uint32( uint32_t val ) { val = ((val << 8) & 0xFF00FF00 ) | ((val >> 8) & 0xFF00FF ); return (val << 16) | (val >> 16); } */ /* Funzione di gestione interrupt pulsante */ /*void pressed(void) { button_int_f = true; }*/ /* Funzione di gestione dell'interrupt dell'ADXL355 */ /*void adxl355_int_handler(void) { }*/ /* Funzione di trasferimento su bus SPI */ uint16_t adxl355_spi_transfer(uint8_t * rbuffer, uint32_t rlen) { uint16_t ads_spi_transfer_error = 0u; uint8_t ads_spi_transfer_data[MAX_LENGTH_SPI_TRANSFER]; uint8_t ads_spi_transfer_index; if(rlen > MAX_LENGTH_SPI_TRANSFER) { ads_spi_transfer_error = (uint16_t)__LINE__;// TROPPI BYTE DA INVIARE !!! } else { memcpy(ads_spi_transfer_data, rbuffer, rlen); spiADXL355cs = 0; for(ads_spi_transfer_index = 0; ads_spi_transfer_index < rlen; ads_spi_transfer_index++) { rbuffer[ads_spi_transfer_index] = spiHandler.write(ads_spi_transfer_data[ads_spi_transfer_index]); } spiADXL355cs = 1; } return ads_spi_transfer_error; }; /* Funzione di salvataggio su SD Card */ /*void save_data_SD_card(uint8_t* data2save, uint16_t length) { }*/