SHENG-HEN HSIEH / Mbed 2 deprecated VDU_2021

Dependencies:   mbed imu_driver

Files at this revision

API Documentation at this revision

Comitter:
open4416
Date:
Fri Mar 13 15:25:57 2020 +0000
Parent:
22:4f764f7cd0b3
Child:
24:518ec8a4fb6d
Commit message:
Fix reset fail condition; Add reset state for pending; Remember to un-comment shit for all four module

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
main.h Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Tue Mar 10 14:56:08 2020 +0000
+++ b/main.cpp	Fri Mar 13 15:25:57 2020 +0000
@@ -75,7 +75,7 @@
     //spi2.frequency();                             //As default
 #endif
 
-    wait_ms(2500);
+    wait_ms(100);
     ticker1.attach_us(&timer1_interrupt, 1000);     //1 ms Systick
     while(1) {
 
@@ -217,18 +217,54 @@
 //                        RR_online = 5;
 //                        PSU_online = 5;
                         VDU_FLT = 0;
-                        VDU_STAT = VDU_PowerOn;
+                        VDU_STAT = VDU_Reset;
                         printf("VDU rebooting...\n");
                         printf("QDrive rebooting...\n");
                     }                                   //Else keep in state
                     break;
+
+                case VDU_Reset:
+                    /* Controller Reset state
+                     * Description:
+                     *  A state after reset by HMI when Fault latched
+                     *  Wait till four driver processing, timeout protected
+                     * Do:
+                     *  Nothing, just a soft delay
+                     * Check:
+                     *  Timeout condition met
+                     * To VDU_Idle:
+                     *  A valid reset
+                     * To VDU_Fault:
+                     *  A fail reset
+                     */
+
+                    RUNT();                             //Run test
+                    if(!RL_DSM) {
+//                    if(!(FL_DSM|FR_DSM|RL_DSM|RR_DSM)) {  // 2020/3/13 for real case
+                        printf("...\n");
+                        VDU_FLT &= ~(DSM_VDUFLTCode);   //Clear if fine
+                    }
+
+                    Reset_to += 1;                      //Time out check
+                    if (Reset_to > 30) {
+                        Reset_to = 0;
+                        if (VDU_FLT != 0) {             //Check if any error
+                            VDU_STAT = VDU_Fault;       //Back to fault state wait for next reset
+                            printf("Reset fail 2 Fault\n");
+                            FLT_print = 1;
+                        } else {                        //A success reset
+                            VDU_STAT = VDU_Idle;
+                            printf("Reset ok 2 Idle\n");
+                        }
+                    }                                   //Else keep in state
+                    break;
             }
 
             // Shit out torque distribution and special command
             if(VDU_STAT == VDU_Run) {
                 //Allow output torque
                 Tx_Tcmd_CAN1();
-            } else if(RST_cmd != 0) {
+            } else if(RST_cmd) {
                 //Send out reset cmd once
                 Tx_CLRerr_CAN1();
             } else {
--- a/main.h	Tue Mar 10 14:56:08 2020 +0000
+++ b/main.h	Fri Mar 13 15:25:57 2020 +0000
@@ -131,11 +131,13 @@
     VDU_PowerOn               = 0U,
     VDU_Idle                  = 1U,
     VDU_Run                   = 2U,
-    VDU_Fault                 = 3U
+    VDU_Fault                 = 3U,
+    VDU_Reset                 = 4U
 } VDU_STATE_TYPE;
 VDU_STATE_TYPE VDU_STAT = VDU_PowerOn;  // VDU current state
 uint16_t VDU_FLT = 0;                   // VDU internal fault code
 uint16_t VDU_FLT_ind = 0;               // A copy for indication
+uint8_t Reset_to = 0;                   // Timer for reset pending
 
 //Indicator pattern generation
 uint8_t Ind_refresh = 0;                // Flag to copy error bits for indicator