//-------------------------------------------------------------------------- // // This module provides a radio control interface using an SPI port. // //-------------------------------------------------------------------------- // $Archive: /WirelessUSB/WUSB Kits/CY4632 LS KBM RDK/DocSrc/CD_Root/Firmware/Source Code/RDK Keyboard/spi.c $ // $Modtime: 6/03/04 9:49a9/29/04 2:19p $ // $Revision: 56 $ //-------------------------------------------------------------------------- // // Copyright 2003-2004, Cypress Semiconductor Corporation. // // This software is owned by Cypress Semiconductor Corporation (Cypress) // and is protected by and subject to worldwide patent protection (United // States and foreign), United States copyright laws and international // treaty provisions. Cypress hereby grants to licensee a personal, // non-exclusive, non-transferable license to copy, use, modify, create // derivative works of, and compile the Cypress Source Code and derivative // works for the sole purpose of creating custom software in support of // licensee product to be used only in conjunction with a Cypress integrated // circuit as specified in the applicable agreement. Any reproduction, // modification, translation, compilation, or representation of this // software except as specified above is prohibited without the express // written permission of Cypress. // // Disclaimer: CYPRESS MAKES NO WARRANTY OF ANY KIND,EXPRESS OR IMPLIED, // WITH REGARD TO THIS MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. // Cypress reserves the right to make changes without further notice to the // materials described herein. Cypress does not assume any liability arising // out of the application or use of any product or circuit described herein. // Cypress does not authorize its products for use as critical components in // life-support systems where a malfunction or failure may reasonably be // expected to result in significant injury to the user. The inclusion of // Cypress’ product in a life-support systems application implies that the // manufacturer assumes all risk of such use and in doing so indemnifies // Cypress against all charges. // // Use may be limited by and subject to the applicable Cypress software // license agreement. // //-------------------------------------------------------------------------- /////////////////////////////////////////////////////////////////////////////// // // Filename: spi.c // // Description: // /////////////////////////////////////////////////////////////////////////////// //-------------------------------------- // Included files //-------------------------------------- #include "spim_1.h" #include "m8c.h" #include "psocgpioint.h" #include "ls_config.h" #include "radio.h" #include "spi.h" #include "isr.h" #include "timer.h" UINT8 spiLock = 0; //-------------------------------------- // Local Defines and Types //-------------------------------------- /////////////////////////////////////////////////////////////////////////////// // // Function: spi_radio_on // // Description: Reset the LS radio // // Inputs: Void // // Returns: Void // /////////////////////////////////////////////////////////////////////////////// #ifndef SPIM_MODE_0 #define SPIM_MODE_0 SPIM_1_SPIM_MODE_0 #endif #ifndef SPIM_MSB_FIRST #define SPIM_MSB_FIRST SPIM_1_SPIM_MSB_FIRST #endif #ifndef SPIM_SPI_COMPLETE #define SPIM_SPI_COMPLETE SPIM_1_SPIM_SPI_COMPLETE #endif #define mSPI_ADDRESS 0x3F //-------------------------------------- // Local Function Declarations //-------------------------------------- //-------------------------------------------------------------------------- // spi_radio_on //-------------------------------------------------------------------------- void spi_radio_on(void) { // disable the PSOC GPIO interrupt (radioIsr) RADIO_ISR_DISABLE(); RADIO_PORT &= ~(nRESET | nPD); RADIO_PORT |= nPD; timer_delay_msec(10); RADIO_PORT |= (nRESET); timer_delay_msec(1); RADIO_PORT &= ~nPD; timer_delay_msec(1); RADIO_PORT |= nPD; timer_delay_msec(1); RADIO_PORT &= ~(nRESET); timer_delay_msec(1); RADIO_PORT |= (nRESET); SPIM_1_Start(SPIM_MODE_0 | SPIM_MSB_FIRST); } /////////////////////////////////////////////////////////////////////////////// // // Function: spi_radio_reset // // Description: Reset the LS radio // // Inputs: Void // // Returns: Void // /////////////////////////////////////////////////////////////////////////////// void spi_radio_reset(void) { RADIO_PORT &= ~(nRESET); timer_delay_50_usec(); RADIO_PORT |= (nRESET); } //-------------------------------------------------------------------------- // spi_radio_off //-------------------------------------------------------------------------- /////////////////////////////////////////////////////////////////////////////// // // Function: spi_radio_put // // Description: Write data to the LS radio via the SPI port // // Inputs: Address // Data // // Returns: Void // /////////////////////////////////////////////////////////////////////////////// #ifndef RADIO_DEFAULT_ON void spi_radio_put(UINT8 address, UINT8 dataoff(void) { UINT8 isrState; if (spiLock) { return; } spiLock = 1; RADIO_ISR_DISABLE(); // assert the slave select RADIO_PORT &= ~nSS; // turn off tx and rx spi_radio_put(REG_CONTROL, 0); } // write the address to the SPI port SPIM_1_TX_BUFFER_REG = ((address & mSPI_ADDRESS)| bSPI_WRITE); while(!(bSPIM_1_ReadStatus() & SPIM_SPI_COMPLETE)); #endif // write the byte to the SPI port SPIM_1_TX_BUFFER_REG = data; while(!(bSPIM_1_ReadStatus() & SPIM_SPI_COMPLETE)); // deassert the slave select RADIO_PORT |= nSS; //-------------------------------------------------------------------------- // spi_radio_reset //-------------------------------------------------------------------------- spiLock = 0; void spi_radio_reset(void) { RADIO_PORT &= ~(nRESET); timer_delay_50_usec(); RADIO_PORT |= (nRESET); } /////////////////////////////////////////////////////////////////////////////// // // Function: spi_radio_get // // Description: Read data from an address in the Radio // // Inputs: Address // Data // // Returns: Void // /////////////////////////////////////////////////////////////////////////////// //-------------------------------------------------------------------------- // spi_radio_access //-------------------------------------------------------------------------- UINT8 spi_radio_get(access(UINT8 address, UINT8 data) { UINT8 isrState; UINT8 isr_state = GPIO_ISR_RADIO_IE_PORT; if(spiLock) { return 0; } spiLock = 1; RADIO_ISR_DISABLE(); // assert the slave select RADIO_PORT &= ~nSS; // read the select address SPIM_1_TX_BUFFER_REG = (address & mSPI_ADDRESS)address; while(!(bSPIM_1_ReadStatus()SPIM_1_CONTROL_REG & SPIM_SPI_COMPLETE)); // read the data SPIM_1_TX_BUFFER_REG = 0xffdata; while(!(bSPIM_1_ReadStatus()SPIM_1_CONTROL_REG & SPIM_SPI_COMPLETE)); // deassert the slave select RADIO_PORT |= nSS; spiLock = 0; data = SPIM_1_RX_BUFFER_REG; if( isr_state & GPIO_ISR_RADIO_INT ) { RADIO_ISR_ENABLE(); } return(SPIM_1_RX_BUFFER_REG) data; }