Skip to content

Commit

Permalink
try with clang format ignore and format
Browse files Browse the repository at this point in the history
  • Loading branch information
jr1221 committed Jun 19, 2024
1 parent 5017c6a commit c2c0e74
Show file tree
Hide file tree
Showing 17 changed files with 411 additions and 386 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/format-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Run clang-format style check for C/C++ sources
uses: Northeastern-Electric-Racing/clang-format-action@main
with:
clang-format-version: '17'
clang-format-version: '18'
# only check core, embedded base covered internally
check-path: ${{ matrix.path['check'] }}
# massive regex to exclude anything CubeMX generated, could require tweaking. Uses posix extended
Expand Down
24 changes: 6 additions & 18 deletions CM4/Core/Inc/fault.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,15 @@

#include "cmsis_os.h"

typedef enum
{
DEFCON1 = 1,
DEFCON2,
DEFCON3,
DEFCON4,
DEFCON5
} fault_sev_t;
typedef enum { DEFCON1 = 1, DEFCON2, DEFCON3, DEFCON4, DEFCON5 } fault_sev_t;

// TODO: add actual fault codes
typedef enum
{
FAULTS_CLEAR = 0x0,
MAX_FAULTS
} fault_code_t;
typedef enum { FAULTS_CLEAR = 0x0, MAX_FAULTS } fault_code_t;

typedef struct
{
fault_code_t id;
fault_sev_t severity;
char *diag;
typedef struct {
fault_code_t id;
fault_sev_t severity;
char *diag;
} fault_data_t;

/* Function to queue a fault */
Expand Down
59 changes: 31 additions & 28 deletions CM4/Core/Src/ipcc.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,51 +7,54 @@
__attribute__((section(".CM4_SHARED_MEM"))) volatile ipcc_msg_t cm4_shared_mem;
__attribute__((section(".CM7_SHARED_MEM"))) volatile ipcc_msg_t cm7_shared_mem;

void ipcc_init(ipcc_t *ipcc, DMA_HandleTypeDef *tx_dma, int tx_hsem_id, int rx_hsem_id)
void ipcc_init(ipcc_t *ipcc, DMA_HandleTypeDef *tx_dma, int tx_hsem_id,
int rx_hsem_id)
{
/* Ensure TX channel works */
ipcc->tx_dma = tx_dma;
/* Ensure TX channel works */
ipcc->tx_dma = tx_dma;

/* Save Hardware Semaphore IDs */
ipcc->tx_sem_id = tx_hsem_id;
ipcc->rx_sem_id = rx_hsem_id;
/* Save Hardware Semaphore IDs */
ipcc->tx_sem_id = tx_hsem_id;
ipcc->rx_sem_id = rx_hsem_id;

assert(HAL_HSEM_FastTake(ipcc->tx_sem_id) == HAL_OK);
assert(HAL_HSEM_FastTake(ipcc->tx_sem_id) == HAL_OK);

/* Set address of local memory */
ipcc->rx_mem = &cm4_shared_mem;
ipcc->tx_mem = &cm7_shared_mem;
/* Set address of local memory */
ipcc->rx_mem = &cm4_shared_mem;
ipcc->tx_mem = &cm7_shared_mem;

/* Handshake of semaphores */
while(!HAL_HSEM_IsSemTaken(ipcc->rx_sem_id)){}
HAL_HSEM_Release(ipcc->tx_sem_id, 1);
/* Handshake of semaphores */
while (!HAL_HSEM_IsSemTaken(ipcc->rx_sem_id)) {
}
HAL_HSEM_Release(ipcc->tx_sem_id, 1);
}

HAL_StatusTypeDef ipcc_transfer(ipcc_t *ipcc, ipcc_msg_t *msg)
{
/* Make sure we are clear to send another message */
//if (HAL_HSEM_FastTake(ipcc->tx_sem_id) == HAL_ERROR)
// return HAL_BUSY;
/* Make sure we are clear to send another message */
//if (HAL_HSEM_FastTake(ipcc->tx_sem_id) == HAL_ERROR)
// return HAL_BUSY;

/* Start DMA transfer to other processor */
return HAL_DMA_Start_IT(ipcc->tx_dma, (uint32_t)msg, (uint32_t)ipcc->tx_mem, sizeof(ipcc_msg_t));
/* Start DMA transfer to other processor */
return HAL_DMA_Start_IT(ipcc->tx_dma, (uint32_t)msg,
(uint32_t)ipcc->tx_mem, sizeof(ipcc_msg_t));
}

void ipcc_signal(ipcc_t *ipcc)
{
/* Notify other processor */
HAL_HSEM_Release(ipcc->tx_sem_id, 1);
HAL_HSEM_ActivateNotification(ipcc->tx_sem_id);
HAL_HSEM_DeactivateNotification(ipcc->tx_sem_id);
/* Note that other processor should clear the flag to send another message */
/* Notify other processor */
HAL_HSEM_Release(ipcc->tx_sem_id, 1);
HAL_HSEM_ActivateNotification(ipcc->tx_sem_id);
HAL_HSEM_DeactivateNotification(ipcc->tx_sem_id);
/* Note that other processor should clear the flag to send another message */
}

void ipcc_receive(ipcc_t *ipcc)
{
/* Queue to the correct task */
if (HAL_HSEM_FastTake(ipcc->tx_sem_id) == HAL_ERROR)
return;
/* Queue to the correct task */
if (HAL_HSEM_FastTake(ipcc->tx_sem_id) == HAL_ERROR)
return;

/* Acknowledge finishing transaction */
HAL_HSEM_Release(ipcc->tx_sem_id, 1);
/* Acknowledge finishing transaction */
HAL_HSEM_Release(ipcc->tx_sem_id, 1);
}
76 changes: 36 additions & 40 deletions CM4/Core/Src/serial_monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <stdlib.h>
#include <string.h>

#define PRINTF_QUEUE_SIZE 16 /* Strings */
#define PRINTF_QUEUE_SIZE 16 /* Strings */

osMessageQueueId_t printf_queue;
osThreadId_t serial_monitor_handle;
Expand All @@ -16,53 +16,49 @@ const osThreadAttr_t serial_monitor_attributes;
*/
int serial_print(const char *format, ...)
{
va_list arg;
char *buffer = malloc(sizeof(char) * PRINTF_BUFFER_LEN);
if (buffer == NULL)
return -1;
va_list arg;
char *buffer = malloc(sizeof(char) * PRINTF_BUFFER_LEN);
if (buffer == NULL)
return -1;

/* Format Variadic Args into string */
va_start(arg, format);
size_t len = vsnprintf(buffer, PRINTF_BUFFER_LEN, format, arg);
va_end(arg);
/* Format Variadic Args into string */
va_start(arg, format);
size_t len = vsnprintf(buffer, PRINTF_BUFFER_LEN, format, arg);
va_end(arg);

/* Check to make sure we don't overflow buffer */
if (len > PRINTF_BUFFER_LEN - 1)
{
free(buffer);
return -2;
}
/* Check to make sure we don't overflow buffer */
if (len > PRINTF_BUFFER_LEN - 1) {
free(buffer);
return -2;
}

/* If string can't be queued */
osStatus_t stat = osMessageQueuePut(printf_queue, &buffer, 0U, 0U);
if (stat)
{
free(buffer);
return -3;
}
/* If string can't be queued */
osStatus_t stat = osMessageQueuePut(printf_queue, &buffer, 0U, 0U);
if (stat) {
free(buffer);
return -3;
}

return 0;
return 0;
}

void vSerialMonitor(void *pv_params)
{
char *message;
osStatus_t status;
char *message;
osStatus_t status;

printf_queue = osMessageQueueNew(PRINTF_QUEUE_SIZE, sizeof(char *), NULL);
printf_queue =
osMessageQueueNew(PRINTF_QUEUE_SIZE, sizeof(char *), NULL);

for (;;)
{
/* Wait until new printf message comes into queue */
status = osMessageQueueGet(printf_queue, &message, NULL, osWaitForever);
if (status != osOK)
{
// TODO: Trigger fault ?
}
else
{
printf(message);
free(message);
}
}
for (;;) {
/* Wait until new printf message comes into queue */
status = osMessageQueueGet(printf_queue, &message, NULL,
osWaitForever);
if (status != osOK) {
// TODO: Trigger fault ?
} else {
printf(message);
free(message);
}
}
}
1 change: 1 addition & 0 deletions CM7/Core/Inc/controls/.clang-format-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*
15 changes: 8 additions & 7 deletions CM7/Core/Inc/foc_ctrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
#include "pid.h"

typedef enum {
SECTOR_1 = 0,
SECTOR_2,
SECTOR_3,
SECTOR_4,
SECTOR_5,
SECTOR_6,
SECTOR_1 = 0,
SECTOR_2,
SECTOR_3,
SECTOR_4,
SECTOR_5,
SECTOR_6,
} sector_t;

typedef enum {
Expand Down Expand Up @@ -69,7 +69,8 @@ void foc_ctrl_init(foc_ctrl_t *controller);
osStatus_t foc_queue_frame(foc_ctrl_t *controller, foc_data_t *phase_currents);

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

extern const osThreadAttr_t foc_ctrl_attributes;

Expand Down
53 changes: 25 additions & 28 deletions CM7/Core/Inc/gatedriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,64 +12,61 @@
* Note that these phases readings should ALWAYS be mapped to the corresponding indices
* Ensure the ADC DMA is mapped the same across boards
*/
enum {
GATEDRV_PHASE_U,
GATEDRV_PHASE_V,
GATEDRV_PHASE_W,
GATEDRV_NUM_PHASES
};
enum { GATEDRV_PHASE_U, GATEDRV_PHASE_V, GATEDRV_PHASE_W, GATEDRV_NUM_PHASES };

enum {
GATEDRV_DC_CURRENT = GATEDRV_NUM_PHASES, /* Keep index rolling from phase enum */
GATEDRV_IGBT_TEMP,
GATEDRV_SIZE_OF_ADC_DMA
GATEDRV_DC_CURRENT =
GATEDRV_NUM_PHASES, /* Keep index rolling from phase enum */
GATEDRV_IGBT_TEMP,
GATEDRV_SIZE_OF_ADC_DMA
};

/* Definition of gatedriver struct */
typedef struct {
TIM_HandleTypeDef* tim;
osMutexId_t* tim_mutex;
TIM_OC_InitTypeDef pwm_cfg;
TIM_HandleTypeDef *tim;
osMutexId_t *tim_mutex;
TIM_OC_InitTypeDef pwm_cfg;
uint32_t pulses[GATEDRV_NUM_PHASES];

ADC_HandleTypeDef* phase_adc;
ADC_HandleTypeDef *phase_adc;
SPI_HandleTypeDef *adc_spi;
uint32_t intern_adc_buffer[GATEDRV_SIZE_OF_ADC_DMA];
uint32_t intern_adc_buffer[GATEDRV_SIZE_OF_ADC_DMA];

osMutexId_t* tim_mutex_mutex;
osMutexAttr_t tim_mutex_attr;
osMutexId_t* ext_adc_mutex;
osMutexAttr_t ext_adc_mutex_attr;
osMutexId_t *tim_mutex_mutex;
osMutexAttr_t tim_mutex_attr;
osMutexId_t *ext_adc_mutex;
osMutexAttr_t ext_adc_mutex_attr;

osThreadId_t write_thread;
foc_ctrl_t *controller;
osThreadId_t write_thread;
foc_ctrl_t *controller;

int initial_reading_taken;
float channel_offsets[3];
int initial_reading_taken;
float channel_offsets[3];
} gatedriver_t;

extern const osThreadAttr_t phase_actor_attributes;
void vPhaseActor(void *pv_params);

/* initialize a new gatedriver */
void gatedrv_init(gatedriver_t *gatedriver, TIM_HandleTypeDef* tim, ADC_HandleTypeDef *phase_adc, foc_ctrl_t *controller);
void gatedrv_init(gatedriver_t *gatedriver, TIM_HandleTypeDef *tim,
ADC_HandleTypeDef *phase_adc, foc_ctrl_t *controller);

/* Note: This has to atomically write to ALL PWM registers */
void gatedrv_write_pwm(gatedriver_t* drv, float duty_cycles[]);
void gatedrv_write_pwm(gatedriver_t *drv, float duty_cycles[]);

/* read the internal IGBT temp */
int16_t gatedrv_read_igbt_temp(gatedriver_t* drv);
int16_t gatedrv_read_igbt_temp(gatedriver_t *drv);

/* Read the phase currents */
void gatedrv_get_phase_currents(gatedriver_t *drv, float phase_currents[3]);

/* read the dc voltage (V) */
int16_t gatedrv_read_dc_voltage(gatedriver_t* drv);
int16_t gatedrv_read_dc_voltage(gatedriver_t *drv);

/* read the dc current (A) */
int16_t gatedrv_read_dc_current(gatedriver_t* drv);
int16_t gatedrv_read_dc_current(gatedriver_t *drv);

/* read the internal IGBT temp */
int16_t gatedrv_read_igbt_temp(gatedriver_t* drv);
int16_t gatedrv_read_igbt_temp(gatedriver_t *drv);

#endif /* GATEDRIVER_H */
2 changes: 1 addition & 1 deletion CM7/Core/Inc/ssi_encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <stdint.h>

typedef struct ssi_encoder {
SPI_HandleTypeDef *hspi;
SPI_HandleTypeDef *hspi;
} ssi_encoder_t;

/**
Expand Down
6 changes: 3 additions & 3 deletions CM7/Core/Inc/state_machine.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#include "proteus_config.h"

typedef struct {
state_t current_state;
osMutexId_t* state_mutex;
osMutexAttr_t state_mutex_attr;
state_t current_state;
osMutexId_t *state_mutex;
osMutexAttr_t state_mutex_attr;
} state_director_t;

extern osThreadId_t sm_director_handle;
Expand Down
1 change: 1 addition & 0 deletions CM7/Core/Src/controls/.clang-format-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*
Loading

0 comments on commit c2c0e74

Please sign in to comment.