PikeAero::CSPIADC Class Reference

#include <cspiadc.h>

Inheritance diagram for PikeAero::CSPIADC:

Inheritance graph
[legend]
Collaboration diagram for PikeAero::CSPIADC:

Collaboration graph
[legend]

Public Member Functions

bool completed ()
 returns status of all channel scan cycle.
 CSPIADC ()
void disableTXInterrupts ()
void enableTXInterrupts ()
virtual void irq (CMachine::InterruptVector v)
 receive a hardware interrupt.
CMachine::ubit16 result ()
 return result of last completed single channel conversion.
bool start (CMachine::ubit8 *buffer)
 start all channel scan.
bool startChannel (CMachine::ubit8 channel)
 start a single channel conversion.
virtual ~CSPIADC ()

Private Member Functions

void functionEnter ()
void functionExit ()

Private Attributes

CMachine::ubit8 mCommand [3]
bool mMultiChannel
CMachine::ubit8 mResult [2]
CMachine::ubit8 mRXChannelWordCount

Detailed Description

Communicates with Microchip 25LC1024 EEPROM multiplexed on BSPI2. Chip Select P6.2 selects 25LC1024 IC. Chip Select P6.3 selects MCP6S28 IC.

Author:
Michael Sharkey <mike@pikeaero.com>

Definition at line 35 of file cspiadc.h.


Constructor & Destructor Documentation

PikeAero::CSPIADC::CSPIADC (  ) 

BSPI1 @ 2MHz

Transmit FIFO only one deep for maintaing C/S sync between mult-channel command stream

Definition at line 27 of file cspiadc.cpp.

References PikeAero::CSPI::bspi(), BSPI_TFEN, and PikeAero::BSPI_TypeDef::CSR2.

00028 : inherited(BSPI1,2000000)  /** BSPI1 @ 2MHz */
00029 , mMultiChannel(false)
00030 , mRXChannelWordCount(0)
00031 {
00032     /** Transmit FIFO only one deep for maintaing C/S sync between mult-channel command stream */
00033     bspi()->CSR2 &= ~BSPI_TFEN(0xF);
00034 }

Here is the call graph for this function:

PikeAero::CSPIADC::~CSPIADC (  )  [virtual]

Definition at line 37 of file cspiadc.cpp.

00038 {
00039 }


Member Function Documentation

bool PikeAero::CSPIADC::completed (  ) 

returns status of all channel scan cycle.

Returns:
true if all channel scan is completed.

Definition at line 136 of file cspiadc.cpp.

References mMultiChannel, and PikeAero::CSPI::mRXCount.

Referenced by start(), and startChannel().

00137 {
00138     if ( mMultiChannel )
00139         return mRXCount == 16;
00140     return (mRXCount == 2);
00141 }

Here is the caller graph for this function:

void PikeAero::CSPIADC::disableTXInterrupts (  )  [inline]

Reimplemented from PikeAero::CSPI.

Definition at line 42 of file cspiadc.h.

References PikeAero::CSPI::bspi(), BSPI_TIE, and PikeAero::BSPI_TypeDef::CSR2.

Referenced by functionEnter(), functionExit(), and irq().

00042 { bspi()->CSR2 &= ~BSPI_TIE(0xFF); }

Here is the call graph for this function:

Here is the caller graph for this function:

void PikeAero::CSPIADC::enableTXInterrupts (  )  [inline]

Reimplemented from PikeAero::CSPI.

Definition at line 41 of file cspiadc.h.

References PikeAero::CSPI::bspi(), BSPI_TIE, and PikeAero::BSPI_TypeDef::CSR2.

Referenced by start(), and startChannel().

00041 { bspi()->CSR2 |= BSPI_TIE(0x03); }

Here is the call graph for this function:

Here is the caller graph for this function:

void PikeAero::CSPIADC::functionEnter (  )  [private]

Activate chip select

enable MCP3208 CS

Definition at line 41 of file cspiadc.cpp.

References PikeAero::CSPI::disableRXInterrupts(), disableTXInterrupts(), PikeAero::CSPI::enableChipSelect(), and GPIO_PIN_0.

Referenced by start(), and startChannel().

00042 {
00043     disableRXInterrupts();
00044     disableTXInterrupts();
00045 
00046     /** Activate chip select */
00047     enableChipSelect( GPIO_PIN_0 );     /** enable MCP3208 CS */
00048 }

Here is the call graph for this function:

Here is the caller graph for this function:

void PikeAero::CSPIADC::functionExit (  )  [private]

Deactivate chip select

disable MCP3208 CS

Definition at line 50 of file cspiadc.cpp.

References PikeAero::CSPI::disableChipSelect(), PikeAero::CSPI::disableRXInterrupts(), disableTXInterrupts(), and GPIO_PIN_0.

Referenced by result(), start(), and startChannel().

00051 {
00052     /** Deactivate chip select */
00053     disableChipSelect( GPIO_PIN_0 );    /** disable MCP3208 CS */
00054 
00055     disableRXInterrupts();
00056     disableTXInterrupts();
00057 }

Here is the call graph for this function:

Here is the caller graph for this function:

void PikeAero::CSPIADC::irq ( CMachine::InterruptVector  v  )  [virtual]

receive a hardware interrupt.

TX FIFO not full...

if transmit buffer is NULL, transmit a zero, else next byte from buffer..

if we're running multi-channel; and we're at a channel boundary, wait for transmitter empty...

end of channel command, toggle chip select to start a new command

get first byte of next command

RX FIFO not empty...

read and store the byte if the RX buffer is not NULL...

Reimplemented from PikeAero::CSPI.

Definition at line 160 of file cspiadc.cpp.

References PikeAero::CSPI::bspi(), BSPI_RFNE, BSPI_TFE, PikeAero::CSPI::disableChipSelect(), disableTXInterrupts(), PikeAero::CSPI::enableChipSelect(), GPIO_PIN_0, mMultiChannel, PikeAero::CSPI::mRXBuffer, mRXChannelWordCount, PikeAero::CSPI::mRXCount, PikeAero::CSPI::mTXBuffer, PikeAero::CSPI::mTXCount, PikeAero::BSPI_TypeDef::RXR, and PikeAero::BSPI_TypeDef::TXR.

00161 {
00162     /** TX FIFO not full... */
00163     if ( ( bspi()->CSR2 & BSPI_TFE ) && mTXCount > 0 )
00164     {
00165         /** if transmit buffer is NULL, transmit a zero, else next byte from buffer.. */
00166         CMachine::ubit8 ch = *mTXBuffer++;
00167         /** if we're running multi-channel; and we're at a channel boundary, wait for transmitter empty... */
00168         if ( mMultiChannel && ch == 0xFF )
00169         {
00170             /** end of channel command, toggle chip select to start a new command */
00171             disableChipSelect( GPIO_PIN_0 );
00172             enableChipSelect( GPIO_PIN_0 );
00173 
00174             /** get first byte of next command */
00175             ch = *mTXBuffer++;
00176         }
00177         bspi()->TXR = (ch << 8);
00178         if ( --mTXCount == 0 )
00179         {
00180             disableTXInterrupts();
00181         }
00182     }
00183     
00184     /** RX FIFO not empty... */
00185     while ( bspi()->CSR2 & BSPI_RFNE )
00186     {
00187         /** read and store the byte if the RX buffer is not NULL... */
00188         CMachine::ubit8 ch = (bspi()->RXR >> 8);
00189         if ( mRXChannelWordCount++ )
00190         {
00191             *mRXBuffer++ = ch;
00192             ++mRXCount;
00193             if ( mRXChannelWordCount >= 3 )
00194             {
00195                 mRXChannelWordCount = 0;
00196             }
00197         }
00198     }
00199 }

Here is the call graph for this function:

CMachine::ubit16 PikeAero::CSPIADC::result (  ) 

return result of last completed single channel conversion.

return result of last completed conversion.

Returns:
0x0000 - 0x0FFF

Definition at line 147 of file cspiadc.cpp.

References functionExit(), mMultiChannel, and mResult.

00148 {
00149     functionExit();
00150     if ( mMultiChannel )
00151     {
00152         return 0;
00153     }
00154     return ((mResult[0]&0x0F)<<8) | mResult[1];
00155 }

Here is the call graph for this function:

bool PikeAero::CSPIADC::start ( CMachine::ubit8 buffer  ) 

start all channel scan.

Parameters:
buffer An array of CMachine::ubit8[16] Array Format (x=undefined, M=MSB, L=LSB): [0] |xxxxMMMM|LLLLLLLL| Channel #0 Result [1] |xxxxMMMM|LLLLLLLL| Channel #1 Result [2] |xxxxMMMM|LLLLLLLL| Channel #2 Result [3] |xxxxMMMM|LLLLLLLL| Channel #3 Result [4] |xxxxMMMM|LLLLLLLL| Channel #4 Result [5] |xxxxMMMM|LLLLLLLL| Channel #5 Result [6] |xxxxMMMM|LLLLLLLL| Channel #6 Result [7] |xxxxMMMM|LLLLLLLL| Channel #7 Result
Returns:
false if a scan is already in progress or other fault.
Parameters:
buffer An array of CMachine::ubit8[16]. Array Format (x=undefined, M=MSB, L=LSB): [0] |xxxxMMMM|LLLLLLLL| Channel #0 Result [1] |xxxxMMMM|LLLLLLLL| Channel #1 Result [2] |xxxxMMMM|LLLLLLLL| Channel #2 Result [3] |xxxxMMMM|LLLLLLLL| Channel #3 Result [4] |xxxxMMMM|LLLLLLLL| Channel #4 Result [5] |xxxxMMMM|LLLLLLLL| Channel #5 Result [6] |xxxxMMMM|LLLLLLLL| Channel #6 Result [7] |xxxxMMMM|LLLLLLLL| Channel #7 Result
Returns:
false if a scan is already in progress or other fault.

Scan all channels

one command at a time, don't count instruction boundary bytes

start the transfer by enabling receiver interrupts first, then transmitter interrupts. the transfer will start at the first transmit buffer empty interrupt.

Definition at line 105 of file cspiadc.cpp.

References PikeAero::CSPI::clearReceiver(), completed(), PikeAero::CSPI::enableRXInterrupts(), enableTXInterrupts(), functionEnter(), functionExit(), mMultiChannel, PikeAero::CSPI::mRXBuffer, mRXChannelWordCount, PikeAero::CSPI::mRXCount, PikeAero::CSPI::mTXBuffer, and PikeAero::CSPI::mTXCount.

00106 {
00107     if ( completed() )
00108     {
00109         functionExit();
00110         functionEnter();
00111 
00112         mTXBuffer = (CMachine::ubit8*)"\030  \377\031  \377\032  \377\033  \377\034  \377\035  \377\036  \377\037  ";   /** Scan all channels */
00113         mTXCount = 24;                          /** one command at a time, don't count instruction boundary bytes */
00114         mRXBuffer = buffer;
00115         mRXCount = 0;
00116         mRXChannelWordCount=0;
00117         clearReceiver();
00118 
00119         mMultiChannel = true;
00120 
00121         /**
00122          ** start the transfer by enabling receiver interrupts first, then transmitter interrupts.
00123          ** the transfer will start at the first transmit buffer empty interrupt.
00124          */
00125         enableRXInterrupts();
00126         enableTXInterrupts();
00127         
00128         return true;
00129     }
00130     return false;
00131 }

Here is the call graph for this function:

bool PikeAero::CSPIADC::startChannel ( CMachine::ubit8  channel  ) 

start a single channel conversion.

start an A/D channel conversion.

Toggle chip select...

Definition at line 62 of file cspiadc.cpp.

References PikeAero::CSPI::clearReceiver(), completed(), PikeAero::CSPI::enableRXInterrupts(), enableTXInterrupts(), functionEnter(), functionExit(), mCommand, mMultiChannel, mResult, PikeAero::CSPI::mRXBuffer, mRXChannelWordCount, PikeAero::CSPI::mRXCount, PikeAero::CSPI::mTXBuffer, and PikeAero::CSPI::mTXCount.

00063 {
00064     if ( completed() )
00065     {
00066         functionExit();     /** Toggle chip select... */
00067         functionEnter();
00068 
00069         clearReceiver();
00070         
00071         mCommand[0] = channel & 0x18;
00072         mCommand[1] = 0x00;
00073         mCommand[2] = 0x00;
00074 
00075         mTXBuffer = mCommand;
00076         mTXCount = 3;
00077         mRXBuffer = mResult;
00078         mRXCount = 0;
00079         mRXChannelWordCount=0;
00080     
00081         mMultiChannel = false;
00082 
00083         enableRXInterrupts();
00084         enableTXInterrupts();
00085 
00086         return true;
00087     }
00088     return false;
00089 }

Here is the call graph for this function:


Field Documentation

Definition at line 85 of file cspiadc.h.

Referenced by startChannel().

Definition at line 83 of file cspiadc.h.

Referenced by completed(), irq(), result(), start(), and startChannel().

Definition at line 86 of file cspiadc.h.

Referenced by result(), and startChannel().

Definition at line 84 of file cspiadc.h.

Referenced by irq(), start(), and startChannel().


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

Generated on Sun Oct 25 14:00:15 2009 for stingray3 by  doxygen 1.5.8