C++ top level passthrough works

This commit is contained in:
Oskar Weigl
2017-09-19 18:08:45 -07:00
parent 2d6fd393e1
commit 6083dba2f6
7 changed files with 98 additions and 19 deletions
-10
View File
@@ -1,10 +0,0 @@
/**
******************************************************************************
* @file : version.h
* @brief : This file implements printf functionality
******************************************************************************
*/
#define ODRIVE_FW_VERSION_MAJOR 0
#define ODRIVE_FW_VERSION_MINOR 1
#define ODRIVE_FW_VERSION_PATCH 0
+6 -1
View File
@@ -78,7 +78,9 @@ C_SOURCES = \
Src/usbd_cdc_if.c \
Src/syscalls.c \
MotorControl/utils.c \
MotorControl/low_level.c
MotorControl/low_level.c
CPP_SOURCES = \
MotorControl/axis.cpp
ASM_SOURCES = \
startup/startup_stm32f405xx.s
@@ -155,6 +157,9 @@ vpath %.s $(sort $(dir $(ASM_SOURCES)))
$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR)
@$(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@
$(BUILD_DIR)/%.o: %.cpp Makefile | $(BUILD_DIR)
@$(CXX) -c $(CXXFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.cpp=.lst)) $< -o $@
$(BUILD_DIR)/%.o: %.s Makefile | $(BUILD_DIR)
@$(AS) -c $(CFLAGS) $< -o $@
+23
View File
@@ -0,0 +1,23 @@
#include "axis.hpp"
//TODO: goal of refactor is to kick this out completely
extern "C" {
#include "low_level.h"
}
// C interface
extern "C" {
void axis_thread_entry(void const* temp_motor_ptr) {
Motor_t* motor = (Motor_t*)temp_motor_ptr;
Axis axis(motor);
axis.StateMachineLoop();
}
} // extern "C"
Axis::Axis(Motor_t* legacy_motor_ref)
: legacy_motor_ref_(legacy_motor_ref) {}
void Axis::StateMachineLoop() {
motor_thread(legacy_motor_ref_);
}
+49
View File
@@ -0,0 +1,49 @@
#ifndef __AXIS_HPP
#define __AXIS_HPP
//TODO: goal of refactor is to kick this out completely
extern "C" {
#include "low_level.h"
}
//Outside axis:
//command handler
//callback dispatch
class Axis {
public:
//thread/os/system management
//timing log
//thread id
//etc.
//state machine
//control mode
//control_en/calib_ok
//error state
//motor
//current controller
//contains rotor phase logic
//motor level calibration routines
//low_level (implementation specifics)
//DRV driver
//adc callback handling
//pwm queueing
//rotor estimator
//kick out rotor phase logic
//pos/vel controller
//step/dir handler
// Object operation requires ptr to legacy object for now, TODO: get rid of this dep
Axis(Motor_t* legacy_motor_ref);
// Infinite loop that does calibration and enters main control loop as appropriate
void StateMachineLoop();
bool enable_control_;
bool do_calibration_;
Motor_t* legacy_motor_ref_;
};
#endif /* __AXIS_HPP */
+14
View File
@@ -0,0 +1,14 @@
#ifndef __AXIS_C_INTERFACE_H
#define __AXIS_C_INTERFACE_H
#ifdef __cplusplus
extern "C" {
#endif
void axis_thread_entry(void const * temp_motor_ptr);
#ifdef __cplusplus
}
#endif
#endif /* __AXIS_C_INTERFACE_H */
+3 -5
View File
@@ -156,16 +156,14 @@ void set_pos_setpoint(Motor_t* motor, float pos_setpoint, float vel_feed_forward
void set_vel_setpoint(Motor_t* motor, float vel_setpoint, float current_feed_forward);
void set_current_setpoint(Motor_t* motor, float current_setpoint);
void safe_assert(int arg);
void init_motor_control();
void step_cb(uint16_t GPIO_Pin);
void pwm_trig_adc_cb(ADC_HandleTypeDef* hadc, bool injected);
void vbus_sense_adc_cb(ADC_HandleTypeDef* hadc, bool injected);
//@TODO move motor thread to high level file
void motor_thread(void const * argument);
void safe_assert(int arg);
void init_motor_control();
//@TODO move cmd parsing to high level file
void motor_thread(void const * argument);
void motor_parse_cmd(uint8_t* buffer, int len);
#endif //__LOW_LEVEL_H
+3 -3
View File
@@ -54,7 +54,7 @@
/* USER CODE BEGIN Includes */
#include "freertos_vars.h"
#include "low_level.h"
#include "version.h"
#include "axis_c_interface.h"
/* USER CODE END Includes */
/* Variables -----------------------------------------------------------------*/
@@ -125,8 +125,8 @@ void StartDefaultTask(void const * argument)
init_motor_control();
// Start motor threads
osThreadDef(task_motor_0, motor_thread, osPriorityHigh+1, 0, 512);
osThreadDef(task_motor_1, motor_thread, osPriorityHigh, 0, 512);
osThreadDef(task_motor_0, axis_thread_entry, osPriorityHigh+1, 0, 512);
osThreadDef(task_motor_1, axis_thread_entry, osPriorityHigh, 0, 512);
thread_motor_0 = osThreadCreate(osThread(task_motor_0), &motors[0]);
thread_motor_1 = osThreadCreate(osThread(task_motor_1), &motors[1]);