Skip to content

Commit

Permalink
some improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
FranciscoLlobet committed Feb 23, 2024
1 parent 604c5d4 commit 1abcdf5
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 26 deletions.
42 changes: 42 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
Checks: >
-*,
bugprone-*,
performance-*,
portability-*,
readability-*,
modernize-*,
cppcoreguidelines-*,
clang-analyzer-*,
cert-*
WarningsAsErrors: '*'
HeaderFilterRegex: '.*'
FormatStyle: 'file'

CheckOptions:
- key: modernize-use-auto
value: '0'
- key: modernize-use-using
value: '0'
- key: modernize-avoid-bind
value: '0'
- key: modernize-use-nullptr
value: '0'
- key: modernize-use-override
value: '0'
- key: cppcoreguidelines-avoid-magic-numbers
value: '0'
- key: cppcoreguidelines-pro-bounds-array-to-pointer-decay
value: '0'
- key: cppcoreguidelines-pro-type-vararg
value: '0'
- key: readability-magic-numbers
value: '1'
- key: bugprone-exception-escape
value: '0'
- key: cert-msc30-c
value: '0'
- key: cert-msc50-cpp
value: '0'
- key: readability-function-cognitive-complexity-threshold
value: '15'
6 changes: 3 additions & 3 deletions csrc/board/inc/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -365,10 +365,10 @@ extern sl_led_t led_orange;
extern sl_led_t led_yellow;

/* SPI DRV Handles */
extern SPIDRV_HandleData_t sd_card_usart;
extern SPIDRV_HandleData_t cc3100_usart;
//extern SPIDRV_HandleData_t sd_card_usart;
//extern SPIDRV_HandleData_t cc3100_usart;

extern UARTDRV_HandleData_t em9301_uart;
//extern UARTDRV_HandleData_t em9301_uart;

extern uint8_t usb_rx_buf[64];
extern uint8_t usb_tx_buf[64];
Expand Down
2 changes: 1 addition & 1 deletion csrc/board/src/board_CC3100.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ static SemaphoreHandle_t rx_queue = NULL;
#define CC3100_SPI_RX_TIMEOUT_MS (1000)
#define CC3100_SPI_TX_TIMEOUT_MS (1000)

SPIDRV_HandleData_t cc3100_usart;
static SPIDRV_HandleData_t cc3100_usart;

const SPIDRV_Init_t cc3100_usart_init_data =
{ .port = WIFI_SERIAL_PORT, .portLocation = _USART_ROUTE_LOCATION_LOC0,
Expand Down
26 changes: 21 additions & 5 deletions csrc/board/src/board_sd_card.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "semphr.h"

/* SPI DRV Handle */
SPIDRV_HandleData_t sd_card_usart;
static SPIDRV_HandleData_t sd_card_usart;

/* Detect SD Card */
static void card_detect_callback(uint8_t intNo);
Expand Down Expand Up @@ -84,6 +84,22 @@ void BOARD_SD_Card_Enable(void)
true);

(void)BOARD_SD_CARD_IsInserted();

/* SPI DRV Init */
SPIDRV_Init_t sd_card_init_data = {
.port = BOARD_SD_CARD_USART,
.portLocation = _USART_ROUTE_LOCATION_LOC1,
.bitRate = BOARD_SD_CARD_WAKEUP_BITRATE,
.frameLength = 8,
.dummyTxValue = 0xFF,
.type = spidrvMaster,
.bitOrder = spidrvBitOrderMsbFirst,
.clockMode = spidrvClockMode0,
.csControl = spidrvCsControlApplication,
.slaveStartMode = spidrvSlaveStartImmediate,
};

(void)SPIDRV_Init(&sd_card_usart, &sd_card_init_data);
}

void BOARD_SD_Card_Disable(void)
Expand Down Expand Up @@ -130,7 +146,7 @@ void BOARD_SD_CARD_SetSlowBaudrate(void)


/* recieve callback for async reception */
static void _recieve_callback(struct SPIDRV_HandleData *handle,
static void recieve_callback(struct SPIDRV_HandleData *handle,
Ecode_t transferStatus,
int itemsTransferred)
{
Expand All @@ -145,7 +161,7 @@ static void _recieve_callback(struct SPIDRV_HandleData *handle,
}

/* tx callback for async tx */
static void _send_callback(struct SPIDRV_HandleData *handle,
static void send_callback(struct SPIDRV_HandleData *handle,
Ecode_t transferStatus,
int itemsTransferred)
{
Expand All @@ -165,7 +181,7 @@ uint32_t BOARD_SD_CARD_Recieve(void * buffer, int count)
Ecode_t ecode = ECODE_EMDRV_SPIDRV_PARAM_ERROR;
if(rx_semaphore != NULL) // Change to check if scheduler is active
{
ecode = SPIDRV_MReceive(&sd_card_usart, buffer, count, _recieve_callback);
ecode = SPIDRV_MReceive(&sd_card_usart, buffer, count, recieve_callback);
if(ECODE_EMDRV_SPIDRV_OK == ecode)
{
(void)xQueueReceive( rx_semaphore, &ecode, portMAX_DELAY);
Expand All @@ -186,7 +202,7 @@ uint32_t BOARD_SD_CARD_Send(const void * buffer, int count)
Ecode_t ecode = ECODE_EMDRV_SPIDRV_PARAM_ERROR;
if(tx_semaphore != NULL) // Change to check if scheduler is active
{
ecode = SPIDRV_MTransmit(&sd_card_usart, buffer, count, _send_callback);
ecode = SPIDRV_MTransmit(&sd_card_usart, buffer, count, send_callback);
if(ECODE_EMDRV_SPIDRV_OK == ecode)
{
(void)xQueueReceive( tx_semaphore, &ecode, portMAX_DELAY);
Expand Down
18 changes: 1 addition & 17 deletions csrc/board/src/sdmm.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
MODIFICATIONS:
UISO, 2022-2023
MISO, 2022-2024
Modifications to add simplified logic to interface with the board
Expand Down Expand Up @@ -319,22 +319,6 @@ DSTATUS disk_initialize (

BOARD_SD_Card_Enable();

/* SPI DRV Init */
SPIDRV_Init_t sd_card_init_data = {
.port = BOARD_SD_CARD_USART,
.portLocation = _USART_ROUTE_LOCATION_LOC1,
.bitRate = BOARD_SD_CARD_WAKEUP_BITRATE,
.frameLength = 8,
.dummyTxValue = 0xFF,
.type = spidrvMaster,
.bitOrder = spidrvBitOrderMsbFirst,
.clockMode = spidrvClockMode0,
.csControl = spidrvCsControlApplication,
.slaveStartMode = spidrvSlaveStartImmediate,
};

SPIDRV_Init(&sd_card_usart, &sd_card_init_data);

rcvr_mmc(buf, 10);

ty = 0;
Expand Down
84 changes: 84 additions & 0 deletions src/spi.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
//! SPI object

const c = @cImport({
@cInclude("board.h");
@cInclude("miso.h");
@cInclude("miso_config.h");
});

const freertos = @import("freertos.zig");

const ecode = c.Ecode_t;
//const spiDrvHandle
const txferElement = struct {
status: ecode, // status
items: isize, // number of items transfered
};

pub fn Spi() type {
return struct {
spidrvHandle: c.SPIDRV_HandleData_t,

txQueue: freertos.StaticQueue(txferElement, 1),
rxQueue: freertos.StaticQueue(txferElement, 1),
//spiDrvHandle: c.SPIDRV_HandleData_t,

fn recieve_callback(handle: c.SPIDRV_HandleData_t, buffer: []u8, n: usize) callconv(.C) void {
var xHigherPriorityTaskWoken: freertos.BaseType_t = freertos.pdFALSE;
const transfer_status_information = txferElement{ .status = c.ECODE_EMDRV_SPIDRV_OK, .items = n };

// self.xQueueSendFromISR(&transfer_status_information, &xHigherPriorityTaskWoken);

freertos.portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
fn send_callback(handle: c.SPIDRV_HandleData_t, buffer: []u8, n: usize) callconv(.C) void {
var xHigherPriorityTaskWoken: freertos.BaseType_t = freertos.pdFALSE;
const transfer_status_information = txferElement{ .status = c.ECODE_EMDRV_SPIDRV_OK, .items = n };

// self.xQueueSendFromISR(&transfer_status_information, &xHigherPriorityTaskWoken);

freertos.portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}

pub fn init(self: *@This(), spiDrvHandle: c.SPIDRV_HandleData_t) void {
//self.spidrvHandle = spiDrvHandle;
//self.txQueue = freertos.StaticQueue(txferElement, 1);
//self.rxQueue = freertos.StaticQueue(txferElement, 1);
}
pub fn deinit(self: *@This()) void {
//self.txQueue.deinit();
//self.rxQueue.deinit();
}

pub fn send(self: *@This(), data: []const u8, timeout_ticks: ?u32) !usize {
var itemsTransfered: usize = 0;

const spiEcode = c.SPIDRV_MTransmit(&self.spiDrvHandle, @ptrCast(data.ptr), @intCast(data.len), send_callback);
if (spiEcode == c.ECODE_EMDRV_SPIDRV_OK) {
if (self.txQueue.receive(timeout_ticks)) |val| {
if (val.status == c.ECODE_EMDRV_SPIDRV_OK) {
itemsTransfered = val.items;
}
} else |err| {
return err;
}
}
return itemsTransfered;
}
pub fn receive(self: *@This(), data: []u8, timeout_ticks: ?u32) ![]u8 {
var itemsTransfered: usize = 0;

const spiEcode = c.SPIDRV_MReceive(&self.spiDrvHandle, @ptrCast(data.ptr), @intCast(data.len), recieve_callback);
if (spiEcode == c.ECODE_EMDRV_SPIDRV_OK) {
if (self.rxQueue.receive(timeout_ticks)) |val| {
if (val.status == c.ECODE_EMDRV_SPIDRV_OK) {
itemsTransfered = val.items;
}
} else |err| {
return err;
}
}
return data[0..itemsTransfered];
}
};
}

0 comments on commit 1abcdf5

Please sign in to comment.