Move console and spindle setup into separate modules
Extract the terminal/console logic and the spindle initialisation out of main.c into dedicated modules so main only wires the components together. - Add consoleLogic.c/.h: init_console_custom() creates the console instance, registers the "capability" command and returns the handle. CapabilityFunc moved here from main.c. - Add spindleLogic.c/.h: init_spindle_custom(console, maxRPM, minRPM, absMinRPM) creates the spindle controller with the given RPM limits. Includes stub platform callbacks (SPINDLE_SetDutyCycle, SPINDLE_EnaPWM) that still need the PWM/H-bridge implementation. - main.c: keep console and spindle handles as static variables, pass the console handle to the spindle module, remove the second playground task. - .cproject: add Core/Inc/Console and Core/Inc/Spindle to the include paths of the CM7 project. - Include IDE-generated settings changes and the root Eclipse .project. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
bdb5db2009
commit
26fe4cc0cf
11 files changed
+167
-70
No files matched your search
@@ -0,0 +1,59 @@
|
||||
#include "consoleLogic.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include <stdio.h>
|
||||
|
||||
static ConsoleHandle_t s_console = NULL; // nur in dieser Datei sichtbar
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
static int CapabilityFunc( int argc, char** argv, void* ctx )
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
(void)ctx;
|
||||
printf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\r\nOK",
|
||||
0, // has spindle
|
||||
0, // has spindle status
|
||||
0, // has stepper
|
||||
0, // has stepper move relative
|
||||
0, // has stepper move speed
|
||||
0, // has stepper move async
|
||||
0, // has stepper status
|
||||
0, // has stepper refrun
|
||||
0, // has stepper refrun timeout
|
||||
0, // has stepper refrun skip
|
||||
0, // has stepper refrun stay enabled
|
||||
0, // has stepper reset
|
||||
0, // has stepper position
|
||||
0, // has stepper config
|
||||
0, // has stepper config torque
|
||||
0, // has stepper config throvercurr
|
||||
0, // has stepper config powerena
|
||||
0, // has stepper config stepmode
|
||||
0, // has stepper config timeoff
|
||||
0, // has stepper config timeon
|
||||
0, // has stepper config timefast
|
||||
0, // has stepper config mmperturn
|
||||
0, // has stepper config posmax
|
||||
0, // has stepper config posmin
|
||||
0, // has stepper config posref
|
||||
0, // has stepper config stepsperturn
|
||||
0 // has stepper cancel
|
||||
);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
ConsoleHandle_t init_console_custom(void)
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
s_console = CONSOLE_CreateInstance( 4*configMINIMAL_STACK_SIZE, configMAX_PRIORITIES - 5 );
|
||||
|
||||
// register capability function
|
||||
CONSOLE_RegisterCommand(s_console, "capability", "prints a specified string of capability bits",
|
||||
CapabilityFunc, NULL);
|
||||
|
||||
return s_console;
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
#include "spindleLogic.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include <stddef.h>
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
static void add_console_commands(void)
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// platform function: called by the spindle library to set the PWM duty cycle (0.0 .. 1.0) and the direction
|
||||
static void SPINDLE_SetDutyCycle(SpindleHandle_t h, void* context, int backwards, float dutyCycle)
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
(void)h;
|
||||
(void)context;
|
||||
(void)backwards;
|
||||
(void)dutyCycle;
|
||||
// TODO: set PWM duty cycle and direction
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// platform function: called by the spindle library to enable (1) or disable (0) PWM and the half bridges
|
||||
static void SPINDLE_EnaPWM(SpindleHandle_t h, void* context, int ena)
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
(void)h;
|
||||
(void)context;
|
||||
(void)ena;
|
||||
// TODO: enable / disable PWM output and half bridges
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
SpindleHandle_t init_spindle_custom(ConsoleHandle_t console, float maxRPM, float minRPM, float absMinRPM)
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
add_console_commands();
|
||||
SpindlePhysicalParams_t s;
|
||||
s.maxRPM = maxRPM;
|
||||
s.minRPM = minRPM;
|
||||
s.absMinRPM = absMinRPM;
|
||||
s.setDutyCycle = SPINDLE_SetDutyCycle;
|
||||
s.enaPWM = SPINDLE_EnaPWM;
|
||||
s.context = NULL;
|
||||
|
||||
// the library copies the params, therefore a local struct is fine here
|
||||
return SPINDLE_CreateInstance( 4*configMINIMAL_STACK_SIZE, configMAX_PRIORITIES - 3, console, &s );
|
||||
}
|
||||
@@ -27,6 +27,9 @@
|
||||
#include "queue.h"
|
||||
#include "stdio.h"
|
||||
#include "assert.h"
|
||||
#include "Console.h"
|
||||
#include "consoleLogic.h"
|
||||
#include "spindleLogic.h"
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
@@ -57,7 +60,8 @@ TIM_HandleTypeDef htim2;
|
||||
UART_HandleTypeDef huart3;
|
||||
|
||||
/* USER CODE BEGIN PV */
|
||||
|
||||
static ConsoleHandle_t console;
|
||||
static SpindleHandle_t spindle;
|
||||
/* USER CODE END PV */
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
@@ -103,7 +107,7 @@ static void playgroundTask(void* args)
|
||||
{
|
||||
(void)args;
|
||||
|
||||
printf("Hello World\r\n");
|
||||
printf("Hnot ello World\r\n");
|
||||
|
||||
while(1) {
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
@@ -114,63 +118,6 @@ static void playgroundTask(void* args)
|
||||
|
||||
}
|
||||
|
||||
static void playgroundTask2(void* args)
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
(void)args;
|
||||
|
||||
printf("Hello World\r\n");
|
||||
|
||||
|
||||
while(1) {
|
||||
vTaskDelay(pdMS_TO_TICKS(2000));
|
||||
HAL_GPIO_TogglePin(LED_YELLOW_GPIO_Port, LED_YELLOW_Pin);
|
||||
}
|
||||
|
||||
vTaskDelete(xTaskGetCurrentTaskHandle());
|
||||
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
static int CapabilityFunc( int argc, char** argv, void* ctx )
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
(void)ctx;
|
||||
printf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\r\nOK",
|
||||
0, // has spindle
|
||||
0, // has spindle status
|
||||
0, // has stepper
|
||||
0, // has stepper move relative
|
||||
0, // has stepper move speed
|
||||
0, // has stepper move async
|
||||
0, // has stepper status
|
||||
0, // has stepper refrun
|
||||
0, // has stepper refrun timeout
|
||||
0, // has stepper refrun skip
|
||||
0, // has stepper refrun stay enabled
|
||||
0, // has stepper reset
|
||||
0, // has stepper position
|
||||
0, // has stepper config
|
||||
0, // has stepper config torque
|
||||
0, // has stepper config throvercurr
|
||||
0, // has stepper config powerena
|
||||
0, // has stepper config stepmode
|
||||
0, // has stepper config timeoff
|
||||
0, // has stepper config timeon
|
||||
0, // has stepper config timefast
|
||||
0, // has stepper config mmperturn
|
||||
0, // has stepper config posmax
|
||||
0, // has stepper config posmin
|
||||
0, // has stepper config posref
|
||||
0, // has stepper config stepsperturn
|
||||
0 // has stepper cancel
|
||||
);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define BKPSRAM_BASE 0x38800000UL
|
||||
|
||||
typedef struct {
|
||||
@@ -295,10 +242,12 @@ int main(void)
|
||||
|
||||
// create a playground task at the very beginning
|
||||
xTaskCreate(playgroundTask, "playground", 1024, NULL, 1, NULL);
|
||||
xTaskCreate(playgroundTask2, "playground2", 1024, NULL, 1, NULL);
|
||||
|
||||
// mask a compiler warning by referencing the function but not using it (void cast)
|
||||
(void)CapabilityFunc;
|
||||
// create the console processor. There are no additional arguments required because it uses stdin, stderr and
|
||||
// stdout of the stdlib of the platform
|
||||
console = init_console_custom();
|
||||
spindle = init_spindle_custom(console, 9000, -9000, 1600);
|
||||
|
||||
|
||||
// start the scheduler and setup free rtos execution context
|
||||
vTaskStartScheduler();
|
||||
|
||||
Reference in new issue
Block a user