-
Notifications
You must be signed in to change notification settings - Fork 0
CAN status and tasks stuff #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
changxu-liu
wants to merge
9
commits into
main
Choose a base branch
from
CAN_and_tasks_stuff
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f1138ab
CAN and tasks stuff
changxu-liu 7ffc4ac
remove old tests because causing Github check to fail
changxu-liu 8e507c1
fix MakeAllTests github check
changxu-liu 2343051
add void argument for RTOS tasks
changxu-liu 1f085b1
remove redundant while(1)
changxu-liu 27fe6fd
fix HSS Control task description
changxu-liu 08e651d
remove unused print status task for now
changxu-liu 87cad32
blank lines
changxu-liu f971971
make tasks less fat
changxu-liu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Submodule Embedded-Sharepoint
updated
183 files
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -7,3 +7,5 @@ | |
| #define PDU_MK1_NUM_CHANNELS 16 | ||
|
|
||
| #define PDU_MK1_REV_A true | ||
|
|
||
| #define PDU_MK1_PRINT_STATUS_VIA_UART true | ||
This file contains hidden or 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,32 @@ | ||
| // PDU_Mk1_CAN.h | ||
| // ---------------------------------------------------------------------------- | ||
| // BBPDU Mk1 CAN stuff | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "stm32xx_hal.h" | ||
|
|
||
| // drivers | ||
| #include "CAN_FD.h" | ||
|
|
||
| // DEFINES -------------------------------------------------------------------- | ||
|
|
||
| #define PDU_MK1_CAN_ID_PDUSTATUS 0x350 | ||
| #define PDU_MK1_CAN_MSGLEN_PDUSTATUS 5 | ||
| #define PDU_MK1_CAN_PDUSTATUS_FAULT_LSHIFT 4 | ||
| #define PDU_MK1_CAN_PDUSTATUS_ENABLED_LSHIFT 5 | ||
| #define PDU_MK1_CAN_PDUSTATUS_VOLTAGE_INDEX 1 | ||
| #define PDU_MK1_CAN_PDUSTATUS_VOLTAGE_INVFACTOR 1000 // 1/0.001 = 1000 | ||
| #define PDU_MK1_CAN_PDUSTATUS_CURRENT_INDEX 3 | ||
| #define PDU_MK1_CAN_PDUSTATUS_CURRENT_INVFACTOR 1000 // 1/0.001 = 1000 | ||
|
|
||
| // VARIABLE DECLARATIONS ------------------------------------------------------ | ||
|
|
||
| // FUNCTIONS ------------------------------------------------------------------ | ||
|
|
||
| /** | ||
| * @brief Initializes CAN stuff. | ||
| * @param None | ||
| * @retval bool: true if successful, false otherwise | ||
| */ | ||
| can_status_t PDU_Mk1_CAN_Init(); |
175 changes: 175 additions & 0 deletions
175
firmware/PowerDistributionUnit_Mk1/core/src/PDU_Mk1_CAN.c
This file contains hidden or 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,175 @@ | ||
| // PDU_Mk1_CAN.c | ||
|
|
||
| #include "PDU_Mk1_CAN.h" | ||
| #include "printf.h" | ||
|
|
||
| #define FDCAN_NVIC_PRIO configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY + 3 | ||
|
|
||
| uint32_t HAL_RCC_FDCAN_CLK_ENABLED = 0; | ||
|
|
||
| can_status_t PDU_Mk1_CAN_Init() | ||
| { | ||
| can_status_t status; | ||
| hfdcan3->Instance = FDCAN3; | ||
| hfdcan3->Init.ClockDivider = FDCAN_CLOCK_DIV1; | ||
| hfdcan3->Init.FrameFormat = FDCAN_FRAME_CLASSIC; | ||
| hfdcan3->Init.Mode = FDCAN_MODE_EXTERNAL_LOOPBACK; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| hfdcan3->Init.AutoRetransmission = DISABLE; | ||
| hfdcan3->Init.TransmitPause = DISABLE; | ||
| hfdcan3->Init.ProtocolException = DISABLE; | ||
| hfdcan3->Init.NominalPrescaler = 20; | ||
| hfdcan3->Init.NominalSyncJumpWidth = 1; | ||
| hfdcan3->Init.NominalTimeSeg1 = 13; | ||
| hfdcan3->Init.NominalTimeSeg2 = 2; | ||
| hfdcan3->Init.DataPrescaler = 1; | ||
| hfdcan3->Init.DataSyncJumpWidth = 1; | ||
| hfdcan3->Init.DataTimeSeg1 = 1; | ||
| hfdcan3->Init.DataTimeSeg2 = 1; | ||
| hfdcan3->Init.StdFiltersNbr = 1; | ||
| hfdcan3->Init.ExtFiltersNbr = 0; | ||
| hfdcan3->Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; | ||
|
|
||
| // FDCAN1 Filter Config | ||
| FDCAN_FilterTypeDef sFilterConfig; | ||
| sFilterConfig.IdType = FDCAN_STANDARD_ID; | ||
| sFilterConfig.FilterIndex = 0; | ||
| sFilterConfig.FilterType = FDCAN_FILTER_MASK; | ||
| sFilterConfig.FilterConfig = FDCAN_FILTER_TO_RXFIFO0; // directs frames to FIFO0 | ||
| sFilterConfig.FilterID1 = 0x000; | ||
| sFilterConfig.FilterID2 = 0x000; | ||
|
|
||
| status = can_fd_init(hfdcan3, &sFilterConfig); | ||
| if(status != CAN_OK) | ||
| { | ||
| return status; | ||
| } | ||
|
|
||
| status = can_fd_start(hfdcan3); | ||
| if(status != CAN_OK){ | ||
| return status; | ||
| } | ||
|
|
||
| return CAN_OK; | ||
| } | ||
|
|
||
| void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef* fdcanHandle) | ||
| { | ||
|
|
||
| GPIO_InitTypeDef GPIO_InitStruct = {0}; | ||
| RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; | ||
|
|
||
| if(0){ // placeholder for if else if there are no FDCANs defined | ||
|
|
||
| } | ||
| #ifdef FDCAN1 | ||
| else if(fdcanHandle->Instance==FDCAN1) | ||
| { | ||
|
|
||
| PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_FDCAN; | ||
| PeriphClkInit.FdcanClockSelection = RCC_FDCANCLKSOURCE_PCLK1; | ||
| if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) | ||
| { | ||
| Error_Handler(); | ||
| } | ||
|
|
||
| /* FDCAN1 clock enable */ | ||
| HAL_RCC_FDCAN_CLK_ENABLED++; | ||
| if(HAL_RCC_FDCAN_CLK_ENABLED==1){ | ||
| __HAL_RCC_FDCAN_CLK_ENABLE(); | ||
| } | ||
|
|
||
| __HAL_RCC_GPIOA_CLK_ENABLE(); | ||
| /**FDCAN1 GPIO Configuration | ||
| PA11 ------> FDCAN1_RX | ||
| PA12 ------> FDCAN1_TX | ||
| */ | ||
| GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12; | ||
| GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; | ||
| GPIO_InitStruct.Pull = GPIO_NOPULL; | ||
| GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; | ||
| GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN1; | ||
| HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); | ||
|
|
||
| /* FDCAN1 interrupt Init */ | ||
| HAL_NVIC_SetPriority(FDCAN1_IT0_IRQn, FDCAN_NVIC_PRIO, 0); | ||
| HAL_NVIC_EnableIRQ(FDCAN1_IT0_IRQn); | ||
| HAL_NVIC_SetPriority(FDCAN1_IT1_IRQn, FDCAN_NVIC_PRIO, 0); | ||
| HAL_NVIC_EnableIRQ(FDCAN1_IT1_IRQn); | ||
| } | ||
| #endif // FDCAN1 | ||
| #ifdef FDCAN2 | ||
| else if(fdcanHandle->Instance==FDCAN2) | ||
| { | ||
|
|
||
| PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_FDCAN; | ||
| PeriphClkInit.FdcanClockSelection = RCC_FDCANCLKSOURCE_PCLK1; | ||
| if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) | ||
| { | ||
| Error_Handler(); | ||
| } | ||
|
|
||
| /* FDCAN2 clock enable */ | ||
| HAL_RCC_FDCAN_CLK_ENABLED++; | ||
| if(HAL_RCC_FDCAN_CLK_ENABLED==1){ | ||
| __HAL_RCC_FDCAN_CLK_ENABLE(); | ||
| } | ||
|
|
||
| __HAL_RCC_GPIOB_CLK_ENABLE(); | ||
| /**FDCAN2 GPIO Configuration | ||
| PB12 ------> FDCAN2_RX | ||
| PB13 ------> FDCAN2_TX | ||
| */ | ||
| GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_13; | ||
| GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; | ||
| GPIO_InitStruct.Pull = GPIO_NOPULL; | ||
| GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; | ||
| GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN2; | ||
| HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); | ||
|
|
||
| /* FDCAN2 interrupt Init */ | ||
| HAL_NVIC_SetPriority(FDCAN2_IT0_IRQn, FDCAN_NVIC_PRIO, 0); | ||
| HAL_NVIC_EnableIRQ(FDCAN2_IT0_IRQn); | ||
| HAL_NVIC_SetPriority(FDCAN2_IT1_IRQn, FDCAN_NVIC_PRIO, 0); | ||
| HAL_NVIC_EnableIRQ(FDCAN2_IT1_IRQn); | ||
|
|
||
| } | ||
| #endif // FDCAN2 | ||
|
|
||
| #ifdef FDCAN3 | ||
| else if(fdcanHandle->Instance==FDCAN3) | ||
| { | ||
| /** Initializes the peripherals clocks | ||
| */ | ||
| PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_FDCAN; | ||
| PeriphClkInit.FdcanClockSelection = RCC_FDCANCLKSOURCE_PCLK1; | ||
| if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) | ||
| { | ||
| Error_Handler(); | ||
| } | ||
|
|
||
| /* FDCAN3 clock enable */ | ||
| HAL_RCC_FDCAN_CLK_ENABLED++; | ||
| if(HAL_RCC_FDCAN_CLK_ENABLED==1){ | ||
| __HAL_RCC_FDCAN_CLK_ENABLE(); | ||
| } | ||
|
|
||
| __HAL_RCC_GPIOA_CLK_ENABLE(); | ||
| /**FDCAN3 GPIO Configuration | ||
| PA8 ------> FDCAN3_RX | ||
| PA15 ------> FDCAN3_TX | ||
| */ | ||
| GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_15; | ||
| GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; | ||
| GPIO_InitStruct.Pull = GPIO_NOPULL; | ||
| GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; | ||
| GPIO_InitStruct.Alternate = GPIO_AF11_FDCAN3; | ||
| HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); | ||
|
|
||
| /* FDCAN3 interrupt Init */ | ||
| HAL_NVIC_SetPriority(FDCAN3_IT0_IRQn, FDCAN_NVIC_PRIO, 0); | ||
| HAL_NVIC_EnableIRQ(FDCAN3_IT0_IRQn); | ||
| HAL_NVIC_SetPriority(FDCAN3_IT1_IRQn, FDCAN_NVIC_PRIO, 0); | ||
| HAL_NVIC_EnableIRQ(FDCAN3_IT1_IRQn); | ||
| } | ||
| #endif | ||
| } | ||
This file contains hidden or 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,24 @@ | ||
| // Task_Blink.h | ||
| // ---------------------------------------------------------------------------- | ||
| // Task blinks LED at fixed interval. | ||
|
|
||
| #pragma once | ||
|
|
||
| // INCLUDES ------------------------------------------------------------------- | ||
|
|
||
| #include "stm32xx_hal.h" | ||
|
|
||
| #include "PDU_Mk1_Pins.h" | ||
|
|
||
| // DEFINES -------------------------------------------------------------------- | ||
|
|
||
| #define TASK_BLINK_STACK_SIZE configMINIMAL_STACK_SIZE | ||
| #define TASK_BLINK_PRIORITY tskIDLE_PRIORITY + 2 | ||
|
|
||
| #define TASK_BLINK_INTERVAL_MS 500 | ||
|
|
||
| // VARIABLE DECLARATIONS ------------------------------------------------------ | ||
|
|
||
| // FUNCTIONS ------------------------------------------------------------------ | ||
|
|
||
| void Task_Blink(void *argument); |
30 changes: 30 additions & 0 deletions
30
firmware/PowerDistributionUnit_Mk1/tasks/inc/Task_CanSendStatus.h
This file contains hidden or 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,30 @@ | ||
| // Task_ReadCurrents.h | ||
| // ---------------------------------------------------------------------------- | ||
| // Task sends PDU status on CAN. | ||
|
|
||
| #pragma once | ||
|
|
||
| // INCLUDES ------------------------------------------------------------------- | ||
|
|
||
| #include "stm32xx_hal.h" | ||
| #include "printf.h" | ||
|
|
||
| #include "PDU_Mk1.h" | ||
| #include "PDU_Mk1_CAN.h" | ||
| #include "PDU_Mk1_CurrentSensing.h" | ||
| #include "PDU_Mk1_HSSControl.h" | ||
|
|
||
| // DEFINES -------------------------------------------------------------------- | ||
|
|
||
| #define TASK_CANSENDSTATUS_STACK_SIZE configMINIMAL_STACK_SIZE+200 | ||
| #define TASK_CANSENDSTATUS_PRIORITY tskIDLE_PRIORITY + 2 | ||
|
|
||
| // sets how often the CAN status is sent | ||
| #define TASK_CANSENDSTATUS_CH_INTERVAL_MS 100 // single channel mode | ||
| // #define TASK_CANSENDSTATUS_INTERVAL_MS 1000 // spam all channels (doesn't work) | ||
|
|
||
| // VARIABLE DECLARATIONS ------------------------------------------------------ | ||
|
|
||
| // FUNCTIONS ------------------------------------------------------------------ | ||
|
|
||
| void Task_CanSendStatus(void *argument); |
26 changes: 26 additions & 0 deletions
26
firmware/PowerDistributionUnit_Mk1/tasks/inc/Task_HSSControl.h
This file contains hidden or 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,26 @@ | ||
| // Task_HSSControl.h | ||
| // ---------------------------------------------------------------------------- | ||
| // Task controls PDU output channels. | ||
|
|
||
| #pragma once | ||
|
|
||
| // INCLUDES ------------------------------------------------------------------- | ||
|
|
||
| #include "stm32xx_hal.h" | ||
| #include "printf.h" | ||
|
|
||
| // BBPDU peripherals | ||
| #include "PDU_Mk1_HSSControl.h" | ||
|
|
||
| // DEFINES -------------------------------------------------------------------- | ||
|
|
||
| #define TASK_HSSCONTROL_STACK_SIZE configMINIMAL_STACK_SIZE+200 | ||
| #define TASK_HSSCONTROL_PRIORITY tskIDLE_PRIORITY + 2 | ||
|
|
||
| #define TASK_HSSCONTROL_INTERVAL_MS 1000 | ||
|
|
||
| // VARIABLE DECLARATIONS ------------------------------------------------------ | ||
|
|
||
| // FUNCTIONS ------------------------------------------------------------------ | ||
|
|
||
| void Task_HSSControl(void *argument); |
This file contains hidden or 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,50 @@ | ||
| // Task_Init.h | ||
| // ---------------------------------------------------------------------------- | ||
| // Task inits everything. | ||
|
|
||
| #pragma once | ||
|
|
||
| // INCLUDES ------------------------------------------------------------------- | ||
|
|
||
| #include "stm32xx_hal.h" | ||
|
|
||
| #include "PDU_Mk1_Pins.h" | ||
| #include "PDU_Mk1_GPIO.h" | ||
| #include "PDU_Mk1_SPI.h" | ||
| #include "PDU_Mk1_UART.h" | ||
| #include "PDU_Mk1_CAN.h" | ||
|
|
||
| #include "PDU_Mk1_CurrentSensing.h" | ||
| #include "PDU_Mk1_HSSControl.h" | ||
|
|
||
| // DEFINES -------------------------------------------------------------------- | ||
|
|
||
| #define TASK_INIT_STACK_SIZE configMINIMAL_STACK_SIZE+1000 | ||
| #define TASK_INIT_PRIORITY tskIDLE_PRIORITY + 3 | ||
|
|
||
| // VARIABLE DECLARATIONS ------------------------------------------------------ | ||
|
|
||
| extern TaskHandle_t task_blink; | ||
| extern TaskHandle_t task_readcurrents; | ||
| extern TaskHandle_t task_cansendstatus; | ||
|
|
||
| extern SemaphoreHandle_t spi1_mutex; // Mutex to prevent simultaneous SPI access | ||
| extern StaticSemaphore_t spi1_mutex_buffer; // Static buffer for mutex allocation | ||
| extern SemaphoreHandle_t spi1_done_sem; // Semaphore to signal SPI IT completion | ||
| extern StaticSemaphore_t spi1_done_sem_buffer; // Static buffer for completion semaphore | ||
|
|
||
| extern SemaphoreHandle_t spi2_mutex; // Mutex to prevent simultaneous SPI access | ||
| extern StaticSemaphore_t spi2_mutex_buffer; // Static buffer for mutex allocation | ||
| extern SemaphoreHandle_t spi2_done_sem; // Semaphore to signal SPI IT completion | ||
| extern StaticSemaphore_t spi2_done_sem_buffer; // Static buffer for completion semaphore | ||
|
|
||
| extern SemaphoreHandle_t spi3_mutex; // Mutex to prevent simultaneous SPI access | ||
| extern StaticSemaphore_t spi3_mutex_buffer; // Static buffer for mutex allocation | ||
| extern SemaphoreHandle_t spi3_done_sem; // Semaphore to signal SPI IT completion | ||
| extern StaticSemaphore_t spi3_done_sem_buffer; // Static buffer for completion semaphore | ||
|
|
||
| // FUNCTIONS ------------------------------------------------------------------ | ||
|
|
||
| void PDU_Mk1_StartTasks(); | ||
|
|
||
| void Task_Init(void *argument); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.