Embedded TCP/IP stack  4.7.0
fnet_cpu.h
1 /**************************************************************************
2 *
3 * Copyright 2008-2018 by Andrey Butok. FNET Community.
4 *
5 ***************************************************************************
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may
8 * not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 ***************************************************************************
20 *
21 * CPU-specific library API.
22 *
23 ***************************************************************************/
24 
25 #ifndef _FNET_CPU_H_
26 
27 #define _FNET_CPU_H_
28 
29 #include "fnet_config.h"
30 
31 #if FNET_MCF /* ColdFire.*/
32  #include "mcf/fnet_mcf.h"
33 #endif
34 
35 #if FNET_MK /* Kinetis.*/
36  #include "mk/fnet_mk.h"
37 #endif
38 
39 #if FNET_MPC /* MPC.*/
40  #include "mpc/fnet_mpc.h"
41 #endif
42 
43 #if FNET_LPC /* LPC.*/
44  #include "lpc/fnet_lpc.h"
45 #endif
46 
47 #if FNET_MIMXRT /* i.MX RT.*/
48  #include "mimxrt/fnet_mimxrt.h"
49 #endif
50 
51 #include "stack/fnet_stdlib.h"
52 
53 
54 /* Non-cacheable region definition macro. */
55 /* Used MCUX "NonCacheable" name for this section. */
56 #if FNET_CFG_CPU_CACHE
57  #if FNET_CFG_COMP_IAR
58  #define FNET_AT_NONCACHEABLE_SECTION(var) var @FNET_CFG_CPU_NONCACHEABLE_SECTION
59  #elif FNET_CFG_COMP_UV || FNET_CFG_COMP_GNUC || FNET_CFG_COMP_GHS
60  #define FNET_AT_NONCACHEABLE_SECTION(var) __attribute__((section(FNET_CFG_CPU_NONCACHEABLE_SECTION))) var
61  #else
62  #error Compiler is not supported
63  #define FNET_AT_NONCACHEABLE_SECTION(var) var
64  #endif
65 #else
66  #define FNET_AT_NONCACHEABLE_SECTION(var) var
67 #endif
68 
69 
73 #if defined(__cplusplus)
74 extern "C" {
75 #endif
76 
77 /************************************************************************
78 * For doing byte order conversions between CPU
79 * and the independent "network" order.
80 * For Freescale CPUs they just return the variable passed.
81 *************************************************************************/
82 
83 #if FNET_CFG_CPU_LITTLE_ENDIAN /* Little endian.*/ || defined(__DOXYGEN__)
84 
85 /**************************************************************************/
93 #define FNET_HTONS(short_var) (((((fnet_uint16_t)(short_var)) & 0x00FFU) << 8U) | (((fnet_uint16_t)(short_var) & 0xFF00U) >> 8U))
94 /**************************************************************************/
102 #define FNET_NTOHS(short_var) FNET_HTONS(short_var)
103 /**************************************************************************/
111 #define FNET_HTONL(long_var) ((((long_var) & 0x000000FFU) << 24U) | (((long_var) & 0x0000FF00U) << 8U) | (((long_var) & 0x00FF0000U) >> 8U) | (((long_var) & 0xFF000000U) >> 24U))
112 /**************************************************************************/
120 #define FNET_NTOHL(long_var) FNET_HTONL(long_var)
121 
122 /***************************************************************************/
140 fnet_uint16_t fnet_htons(fnet_uint16_t short_var);
141 
142 #define fnet_ntohs fnet_htons
143 /***************************************************************************/
161 fnet_uint16_t fnet_ntohs(fnet_uint16_t short_var);
162 
163 /***************************************************************************/
181 fnet_uint32_t fnet_htonl(fnet_uint32_t long_var);
182 
183 #define fnet_ntohl fnet_htonl
184 /***************************************************************************/
202 fnet_uint32_t fnet_ntohl(fnet_uint32_t long_var);
203 
204 
205 #else /* Big endian. */
206 #define FNET_HTONS(short_var) (short_var)
207 #define FNET_NTOHS(short_var) (short_var)
208 #define FNET_HTONL(long_var) (long_var)
209 #define FNET_NTOHL(long_var) (long_var)
210 
211 #define fnet_htons(short_var) (short_var) /* Convert 16 bit integer from host- to network byte order.*/
212 #define fnet_ntohs(short_var) (short_var) /* Convert 16 bit integer from network - to host byte order.*/
213 #define fnet_htonl(long_var) (long_var) /* Convert 32 bit integer from host- to network byte order.*/
214 #define fnet_ntohl(long_var) (long_var) /* Convert 32 bit integer from network - to host byte order.*/
215 #endif
216 
226 /**************************************************************************/
231 typedef fnet_uint32_t fnet_cpu_irq_desc_t;
232 
233 /***************************************************************************/
243 void fnet_cpu_reset (void);
244 
245 /***************************************************************************/
261 
262 /***************************************************************************/
280 
281 /***************************************************************************/
297 void fnet_cpu_serial_putchar( fnet_index_t port_number, fnet_char_t character );
298 
299 /***************************************************************************/
317 fnet_int32_t fnet_cpu_serial_getchar( fnet_index_t port_number );
318 
319 /***************************************************************************/
339 fnet_return_t fnet_cpu_serial_init(fnet_index_t port_number, fnet_uint32_t baud_rate);
340 
341 /***************************************************************************/
368 
369 /***************************************************************************/
391 fnet_return_t fnet_cpu_flash_write(fnet_uint8_t *dest, const fnet_uint8_t *data);
392 
393 /***************************************************************************/
404 void fnet_cpu_isr(void);
405 
406 /***************************************************************************/
422 #ifndef FNET_CPU_ADDR_TO_INSTRUCTION
423 #define FNET_CPU_ADDR_TO_INSTRUCTION(addr) (addr)
424 #endif
425 
426 /***************************************************************************/
442 #ifndef FNET_CPU_INSTRUCTION_TO_ADDR
443 #define FNET_CPU_INSTRUCTION_TO_ADDR(addr) (addr)
444 #endif
445 
446 /***************************************************************************/
457 #ifndef FNET_CPU_DATA_MEMORY_BARRIER
458 #define FNET_CPU_DATA_MEMORY_BARRIER do{}while(0)
459 #endif
460 
461 
462 struct fnet_netif; /* Forward declaration.*/
463 #if FNET_CFG_CPU_ETH0
464 extern struct fnet_netif fnet_cpu_eth0_if;
465 #define FNET_CPU_ETH0_IF ((fnet_netif_desc_t)(&fnet_cpu_eth0_if))
466 #endif
467 #if FNET_CFG_CPU_ETH1
468 extern struct fnet_netif fnet_cpu_eth1_if;
469 #define FNET_CPU_ETH1_IF ((fnet_netif_desc_t)(&fnet_cpu_eth1_if))
470 #endif
471 #if FNET_CFG_CPU_WIFI
472 extern struct fnet_netif fnet_cpu_wifi_if;
473 #define FNET_CPU_WIFI_IF ((fnet_netif_desc_t)(&fnet_cpu_wifi_if))
474 #endif
475 
476 /***************************************************************************/
480 #define FNET_CPU_NETIF_NUMBER (FNET_CFG_CPU_ETH0+FNET_CFG_CPU_ETH1+FNET_CFG_CPU_WIFI)
481 
482 #if defined(__cplusplus)
483 }
484 #endif
485 
488 #endif /* _FNET_CPU_H_ */
fnet_uint16_t fnet_ntohs(fnet_uint16_t short_var)
Converts 16-bit value from network to host byte order.
void fnet_cpu_irq_enable(fnet_cpu_irq_desc_t irq_desc)
Enables interrupts.
fnet_int32_t fnet_cpu_serial_getchar(fnet_index_t port_number)
Reads character from the serial port.
void fnet_cpu_serial_putchar(fnet_index_t port_number, fnet_char_t character)
Writes character to the serial port.
fnet_return_t
General return codes, used by most of API functions.
Definition: fnet_stdlib.h:89
unsigned long fnet_size_t
Unsigned integer type representing the size in bytes.
Definition: fnet_stdlib.h:55
fnet_uint16_t fnet_htons(fnet_uint16_t short_var)
Converts 16-bit value from host to network byte order.
fnet_uint32_t fnet_htonl(fnet_uint32_t long_var)
Converts 32-bit value from host to network byte order.
fnet_return_t fnet_cpu_flash_write(fnet_uint8_t *dest, const fnet_uint8_t *data)
Writes the specified data to the Flash memory.
fnet_size_t bytes
Number of received bytes, in addition to megabytes, during the benchmark session. ...
fnet_return_t fnet_cpu_serial_init(fnet_index_t port_number, fnet_uint32_t baud_rate)
Initializes the serial port.
fnet_uint32_t fnet_cpu_irq_desc_t
IRQ status descriptor returned by the fnet_cpu_irq_disable() function. Actually it corresponds to the...
Definition: fnet_cpu.h:231
fnet_return_t fnet_cpu_flash_erase(void *flash_addr, fnet_size_t bytes)
Erases the specified range of the Flash memory.
void fnet_cpu_isr(void)
CPU-specific FNET interrupt service routine.
fnet_cpu_irq_desc_t fnet_cpu_irq_disable(void)
Disables all interrupts.
void fnet_cpu_reset(void)
Initiates software reset.
unsigned int fnet_index_t
Unsigned integer type representing the index.
Definition: fnet_stdlib.h:70
char fnet_char_t
Type representing the charecter.
Definition: fnet_stdlib.h:75
fnet_uint32_t fnet_ntohl(fnet_uint32_t long_var)
Converts 32-bit value from network to host byte order.

© 2005-2020 by Andrej Butok. http://fnet.sourceforge.net