My fork of X_NUCLEO_IDB0XA1
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 "ble_gp_timer.h" 00056 #include "ble_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 // Reset BlueNRG SPI interface 00126 BlueNRG_RST(); 00127 00128 // Send an ACI command to reboot BlueNRG in bootloader mode 00129 // The safest way to get in bootloader mode is keeping high 00130 // the interrupt pin during reset, but this would require many 00131 // changes to the current mbed driver 00132 aci_updater_start(); 00133 } 00134 00135 /** 00136 * @brief Reads from BlueNRG SPI buffer and store data into local buffer. 00137 * @param buffer : Buffer where data from SPI are stored 00138 * @param buff_size: Buffer size 00139 * @retval int32_t : Number of read bytes 00140 */ 00141 int32_t BlueNRG_SPI_Read_All(uint8_t *buffer, 00142 uint8_t buff_size) 00143 { 00144 int32_t ret = bluenrgDeviceInstance.spiRead(buffer, buff_size); 00145 00146 return ret; 00147 } 00148 00149 /** 00150 * @brief Writes data from local buffer to SPI. 00151 * @param data1 : First data buffer to be written 00152 * @param data2 : Second data buffer to be written 00153 * @param Nb_bytes1: Size of first data buffer to be written 00154 * @param Nb_bytes2: Size of second data buffer to be written 00155 * @retval Number of read bytes 00156 */ 00157 int32_t BlueNRG_SPI_Write(uint8_t* data1, 00158 uint8_t* data2, uint8_t Nb_bytes1, uint8_t Nb_bytes2) 00159 { 00160 int32_t ret = bluenrgDeviceInstance.spiWrite(data1, data2, Nb_bytes1, Nb_bytes2); 00161 00162 return ret; 00163 } 00164 00165 /** 00166 * @brief Enable SPI IRQ. 00167 * @param None 00168 * @retval None 00169 */ 00170 void Enable_SPI_IRQ(void) 00171 { 00172 bluenrgDeviceInstance.enable_irq(); 00173 } 00174 00175 void signalEventsToProcess(void) { 00176 if(btle_handler_pending == 0) { 00177 btle_handler_pending = 1; 00178 bluenrgDeviceInstance.signalEventsToProcess(BLE::DEFAULT_INSTANCE); 00179 } 00180 } 00181 00182 /** 00183 * @brief Disable SPI IRQ. 00184 * @param None 00185 * @retval None 00186 */ 00187 void Disable_SPI_IRQ(void) 00188 { 00189 bluenrgDeviceInstance.disable_irq(); 00190 } 00191 00192 /** 00193 * @brief Clear Pending SPI IRQ. 00194 * @param None 00195 * @retval None 00196 */ 00197 void Clear_SPI_IRQ(void) 00198 { 00199 } 00200 00201 /** 00202 * @brief Clear EXTI (External Interrupt) line for SPI IRQ. 00203 * @param None 00204 * @retval None 00205 */ 00206 void Clear_SPI_EXTI_Flag(void) 00207 { 00208 } 00209 00210 00211 00212 00213 #ifdef __cplusplus 00214 } 00215 #endif 00216 // End of C function wrappers 00217 //////////////////////////////////////// 00218 00219 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Wed Jul 13 2022 03:04:51 by 1.7.2