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:
leonardoaraujosantos
Date:
Tue Nov 03 23:10:27 2015 +0000
Revision:
129:57997390c086
Parent:
70:d20d30f59b1c
Changing pin D13

Who changed what in which revision?

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