diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2011-04-15 16:20:25 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2011-04-15 16:20:25 +0000 |
commit | 3a3fe9efb1e3f0fe6a756b8e4d2fa48d5564137b (patch) | |
tree | 13d2c82c982b760b250741f7167faf0d509ecbc4 /nuttx/configs/vsn/src | |
parent | f1893cbaf513c7f0fbca77240fc59707ad039734 (diff) | |
download | px4-nuttx-3a3fe9efb1e3f0fe6a756b8e4d2fa48d5564137b.tar.gz px4-nuttx-3a3fe9efb1e3f0fe6a756b8e4d2fa48d5564137b.tar.bz2 px4-nuttx-3a3fe9efb1e3f0fe6a756b8e4d2fa48d5564137b.zip |
Add code changes from Uros
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3507 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/configs/vsn/src')
-rw-r--r-- | nuttx/configs/vsn/src/sif.c | 45 |
1 files changed, 32 insertions, 13 deletions
diff --git a/nuttx/configs/vsn/src/sif.c b/nuttx/configs/vsn/src/sif.c index 6f75c4a9e..555c43f63 100644 --- a/nuttx/configs/vsn/src/sif.c +++ b/nuttx/configs/vsn/src/sif.c @@ -70,8 +70,13 @@ #include <nuttx/config.h> #include <nuttx/fs.h> -#include <nuttx/i2c/i2c.h> #include <semaphore.h> +#include <nuttx/clock.h> +#include <nuttx/time.h> +#include <nuttx/rtc.h> + +#include <nuttx/i2c/i2c.h> +#include <nuttx/i2c/st_lis331dl.h> #include <stdio.h> #include <stdlib.h> @@ -80,7 +85,7 @@ #include <errno.h> #include "vsn.h" -#include <nuttx/i2c/st_lis331dl.h> + /**************************************************************************** @@ -297,10 +302,7 @@ int sif_anout_init(void) { vsn_sif.tim3 = stm32_tim_init(3); vsn_sif.tim8 = stm32_tim_init(8); - - vsn_sif.i2c1 = up_i2cinitialize(1); - vsn_sif.i2c2 = up_i2cinitialize(2); - + if (!vsn_sif.tim3 || !vsn_sif.tim8) return ERROR; // Use the TIM3 as PWM modulated analogue output @@ -318,12 +320,15 @@ int sif_anout_init(void) STM32_TIM_ENABLEINT(vsn_sif.tim8, 0); STM32_TIM_SETPERIOD(vsn_sif.tim8, 4096); - STM32_TIM_SETCOMPARE(vsn_sif.tim8, GPIO_OUT_PWRPWM_TIM8_CH, 0); + STM32_TIM_SETCOMPARE(vsn_sif.tim8, GPIO_OUT_PWRPWM_TIM8_CH, 5000); STM32_TIM_SETCLOCK(vsn_sif.tim8, 36e6); STM32_TIM_SETMODE(vsn_sif.tim8, STM32_TIM_MODE_UP); STM32_TIM_SETCHANNEL(vsn_sif.tim8, GPIO_OUT_PWRPWM_TIM8_CH, STM32_TIM_CH_OUTPWM | STM32_TIM_CH_POLARITY_NEG); + vsn_sif.i2c1 = up_i2cinitialize(1); + vsn_sif.i2c2 = up_i2cinitialize(2); + return OK; } @@ -470,7 +475,7 @@ int sif_init(void) sif_gpios_reset(); if ( sif_anout_init() != OK ) return -1; - + /* If everything is okay, register the driver */ (void)register_driver("/dev/sif0", &devsif_fops, 0666, NULL); @@ -502,28 +507,41 @@ int sif_main(int argc, char *argv[]) STM32_TIM_SETCOMPARE(vsn_sif.tim8, GPIO_OUT_PWRPWM_TIM8_CH, val); return 0; } + else if (!strcmp(argv[1], "time") && argc == 3) { + int val = atoi(argv[2]); + up_rtc_settime(val); + } else if (!strcmp(argv[1], "i2c") && argc == 3) { int val = atoi(argv[2]); - struct st_lis331dl_dev_s * lis = st_lis331dl_init(vsn_sif.i2c1, val); + + I2C_SETFREQUENCY(vsn_sif.i2c2, 100000); + + struct st_lis331dl_dev_s * lis = st_lis331dl_init(vsn_sif.i2c2, val); if (lis) { struct st_lis331dl_vector_s * a; int i; + uint32_t time_stamp = clock_systimer(); + + /* Set to 400 Hz : 3 = 133 Hz/axis */ + + st_lis331dl_setconversion(lis, false, true); /* Sample some values */ - for (i=0; i<200000; i++) { + for (i=0; i<1000; ) { if ( (a = st_lis331dl_getreadings(lis)) ) { + i++; printf("%d %d %d\n", a->x, a->y, a->z); } else if (errno != 11) { printf("Readings errno %d\n", errno); break; } - fflush(stdout); - usleep(10000); } + printf("Time diff = %d\n", clock_systimer() - time_stamp); + st_lis331dl_deinit(lis); } else printf("Exit point: errno=%d\n", errno); @@ -533,6 +551,7 @@ int sif_main(int argc, char *argv[]) } fprintf(stderr, "%s:\tinit\n\tgpio\tA B\n\tpwr\tval\n", argv[0]); - fprintf(stderr, "test = %.8x, test irq = %.8x\n", test, test_irq); + fprintf(stderr, "time = %d / %d, time = %d\n", + up_rtc_gettime(), up_rtc_getclock(), time(NULL) ); return -1; } |