project
Fork of X_NUCLEO_IDB0XA1 by
Embed:
(wiki syntax)
Show/hide line numbers
stm32_bluenrg_ble.cpp
Go to the documentation of this file.
00001 /** 00002 ****************************************************************************** 00003 * @file stm32_bluenrg_ble.cpp 00004 * @author CL 00005 * @version V1.0.0 00006 * @date 15-June-2015 00007 * @brief 00008 ****************************************************************************** 00009 * @attention 00010 * 00011 * <h2><center>© 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 /* Includes ------------------------------------------------------------------*/ 00039 #include "BlueNRGGap.h" 00040 #include "BlueNRGDevice.h" 00041 //#include "Utils.h" 00042 #include "btle.h" 00043 00044 // FIXME: find a better way to get the instance of the BlueNRG device 00045 extern BlueNRGDevice bluenrgDeviceInstance; 00046 00047 00048 //////////////////////////////////////// 00049 // Start of C function wrappers 00050 #ifdef __cplusplus 00051 extern "C" { 00052 #endif 00053 00054 #include "stm32_bluenrg_ble.h " 00055 #include "gp_timer.h" 00056 #include "debug.h" 00057 00058 00059 void BlueNRG_RST(void) 00060 { 00061 bluenrgDeviceInstance.reset(); 00062 } 00063 00064 uint8_t BlueNRG_DataPresent(void) 00065 { 00066 return (bluenrgDeviceInstance.dataPresent()); 00067 } 00068 00069 00070 /** 00071 * @brief This function is a utility to print the log time 00072 * in the format HH:MM:SS:MSS (DK GUI time format) 00073 * @param None 00074 * @retval None 00075 */ 00076 void print_csv_time(void){ 00077 #ifdef PRINT_CSV_FORMAT 00078 uint32_t ms = 0;//ms_counter; 00079 PRINT_CSV("%02d:%02d:%02d.%03d", ms/(60*60*1000)%24, ms/(60*1000)%60, (ms/1000)%60, ms%1000); 00080 #endif 00081 } 00082 00083 /** 00084 * @brief Writes data to a serial interface. 00085 * @param data1 : 1st buffer 00086 * @param data2 : 2nd buffer 00087 * @param n_bytes1: number of bytes in 1st buffer 00088 * @param n_bytes2: number of bytes in 2nd buffer 00089 * @retval None 00090 */ 00091 void Hal_Write_Serial(const void* data1, const void* data2, int32_t n_bytes1, 00092 int32_t n_bytes2) 00093 { 00094 struct timer t; 00095 00096 Timer_Set(&t, CLOCK_SECOND/10); 00097 00098 #ifdef PRINT_CSV_FORMAT 00099 print_csv_time(); 00100 for (int i=0; i<n_bytes1; i++) { 00101 PRINT_CSV(" %02x", ((uint8_t *)data1)[i]); 00102 } 00103 for (int i=0; i<n_bytes2; i++) { 00104 PRINT_CSV(" %02x", ((uint8_t *)data2)[i]); 00105 } 00106 PRINT_CSV("\n"); 00107 #endif 00108 00109 while(1){ 00110 if(BlueNRG_SPI_Write((uint8_t *)data1,(uint8_t *)data2, n_bytes1, n_bytes2)==0) break; 00111 if(Timer_Expired(&t)){ 00112 break; 00113 } 00114 } 00115 } 00116 00117 00118 /** 00119 * @brief Activate internal bootloader using pin. 00120 * @param None 00121 * @retval None 00122 */ 00123 void BlueNRG_HW_Bootloader(void) 00124 { 00125 // FIXME: this is not implemented yet 00126 while (1); 00127 } 00128 00129 /** 00130 * @brief Reads from BlueNRG SPI buffer and store data into local buffer. 00131 * @param buffer : Buffer where data from SPI are stored 00132 * @param buff_size: Buffer size 00133 * @retval int32_t : Number of read bytes 00134 */ 00135 int32_t BlueNRG_SPI_Read_All(uint8_t *buffer, 00136 uint8_t buff_size) 00137 { 00138 int32_t ret = bluenrgDeviceInstance.spiRead(buffer, buff_size); 00139 00140 return ret; 00141 } 00142 00143 /** 00144 * @brief Writes data from local buffer to SPI. 00145 * @param data1 : First data buffer to be written 00146 * @param data2 : Second data buffer to be written 00147 * @param Nb_bytes1: Size of first data buffer to be written 00148 * @param Nb_bytes2: Size of second data buffer to be written 00149 * @retval Number of read bytes 00150 */ 00151 int32_t BlueNRG_SPI_Write(uint8_t* data1, 00152 uint8_t* data2, uint8_t Nb_bytes1, uint8_t Nb_bytes2) 00153 { 00154 int32_t ret = bluenrgDeviceInstance.spiWrite(data1, data2, Nb_bytes1, Nb_bytes2); 00155 00156 return ret; 00157 } 00158 00159 /** 00160 * @brief Enable SPI IRQ. 00161 * @param None 00162 * @retval None 00163 */ 00164 void Enable_SPI_IRQ(void) 00165 { 00166 bluenrgDeviceInstance.enable_irq(); 00167 } 00168 00169 #ifdef AST_FOR_MBED_OS 00170 /** 00171 * Call BTLE callback handler. 00172 * @param None 00173 * @retval None 00174 */ 00175 void Call_BTLE_Handler(void) 00176 { 00177 if(!btle_handler_pending) { 00178 btle_handler_pending = 1; 00179 minar::Scheduler::postCallback(btle_handler); 00180 } 00181 } 00182 #endif 00183 00184 /** 00185 * @brief Disable SPI IRQ. 00186 * @param None 00187 * @retval None 00188 */ 00189 void Disable_SPI_IRQ(void) 00190 { 00191 bluenrgDeviceInstance.disable_irq(); 00192 } 00193 00194 /** 00195 * @brief Clear Pending SPI IRQ. 00196 * @param None 00197 * @retval None 00198 */ 00199 void Clear_SPI_IRQ(void) 00200 { 00201 } 00202 00203 /** 00204 * @brief Clear EXTI (External Interrupt) line for SPI IRQ. 00205 * @param None 00206 * @retval None 00207 */ 00208 void Clear_SPI_EXTI_Flag(void) 00209 { 00210 } 00211 00212 00213 00214 00215 #ifdef __cplusplus 00216 } 00217 #endif 00218 // End of C function wrappers 00219 //////////////////////////////////////// 00220 00221 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Tue Jul 12 2022 19:31:15 by 1.7.2