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@58:027c65a54097, 2014-10-07 (annotated)
- Committer:
- hemddabral
- Date:
- Tue Oct 07 10:13:02 2014 +0000
- Revision:
- 58:027c65a54097
- Parent:
- 16:8aeb0c44869b
code cleanup and indentation.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hemddabral | 12:a5d7db4a1e49 | 1 | /* mbed Microcontroller Library |
hemddabral | 58:027c65a54097 | 2 | * Copyright (c) 2006-2013 ARM Limited |
hemddabral | 58:027c65a54097 | 3 | * |
hemddabral | 58:027c65a54097 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
hemddabral | 58:027c65a54097 | 5 | * you may not use this file except in compliance with the License. |
hemddabral | 58:027c65a54097 | 6 | * You may obtain a copy of the License at |
hemddabral | 58:027c65a54097 | 7 | * |
hemddabral | 58:027c65a54097 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
hemddabral | 58:027c65a54097 | 9 | * |
hemddabral | 58:027c65a54097 | 10 | * Unless required by applicable law or agreed to in writing, software |
hemddabral | 58:027c65a54097 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
hemddabral | 58:027c65a54097 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
hemddabral | 58:027c65a54097 | 13 | * See the License for the specific language governing permissions and |
hemddabral | 58:027c65a54097 | 14 | * limitations under the License. |
hemddabral | 58:027c65a54097 | 15 | */ |
hemddabral | 58:027c65a54097 | 16 | |
hemddabral | 58:027c65a54097 | 17 | #include "Utils.h" |
hemddabral | 58:027c65a54097 | 18 | |
hemddabral | 58:027c65a54097 | 19 | #if NEED_CONSOLE_OUTPUT |
hemddabral | 16:8aeb0c44869b | 20 | Serial pc(USBTX, USBRX); |
hemddabral | 16:8aeb0c44869b | 21 | #endif /* #if NEED_CONSOLE_OUTPUT */ |
hemddabral | 58:027c65a54097 | 22 | |
hemddabral | 58:027c65a54097 | 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 | 58:027c65a54097 | 38 | double getHighPowerAndPALevelValue(int8_t dBMLevel, int8_t& EN_HIGH_POWER, int8_t& PA_LEVEL) { |
hemddabral | 58:027c65a54097 | 39 | double dbm = (double) dBMLevel; |
hemddabral | 58:027c65a54097 | 40 | if(dbm<-18.0) { |
hemddabral | 58:027c65a54097 | 41 | dbm = -18; |
hemddabral | 58:027c65a54097 | 42 | EN_HIGH_POWER = 0; |
hemddabral | 58:027c65a54097 | 43 | PA_LEVEL = 0; |
hemddabral | 58:027c65a54097 | 44 | } |
hemddabral | 58:027c65a54097 | 45 | else if(dbm>8.0) { |
hemddabral | 58:027c65a54097 | 46 | dbm = 8; |
hemddabral | 58:027c65a54097 | 47 | EN_HIGH_POWER = 1; |
hemddabral | 58:027c65a54097 | 48 | PA_LEVEL = 7; |
hemddabral | 58:027c65a54097 | 49 | } |
hemddabral | 58:027c65a54097 | 50 | |
hemddabral | 58:027c65a54097 | 51 | // As a policy we are setting tx power level to the higher side |
hemddabral | 58:027c65a54097 | 52 | if((dbm>-18.0) && (dbm<=-15)) { |
hemddabral | 58:027c65a54097 | 53 | // set tx power to -15dBM |
hemddabral | 58:027c65a54097 | 54 | EN_HIGH_POWER = 0; |
hemddabral | 58:027c65a54097 | 55 | PA_LEVEL = 0; |
hemddabral | 58:027c65a54097 | 56 | } |
hemddabral | 58:027c65a54097 | 57 | else if((dbm>-15) && (dbm<=-14.7)) { |
hemddabral | 58:027c65a54097 | 58 | // set tx power to -14.7dBM |
hemddabral | 58:027c65a54097 | 59 | EN_HIGH_POWER = 0; |
hemddabral | 58:027c65a54097 | 60 | PA_LEVEL = 1; |
hemddabral | 58:027c65a54097 | 61 | } |
hemddabral | 58:027c65a54097 | 62 | else if((dbm>-14.7) && (dbm<=-11.7)) { |
hemddabral | 58:027c65a54097 | 63 | // set tx power to -11.7dBM |
hemddabral | 58:027c65a54097 | 64 | EN_HIGH_POWER = 1; |
hemddabral | 58:027c65a54097 | 65 | PA_LEVEL = 1; |
hemddabral | 58:027c65a54097 | 66 | } |
hemddabral | 58:027c65a54097 | 67 | else if((dbm>-11.7) && (dbm<=-11.4)) { |
hemddabral | 58:027c65a54097 | 68 | // set tx power to -11.4dBM |
hemddabral | 58:027c65a54097 | 69 | EN_HIGH_POWER = 0; |
hemddabral | 58:027c65a54097 | 70 | PA_LEVEL = 2; |
hemddabral | 58:027c65a54097 | 71 | } |
hemddabral | 58:027c65a54097 | 72 | else if((dbm>-11.4) && (dbm<=-8.4)) { |
hemddabral | 58:027c65a54097 | 73 | // set tx power to -8.4dBM |
hemddabral | 58:027c65a54097 | 74 | EN_HIGH_POWER = 1; |
hemddabral | 58:027c65a54097 | 75 | PA_LEVEL = 2; |
hemddabral | 58:027c65a54097 | 76 | } |
hemddabral | 58:027c65a54097 | 77 | else if((dbm>-8.4) && (dbm<=-8.1)) { |
hemddabral | 58:027c65a54097 | 78 | // set tx power to -8.1dBM |
hemddabral | 58:027c65a54097 | 79 | EN_HIGH_POWER = 0; |
hemddabral | 58:027c65a54097 | 80 | PA_LEVEL = 3; |
hemddabral | 58:027c65a54097 | 81 | } |
hemddabral | 58:027c65a54097 | 82 | else if((dbm>-8.1) && (dbm<=-5.1)) { |
hemddabral | 58:027c65a54097 | 83 | // set tx power to -5.1dBM |
hemddabral | 58:027c65a54097 | 84 | EN_HIGH_POWER = 1; |
hemddabral | 58:027c65a54097 | 85 | PA_LEVEL = 3; |
hemddabral | 58:027c65a54097 | 86 | } |
hemddabral | 58:027c65a54097 | 87 | else if((dbm>-5.1) && (dbm<=-4.9)) { |
hemddabral | 58:027c65a54097 | 88 | // set tx power to -4.9dBM |
hemddabral | 58:027c65a54097 | 89 | EN_HIGH_POWER = 0; |
hemddabral | 58:027c65a54097 | 90 | PA_LEVEL = 4; |
hemddabral | 58:027c65a54097 | 91 | } |
hemddabral | 58:027c65a54097 | 92 | else if((dbm>-4.9) && (dbm<=-2.1)) { |
hemddabral | 58:027c65a54097 | 93 | // set tx power to -2.1dBM |
hemddabral | 58:027c65a54097 | 94 | EN_HIGH_POWER = 1; |
hemddabral | 58:027c65a54097 | 95 | PA_LEVEL = 4; |
hemddabral | 58:027c65a54097 | 96 | } |
hemddabral | 58:027c65a54097 | 97 | else if((dbm>-2.1) && (dbm<=-1.6)) { |
hemddabral | 58:027c65a54097 | 98 | // set tx power to -1.6dBM |
hemddabral | 58:027c65a54097 | 99 | EN_HIGH_POWER = 0; |
hemddabral | 58:027c65a54097 | 100 | PA_LEVEL = 5; |
hemddabral | 58:027c65a54097 | 101 | } |
hemddabral | 58:027c65a54097 | 102 | else if((dbm>-1.6) && (dbm<=1.4)) { |
hemddabral | 58:027c65a54097 | 103 | // set tx power to -1.6dBM |
hemddabral | 58:027c65a54097 | 104 | EN_HIGH_POWER = 1; |
hemddabral | 58:027c65a54097 | 105 | PA_LEVEL = 5; |
hemddabral | 58:027c65a54097 | 106 | } |
hemddabral | 58:027c65a54097 | 107 | else if((dbm>1.4) && (dbm<=1.7)) { |
hemddabral | 58:027c65a54097 | 108 | // set tx power to 1.7dBM |
hemddabral | 58:027c65a54097 | 109 | EN_HIGH_POWER = 0; |
hemddabral | 58:027c65a54097 | 110 | PA_LEVEL = 6; |
hemddabral | 58:027c65a54097 | 111 | } |
hemddabral | 58:027c65a54097 | 112 | else if((dbm>1.7) && (dbm<=4.7)) { |
hemddabral | 58:027c65a54097 | 113 | // set tx power to 4.7dBM |
hemddabral | 58:027c65a54097 | 114 | EN_HIGH_POWER = 1; |
hemddabral | 58:027c65a54097 | 115 | PA_LEVEL = 6; |
hemddabral | 58:027c65a54097 | 116 | } |
hemddabral | 58:027c65a54097 | 117 | else if((dbm>4.7) && (dbm<=5.0)) { |
hemddabral | 58:027c65a54097 | 118 | // set tx power to 5.0dBM |
hemddabral | 58:027c65a54097 | 119 | EN_HIGH_POWER = 0; |
hemddabral | 58:027c65a54097 | 120 | PA_LEVEL = 7; |
hemddabral | 58:027c65a54097 | 121 | } |
hemddabral | 58:027c65a54097 | 122 | else if((dbm>5.0) && (dbm<=8)) { |
hemddabral | 58:027c65a54097 | 123 | // set tx power to 8.0dBM |
hemddabral | 58:027c65a54097 | 124 | EN_HIGH_POWER = 1; |
hemddabral | 58:027c65a54097 | 125 | PA_LEVEL = 7; |
hemddabral | 58:027c65a54097 | 126 | } |
hemddabral | 58:027c65a54097 | 127 | |
hemddabral | 12:a5d7db4a1e49 | 128 | return dbm; |
hemddabral | 12:a5d7db4a1e49 | 129 | } |