/*
 * GTCP_SPI.h
 *
 */

#ifndef GTCP_SPI_H_
#define GTCP_SPI_H_

#include <stdint.h>
#include <stdio.h>
#ifdef __MSP430F5529__
#include <msp430f5529.h>
#elif defined __MSP430FR6989__
#include <msp430fr6989.h>
#endif
#include "Interface.h"

#define READ_DELAY 22
#define CS_DELAY 15
#define WRITE_IDENTIFIER 0x44
#define DATAREAD_IDENTIFIER 0x54
#define STATUSREAD_IDENTIFIER 0x58
#define MAX_BYTES_TO_READ 63

int dataRead;
int statusRead;
int bytesToRead;

// Function Prototypes
void initSPI();
void resetUSCIStateMachine_SPI();
void initUSCIStateMachine_SPI();
void configureSPIGPIO();
void configureSPI();
void setCS();
void clearCS();
void checkMBUSY();
void checkTXBufEmpty();
void checkRXBufEmpty();
void beginWriteSPI();
void putTXBUF(uint8_t data);
uint8_t readRXBUF();
void endSPI();
void writeSPI(char data);
void writeStringSPI(unsigned char* data);
void writeArraySPI(uint8_t* data, int size);
void startSPIRead();
void readSPI(unsigned char* data);
int readSPIStatus();

#endif /* GTCP_SPI_H_ */
