test
Dependents: BLE_HeartRate_IDB0XA1_EPUDEE_Avril2018
Fork of X_NUCLEO_IDB0XA1 by
bluenrg_hal_aci.c
00001 /******************** (C) COPYRIGHT 2013 STMicroelectronics ******************** 00002 * File Name : bluenrg_hci.c 00003 * Author : AMS - HEA&RF BU 00004 * Version : V1.0.0 00005 * Date : 4-Oct-2013 00006 * Description : File with HCI commands for BlueNRG FW6.0 and above. 00007 ******************************************************************************** 00008 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 00009 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 00010 * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 00011 * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 00012 * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 00013 * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 00014 *******************************************************************************/ 00015 00016 #include "ble_hal_types.h" 00017 #include "ble_osal.h" 00018 #include "ble_status.h" 00019 #include "ble_hal.h" 00020 #include "ble_osal.h" 00021 #include "ble_hci_const.h" 00022 #include "bluenrg_aci_const.h" 00023 #include "bluenrg_hal_aci.h" 00024 #include "bluenrg_gatt_server.h" 00025 #include "bluenrg_gap.h" 00026 00027 #define MIN(a,b) ((a) < (b) )? (a) : (b) 00028 #define MAX(a,b) ((a) > (b) )? (a) : (b) 00029 00030 00031 tBleStatus aci_hal_write_config_data(uint8_t offset, 00032 uint8_t len, 00033 const uint8_t *val) 00034 { 00035 struct hci_request rq; 00036 uint8_t status; 00037 uint8_t buffer[HCI_MAX_PAYLOAD_SIZE]; 00038 uint8_t indx = 0; 00039 00040 if ((len+2) > HCI_MAX_PAYLOAD_SIZE) 00041 return BLE_STATUS_INVALID_PARAMS; 00042 00043 buffer[indx] = offset; 00044 indx++; 00045 00046 buffer[indx] = len; 00047 indx++; 00048 00049 Osal_MemCpy(buffer + indx, val, len); 00050 indx += len; 00051 00052 Osal_MemSet(&rq, 0, sizeof(rq)); 00053 rq.ogf = OGF_VENDOR_CMD; 00054 rq.ocf = OCF_HAL_WRITE_CONFIG_DATA; 00055 rq.cparam = (void *)buffer; 00056 rq.clen = indx; 00057 rq.rparam = &status; 00058 rq.rlen = 1; 00059 00060 if (hci_send_req(&rq, FALSE) < 0) 00061 return BLE_STATUS_TIMEOUT; 00062 00063 if (status) { 00064 return status; 00065 } 00066 00067 return 0; 00068 } 00069 00070 tBleStatus aci_hal_read_config_data(uint8_t offset, uint16_t data_len, uint8_t *data_len_out_p, uint8_t *data) 00071 { 00072 struct hci_request rq; 00073 hal_read_config_data_cp cp; 00074 hal_read_config_data_rp rp; 00075 00076 cp.offset = offset; 00077 00078 Osal_MemSet(&rq, 0, sizeof(rq)); 00079 rq.ogf = OGF_VENDOR_CMD; 00080 rq.ocf = OCF_HAL_READ_CONFIG_DATA; 00081 rq.cparam = &cp; 00082 rq.clen = sizeof(cp); 00083 rq.rparam = &rp; 00084 rq.rlen = sizeof(rp); 00085 00086 if (hci_send_req(&rq, FALSE) < 0) 00087 return BLE_STATUS_TIMEOUT; 00088 00089 if(rp.status) 00090 return rp.status; 00091 00092 *data_len_out_p = rq.rlen-1; 00093 00094 Osal_MemCpy(data, rp.data, MIN(data_len, *data_len_out_p)); 00095 00096 return 0; 00097 } 00098 00099 tBleStatus aci_hal_set_tx_power_level(uint8_t en_high_power, uint8_t pa_level) 00100 { 00101 struct hci_request rq; 00102 hal_set_tx_power_level_cp cp; 00103 uint8_t status; 00104 00105 cp.en_high_power = en_high_power; 00106 cp.pa_level = pa_level; 00107 00108 Osal_MemSet(&rq, 0, sizeof(rq)); 00109 rq.ogf = OGF_VENDOR_CMD; 00110 rq.ocf = OCF_HAL_SET_TX_POWER_LEVEL; 00111 rq.cparam = &cp; 00112 rq.clen = HAL_SET_TX_POWER_LEVEL_CP_SIZE; 00113 rq.rparam = &status; 00114 rq.rlen = 1; 00115 00116 if (hci_send_req(&rq, FALSE) < 0) 00117 return BLE_STATUS_TIMEOUT; 00118 00119 if (status) { 00120 return status; 00121 } 00122 00123 return 0; 00124 } 00125 00126 tBleStatus aci_hal_device_standby(void) 00127 { 00128 struct hci_request rq; 00129 uint8_t status; 00130 00131 Osal_MemSet(&rq, 0, sizeof(rq)); 00132 rq.ogf = OGF_VENDOR_CMD; 00133 rq.ocf = OCF_HAL_DEVICE_STANDBY; 00134 rq.rparam = &status; 00135 rq.rlen = 1; 00136 00137 if (hci_send_req(&rq, FALSE) < 0) 00138 return BLE_STATUS_TIMEOUT; 00139 00140 return status; 00141 } 00142 00143 tBleStatus aci_hal_tone_start(uint8_t rf_channel) 00144 { 00145 struct hci_request rq; 00146 hal_tone_start_cp cp; 00147 uint8_t status; 00148 00149 cp.rf_channel = rf_channel; 00150 00151 Osal_MemSet(&rq, 0, sizeof(rq)); 00152 rq.ogf = OGF_VENDOR_CMD; 00153 rq.ocf = OCF_HAL_TONE_START; 00154 rq.cparam = &cp; 00155 rq.clen = HAL_TONE_START_CP_SIZE; 00156 rq.rparam = &status; 00157 rq.rlen = 1; 00158 00159 if (hci_send_req(&rq, FALSE) < 0) 00160 return BLE_STATUS_TIMEOUT; 00161 00162 return status; 00163 } 00164 00165 tBleStatus aci_hal_tone_stop(void) 00166 { 00167 struct hci_request rq; 00168 uint8_t status; 00169 00170 Osal_MemSet(&rq, 0, sizeof(rq)); 00171 rq.ogf = OGF_VENDOR_CMD; 00172 rq.ocf = OCF_HAL_TONE_STOP; 00173 rq.rparam = &status; 00174 rq.rlen = 1; 00175 00176 if (hci_send_req(&rq, FALSE) < 0) 00177 return BLE_STATUS_TIMEOUT; 00178 00179 return status; 00180 } 00181 00182
Generated on Tue Jul 12 2022 16:33:09 by 1.7.2