mrfioc2  2.3.0
Public Member Functions | List of all members
MRMSPI Class Reference

#include <mrmspi.h>

Inheritance diagram for MRMSPI:
Inheritance graph
[legend]
Collaboration diagram for MRMSPI:
Collaboration graph
[legend]

Public Member Functions

 MRMSPI (volatile unsigned char *base)
 
virtual ~MRMSPI ()
 
virtual void select (unsigned id) OVERRIDE FINAL
 Select numbered device. 0 clears selection. More...
 
virtual epicsUInt8 cycle (epicsUInt8 in) OVERRIDE FINAL
 
- Public Member Functions inherited from mrf::SPIInterface
 SPIInterface ()
 
virtual ~SPIInterface ()
 
virtual void cycles (size_t nops, const Operation *ops)
 
double timeout () const
 timeout in seconds for an individual cycle() More...
 
void setTimeout (double t)
 

Additional Inherited Members

- Protected Attributes inherited from mrf::SPIInterface
epicsMutex mutex
 

Detailed Description

Definition at line 20 of file mrmspi.h.

Constructor & Destructor Documentation

◆ MRMSPI()

MRMSPI::MRMSPI ( volatile unsigned char *  base)

Definition at line 36 of file mrmspi.cpp.

37  :base(base)
38 {}

◆ ~MRMSPI()

MRMSPI::~MRMSPI ( )
virtual

Definition at line 40 of file mrmspi.cpp.

40 {}

Member Function Documentation

◆ cycle()

epicsUInt8 MRMSPI::cycle ( epicsUInt8  in)
virtual

Perform a single SPI transaction

Exceptions
std::runtime_erroron timeout

Implements mrf::SPIInterface.

Definition at line 65 of file mrmspi.cpp.

66 {
67  double timeout = this->timeout();
68 
69  if(mrmSPIDebug)
70  printf("SPI %02x ", int(in));
71 
72  // wait for send ready to be set
73  {
74  mrf::TimeoutCalculator T(timeout);
75  while(T.ok() && !(READ32(base, SPIDCtrl)&SPIDCtrl_SendRdy))
76  epicsThreadSleep(T.inc());
77  if(!T.ok())
78  throw std::runtime_error("SPI cycle timeout2");
79 
80  if(mrmSPIDebug)
81  printf("(%f) ", T.sofar());
82  }
83 
84  WRITE32(base, SPIDData, in);
85 
86  if(mrmSPIDebug)
87  printf("-> ");
88 
89  // wait for recv ready to be set
90  {
91  mrf::TimeoutCalculator T(timeout);
92  while(T.ok() && !(READ32(base, SPIDCtrl)&SPIDCtrl_RecvRdy))
93  epicsThreadSleep(T.inc());
94  if(!T.ok())
95  throw std::runtime_error("SPI cycle timeout2");
96 
97  if(mrmSPIDebug)
98  printf("(%f) ", T.sofar());
99  }
100 
101  epicsUInt8 ret = READ32(base, SPIDData)&0xff;
102 
103  if(mrmSPIDebug) {
104  printf("%02x\n", int(ret));
105  }
106  return ret;
107 }
#define READ32(base, offset)
Definition: mrfCommonIO.h:114
double timeout() const
timeout in seconds for an individual cycle()
Definition: spi.cpp:41
#define SPIDCtrl_RecvRdy
Definition: mrmspi.cpp:26
int mrmSPIDebug
Definition: mrmspi.cpp:34
#define SPIDCtrl_SendRdy
Definition: mrmspi.cpp:27
#define WRITE32(base, offset, value)
Definition: mrfCommonIO.h:119

◆ select()

void MRMSPI::select ( unsigned  id)
virtual

Select numbered device. 0 clears selection.

Implements mrf::SPIInterface.

Definition at line 43 of file mrmspi.cpp.

44 {
45  if(mrmSPIDebug)
46  printf("SPI: select %u\n", id);
47 
48  if(id==0) {
49  // deselect
50  WRITE32(base, SPIDCtrl, SPIDCtrl_OE);
51  // wait a bit to ensure the chip sees deselect
52  epicsThreadSleep(0.001);
53  // disable drivers
54  WRITE32(base, SPIDCtrl, 0);
55  } else {
56  // drivers on w/ !SS
57  WRITE32(base, SPIDCtrl, SPIDCtrl_OE);
58  // wait a bit to ensure the chip sees deselect
59  epicsThreadSleep(0.001);
60  // select
61  WRITE32(base, SPIDCtrl, SPIDCtrl_OE|SPIDCtrl_SS);
62  }
63 }
#define SPIDCtrl_OE
Definition: mrmspi.cpp:31
#define SPIDCtrl_SS
Definition: mrmspi.cpp:32
int mrmSPIDebug
Definition: mrmspi.cpp:34
#define WRITE32(base, offset, value)
Definition: mrfCommonIO.h:119

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