SCAMP-5c SPI Interface  1.0.0
SCAMP-5c is connected to the flight computer via a SPI interface
Data Structures | Public Member Functions | Data Fields | Protected Member Functions | Static Protected Member Functions | Protected Attributes
scamp5c_spi Class Reference

the object-oriented interface of the spi bus More...

#include <scamp5c_spi.hpp>

Inheritance diagram for scamp5c_spi:
scamp5c_spi_ht scamp5c_spi_vts

Data Structures

class  packet
 the SPI packet class More...
 

Public Member Functions

int OpenSPI (const char *dev_path, uint32_t d_clk=2500000)
 open the spi interface More...
 
int CloseSPI (void)
 close the spi interface
 
int StartThreads ()
 start running the internal functions in different threads More...
 
int EndThreads ()
 stop the interface and close all threads created in the background More...
 
void SetTransferSize (uint32_t s)
 change the transfer size More...
 
uint32_t GetTransferSize ()
 
void ResetAllCounters ()
 
uint32_t GetTriggerCounter ()
 
uint32_t GetTxSwapCounter ()
 
uint32_t GetTransferCounter ()
 
uint32_t GetSignatureCounter ()
 
uint32_t GetHeaderCounter ()
 
uint32_t GetPacketCounter ()
 
size_t GetPacketQueueLength ()
 get the number of packet in the packet queue
 
packetPopPacketFromQueue ()
 get a packet from the queue as the packet is removed from queue
 
void DeletePacket (packet *p)
 delete a packet taken from the packet queue
 
void OpenTxBuffer ()
 gain access to the transmit buffer
 
uint8_t * GetTxBuffer ()
 get the pointer to the transmit buffer thus modify the content in it
 
void CloseTxBuffer ()
 release access to the transmit buffer
 

Data Fields

const size_t SPI_TRANSFER_SIZE_MIN = 16
 
const size_t SPI_TRANSFER_SIZE_MAX = 4096
 
const size_t SPI_TRANSFER_SIZE_DEFAULT = 200
 
const size_t PACKET_BUFFER_SIZE = 256*256*4
 
const size_t PACKET_HEADER_LENGTH = sizeof(packet_header)
 
const uint8_t PACKET_SIGNATURE [3] = { 0x20, 0x16, 0xAA }
 

Protected Member Functions

void spi_transfer_thread ()
 
void spi_packet_thread ()
 
virtual void spi_cs_high ()
 
virtual void spi_cs_low ()
 
virtual bool spi_transfer_trigger ()
 
virtual void save_rx_buf ()
 
virtual void rtc_sleep_usec (uint32_t u_sec)
 
void queue_packet_buffer ()
 
virtual size_t transfer_callback ()
 
virtual bool check_header (uint8_t *p)
 
virtual void header_callback (size_t rx_offset, packet_header *p)
 
virtual void command_callback (uint8_t command, uint8_t a, uint8_t b)
 
virtual void packet_callback (size_t rx_offset)
 
uint8_t * get_rx_buffer ()
 
uint8_t * get_tx_buffer ()
 
uint32_t get_transfer_size ()
 
void set_transfer_size (uint32_t s)
 
uint8_t * get_packet_buffer ()
 
size_t get_packet_length ()
 

Static Protected Member Functions

static int write_hex (const char *filepath, const uint8_t *data, size_t s)
 
static int report_error (const char *f_name, int line_num, int err_code)
 
static void report_warning (const char *f_name, int line_num, const char *text)
 

Protected Attributes

int dev_file
 
uint8_t mode
 
uint8_t bits
 
uint32_t clock
 
std::thread * th_transfer
 
std::thread * th_packet
 
std::mutex section_transfer
 
std::mutex section_tx_buffer
 
std::mutex section_packet_queue
 
std::atomic< bool > control_quit
 
volatile uint32_t trigger_counter
 
volatile uint32_t transfer_counter
 
volatile uint32_t tx_swap_counter
 
volatile uint32_t signature_counter
 
volatile uint32_t header_counter
 
volatile uint32_t packet_counter
 
std::list< packet * > packet_queue
 

Detailed Description

the object-oriented interface of the spi bus

Member Function Documentation

int scamp5c_spi::OpenSPI ( const char *  dev_path,
uint32_t  d_clk = 2500000 
)

open the spi interface

Parameters
dev_paththe file device path of the spidev
d_clkthe data clock frequency of the spi bus
Returns
0 if successful, -1 otherwise
int scamp5c_spi::StartThreads ( )

start running the internal functions in different threads

This function starts the whole mechanism.

int scamp5c_spi::EndThreads ( )

stop the interface and close all threads created in the background

This function stops the whole mechanism.

void scamp5c_spi::SetTransferSize ( uint32_t  s)
inline

change the transfer size

The transfer size can be changed from both the host and the SCAMP, so the transfer size may not always be the one set using this function.


The documentation for this class was generated from the following file: