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_cpu.h
00001 /************************************************************************** 00002 * 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 CPU-specific library API. 00023 * 00024 ***************************************************************************/ 00025 00026 #ifndef _FNET_CPU_H_ 00027 00028 #define _FNET_CPU_H_ 00029 00030 #include "fnet_config.h" 00031 00032 #if FNET_MCF /* ColdFire.*/ 00033 #include "mcf/fnet_mcf.h" 00034 #endif 00035 00036 #if FNET_MK /* Kinetis.*/ 00037 #include "mk/fnet_mk.h" 00038 #endif 00039 00040 #if FNET_MPC /* MPC.*/ 00041 #include "mpc/fnet_mpc.h" 00042 #endif 00043 00044 #if FNET_LPC /* NXP's LPC.*/ 00045 #include "lpc/fnet_lpc.h" 00046 #endif 00047 00048 #include "stack/fnet_stdlib.h" 00049 00050 /*! @addtogroup fnet_socket */ 00051 /*! @{ */ 00052 00053 #if defined(__cplusplus) 00054 extern "C" { 00055 #endif 00056 00057 /************************************************************************ 00058 * For doing byte order conversions between CPU 00059 * and the independent "network" order. 00060 * For Freescale CPUs they just return the variable passed. 00061 *************************************************************************/ 00062 00063 #if FNET_CFG_CPU_LITTLE_ENDIAN /* Little endian.*/ || defined(__DOXYGEN__) 00064 00065 /**************************************************************************/ /*! 00066 * @def FNET_HTONS 00067 * @param short_var A 16-bit number in host byte order. 00068 * @hideinitializer 00069 * @see FNET_NTOHS(), FNET_HTONL(), FNET_NTOHL(), fnet_htons(), fnet_ntohs(), fnet_htonl(), fnet_ntohl() 00070 * @brief Macros which converts the unsigned short integer from host byte order to 00071 * network byte order. 00072 ******************************************************************************/ 00073 #define FNET_HTONS(short_var) ((((short_var) & 0x00FFU) << 8U) | (((short_var) & 0xFF00U) >> 8U)) 00074 /**************************************************************************/ /*! 00075 * @def FNET_NTOHS 00076 * @param short_var A 16-bit number in network byte order. 00077 * @hideinitializer 00078 * @see FNET_HTONS(), FNET_HTONL(), FNET_NTOHL(), fnet_htons(), fnet_ntohs(), fnet_htonl(), fnet_ntohl() 00079 * @brief Macros which converts the unsigned 16-bit integer from network byte order to 00080 * host byte order. 00081 ******************************************************************************/ 00082 #define FNET_NTOHS(short_var) FNET_HTONS(short_var) 00083 /**************************************************************************/ /*! 00084 * @def FNET_HTONL 00085 * @param long_var A 32-bit number in host byte order. 00086 * @hideinitializer 00087 * @see FNET_HTONS(), FNET_NTOHS(), FNET_NTOHL(), fnet_htons(), fnet_ntohs(), fnet_htonl(), fnet_ntohl() 00088 * @brief Macros which converts the unsigned long integer from host byte order to 00089 * network byte order. 00090 ******************************************************************************/ 00091 #define FNET_HTONL(long_var) ((((long_var) & 0x000000FFU) << 24U) | (((long_var) & 0x0000FF00U) << 8U) | (((long_var) & 0x00FF0000U) >> 8U) | (((long_var) & 0xFF000000U) >> 24U)) 00092 /**************************************************************************/ /*! 00093 * @def FNET_NTOHL 00094 * @param long_var A 32-bit number in network byte order. 00095 * @hideinitializer 00096 * @see FNET_HTONS(), FNET_NTOHS(), FNET_HTONL(), fnet_htons(), fnet_ntohs(), fnet_htonl(), fnet_ntohl() 00097 * @brief Macros which converts the unsigned long integer from network byte order to 00098 * host byte order. 00099 ******************************************************************************/ 00100 #define FNET_NTOHL(long_var) FNET_HTONL(long_var) 00101 00102 /***************************************************************************/ /*! 00103 * 00104 * @brief Converts 16-bit value from host to network byte order. 00105 * 00106 * 00107 * @param short_var A 16-bit number in host byte order. 00108 * 00109 * 00110 * @return This function returns the network byte-ordered @c short_var. 00111 * 00112 * @see FNET_HTONS(), FNET_NTOHS(), FNET_HTONL(), FNET_NTOHL(), fnet_ntohs(), fnet_htonl(), fnet_ntohl() 00113 * 00114 ****************************************************************************** 00115 * 00116 * The function converts the unsigned 16-bit integer from host byte order to 00117 * network byte order. 00118 * 00119 ******************************************************************************/ 00120 fnet_uint16_t fnet_htons(fnet_uint16_t short_var); 00121 00122 #define fnet_ntohs fnet_htons 00123 /***************************************************************************/ /*! 00124 * 00125 * @brief Converts 16-bit value from network to host byte order. 00126 * 00127 * 00128 * @param short_var A 16-bit number in network byte order. 00129 * 00130 * 00131 * @return This function returns the host byte-ordered @c short_var. 00132 * 00133 * @see FNET_HTONS(), FNET_NTOHS(), FNET_HTONL(), FNET_NTOHL(), fnet_htons(), fnet_htonl(), fnet_ntohl() 00134 * 00135 ****************************************************************************** 00136 * 00137 * The function converts the unsigned 16-bit integer from network byte order to 00138 * host byte order. 00139 * 00140 ******************************************************************************/ 00141 fnet_uint16_t fnet_ntohs(fnet_uint16_t short_var); 00142 00143 /***************************************************************************/ /*! 00144 * 00145 * @brief Converts 32-bit value from host to network byte order. 00146 * 00147 * 00148 * @param long_var A 32-bit number in host byte order. 00149 * 00150 * 00151 * @return This function returns the network byte-ordered @c long_var. 00152 * 00153 * @see FNET_HTONS(), FNET_NTOHS(), FNET_HTONL(), FNET_NTOHL(), fnet_ntohs(), fnet_htons(), fnet_ntohl() 00154 * 00155 ****************************************************************************** 00156 * 00157 * The function converts the unsigned long integer from host byte order to 00158 * network byte order. 00159 * 00160 ******************************************************************************/ 00161 fnet_uint32_t fnet_htonl(fnet_uint32_t long_var); 00162 00163 #define fnet_ntohl fnet_htonl 00164 /***************************************************************************/ /*! 00165 * 00166 * @brief Converts 32-bit value from network to host byte order. 00167 * 00168 * 00169 * @param long_var A 32-bit number in network byte order. 00170 * 00171 * 00172 * @return This function returns the host byte-ordered @c long_var. 00173 * 00174 * @see FNET_HTONS(), FNET_NTOHS(), FNET_HTONL(), FNET_NTOHL(), fnet_htons(), fnet_ntohs(), fnet_htonl() 00175 * 00176 ****************************************************************************** 00177 * 00178 * The function converts the unsigned long integer from network byte order to 00179 * host byte order. 00180 * 00181 ******************************************************************************/ 00182 fnet_uint32_t fnet_ntohl(fnet_uint32_t long_var); 00183 00184 00185 #else /* Big endian. */ 00186 #define FNET_HTONS(short_var) (short_var) 00187 #define FNET_NTOHS(short_var) (short_var) 00188 #define FNET_HTONL(long_var) (long_var) 00189 #define FNET_NTOHL(long_var) (long_var) 00190 00191 #define fnet_htons(short_var) (short_var) /* Convert 16 bit integer from host- to network byte order.*/ 00192 #define fnet_ntohs(short_var) (short_var) /* Convert 16 bit integer from network - to host byte order.*/ 00193 #define fnet_htonl(long_var) (long_var) /* Convert 32 bit integer from host- to network byte order.*/ 00194 #define fnet_ntohl(long_var) (long_var) /* Convert 32 bit integer from network - to host byte order.*/ 00195 #endif 00196 00197 /*! @} */ 00198 00199 /*! @addtogroup fnet_cpu 00200 * The CPU-specific library provides commonly used platform dependent functions. 00201 * Most of these functions are not used by the FNET, but can be useful for 00202 * an application. 00203 */ 00204 /*! @{ */ 00205 00206 /**************************************************************************/ /*! 00207 * @brief IRQ status descriptor returned by the @ref fnet_cpu_irq_disable() function. 00208 * Actually it corresponds to the interrupt level mask value. 00209 * @see fnet_cpu_irq_disable(), fnet_cpu_irq_enable() 00210 ******************************************************************************/ 00211 typedef fnet_uint32_t fnet_cpu_irq_desc_t; 00212 00213 /***************************************************************************/ /*! 00214 * 00215 * @brief Initiates software reset. 00216 * 00217 ****************************************************************************** 00218 * 00219 * This function performs software reset and asserts the external reset 00220 * (RSTO) pin. 00221 * 00222 ******************************************************************************/ 00223 void fnet_cpu_reset (void); 00224 00225 /***************************************************************************/ /*! 00226 * 00227 * @brief Disables all interrupts. 00228 * 00229 * @return This function returns the current IRQ status defined 00230 * by @ref fnet_cpu_irq_desc_t. 00231 * 00232 * @see fnet_cpu_irq_enable() 00233 * 00234 ****************************************************************************** 00235 * 00236 * This function disables all interrupts. @n 00237 * The interrupts can be enabled again by the @ref fnet_cpu_irq_enable() function. 00238 * 00239 ******************************************************************************/ 00240 fnet_cpu_irq_desc_t fnet_cpu_irq_disable(void); 00241 00242 /***************************************************************************/ /*! 00243 * 00244 * @brief Enables interrupts. 00245 * 00246 * @param irq_desc IRQ status descriptor returned by the 00247 * @ref fnet_cpu_irq_disable() function.@n 00248 * Pass @c 0 value to enable all interrupts. 00249 * 00250 * @see fnet_cpu_irq_disable() 00251 * 00252 ****************************************************************************** 00253 * 00254 * This function enables interrupts that were disabled by the 00255 * @ref fnet_cpu_irq_disable function. @n 00256 * The functions can enable all interrupts by passing into it the @c 0 value. 00257 * 00258 ******************************************************************************/ 00259 void fnet_cpu_irq_enable(fnet_cpu_irq_desc_t irq_desc); 00260 00261 /***************************************************************************/ /*! 00262 * 00263 * @brief Writes character to the serial port. 00264 * 00265 * @param port_number Serial port number. 00266 * 00267 * @param character Character to be written to the serial port. 00268 * 00269 * @see fnet_cpu_serial_getchar(), fnet_cpu_serial_init() 00270 * 00271 ****************************************************************************** 00272 * 00273 * This function writes @c character to the serial port defined 00274 * by @c port_number. @n 00275 * 00276 ******************************************************************************/ 00277 void fnet_cpu_serial_putchar( fnet_index_t port_number, fnet_char_t character ); 00278 00279 /***************************************************************************/ /*! 00280 * 00281 * @brief Reads character from the serial port. 00282 * 00283 * @param port_number Serial port number. 00284 * 00285 * @return This function returns: 00286 * - character received by the serial port. 00287 * - @ref FNET_ERR if no character is available. 00288 * 00289 * @see fnet_cpu_serial_putchar(), fnet_cpu_serial_init() 00290 * 00291 ****************************************************************************** 00292 * 00293 * This function reads character from the serial port defined 00294 * by @c port_number. @n 00295 * 00296 ******************************************************************************/ 00297 fnet_int32_t fnet_cpu_serial_getchar( fnet_index_t port_number ); 00298 00299 /***************************************************************************/ /*! 00300 * 00301 * @brief Initializes the serial port. 00302 * 00303 * @param port_number Serial port number. 00304 * 00305 * @param baud_rate Baud rate to be set to the serial port. 00306 * 00307 * @see fnet_cpu_serial_putchar(), fnet_cpu_serial_getchar() 00308 * 00309 ****************************************************************************** 00310 * 00311 * This function executes the HW initialization of the serial port defined 00312 * by the @c port_number. 00313 * 00314 ******************************************************************************/ 00315 void fnet_cpu_serial_init(fnet_index_t port_number, fnet_uint32_t baud_rate); 00316 00317 /***************************************************************************/ /*! 00318 * 00319 * @brief Invalidates CPU-cache memory. 00320 * 00321 ****************************************************************************** 00322 * 00323 * If the CPU has cache memory, this function invalidates it.@n 00324 * This function is called only if @c FNET_CFG_CPU_CACHE is @c 1. 00325 * 00326 ******************************************************************************/ 00327 #if FNET_CFG_CPU_CACHE || defined(__DOXYGEN__) 00328 void fnet_cpu_cache_invalidate(void); 00329 #else 00330 #define fnet_cpu_cache_invalidate() do{}while(0) 00331 #endif 00332 00333 /***************************************************************************/ /*! 00334 * 00335 * @brief Erases the specified range of the Flash memory. 00336 * 00337 * @param flash_addr Address in the Flash to erase from. 00338 * 00339 * @param bytes Number of bytes to erase in the Flash memory. 00340 * 00341 * @return This function returns: 00342 * - @ref FNET_OK if successful. 00343 * - @ref FNET_ERR if failed. 00344 * 00345 * @see fnet_cpu_flash_write() 00346 * 00347 ****************************************************************************** 00348 * 00349 * This function attempt to erase the number of @c bytes bytes beginning 00350 * at @c flash_addr.@n 00351 * It should be noted that the Flash is block oriented when erasing. 00352 * It is not possible to erase a few bytes within a page, the whole page will 00353 * be erased. 00354 * The @c flash_addr parameter may be anywhere within the first page to be 00355 * erased and @c flash_addr+ @c bytes may be anywhere in the last block to 00356 * be erased. @n 00357 * 00358 ******************************************************************************/ 00359 fnet_return_t fnet_cpu_flash_erase(void *flash_addr, fnet_size_t bytes); 00360 00361 /***************************************************************************/ /*! 00362 * 00363 * @brief Writes the specified data to the Flash memory. 00364 * 00365 * @param dest Destination address in the Flash to write to. 00366 * 00367 * @param data Pointer to the block of data to write to the Flash memory 00368 * Size of the data block must be equal to 00369 * @ref FNET_CFG_CPU_FLASH_PROGRAM_SIZE. 00370 * 00371 * @return This function returns: 00372 * - @ref FNET_OK if successful. 00373 * - @ref FNET_ERR if failed. 00374 * 00375 * @see fnet_cpu_flash_erase() 00376 * 00377 ****************************************************************************** 00378 * 00379 * This function copies @ref FNET_CFG_CPU_FLASH_PROGRAM_SIZE bytes pointed by @c data 00380 * to the Flash memory pointed by @c dest. 00381 * 00382 ******************************************************************************/ 00383 fnet_return_t fnet_cpu_flash_write(fnet_uint8_t *dest, const fnet_uint8_t *data); 00384 00385 /***************************************************************************/ /*! 00386 * 00387 * @brief CPU-specific FNET interrupt service routine. 00388 * 00389 ****************************************************************************** 00390 * 00391 * This is CPU-specific ISR which is executed on every FNET interrupt 00392 * (from Ethernet and timer module).@n 00393 * It extracts vector number and calls fnet_isr_handler(). 00394 * 00395 ******************************************************************************/ 00396 void fnet_cpu_isr(void); 00397 00398 /***************************************************************************/ /*! 00399 * @def FNET_CPU_ADDR_TO_INSTRUCTION 00400 * 00401 * @brief Adjust value of the instruction address. 00402 * 00403 * @param addr Instruction address to be adjusted. 00404 * 00405 ****************************************************************************** 00406 * 00407 * This is CPU-specific macro that adjusts the instruction address. @n 00408 * If the current platform is Kinetis, it sets the Thumb bit (bit 0) of 00409 * the address to 1. @n 00410 * If the current platform is ColdFire or MPC, it does nothing. 00411 * 00412 ******************************************************************************/ 00413 #ifndef FNET_CPU_ADDR_TO_INSTRUCTION 00414 #define FNET_CPU_ADDR_TO_INSTRUCTION(addr) (addr) 00415 #endif 00416 00417 #ifndef FNET_CPU_INSTRUCTION_TO_ADDR 00418 #define FNET_CPU_INSTRUCTION_TO_ADDR(addr) (addr) 00419 #endif 00420 00421 struct fnet_netif; /* Forward declaration.*/ 00422 #if FNET_CFG_CPU_ETH0 00423 extern struct fnet_netif fnet_cpu_eth0_if; 00424 #define FNET_CPU_ETH0_IF ((fnet_netif_desc_t)(&fnet_cpu_eth0_if)) 00425 #endif 00426 #if FNET_CFG_CPU_ETH1 00427 extern struct fnet_netif fnet_cpu_eth1_if; 00428 #define FNET_CPU_ETH1_IF ((fnet_netif_desc_t)(&fnet_cpu_eth1_if)) 00429 #endif 00430 00431 #if defined(__cplusplus) 00432 } 00433 #endif 00434 00435 /*! @} */ 00436 00437 #endif /* _FNET_CPU_H_ */
Generated on Fri Jul 22 2022 04:53:49 by
