Mike Moore / mmSPI
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers mmSPI.h Source File

mmSPI.h

00001 #ifndef mmSPI_H                                 // include guard.
00002 #define mmSPI_H                                 // include guard.
00003 /*----------------------------------------------//------------------------------
00004     student   : m-moore
00005     email     : gated.clock@gmail.com
00006     class     : usb device drivers
00007     directory : USB_device_project/mmSPI
00008     file      : mmSPI.h
00009     date      : september 3, 2013.
00010 ----copyright-----------------------------------//------------------------------   
00011     licensed for personal and academic use.
00012     commercial use must be approved by the account-holder of
00013     gated.clock@gmail.com
00014 ----description---------------------------------//------------------------------  
00015     this library provides the low-level SPI data and clock signaling 
00016     for communication with the altera development board, via four i/o
00017     pins available on the mbed development board's zigbee header.  
00018 ----notes---------------------------------------//------------------------------ 
00019 ------------------------------------------------//----------------------------*/
00020     #include "mbed.h"                           // standard mbed.org class.
00021 //---defines------------------------------------//------------------------------
00022     #define mmSPI_MOSI p29                      // SPI interface pin.
00023     #define mmSPI_MISO p30                      // SPI interface pin.
00024     #define mmSPI_SCLK p9                       // SPI interface pin.
00025     #define mmCPU_CLK  p10                      // soft CPU system clock.
00026 //==============================================//==============================
00027     class mmSPI
00028     {
00029       public:
00030                       mmSPI();                  // constructor.
00031                      ~mmSPI();                  // destructor.
00032         void          allocations();            // object allocations.       
00033         
00034         void          setSPIfrequency (float);  // initializations.
00035         void          setSendBuffer   (char * pcSendBuffer);
00036         void          setReceiveBuffer(char * pcReceiveBuffer);
00037         void          setNumberOfBytes(int    dNumberOfBytes);
00038 
00039                                                 // SPI transceive loop.
00040         void          transceive_vector(char cPreCPU, char cPreSPI, char cScan, char cPostCPU);       
00041         
00042                                                 // write/read CPU registers.     
00043         void          write_register(char cRegister, char cValue);
00044         void          write_IR      (char cValueH, char cValueL);
00045         char          read_register (char cRegister);
00046         
00047                                                 // write/read CPU main-memory.
00048         void          write_memory(char cHData, char cLdata, char cAddress);
00049         unsigned int  read_memory (char cAddress);
00050         
00051         void          step();                   // step the CPU.
00052         
00053         void          clear_transmit_vector();  // fill with 0.
00054         
00055         unsigned long SPIClockCount();          // return SPI clock count.
00056         unsigned long CPUClockCount();          // return CPU clock count.      
00057         
00058       private:
00059       
00060       DigitalOut  * pMOSI;                      // SPI pin.
00061       DigitalOut  * pMISO;                      // SPI pin.
00062       DigitalOut  * pSCLK;                      // SPI pin.
00063       DigitalOut  * pCPUclk;                    // soft cpu clock.
00064       char        * pcSend;                     // SPI transmit vector.
00065       char        * pcReceive;                  // SPI receive  vector.
00066       float         fSPIfreq;                   // SPI clock   frequency.
00067       float         fSPIquarterP;               // SPI quarter period.
00068       int           dNumBytes;                  // number of SPI bytes.
00069       int           dLoop01;                    // loop index.
00070       int           dLoop02;                    // loop index.
00071       unsigned long ulSPIclkCount;              // SPI clock count.
00072       unsigned long ulCPUclkCount;              // CPU clock count.
00073     };
00074 //----------------------------------------------//------------------------------
00075 #endif                                          // include guard.