Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 0:e2579e8d9b13, committed 2017-09-29
- Comitter:
- DUR
- Date:
- Fri Sep 29 12:53:50 2017 +0000
- Commit message:
- Working version.
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.gitignore Fri Sep 29 12:53:50 2017 +0000 @@ -0,0 +1,4 @@ +.build +.mbed +projectfiles +*.py*
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README.md Fri Sep 29 12:53:50 2017 +0000 @@ -0,0 +1,87 @@ +# Getting started with Blinky on mbed OS + +This guide reviews the steps required to get Blinky working on an mbed OS platform. + +Please install [mbed CLI](https://github.com/ARMmbed/mbed-cli#installing-mbed-cli). + +## Import the example application + +From the command-line, import the example: + +``` +mbed import mbed-os-example-blinky +cd mbed-os-example-blinky +``` + +### Now compile + +Invoke `mbed compile`, and specify the name of your platform and your favorite toolchain (`GCC_ARM`, `ARM`, `IAR`). For example, for the ARM Compiler 5: + +``` +mbed compile -m K64F -t ARM +``` + +Your PC may take a few minutes to compile your code. At the end, you see the following result: + +``` +[snip] ++----------------------------+-------+-------+------+ +| Module | .text | .data | .bss | ++----------------------------+-------+-------+------+ +| Misc | 13939 | 24 | 1372 | +| core/hal | 16993 | 96 | 296 | +| core/rtos | 7384 | 92 | 4204 | +| features/FEATURE_IPV4 | 80 | 0 | 176 | +| frameworks/greentea-client | 1830 | 60 | 44 | +| frameworks/utest | 2392 | 512 | 292 | +| Subtotals | 42618 | 784 | 6384 | ++----------------------------+-------+-------+------+ +Allocated Heap: unknown +Allocated Stack: unknown +Total Static RAM memory (data + bss): 7168 bytes +Total RAM memory (data + bss + heap + stack): 7168 bytes +Total Flash memory (text + data + misc): 43402 bytes +Image: .\.build\K64F\ARM\mbed-os-example-blinky.bin +``` + +### Program your board + +1. Connect your mbed device to the computer over USB. +1. Copy the binary file to the mbed device. +1. Press the reset button to start the program. + +The LED on your platform turns on and off. + +## Export the project to Keil MDK, and debug your application + +From the command-line, run the following command: + +``` +mbed export -m K64F -i uvision +``` + +To debug the application: + +1. Start uVision. +1. Import the uVision project generated earlier. +1. Compile your application, and generate an `.axf` file. +1. Make sure uVision is configured to debug over CMSIS-DAP (From the Project menu > Options for Target '...' > Debug tab > Use CMSIS-DAP Debugger). +1. Set breakpoints, and start a debug session. + + + +## Troubleshooting + +1. Make sure `mbed-cli` is working correctly and its version is `>1.0.0` + + ``` + mbed --version + ``` + + If not, you can update it: + + ``` + pip install mbed-cli --upgrade + ``` + +2. If using Keil MDK, make sure you have a license installed. [MDK-Lite](http://www.keil.com/arm/mdk.asp) has a 32 KB restriction on code size. \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/adxl355.cpp Fri Sep 29 12:53:50 2017 +0000
@@ -0,0 +1,659 @@
+/**
+ ******************************************************************************
+ * @file adxl355.cpp
+ * @author DUR
+ * @version V1.0.0
+ * @date 01-Aug-2017
+ * @brief Library for adxl355 interface.
+ *
+ * @par Manual Reference Names:
+ * 1. "Low Noise, Low Drift, Low Power, 3-Axis MEMS Accelerometers
+ * ADXL354/ADXL355"
+ * 9/2016—Revision 0: Initial Version
+ *
+ * @par Document History:
+ *
+ * Version: 1.0.0 (01/08/2017)
+ * ----------------------------------------------------------------------------
+ * Author: DUR
+ * First release.
+ * ----------------------------------------------------------------------------
+ *
+@verbatim
+================================================================================
+ ##### How to use this file #####
+================================================================================
+Questa libreria è stata redatta per poter gestire ad alto livello il sensore di
+accelerazione ad uscita digitale a 20 bit della Analog Devices ADXL355, dotato
+di un bus SPI/I2C per la comunicazione, insieme ad un pin per la segnalazione di
+nuovi dati pronti e ben 2 pin di interrupt che sono configurabili per scattare a
+seguito di ben precisi eventi interni.
+Perché si possa utilizzare questa libreria su di una qualunque piattaforma
+hardware, la seguente funzione dovrà poi essere associata a quella di basso
+livello:
+ (+) uint16_t adxl355_spi_transfer(uint8_t * rbuffer, uint32_t rlen)
+ < trasferimento su bus SPI >;
+Nella presente versione della libreria, sono state fatte le seguenti scelte
+progettuali:
+ (+) è stato scelto di utilizzare il bus SPI piuttosto che il bus I2C per la
+ comunicazione da e verso l'host;
+ (+) è stato scelto l'utilizzo della sincronizzazione interna (EXT_SYNC = 0x00).
+L'accelerometro viene configurato dall'utente, per mezzo di una struttura dati
+adxl355_handler, con la quale è possibile definire un setting di parametri
+applicativi in base alle differenti esigenze. Nel suo utilizzo è importante tenere
+a mente le seguenti osservzioni:
+ (i) dopo avere lanciato il comando di reset software (adxl355_sw_reset) il
+ sensore deve essere nuovamente inizializzato (adxl355_init);
+ (i) per effettuare il self test, il sensore deve già essere in modalità di
+ acquisizione; il camando adxl355_self_test(true) dovrà essere lanciato
+ più volte perché ad ogni invocazione del metodo viene appicata una
+ specifica accelerazione all'interno, e quella che si andrà a rilevare
+ sarà proprio la differenza tra i valori in g rilevati tra due invocazioni
+ successive, e che dovrà rispettare i valori imposti dal datasheet.
+@endverbatim
+
+ ******************************************************************************
+@attention
+<h2><center>© COPYRIGHT(c) 2014 TD Group</center></h2>
+
+The information contained herein is property of TD Group S.p.A.
+
+Licensees are granted free, non-transferable use of the information. NO
+WARRANTY of ANY KIND is provided. This heading must NOT be removed from
+the file.
+ ******************************************************************************
+ */
+
+#define ADXL355_VERSION 1
+#define ADXL355_REVISION 0
+#define ADXL355_PATCH 0
+
+
+/* Includes ------------------------------------------------------------------*/
+
+/** @brief Add ONLY the header of THIS source file and not others.
+ */
+
+#include "adxl355.h"
+
+/** @addtogroup FILE_FUNCTIONS
+ * @{
+ */
+
+
+
+/* Private function prototypes -----------------------------------------------*/
+/* Ricava da una maschera di bit, la posizione del primo bit della maschera stessa */
+static uint8_t adxl355_get_bit_position(uint8_t gbp_mask);
+/* Setting dei parametri */
+static uint16_t adxl355_set_parameter(uint8_t sp_reg, uint8_t sp_mask_data, uint8_t sp_data);
+/* Lettura valore accelerazione lungo asse X, Y e Z */
+static uint16_t adxl355_read_acc_value(adxl355_handler *adxl_acc);
+/* Lettura valore di temperatura */
+static uint16_t adxl355_read_temp_value(adxl355_handler *adxl_temp);
+
+
+/* Private variables ---------------------------------------------------------*/
+/* Definisce in ogni momento quali misure sono attive */
+static adxl355_measure_enabled adxl_measure_on;
+
+
+/* Exported variables --------------------------------------------------------*/
+
+
+/* Private functions ---------------------------------------------------------*/
+
+/** @defgroup Group1 Private_Functions
+ * @brief Function used only in this file and NOT visible to the rest of the
+ * code.
+ * @{
+ */
+
+
+/**
+ * @brief Ricava da una maschera di bit, la posizione del primo bit della maschera
+ * stessa.
+ * @note No one.
+ * @param gbp_mask maschera di bit
+ * @retval uint8_t posizione del primo bit nella maschera
+ * @todo Nothing.
+ * @warning No one.
+ */
+static uint8_t adxl355_get_bit_position(uint8_t gbp_mask)
+{
+ uint8_t gbp_index;
+
+ for(gbp_index = 0; gbp_index < 8; gbp_index++)
+ {
+ if(((gbp_mask>>gbp_index) & 0x01) != 0)
+ {
+ break;
+ }else{}
+ }
+
+ return gbp_index;
+}
+
+
+/**
+ * @brief Funzione per la scrittura di un parametro su di un registro dell'accelerometro.
+ * @note No one.
+ * @param sp_reg indirizzo del registro da settare
+ * @param sp_mask_data posizione del/i bit da settare sotto forma di maschera
+ * @param sp_data valore del/i bit da settare
+ * @retval uint16_t errore restituito dal metodo (se 0, tutto ok)
+ * @todo Nothing.
+ * @warning No one.
+ */
+static uint16_t adxl355_set_parameter(uint8_t sp_reg, uint8_t sp_mask_data, uint8_t sp_data)
+{
+ uint16_t adxl_sp_error = 0u;
+ uint8_t adxl_sp_data[2];
+
+ /* Lettura del registro */
+ adxl_sp_data[0] = (uint8_t)((sp_reg << 1) | ADXL355_READ_BYTE_MASK);
+ adxl_sp_data[1] = 0x00;
+ if(adxl355_spi_transfer((uint8_t*)&adxl_sp_data, 2) == 0)
+ {
+ adxl_sp_data[0] = (uint8_t)((sp_reg << 1) & ADXL355_WRITE_BYTE_MASK);
+ adxl_sp_data[1] &= (uint8_t)~sp_mask_data;
+ adxl_sp_data[1] |= (uint8_t)(sp_data << (adxl355_get_bit_position(sp_mask_data)));
+ /* Scrittura del nuovo valore */
+ if(adxl355_spi_transfer((uint8_t*)&adxl_sp_data, 2) == 0)
+ {}
+ else
+ {
+ adxl_sp_error = (uint16_t)__LINE__;//ERRORE SCRITTURA REGISTRO
+ }
+ }
+ else
+ {
+ adxl_sp_error = (uint16_t)__LINE__;//ERRORE LETTURA REGISTRO
+ }
+
+ return adxl_sp_error;
+}
+
+
+/**
+ * @brief Funzione di lettura del dato grezzo di accelerazione lungo gli assi
+ * X, Y e Z dell'accelerometro.
+ * @note No one.
+ * @param adxl_acc puntatore all'handler dell'accelerometro
+ * @retval uint16_t errore restituito dal metodo (se 0, tutto ok)
+ * @todo No one.
+ * @warning No one.
+ */
+static uint16_t adxl355_read_acc_value(adxl355_handler *adxl_acc)
+{
+ uint16_t adxl_read_acc_error = 0u;
+ uint8_t adxl_read_acc_data[10];
+ /* Azzeramento buffer dati SPI */
+ memset(adxl_read_acc_data, 0x00, 10);
+ adxl_read_acc_data[0u] = (uint8_t)((ADXL355_XDATA3<<1) | ADXL355_READ_BYTE_MASK);
+
+ if(adxl355_spi_transfer((uint8_t*)&adxl_read_acc_data, 10) == 0)
+ {
+ adxl_acc->raw_acc_x_value = 0u;
+ adxl_acc->raw_acc_x_value = (adxl_read_acc_data[1]<<16u) | (adxl_read_acc_data[2]<<8u) | (adxl_read_acc_data[3]);
+ adxl_acc->raw_acc_x_value = (adxl_acc->raw_acc_x_value>>4u) & ADXL355_20_BIT_MASK;
+
+ adxl_acc->raw_acc_y_value = 0u;
+ adxl_acc->raw_acc_y_value = (adxl_read_acc_data[4]<<16u) | (adxl_read_acc_data[5]<<8u) | (adxl_read_acc_data[6]);
+ adxl_acc->raw_acc_y_value = (adxl_acc->raw_acc_y_value>>4u) & ADXL355_20_BIT_MASK;
+
+ adxl_acc->raw_acc_z_value = 0u;
+ adxl_acc->raw_acc_z_value = (adxl_read_acc_data[7]<<16u) | (adxl_read_acc_data[8]<<8u) | (adxl_read_acc_data[9]);
+ adxl_acc->raw_acc_z_value = (adxl_acc->raw_acc_z_value>>4u) & ADXL355_20_BIT_MASK;
+ }
+ else
+ {
+ adxl_read_acc_error = (uint16_t)__LINE__;//ERRORE LETTURA DATI ACCELERAZIONE
+ }
+
+ return adxl_read_acc_error;
+}
+
+
+
+/**
+ * @brief Funzione di lettura del dato grezzo di temperatura fornito dall'accelerometro.
+ * @note No one.
+ * @param adxl_temp puntatore all'handler dell'accelerometro
+ * @retval uint16_t errore restituito dal metodo (se 0, tutto ok)
+ * @todo No one.
+ * @warning No one.
+ */
+static uint16_t adxl355_read_temp_value(adxl355_handler *adxl_temp)
+{
+ uint16_t adxl_read_temp_error = 0u;
+ uint8_t adxl_read_temp_data[3];
+ /* Azzeramento buffer dati SPI */
+ memset(adxl_read_temp_data, 0x00, 3);
+ adxl_read_temp_data[0u] = (uint8_t)((ADXL355_TEMP2<<1) | ADXL355_READ_BYTE_MASK);
+
+ if(adxl355_spi_transfer((uint8_t*)&adxl_read_temp_data, 3) == 0)
+ {
+ adxl_temp->raw_temp_value = 0u;
+ adxl_temp->raw_temp_value = (adxl_read_temp_data[1]<<8u) | adxl_read_temp_data[2];
+ adxl_temp->raw_temp_value &= ADXL355_12_BIT_MASK;
+ }
+ else
+ {
+ adxl_read_temp_error = (uint16_t)__LINE__;//ERRORE LETTURA DATI ACCELERAZIONE
+ }
+
+ return adxl_read_temp_error;
+}
+
+
+
+
+
+
+/**
+ * @}
+ */
+
+
+/* Exported functions --------------------------------------------------------*/
+
+/** @defgroup Group2 Exported_Functions
+ * @brief Functions used in this file and also visible to the rest of the
+ * code.
+ * @{
+ */
+
+
+
+/**
+* @brief Funzione che restituisce i parametri identificativi del driver.
+* @note No one.
+* @param adxl355_driver_version puntatore all'identificatore di versione del driver
+* @param adxl355_driver_revision puntatore all'identificatore di revisione del driver
+* @param adxl355_driver_patch puntatore all'identificatore di patch del driver
+* @retval No one.
+* @todo No one.
+* @warning No one.
+*/
+void adxl355_driver_info(uint8_t * adxl355_driver_version, uint8_t * adxl355_driver_revision, uint8_t * adxl355_driver_patch)
+{
+ *adxl355_driver_version = ADXL355_VERSION;
+ *adxl355_driver_revision = ADXL355_REVISION;
+ *adxl355_driver_patch = ADXL355_PATCH;
+}
+
+
+/**
+* @brief Funzione che restituisce l'ID dell'accelerometro.
+* @note No one.
+* @param adxl355_device_id puntatore all'identificatore del device
+* @retval uint16_t errore restituito dal metodo (se 0, tutto ok)
+* @todo No one.
+* @warning No one.
+*/
+uint16_t adxl355_who_am_i(uint8_t * adxl355_device_id)
+{
+ uint16_t adxl_whoami_error = 0u;
+ uint8_t adxl_whoami_data[2];
+
+ /* Lettura del registro */
+ adxl_whoami_data[0] = (uint8_t)((ADXL355_PARTID << 1) | ADXL355_READ_BYTE_MASK);
+ adxl_whoami_data[1] = 0x00;
+ if(adxl355_spi_transfer((uint8_t*)&adxl_whoami_data, 2) == 0)
+ {
+ *adxl355_device_id = adxl_whoami_data[1];
+ }
+ else
+ {
+ adxl_whoami_error = (uint16_t)__LINE__;//ERRORE LETTURA ID
+ }
+
+ return adxl_whoami_error;
+}
+
+
+/**
+ * @brief Funzione di inizializzazione dell'accelerometro.
+ * @note No one.
+ * @param adxl_init_handler puntatore all'handler dell'accelerometro
+ * @retval uint16_t errore restituito dal metodo (se 0, tutto ok)
+ * @todo No one.
+ * @warning No one.
+ */
+uint16_t adxl355_init(adxl355_handler *adxl_init_handler)
+{
+ uint16_t adxl_init_error = 0u;
+ uint8_t adxl_init_state = 0u;
+
+ switch(adxl_init_state)
+ {
+ case 0:/* Configurazione range di misura */
+ if(0u == adxl355_set_parameter(ADXL355_RANGE, ADXL355_RANGE_MASK, (uint8_t)adxl_init_handler->measure_range))
+ {}
+ else
+ {
+ adxl_init_error = (uint16_t)__LINE__;//ERRORE SETTING RANGE DI MISURA
+ break;
+ }
+
+
+ case 1:/* Configurazione output data rate */
+ if(0u == adxl355_set_parameter(ADXL355_FILTER, ADXL355_ODR_MASK, (uint8_t)adxl_init_handler->out_data_rate))
+ {}
+ else
+ {
+ adxl_init_error = (uint16_t)__LINE__;//ERRORE SETTING OUTPUT DATA RATE
+ break;
+ }
+
+
+ case 2:/* Configurazione polarità interrupt */
+ if((adxl_init_handler->int1_pin == NULL) &&
+ (adxl_init_handler->int2_pin == NULL)){}//Se i pin non sono configurati, è inutile configurare la polarità degli interrupt
+ else
+ {
+ if(0u == adxl355_set_parameter(ADXL355_RANGE, ADXL355_ODR_MASK, (adxl_init_handler->int_config.int_act_low==true) ? 0:1))
+ {}
+ else
+ {
+ adxl_init_error = (uint16_t)__LINE__;//ERRORE SETTING POLARITA' INTERRUPT
+ break;
+ }
+ }
+
+
+ case 3:/* Configurazione interrupt 1 */
+ if(adxl_init_handler->int1_pin == NULL){}//Se il pin non è configurato, è inutile configurare il relativo interrupt
+ else
+ {
+ if(0u == adxl355_set_parameter(ADXL355_INT_MAP, ADXL355_INT_1_MASK, (uint8_t)adxl_init_handler->int_config.int1_evt))
+ {}
+ else
+ {
+ adxl_init_error = (uint16_t)__LINE__;//ERRORE SETTING EVENTO ASSOCIATO AD INTERRUPT 1
+ break;
+ }
+ }
+
+
+ case 4:/* Configurazione interrupt 2 */
+ if(adxl_init_handler->int2_pin == NULL){}//Se il pin non è configurato, è inutile configurare il relativo interrupt
+ else
+ {
+ if(0u == adxl355_set_parameter(ADXL355_INT_MAP, ADXL355_INT_2_MASK, (uint8_t)adxl_init_handler->int_config.int2_evt))
+ {}
+ else
+ {
+ adxl_init_error = (uint16_t)__LINE__;//ERRORE SETTING EVENTO ASSOCIATO AD INTERRUPT 2
+ break;
+ }
+ }
+
+
+ case 5:/* Stop di tutte le possibili misure */
+ if(0u == adxl355_start_acquisition(adxl355_none))
+ {}
+ else
+ {
+ adxl_init_error = (uint16_t)__LINE__;//ERRORE SETTING STOP MISURE
+ break;
+ }
+
+
+ case 6:/* Self-test disabilitato */
+ if(0u == adxl355_self_test(false))
+ {}
+ else
+ {
+ adxl_init_error = (uint16_t)__LINE__;//ERRORE DISABILITAZIONE SELF-TEST
+ break;
+ }
+
+
+ default:
+ break;
+ }
+
+ return adxl_init_error;
+}
+
+
+
+/**
+ * @brief Funzione di start/stop delle acquisizioni.
+ * @note No one.
+ * @param adxl_start misura/e da avviare
+ * @retval uint16_t errore restituito dal metodo (se 0, tutto ok)
+ * @todo No one.
+ * @warning No one.
+ */
+uint16_t adxl355_start_acquisition(adxl355_measure_enabled adxl_start)
+{
+ uint16_t adxl_start_error = 0u;
+ uint8_t adxl_start_data;
+
+ switch(adxl_start)
+ {
+ case 0://Solo accelerazione
+ adxl_start_data = 0x02;
+ break;
+
+ case 1://Entrambe le misure (accelerazione e temperatura)
+ adxl_start_data = 0x00;
+ break;
+
+ case 2://Nessuna misura (mette in standby il sensore)
+ adxl_start_data = 0x03;
+ break;
+
+ default:
+ break;
+ }
+
+ if(0u == adxl355_set_parameter(ADXL355_POWER_CTL, ADXL355_MEAS_MASK, adxl_start_data))
+ {
+ adxl_measure_on = adxl_start;
+ }
+ else
+ {
+ adxl_start_error = (uint16_t)__LINE__;//ERRORE SETTING RANGE DI MISURA
+ }
+
+ return adxl_start_error;
+}
+
+
+
+/**
+ * @brief Funzione per la lettura del/i dato/i acquisito/i.
+ * @note No one.
+ * @param adxl_data_handler puntatore all'handler dell'accelerometro
+ * @retval uint16_t errore restituito dal metodo (se 0, tutto ok)
+ * @todo No one.
+ * @warning No one.
+ */
+uint16_t adxl355_get_data(adxl355_handler *adxl_data_handler)
+{
+ uint16_t adxl_data_error = 0u;
+
+ if((adxl_measure_on == adxl355_acc) || (adxl_measure_on == adxl355_both))
+ { /* Lettura accelerazione */
+ if(adxl355_read_acc_value(adxl_data_handler) == 0u)
+ {
+ if(adxl_measure_on == adxl355_both)
+ { /* Lettura temperatura */
+ if(adxl355_read_temp_value(adxl_data_handler) == 0u)
+ {}
+ else
+ {
+ adxl_data_error = (uint16_t)__LINE__;//ERRORE LETTURA MISURA TEMPERATURA
+ }
+ }
+ else{}
+
+ }
+ else
+ {
+ adxl_data_error = (uint16_t)__LINE__;//ERRORE LETTURA MISURA ACCELERAZIONE
+ }
+ }else{}
+
+ return adxl_data_error;
+}
+
+
+
+/**
+ * @brief Funzione che restituisce il valore grezzo di accelerazione lungo l'asse X.
+ * @note No one.
+ * @param adxl_xdata_handler puntatore all'handler dell'accelerometro
+ * @retval uint32_t valore grezzo accelerazione
+ * @todo No one.
+ * @warning No one.
+ */
+uint32_t adxl355_raw_x_acc(adxl355_handler *adxl_xdata_handler)
+{
+ return adxl_xdata_handler->raw_acc_x_value;
+}
+
+
+
+/**
+ * @brief Funzione che restituisce il valore grezzo di accelerazione lungo l'asse Y.
+ * @note No one.
+ * @param adxl_ydata_handler puntatore all'handler dell'accelerometro
+ * @retval uint32_t valore grezzo accelerazione
+ * @todo No one.
+ * @warning No one.
+ */
+uint32_t adxl355_raw_y_acc(adxl355_handler *adxl_ydata_handler)
+{
+ return adxl_ydata_handler->raw_acc_y_value;
+}
+
+
+
+/**
+ * @brief Funzione che restituisce il valore grezzo di accelerazione lungo l'asse Z.
+ * @note No one.
+ * @param adxl_zdata_handler puntatore all'handler dell'accelerometro
+ * @retval uint32_t valore grezzo accelerazione
+ * @todo No one.
+ * @warning No one.
+ */
+uint32_t adxl355_raw_z_acc(adxl355_handler *adxl_zdata_handler)
+{
+ return adxl_zdata_handler->raw_acc_z_value;
+}
+
+
+
+/**
+ * @brief Funzione che restituisce il valore grezzo di temperatura.
+ * @note No one.
+ * @param adxl_tdata_handler puntatore all'handler dell'accelerometro
+ * @retval uint16_t valore grezzo temperatura
+ * @todo No one.
+ * @warning No one.
+ */
+uint16_t adxl355_raw_temp(adxl355_handler *adxl_tdata_handler)
+{
+ return adxl_tdata_handler->raw_temp_value;
+}
+
+
+
+/**
+ * @brief Funzione per il reset sw.
+ * @note No one.
+ * @param No one.
+ * @retval uint16_t errore restituito dal metodo (se 0, tutto ok)
+ * @todo No one.
+ * @warning No one.
+ */
+uint16_t adxl355_sw_reset(void)
+{
+ uint16_t adxl_swres_error = 0u;
+ uint8_t adxl_swres_data[2];
+
+ /* Lettura del registro */
+ adxl_swres_data[0] = (uint8_t)((ADXL355_RESET << 1) & ADXL355_WRITE_BYTE_MASK);
+ adxl_swres_data[1] = ADXL355_RESET_CODE;
+ if(adxl355_spi_transfer((uint8_t*)&adxl_swres_data, 2) == 0)
+ {}
+ else
+ {
+ adxl_swres_error = (uint16_t)__LINE__;//ERRORE RESET ACCELEROMETRO
+ }
+
+ return adxl_swres_error;
+}
+
+
+
+/**
+ * @brief Funzione per il self-test.
+ * @note Questo metodo va utilizzato lanciandolo ponendo a true adxl_start
+ * ad acquisizione in corso; in questa modalità il metodo va lanciato
+ * diverse volte in modo che si possa registrare la variazione di
+ * accelerazione sui 3 assi che deve essere, secondo datasheet:
+ * [X]: 0.3g
+ * [Y]: 0.3g
+ * [Z]: 1.5g
+ * In modalità self-test, il sensore non registra alcuna accelerazione
+ * esterna; ponendo a false adxl_start, il sensore termina il self-test
+ * e ritorna in modalità normale di funzionamento.
+ * @param adxl_start booleano per avviare/fermare il self test
+ * @retval uint16_t errore restituito dal metodo (se 0, tutto ok)
+ * @todo No one.
+ * @warning No one.
+ */
+uint16_t adxl355_self_test(bool adxl_start)
+{
+ uint16_t adxl_st_error = 0u;
+ static uint8_t adxl_st2_val = 0u;
+
+ if(adxl_start == true)
+ {
+ adxl_measure_on = adxl355_acc;
+ if(0u == adxl355_set_parameter(ADXL355_SELF_TEST, ADXL355_SELF_TEST_MASK, (adxl_st2_val<<1)|ADXL355_SELF_TEST_ENABLE ))
+ {
+ if(adxl_st2_val == 0u) adxl_st2_val = 1u;
+ else adxl_st2_val = 0u;
+ }
+ else
+ {
+ adxl_st_error = (uint16_t)__LINE__;//ERRORE AVVIO SELF-TEST
+ }
+ }
+ else
+ {
+ if(0u == adxl355_set_parameter(ADXL355_SELF_TEST, ADXL355_SELF_TEST_MASK, ADXL355_SELF_TEST_DISABLE))
+ {
+ adxl_st2_val = 0u;
+ }
+ else
+ {
+ adxl_st_error = (uint16_t)__LINE__;//ERRORE STOP SELF-TEST
+ }
+ }
+
+ return adxl_st_error;
+}
+
+
+
+/**
+ * @}
+ */
+
+
+
+ /**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT TD Group *****END OF FILE**************/
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/adxl355.h Fri Sep 29 12:53:50 2017 +0000
@@ -0,0 +1,247 @@
+/**
+ ******************************************************************************
+ * @file adxl355.h
+ * @author DUR
+ * @version V1.0.0
+ * @date 01-Aug-2017
+ * @brief Header file of a library for adxl355 interface.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>© COPYRIGHT(c) 2014 TD Group</center></h2>
+ *
+ * The information contained herein is property of TD Group S.p.A.
+ *
+ * Licensees are granted free, non-transferable use of the information. NO
+ * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
+ * the file.
+ *
+ ******************************************************************************
+ */
+
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __ADXL355_H
+#define __ADXL355_H
+
+
+/* Includes ------------------------------------------------------------------*/
+#include <stdint.h>
+#include <string.h>
+
+
+
+/* Exported define -----------------------------------------------------------*/
+
+/** @brief ID dell'accelerometro
+ */
+#define ADXL355_DEVICE_ID 0xED
+
+
+/** @brief Codice per effettuare il reset sw dell'accelerometro
+ */
+#define ADXL355_RESET_CODE 0x52
+
+
+/** @brief Start/stop self-test
+ */
+#define ADXL355_SELF_TEST_ENABLE 0x01
+#define ADXL355_SELF_TEST_DISABLE 0x00
+
+
+/** @brief Indirizzi registri accelerometro
+ */
+#define ADXL355_DEVID_AD 0x00
+#define ADXL355_DEVID_MST 0x01
+#define ADXL355_PARTID 0x02
+#define ADXL355_REVID 0x03
+#define ADXL355_STATUS 0x04
+#define ADXL355_FIFO_ENTRIES 0x05
+#define ADXL355_TEMP2 0x06
+#define ADXL355_TEMP1 0x07
+#define ADXL355_XDATA3 0x08
+#define ADXL355_XDATA2 0x09
+#define ADXL355_XDATA1 0x0A
+#define ADXL355_YDATA3 0x0B
+#define ADXL355_YDATA2 0x0C
+#define ADXL355_YDATA1 0x0D
+#define ADXL355_ZDATA3 0x0E
+#define ADXL355_ZDATA2 0x0F
+#define ADXL355_ZDATA1 0x10
+#define ADXL355_FIFO_DATA 0x11
+#define ADXL355_OFFSET_X_H 0x1E
+#define ADXL355_OFFSET_X_L 0x1F
+#define ADXL355_OFFSET_Y_H 0x20
+#define ADXL355_OFFSET_Y_L 0x21
+#define ADXL355_OFFSET_Z_H 0x22
+#define ADXL355_OFFSET_Z_L 0x23
+#define ADXL355_ACT_EN 0x24
+#define ADXL355_ACT_THRESH_H 0x25
+#define ADXL355_ACT_THRESH_L 0x26
+#define ADXL355_ACT_COUNT 0x27
+#define ADXL355_FILTER 0x28
+#define ADXL355_FIFO_SAMPLES 0x29
+#define ADXL355_INT_MAP 0x2A
+#define ADXL355_SYNC 0x2B
+#define ADXL355_RANGE 0x2C
+#define ADXL355_POWER_CTL 0x2D
+#define ADXL355_SELF_TEST 0x2E
+#define ADXL355_RESET 0x2F
+
+
+/** @brief Maschere di bit
+ */
+#define ADXL355_READ_BYTE_MASK 0x01
+#define ADXL355_WRITE_BYTE_MASK 0xFE
+
+#define ADXL355_20_BIT_MASK 0x000FFFFF
+#define ADXL355_12_BIT_MASK 0x0FFF
+
+#define ADXL355_RANGE_MASK 0x03
+#define ADXL355_ODR_MASK 0x0F
+#define ADXL355_INT_POL_MASK 0x40
+#define ADXL355_INT_1_MASK 0x0F
+#define ADXL355_INT_2_MASK 0xF0
+#define ADXL355_MEAS_MASK 0x03
+#define ADXL355_DRDY_OFF_MASK 0x04
+#define ADXL355_SELF_TEST_MASK 0x03
+
+
+/** @brief Temperature parameters
+ */
+#define ADXL355_TEMP_BIAS (float)1852.0 /* Accelerometer temperature bias(in ADC codes) at 25 Deg C */
+#define ADXL355_TEMP_SLOPE (float)-9.05 /* Accelerometer temperature change from datasheet (LSB/degC) */
+
+
+
+/* Exported typedef ----------------------------------------------------------*/
+/** @brief Enumerativo per le misure attive sul sensore in un determinato momento.
+ */
+typedef enum
+{
+ adxl355_acc = 0u, //Sola misura di accelerazione attiva
+ adxl355_both, //Entrambe le misure attive (accelerazione e temperatura)
+ adxl355_none //Nessuna misura attiva
+}adxl355_measure_enabled;
+
+
+/** @brief Enumerativo per valori di range di misura ammissibili.
+ */
+typedef enum
+{
+ adxl355_2g = 1u,
+ adxl355_4g,
+ adxl355_8g
+}adxl355_range_value;
+
+
+/** @brief Enumerativo per valori di output data rate ammissibili.
+ */
+typedef enum
+{
+ adxl355_4000hz = 0u,
+ adxl355_2000hz,
+ adxl355_1000hz,
+ adxl355_500hz,
+ adxl355_250hz,
+ adxl355_125hz,
+ adxl355_62p5hz,
+ adxl355_31p25hz,
+ adxl355_15p625hz,
+ adxl355_7p813hz,
+ adxl355_3p906hz
+}adxl355_output_datarate_value;
+
+
+
+/** @brief Enumerativo per i differenti eventi associabili ai 2 interrupt ammissibili.
+ */
+typedef enum
+{
+ adxl355_rdy_en = 0u, //DATA_RDY interrupt enable on INT1/2
+ adxl355_full_en, //FIFO_FULL interrupt enable on INT1/2
+ adxl355_ovr_en, //FIFO_OVR interrupt enable on INT1/2
+ adxl355_act_en //Activity interrupt enable on INT1/2
+}adxl355_int_event;
+
+
+
+
+/** @brief Struttura che setta i parametri degli interrupt sui 2 pin a disposizione.
+ */
+typedef struct adxl355_gpio_config_t
+{
+ adxl355_int_event int1_evt; //evento che scatena l'interrupt 1
+ adxl355_int_event int2_evt; //evento che scatena l'interrupt 2
+ bool int_act_low; // se true gli interrupt sono attivi basso, altrimenti attivi alto
+}adxl355_int_config;
+
+
+
+/** @brief Struttura che definisce i parametri di configurazione ed utilizzo
+ * dell'accelerometro
+ */
+typedef struct adxl355_handler_t
+{
+ /* Range di misura */
+ adxl355_range_value measure_range;
+ /* Data rate di acquisizione */
+ adxl355_output_datarate_value out_data_rate;
+ /* Pin di controllo dell'accelerometro - porre a NULL se non utilizzati */
+ uint32_t drdy_pin; //output
+ uint32_t int1_pin; //output
+ uint32_t int2_pin; //output
+ /* Configurazione interrupt */
+ adxl355_int_config int_config;
+ /* Valori grezzi della accelerazione */
+ uint32_t raw_acc_x_value;
+ uint32_t raw_acc_y_value;
+ uint32_t raw_acc_z_value;
+ /* Valore grezzo della temperatura */
+ uint16_t raw_temp_value;
+}adxl355_handler;
+
+
+
+
+
+/* Exported types ------------------------------------------------------------*/
+
+/* Exported constants --------------------------------------------------------*/
+
+/* Exported macro ------------------------------------------------------------*/
+
+
+/* Exported function prototypes ----------------------------------------------*/
+/**< Funzione che restituisce i parametri identificativi del driver */
+void adxl355_driver_info(uint8_t * adxl355_driver_version, uint8_t * adxl355_driver_revision, uint8_t * adxl355_driver_patch);
+/**< Funzione che restituisce l'ID dell'accelerometro */
+uint16_t adxl355_who_am_i(uint8_t * adxl355_device_id);
+/**< Funzione di inizializzazione dell'accelerometro */
+uint16_t adxl355_init(adxl355_handler *adxl_init_handler);
+/**< Funzione di start/stop delle acquisizioni */
+uint16_t adxl355_start_acquisition(adxl355_measure_enabled adxl_start);
+/**< Funzione per la lettura del/i dato/i acquisito/i */
+uint16_t adxl355_get_data(adxl355_handler *adxl_data_handler);
+/**< Funzione che restituisce il valore grezzo di accelerazione lungo l'asse X */
+uint32_t adxl355_raw_x_acc(adxl355_handler *adxl_xdata_handler);
+/**< Funzione che restituisce il valore grezzo di accelerazione lungo l'asse Y */
+uint32_t adxl355_raw_y_acc(adxl355_handler *adxl_ydata_handler);
+/**< Funzione che restituisce il valore grezzo di accelerazione lungo l'asse Z */
+uint32_t adxl355_raw_z_acc(adxl355_handler *adxl_zdata_handler);
+/**< Funzione che restituisce il valore grezzo di temperatura */
+uint16_t adxl355_raw_temp(adxl355_handler *adxl_tdata_handler);
+/**< Funzione per il reset sw */
+uint16_t adxl355_sw_reset(void);
+/**< Funzione per il self-test */
+uint16_t adxl355_self_test(bool adxl_start);
+
+
+/* Funzione di trasferimento su bus SPI */
+extern uint16_t adxl355_spi_transfer(uint8_t * rbuffer, uint32_t rlen);
+
+#endif
+
+/************************ (C) COPYRIGHT TD Group *****END OF FILE****/
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/define.h Fri Sep 29 12:53:50 2017 +0000 @@ -0,0 +1,45 @@ +#ifndef __DEFINE_H +#define __DEFINE_H + +/* + SEGNALI THREAD +*/ +#define ADXL355_SIGNAL 0x01 //Nuovi dati pronti +/* + SD CARD READER +*/ +#define SDCARD_CS PC_8 +#define SDCARD_SCK PB_13 +#define SDCARD_MISO PB_14 +#define SDCARD_MOSI PB_15 +/* + PIN DEBUG +*/ +#define DBG_PIN PC_10 //VERDE +#define DBG_PIN_2 PC_11 //BLU +#define DBG_PIN_3 PC_12 //VIOLA +#define DBG_PIN_4 PC_9 //GIALLO +/* + BUS SPI +*/ +#define SPI_MISO PA_6 +#define SPI_MOSI PA_7 +#define SPI_SCK PA_5 +#define MAX_LENGTH_SPI_TRANSFER 50 +#define SPI_FREQUENCY_HZ 8000000 +/* + ADXL355 +*/ +#define ADXL355_CS SPI_CS +#define ADXL355_DRDY PC_7 +#define RECORD_NUMBER 30 //1 secondo @50Hz +#define RECORD_SIZE 50 +/* + PULSANTE +*/ +#define USER_KEY_PIN PC_13 +/* + LED +*/ +#define STATUS_LED_PIN PA_9 +#endif \ No newline at end of file
Binary file img/uvision.png has changed
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Fri Sep 29 12:53:50 2017 +0000
@@ -0,0 +1,264 @@
+#include "mbed.h"
+#include "rtos.h"
+#include "SDBlockDevice.h"
+#include "FATFileSystem.h"
+#include "utility.h"
+
+
+/*
+ FLAG SCRITTURA SU SD CARD IN CORSO
+*/
+bool volatile start_writing;
+/*
+ PULSANTE
+*/
+bool volatile button_int_f;/* Flag pulsante pigiato */
+InterruptIn user_button(USER_KEY_PIN);
+/*
+ OGGETTO FILE
+*/
+FILE *fp = NULL;
+uint32_t file_index;//Indice che conteggia in maniera progressiva i record sul file
+/*
+ SD Card
+*/
+SDBlockDevice sd(SDCARD_MOSI, SDCARD_MISO, SDCARD_SCK, SDCARD_CS, 8000000);
+FATFileSystem fs("fs");
+/*
+ Bus SPI
+*/
+SPI spiHandler(SPI_MOSI, SPI_MISO, SPI_SCK);
+DigitalOut spiADXL355cs(ADXL355_CS);// Pin di CS ADXL355
+/*
+ ADXL355
+*/
+adxl355_handler adxl355_config =//Handler accelerometro
+{
+ .measure_range = adxl355_2g,
+ .out_data_rate = adxl355_250hz,
+ .drdy_pin = ADXL355_DRDY,
+ .int1_pin = NULL,
+ .int2_pin = NULL,
+ .int_config = {}
+};
+InterruptIn adxl355_int((PinName)adxl355_config.drdy_pin);// Interrupt su pin accelerometro
+uint32_t adxl355_int_timestamp;//Timestamp registrato nella routine di interrupt
+uint8_t adxl355_int_index;//Numero di interrupt consecutivi
+uint16_t adxl355_newData_error = 0;//Errore metodo
+//uint8_t adxl355_newData_sample = 0;//Conteggio dei sample acquisiti
+uint32_t adxl355_newData_timestamp;//Timestamp rilevato al 5° sample
+/* Dati locali temporanei ADXL355 */
+//uint32_t adxl355_rawX_tmp = 0;
+//uint32_t adxl355_rawY_tmp = 0;
+//uint32_t adxl355_rawZ_tmp = 0;
+//uint32_t adxl355_rawT_tmp = 0;
+/*
+ DEBUG PIN
+*/
+DigitalOut BLUpin(DBG_PIN_2);
+DigitalOut YELLOWpin(DBG_PIN_4);
+DigitalOut GREENpin(DBG_PIN);
+DigitalOut VIOLApin(DBG_PIN_3);
+DigitalOut led_pin(STATUS_LED_PIN);
+/*
+ DEFINIZIONE CODA DATI
+*/
+MemoryPool<record_t, RECORD_NUMBER*RECORD_SIZE> mpool;
+Queue<record_t, RECORD_NUMBER*RECORD_SIZE> queue;
+/*
+ SCRITTURA SU SD CARD
+*/
+void writeOnSDcard(void)
+{
+ while(1)
+ {
+ Thread::wait(10);
+ osEvent evt = queue.get();
+ if((evt.status == osEventMessage) && (start_writing == true))
+ {
+ record_t *message = (record_t*)evt.value.p;
+ BLUpin = 1;
+ fprintf(fp, "%06d;%04x;%08d;%05x;%05x;%05x;%03x;%06x;%06x;%06x;%06x;%06x;%06x \r\n",
+ message->index, //#
+ message->error, //Error
+ message->timestamp, //Timestamp
+ message->adxl355_rawX, //ACC_DIG_3A_X
+ message->adxl355_rawY, //ACC_DIG_3A_Y
+ message->adxl355_rawZ, //ACC_DIG_3A_Z
+ message->adxl355_rawT, //ACC_DIG_3A_TEMP
+ message->adxl354_rawX, //ACC_AN_3A_X
+ message->adxl354_rawY, //ACC_AN_3A_Y
+ message->adxl354_rawZ, //ACC_AN_3A_Z
+ message->adxl354_rawT, //ACC_AN_3A_TEMP
+ message->colibrys_rawVal, //ACC_AN_1A_VAL
+ message->colibrys_rawTEMPval //ACC_AN_1A_TEMP
+ );
+ BLUpin = 0;
+ mpool.free(message);
+ }else{}
+
+ if((button_int_f == true)&&(start_writing == true))
+ {
+ fprintf(fp,"DATA END \r\n");
+ fclose(fp); // DO THIS AT THE END!!!
+ sd.deinit();
+ fs.unmount();
+ start_writing = false;
+
+ Thread::wait(100);
+ if(adxl355_start_acquisition(adxl355_none) == 0)
+ {
+ led_pin = 0;
+ YELLOWpin = 1;
+ }else{}
+
+ }else{}
+ }
+}
+/*
+ THREAD SCRITTURA SU SD CARD
+*/
+Thread writeSDthread(writeOnSDcard);
+/*
+ NUOVI DATI ADXL355
+*/
+void adxl355_newData(void)
+{
+ while (true)
+ { // Signal flags that are reported as event are automatically cleared.
+ Thread::signal_wait(ADXL355_SIGNAL);
+ GREENpin = 1;
+ if(adxl355_get_data(&adxl355_config) != 0)
+ {
+ adxl355_newData_error |= 0xFF00;
+ }else{}
+
+ file_index++;
+ adxl355_newData_timestamp = HAL_GetTick();
+ adxl355_newData_error |= (uint16_t)(adxl355_newData_timestamp - adxl355_int_timestamp);
+
+ record_t *message = mpool.alloc();
+ message->index = file_index;
+ message->error = adxl355_newData_error;
+ message->timestamp = adxl355_newData_timestamp;
+
+ message->adxl355_rawX = adxl355_raw_x_acc(&adxl355_config);
+ message->adxl355_rawY = adxl355_raw_y_acc(&adxl355_config);
+ message->adxl355_rawZ = adxl355_raw_z_acc(&adxl355_config);
+ message->adxl355_rawT = adxl355_raw_temp(&adxl355_config);
+
+ message->adxl354_rawX = 3;
+ message->adxl354_rawY = 3;
+ message->adxl354_rawZ = 3;
+ message->adxl354_rawT = 3;
+
+ message->colibrys_rawVal = 4;
+ message->colibrys_rawTEMPval = 4;
+
+ queue.put(message);
+
+ adxl355_newData_error = 0;
+
+ GREENpin = 0;
+ }
+}
+/*
+ THREAD NUOVI DATI ADXL355
+*/
+Thread adxl355Thread(adxl355_newData);
+/*
+ FUNZIONE DI GESTIONE DELL'INTERRUPT ADXL355
+*/
+void adxl355_int_handler(void)
+{
+ VIOLApin = 1;
+ adxl355_int_index++;
+ if(adxl355_int_index == 5)
+ {
+ adxl355_int_timestamp = HAL_GetTick();
+ adxl355_int_index = 0;
+ adxl355Thread.signal_set(ADXL355_SIGNAL);
+ }else{};
+// adxl355Thread.signal_set(ADXL355_SIGNAL);
+ VIOLApin = 0;
+}
+/*
+ FUNZIONE DI GESTIONE INTERRUPT PULSANTE
+*/
+void pressed(void)
+{
+ button_int_f = true;
+}
+
+
+
+
+int main()
+{
+ uint16_t u16error;
+
+ start_writing = false;
+ button_int_f = false;
+ file_index = 0;
+ adxl355_int_timestamp = 0;
+ adxl355_int_index = 0;
+
+ led_pin = 0;
+
+ BLUpin = 0;
+ GREENpin = 0;
+ VIOLApin = 0;
+
+ /* Impulso che segnala l'avvio del codice */
+ YELLOWpin = 0;
+ YELLOWpin = 1;
+ YELLOWpin = 0;
+
+ /* Setting SPI */
+ spiHandler.frequency(SPI_FREQUENCY_HZ);
+ spiHandler.format(8, 0);//POL = 0; PHA = 0
+
+ /* Setting interrupt su pin accelerometro */
+ adxl355_int.rise(&adxl355_int_handler);
+ /* Setting interrupt pulsante */
+ user_button.fall(&pressed);
+
+ /* Init ADXL355 */
+ u16error = adxl355_init(&adxl355_config);
+ if(u16error != 0)
+ {
+ //VIOLApin = !VIOLApin;
+ }else{}
+ /* Init SD CARD reader */
+ sd.init();
+ fs.mount(&sd);
+ fp = fopen("/fs/mydata.csv", "w");
+ if(fp == NULL)
+ {
+ start_writing = false;
+ led_pin = 0;
+ }
+ else
+ {
+ start_writing = true;
+ fprintf(fp,"#;ERROR;TIMESTAMP;ACC_DIG_3A_X;ACC_DIG_3A_Y;ACC_DIG_3A_Z;ACC_DIG_3A_TEMP;ACC_AN_3A_X;ACC_AN_3A_Y;ACC_AN_3A_Z;ACC_AN_3A_TEMP;ACC_AN_1A_VAL;ACC_AN_1A_TEMP\r\n");
+ u16error = adxl355_start_acquisition(adxl355_both);
+ if(u16error != 0)
+ {
+ led_pin = 0;
+ fclose(fp);
+ sd.deinit();
+ fs.unmount();
+ start_writing = false;
+ }else
+ {
+ led_pin = 1;
+ }
+ }
+
+ while(1)
+ {
+ Thread::wait(1000);
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-os.lib Fri Sep 29 12:53:50 2017 +0000 @@ -0,0 +1,1 @@ +https://github.com/ARMmbed/mbed-os/#ca661f9d28526ca8f874b05432493a489c9671ea
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sd-driver.lib Fri Sep 29 12:53:50 2017 +0000 @@ -0,0 +1,1 @@ +https://github.com/armmbed/sd-driver/#1cb007fb3809a5e2d56d179e81332615c0a9b9fd
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/utility.cpp Fri Sep 29 12:53:50 2017 +0000
@@ -0,0 +1,115 @@
+/*****************************************************************************
+* 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)
+{
+
+}*/
+
+
+
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/utility.h Fri Sep 29 12:53:50 2017 +0000
@@ -0,0 +1,41 @@
+#ifndef __UTILITY_H
+#define __UTILITY_H
+
+
+#include "mbed.h"
+#include <ctype.h>
+#include <stdio.h>
+#include "adxl355.h"
+#include "define.h"
+
+typedef struct
+{ /* Index */
+ uint32_t index;
+ /* Error */
+ uint16_t error;
+ /* Timestamp */
+ uint32_t timestamp;
+ /* ADXL 355 */
+ uint32_t adxl355_rawX;
+ uint32_t adxl355_rawY;
+ uint32_t adxl355_rawZ;
+ uint32_t adxl355_rawT;
+ /* ADXL 354 */
+ uint32_t adxl354_rawX;
+ uint32_t adxl354_rawY;
+ uint32_t adxl354_rawZ;
+ uint32_t adxl354_rawT;
+ /* COLIBRYS */
+ uint32_t colibrys_rawVal;
+ uint32_t colibrys_rawTEMPval;
+}record_t;
+
+
+/* Funzione di gestione interrupt pulsante */
+//void pressed(void);
+/* Funzione di gestione dell'interrupt dell'ADXL355 */
+//void adxl355_int_handler(void);
+/* Funzione di salvataggio su SD Card */
+//void save_data_SD_card(uint8_t* data2save, uint16_t length);
+#endif
+