Added support for WNC M14A2A Cellular LTE Data Module.

Dependencies:   WNC14A2AInterface

Dependents:   http-example-wnc http-example-wnc-modified

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers radio_spi.h Source File

radio_spi.h

Go to the documentation of this file.
00001 /**
00002 ******************************************************************************
00003 * @file    radio_spi.h
00004 * @author  System Lab - NOIDA
00005 * @version V1.0.0
00006 * @date    15-May-2014
00007 * @brief   This file contains all the functions prototypes for SPI .
00008 ******************************************************************************
00009 * @attention
00010 *
00011 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
00012 *
00013 * Redistribution and use in source and binary forms, with or without modification,
00014 * are permitted provided that the following conditions are met:
00015 *   1. Redistributions of source code must retain the above copyright notice,
00016 *      this list of conditions and the following disclaimer.
00017 *   2. Redistributions in binary form must reproduce the above copyright notice,
00018 *      this list of conditions and the following disclaimer in the documentation
00019 *      and/or other materials provided with the distribution.
00020 *   3. Neither the name of STMicroelectronics nor the names of its contributors
00021 *      may be used to endorse or promote products derived from this software
00022 *      without specific prior written permission.
00023 *
00024 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00025 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00026 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00027 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00028 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00029 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00030 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00031 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00032 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00033 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034 *
00035 ******************************************************************************
00036 */
00037 
00038 
00039 /* Define to prevent recursive inclusion -------------------------------------*/
00040 #ifndef __RADIO_SPI_H
00041 #define __RADIO_SPI_H
00042 #ifdef __cplusplus
00043 extern "C" {
00044 #endif
00045   
00046 /* Includes ------------------------------------------------------------------*/
00047 #ifdef USE_STM32L1XX_NUCLEO
00048 // #include "stm32l1xx_hal.h"
00049 #endif
00050 
00051 #ifdef USE_STM32F4XX_NUCLEO
00052 // #include "stm32f4xx_hal.h"
00053 #endif
00054 #include "SPIRIT_Config.h"
00055 #include "radio_spi.h" 
00056 // #include "spirit1-arch.h"
00057 
00058 /**
00059  * @addtogroup BSP
00060  * @{
00061  */ 
00062   
00063 /* Exported types ------------------------------------------------------------*/
00064 
00065   
00066 /* Exported constants --------------------------------------------------------*/
00067   
00068   
00069 /* Exported macro ------------------------------------------------------------*/
00070   /* Define for SPIRIT1 board  */  
00071  #if !defined (USE_SPIRIT1_DEFAULT)
00072  #define USE_SPIRIT1_DEFAULT
00073 #endif
00074   
00075 /* SPIRIT1_Spi_config */ 
00076 /* SPI1 */  
00077 #define RADIO_SPI                                 SPI1
00078 #define RADIO_SPI_CLK_ENABLE()                  __SPI1_CLK_ENABLE()
00079 #define RADIO_SPI_CLK_DISABLE()                 __SPI1_CLK_DISABLE()
00080 
00081 #define RADIO_SPI_MISO_PORT                      GPIOA
00082 #define RADIO_SPI_MISO_PIN                       GPIO_PIN_6
00083 #define RADIO_SPI_MISO_CLOCK_ENABLE()            __GPIOA_CLK_ENABLE()
00084 #define RADIO_SPI_MISO_CLOCK_DISABLE()           __GPIOA_CLK_DISABLE() 
00085   
00086 #define RADIO_SPI_MOSI_PORT                      GPIOA
00087 #define RADIO_SPI_MOSI_PIN                       GPIO_PIN_7
00088 #define RADIO_SPI_MOSI_CLOCK_ENABLE()            __GPIOA_CLK_ENABLE()
00089 #define RADIO_SPI_MOSI_CLOCK_DISABLE()           __GPIOA_CLK_DISABLE()   
00090   
00091  
00092  
00093 #ifdef USE_SPIRIT1_DEFAULT    
00094 
00095 #define RADIO_SPI_SCK_PORT                      GPIOB
00096 #define RADIO_SPI_SCK_PIN                       GPIO_PIN_3
00097 #define RADIO_SPI_SCK_CLOCK_ENABLE()            __GPIOB_CLK_ENABLE()
00098 #define RADIO_SPI_SCK_CLOCK_DISABLE()           __GPIOB_CLK_DISABLE()
00099 
00100   
00101 #define RADIO_SPI_CS_PORT                        GPIOB
00102 #define RADIO_SPI_CS_PIN                         GPIO_PIN_6
00103 #define RADIO_SPI_CS_CLOCK_ENABLE()            __GPIOB_CLK_ENABLE()
00104 #define RADIO_SPI_CS_CLOCK_DISABLE()           __GPIOB_CLK_DISABLE()
00105  
00106 #else 
00107  
00108 #define RADIO_SPI_SCK_PORT                      GPIOB
00109 #define RADIO_SPI_SCK_PIN                       GPIO_PIN_3
00110 #define RADIO_SPI_SCK_CLOCK_ENABLE()            __GPIOB_CLK_ENABLE()
00111 #define RADIO_SPI_SCK_CLOCK_DISABLE()           __GPIOB_CLK_DISABLE()
00112 
00113   
00114 #define RADIO_SPI_CS_PORT                        GPIOB
00115 #define RADIO_SPI_CS_PIN                         GPIO_PIN_6
00116 #define RADIO_SPI_CS_CLOCK_ENABLE()            __GPIOB_CLK_ENABLE()
00117 #define RADIO_SPI_CS_CLOCK_DISABLE()           __GPIOB_CLK_DISABLE()
00118     
00119 #endif  
00120   
00121 /* Maximum Timeout values for flags waiting loops. These timeouts are not based
00122    on accurate values, they just guarantee that the application will not remain
00123    stuck if the SPI communication is corrupted.
00124    You may modify these timeout values depending on CPU frequency and application
00125    conditions (interrupts routines ...) */    
00126 #define RADIO_SPI_TIMEOUT_MAX                   ((uint32_t)1000)
00127 
00128 /* SPIRIT1_Spi_config_Private_Defines */  
00129 #define CS_TO_SCLK_DELAY     0x0200//FIXME what is this doing?
00130 #define CLK_TO_CS_DELAY      0x0001
00131   
00132 /* SPIRIT1_Spi_config_Headers */
00133 #define HEADER_WRITE_MASK     0x00                                /*!< Write mask for header byte*/
00134 #define HEADER_READ_MASK      0x01                                /*!< Read mask for header byte*/
00135 #define HEADER_ADDRESS_MASK   0x00                                /*!< Address mask for header byte*/
00136 #define HEADER_COMMAND_MASK   0x80                                /*!< Command mask for header byte*/
00137   
00138 #define LINEAR_FIFO_ADDRESS 0xFF                                  /*!< Linear FIFO address*/
00139   
00140 /* SPIRIT1_Spi_config_Private_FunctionPrototypes */
00141 #define SPI_ENTER_CRITICAL()         IRQ_DISABLE()
00142 #define SPI_EXIT_CRITICAL()          IRQ_ENABLE()
00143   
00144 /* SPIRIT1_Spi_config_Private_Functions */
00145 #define RadioSpiCSLow()        HAL_GPIO_WritePin(RADIO_SPI_CS_PORT, RADIO_SPI_CS_PIN, GPIO_PIN_RESET)
00146 #define RadioSpiCSHigh()       HAL_GPIO_WritePin(RADIO_SPI_CS_PORT, RADIO_SPI_CS_PIN, GPIO_PIN_SET)
00147   
00148 /* SPIRIT1_Spi_config_Private_Macros */
00149 #define BUILT_HEADER(add_comm, w_r) (add_comm | w_r)                             /*!< macro to build the header byte*/
00150 #define WRITE_HEADER        BUILT_HEADER(HEADER_ADDRESS_MASK, HEADER_WRITE_MASK) /*!< macro to build the write 
00151                                                                                                          header byte*/
00152 #define READ_HEADER         BUILT_HEADER(HEADER_ADDRESS_MASK, HEADER_READ_MASK)  /*!< macro to build the read 
00153                                                                                                          header byte*/
00154 #define COMMAND_HEADER      BUILT_HEADER(HEADER_COMMAND_MASK, HEADER_WRITE_MASK) /*!< macro to build the command 
00155                                                                                                          header byte*/
00156   
00157   
00158   
00159 /* Exported Variables --------------------------------------------------------*/
00160   
00161   
00162 /* Exported functions ------------------------------------------------------- */ 
00163 void SdkEvalSpiInit(void);
00164 // void SpiCSGpioSetLevel(GPIO_PinState xState);
00165 StatusBytes SdkEvalSpiWriteRegisters(uint8_t cRegAddress, uint8_t cNbBytes, uint8_t* pcBuffer);
00166 StatusBytes SdkEvalSpiReadRegisters(uint8_t cRegAddress, uint8_t cNbBytes, uint8_t* pcBuffer);
00167 StatusBytes SdkEvalSpiCommandStrobes(uint8_t cCommandCode);
00168 StatusBytes SdkEvalSpiWriteFifo(uint8_t cNbBytes, uint8_t* pcBuffer);
00169 StatusBytes SdkEvalSpiReadFifo(uint8_t cNbBytes, uint8_t* pcBuffer);
00170 
00171   
00172 #ifdef __cplusplus
00173 }
00174 #endif
00175 #endif /*__RADIO_SPI_H */
00176 
00177 /**
00178 * @}
00179 */
00180 
00181 /**
00182 * @}
00183 */
00184 
00185 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/