Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of X_NUCLEO_IDB0XA1 by
stm32_bluenrg_ble.cpp
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 // Reset BlueNRG SPI interface 00126 BlueNRG_RST(); 00127 00128 // Send an ACI command to reboot BlueNRG in bootloader mode 00129 aci_updater_start(); 00130 } 00131 00132 /** 00133 * @brief Reads from BlueNRG SPI buffer and store data into local buffer. 00134 * @param buffer : Buffer where data from SPI are stored 00135 * @param buff_size: Buffer size 00136 * @retval int32_t : Number of read bytes 00137 */ 00138 int32_t BlueNRG_SPI_Read_All(uint8_t *buffer, 00139 uint8_t buff_size) 00140 { 00141 int32_t ret = bluenrgDeviceInstance.spiRead(buffer, buff_size); 00142 00143 return ret; 00144 } 00145 00146 /** 00147 * @brief Writes data from local buffer to SPI. 00148 * @param data1 : First data buffer to be written 00149 * @param data2 : Second data buffer to be written 00150 * @param Nb_bytes1: Size of first data buffer to be written 00151 * @param Nb_bytes2: Size of second data buffer to be written 00152 * @retval Number of read bytes 00153 */ 00154 int32_t BlueNRG_SPI_Write(uint8_t* data1, 00155 uint8_t* data2, uint8_t Nb_bytes1, uint8_t Nb_bytes2) 00156 { 00157 int32_t ret = bluenrgDeviceInstance.spiWrite(data1, data2, Nb_bytes1, Nb_bytes2); 00158 00159 return ret; 00160 } 00161 00162 /** 00163 * @brief Enable SPI IRQ. 00164 * @param None 00165 * @retval None 00166 */ 00167 void Enable_SPI_IRQ(void) 00168 { 00169 bluenrgDeviceInstance.enable_irq(); 00170 } 00171 00172 #ifdef AST_FOR_MBED_OS 00173 /** 00174 * Call BTLE callback handler. 00175 * @param None 00176 * @retval None 00177 */ 00178 void Call_BTLE_Handler(void) 00179 { 00180 if(!btle_handler_pending) { 00181 btle_handler_pending = 1; 00182 minar::Scheduler::postCallback(btle_handler); 00183 } 00184 } 00185 #endif 00186 00187 /** 00188 * @brief Disable SPI IRQ. 00189 * @param None 00190 * @retval None 00191 */ 00192 void Disable_SPI_IRQ(void) 00193 { 00194 bluenrgDeviceInstance.disable_irq(); 00195 } 00196 00197 /** 00198 * @brief Clear Pending SPI IRQ. 00199 * @param None 00200 * @retval None 00201 */ 00202 void Clear_SPI_IRQ(void) 00203 { 00204 } 00205 00206 /** 00207 * @brief Clear EXTI (External Interrupt) line for SPI IRQ. 00208 * @param None 00209 * @retval None 00210 */ 00211 void Clear_SPI_EXTI_Flag(void) 00212 { 00213 } 00214 00215 00216 00217 00218 #ifdef __cplusplus 00219 } 00220 #endif 00221 // End of C function wrappers 00222 //////////////////////////////////////// 00223 00224 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Tue Jul 12 2022 16:31:46 by
