HW layer for the Nucleo board, it only work with old BLE_API

Dependents:   Hello_BLE F446RE-BLE

Fork of X_NUCLEO_IDB0XA1 by ST

Committer:
hemddabral
Date:
Tue Aug 05 06:33:39 2014 +0000
Revision:
12:a5d7db4a1e49
Child:
16:8aeb0c44869b
support for setting tx power level

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hemddabral 12:a5d7db4a1e49 1 /* mbed Microcontroller Library
hemddabral 12:a5d7db4a1e49 2 * Copyright (c) 2006-2013 ARM Limited
hemddabral 12:a5d7db4a1e49 3 *
hemddabral 12:a5d7db4a1e49 4 * Licensed under the Apache License, Version 2.0 (the "License");
hemddabral 12:a5d7db4a1e49 5 * you may not use this file except in compliance with the License.
hemddabral 12:a5d7db4a1e49 6 * You may obtain a copy of the License at
hemddabral 12:a5d7db4a1e49 7 *
hemddabral 12:a5d7db4a1e49 8 * http://www.apache.org/licenses/LICENSE-2.0
hemddabral 12:a5d7db4a1e49 9 *
hemddabral 12:a5d7db4a1e49 10 * Unless required by applicable law or agreed to in writing, software
hemddabral 12:a5d7db4a1e49 11 * distributed under the License is distributed on an "AS IS" BASIS,
hemddabral 12:a5d7db4a1e49 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
hemddabral 12:a5d7db4a1e49 13 * See the License for the specific language governing permissions and
hemddabral 12:a5d7db4a1e49 14 * limitations under the License.
hemddabral 12:a5d7db4a1e49 15 */
hemddabral 12:a5d7db4a1e49 16
hemddabral 12:a5d7db4a1e49 17 #include "Utils.h"
hemddabral 12:a5d7db4a1e49 18
hemddabral 12:a5d7db4a1e49 19 /**************************************************************************/
hemddabral 12:a5d7db4a1e49 20 /*!
hemddabral 12:a5d7db4a1e49 21 @brief sets values of EN_HIGH_POWER and PA_LEVEL corresponding to dBMLevel of tx power
hemddabral 12:a5d7db4a1e49 22
hemddabral 12:a5d7db4a1e49 23 @returns value of tx power in dbm actually set
hemddabral 12:a5d7db4a1e49 24
hemddabral 12:a5d7db4a1e49 25 @params[in] dBMLevel
hemddabral 12:a5d7db4a1e49 26 dBMLevel of tx power to be set
hemddabral 12:a5d7db4a1e49 27
hemddabral 12:a5d7db4a1e49 28 @params[in] dBMLevel
hemddabral 12:a5d7db4a1e49 29 dBMLevel of tx power to be set
hemddabral 12:a5d7db4a1e49 30
hemddabral 12:a5d7db4a1e49 31 @endcode
hemddabral 12:a5d7db4a1e49 32 */
hemddabral 12:a5d7db4a1e49 33 /**************************************************************************/
hemddabral 12:a5d7db4a1e49 34 double getHighPowerAndPALevelValue(int8_t dBMLevel, int8_t& EN_HIGH_POWER, int8_t& PA_LEVEL) {
hemddabral 12:a5d7db4a1e49 35 double dbm = (double) dBMLevel;
hemddabral 12:a5d7db4a1e49 36 if(dbm<-18.0) {
hemddabral 12:a5d7db4a1e49 37 dbm = -18;
hemddabral 12:a5d7db4a1e49 38 EN_HIGH_POWER = 0;
hemddabral 12:a5d7db4a1e49 39 PA_LEVEL = 0;
hemddabral 12:a5d7db4a1e49 40 }
hemddabral 12:a5d7db4a1e49 41 else if(dbm>8.0) {
hemddabral 12:a5d7db4a1e49 42 dbm = 8;
hemddabral 12:a5d7db4a1e49 43 EN_HIGH_POWER = 1;
hemddabral 12:a5d7db4a1e49 44 PA_LEVEL = 7;
hemddabral 12:a5d7db4a1e49 45 }
hemddabral 12:a5d7db4a1e49 46
hemddabral 12:a5d7db4a1e49 47 // As a policy we are setting tx power level to the higher side
hemddabral 12:a5d7db4a1e49 48 if((dbm>-18.0) && (dbm<=-15)) {
hemddabral 12:a5d7db4a1e49 49 // set tx power to -15dBM
hemddabral 12:a5d7db4a1e49 50 EN_HIGH_POWER = 0;
hemddabral 12:a5d7db4a1e49 51 PA_LEVEL = 0;
hemddabral 12:a5d7db4a1e49 52 }
hemddabral 12:a5d7db4a1e49 53 else if((dbm>-15) && (dbm<=-14.7)) {
hemddabral 12:a5d7db4a1e49 54 // set tx power to -14.7dBM
hemddabral 12:a5d7db4a1e49 55 EN_HIGH_POWER = 0;
hemddabral 12:a5d7db4a1e49 56 PA_LEVEL = 1;
hemddabral 12:a5d7db4a1e49 57 }
hemddabral 12:a5d7db4a1e49 58 else if((dbm>-14.7) && (dbm<=-11.7)) {
hemddabral 12:a5d7db4a1e49 59 // set tx power to -11.7dBM
hemddabral 12:a5d7db4a1e49 60 EN_HIGH_POWER = 1;
hemddabral 12:a5d7db4a1e49 61 PA_LEVEL = 1;
hemddabral 12:a5d7db4a1e49 62 }
hemddabral 12:a5d7db4a1e49 63 else if((dbm>-11.7) && (dbm<=-11.4)) {
hemddabral 12:a5d7db4a1e49 64 // set tx power to -11.4dBM
hemddabral 12:a5d7db4a1e49 65 EN_HIGH_POWER = 0;
hemddabral 12:a5d7db4a1e49 66 PA_LEVEL = 2;
hemddabral 12:a5d7db4a1e49 67 }
hemddabral 12:a5d7db4a1e49 68 else if((dbm>-11.4) && (dbm<=-8.4)) {
hemddabral 12:a5d7db4a1e49 69 // set tx power to -8.4dBM
hemddabral 12:a5d7db4a1e49 70 EN_HIGH_POWER = 1;
hemddabral 12:a5d7db4a1e49 71 PA_LEVEL = 2;
hemddabral 12:a5d7db4a1e49 72 }
hemddabral 12:a5d7db4a1e49 73 else if((dbm>-8.4) && (dbm<=-8.1)) {
hemddabral 12:a5d7db4a1e49 74 // set tx power to -8.1dBM
hemddabral 12:a5d7db4a1e49 75 EN_HIGH_POWER = 0;
hemddabral 12:a5d7db4a1e49 76 PA_LEVEL = 3;
hemddabral 12:a5d7db4a1e49 77 }
hemddabral 12:a5d7db4a1e49 78 else if((dbm>-8.1) && (dbm<=-5.1)) {
hemddabral 12:a5d7db4a1e49 79 // set tx power to -5.1dBM
hemddabral 12:a5d7db4a1e49 80 EN_HIGH_POWER = 1;
hemddabral 12:a5d7db4a1e49 81 PA_LEVEL = 3;
hemddabral 12:a5d7db4a1e49 82 }
hemddabral 12:a5d7db4a1e49 83 else if((dbm>-5.1) && (dbm<=-4.9)) {
hemddabral 12:a5d7db4a1e49 84 // set tx power to -4.9dBM
hemddabral 12:a5d7db4a1e49 85 EN_HIGH_POWER = 0;
hemddabral 12:a5d7db4a1e49 86 PA_LEVEL = 4;
hemddabral 12:a5d7db4a1e49 87 }
hemddabral 12:a5d7db4a1e49 88 else if((dbm>-4.9) && (dbm<=-2.1)) {
hemddabral 12:a5d7db4a1e49 89 // set tx power to -2.1dBM
hemddabral 12:a5d7db4a1e49 90 EN_HIGH_POWER = 1;
hemddabral 12:a5d7db4a1e49 91 PA_LEVEL = 4;
hemddabral 12:a5d7db4a1e49 92 }
hemddabral 12:a5d7db4a1e49 93 else if((dbm>-2.1) && (dbm<=-1.6)) {
hemddabral 12:a5d7db4a1e49 94 // set tx power to -1.6dBM
hemddabral 12:a5d7db4a1e49 95 EN_HIGH_POWER = 0;
hemddabral 12:a5d7db4a1e49 96 PA_LEVEL = 5;
hemddabral 12:a5d7db4a1e49 97 }
hemddabral 12:a5d7db4a1e49 98 else if((dbm>-1.6) && (dbm<=1.4)) {
hemddabral 12:a5d7db4a1e49 99 // set tx power to -1.6dBM
hemddabral 12:a5d7db4a1e49 100 EN_HIGH_POWER = 1;
hemddabral 12:a5d7db4a1e49 101 PA_LEVEL = 5;
hemddabral 12:a5d7db4a1e49 102 }
hemddabral 12:a5d7db4a1e49 103 else if((dbm>1.4) && (dbm<=1.7)) {
hemddabral 12:a5d7db4a1e49 104 // set tx power to 1.7dBM
hemddabral 12:a5d7db4a1e49 105 EN_HIGH_POWER = 0;
hemddabral 12:a5d7db4a1e49 106 PA_LEVEL = 6;
hemddabral 12:a5d7db4a1e49 107 }
hemddabral 12:a5d7db4a1e49 108 else if((dbm>1.7) && (dbm<=4.7)) {
hemddabral 12:a5d7db4a1e49 109 // set tx power to 4.7dBM
hemddabral 12:a5d7db4a1e49 110 EN_HIGH_POWER = 1;
hemddabral 12:a5d7db4a1e49 111 PA_LEVEL = 6;
hemddabral 12:a5d7db4a1e49 112 }
hemddabral 12:a5d7db4a1e49 113 else if((dbm>4.7) && (dbm<=5.0)) {
hemddabral 12:a5d7db4a1e49 114 // set tx power to 5.0dBM
hemddabral 12:a5d7db4a1e49 115 EN_HIGH_POWER = 0;
hemddabral 12:a5d7db4a1e49 116 PA_LEVEL = 7;
hemddabral 12:a5d7db4a1e49 117 }
hemddabral 12:a5d7db4a1e49 118 else if((dbm>5.0) && (dbm<=8)) {
hemddabral 12:a5d7db4a1e49 119 // set tx power to 8.0dBM
hemddabral 12:a5d7db4a1e49 120 EN_HIGH_POWER = 1;
hemddabral 12:a5d7db4a1e49 121 PA_LEVEL = 7;
hemddabral 12:a5d7db4a1e49 122 }
hemddabral 12:a5d7db4a1e49 123
hemddabral 12:a5d7db4a1e49 124 return dbm;
hemddabral 12:a5d7db4a1e49 125 }
hemddabral 12:a5d7db4a1e49 126