Mistake on this page?
Report an issue in GitHub or email us
emac_util.h
1 /*
2  * Copyright (c) 2017, ARM Limited, All Rights Reserved
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License"); you may
6  * not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef EMAC_UTIL_H
19 #define EMAC_UTIL_H
20 
21 #define SECOND_TO_US 1000000
22 #define SECOND_TO_MS 1000
23 #define MS_TO_US 1000
24 
25 extern const unsigned char eth_mac_broadcast_addr[];
26 
27 // Trace flags
28 #define TRACE_NONE 0x00
29 #define TRACE_ETH_FRAMES 0x01
30 #define TRACE_SUCCESS 0x02
31 #define TRACE_FAILURE 0x04
32 #define TRACE_SEND 0x08
33 // Sets trace level
34 #define SET_TRACE_LEVEL(level) emac_if_set_trace_level(level)
35 
36 // Message validation flags
37 #define BROADCAST 0x01
38 #define RESPONSE_RECEIVED 0x02
39 #define INVALID_LENGHT 0x04
40 #define INVALID_DATA 0x08
41 #define PRINTED 0x10
42 // Validates outgoing messages for replies, sets error flags on error
43 #define VALIDATE_OUTGOING_MESSAGES emac_if_validate_outgoing_msg();
44 // Resets message data
45 #define RESET_OUTGOING_MSG_DATA emac_if_reset_outgoing_msg()
46 
47 // General error flags
48 #define TEST_FAILED 0x01
49 #define MSG_VALID_ERROR 0x02
50 #define OUT_OF_MSG_DATA 0x04
51 #define NO_FREE_MEM_BUF 0x08
52 #define NO_RESPONSE 0x10
53 
54 #define ERROR_FLAGS emac_if_get_error_flags()
55 #define RESET_ALL_ERROR_FLAGS emac_if_reset_all_error_flags()
56 #define PRINT_ERROR_FLAGS emac_if_print_error_flags()
57 #define SET_ERROR_FLAGS(flags) emac_if_set_error_flags(flags)
58 #define RESET_ERROR_FLAGS(flags) emac_if_reset_error_flags(flags)
59 
60 #define ETH_FRAME_HEADER_LEN 28
61 #define ETH_FRAME_MIN_LEN 60 + 4
62 #define ETH_FRAME_PADD_LEN 60
63 #define ETH_MAC_ADDR_LEN 6
64 
65 #define TIMEOUT 1
66 #define INPUT 2
67 
68 #define ETH_MAX_LEN (14 + emac_if_get_mtu_size())
69 
70 // Starts test loop. Calls callback function on interval defined by the timeout
71 // and when input message is received.
72 #define START_TEST_LOOP(cb_function, timeout) worker_loop_start(cb_function, timeout)
73 
74 // Ends test loop
75 #define END_TEST_LOOP { worker_loop_end(); return; }
76 
77 // Checks if echo server MAC address is known
78 #define ECHO_SERVER_ADDRESS_KNOWN emac_if_count_echo_server_addr()
79 
80 int emac_if_find_outgoing_msg(int receipt_number);
81 void emac_if_free_outgoing_msg(int index);
82 int emac_if_count_outgoing_msg(void);
83 void emac_if_reset_outgoing_msg(void);
84 int emac_if_add_outgoing_msg(int length);
85 void emac_if_timeout_outgoing_msg(void);
86 void emac_if_validate_outgoing_msg(void);
87 void emac_if_set_outgoing_msg_receipt_num(int index, int receipt_number);
88 void emac_if_set_outgoing_msg_flags(int index, int flags);
89 
90 void emac_if_add_echo_server_addr(unsigned char *addr);
91 int emac_if_count_echo_server_addr(void);
92 unsigned char *emac_if_get_echo_server_addr(int index);
93 
94 void emac_if_set_error_flags(unsigned int error_flags_value);
95 unsigned int emac_if_get_error_flags(void);
96 void emac_if_reset_all_error_flags(void);
97 void emac_if_reset_error_flags(unsigned int error_flags_value);
98 void emac_if_print_error_flags(void);
99 
100 void emac_if_set_trace_level(char trace_level_value);
101 char emac_if_get_trace_level();
102 
103 void emac_if_trace_to_ascii_hex_dump(const char *prefix, int len, char *data);
104 
105 void emac_if_link_state_change_cb(void *data, bool up);
106 
107 unsigned char *emac_if_get_own_addr(void);
108 
109 int emac_if_get_mtu_size();
110 void emac_if_set_mtu_size(int mtu_size);
111 
112 extern void emac_if_link_input_cb(void *buf);
113 extern void emac_if_link_state_change_cb(bool up);
114 
115 void emac_if_set_all_multicast(bool all);
116 void emac_if_add_multicast_group(uint8_t *address);
117 
118 void emac_if_set_output_memory(bool memory);
119 void emac_if_set_input_memory(bool memory);
120 void emac_if_check_memory(bool output);
121 void emac_if_set_memory(bool memory);
122 
123 void worker_loop_init(void);
124 void worker_loop_start(void (*test_step_cb_fnc)(int opt), int timeout);
125 void worker_loop_end(void);
126 void worker_loop_link_up_wait(void);
127 
128 #endif /* EMAC_UTIL_H */
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.