Skip to content

Commit

Permalink
Refactoring and code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
prichards-wmko committed Feb 21, 2024
1 parent 2198570 commit 0ceae61
Show file tree
Hide file tree
Showing 9 changed files with 857 additions and 728 deletions.
67 changes: 27 additions & 40 deletions SSI0.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,48 +8,26 @@
*
*/

#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>

#include <inc/tm4c123gh6pm.h>
#include <inc/hw_memmap.h>
#include <inc/hw_types.h>
#include <inc/hw_gpio.h>
#include <inc/hw_ssi.h>

#include <driverlib/ssi.h>
#include <driverlib/gpio.h>
#include <driverlib/pin_map.h>
#include <driverlib/sysctl.h>
#include <driverlib/interrupt.h>
#include <driverlib/udma.h>

#include "SSI0.h"

/* Function prototypes */
void SSI0SlaveSelectIntHandler(void);
#define SSI0_C_
#include "includes.h"

/* Variables and pointers used */
static uint8_t *SSI0_RxPointer;
static uint8_t *SSI0_TxPointer;
static bool *dataReceived;
static bool *dataSent;

static uint16_t dataLength;

void SSI0Init(bool *received, bool *sent, uint8_t RxBuffer[], uint8_t TxBuffer[], uint16_t length) {
/* -----------------------------------------------------------------------------
* Initialize the SSI0 device.
*/
void SSI0Init(uint8_t RxBuffer[], uint8_t TxBuffer[], uint16_t length) {

uint32_t trashBin[1] = {0};

/* Initialize flags for receiving message */
SSI0_RxPointer = &RxBuffer[0];
SSI0_TxPointer = &TxBuffer[0];

dataReceived = received;
*dataReceived = false;
dataSent = sent;
*dataSent = false;
dataLength = length;

/* Enable the uDMA and SSI0 peripherals */
Expand All @@ -69,23 +47,22 @@ void SSI0Init(bool *received, bool *sent, uint8_t RxBuffer[], uint8_t TxBuffer[]
/* Configure SSI clock to run at 5MHz */
SSIConfigSetExpClk(SSI0_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_3, SSI_MODE_SLAVE, 5000000, 8);

/* Configure the SSI to interrupt on receive timeout or overrun */
//SSIIntEnable(SSI0_BASE, SSI_RXTO);
//SSIIntEnable(SSI0_BASE, SSI_RXOR);


/* Connect an interrupt handler to the chip select pin. This will be used to drive
* the next transaction. */
GPIOIntRegister(GPIO_PORTA_BASE, SSI0SlaveSelectIntHandler);
GPIOIntTypeSet(GPIO_PORTA_BASE, GPIO_PIN_3, GPIO_RISING_EDGE);
GPIOIntEnable(GPIO_PORTA_BASE, GPIO_PIN_3);


/* Turn on the SSI0 */
SSIEnable(SSI0_BASE);

/* Clear SSI0 RX Buffer */
while (SSIDataGetNonBlocking(SSI0_BASE, &trashBin[0])) {}
}

/* -----------------------------------------------------------------------------
* Interrupt handler for the SSI0 chip select rising edge (when it's deasserted)
*/
void SSI0SlaveSelectIntHandler(void) {

/* Clear the interrupt that signaled the end of chip select to this device */
Expand Down Expand Up @@ -115,10 +92,15 @@ void SSI0SlaveSelectIntHandler(void) {

/* Enable the DMA transfer */
SSIDMAEnable(SSI0_BASE, SSI_DMA_RX | SSI_DMA_TX);

/* Set the flag that the message has been received */
rxMessageReady = true;
}


/* Interrupt handler for uDMA/SSI */
/* -----------------------------------------------------------------------------
* Interrupt handler for uDMA/SSI
*/
void SSI0IntHandler(void) {

uint32_t ui32Status;
Expand Down Expand Up @@ -162,7 +144,10 @@ void SSI0IntHandler(void) {
}


void InitSPITransfer(void) {
/* -----------------------------------------------------------------------------
*
*/
void SSI0InitTransfer(void) {

/* Enable the uDMA interface for both TX and RX channels */
SSIDMAEnable(SSI0_BASE, SSI_DMA_RX | SSI_DMA_TX);
Expand Down Expand Up @@ -233,9 +218,11 @@ void InitSPITransfer(void) {
IntEnable(INT_SSI0);
}

/* The interrupt handler for uDMA errors. This interrupt will occur if the
uDMA encounters a bus error while trying to perform a transfer. This
handler just increments a counter if an error occurs. */
/* -----------------------------------------------------------------------------
* The interrupt handler for uDMA errors. This interrupt will occur if the
* uDMA encounters a bus error while trying to perform a transfer. This
* handler just increments a counter if an error occurs.
*/
void uDMAErrorHandler(void) {

if (uDMAErrorStatusGet()) {
Expand Down
34 changes: 26 additions & 8 deletions SSI0.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,35 @@
/*
* SSI0.h
* SSI0.h - Prototypes for the SSI0 interface.
*
* Copyright (c) 2024, W. M. Keck Observatory
* All rights reserved.
*
* Author: Paul Richards
*
*/

#ifndef SSI0_H_
#define SSI0_H_

#include <stdint.h>
/* Only instantiate variables if we are the .c routine for this header file. */
#ifndef SENSOR_TASK_C_
#define EXTERN extern
#else
#define EXTERN
#endif

/* Function prototypes */
extern void SSI0Init(bool *received, bool *sent, uint8_t RxBuffer[], uint8_t TxBuffer[], uint16_t length);
extern void SSI0Interrupt(void);
extern void SSI0SendMessage(void);
extern void InitSPITransfer(void);
extern void uDMAErrorHandler(void);
#include "includes.h"

/* -----------------------------------------------------------------------------
* Function prototypes
*/
EXTERN void SSI0SlaveSelectIntHandler(void);
EXTERN void SSI0Init(uint8_t RxBuffer[], uint8_t TxBuffer[], uint16_t length);
EXTERN void SSI0Interrupt(void);
EXTERN void SSI0SendMessage(void);
EXTERN void SSI0InitTransfer(void);
EXTERN void uDMAErrorHandler(void);

#undef EXTERN

#endif /* SSI0_H_ */
58 changes: 58 additions & 0 deletions includes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* includes.h - Common #includes for the ACS Node Box Sensor firmware project
*
* Copyright (c) 2024, W. M. Keck Observatory
* All rights reserved.
*
* Author: Paul Richards
*
*/

#ifndef INCLUDES_H_
#define INCLUDES_H_

#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>

// Board support includes
#include <inc/tm4c123gh6pm.h>
#include <inc/hw_memmap.h>
#include <inc/hw_types.h>
#include <inc/hw_gpio.h>
#include <inc/hw_i2c.h>
#include <inc/hw_ssi.h>

#include <driverlib/interrupt.h>
#include <driverlib/sysctl.h>
#include <driverlib/gpio.h>
#include <driverlib/i2c.h>
#include <driverlib/ssi.h>
#include <driverlib/pin_map.h>
#include <driverlib/rom.h>
#include <driverlib/sysctl.h>
#include <driverlib/uart.h>
#include <driverlib/udma.h>
#include <utils/uartstdio.h>

// FreeRTOS includes
#include "FreeRTOS.h"
#include "priorities.h"
#include "task.h"
#include "queue.h"
#include "semphr.h"

// Tasks
#include "main.h"
#include "spi_task.h"
#include "sensor_task.h"

// External interfaces
#include "SSI0.h"


#endif /* INCLUDES_H_ */




Loading

0 comments on commit 0ceae61

Please sign in to comment.