SPI library used to communicate with an altera development board attached to four zigbee-header pins.

Committer:
gatedClock
Date:
Mon Aug 26 22:39:44 2013 +0000
Revision:
32:5a5d9525c6c4
Parent:
31:ea7b25e494b5
Child:
34:d5553509f31a
cleanup.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gatedClock 2:bebcf53b72dc 1 #ifndef mmSPI_H // include guard.
gatedClock 2:bebcf53b72dc 2 #define mmSPI_H // include guard.
gatedClock 0:fb42c5acf810 3 /*----------------------------------------------//------------------------------
gatedClock 0:fb42c5acf810 4 student : m-moore
gatedClock 32:5a5d9525c6c4 5 email : gated.clock@gmail.com
gatedClock 32:5a5d9525c6c4 6 class : usb device drivers
gatedClock 0:fb42c5acf810 7 directory : mmSPI
gatedClock 0:fb42c5acf810 8 file : mmSPI.h
gatedClock 32:5a5d9525c6c4 9 date : september 3, 2013.
gatedClock 1:15706d15d123 10 ----description---------------------------------//------------------------------
gatedClock 1:15706d15d123 11 ----notes---------------------------------------//------------------------------
gatedClock 1:15706d15d123 12 1. the SPI interface pins are routed to the zigbee header.
gatedClock 0:fb42c5acf810 13 ------------------------------------------------//----------------------------*/
gatedClock 0:fb42c5acf810 14 #include "mbed.h" // standard mbed.org class.
gatedClock 1:15706d15d123 15 //---defines------------------------------------//------------------------------
gatedClock 8:e2d8bbc3e659 16 #define mmSPI_MOSI p29 // SPI interface pin.
gatedClock 8:e2d8bbc3e659 17 #define mmSPI_MISO p30 // SPI interface pin.
gatedClock 8:e2d8bbc3e659 18 #define mmSPI_SCLK p9 // SPI interface pin.
gatedClock 8:e2d8bbc3e659 19 #define mmCPU_CLK p10 // soft CPU system clock.
gatedClock 0:fb42c5acf810 20 /*----------------------------------------------//------------------------------
gatedClock 0:fb42c5acf810 21 ------------------------------------------------//----------------------------*/
gatedClock 2:bebcf53b72dc 22
gatedClock 0:fb42c5acf810 23 //==============================================//==============================
gatedClock 0:fb42c5acf810 24 class mmSPI
gatedClock 0:fb42c5acf810 25 {
gatedClock 0:fb42c5acf810 26 public:
gatedClock 32:5a5d9525c6c4 27 mmSPI(); // constructor.
gatedClock 32:5a5d9525c6c4 28 ~mmSPI(); // destructor.
gatedClock 32:5a5d9525c6c4 29 void allocations(); // object allocations.
gatedClock 32:5a5d9525c6c4 30
gatedClock 32:5a5d9525c6c4 31 void setSPIfrequency (float); // initializations.
gatedClock 32:5a5d9525c6c4 32 void setSendBuffer (char * pcSendBuffer);
gatedClock 32:5a5d9525c6c4 33 void setReceiveBuffer(char * pcReceiveBuffer);
gatedClock 32:5a5d9525c6c4 34 void setNumberOfBytes(int dNumberOfBytes);
gatedClock 21:e90dd0f8aaa1 35
gatedClock 31:ea7b25e494b5 36 // SPI transceive loop.
gatedClock 32:5a5d9525c6c4 37 void transceive_vector(char cPreCPU, char cPreSPI, char cScan, char cPostCPU);
gatedClock 16:0e422fd263c6 38
gatedClock 24:d3b8c68f41f2 39 // write/read CPU registers.
gatedClock 32:5a5d9525c6c4 40 void write_register(char cRegister, char cValue);
gatedClock 32:5a5d9525c6c4 41 char read_register (char cRegister);
gatedClock 32:5a5d9525c6c4 42
gatedClock 24:d3b8c68f41f2 43 // write/read CPU main-memory.
gatedClock 32:5a5d9525c6c4 44 void write_memory(char cHData, char cLdata, char cAddress);
gatedClock 32:5a5d9525c6c4 45 unsigned int read_memory (char cAddress);
gatedClock 32:5a5d9525c6c4 46
gatedClock 32:5a5d9525c6c4 47 void step(); // step the CPU.
gatedClock 22:7524dee5c753 48
gatedClock 32:5a5d9525c6c4 49 void clear_transmit_vector(); // fill with 0.
gatedClock 30:331c7c7d8bc1 50
gatedClock 32:5a5d9525c6c4 51 unsigned long SPIClockCount(); // return SPI clock count.
gatedClock 32:5a5d9525c6c4 52 unsigned long CPUClockCount(); // return CPU clock count.
gatedClock 24:d3b8c68f41f2 53
gatedClock 0:fb42c5acf810 54 private:
gatedClock 2:bebcf53b72dc 55
gatedClock 32:5a5d9525c6c4 56 DigitalOut * pMOSI; // SPI pin.
gatedClock 32:5a5d9525c6c4 57 DigitalOut * pMISO; // SPI pin.
gatedClock 32:5a5d9525c6c4 58 DigitalOut * pSCLK; // SPI pin.
gatedClock 32:5a5d9525c6c4 59 DigitalOut * pCPUclk; // soft cpu clock.
gatedClock 32:5a5d9525c6c4 60 char * pcSend; // SPI transmit vector.
gatedClock 32:5a5d9525c6c4 61 char * pcReceive; // SPI receive vector.
gatedClock 32:5a5d9525c6c4 62 float fSPIfreq; // SPI clock frequency.
gatedClock 32:5a5d9525c6c4 63 float fSPIquarterP; // SPI quarter period.
gatedClock 32:5a5d9525c6c4 64 int dNumBytes; // number of SPI bytes.
gatedClock 32:5a5d9525c6c4 65 int dLoop01; // loop index.
gatedClock 32:5a5d9525c6c4 66 int dLoop02; // loop index.
gatedClock 32:5a5d9525c6c4 67 unsigned long ulSPIclkCount; // SPI clock count.
gatedClock 32:5a5d9525c6c4 68 unsigned long ulCPUclkCount; // CPU clock count.
gatedClock 0:fb42c5acf810 69 };
gatedClock 2:bebcf53b72dc 70 //----------------------------------------------//------------------------------
gatedClock 2:bebcf53b72dc 71 #endif // include guard.