HW layer for the Nucleo board, it only work with old BLE_API
Dependents: Hello_BLE F446RE-BLE
Fork of X_NUCLEO_IDB0XA1 by
utils/src/Utils.cpp@16:8aeb0c44869b, 2014-08-07 (annotated)
- Committer:
- hemddabral
- Date:
- Thu Aug 07 09:33:27 2014 +0000
- Revision:
- 16:8aeb0c44869b
- Parent:
- 12:a5d7db4a1e49
- Child:
- 58:027c65a54097
changes done: (1) DEBUG macro moved to Utils (2) Advertising interval implementation done;
Who changed what in which revision?
User | Revision | Line number | New 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 | 16:8aeb0c44869b | 19 | #if NEED_CONSOLE_OUTPUT |
hemddabral | 16:8aeb0c44869b | 20 | Serial pc(USBTX, USBRX); |
hemddabral | 16:8aeb0c44869b | 21 | #endif /* #if NEED_CONSOLE_OUTPUT */ |
hemddabral | 16:8aeb0c44869b | 22 | |
hemddabral | 12:a5d7db4a1e49 | 23 | /**************************************************************************/ |
hemddabral | 12:a5d7db4a1e49 | 24 | /*! |
hemddabral | 12:a5d7db4a1e49 | 25 | @brief sets values of EN_HIGH_POWER and PA_LEVEL corresponding to dBMLevel of tx power |
hemddabral | 12:a5d7db4a1e49 | 26 | |
hemddabral | 12:a5d7db4a1e49 | 27 | @returns value of tx power in dbm actually set |
hemddabral | 12:a5d7db4a1e49 | 28 | |
hemddabral | 12:a5d7db4a1e49 | 29 | @params[in] dBMLevel |
hemddabral | 12:a5d7db4a1e49 | 30 | dBMLevel of tx power to be set |
hemddabral | 12:a5d7db4a1e49 | 31 | |
hemddabral | 12:a5d7db4a1e49 | 32 | @params[in] dBMLevel |
hemddabral | 12:a5d7db4a1e49 | 33 | dBMLevel of tx power to be set |
hemddabral | 12:a5d7db4a1e49 | 34 | |
hemddabral | 12:a5d7db4a1e49 | 35 | @endcode |
hemddabral | 12:a5d7db4a1e49 | 36 | */ |
hemddabral | 12:a5d7db4a1e49 | 37 | /**************************************************************************/ |
hemddabral | 12:a5d7db4a1e49 | 38 | double getHighPowerAndPALevelValue(int8_t dBMLevel, int8_t& EN_HIGH_POWER, int8_t& PA_LEVEL) { |
hemddabral | 12:a5d7db4a1e49 | 39 | double dbm = (double) dBMLevel; |
hemddabral | 12:a5d7db4a1e49 | 40 | if(dbm<-18.0) { |
hemddabral | 12:a5d7db4a1e49 | 41 | dbm = -18; |
hemddabral | 12:a5d7db4a1e49 | 42 | EN_HIGH_POWER = 0; |
hemddabral | 12:a5d7db4a1e49 | 43 | PA_LEVEL = 0; |
hemddabral | 12:a5d7db4a1e49 | 44 | } |
hemddabral | 12:a5d7db4a1e49 | 45 | else if(dbm>8.0) { |
hemddabral | 12:a5d7db4a1e49 | 46 | dbm = 8; |
hemddabral | 12:a5d7db4a1e49 | 47 | EN_HIGH_POWER = 1; |
hemddabral | 12:a5d7db4a1e49 | 48 | PA_LEVEL = 7; |
hemddabral | 12:a5d7db4a1e49 | 49 | } |
hemddabral | 12:a5d7db4a1e49 | 50 | |
hemddabral | 12:a5d7db4a1e49 | 51 | // As a policy we are setting tx power level to the higher side |
hemddabral | 12:a5d7db4a1e49 | 52 | if((dbm>-18.0) && (dbm<=-15)) { |
hemddabral | 12:a5d7db4a1e49 | 53 | // set tx power to -15dBM |
hemddabral | 12:a5d7db4a1e49 | 54 | EN_HIGH_POWER = 0; |
hemddabral | 12:a5d7db4a1e49 | 55 | PA_LEVEL = 0; |
hemddabral | 12:a5d7db4a1e49 | 56 | } |
hemddabral | 12:a5d7db4a1e49 | 57 | else if((dbm>-15) && (dbm<=-14.7)) { |
hemddabral | 12:a5d7db4a1e49 | 58 | // set tx power to -14.7dBM |
hemddabral | 12:a5d7db4a1e49 | 59 | EN_HIGH_POWER = 0; |
hemddabral | 12:a5d7db4a1e49 | 60 | PA_LEVEL = 1; |
hemddabral | 12:a5d7db4a1e49 | 61 | } |
hemddabral | 12:a5d7db4a1e49 | 62 | else if((dbm>-14.7) && (dbm<=-11.7)) { |
hemddabral | 12:a5d7db4a1e49 | 63 | // set tx power to -11.7dBM |
hemddabral | 12:a5d7db4a1e49 | 64 | EN_HIGH_POWER = 1; |
hemddabral | 12:a5d7db4a1e49 | 65 | PA_LEVEL = 1; |
hemddabral | 12:a5d7db4a1e49 | 66 | } |
hemddabral | 12:a5d7db4a1e49 | 67 | else if((dbm>-11.7) && (dbm<=-11.4)) { |
hemddabral | 12:a5d7db4a1e49 | 68 | // set tx power to -11.4dBM |
hemddabral | 12:a5d7db4a1e49 | 69 | EN_HIGH_POWER = 0; |
hemddabral | 12:a5d7db4a1e49 | 70 | PA_LEVEL = 2; |
hemddabral | 12:a5d7db4a1e49 | 71 | } |
hemddabral | 12:a5d7db4a1e49 | 72 | else if((dbm>-11.4) && (dbm<=-8.4)) { |
hemddabral | 12:a5d7db4a1e49 | 73 | // set tx power to -8.4dBM |
hemddabral | 12:a5d7db4a1e49 | 74 | EN_HIGH_POWER = 1; |
hemddabral | 12:a5d7db4a1e49 | 75 | PA_LEVEL = 2; |
hemddabral | 12:a5d7db4a1e49 | 76 | } |
hemddabral | 12:a5d7db4a1e49 | 77 | else if((dbm>-8.4) && (dbm<=-8.1)) { |
hemddabral | 12:a5d7db4a1e49 | 78 | // set tx power to -8.1dBM |
hemddabral | 12:a5d7db4a1e49 | 79 | EN_HIGH_POWER = 0; |
hemddabral | 12:a5d7db4a1e49 | 80 | PA_LEVEL = 3; |
hemddabral | 12:a5d7db4a1e49 | 81 | } |
hemddabral | 12:a5d7db4a1e49 | 82 | else if((dbm>-8.1) && (dbm<=-5.1)) { |
hemddabral | 12:a5d7db4a1e49 | 83 | // set tx power to -5.1dBM |
hemddabral | 12:a5d7db4a1e49 | 84 | EN_HIGH_POWER = 1; |
hemddabral | 12:a5d7db4a1e49 | 85 | PA_LEVEL = 3; |
hemddabral | 12:a5d7db4a1e49 | 86 | } |
hemddabral | 12:a5d7db4a1e49 | 87 | else if((dbm>-5.1) && (dbm<=-4.9)) { |
hemddabral | 12:a5d7db4a1e49 | 88 | // set tx power to -4.9dBM |
hemddabral | 12:a5d7db4a1e49 | 89 | EN_HIGH_POWER = 0; |
hemddabral | 12:a5d7db4a1e49 | 90 | PA_LEVEL = 4; |
hemddabral | 12:a5d7db4a1e49 | 91 | } |
hemddabral | 12:a5d7db4a1e49 | 92 | else if((dbm>-4.9) && (dbm<=-2.1)) { |
hemddabral | 12:a5d7db4a1e49 | 93 | // set tx power to -2.1dBM |
hemddabral | 12:a5d7db4a1e49 | 94 | EN_HIGH_POWER = 1; |
hemddabral | 12:a5d7db4a1e49 | 95 | PA_LEVEL = 4; |
hemddabral | 12:a5d7db4a1e49 | 96 | } |
hemddabral | 12:a5d7db4a1e49 | 97 | else if((dbm>-2.1) && (dbm<=-1.6)) { |
hemddabral | 12:a5d7db4a1e49 | 98 | // set tx power to -1.6dBM |
hemddabral | 12:a5d7db4a1e49 | 99 | EN_HIGH_POWER = 0; |
hemddabral | 12:a5d7db4a1e49 | 100 | PA_LEVEL = 5; |
hemddabral | 12:a5d7db4a1e49 | 101 | } |
hemddabral | 12:a5d7db4a1e49 | 102 | else if((dbm>-1.6) && (dbm<=1.4)) { |
hemddabral | 12:a5d7db4a1e49 | 103 | // set tx power to -1.6dBM |
hemddabral | 12:a5d7db4a1e49 | 104 | EN_HIGH_POWER = 1; |
hemddabral | 12:a5d7db4a1e49 | 105 | PA_LEVEL = 5; |
hemddabral | 12:a5d7db4a1e49 | 106 | } |
hemddabral | 12:a5d7db4a1e49 | 107 | else if((dbm>1.4) && (dbm<=1.7)) { |
hemddabral | 12:a5d7db4a1e49 | 108 | // set tx power to 1.7dBM |
hemddabral | 12:a5d7db4a1e49 | 109 | EN_HIGH_POWER = 0; |
hemddabral | 12:a5d7db4a1e49 | 110 | PA_LEVEL = 6; |
hemddabral | 12:a5d7db4a1e49 | 111 | } |
hemddabral | 12:a5d7db4a1e49 | 112 | else if((dbm>1.7) && (dbm<=4.7)) { |
hemddabral | 12:a5d7db4a1e49 | 113 | // set tx power to 4.7dBM |
hemddabral | 12:a5d7db4a1e49 | 114 | EN_HIGH_POWER = 1; |
hemddabral | 12:a5d7db4a1e49 | 115 | PA_LEVEL = 6; |
hemddabral | 12:a5d7db4a1e49 | 116 | } |
hemddabral | 12:a5d7db4a1e49 | 117 | else if((dbm>4.7) && (dbm<=5.0)) { |
hemddabral | 12:a5d7db4a1e49 | 118 | // set tx power to 5.0dBM |
hemddabral | 12:a5d7db4a1e49 | 119 | EN_HIGH_POWER = 0; |
hemddabral | 12:a5d7db4a1e49 | 120 | PA_LEVEL = 7; |
hemddabral | 12:a5d7db4a1e49 | 121 | } |
hemddabral | 12:a5d7db4a1e49 | 122 | else if((dbm>5.0) && (dbm<=8)) { |
hemddabral | 12:a5d7db4a1e49 | 123 | // set tx power to 8.0dBM |
hemddabral | 12:a5d7db4a1e49 | 124 | EN_HIGH_POWER = 1; |
hemddabral | 12:a5d7db4a1e49 | 125 | PA_LEVEL = 7; |
hemddabral | 12:a5d7db4a1e49 | 126 | } |
hemddabral | 12:a5d7db4a1e49 | 127 | |
hemddabral | 12:a5d7db4a1e49 | 128 | return dbm; |
hemddabral | 12:a5d7db4a1e49 | 129 | } |
hemddabral | 12:a5d7db4a1e49 | 130 |