Skip to content

Commit

Permalink
formatingg/linting
Browse files Browse the repository at this point in the history
  • Loading branch information
Akashem06 committed Sep 29, 2024
1 parent 7001eaf commit c6c3487
Show file tree
Hide file tree
Showing 19 changed files with 157 additions and 335 deletions.
2 changes: 1 addition & 1 deletion libraries/core/inc/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#define SIZEOF_ARRAY(arr) (sizeof((arr)) / sizeof((arr)[0]))
#define SIZEOF_FIELD(type, field) (sizeof(((type *)0)->field))
// Casts void * to uint8_t *
#define VOID_PTR_UINT8(x) (_Generic((x), void * : (uint8_t *)(x), default : (x)))
#define VOID_PTR_UINT8(x) (_Generic((x), void *: (uint8_t *)(x), default: (x)))
#define SWAP_UINT16(x) (uint16_t)(((uint16_t)(x) >> 8) | ((uint16_t)(x) << 8))

#define STRINGIFY_(x) #x
Expand Down
2 changes: 1 addition & 1 deletion libraries/ms-common/inc/delay.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ void delay_ms(uint32_t t);
void non_blocking_delay_ms(uint32_t t);

// Delay for a period in seconds.
#define delay_s(time) delay_ms((time)*1000)
#define delay_s(time) delay_ms((time) * 1000)
2 changes: 1 addition & 1 deletion libraries/ms-common/inc/flash.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

#define FLASH_ADDR_TO_PAGE(addr) \
(((uintptr_t)(addr) - (uintptr_t)FLASH_BASE_ADDR) / FLASH_PAGE_BYTES)
#define FLASH_PAGE_TO_ADDR(page) ((uintptr_t)(page)*FLASH_PAGE_BYTES + (uintptr_t)FLASH_BASE_ADDR)
#define FLASH_PAGE_TO_ADDR(page) ((uintptr_t)(page) * FLASH_PAGE_BYTES + (uintptr_t)FLASH_BASE_ADDR)
#define FLASH_WRITE_BYTES FLASH_MCU_WRITE_BYTES
#define FLASH_PAGE_BYTES FLASH_MCU_PAGE_BYTES

Expand Down
3 changes: 1 addition & 2 deletions libraries/ms-freertos/inc/FreeRTOSConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ extern uint32_t SystemCoreClock;
#define configASSERT(x) \
if ((x) == 0) { \
taskDISABLE_INTERRUPTS(); \
for (;;) \
; \
for (;;); \
}

// Definitions that map the FreeRTOS port interrupt handlers to their CMSIS
Expand Down
6 changes: 2 additions & 4 deletions projects/bms_carrier/inc/bms.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@
#include "status.h"

#define BMS_PERIPH_I2C_PORT I2C_PORT_2
#define BMS_PERIPH_I2C_SDA_PIN \
{ .port = GPIO_PORT_B, .pin = 11 }
#define BMS_PERIPH_I2C_SCL_PIN \
{ .port = GPIO_PORT_B, .pin = 10 }
#define BMS_PERIPH_I2C_SDA_PIN { .port = GPIO_PORT_B, .pin = 11 }
#define BMS_PERIPH_I2C_SCL_PIN { .port = GPIO_PORT_B, .pin = 10 }

typedef struct CurrentStorage {
uint16_t soc;
Expand Down
12 changes: 4 additions & 8 deletions projects/bms_carrier/inc/cell_sense.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,10 @@
#define AFE_BALANCING_LOWER_THRESHOLD 40000

#define AFE_SPI_PORT SPI_PORT_2
#define AFE_SPI_CS \
{ .port = GPIO_PORT_B, .pin = 12 }
#define AFE_SPI_SCK \
{ .port = GPIO_PORT_B, .pin = 13 }
#define AFE_SPI_MISO \
{ .port = GPIO_PORT_B, .pin = 14 }
#define AFE_SPI_MOSI \
{ .port = GPIO_PORT_B, .pin = 15 }
#define AFE_SPI_CS { .port = GPIO_PORT_B, .pin = 12 }
#define AFE_SPI_SCK { .port = GPIO_PORT_B, .pin = 13 }
#define AFE_SPI_MISO { .port = GPIO_PORT_B, .pin = 14 }
#define AFE_SPI_MOSI { .port = GPIO_PORT_B, .pin = 15 }

StatusCode cell_sense_init(BmsStorage *bms_store);

Expand Down
3 changes: 2 additions & 1 deletion projects/bootloader/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"arm_libs": [
"stm32f10x"
]
],
"no_lint": true
}
2 changes: 1 addition & 1 deletion projects/bootloader/inc/boot_crc32.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include "bootloader.h"

#define BYTES_TO_WORD(bytes) (bytes / 4)
#define BYTES_TO_WORD(bytes) (bytes / 4)

BootloaderError crc_init(void);
uint32_t crc_calculate(const uint32_t *buffer, size_t buffer_len);
Expand Down
3 changes: 1 addition & 2 deletions projects/bootloader/inc/bootloader_mcu.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ extern uint32_t _ram_start;
extern uint32_t _ram_size;
extern uint32_t _vector_table_size;

#define APP_START_ADDRESS ((uint32_t)&_application_start)
#define APP_START_ADDRESS ((uint32_t) & _application_start)
#define BOOTLOADER_APPLICATION_SIZE ((size_t)_application_size)
#define RAM_START_ADDRESS (_ram_start)
#define BOOTLOADER_RAM_SIZE ((size_t)_ram_size)
#define BOOTLOADER_VECTOR_TABLE_SIZE ((size_t)_vector_table_size)


// ERROR DATA
typedef enum {
/// @brief no data is found
Expand Down
17 changes: 9 additions & 8 deletions projects/bootloader/src/boot_crc32.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "boot_crc32.h"

#include "stm32f10x.h"
#include "stm32f10x_crc.h"

Expand All @@ -11,17 +12,17 @@ BootloaderError crc_init(void) {
}

uint32_t crc_calculate(const uint32_t *buffer, size_t buffer_len) {
CRC_ResetDR();
CRC_ResetDR();

for (size_t i = 0; i < buffer_len; i++) {
CRC_CalcCRC(buffer[i]);
}
for (size_t i = 0; i < buffer_len; i++) {
CRC_CalcCRC(buffer[i]);
}

return ~CRC_GetCRC();
return ~CRC_GetCRC();
}

void align_to_32bit_words(uint8_t *buffer, size_t *buffer_len) {
uint8_t padding = (4 - (*buffer_len % 4)) % 4;
memset(buffer + *buffer_len, 0, padding);
*buffer_len += padding;
uint8_t padding = (4 - (*buffer_len % 4)) % 4;
memset(buffer + *buffer_len, 0, padding);
*buffer_len += padding;
}
23 changes: 14 additions & 9 deletions projects/bootloader/src/bootloader.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "bootloader.h"

#include "boot_crc32.h"

// Store CAN traffic in 1024 byte buffer to write to flash
Expand Down Expand Up @@ -156,7 +157,7 @@ static BootloaderError bootloader_data_ready() {
}

static BootloaderError bootloader_data_receive() {
BootloaderError error = BOOTLOADER_ERROR_NONE;
BootloaderError error = BOOTLOADER_ERROR_NONE;
if (!prv_bootloader.first_byte_received) {
send_ack_datagram(false, BOOTLOADER_INTERNAL_ERR);
return BOOTLOADER_INTERNAL_ERR;
Expand All @@ -170,22 +171,25 @@ static BootloaderError bootloader_data_receive() {
if (BOOTLOADER_PAGE_BYTES - prv_bootloader.buffer_index < 8) {
bytes_to_copy = BOOTLOADER_PAGE_BYTES - prv_bootloader.buffer_index;
}
if (prv_bootloader.binary_size - (prv_bootloader.buffer_index + prv_bootloader.bytes_written) < 8) {
bytes_to_copy = prv_bootloader.binary_size - (prv_bootloader.buffer_index + prv_bootloader.bytes_written);
if (prv_bootloader.binary_size - (prv_bootloader.buffer_index + prv_bootloader.bytes_written) <
8) {
bytes_to_copy =
prv_bootloader.binary_size - (prv_bootloader.buffer_index + prv_bootloader.bytes_written);
}

memcpy(flash_buffer + prv_bootloader.buffer_index, datagram.payload.data.binary_data, bytes_to_copy);
memcpy(flash_buffer + prv_bootloader.buffer_index, datagram.payload.data.binary_data,
bytes_to_copy);
prv_bootloader.buffer_index += bytes_to_copy;

if (prv_bootloader.buffer_index == BOOTLOADER_PAGE_BYTES ||
(prv_bootloader.bytes_written + prv_bootloader.buffer_index) >= prv_bootloader.binary_size) {

uint32_t calculated_crc32 = crc_calculate((const uint32_t *)flash_buffer, BYTES_TO_WORD(prv_bootloader.buffer_index));
(prv_bootloader.bytes_written + prv_bootloader.buffer_index) >= prv_bootloader.binary_size) {
uint32_t calculated_crc32 =
crc_calculate((const uint32_t *)flash_buffer, BYTES_TO_WORD(prv_bootloader.buffer_index));
if (calculated_crc32 != prv_bootloader.packet_crc32) {
send_ack_datagram(false, BOOTLOADER_CRC_MISMATCH_BEFORE_WRITE);
return BOOTLOADER_CRC_MISMATCH_BEFORE_WRITE;
}

error |= boot_flash_erase(BOOTLOADER_ADDR_TO_PAGE(prv_bootloader.current_address));
error |= boot_flash_write(prv_bootloader.current_address, flash_buffer, BOOTLOADER_PAGE_BYTES);
error |= boot_flash_read(prv_bootloader.current_address, flash_buffer, BOOTLOADER_PAGE_BYTES);
Expand All @@ -195,7 +199,8 @@ static BootloaderError bootloader_data_receive() {
return error;
}

calculated_crc32 = crc_calculate((uint32_t *)flash_buffer, BYTES_TO_WORD(prv_bootloader.buffer_index));
calculated_crc32 =
crc_calculate((uint32_t *)flash_buffer, BYTES_TO_WORD(prv_bootloader.buffer_index));
if (calculated_crc32 != prv_bootloader.packet_crc32) {
send_ack_datagram(false, BOOTLOADER_CRC_MISMATCH_AFTER_WRITE);
return BOOTLOADER_CRC_MISMATCH_AFTER_WRITE;
Expand Down
4 changes: 2 additions & 2 deletions projects/bootloader/src/can_datagram.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ BootloaderDatagram_t unpack_datagram(Boot_CanMessage *msg, uint16_t *target_node
void send_ack_datagram(bool ack, BootloaderError error) {
error_buffer[0] = ack;
uint16_t status_code = error;
error_buffer[1] = (uint8_t) (error << 8);
error_buffer[2] = (uint8_t) (error);
error_buffer[1] = (uint8_t)(error << 8);
error_buffer[2] = (uint8_t)(error);

boot_can_transmit(CAN_ARBITRATION_ACK_ID, false, error_buffer, sizeof(error_buffer));
}
90 changes: 0 additions & 90 deletions projects/bootloader/test/test_can_datagram.c

This file was deleted.

Loading

0 comments on commit c6c3487

Please sign in to comment.