Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
channel_list.c
00001 /* 00002 * Copyright (c) 2015-2018, Arm Limited and affiliates. 00003 * SPDX-License-Identifier: Apache-2.0 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 00018 00019 #include "nsconfig.h" 00020 #include "Service_Libs/fhss/channel_list.h" 00021 00022 #include "common_functions.h" 00023 #include "ns_trace.h" 00024 00025 #include <stdint.h> 00026 #include <string.h> 00027 00028 const int CHANNEL_LIST_SIZE_IN_BITS = 8*32; 00029 00030 static bool channel_list_bit_test32(uint32_t word, int_fast8_t bit_number); 00031 static bool channel_list_bit_test(const uint32_t* list, int bit_number); 00032 00033 // test bit by number 00034 static bool channel_list_bit_test32(uint32_t word, int_fast8_t bit_number) 00035 { 00036 bool bitSet; 00037 00038 if (word & ((uint32_t) 1 << bit_number)) { 00039 bitSet = true; 00040 } else { 00041 bitSet = false; 00042 } 00043 return bitSet; 00044 } 00045 00046 static bool channel_list_bit_test(const uint32_t* list, int bit_number) 00047 { 00048 const int_fast8_t word_index = bit_number / 32; 00049 const int_fast8_t bit_index = bit_number % 32; 00050 00051 return channel_list_bit_test32(list[word_index], bit_index); 00052 } 00053 00054 static uint8_t channel_list_search(const uint32_t* list, int index) 00055 { 00056 uint8_t channel = 0; 00057 int enabled_channels = 0; 00058 int i, j; 00059 00060 for(j=0; j<8; j++) 00061 { 00062 for(i=0; i<32; i++) 00063 { 00064 if (list[j] & ((uint32_t)1 << i)) { 00065 enabled_channels++; 00066 if (enabled_channels == (index + 1)) { 00067 goto exit; 00068 } 00069 } 00070 channel++; 00071 } 00072 } 00073 exit: 00074 return channel; 00075 00076 } 00077 00078 uint8_t channel_list_get_channel(const uint32_t* list, int current_index) 00079 { 00080 uint8_t found_index; 00081 00082 if (current_index >= CHANNEL_LIST_SIZE_IN_BITS) { 00083 current_index = 0; 00084 } 00085 00086 found_index = channel_list_search(list, current_index); 00087 00088 return found_index; 00089 } 00090 00091 // count the amount of channels enabled in a list 00092 int channel_list_count_channels(const uint32_t* list) 00093 { 00094 00095 int channel_count = 0; 00096 00097 for (int index=0; index < CHANNEL_LIST_SIZE_IN_BITS; index++) { 00098 00099 if (channel_list_bit_test(list, index)) { 00100 channel_count++; 00101 } 00102 } 00103 00104 return channel_count; 00105 }
Generated on Tue Aug 9 2022 00:37:04 by
1.7.2