test

Dependents:   BLE_HeartRate_IDB0XA1_EPUDEE_Avril2018

Fork of X_NUCLEO_IDB0XA1 by ST

Committer:
Wolfgang Betz
Date:
Tue Oct 06 14:25:08 2015 +0200
Revision:
130:770ce14d3d15
Include mbed-classic version

Derived from
- repo (on Codex): gitolite@codex.cro.st.com:x-nucleodev/X-NUCLEO-IKC01A1-MBED.git
- branch: ble_wb
- SHA1 ID: 5ccc73e35868169e42132c0d1c056f908a6d70c0

Who changed what in which revision?

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