2 \author Travis Goodspeed
3 \brief Chipcon SPI Register Interface
6 //Higher level left to client application.
19 #define RADIOACTIVE SETCE
20 #define RADIOPASSIVE CLRCE
22 //! Set up the pins for CCSPI mode.
30 //Begin a new transaction.
35 //! Read and write an CCSPI byte.
36 u8 ccspitrans8(u8 byte){
37 register unsigned int bit;
38 //This function came from the CCSPI Wikipedia article.
41 for (bit = 0; bit < 8; bit++) {
42 /* write MOSI on trailing edge of previous clock */
51 /* read MISO on trailing edge */
61 u8 ccspi_regwrite(u8 reg, const u8 *buf, int len){
72 u8 ccspi_regread(u8 reg, u8 *buf, int len){
77 *buf++=ccspitrans8(0);
83 //! Handles a Chipcon SPI command.
84 void ccspihandle(unsigned char app,
89 //Drop CE to passify radio.
91 //Raise !SS to end transaction, just in case we forgot.
96 //PEEK and POKE might come later.
99 CLRSS; //Drop !SS to begin transaction.
101 cmddata[i]=ccspitrans8(cmddata[i]);
102 SETSS; //Raise !SS to end transaction.
103 txdata(app,verb,len);
106 case PEEK://Grab CCSPI Register
107 CLRSS; //Drop !SS to begin transaction.
108 ccspitrans8(CCSPI_R_REGISTER | cmddata[0]); //000A AAAA
110 cmddata[i]=ccspitrans8(cmddata[i]);
111 SETSS; //Raise !SS to end transaction.
112 txdata(app,verb,len);
115 case POKE://Poke CCSPI Register
116 CLRSS; //Drop !SS to begin transaction.
117 ccspitrans8(CCSPI_W_REGISTER | cmddata[0]); //001A AAAA
119 cmddata[i]=ccspitrans8(cmddata[i]);
120 SETSS; //Raise !SS to end transaction.
121 txdata(app,verb,len);
131 ccspitrans8(CCSPI_R_RX_PAYLOAD);
133 cmddata[i]=ccspitrans8(0xde);
141 ccspitrans8(CCSPI_FLUSH_RX);
150 debugstr("Not yet supported.");