Skip to content

Commit

Permalink
Adding in dequeue wrapper and adding to makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
nwdepatie committed Mar 13, 2024
1 parent 528a37d commit 447ac00
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
7 changes: 5 additions & 2 deletions CM7/Core/Inc/foc_ctrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ typedef struct {
osMessageQueueId_t command_queue;
} foc_ctrl_t;

foc_ctrl_t *init_foc_ctrl();
foc_ctrl_t *foc_ctrl_init();

/* Enqueue a single frame of controller observation */
int8_t queue_frame(foc_ctrl_t *controller, int16_t phase_currents[3]);
osStatus_t foc_queue_frame(foc_ctrl_t *controller, int16_t phase_currents[3]);

/* Wait for a command to be sent from the controller */
osStatus_t foc_retrieve_cmd(foc_ctrl_t *controller, int16_t duty_cycles[3]);

const osThreadAttr_t foc_ctrl_attributes = {
.name = "FOC Controller",
Expand Down
11 changes: 7 additions & 4 deletions CM7/Core/Src/foc_ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#define INBOUND_QUEUE_SIZE 15

foc_ctrl_t *init_foc_ctrl()
foc_ctrl_t *foc_ctrl_init()
{
/* Create FOC struct */
foc_ctrl_t* controller = malloc(sizeof(foc_ctrl_t));
Expand All @@ -13,14 +13,17 @@ foc_ctrl_t *init_foc_ctrl()
return controller;
}

int8_t queue_frame(foc_ctrl_t *controller, int16_t phase_currents[3])
osStatus_t foc_queue_frame(foc_ctrl_t *controller, int16_t phase_currents[3])
{
if (!controller->data_queue)
return -1;

osMessageQueuePut(controller->data_queue, phase_currents, 0U, 0U);
return osMessageQueuePut(controller->data_queue, phase_currents, 0U, 0U);
}

return 0;
osStatus_t foc_retrieve_cmd(foc_ctrl_t *controller, int16_t duty_cycles[3])
{
return osMessageQueueGet(controller->command_queue, duty_cycles, NULL, osWaitForever);
}

void vFOCctrl(void* pv_params)
Expand Down
1 change: 1 addition & 0 deletions Makefile/CM7/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ C_SOURCES = \
../../CM7/Core/Src/stm32h7xx_it.c \
../../CM7/Core/Src/stm32h7xx_hal_msp.c \
../../CM7/Core/Src/gatedriver.c \
../../CM7/Core/Src/foc_ctrl.c \
../../Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_cortex.c \
../../Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rcc.c \
../../Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rcc_ex.c \
Expand Down

0 comments on commit 447ac00

Please sign in to comment.