Skip to content

Commit

Permalink
190 more notificaitons, check mph before drive state transition, peda…
Browse files Browse the repository at this point in the history
…ls processing task, malloc and stack overflow hooks
  • Loading branch information
Sabramz committed Aug 4, 2024
1 parent 39f7b27 commit 941ca77
Show file tree
Hide file tree
Showing 19 changed files with 342 additions and 317 deletions.
2 changes: 1 addition & 1 deletion .mxproject

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Core/Inc/FreeRTOSConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@
#define configUSE_16_BIT_TICKS 0
#define configUSE_MUTEXES 1
#define configQUEUE_REGISTRY_SIZE 8
#define configCHECK_FOR_STACK_OVERFLOW 1
#define configUSE_RECURSIVE_MUTEXES 1
#define configUSE_MALLOC_FAILED_HOOK 1
#define configUSE_COUNTING_SEMAPHORES 1
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 0
/* USER CODE BEGIN MESSAGE_BUFFER_LENGTH_TYPE */
Expand Down
2 changes: 2 additions & 0 deletions Core/Inc/nero.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "cmsis_os.h"
#include "stm32f4xx_hal.h"

#define NERO_UPDATE_FLAG 1U

/*
* Tells NERO the current MPH
*/
Expand Down
23 changes: 22 additions & 1 deletion Core/Inc/processing.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,21 @@
#include "cmsis_os.h"
#include "stdbool.h"

#define TSMS_UPDATE_FLAG 0x00000001U
#define TSMS_UPDATE_FLAG 1U
#define PEDAL_DATA_FLAG 1U

#define PIT_MAX_SPEED 5.0 /* mph */
#define ACCUMULATOR_SIZE 10 /* size of the accumulator for averaging */

/*
* Increases the torque limit by 10%
*/
void increase_torque_limit();

/*
* Decreases the torque limit by 10%
*/
void decrease_torque_limit();

/**
* @brief Get the debounced TSMS reading.
Expand All @@ -31,4 +45,11 @@ void vProcessTSMS(void *pv_params);
extern osThreadId_t process_tsms_thread_id;
extern const osThreadAttr_t process_tsms_attributes;

/**
* @brief Task for processing pedal data.
*/
void vProcessPedals(void *pv_params);
extern osThreadId_t process_pedals_thread;
extern const osThreadAttr_t torque_calc_attributes;

#endif
4 changes: 2 additions & 2 deletions Core/Inc/queues.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ typedef struct {
extern osMessageQueueId_t imu_queue;

typedef struct {
uint16_t brake_value; /* 0-1 */
uint16_t accelerator_value; /* 0-1 */
uint16_t brake_value;
uint16_t accelerator_value; /* 0-100 */
} pedals_t;

extern osMessageQueueId_t pedal_data_queue;
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 @@ -214,7 +214,7 @@
#define MAC_ADDR5 0U

/* Definition of the Ethernet driver buffers size and count */
#define ETH_RX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for receive */
#define ETH_RX_BUF_SIZE /* buffer size for receive */
#define ETH_TX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for transmit */
#define ETH_RXBUFNB 4U /* 4 Rx buffers of size ETH_RX_BUF_SIZE */
#define ETH_TXBUFNB 4U /* 4 Tx buffers of size ETH_TX_BUF_SIZE */
Expand Down
38 changes: 0 additions & 38 deletions Core/Inc/torque.h

This file was deleted.

2 changes: 2 additions & 0 deletions Core/Src/dti.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <stdio.h>
#include "bms.h"
#include "serial_monitor.h"
#include "nero.h"

#define CAN_QUEUE_SIZE 5 /* messages */
#define SAMPLES 20
Expand Down Expand Up @@ -284,6 +285,7 @@ static void dti_record_rpm(dti_t *mc, can_msg_t msg)
osMutexAcquire(*mc->mutex, osWaitForever);
mc->rpm = rpm;
osMutexRelease(*mc->mutex);
set_mph(dti_get_mph(mc));
}

void vDTIRouter(void *pv_params)
Expand Down
36 changes: 34 additions & 2 deletions Core/Src/freertos.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */

#include <stdio.h>
/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
Expand Down Expand Up @@ -52,8 +52,40 @@

/* USER CODE END FunctionPrototypes */

/* Hook prototypes */
void vApplicationStackOverflowHook(xTaskHandle xTask, signed char *pcTaskName);
void vApplicationMallocFailedHook(void);

/* USER CODE BEGIN 4 */
void vApplicationStackOverflowHook(xTaskHandle xTask, signed char *pcTaskName)
{
/* Run time stack overflow checking is performed if
configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook function is
called if a stack overflow is detected. */
printf("ERROR: STACK OVERFLOW in ");
printf((char *)pcTaskName);
printf("\r\n");
}
/* USER CODE END 4 */

/* USER CODE BEGIN 5 */
void vApplicationMallocFailedHook(void)
{
/* vApplicationMallocFailedHook() will only be called if
configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h. It is a hook
function that will get called if a call to pvPortMalloc() fails.
pvPortMalloc() is called internally by the kernel whenever a task, queue,
timer or semaphore is created. It is also called by various parts of the
demo application. If heap_1.c or heap_2.c are used, then the size of the
heap available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in
FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used
to query the size of free heap space that remains (although it does not
provide information on how the remaining heap might be fragmented). */
printf("ERROR: MALLOC FAILED\r\n");
}
/* USER CODE END 5 */

/* Private application code --------------------------------------------------*/
/* USER CODE BEGIN Application */

/* USER CODE END Application */

9 changes: 3 additions & 6 deletions Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#include "serial_monitor.h"
#include "state_machine.h"
#include "bms.h"
#include "torque.h"
#include "pdu.h"
#include "nero.h"
#include "mpu.h"
Expand Down Expand Up @@ -138,7 +137,6 @@ int _write(int file, char* ptr, int len) {
*/
int main(void)
{

/* USER CODE BEGIN 1 */
printf("BOOT\r\n");
/* USER CODE END 1 */
Expand Down Expand Up @@ -253,11 +251,11 @@ int main(void)
assert(nero_monitor_handle);

/* Control Logic */
torque_calc_handle = osThreadNew(vCalcTorque, mc, &torque_calc_attributes);
assert(torque_calc_handle);
process_pedals_thread = osThreadNew(vProcessPedals, mc, &torque_calc_attributes);
assert(process_pedals_thread);
fault_handle = osThreadNew(vFaultHandler, NULL, &fault_handle_attributes);
assert(fault_handle);
sm_director_handle = osThreadNew(vStateMachineDirector, pdu, &sm_director_attributes);
sm_director_handle = osThreadNew(vStateMachineDirector, mc, &sm_director_attributes);
assert(sm_director_handle);
brakelight_control_thread = osThreadNew(vBrakelightControl, pdu, &brakelight_monitor_attributes);;
assert(brakelight_control_thread);
Expand All @@ -272,7 +270,6 @@ int main(void)
osKernelStart();

/* We should never get here as control is now taken by the scheduler */

/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
Expand Down
1 change: 1 addition & 0 deletions Core/Src/monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ void vPedalsMonitor(void *pv_params)
/* Publish to Onboard Pedals Queue */
osStatus_t check = osMessageQueuePut(pedal_data_queue,
&sensor_data, 0U, 0U);
osThreadFlagsSet(process_pedals_thread, PEDAL_DATA_FLAG);

if (check != 0) {
fault_data.diag = "Failed to push pedal data to queue";
Expand Down
5 changes: 3 additions & 2 deletions Core/Src/nero.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ static void send_mode_status()
void set_mph(int8_t new_mph)
{
mph = new_mph;
osThreadFlagsSet(nero_monitor_handle, NERO_UPDATE_FLAG);
}

osThreadId_t nero_monitor_handle;
Expand All @@ -40,8 +41,8 @@ const osThreadAttr_t nero_monitor_attributes = {
void vNeroMonitor(void *pv_params)
{
for (;;) {
osThreadFlagsWait(NERO_UPDATE_FLAG, osFlagsWaitAny,
osWaitForever);
send_mode_status();

osDelay(NERO_DELAY_TIME);
}
}
Loading

0 comments on commit 941ca77

Please sign in to comment.