Skip to content

Commit

Permalink
update mqtt and fixing issue with the TLS connection
Browse files Browse the repository at this point in the history
  • Loading branch information
FranciscoLlobet committed Mar 8, 2024
1 parent 4f06fd1 commit f24d06d
Show file tree
Hide file tree
Showing 13 changed files with 304 additions and 183 deletions.
31 changes: 31 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@
"rtos": "FreeRTOS",
"swoConfig": { "cpuFrequency": 48000000, "swoFrequency": 875000, "enabled": true, "source": "socket", "decoders": [{"port": 0, "type": "console", "encoding": "ascii", "label": "Output"}]},
},
{
"cwd": "${workspaceFolder}",
"executable": "${workspaceRoot}/zig-out/firmware/mqtt.elf",
"name": "MQTT App MacOS",
"request": "launch",
"type": "cortex-debug",
"runToEntryPoint": "ResetHandler",
"showDevDebugOutput": "none",
"servertype": "jlink",
"device": "EFM32GG390F1024",
"interface": "swd",
"svdFile": "${workspaceRoot}/src/chips/EFM32GG390F1024.svd",
"rtos": "FreeRTOS",
"swoConfig": { "cpuFrequency": 48000000, "swoFrequency": 875000, "enabled": true, "source": "socket", "decoders": [{"port": 0, "type": "console", "encoding": "ascii", "label": "Output"}]},
},
{
"cwd": "${workspaceRoot}",
"executable": "${workspaceRoot}/zig-out/firmware/boot.elf",
Expand Down Expand Up @@ -67,6 +82,22 @@
"svdFile": "${workspaceRoot}/src/chips/EFM32GG390F1024.svd",
"rtos": "FreeRTOS",
"swoConfig": { "cpuFrequency": 48000000, "swoFrequency": 875000, "enabled": true, "source": "socket", "decoders": [{"port": 0, "type": "console", "encoding": "ascii", "label": "Output"}]},
} {
"cwd": "${workspaceRoot}",
"executable": "${workspaceRoot}/zig-out/firmware/mqtt.elf",
"name": "MQTT App WINDOWS",
"request": "launch",
"type": "cortex-debug",
"servertype": "jlink",
"serverpath": "C:\\Program Files\\SEGGER\\JLink\\JLinkGDBServerCL.exe",
"armToolchainPath": "C:\\Program Files (x86)\\Arm GNU Toolchain arm-none-eabi\\12.2 mpacbti-rel1\\bin",
"device": "EFM32GG390F1024",
"interface": "swd",
"runToEntryPoint": "ResetHandler"
"serialNumber": "", // add J-Link serial number if having multiple attached the same time.
"svdFile": "${workspaceRoot}/src/chips/EFM32GG390F1024.svd",
"rtos": "FreeRTOS",
"swoConfig": { "cpuFrequency": 48000000, "swoFrequency": 875000, "enabled": true, "source": "socket", "decoders": [{"port": 0, "type": "console", "encoding": "ascii", "label": "Output"}]},
}
]
}
9 changes: 8 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,14 @@
"__locale": "c",
"string": "c",
"string_view": "c",
"diskio.h": "c"
"diskio.h": "c",
"array": "c",
"span": "c",
"vector": "c",
"xstring": "c",
"xutility": "c",
"regex": "c",
"xiosbase": "c"
},
"cmake.configureOnOpen": false,
"cortex-debug.variableUseNaturalFormat": true
Expand Down
34 changes: 16 additions & 18 deletions csrc/board/inc/miso_spi.h
Original file line number Diff line number Diff line change
@@ -1,49 +1,47 @@
/**
* @file miso_spi.h
* @author Francisco
* @brief
* @brief
* @date 2024-03-08
*
*
* @copyright Copyright (c) 2024
*
*
*/

#ifndef __MISO_SPI_H__
#define __MISO_SPI_H__

#include "miso.h"

/**
/**
* @brief Miso Generic SPI error
*/
#define MISO_SPI_ERROR ((ssize_t)-127)
#define MISO_SPI_ERROR ((ssize_t)-127)

/**
* @brief Forward declaration of miso spi device
*
*
*/
typedef struct miso_spi_dev_s * miso_spi_t;
typedef struct miso_spi_dev_s* miso_spi_t;

/**
* @brief Miso SPI send data
*
* @param dev Miso SPI device
*
*
* @param data Data to send
*
*
* @param size Size of data to send
*
* @return Number of bytes sent. Negative value on error
*
* @return Number of bytes sent. Negative value on error
*/
ssize_t miso_spi_send(miso_spi_t dev, const void * data, size_t nBytes);
ssize_t miso_spi_send(miso_spi_t dev, const void* data, size_t nBytes);

/**
* @brief Miso SPI receive data
*
*
*
*
*/
ssize_t miso_spi_receive(miso_spi_t dev, void * data, size_t nBytes);


ssize_t miso_spi_receive(miso_spi_t dev, void* data, size_t nBytes);

#endif // __MISO_SPI_H__
#endif // __MISO_SPI_H__
2 changes: 2 additions & 0 deletions csrc/board/src/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ void BOARD_Init(void)

CMU_ClockEnable(cmuClock_GPIO, true);

CMU_OscillatorEnable(cmuOsc_ULFRCO, true, true);

/* ENABLE SWO */
sl_debug_swo_init();

Expand Down
69 changes: 36 additions & 33 deletions csrc/board/src/board_CC3100.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,45 +41,51 @@ struct transfer_status_s
};

static volatile P_EVENT_HANDLER interrupt_handler_callback = NULL;
static void *interrupt_handler_pValue = NULL;
static volatile void *interrupt_handler_pValue = NULL;

extern void system_reset(void);

static void cc3100_interrupt_callback(uint8_t intNo)
{
(void)intNo; // Validate interrupt ?

if (NULL != interrupt_handler_callback)
if ((uint8_t)WIFI_INT_PIN == intNo)
{
interrupt_handler_callback(interrupt_handler_pValue);
if (NULL != interrupt_handler_callback)
{
interrupt_handler_callback(interrupt_handler_pValue);
}
}
}

static void recieve_callback(struct SPIDRV_HandleData *handle, Ecode_t transferStatus, int itemsTransferred)
{
(void)handle; // Validate handle ?
struct transfer_status_s transfer_status_information = {.transferStatus = transferStatus,
.itemsTransferred = itemsTransferred};

BaseType_t xHigherPriorityTaskWoken = pdFALSE;
BaseType_t xHigherPriorityTaskWoken = pdFALSE;

if (NULL != rx_queue)
if (handle == &cc3100_usart)
{
(void)xQueueSendFromISR(rx_queue, &transfer_status_information, &xHigherPriorityTaskWoken);
struct transfer_status_s transfer_status_information = {.transferStatus = transferStatus,
.itemsTransferred = itemsTransferred};

if (NULL != rx_queue)
{
(void)xQueueSendFromISR(rx_queue, &transfer_status_information, &xHigherPriorityTaskWoken);
}
}

portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}

static void send_callback(struct SPIDRV_HandleData *handle, Ecode_t transferStatus, int itemsTransferred)
{
(void)handle; // Validate handle ?
struct transfer_status_s transfer_status_information = {.transferStatus = transferStatus,
.itemsTransferred = itemsTransferred};
BaseType_t xHigherPriorityTaskWoken = pdFALSE;

BaseType_t xHigherPriorityTaskWoken = pdFALSE;

if (NULL != tx_queue)
if (handle == &cc3100_usart)
{
(void)xQueueSendFromISR(tx_queue, &transfer_status_information, &xHigherPriorityTaskWoken);
struct transfer_status_s transfer_status_information = {.transferStatus = transferStatus,
.itemsTransferred = itemsTransferred};
if (NULL != tx_queue)
{
(void)xQueueSendFromISR(tx_queue, &transfer_status_information, &xHigherPriorityTaskWoken);
}
}

portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
Expand Down Expand Up @@ -170,11 +176,10 @@ void CC3100_DeviceDisable(void)

int CC3100_IfOpen(const char *pIfName, unsigned long flags)
{
(void)flags;
int ret = -1;
// Success: FD (positive integer)
// Failure: -1
if (strncmp(pIfName, CC3100_DEVICE_NAME, strlen(CC3100_DEVICE_NAME)) == 0)
if ((strncmp(pIfName, CC3100_DEVICE_NAME, strlen(CC3100_DEVICE_NAME)) == 0) && (flags == 0))
{
if (ECODE_OK == SPIDRV_Init(&cc3100_usart, &cc3100_usart_init_data))
{
Expand Down Expand Up @@ -213,13 +218,13 @@ int CC3100_IfRead(Fd_t Fd, uint8_t *pBuff, int Len)
return -1;
}

int retVal = -1;
struct transfer_status_s transfer_status = {ECODE_EMDRV_SPIDRV_PARAM_ERROR, 0};

int retVal = -1;
cc3100_spi_select();

if (rx_queue != NULL) // Change to check if scheduler is active
{
struct transfer_status_s transfer_status = {ECODE_EMDRV_SPIDRV_PARAM_ERROR, -1};

(void)xQueueReset(rx_queue);

Ecode_t ecode = SPIDRV_MReceive(&cc3100_usart, pBuff, Len, recieve_callback);
Expand All @@ -233,11 +238,11 @@ int CC3100_IfRead(Fd_t Fd, uint8_t *pBuff, int Len)
{
ecode = ECODE_EMDRV_SPIDRV_TIMEOUT;
}
}

if (ECODE_EMDRV_SPIDRV_OK == ecode)
{
retVal = transfer_status.itemsTransferred;
}
if (ECODE_EMDRV_SPIDRV_OK == ecode)
{
retVal = transfer_status.itemsTransferred;
}
}

Expand All @@ -252,15 +257,15 @@ int CC3100_IfWrite(Fd_t Fd, const uint8_t *pBuff, int Len)
return -1;
}

int retVal = -1;
struct transfer_status_s transfer_status = {ECODE_EMDRV_SPIDRV_PARAM_ERROR, 0};
int retVal = -1;

cc3100_spi_select();

if (tx_queue != NULL) // Change to check if scheduler is active
{
xQueueReset(tx_queue);
struct transfer_status_s transfer_status = {ECODE_EMDRV_SPIDRV_PARAM_ERROR, -1};

xQueueReset(tx_queue);
Ecode_t ecode = SPIDRV_MTransmit(&cc3100_usart, pBuff, Len, send_callback);
if (ECODE_EMDRV_SPIDRV_OK == ecode)
{
Expand Down Expand Up @@ -294,8 +299,6 @@ void CC3100_MaskIntHdlr(void) { ; }

void CC3100_UnmaskIntHdlr(void) { ; }

extern void system_reset(void);

/* General Event Handler */
void CC3100_GeneralEvtHdlr(SlDeviceEvent_t *slGeneralEvent)
{
Expand Down
62 changes: 37 additions & 25 deletions csrc/board/src/board_bma280.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,55 +7,67 @@
#include "board_i2c_sensors.h"

struct bma2_dev board_bma280;

static uint32_t dummy_val = 0;

static BMA2_INTF_RET_TYPE _bma280_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr)
{
(void)intf_ptr;
BMA2_INTF_RET_TYPE ret = BMA2_E_COM_FAIL;

I2C_TransferSeq_TypeDef transfer;
transfer.addr = (BMA2_I2C_ADDR1 << 1);
transfer.buf[0].data = &reg_addr;
transfer.buf[0].len = 1;
transfer.buf[1].data = reg_data;
transfer.buf[1].len = len;
transfer.flags = I2C_FLAG_WRITE_READ;

if (i2cTransferDone == board_i2c0_transfer(&transfer))
if (intf_ptr == &dummy_val)
{
ret = BMA2_OK;
I2C_TransferSeq_TypeDef transfer;
transfer.addr = (BMA2_I2C_ADDR1 << 1);
transfer.buf[0].data = &reg_addr;
transfer.buf[0].len = 1;
transfer.buf[1].data = reg_data;
transfer.buf[1].len = len;
transfer.flags = I2C_FLAG_WRITE_READ;

if (i2cTransferDone == board_i2c0_transfer(&transfer))
{
ret = BMA2_OK;
}
}

return ret;
}

static BMA2_INTF_RET_TYPE _bma280_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, void *intf_ptr)
{
(void)intf_ptr;
BMA2_INTF_RET_TYPE ret = BMA2_E_COM_FAIL;

I2C_TransferSeq_TypeDef transfer;
transfer.addr = (BMA2_I2C_ADDR1 << 1);
transfer.buf[0].data = &reg_addr;
transfer.buf[0].len = 1;
transfer.buf[1].data = reg_data;
transfer.buf[1].len = len;
transfer.flags = I2C_FLAG_WRITE_WRITE;

if (i2cTransferDone == board_i2c0_transfer(&transfer))
if (intf_ptr == &dummy_val)
{
ret = BMA2_OK;
I2C_TransferSeq_TypeDef transfer;
transfer.addr = (BMA2_I2C_ADDR1 << 1);
transfer.buf[0].data = &reg_addr;
transfer.buf[0].len = 1;
transfer.buf[1].data = reg_data;
transfer.buf[1].len = len;
transfer.flags = I2C_FLAG_WRITE_WRITE;

if (i2cTransferDone == board_i2c0_transfer(&transfer))
{
ret = BMA2_OK;
}
}

return ret;
}

static void _bma280_delay_us(uint32_t period, void *intf_ptr)
{
(void)intf_ptr;
BOARD_usDelay(period);
if (intf_ptr == &dummy_val)
{
BOARD_usDelay(period);
}
else
{
while (1)
{
__NOP();
}
}
}

void board_bma280_enable(void)
Expand Down
Loading

0 comments on commit f24d06d

Please sign in to comment.