From 441b84b480fd116f634a86b82c470a8333487d07 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sergi=20Hern=C3=A1ndez?= <shernand@iri.upc.edu>
Date: Sat, 10 Jan 2015 12:01:03 +0000
Subject: [PATCH] Made the dynamixel communications more robust.

---
 include/{time.h => stm32_time.h} |  4 ++--
 src/action.c                     |  1 -
 src/bioloid_stm32.c              | 20 ++++----------------
 src/dynamixel_master_uart_dma.c  |  2 +-
 src/motion_manager.c             |  2 +-
 src/motion_pages.c               |  2 +-
 src/{time.c => stm32_time.c}     |  2 +-
 7 files changed, 10 insertions(+), 23 deletions(-)
 rename include/{time.h => stm32_time.h} (77%)
 rename src/{time.c => stm32_time.c} (98%)

diff --git a/include/time.h b/include/stm32_time.h
similarity index 77%
rename from include/time.h
rename to include/stm32_time.h
index 365b666..9595bec 100755
--- a/include/time.h
+++ b/include/stm32_time.h
@@ -1,5 +1,5 @@
-#ifndef _TIME_H
-#define _TIME_H
+#ifndef _STM32_TIME_H
+#define _STM32_TIME_H
 
 #include "stm32f4xx.h"
 #include "system_stm32f4xx.h"
diff --git a/src/action.c b/src/action.c
index ee7f1e4..365f41e 100644
--- a/src/action.c
+++ b/src/action.c
@@ -423,7 +423,6 @@ void action_process(void)
                           {
                             if(action_end)
                             {
-                              action_load_next_step();
                               state=ACTION_PAUSE;
                               action_end=0x00;
                               ram_clear_bit(BIOLOID_ACTION_STATUS,0);
diff --git a/src/bioloid_stm32.c b/src/bioloid_stm32.c
index 81b5f69..950f087 100644
--- a/src/bioloid_stm32.c
+++ b/src/bioloid_stm32.c
@@ -1,7 +1,7 @@
 #include "stm32f4xx.h"
 #include "system_stm32f4xx.h"
 
-#include "time.h"
+#include "stm32_time.h"
 #include "dynamixel.h"
 #include "dynamixel_master_uart_dma.h"
 #include "dynamixel_slave_uart_dma.h"
@@ -17,9 +17,7 @@
 
 int32_t main(void)
 {
-  uint16_t eeprom_data,i,num_errors=0;
-  uint16_t action_period,mm_period;
-  TPage page;
+  uint16_t eeprom_data,action_period,mm_period;
 
   /* initialize EEPROM */
   EE_Init();
@@ -30,8 +28,8 @@ int32_t main(void)
   /* initialize the gpio */
   gpio_init();
   /* initialize the dynamixel master interface */
-//  dyn_master_init();  
-//  dyn_master_set_timeout(20);
+  dyn_master_init();  
+  dyn_master_set_timeout(20);
   /* initialize the dynamixel slave interface*/
   dyn_slave_init();
   EE_ReadVariable(DEVICE_ID_OFFSET,&eeprom_data);
@@ -54,20 +52,10 @@ int32_t main(void)
   // initialize the action module
 //  action_init(action_period);
   comm_init();
-
   comm_start();
 
   gpio_blink_led(NORTH_LED,1000);
 
-  for(i=0;i<256;i++)
-  {
-    pages_get_page(i,&page);
-    if(!pages_check_checksum(&page))
-      num_errors++;
-  }
-  if(num_errors==0)
-    gpio_set_led(SOUTH_LED);
-
   while(1);
 }
 
diff --git a/src/dynamixel_master_uart_dma.c b/src/dynamixel_master_uart_dma.c
index b1f98b0..a5b515e 100755
--- a/src/dynamixel_master_uart_dma.c
+++ b/src/dynamixel_master_uart_dma.c
@@ -1,6 +1,6 @@
 #include "dynamixel_master_uart_dma.h"
 #include "motion_manager.h"
-#include "time.h"
+#include "stm32_time.h"
 
 #define     USART                    USART2
 #define     USART_CLK                RCC_APB1Periph_USART2
diff --git a/src/motion_manager.c b/src/motion_manager.c
index 0650f7b..703a7c8 100644
--- a/src/motion_manager.c
+++ b/src/motion_manager.c
@@ -4,7 +4,7 @@
 #include "gpio.h"
 #include "ram.h"
 #include "action.h"
-#include "time.h"
+#include "stm32_time.h"
 
 #define      MOTION_TIMER                 TIM3
 #define      MOTION_TIMER_IRQn            TIM3_IRQn
diff --git a/src/motion_pages.c b/src/motion_pages.c
index afc0e0e..147398d 100644
--- a/src/motion_pages.c
+++ b/src/motion_pages.c
@@ -5,7 +5,7 @@ void pages_get_page(uint8_t page_id,TPage *page)
   uint16_t i=0;
 
   for(i=0;i<sizeof(TPage);i++)
-    ((uint8_t *)page)[i]=((__IO uint8_t *)&motion_pages[page_id])[i];
+    ((uint8_t *)page)[i]=((uint8_t *)&motion_pages[page_id])[i];
 }
 
 uint8_t pages_check_checksum(TPage *page)
diff --git a/src/time.c b/src/stm32_time.c
similarity index 98%
rename from src/time.c
rename to src/stm32_time.c
index 44dd1b7..f2f8044 100644
--- a/src/time.c
+++ b/src/stm32_time.c
@@ -1,4 +1,4 @@
-#include "time.h"
+#include "stm32_time.h"
 
 static __IO uint32_t timing_delay;
 uint32_t clocks_per_us;
-- 
GitLab