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.
Fork of OmniWheels by
fnet_poll.c
00001 /************************************************************************** 00002 * Copyright (c) 2017, Arm Limited and affiliates. 00003 * Copyright 2011-2016 by Andrey Butok. FNET Community. 00004 * Copyright 2008-2010 by Andrey Butok. Freescale Semiconductor, Inc. 00005 * 00006 *************************************************************************** 00007 * 00008 * Licensed under the Apache License, Version 2.0 (the "License"); you may 00009 * not use this file except in compliance with the License. 00010 * You may obtain a copy of the License at 00011 * 00012 * http://www.apache.org/licenses/LICENSE-2.0 00013 * 00014 * Unless required by applicable law or agreed to in writing, software 00015 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 00016 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00017 * See the License for the specific language governing permissions and 00018 * limitations under the License. 00019 * 00020 **********************************************************************/ 00021 /*! 00022 * @brief FNET Services polling mechanism implementation. 00023 * 00024 ***************************************************************************/ 00025 00026 #include "fnet.h" 00027 00028 /************************************************************************ 00029 * Definitions 00030 *************************************************************************/ 00031 00032 /* Polling list element type definition */ 00033 00034 typedef struct 00035 { 00036 fnet_poll_service_t service; 00037 void *service_param; 00038 } fnet_poll_list_entry_t; 00039 00040 /* Polling interface structure */ 00041 static struct 00042 { 00043 fnet_poll_list_entry_t list[FNET_CFG_POLL_MAX]; /* Polling list.*/ 00044 fnet_poll_desc_t last; /* Index of the last valid entry plus 1, in the polling list.*/ 00045 } fnet_poll_if; 00046 00047 /************************************************************************ 00048 * DESCRIPTION: This function calls all registered service routines in 00049 * the polling list. 00050 *************************************************************************/ 00051 void fnet_poll_service( void ) 00052 { 00053 fnet_poll_desc_t i; 00054 00055 for (i = 0u; i < fnet_poll_if.last; i++) 00056 { 00057 if(fnet_poll_if.list[i].service) 00058 { 00059 fnet_poll_if.list[i].service(fnet_poll_if.list[i].service_param); 00060 } 00061 } 00062 } 00063 00064 /************************************************************************ 00065 * DESCRIPTION: This function calls all registered service routines in 00066 * the polling list. 00067 *************************************************************************/ 00068 void fnet_poll_service_release( void ) 00069 { 00070 fnet_memset_zero(&fnet_poll_if, sizeof(fnet_poll_if)); 00071 } 00072 00073 /************************************************************************ 00074 * DESCRIPTION: This function adds service routine into the polling list. 00075 *************************************************************************/ 00076 fnet_poll_desc_t fnet_poll_service_register( fnet_poll_service_t service, void *service_param ) 00077 { 00078 fnet_index_t i = 0u; 00079 fnet_poll_list_entry_t *poll_entry = 0; 00080 00081 if(service) 00082 { 00083 while((i < FNET_CFG_POLL_MAX) && (fnet_poll_if.list[i].service)) 00084 { 00085 i++; 00086 } 00087 00088 if(i != FNET_CFG_POLL_MAX) 00089 { 00090 fnet_poll_if.list[i].service = service; 00091 fnet_poll_if.list[i].service_param = service_param; 00092 poll_entry = &fnet_poll_if.list[i]; 00093 00094 if(i >= fnet_poll_if.last) 00095 { 00096 fnet_poll_if.last = i + 1u; 00097 } 00098 } 00099 } 00100 00101 return (fnet_poll_desc_t)(uintptr_t)poll_entry; 00102 } 00103 00104 /************************************************************************ 00105 * DESCRIPTION: This function removes service routine from the polling list. 00106 *************************************************************************/ 00107 void fnet_poll_service_unregister( fnet_poll_desc_t desc ) 00108 { 00109 fnet_poll_list_entry_t *poll_entry = (fnet_poll_list_entry_t *)(uintptr_t)desc; 00110 00111 if(poll_entry) 00112 { 00113 poll_entry->service = 0; 00114 } 00115 }
Generated on Fri Jul 22 2022 04:53:49 by
1.7.2
