Skip to content

Commit

Permalink
add adcs and can id conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
jr1221 committed May 24, 2024
1 parent c4d9c00 commit 0809e47
Show file tree
Hide file tree
Showing 22 changed files with 566 additions and 179 deletions.
7 changes: 4 additions & 3 deletions .mxproject

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions Core/Inc/FreeRTOSConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
#if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__)
#include <stdint.h>
extern uint32_t SystemCoreClock;
void xPortSysTickHandler(void);
#endif
#ifndef CMSIS_device_header
#define CMSIS_device_header "stm32f4xx.h"
Expand Down Expand Up @@ -162,7 +161,7 @@ standard names. */

/* IMPORTANT: After 10.3.1 update, Systick_Handler comes from NVIC (if SYS timebase = systick), otherwise from cmsis_os2.c */

#define USE_CUSTOM_SYSTICK_HANDLER_IMPLEMENTATION 1
#define USE_CUSTOM_SYSTICK_HANDLER_IMPLEMENTATION 0

/* USER CODE BEGIN Defines */
/* Section where parameter definitions can be added (for instance, to override default ones in FreeRTOS.h) */
Expand Down
6 changes: 3 additions & 3 deletions Core/Inc/can_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
#include "can.h"
#include "cmsis_os.h"

void can1_callback(CAN_HandleTypeDef* hcan);
void can1_callback(CAN_HandleTypeDef *hcan);

void vCanDispatch(void* pv_params);
void vCanDispatch(void *pv_params);
extern osThreadId_t can_dispatch_handle;
extern const osThreadAttr_t can_dispatch_attributes;

int8_t queue_can_msg(can_msg_t msg);
void init_can1(CAN_HandleTypeDef* hcan);
void init_can1(CAN_HandleTypeDef *hcan);

#endif
10 changes: 10 additions & 0 deletions Core/Inc/controller.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef CONTROL_MSB
#define CONTROL_MSB

#include "cmsis_os.h"

void vLedController(void *pv_params);
extern osThreadId_t led_controller_handle;
extern const osThreadAttr_t led_controller_attributes;

#endif
3 changes: 2 additions & 1 deletion Core/Inc/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,13 @@ extern "C" {
void Error_Handler(void);

/* USER CODE BEGIN EFP */

/* USER CODE END EFP */

/* Private defines -----------------------------------------------------------*/
#define VCC5_En_Pin GPIO_PIN_2
#define VCC5_En_GPIO_Port GPIOC
#define Shockpot_Pin GPIO_PIN_0
#define Shockpot_GPIO_Port GPIOA
#define Strain1_Pin GPIO_PIN_5
#define Strain1_GPIO_Port GPIOA
#define Strain2_Pin GPIO_PIN_6
Expand Down
12 changes: 10 additions & 2 deletions Core/Inc/monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,21 @@
#include "stm32f4xx_hal.h"

/* Defining Temperature Monitor Task */
void vTempMonitor(void* pv_params);
void vTempMonitor(void *pv_params);
extern osThreadId_t temp_monitor_handle;
extern const osThreadAttr_t temp_monitor_attributes;

/* Task for Monitoring the IMU */
void vIMUMonitor(void* pv_params);
void vIMUMonitor(void *pv_params);
extern osThreadId_t imu_monitor_handle;
extern const osThreadAttr_t imu_monitor_attributes;

void vShockpotMonitor(void *pv_params);
extern osThreadId_t shockpot_monitor_handle;
extern const osThreadAttr_t shockpot_monitor_attributes;

void vStrainMonitor(void *pv_params);
extern osThreadId_t strain_monitor_handle;
extern const osThreadAttr_t strain_monitor_attributes;

#endif
21 changes: 8 additions & 13 deletions Core/Inc/msb.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,17 @@ typedef struct
sht30_t *temp_sensor;
lsm6dso_t *imu;
ADC_HandleTypeDef *adc1;
uint32_t adc1_buf[3];
GPIO_TypeDef *debug_led1_gpio;
uint16_t *debug_led1_pin;
GPIO_TypeDef *debug_led2_gpio;
uint16_t *debug_led2_pin;
device_loc_t *device_loc;
osMutexId_t *adc_mutex;
osMutexId_t *i2c_mutex;
} msb_t;

typedef struct
{
int8_t channel_0;
int8_t channel_1;
int8_t channel_2;
int8_t channel_3;
} adc_channels;

msb_t *init_msb(I2C_HandleTypeDef *hi2c, ADC_HandleTypeDef *adc1, GPIO_TypeDef *debug_led1_gpio,
uint16_t *debug_led1_pin, GPIO_TypeDef *debug_led2_gpio, uint16_t *debug_led2_pin,
msb_t *init_msb(I2C_HandleTypeDef *hi2c, ADC_HandleTypeDef *adc1, GPIO_TypeDef *debug_led1_gpio,
uint16_t *debug_led1_pin, GPIO_TypeDef *debug_led2_gpio, uint16_t *debug_led2_pin,
device_loc_t *device_loc);

int8_t measure_central_temp(msb_t *msb, uint16_t *temp, uint16_t *humidity);
Expand All @@ -48,9 +40,12 @@ int8_t read_accel(msb_t *msb, uint16_t accel[3]);

int8_t read_gyro(msb_t *msb, uint16_t gyro[3]);

int8_t write_debug1(msb_t* msb, bool status);
int8_t write_debug1(msb_t *msb, bool status);

int8_t write_debug2(msb_t* msb, bool status);
int8_t write_debug2(msb_t *msb, bool status);

void read_shockpot(msb_t *msb, uint32_t shockpot_sense);
void read_strain1(msb_t *msb, uint32_t strain1);
void read_strain2(msb_t *msb, uint32_t strain2);

#endif
12 changes: 10 additions & 2 deletions Core/Inc/msb_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@
#define DELAY_CAN_DISPATCH 5
#define DELAY_TEMP_SENSOR_REFRESH 500
#define DELAY_IMU_REFRESH 500
#define DELAY_SHOCKPOT_REFRESH 500
#define DELAY_STRAIN_REFRESH 500
#define DELAY_TOF_REFRESH 500
#define DELAY_WHEEL_TEMP_REFRESH 500

#define DELAY_DEBUG_LED_REFRESH 250

// CAN IDS
#define CANID_TEMP_SENSOR 0x602
#define CANID_IMU_ACCEL 0x603
#define CANID_IMU_GYRO 0x604


#define CANID_STRAIN_SENSE 0x605
#define CANID_SHOCK_SENSE 0x606
#define CANID_TOF 0x607
#define CANID_WHEEL_TEMP 0x608
4 changes: 2 additions & 2 deletions Core/Inc/serial_monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
#include "cmsis_os.h"

/* Function to queue a message to be sent on the UART stream */
int serial_print(const char* format, ...);
int serial_print(const char *format, ...);

/* Defining Temperature Monitor Task */
void vSerialMonitor(void* pv_params);
void vSerialMonitor(void *pv_params);

extern osThreadId_t serial_monitor_handle;
extern const osThreadAttr_t serial_monitor_attributes;
Expand Down
2 changes: 1 addition & 1 deletion Core/Inc/stm32f4xx_hal_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
/* #define HAL_SD_MODULE_ENABLED */
/* #define HAL_MMC_MODULE_ENABLED */
#define HAL_SPI_MODULE_ENABLED
/* #define HAL_TIM_MODULE_ENABLED */
#define HAL_TIM_MODULE_ENABLED
#define HAL_UART_MODULE_ENABLED
/* #define HAL_USART_MODULE_ENABLED */
/* #define HAL_IRDA_MODULE_ENABLED */
Expand Down
2 changes: 1 addition & 1 deletion Core/Inc/stm32f4xx_it.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ void MemManage_Handler(void);
void BusFault_Handler(void);
void UsageFault_Handler(void);
void DebugMon_Handler(void);
void SysTick_Handler(void);
void CAN1_RX0_IRQHandler(void);
void TIM5_IRQHandler(void);
void DMA2_Stream0_IRQHandler(void);
/* USER CODE BEGIN EFP */

Expand Down
21 changes: 11 additions & 10 deletions Core/Src/can_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ static osMessageQueueId_t can_outbound_queue;

can_t *can1;

void init_can1(CAN_HandleTypeDef* hcan)
void init_can1(CAN_HandleTypeDef *hcan)
{
assert(hcan);

can1 = malloc(sizeof(can_t));
assert(can1);

can1->hcan = hcan;
can1->hcan = hcan;

assert(!can_init(can1));

Expand All @@ -40,19 +40,21 @@ void init_can1(CAN_HandleTypeDef* hcan)

osThreadId_t can_dispatch_handle;
const osThreadAttr_t can_dispatch_attributes = {
.name = "CanDispatch",
.name = "CanDispatch",
.stack_size = 128 * 8,
.priority = (osPriority_t)osPriorityRealtime5,
.priority = (osPriority_t)osPriorityRealtime5,
};

void vCanDispatch(void* pv_params)
void vCanDispatch(void *pv_params)
{
can_msg_t msg_from_queue;
HAL_StatusTypeDef msg_status;

for (;;) {
for (;;)
{
/* Send CAN message */
if (osOK == osMessageQueueGet(can_outbound_queue, &msg_from_queue, NULL, osWaitForever)) {
if (osOK == osMessageQueueGet(can_outbound_queue, &msg_from_queue, NULL, osWaitForever))
{
msg_status = can_send_msg(can1, &msg_from_queue);
if (msg_status == HAL_ERROR)
{
Expand All @@ -62,12 +64,12 @@ void vCanDispatch(void* pv_params)
{
serial_print("Outbound mailbox full!");
}
#ifdef LOG_VERBOSE
#ifdef LOG_VERBOSE
else
{
printf("Message sent: %lX\r\n", msg_from_queue.id);
}
#endif
#endif
}

osDelay(DELAY_CAN_DISPATCH);
Expand All @@ -82,4 +84,3 @@ int8_t queue_can_msg(can_msg_t msg)
osMessageQueuePut(can_outbound_queue, &msg, 0U, 0U);
return 0;
}

42 changes: 42 additions & 0 deletions Core/Src/controller.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include "controller.h"
#include "msb_conf.h"
#include "msb.h"

osThreadId_t led_controller_handle;
const osThreadAttr_t led_controller_attributes = {
.name = "LedController",
.stack_size = 32 * 8,
.priority = (osPriority_t)osPriorityBelowNormal1,
};

void vLedController(void *pv_params)
{

msb_t *msb = (msb_t *)pv_params;

switch (*msb->device_loc)
{
case DEVICE_FRONT_LEFT:
write_debug1(msb, true);
write_debug2(msb, true);
break;
case DEVICE_FRONT_RIGHT:
write_debug1(msb, true);
write_debug2(msb, false);
break;
case DEVICE_BACK_LEFT:
write_debug1(msb, false);
write_debug2(msb, true);
break;
case DEVICE_BACK_RIGHT:
write_debug1(msb, false);
write_debug2(msb, false);
break;
}

for (;;)
{

osDelay(DELAY_DEBUG_LED_REFRESH);
}
}
Loading

0 comments on commit 0809e47

Please sign in to comment.