SPI object for communication with an altera FPGA.

Dependents:   RTOS_project RTOS_project_fork_01 RTOS_project_fork_02

mmSPI_RTOS.h

Committer:
gatedClock
Date:
2013-09-17
Revision:
0:7b8e6b90c874

File content as of revision 0:7b8e6b90c874:

#ifndef mmSPI_RTOS_H                            // include guard.
#define mmSPI_RTOS_H                            // include guard.
/*----------------------------------------------//------------------------------
    student   : m-moore
    email     : gated.clock@gmail.com
    class     : embedded RTOS
    directory : RTOS_project/mmSPI_RTOS
    file      : mmSPI_RTOS.h
    date      : september 19, 2013.
----copyright-----------------------------------//------------------------------   
    licensed for personal and academic use.
    commercial use of original code must be approved by the account-holder of
    gated.clock@gmail.com
----description---------------------------------//------------------------------  
    this library provides the low-level SPI data and clock signaling 
    for communication with the altera development board, via four i/o
    pins available on the mbed development board's zigbee header.  
----notes---------------------------------------//------------------------------ 
------------------------------------------------//----------------------------*/
    #include "mbed.h"                           // standard mbed.org class.
//---defines------------------------------------//------------------------------
    #define mmSPI_RTOS_MOSI p29                 // SPI interface pin.
    #define mmSPI_RTOS_MISO p30                 // SPI interface pin.
    #define mmSPI_RTOS_SCLK p9                  // SPI interface pin.
    #define mmCPU_CLK  p10                      // soft CPU system clock.
//==============================================//==============================
    class mmSPI_RTOS
    {
      public:
                      mmSPI_RTOS();             // constructor.
                     ~mmSPI_RTOS();             // destructor.
        void          allocations();            // object allocations.       
        
        void          setSPIfrequency (float);  // initializations.
        void          setSendBuffer   (char * pcSendBuffer);
        void          setReceiveBuffer(char * pcReceiveBuffer);
        void          setNumberOfBytes(int    dNumberOfBytes);

                                                // SPI transceive loop.
        void          transceive_vector(char cPreCPU, char cPreSPI, char cScan, char cPostCPU);       
        
                                                // write/read CPU registers.     
        void          write_register    (char   cRegister, char cValue);
        void          write_IR          (char   cValueH,   char cValueL);
        char          read_register     (char   cRegister);
        void          read_all_registers(char * pcRegisters);
        
                                                // write/read CPU main-memory.
        void          write_memory(char cHData, char cLdata, char cAddress);
        unsigned int  read_memory (char cAddress);
        
        void          step();                   // step the CPU.
        
        void          clear_transmit_vector();  // fill with 0.
        
        unsigned long SPIClockCount();          // return SPI clock count.
        unsigned long CPUClockCount();          // return CPU clock count.      
        
      private:
      
      DigitalOut  * pMOSI;                      // SPI pin.
      DigitalOut  * pMISO;                      // SPI pin.
      DigitalOut  * pSCLK;                      // SPI pin.
      DigitalOut  * pCPUclk;                    // soft cpu clock.
      char        * pcSend;                     // SPI transmit vector.
      char        * pcReceive;                  // SPI receive  vector.
      float         fSPIfreq;                   // SPI clock   frequency.
      float         fSPIquarterP;               // SPI quarter period.
      int           dNumBytes;                  // number of SPI bytes.
      int           dLoop01;                    // loop index.
      int           dLoop02;                    // loop index.
      unsigned long ulSPIclkCount;              // SPI clock count.
      unsigned long ulCPUclkCount;              // CPU clock count.
    };
//----------------------------------------------//------------------------------
#endif                                          // include guard.