Bonjour,
Pour le TP7, j’ai bien compris que l’on pouvait utiliser un seul thread et rajouter la lecture des deux capteurs supplémentaires dans celui-ci. Mais je veux essayer avec 3 thread. Si je mets les priorité à la même valeur je ne lis qu’un capteur et si je régle les prioritées différentes j’ai un reboot de la cible.
Voici mon code main.
#include <stdio.h>
#include “thread.h”
#include “xtimer.h”
/* Add lps331ap related include here */
#include “lpsxxx.h”
#include “lpsxxx_params.h”
/* Add lsm303dlhc related include here */
#include “lsm303dlhc.h”
#include “lsm303dlhc_params.h”
/* Add isl29020 related include here */
#include “isl29020.h”
#include “isl29020_params.h”
/* Add l3g4200d related include here */
#include “l3g4200d.h”
#include “l3g4200d_params.h”
/* Declare the lps331ap device variable here */
static lpsxxx_t lpsxxx;
/* Declare the lsm303dlhc device variable here */
static lsm303dlhc_t lsm303dlhc;
/* Declare the isl29020 device variable here */
static isl29020_t isl29020;
/* Declare the l3g4200d device variable here */
static l3g4200d_t l3g4200d;
static char stack[THREAD_STACKSIZE_MAIN];
/* declaration du thread pour le lsm303dlhc */
static void *thread_lsm303dlhc(void *arg)
{
(void)arg;
/* Add the lsm303dlhc sensor polling endless loop here */
while (1) {
lsm303dlhc_3d_data_t mag_value;
lsm303dlhc_3d_data_t acc_value;
lsm303dlhc_read_acc(&lsm303dlhc, &acc_value);
printf("Accelerometer x: %i y: %i z: %i\n",
acc_value.x_axis, acc_value.y_axis, acc_value.z_axis);
lsm303dlhc_read_mag(&lsm303dlhc, &mag_value);
printf("Magnetometer x: %i y: %i z: %i\n",
mag_value.x_axis, mag_value.y_axis, mag_value.z_axis);
xtimer_usleep(500 * US_PER_MS);
}
return 0;
}
/* declaration du thread pour le isl29020 */
static void *thread_isl29020(void *arg)
{
(void)arg;
/* Add the isl29020 sensor polling endless loop here */
while (1) {
isl29020_t lumin_value;
printf("Intensite lumineuse: %5i LUX\n", isl29020_read(&lumin_value));
xtimer_usleep(500 * US_PER_MS);
}
return 0;
}
/* declaration du thread pour le l3g4200d */
static void *thread_l3g4200d (void *arg)
{
(void)arg;
/* Add the l3g4200d sensor polling endless loop here */
while (1) {
l3g4200d_t dev;
l3g4200d_data_t acc_data;
l3g4200d_read(&dev, &acc_data);
printf("Gyro data [dps] - X: %6i Y: %6i Z: %6i\n",
acc_data.acc_x, acc_data.acc_y, acc_data.acc_z);
xtimer_usleep(500 * US_PER_MS);
}
return 0;
}
int main(void)
{
/* Initialize the lps331ap sensor here /
lpsxxx_init(&lpsxxx, &lpsxxx_params[0]);
/ Initialize the lsm303dlhc sensor here /
lsm303dlhc_init(&lsm303dlhc, lsm303dlhc_params);
/ Initialize the isl29020 sensor here /
isl29020_init(&isl29020, &isl29020_params[0]);
/ Initialize the l3g4200d sensor here */
l3g4200d_init(&l3g4200d, &l3g4200d_params[0]);
thread_create(stack, sizeof(stack), THREAD_PRIORITY_MAIN +1,
0, thread_lsm303dlhc, NULL, "lsm303dlhc");
thread_create(stack, sizeof(stack), THREAD_PRIORITY_MAIN +1,
0, thread_isl29020, NULL, "isl29020");
thread_create(stack, sizeof(stack), THREAD_PRIORITY_MAIN +1,
0, thread_l3g4200d, NULL, "l3g4200d");
/* Add the lps331ap sensor polling endless loop here */
while (1) {
uint16_t pres = 0;
int16_t temp = 0;
lpsxxx_read_temp(&lpsxxx, &temp);
lpsxxx_read_pres(&lpsxxx, &pres);
printf("Pressure: %uhPa, Temperature: %u.%u°C\n",
pres, (temp / 100), (temp % 100));
xtimer_sleep(2);
}
return 0;
}