Fork of my MQTTGateway

Dependencies:   mbed-http

Committer:
vpcola
Date:
Sat Apr 08 14:45:51 2017 +0000
Revision:
0:f1d3878b8dd9
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vpcola 0:f1d3878b8dd9 1 /**
vpcola 0:f1d3878b8dd9 2 ******************************************************************************
vpcola 0:f1d3878b8dd9 3 * @file radio_spi.h
vpcola 0:f1d3878b8dd9 4 * @author System Lab - NOIDA
vpcola 0:f1d3878b8dd9 5 * @version V1.0.0
vpcola 0:f1d3878b8dd9 6 * @date 15-May-2014
vpcola 0:f1d3878b8dd9 7 * @brief This file contains all the functions prototypes for SPI .
vpcola 0:f1d3878b8dd9 8 ******************************************************************************
vpcola 0:f1d3878b8dd9 9 * @attention
vpcola 0:f1d3878b8dd9 10 *
vpcola 0:f1d3878b8dd9 11 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
vpcola 0:f1d3878b8dd9 12 *
vpcola 0:f1d3878b8dd9 13 * Redistribution and use in source and binary forms, with or without modification,
vpcola 0:f1d3878b8dd9 14 * are permitted provided that the following conditions are met:
vpcola 0:f1d3878b8dd9 15 * 1. Redistributions of source code must retain the above copyright notice,
vpcola 0:f1d3878b8dd9 16 * this list of conditions and the following disclaimer.
vpcola 0:f1d3878b8dd9 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
vpcola 0:f1d3878b8dd9 18 * this list of conditions and the following disclaimer in the documentation
vpcola 0:f1d3878b8dd9 19 * and/or other materials provided with the distribution.
vpcola 0:f1d3878b8dd9 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
vpcola 0:f1d3878b8dd9 21 * may be used to endorse or promote products derived from this software
vpcola 0:f1d3878b8dd9 22 * without specific prior written permission.
vpcola 0:f1d3878b8dd9 23 *
vpcola 0:f1d3878b8dd9 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
vpcola 0:f1d3878b8dd9 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
vpcola 0:f1d3878b8dd9 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
vpcola 0:f1d3878b8dd9 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
vpcola 0:f1d3878b8dd9 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
vpcola 0:f1d3878b8dd9 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
vpcola 0:f1d3878b8dd9 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
vpcola 0:f1d3878b8dd9 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
vpcola 0:f1d3878b8dd9 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
vpcola 0:f1d3878b8dd9 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
vpcola 0:f1d3878b8dd9 34 *
vpcola 0:f1d3878b8dd9 35 ******************************************************************************
vpcola 0:f1d3878b8dd9 36 */
vpcola 0:f1d3878b8dd9 37
vpcola 0:f1d3878b8dd9 38
vpcola 0:f1d3878b8dd9 39 /* Define to prevent recursive inclusion -------------------------------------*/
vpcola 0:f1d3878b8dd9 40 #ifndef __RADIO_SPI_H
vpcola 0:f1d3878b8dd9 41 #define __RADIO_SPI_H
vpcola 0:f1d3878b8dd9 42 #ifdef __cplusplus
vpcola 0:f1d3878b8dd9 43 extern "C" {
vpcola 0:f1d3878b8dd9 44 #endif
vpcola 0:f1d3878b8dd9 45
vpcola 0:f1d3878b8dd9 46 /* Includes ------------------------------------------------------------------*/
vpcola 0:f1d3878b8dd9 47 #ifdef USE_STM32L1XX_NUCLEO
vpcola 0:f1d3878b8dd9 48 // #include "stm32l1xx_hal.h"
vpcola 0:f1d3878b8dd9 49 #endif
vpcola 0:f1d3878b8dd9 50
vpcola 0:f1d3878b8dd9 51 #ifdef USE_STM32F4XX_NUCLEO
vpcola 0:f1d3878b8dd9 52 // #include "stm32f4xx_hal.h"
vpcola 0:f1d3878b8dd9 53 #endif
vpcola 0:f1d3878b8dd9 54 #include "SPIRIT_Config.h"
vpcola 0:f1d3878b8dd9 55 #include "radio_spi.h"
vpcola 0:f1d3878b8dd9 56 // #include "spirit1-arch.h"
vpcola 0:f1d3878b8dd9 57
vpcola 0:f1d3878b8dd9 58 /**
vpcola 0:f1d3878b8dd9 59 * @addtogroup BSP
vpcola 0:f1d3878b8dd9 60 * @{
vpcola 0:f1d3878b8dd9 61 */
vpcola 0:f1d3878b8dd9 62
vpcola 0:f1d3878b8dd9 63 /* Exported types ------------------------------------------------------------*/
vpcola 0:f1d3878b8dd9 64
vpcola 0:f1d3878b8dd9 65
vpcola 0:f1d3878b8dd9 66 /* Exported constants --------------------------------------------------------*/
vpcola 0:f1d3878b8dd9 67
vpcola 0:f1d3878b8dd9 68
vpcola 0:f1d3878b8dd9 69 /* Exported macro ------------------------------------------------------------*/
vpcola 0:f1d3878b8dd9 70 /* Define for SPIRIT1 board */
vpcola 0:f1d3878b8dd9 71 #if !defined (USE_SPIRIT1_DEFAULT)
vpcola 0:f1d3878b8dd9 72 #define USE_SPIRIT1_DEFAULT
vpcola 0:f1d3878b8dd9 73 #endif
vpcola 0:f1d3878b8dd9 74
vpcola 0:f1d3878b8dd9 75 /* SPIRIT1_Spi_config */
vpcola 0:f1d3878b8dd9 76 /* SPI1 */
vpcola 0:f1d3878b8dd9 77 #define RADIO_SPI SPI1
vpcola 0:f1d3878b8dd9 78 #define RADIO_SPI_CLK_ENABLE() __SPI1_CLK_ENABLE()
vpcola 0:f1d3878b8dd9 79 #define RADIO_SPI_CLK_DISABLE() __SPI1_CLK_DISABLE()
vpcola 0:f1d3878b8dd9 80
vpcola 0:f1d3878b8dd9 81 #define RADIO_SPI_MISO_PORT GPIOA
vpcola 0:f1d3878b8dd9 82 #define RADIO_SPI_MISO_PIN GPIO_PIN_6
vpcola 0:f1d3878b8dd9 83 #define RADIO_SPI_MISO_CLOCK_ENABLE() __GPIOA_CLK_ENABLE()
vpcola 0:f1d3878b8dd9 84 #define RADIO_SPI_MISO_CLOCK_DISABLE() __GPIOA_CLK_DISABLE()
vpcola 0:f1d3878b8dd9 85
vpcola 0:f1d3878b8dd9 86 #define RADIO_SPI_MOSI_PORT GPIOA
vpcola 0:f1d3878b8dd9 87 #define RADIO_SPI_MOSI_PIN GPIO_PIN_7
vpcola 0:f1d3878b8dd9 88 #define RADIO_SPI_MOSI_CLOCK_ENABLE() __GPIOA_CLK_ENABLE()
vpcola 0:f1d3878b8dd9 89 #define RADIO_SPI_MOSI_CLOCK_DISABLE() __GPIOA_CLK_DISABLE()
vpcola 0:f1d3878b8dd9 90
vpcola 0:f1d3878b8dd9 91
vpcola 0:f1d3878b8dd9 92
vpcola 0:f1d3878b8dd9 93 #ifdef USE_SPIRIT1_DEFAULT
vpcola 0:f1d3878b8dd9 94
vpcola 0:f1d3878b8dd9 95 #define RADIO_SPI_SCK_PORT GPIOB
vpcola 0:f1d3878b8dd9 96 #define RADIO_SPI_SCK_PIN GPIO_PIN_3
vpcola 0:f1d3878b8dd9 97 #define RADIO_SPI_SCK_CLOCK_ENABLE() __GPIOB_CLK_ENABLE()
vpcola 0:f1d3878b8dd9 98 #define RADIO_SPI_SCK_CLOCK_DISABLE() __GPIOB_CLK_DISABLE()
vpcola 0:f1d3878b8dd9 99
vpcola 0:f1d3878b8dd9 100
vpcola 0:f1d3878b8dd9 101 #define RADIO_SPI_CS_PORT GPIOB
vpcola 0:f1d3878b8dd9 102 #define RADIO_SPI_CS_PIN GPIO_PIN_6
vpcola 0:f1d3878b8dd9 103 #define RADIO_SPI_CS_CLOCK_ENABLE() __GPIOB_CLK_ENABLE()
vpcola 0:f1d3878b8dd9 104 #define RADIO_SPI_CS_CLOCK_DISABLE() __GPIOB_CLK_DISABLE()
vpcola 0:f1d3878b8dd9 105
vpcola 0:f1d3878b8dd9 106 #else
vpcola 0:f1d3878b8dd9 107
vpcola 0:f1d3878b8dd9 108 #define RADIO_SPI_SCK_PORT GPIOB
vpcola 0:f1d3878b8dd9 109 #define RADIO_SPI_SCK_PIN GPIO_PIN_3
vpcola 0:f1d3878b8dd9 110 #define RADIO_SPI_SCK_CLOCK_ENABLE() __GPIOB_CLK_ENABLE()
vpcola 0:f1d3878b8dd9 111 #define RADIO_SPI_SCK_CLOCK_DISABLE() __GPIOB_CLK_DISABLE()
vpcola 0:f1d3878b8dd9 112
vpcola 0:f1d3878b8dd9 113
vpcola 0:f1d3878b8dd9 114 #define RADIO_SPI_CS_PORT GPIOB
vpcola 0:f1d3878b8dd9 115 #define RADIO_SPI_CS_PIN GPIO_PIN_6
vpcola 0:f1d3878b8dd9 116 #define RADIO_SPI_CS_CLOCK_ENABLE() __GPIOB_CLK_ENABLE()
vpcola 0:f1d3878b8dd9 117 #define RADIO_SPI_CS_CLOCK_DISABLE() __GPIOB_CLK_DISABLE()
vpcola 0:f1d3878b8dd9 118
vpcola 0:f1d3878b8dd9 119 #endif
vpcola 0:f1d3878b8dd9 120
vpcola 0:f1d3878b8dd9 121 /* Maximum Timeout values for flags waiting loops. These timeouts are not based
vpcola 0:f1d3878b8dd9 122 on accurate values, they just guarantee that the application will not remain
vpcola 0:f1d3878b8dd9 123 stuck if the SPI communication is corrupted.
vpcola 0:f1d3878b8dd9 124 You may modify these timeout values depending on CPU frequency and application
vpcola 0:f1d3878b8dd9 125 conditions (interrupts routines ...) */
vpcola 0:f1d3878b8dd9 126 #define RADIO_SPI_TIMEOUT_MAX ((uint32_t)1000)
vpcola 0:f1d3878b8dd9 127
vpcola 0:f1d3878b8dd9 128 /* SPIRIT1_Spi_config_Private_Defines */
vpcola 0:f1d3878b8dd9 129 #define CS_TO_SCLK_DELAY 0x0200//FIXME what is this doing?
vpcola 0:f1d3878b8dd9 130 #define CLK_TO_CS_DELAY 0x0001
vpcola 0:f1d3878b8dd9 131
vpcola 0:f1d3878b8dd9 132 /* SPIRIT1_Spi_config_Headers */
vpcola 0:f1d3878b8dd9 133 #define HEADER_WRITE_MASK 0x00 /*!< Write mask for header byte*/
vpcola 0:f1d3878b8dd9 134 #define HEADER_READ_MASK 0x01 /*!< Read mask for header byte*/
vpcola 0:f1d3878b8dd9 135 #define HEADER_ADDRESS_MASK 0x00 /*!< Address mask for header byte*/
vpcola 0:f1d3878b8dd9 136 #define HEADER_COMMAND_MASK 0x80 /*!< Command mask for header byte*/
vpcola 0:f1d3878b8dd9 137
vpcola 0:f1d3878b8dd9 138 #define LINEAR_FIFO_ADDRESS 0xFF /*!< Linear FIFO address*/
vpcola 0:f1d3878b8dd9 139
vpcola 0:f1d3878b8dd9 140 /* SPIRIT1_Spi_config_Private_FunctionPrototypes */
vpcola 0:f1d3878b8dd9 141 #define SPI_ENTER_CRITICAL() IRQ_DISABLE()
vpcola 0:f1d3878b8dd9 142 #define SPI_EXIT_CRITICAL() IRQ_ENABLE()
vpcola 0:f1d3878b8dd9 143
vpcola 0:f1d3878b8dd9 144 /* SPIRIT1_Spi_config_Private_Functions */
vpcola 0:f1d3878b8dd9 145 #define RadioSpiCSLow() HAL_GPIO_WritePin(RADIO_SPI_CS_PORT, RADIO_SPI_CS_PIN, GPIO_PIN_RESET)
vpcola 0:f1d3878b8dd9 146 #define RadioSpiCSHigh() HAL_GPIO_WritePin(RADIO_SPI_CS_PORT, RADIO_SPI_CS_PIN, GPIO_PIN_SET)
vpcola 0:f1d3878b8dd9 147
vpcola 0:f1d3878b8dd9 148 /* SPIRIT1_Spi_config_Private_Macros */
vpcola 0:f1d3878b8dd9 149 #define BUILT_HEADER(add_comm, w_r) (add_comm | w_r) /*!< macro to build the header byte*/
vpcola 0:f1d3878b8dd9 150 #define WRITE_HEADER BUILT_HEADER(HEADER_ADDRESS_MASK, HEADER_WRITE_MASK) /*!< macro to build the write
vpcola 0:f1d3878b8dd9 151 header byte*/
vpcola 0:f1d3878b8dd9 152 #define READ_HEADER BUILT_HEADER(HEADER_ADDRESS_MASK, HEADER_READ_MASK) /*!< macro to build the read
vpcola 0:f1d3878b8dd9 153 header byte*/
vpcola 0:f1d3878b8dd9 154 #define COMMAND_HEADER BUILT_HEADER(HEADER_COMMAND_MASK, HEADER_WRITE_MASK) /*!< macro to build the command
vpcola 0:f1d3878b8dd9 155 header byte*/
vpcola 0:f1d3878b8dd9 156
vpcola 0:f1d3878b8dd9 157
vpcola 0:f1d3878b8dd9 158
vpcola 0:f1d3878b8dd9 159 /* Exported Variables --------------------------------------------------------*/
vpcola 0:f1d3878b8dd9 160
vpcola 0:f1d3878b8dd9 161
vpcola 0:f1d3878b8dd9 162 /* Exported functions ------------------------------------------------------- */
vpcola 0:f1d3878b8dd9 163 void SdkEvalSpiInit(void);
vpcola 0:f1d3878b8dd9 164 // void SpiCSGpioSetLevel(GPIO_PinState xState);
vpcola 0:f1d3878b8dd9 165 StatusBytes SdkEvalSpiWriteRegisters(uint8_t cRegAddress, uint8_t cNbBytes, uint8_t* pcBuffer);
vpcola 0:f1d3878b8dd9 166 StatusBytes SdkEvalSpiReadRegisters(uint8_t cRegAddress, uint8_t cNbBytes, uint8_t* pcBuffer);
vpcola 0:f1d3878b8dd9 167 StatusBytes SdkEvalSpiCommandStrobes(uint8_t cCommandCode);
vpcola 0:f1d3878b8dd9 168 StatusBytes SdkEvalSpiWriteFifo(uint8_t cNbBytes, uint8_t* pcBuffer);
vpcola 0:f1d3878b8dd9 169 StatusBytes SdkEvalSpiReadFifo(uint8_t cNbBytes, uint8_t* pcBuffer);
vpcola 0:f1d3878b8dd9 170
vpcola 0:f1d3878b8dd9 171
vpcola 0:f1d3878b8dd9 172 #ifdef __cplusplus
vpcola 0:f1d3878b8dd9 173 }
vpcola 0:f1d3878b8dd9 174 #endif
vpcola 0:f1d3878b8dd9 175 #endif /*__RADIO_SPI_H */
vpcola 0:f1d3878b8dd9 176
vpcola 0:f1d3878b8dd9 177 /**
vpcola 0:f1d3878b8dd9 178 * @}
vpcola 0:f1d3878b8dd9 179 */
vpcola 0:f1d3878b8dd9 180
vpcola 0:f1d3878b8dd9 181 /**
vpcola 0:f1d3878b8dd9 182 * @}
vpcola 0:f1d3878b8dd9 183 */
vpcola 0:f1d3878b8dd9 184
vpcola 0:f1d3878b8dd9 185 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/