-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into #23-state-machine
- Loading branch information
Showing
11 changed files
with
368 additions
and
203 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#ifndef PROTEUS_FAULT_H | ||
#define PROTEUS_FAULT_H | ||
|
||
#include "cmsis_os.h" | ||
|
||
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 struct | ||
{ | ||
fault_code_t id; | ||
fault_sev_t severity; | ||
char *diag; | ||
} fault_data_t; | ||
|
||
/* Function to queue a fault */ | ||
int queue_fault(fault_data_t *fault_data); | ||
|
||
/* Defining Fault Hanlder Task */ | ||
void vFaultHandler(void *pv_params); | ||
extern osThreadId_t fault_handle; | ||
extern const osThreadAttr_t fault_handle_attributes; | ||
|
||
#endif // FAULT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#ifndef SSI_ENCODER_H | ||
#define SSI_ENCODER_H | ||
|
||
#include "stm32h7xx.h" | ||
#include "stm32h7xx_hal_spi.h" | ||
#include <stdint.h> | ||
|
||
typedef struct ssi_encoder { | ||
SPI_HandleTypeDef *hspi; | ||
} ssi_encoder_t; | ||
|
||
/** | ||
* @brief Creates new ssi encoder operating on given spi peripheral | ||
* | ||
* @param spi_handle | ||
* @return ssi_encoder_t* pointer to new ssi encoder object | ||
*/ | ||
ssi_encoder_t *ssi_encoder_init(SPI_HandleTypeDef *spi_handle); | ||
|
||
/** | ||
* @brief Reads absolute angle from encoder and converts it to radians | ||
* NOTE: The datasheet for the encoder states that the minimum delay | ||
* between reads must be between 12.5 us and 20.5 us | ||
* | ||
* @param encoder | ||
* @param angle pointer to angle in radians | ||
* @return int16_t nonzero if the read fails, 0 on success | ||
*/ | ||
int16_t ssi_encoder_get_angle(ssi_encoder_t *encoder, float *angle); | ||
|
||
#endif /* SSI_ENCODER_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#include "fault.h" | ||
#include "task.h" | ||
|
||
#define FAULT_HANDLE_QUEUE_SIZE 16 | ||
|
||
osMessageQueueId_t fault_handle_queue; | ||
|
||
osThreadId_t fault_handle; | ||
const osThreadAttr_t fault_handle_attributes = { | ||
.name = "FaultHandler", | ||
.stack_size = 128 * 8, | ||
.priority = (osPriority_t)osPriorityHigh7, | ||
}; | ||
|
||
int queue_fault(fault_data_t *fault_data) | ||
{ | ||
if (!fault_handle_queue) | ||
return -1; | ||
|
||
osMessageQueuePut(fault_handle_queue, fault_data, 0U, 0U); | ||
return 0; | ||
} | ||
|
||
void vFaultHandler(void *pv_params) | ||
{ | ||
fault_data_t fault_data; | ||
osStatus_t status; | ||
fault_handle_queue = osMessageQueueNew(FAULT_HANDLE_QUEUE_SIZE, sizeof(fault_data_t), NULL); | ||
|
||
for (;;) | ||
{ | ||
/* Wait until a message is in the queue, send messages when they are in the queue */ | ||
status = osMessageQueueGet(fault_handle_queue, &fault_data, NULL, osWaitForever); | ||
if (status == osOK) | ||
{ | ||
// TODO: add logging functionality? | ||
switch (fault_data.severity) | ||
{ | ||
case DEFCON1: /* Highest(1st) Priority */ | ||
break; | ||
case DEFCON2: | ||
break; | ||
case DEFCON3: | ||
break; | ||
case DEFCON4: | ||
break; | ||
case DEFCON5: /* Lowest Priority */ | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
/* Yield to other tasks */ | ||
osThreadYield(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.