]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/blobdiff - rpp/src/rpp/hbr.c
Added watchdog stop feature and refactored a bit the H-Bridge driver. Untested, might...
[pes-rpp/rpp-lib.git] / rpp / src / rpp / hbr.c
index deb8a6a471f9ba8e80f01e4e7993d2908c416a35..c7296a386141d1a3822e5ab18d420ea432f61202 100644 (file)
@@ -51,10 +51,10 @@ int8_t rpp_hbr_init()
 static void rpp_hdr_reset()
 {
     #if rppCONFIG_DRV == 1
-    hbr_set_en(LOW);
-    hbr_pwm_set_duty(0);
-    hbr_pwm_stop();
-    hbr_set_dir(LOW);
+    drv_hbr_set_en(LOW);
+    drv_hbr_pwm_set_duty(0);
+    drv_hbr_pwm_stop();
+    drv_hbr_set_dir(LOW);
     #endif
 }
 
@@ -72,9 +72,13 @@ int8_t rpp_hbr_enable(int32_t period)
     }
 
     #if rppCONFIG_DRV == 1
-    hbr_pwm_set_signal(period, 0);
+    // Configure H-Bridge
+    drv_hbr_pwm_set_signal(period, 0);
     rpp_hdr_reset();
-    // FIXME enable watchdog task
+    // Start watchdog
+    if(drv_hbr_wdg_start() != SUCCESS) {
+        return FAILURE;
+    }
     #endif
 
     enabled = TRUE;
@@ -107,17 +111,17 @@ int8_t rpp_hbr_control(double cmd)
     /// Enabled, configure
     // Set direction
     if(scaled < 0) {
-        hbr_set_dir(LOW);
+        drv_hbr_set_dir(LOW);
     } else {
-        hbr_set_dir(HIGH);
+        drv_hbr_set_dir(HIGH);
     }
 
     // Set PWM duty cycle
-    hbr_pwm_set_duty(abs(scaled));
-    hbr_pwm_start();
+    drv_hbr_pwm_set_duty(abs(scaled));
+    drv_hbr_pwm_start();
 
     // Enable H-Bridge
-    hbr_set_en(HIGH);
+    drv_hbr_set_en(HIGH);
     #endif
 
     return SUCCESS;
@@ -130,6 +134,13 @@ int8_t rpp_hbr_disable()
         return FAILURE;
     }
 
+    #if rppCONFIG_DRV == 1
+    // We ignore is watchdog could not be stopped, because is harmless.
+    // It would be worse if we just could not stop the H-Bridge just because
+    // the watchdog could not be stopped.
+    drv_hbr_wdg_stop();
+    #endif
+
     rpp_hdr_reset();
     enabled = FALSE;