Fixed concurrency on ic2. Clean main program master
authorThomas Pietrzak <thomas.pietrzak@gmail.com>
Mon, 21 Oct 2013 09:21:04 +0000 (09:21 +0000)
committerThomas Pietrzak <thomas.pietrzak@gmail.com>
Mon, 21 Oct 2013 09:21:04 +0000 (09:21 +0000)
git-svn-id: svn+ssh://thomaspietrzak.com/var/svn/rep@127 47cf9a05-e0a8-4ed5-9e9b-101a649bc004

lib/HAL_LSM303DLHC.h
lib/i2c.c
multitouchglove.c

index 80bc74fbdda72e229611e8bc3dcfacac4e298e04..67288a7d66f998a710f02f26e7f4180beb43c6b0 100755 (executable)
@@ -8,6 +8,7 @@
 #include "stm32f10x.h"\r
 #include "i2c.h"\r
 \r
+#define LSM_I2C_Speed                                            400000\r
 #define Lsm303dlhcI2CInit()                                      i2c_init(2, LSM_I2C_Speed)\r
 #define Lsm303dlhcI2CBufferRead(dest, buffer, address, nb)       i2c_get(dest, address, buffer, nb)\r
 #define Lsm303dlhcI2CBufferWrite(dest, buffer, address, nb)      i2c_set(dest, address, buffer, nb)\r
index c72f126d457165c48a18eb8f2e44f9131654fadc..33153db052197c01d72d8d59c2408c8a9187eb62 100644 (file)
--- a/lib/i2c.c
+++ b/lib/i2c.c
@@ -113,6 +113,8 @@ void i2c_read_polling(uint8_t id, uint8_t *buffer, uint8_t nb)
 
     struct i2cInitDef_t * i2cInitDef = i2cInitDefs + id - 1;
  
+    taskENTER_CRITICAL();
+
     while(nb--)
     {
         if(nb == 0)
@@ -123,6 +125,8 @@ void i2c_read_polling(uint8_t id, uint8_t *buffer, uint8_t nb)
     }
     
     I2C_AcknowledgeConfig(i2cInitDef->id, ENABLE);
+
+    taskEXIT_CRITICAL();
 }
 
 void i2c_write_polling(uint8_t id, uint8_t *buffer, uint8_t nb)
index d398f62f834904835895cc81d687b9d1d2e53f72..9800da7827e6cc2692010e77d1699e0456ee597c 100644 (file)
@@ -6,11 +6,7 @@
 
 #include <stm32f10x.h>
 #include <stm32f10x_gpio.h>
-#include <stm32f10x_rcc.h>
-#include <stm32f10x_i2c.h>
 
-#include <spi.h>
-#include <i2c.h>
 #include <L3Gx.h>
 #include <LSM303DLHC.h>
 
@@ -56,6 +52,8 @@ static void blinkerTask(void *p)
 #ifdef GYRO
 void initGyro()
 {
+    L3gxCommInit();
+
     L3GInit gyrodef;
 
     /* Fill the gyro structure */
@@ -83,7 +81,7 @@ void getGyroInfo()
     printf("Data update: %02x\n", gyroinfo.xDataUpdate);
     printf("Endianness: %02x\n", gyroinfo.xEndianness);
 }
-/*
+
 static void gyroTask(void *p) 
 {
     printf("Start gyro task\n");
@@ -97,12 +95,14 @@ static void gyroTask(void *p)
          vTaskDelay(1000);
     }
     free(values);
-}*/
+}
 #endif
 
 #ifdef ACCELERO
 void initAccelero()
 {
+    Lsm303dlhcI2CInit();
+    
     LSMAccInit accelerodef;
 
     /* Fill the gyro structure */
@@ -141,8 +141,6 @@ static void acceleroTask(void *p)
         return;
     while (1) 
     {
-         L3gxReadAngRate(values);
-         printf("Gyro: x=%.4f y=%.4f z=%.4f\n", values[0], values[1], values[2]);
          Lsm303dlhcAccReadAcc(values);
          printf("Accelero: x=%.4f y=%.4f z=%.4f\n", values[0], values[1], values[2]);
          vTaskDelay(1000);
@@ -155,7 +153,6 @@ int main()
 {
     init_malloc_wrapper();
 
-
 #ifdef LEDS
     printf("Init led\n");
     initLed();
@@ -164,23 +161,19 @@ int main()
 #endif
 
 #ifdef GYRO
-    printf("Init SPI2\n");
-    spi_init(2);
     printf("Init Gyro\n");
     initGyro();
     printf("Get Gyro Information\n");
     getGyroInfo();
-//    printf("Start gyroTask\n");
-//    xTaskCreate(gyroTask, (const signed char *)NULL, configMINIMAL_STACK_SIZE, (void *)NULL, tskIDLE_PRIORITY, NULL);
+    printf("Start gyroTask\n");
+    xTaskCreate(gyroTask, (const signed char *)NULL, configMINIMAL_STACK_SIZE, (void *)NULL, tskIDLE_PRIORITY, NULL);
 #endif
 
 #ifdef ACCELERO
-    printf("Init I2C2\n");
-    i2c_init(2, 400000);
-    printf("Get Accelero Information\n");
-    getAcceleroInfo();
     printf("Init Accelero\n");
     initAccelero();
+    printf("Get Accelero Information\n");
+    getAcceleroInfo();
     printf("Start acceleroTask\n");
     xTaskCreate(acceleroTask, (const signed char *)NULL, configMINIMAL_STACK_SIZE, (void *)NULL, tskIDLE_PRIORITY, NULL);
 #endif