Sungwoo Kim
/
HydraulicControlBoard_LIGHT
For LIGHT
Diff: CAN/function_CAN.cpp
- Revision:
- 16:903b5a4433b4
- Parent:
- 15:bd0d12728506
- Child:
- 17:1865016ca2e7
diff -r bd0d12728506 -r 903b5a4433b4 CAN/function_CAN.cpp --- a/CAN/function_CAN.cpp Fri Aug 30 02:26:11 2019 +0000 +++ b/CAN/function_CAN.cpp Mon Sep 02 13:32:33 2019 +0000 @@ -2,6 +2,8 @@ #include "setting.h" #include "function_utilities.h" #include "SPI_EEP_ENC.h" +#include "stm32f4xx_flash.h" +#include "FlashWriter.h" // CAN ID Setting Variables int CID_RX_CMD = 100; @@ -57,7 +59,10 @@ } case CRX_SET_BNO: { BNO = (int16_t) msg.data[1]; - spi_eeprom_write(RID_BNO, (int16_t) BNO); + + ROM_RESET_DATA(); + + //spi_eeprom_write(RID_BNO, (int16_t) BNO); CAN_ID_INIT(); // can id init break; } @@ -67,7 +72,10 @@ } case CRX_SET_OPERATING_MODE: { OPERATING_MODE = (int16_t) msg.data[1]; - spi_eeprom_write(RID_OPERATING_MODE, (int16_t) OPERATING_MODE); + + ROM_RESET_DATA(); + + //spi_eeprom_write(RID_OPERATING_MODE, (int16_t) OPERATING_MODE); break; } case CRX_SET_ENC_ZERO: { @@ -95,7 +103,10 @@ case CRX_SET_CAN_FREQ: { CAN_FREQ = (int16_t) (msg.data[1] | msg.data[2] << 8); - spi_eeprom_write(RID_CAN_FREQ, (int16_t) CAN_FREQ); + + ROM_RESET_DATA(); + + //spi_eeprom_write(RID_CAN_FREQ, (int16_t) CAN_FREQ); break; } @@ -138,7 +149,10 @@ DIR_JOINT_ENC = 1; else DIR_JOINT_ENC = -1; - spi_eeprom_write(RID_JOINT_ENC_DIR, (int16_t) DIR_JOINT_ENC); + + ROM_RESET_DATA(); + + //spi_eeprom_write(RID_JOINT_ENC_DIR, (int16_t) DIR_JOINT_ENC); break; } @@ -155,7 +169,10 @@ DIR_VALVE = 1; else DIR_VALVE = -1; - spi_eeprom_write(RID_VALVE_DIR, (int16_t) DIR_VALVE); + + ROM_RESET_DATA(); + + //spi_eeprom_write(RID_VALVE_DIR, (int16_t) DIR_VALVE); break; } @@ -172,8 +189,10 @@ DIR_VALVE_ENC = 1; else DIR_VALVE_ENC = -1; + + ROM_RESET_DATA(); - spi_eeprom_write(RID_VALVE_ENC_DIR, (int16_t) DIR_VALVE_ENC); + //spi_eeprom_write(RID_VALVE_ENC_DIR, (int16_t) DIR_VALVE_ENC); break; } @@ -186,7 +205,10 @@ case CRX_SET_VOLTAGE_SUPPLY: { SUPPLY_VOLTAGE = (double) ((int16_t) (msg.data[1] | msg.data[2] << 8)) / 10.; - spi_eeprom_write(RID_VOLATGE_SUPPLY, (int16_t) (SUPPLY_VOLTAGE * 10.)); + + ROM_RESET_DATA(); + + //spi_eeprom_write(RID_VOLATGE_SUPPLY, (int16_t) (SUPPLY_VOLTAGE * 10.)); break; } @@ -199,7 +221,10 @@ case CRX_SET_VOLTAGE_VALVE: { VALVE_VOLTAGE_LIMIT = (double) ((int16_t) (msg.data[1] | msg.data[2] << 8)) / 10.; - spi_eeprom_write(RID_VOLTAGE_VALVE, (int16_t) (VALVE_VOLTAGE_LIMIT * 10.)); + + ROM_RESET_DATA(); + + //spi_eeprom_write(RID_VOLTAGE_VALVE, (int16_t) (VALVE_VOLTAGE_LIMIT * 10.)); break; @@ -222,28 +247,34 @@ P_GAIN_VALVE_POSITION = (int16_t) (msg.data[2] | msg.data[3] << 8); I_GAIN_VALVE_POSITION = (int16_t) (msg.data[4] | msg.data[5] << 8); D_GAIN_VALVE_POSITION = (int16_t) (msg.data[6] | msg.data[7] << 8); - - spi_eeprom_write(RID_P_GAIN_VALVE_POSITION, (int16_t) P_GAIN_VALVE_POSITION); - spi_eeprom_write(RID_I_GAIN_VALVE_POSITION, (int16_t) I_GAIN_VALVE_POSITION); - spi_eeprom_write(RID_D_GAIN_VALVE_POSITION, (int16_t) D_GAIN_VALVE_POSITION); + + ROM_RESET_DATA(); + + //spi_eeprom_write(RID_P_GAIN_VALVE_POSITION, (int16_t) P_GAIN_VALVE_POSITION); + //spi_eeprom_write(RID_I_GAIN_VALVE_POSITION, (int16_t) I_GAIN_VALVE_POSITION); + //spi_eeprom_write(RID_D_GAIN_VALVE_POSITION, (int16_t) D_GAIN_VALVE_POSITION); } else if (msg.data[1] == 1) { P_GAIN_JOINT_POSITION = (int16_t) (msg.data[2] | msg.data[3] << 8); I_GAIN_JOINT_POSITION = (int16_t) (msg.data[4] | msg.data[5] << 8); D_GAIN_JOINT_POSITION = (int16_t) (msg.data[6] | msg.data[7] << 8); + + ROM_RESET_DATA(); - spi_eeprom_write(RID_P_GAIN_JOINT_POSITION, (int16_t) P_GAIN_JOINT_POSITION); - spi_eeprom_write(RID_I_GAIN_JOINT_POSITION, (int16_t) I_GAIN_JOINT_POSITION); - spi_eeprom_write(RID_D_GAIN_JOINT_POSITION, (int16_t) D_GAIN_JOINT_POSITION); + //spi_eeprom_write(RID_P_GAIN_JOINT_POSITION, (int16_t) P_GAIN_JOINT_POSITION); + //spi_eeprom_write(RID_I_GAIN_JOINT_POSITION, (int16_t) I_GAIN_JOINT_POSITION); + //spi_eeprom_write(RID_D_GAIN_JOINT_POSITION, (int16_t) D_GAIN_JOINT_POSITION); } else if (msg.data[1] == 2) { P_GAIN_JOINT_TORQUE = (int16_t) (msg.data[2] | msg.data[3] << 8); I_GAIN_JOINT_TORQUE = (int16_t) (msg.data[4] | msg.data[5] << 8); D_GAIN_JOINT_TORQUE = (int16_t) (msg.data[6] | msg.data[7] << 8); - - spi_eeprom_write(RID_P_GAIN_JOINT_TORQUE, (int16_t) P_GAIN_JOINT_TORQUE); - spi_eeprom_write(RID_I_GAIN_JOINT_TORQUE, (int16_t) I_GAIN_JOINT_TORQUE); - spi_eeprom_write(RID_D_GAIN_JOINT_TORQUE, (int16_t) D_GAIN_JOINT_TORQUE); + + ROM_RESET_DATA(); + + //spi_eeprom_write(RID_P_GAIN_JOINT_TORQUE, (int16_t) P_GAIN_JOINT_TORQUE); + //spi_eeprom_write(RID_I_GAIN_JOINT_TORQUE, (int16_t) I_GAIN_JOINT_TORQUE); + //spi_eeprom_write(RID_D_GAIN_JOINT_TORQUE, (int16_t) D_GAIN_JOINT_TORQUE); } break; @@ -259,10 +290,12 @@ VALVE_CENTER = (int16_t) (msg.data[1] | msg.data[2] << 8); VALVE_DEADZONE_PLUS = (int16_t) (msg.data[3] | msg.data[4] << 8); VALVE_DEADZONE_MINUS = (int16_t) (msg.data[5] | msg.data[6] << 8); - - spi_eeprom_write(RID_VALVE_CNETER, (int16_t) (VALVE_CENTER)); - spi_eeprom_write(RID_VALVE_DEADZONE_PLUS, (int16_t) (VALVE_DEADZONE_PLUS)); - spi_eeprom_write(RID_VALVE_DEADZONE_MINUS, (int16_t) (VALVE_DEADZONE_MINUS)); + + ROM_RESET_DATA(); + + //spi_eeprom_write(RID_VALVE_CNETER, (int16_t) (VALVE_CENTER)); + //spi_eeprom_write(RID_VALVE_DEADZONE_PLUS, (int16_t) (VALVE_DEADZONE_PLUS)); + //spi_eeprom_write(RID_VALVE_DEADZONE_MINUS, (int16_t) (VALVE_DEADZONE_MINUS)); break; } @@ -275,8 +308,10 @@ case CRX_SET_VELOCITY_COMP_GAIN: { VELOCITY_COMP_GAIN = (int16_t) (msg.data[1] | msg.data[2] << 8); - - spi_eeprom_write(RID_VELOCITY_COMP_GAIN, (int16_t) VELOCITY_COMP_GAIN); + + ROM_RESET_DATA(); + + //spi_eeprom_write(RID_VELOCITY_COMP_GAIN, (int16_t) VELOCITY_COMP_GAIN); break; } @@ -290,7 +325,9 @@ case CRX_SET_COMPLIANCE_GAIN: { COMPLIANCE_GAIN = (int16_t) (msg.data[1] | msg.data[2] << 8); - spi_eeprom_write(RID_COMPLIANCE_GAIN, (int16_t) COMPLIANCE_GAIN); + ROM_RESET_DATA(); + + //spi_eeprom_write(RID_COMPLIANCE_GAIN, (int16_t) COMPLIANCE_GAIN); break; } @@ -303,8 +340,10 @@ case CRX_SET_VALVE_FF: { VALVE_FF = (int16_t) (msg.data[1] | msg.data[2] << 8); - - spi_eeprom_write(RID_VALVE_FF, (int16_t) VALVE_FF); + + ROM_RESET_DATA(); + + //spi_eeprom_write(RID_VALVE_FF, (int16_t) VALVE_FF); break; } @@ -317,8 +356,10 @@ case CRX_SET_BULK_MODULUS: { BULK_MODULUS = (int16_t) (msg.data[1] | msg.data[2] << 8); - - spi_eeprom_write(RID_BULK_MODULUS, (int16_t) BULK_MODULUS); + + ROM_RESET_DATA(); + + //spi_eeprom_write(RID_BULK_MODULUS, (int16_t) BULK_MODULUS); break; } @@ -333,8 +374,10 @@ CHAMBER_VOLUME_A = (int16_t) (msg.data[1] | msg.data[2] << 8); CHAMBER_VOLUME_B = (int16_t) (msg.data[3] | msg.data[4] << 8); - spi_eeprom_write(RID_CHAMBER_VOLUME_A, (int16_t) CHAMBER_VOLUME_A); - spi_eeprom_write(RID_CHAMBER_VOLUME_B, (int16_t) CHAMBER_VOLUME_B); + ROM_RESET_DATA(); + + //spi_eeprom_write(RID_CHAMBER_VOLUME_A, (int16_t) CHAMBER_VOLUME_A); + //spi_eeprom_write(RID_CHAMBER_VOLUME_B, (int16_t) CHAMBER_VOLUME_B); break; } @@ -349,17 +392,19 @@ PISTON_AREA_A = (int16_t) (msg.data[1] | msg.data[2] << 8); PISTON_AREA_B = (int16_t) (msg.data[3] | msg.data[4] << 8); PISTON_AREA_alpha = (double)PISTON_AREA_B/(double)PISTON_AREA_A; - - spi_eeprom_write(RID_PISTON_AREA_A, (int16_t) PISTON_AREA_A); - spi_eeprom_write(RID_PISTON_AREA_B, (int16_t) PISTON_AREA_B); + + ROM_RESET_DATA(); + + //spi_eeprom_write(RID_PISTON_AREA_A, (int16_t) PISTON_AREA_A); + //spi_eeprom_write(RID_PISTON_AREA_B, (int16_t) PISTON_AREA_B); break; } case CRX_ASK_PRES: { CAN_TX_PRES_A_AND_B(); // SPI_VREF_DAC_WRITE(PRES_A_VREF, PRES_B_VREF, TORQUE_VREF, 0); - dac_1 = PRES_A_VREF; - dac_2 = PRES_B_VREF; + //dac_1 = PRES_A_VREF; + //dac_2 = PRES_B_VREF; break; } @@ -367,9 +412,9 @@ case CRX_SET_PRES: { PRES_SUPPLY = (int16_t) (msg.data[1] | msg.data[2] << 8); PRES_RETURN = (int16_t) (msg.data[3] | msg.data[4] << 8); - - spi_eeprom_write(RID_PRES_SUPPLY, (int16_t) PRES_SUPPLY); - spi_eeprom_write(RID_PRES_RETURN, (int16_t) PRES_RETURN); + ROM_RESET_DATA(); + //spi_eeprom_write(RID_PRES_SUPPLY, (int16_t) PRES_SUPPLY); + //spi_eeprom_write(RID_PRES_RETURN, (int16_t) PRES_RETURN); break; @@ -384,9 +429,9 @@ case CRX_SET_ENC_LIMIT: { ENC_LIMIT_MINUS = (int16_t) (msg.data[1] | msg.data[2] << 8); ENC_LIMIT_PLUS = (int16_t) (msg.data[3] | msg.data[4] << 8); - - spi_eeprom_write(RID_ENC_LIMIT_MINUS, (int16_t) ENC_LIMIT_MINUS); - spi_eeprom_write(RID_ENC_LIMIT_PLUS, (int16_t) ENC_LIMIT_PLUS); + ROM_RESET_DATA(); + //spi_eeprom_write(RID_ENC_LIMIT_MINUS, (int16_t) ENC_LIMIT_MINUS); + //spi_eeprom_write(RID_ENC_LIMIT_PLUS, (int16_t) ENC_LIMIT_PLUS); break; } @@ -398,8 +443,8 @@ case CRX_SET_STROKE: { STROKE = (int16_t) (msg.data[1] | msg.data[2] << 8); - - spi_eeprom_write(RID_STROKE, (int16_t) STROKE); + ROM_RESET_DATA(); + //spi_eeprom_write(RID_STROKE, (int16_t) STROKE); break; } @@ -413,9 +458,9 @@ case CRX_SET_VALVE_LIMIT: { VALVE_LIMIT_MINUS = (int16_t) (msg.data[1] | msg.data[2] << 8); VALVE_LIMIT_PLUS = (int16_t) (msg.data[3] | msg.data[4] << 8); - - spi_eeprom_write(RID_VALVE_LIMIT_MINUS, (int16_t) VALVE_LIMIT_MINUS); - spi_eeprom_write(RID_VALVE_LIMIT_PLUS, (int16_t) VALVE_LIMIT_PLUS); + ROM_RESET_DATA(); + //spi_eeprom_write(RID_VALVE_LIMIT_MINUS, (int16_t) VALVE_LIMIT_MINUS); + //spi_eeprom_write(RID_VALVE_LIMIT_PLUS, (int16_t) VALVE_LIMIT_PLUS); break; } @@ -428,8 +473,8 @@ case CRX_SET_ENC_PULSE_PER_POSITION: { ENC_PULSE_PER_POSITION = (int16_t) (msg.data[1] | msg.data[2] << 8); - - spi_eeprom_write(RID_ENC_PULSE_PER_POSITION, (int16_t) ENC_PULSE_PER_POSITION); + ROM_RESET_DATA(); + //spi_eeprom_write(RID_ENC_PULSE_PER_POSITION, (int16_t) ENC_PULSE_PER_POSITION); break; } @@ -442,8 +487,8 @@ case CRX_SET_TORQUE_SENSOR_PULSE_PER_TORQUE: { TORQUE_SENSOR_PULSE_PER_TORQUE = (int16_t) (msg.data[1] | msg.data[2] << 8); - - spi_eeprom_write(RID_TORQUE_SENSOR_PULSE_PER_TORQUE, (int16_t) TORQUE_SENSOR_PULSE_PER_TORQUE); + ROM_RESET_DATA(); + //spi_eeprom_write(RID_TORQUE_SENSOR_PULSE_PER_TORQUE, (int16_t) TORQUE_SENSOR_PULSE_PER_TORQUE); break; } @@ -457,9 +502,9 @@ case CRX_SET_PRES_SENSOR_PULSE_PER_PRES: { PRES_SENSOR_A_PULSE_PER_BAR = (double) ((int16_t) (msg.data[1] | msg.data[2] << 8)) * 0.01; PRES_SENSOR_B_PULSE_PER_BAR = (double) ((int16_t) (msg.data[3] | msg.data[4] << 8)) * 0.01; - - spi_eeprom_write(RID_PRES_SENSOR_A_PULSE_PER_BAR, (int16_t) (PRES_SENSOR_A_PULSE_PER_BAR * 100.)); - spi_eeprom_write(RID_PRES_SENSOR_B_PULSE_PER_BAR, (int16_t) (PRES_SENSOR_B_PULSE_PER_BAR * 100.)); + ROM_RESET_DATA(); + //spi_eeprom_write(RID_PRES_SENSOR_A_PULSE_PER_BAR, (int16_t) (PRES_SENSOR_A_PULSE_PER_BAR * 100.)); + //(RID_PRES_SENSOR_B_PULSE_PER_BAR, (int16_t) (PRES_SENSOR_B_PULSE_PER_BAR * 100.)); break; } @@ -472,8 +517,8 @@ case CRX_SET_FRICTION: { FRICTION = (double) ((int16_t) (msg.data[1] | msg.data[2] << 8)) / 10.; - - spi_eeprom_write(RID_FRICTION, (int16_t) (FRICTION * 10.)); + ROM_RESET_DATA(); + //spi_eeprom_write(RID_FRICTION, (int16_t) (FRICTION * 10.)); break; } @@ -489,12 +534,12 @@ VALVE_GAIN_LPM_PER_V[4] = (double) msg.data[3] / 50.; VALVE_GAIN_LPM_PER_V[6] = (double) msg.data[4] / 50.; VALVE_GAIN_LPM_PER_V[8] = (double) msg.data[5] / 50.; - - spi_eeprom_write(RID_VALVE_GAIN_PLUS_1, (int16_t) (VALVE_GAIN_LPM_PER_V[0] * 100.)); - spi_eeprom_write(RID_VALVE_GAIN_PLUS_2, (int16_t) (VALVE_GAIN_LPM_PER_V[2] * 100.)); - spi_eeprom_write(RID_VALVE_GAIN_PLUS_3, (int16_t) (VALVE_GAIN_LPM_PER_V[4] * 100.)); - spi_eeprom_write(RID_VALVE_GAIN_PLUS_4, (int16_t) (VALVE_GAIN_LPM_PER_V[6] * 100.)); - spi_eeprom_write(RID_VALVE_GAIN_PLUS_5, (int16_t) (VALVE_GAIN_LPM_PER_V[8] * 100.)); + ROM_RESET_DATA(); + //spi_eeprom_write(RID_VALVE_GAIN_PLUS_1, (int16_t) (VALVE_GAIN_LPM_PER_V[0] * 100.)); + //spi_eeprom_write(RID_VALVE_GAIN_PLUS_2, (int16_t) (VALVE_GAIN_LPM_PER_V[2] * 100.)); + //spi_eeprom_write(RID_VALVE_GAIN_PLUS_3, (int16_t) (VALVE_GAIN_LPM_PER_V[4] * 100.)); + //spi_eeprom_write(RID_VALVE_GAIN_PLUS_4, (int16_t) (VALVE_GAIN_LPM_PER_V[6] * 100.)); + //spi_eeprom_write(RID_VALVE_GAIN_PLUS_5, (int16_t) (VALVE_GAIN_LPM_PER_V[8] * 100.)); break; } @@ -510,12 +555,12 @@ VALVE_GAIN_LPM_PER_V[5] = (double) msg.data[3] / 50.; VALVE_GAIN_LPM_PER_V[7] = (double) msg.data[4] / 50.; VALVE_GAIN_LPM_PER_V[9] = (double) msg.data[5] / 50.; - - spi_eeprom_write(RID_VALVE_GAIN_MINUS_1, (int16_t) (VALVE_GAIN_LPM_PER_V[1] * 100.)); - spi_eeprom_write(RID_VALVE_GAIN_MINUS_2, (int16_t) (VALVE_GAIN_LPM_PER_V[3] * 100.)); - spi_eeprom_write(RID_VALVE_GAIN_MINUS_3, (int16_t) (VALVE_GAIN_LPM_PER_V[5] * 100.)); - spi_eeprom_write(RID_VALVE_GAIN_MINUS_4, (int16_t) (VALVE_GAIN_LPM_PER_V[7] * 100.)); - spi_eeprom_write(RID_VALVE_GAIN_MINUS_5, (int16_t) (VALVE_GAIN_LPM_PER_V[9] * 100.)); + ROM_RESET_DATA(); + //spi_eeprom_write(RID_VALVE_GAIN_MINUS_1, (int16_t) (VALVE_GAIN_LPM_PER_V[1] * 100.)); + //spi_eeprom_write(RID_VALVE_GAIN_MINUS_2, (int16_t) (VALVE_GAIN_LPM_PER_V[3] * 100.)); + //spi_eeprom_write(RID_VALVE_GAIN_MINUS_3, (int16_t) (VALVE_GAIN_LPM_PER_V[5] * 100.)); + //spi_eeprom_write(RID_VALVE_GAIN_MINUS_4, (int16_t) (VALVE_GAIN_LPM_PER_V[7] * 100.)); + //(RID_VALVE_GAIN_MINUS_5, (int16_t) (VALVE_GAIN_LPM_PER_V[9] * 100.)); break; } @@ -561,8 +606,8 @@ } case CRX_SET_HOMEPOS_OFFSET: { HOMEPOS_OFFSET = (int16_t) (msg.data[1] | msg.data[2] << 8); - - spi_eeprom_write(RID_HOMEPOS_OFFSET, (int16_t) HOMEPOS_OFFSET); + ROM_RESET_DATA(); + //spi_eeprom_write(RID_HOMEPOS_OFFSET, (int16_t) HOMEPOS_OFFSET); break; } @@ -572,8 +617,8 @@ } case CRX_SET_HOMEPOS_VALVE_OPENING: { HOMEPOS_VALVE_OPENING = (int16_t) (msg.data[1] | msg.data[2] << 8); - - spi_eeprom_write(RID_HOMEPOS_VALVE_OPENING, (int16_t) HOMEPOS_VALVE_OPENING); + ROM_RESET_DATA(); + //spi_eeprom_write(RID_HOMEPOS_VALVE_OPENING, (int16_t) HOMEPOS_VALVE_OPENING); break; }