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.
rf_driver_storage.c
00001 /* 00002 * Copyright (c) 2016-2017, 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 #include "nsconfig.h" 00019 #include "string.h" 00020 #include "ns_types.h" 00021 #include "common_functions.h" 00022 #include "nsdynmemLIB.h" 00023 #include "MAC/rf_driver_storage.h" 00024 00025 static arm_device_driver_list_s *dev_driver_dynamically_allocate(void); 00026 static int8_t dev_driver_get_free_id(void); 00027 00028 static NS_LIST_DEFINE(arm_device_driver_list, arm_device_driver_list_s, link); 00029 00030 arm_device_driver_list_s *arm_net_phy_driver_pointer(int8_t id) 00031 { 00032 ns_list_foreach(arm_device_driver_list_s, cur, &arm_device_driver_list) { 00033 if (cur->id == id) { 00034 return cur; 00035 } 00036 } 00037 00038 return NULL; 00039 } 00040 00041 static arm_device_driver_list_s *dev_driver_dynamically_allocate(void) 00042 { 00043 arm_device_driver_list_s *event = 0; 00044 event = ns_dyn_mem_alloc(sizeof(arm_device_driver_list_s)); 00045 if (event) { 00046 event->phy_sap_identifier = NULL; 00047 event->phy_sap_upper_cb = NULL; 00048 event->mlme_observer_cb = NULL; 00049 ns_list_link_init(event, link); 00050 } 00051 return event; 00052 } 00053 00054 static int8_t dev_driver_get_free_id(void) 00055 { 00056 uint_fast8_t id; // Must be unsigned for loop test to work... 00057 00058 for (id = 0; id <= INT8_MAX; id++) { 00059 if (!arm_net_phy_driver_pointer(id)) { 00060 return id; 00061 } 00062 } 00063 00064 return -1; 00065 } 00066 00067 int8_t arm_net_phy_register(phy_device_driver_s *phy_driver) 00068 { 00069 arm_device_driver_list_s *new; 00070 if(!phy_driver) { 00071 return -1; 00072 } 00073 00074 ns_list_foreach(arm_device_driver_list_s, cur, &arm_device_driver_list) { 00075 if (cur->phy_driver == phy_driver) { 00076 return -1; 00077 } 00078 } 00079 /* Validate That Channel page is defined for RF driver */ 00080 if (phy_driver->link_type == PHY_LINK_15_4_2_4GHZ_TYPE || phy_driver->link_type == PHY_LINK_15_4_SUBGHZ_TYPE) { 00081 if (!phy_driver->phy_channel_pages || !phy_driver->phy_channel_pages->rf_channel_configuration) { 00082 return -1; 00083 } 00084 } 00085 00086 00087 //Allocate new 00088 new = dev_driver_dynamically_allocate(); 00089 if (!new) { 00090 return -2; 00091 } 00092 00093 new->id = dev_driver_get_free_id(); 00094 new->phy_driver = phy_driver; 00095 if (new->phy_driver->state_control) { 00096 new->phy_driver->state_control(PHY_INTERFACE_RESET, 0); 00097 } 00098 ns_list_add_to_end(&arm_device_driver_list, new); 00099 00100 return new->id; 00101 } 00102 00103 int8_t arm_net_phy_mac64_set(uint8_t *MAC, int8_t id) 00104 { 00105 arm_device_driver_list_s *driver = arm_net_phy_driver_pointer(id); 00106 if (!driver || !driver->phy_driver->PHY_MAC || !MAC) { 00107 return -1; 00108 } 00109 00110 memcpy(driver->phy_driver->PHY_MAC, MAC, 8); 00111 return 0; 00112 } 00113 00114 uint8_t *arm_net_phy_mac64_get(int8_t id) 00115 { 00116 arm_device_driver_list_s *driver = arm_net_phy_driver_pointer(id); 00117 if (!driver ) { 00118 return NULL; 00119 } 00120 return driver->phy_driver->PHY_MAC; 00121 } 00122 00123 int arm_net_phy_rf_type(int8_t id) 00124 { 00125 arm_device_driver_list_s *driver = arm_net_phy_driver_pointer(id); 00126 if (!driver ) { 00127 return -1; 00128 } 00129 return driver->phy_driver->link_type; 00130 } 00131 00132 uint16_t arm_net_phy_mtu_size(int8_t id) 00133 { 00134 arm_device_driver_list_s *driver = arm_net_phy_driver_pointer(id); 00135 if (!driver ) { 00136 return 0; 00137 } 00138 return driver->phy_driver->phy_MTU; 00139 } 00140 00141 void arm_net_phy_unregister(int8_t driver_id) 00142 { 00143 ns_list_foreach_safe(arm_device_driver_list_s, cur, &arm_device_driver_list){ 00144 if (cur->id == driver_id) { 00145 ns_list_remove(&arm_device_driver_list, cur); 00146 ns_dyn_mem_free(cur); 00147 cur = NULL; 00148 } 00149 } 00150 } 00151 00152 int8_t arm_net_phy_init(phy_device_driver_s *phy_driver, arm_net_phy_rx_fn *rx_cb, arm_net_phy_tx_done_fn *done_cb) 00153 { 00154 if(!phy_driver){ 00155 return -1; 00156 } 00157 phy_driver->phy_rx_cb = rx_cb; 00158 phy_driver->phy_tx_done_cb = done_cb; 00159 return 0; 00160 } 00161 00162 void arm_net_observer_cb_set(int8_t id, internal_mib_observer *observer_cb) 00163 { 00164 arm_device_driver_list_s *driver = arm_net_phy_driver_pointer(id); 00165 if (!driver ) { 00166 return; 00167 } 00168 driver->mlme_observer_cb = observer_cb; 00169 } 00170 00171 void arm_net_virtual_config_rx_cb_set(phy_device_driver_s *phy_driver, arm_net_virtual_config_rx_fn *virtual_config_rx) 00172 { 00173 if(!phy_driver){ 00174 return; 00175 } 00176 phy_driver->virtual_config_rx_cb = virtual_config_rx; 00177 } 00178 00179 void arm_net_virtual_confirmation_rx_cb_set(phy_device_driver_s *phy_driver, arm_net_virtual_confirmation_rx_fn *virtual_confirmation_rx) 00180 { 00181 if(!phy_driver){ 00182 return; 00183 } 00184 phy_driver->virtual_confirmation_rx_cb = virtual_confirmation_rx; 00185 } 00186 00187 uint32_t dev_get_phy_datarate(phy_device_driver_s *phy_driver, channel_page_e channel_page) 00188 { 00189 uint32_t retval = 0; 00190 const phy_device_channel_page_s *phy_ch_pages = phy_driver->phy_channel_pages; 00191 while(1) 00192 { 00193 if(phy_ch_pages->rf_channel_configuration == NULL) 00194 break; 00195 00196 if(phy_ch_pages->channel_page == channel_page) 00197 { 00198 retval = phy_ch_pages->rf_channel_configuration->datarate; 00199 break; 00200 } 00201 phy_ch_pages++; 00202 } 00203 return retval; 00204 }
Generated on Tue Jul 12 2022 12:22:18 by
