1 /***************************************************************************//**
\r
3 * SmartFusion MSS Ethernet MAC header file.
\r
5 * (c) Copyright 2007 Actel Corporation
\r
7 * SVN $Revision: 2364 $
\r
8 * SVN $Date: 2010-03-01 17:58:41 +0000 (Mon, 01 Mar 2010) $
\r
10 *******************************************************************************/
\r
12 #ifndef __MSS_ETHERNET_MAC_H
\r
13 #define __MSS_ETHERNET_MAC_H 1
\r
21 /******************************** DEFINES *************************************/
\r
23 /*******************************************************************************
\r
28 * When set, all incoming frames are received, regardless of their destination address.
\r
29 * An address check is performed, and the result of the check is written into the receive
\r
32 #define MSS_MAC_CFG_RECEIVE_ALL 0x00000001u
\r
35 * Transmit threshold mode.
\r
36 * 1 - Transmit FIFO threshold set for 100 Mbps mode
\r
37 * 0 - Transmit FIFO threshold set for 10 Mbps mode
\r
38 * This bit can be changed only when a transmit process is in a stopped state.
\r
40 #define MSS_MAC_CFG_TRANSMIT_THRESHOLD_MODE 0x00000002u
\r
43 * Store and forward.
\r
44 * When set, the transmission starts after a full packet is written into the transmit
\r
45 * FIFO, regardless of the current FIFO threshold level.
\r
46 * This bit can be changed only when the transmit process is in the stopped state.
\r
48 #define MSS_MAC_CFG_STORE_AND_FORWARD 0x00000004u
\r
51 * Threshold control bits.
\r
52 * These bits, together with TTM, SF, and PS, control the threshold level for the
\r
55 #define MSS_MAC_CFG_THRESHOLD_CONTROL_00 0x00000000u
\r
56 #define MSS_MAC_CFG_THRESHOLD_CONTROL_01 0x00000008u
\r
57 #define MSS_MAC_CFG_THRESHOLD_CONTROL_10 0x00000010u
\r
58 #define MSS_MAC_CFG_THRESHOLD_CONTROL_11 0x00000018u
\r
62 * 0 - Half-duplex mode <br>
\r
63 * 1 - Forcing full-duplex mode <br>
\r
64 * Changing of this bit is allowed only when both the transmitter and receiver processes
\r
65 * are in the stopped state.
\r
67 #define MSS_MAC_CFG_FULL_DUPLEX_MODE 0x00000020u
\r
70 * Pass all multicast.
\r
71 * When set, all frames with multicast destination addresses will be received, regardless
\r
72 * of the address check result.
\r
74 #define MSS_MAC_CFG_PASS_ALL_MULTICAST 0x00000040u
\r
78 * When set, all frames will be received regardless of the address check result. An
\r
79 * address check is not performed.
\r
81 #define MSS_MAC_CFG_PROMISCUOUS_MODE 0x00000080u
\r
84 * Inverse filtering (read-only).
\r
85 * If this bit is set when working in a perfect filtering mode, the receiver performs an
\r
86 * inverse filtering during the address check process.
\r
87 * The 'filtering type' bits of the setup frame determine the state of this bit.
\r
89 #define MSS_MAC_CFG_INVERSE_FILTERING 0x00000100u
\r
93 * When set, Core10/100 transfers all frames into the data buffers, regardless of the
\r
94 * receive errors. This allows the runt frames, collided fragments, and truncated frames
\r
97 #define MSS_MAC_CFG_PASS_BAD_FRAMES 0x00000200u
\r
100 * Hash-only filtering mode (read-only).
\r
101 * When set, Core10/100 performs an imperfect filtering over both the multicast and
\r
102 * physical addresses.
\r
103 * The 'filtering type' bits of the setup frame determine the state of this bit.
\r
105 #define MSS_MAC_CFG_HASH_ONLY_FILTERING_MODE 0x00000400u
\r
108 * Hash/perfect receive filtering mode (read-only).
\r
109 * 0 - Perfect filtering of the incoming frames is performed according to the physical
\r
110 * addresses specified in a setup frame. <br>
\r
111 * 1 - Imperfect filtering over the frames with the multicast addresses is performed
\r
112 * according to the hash table specified in a setup frame. <br>
\r
113 * A physical address check is performed according to the CSR6.2 (HO, hash-only) bit.
\r
114 * When both the HO and HP bits are set, an imperfect filtering is performed on all of
\r
116 * The 'filtering type' bits of the setup frame determine the state of this bit.
\r
118 #define MSS_MAC_CFG_HASH_PERFECT_RECEIVE_FILTERING_MODE 0x00000800u
\r
121 /*******************************************************************************
\r
122 * Link status values.
\r
124 #define MSS_MAC_LINK_STATUS_LINK 0x0001u /**< Link up/down */
\r
125 #define MSS_MAC_LINK_STATUS_100MB 0x0002u /**< Connection is 100Mb/10Mb */
\r
126 #define MSS_MAC_LINK_STATUS_FDX 0x0004u /**< Connection is full/half duplex */
\r
130 * Size of the max packet that can be received/transmited.
\r
132 #define MSS_MAX_PACKET_SIZE 1514uL
\r
135 * Size of a receive/transmit buffer.
\r
136 * Buffer size must be enough big to hold a full frame and must be multiple of
\r
137 * four. For rx buffer +4 bytes allocated for crc values. These bytes doesn't
\r
138 * copied to the user buffer.
\r
140 #define MSS_TX_BUFF_SIZE ((MSS_MAX_PACKET_SIZE + 3u) & (~(uint32_t)3))
\r
141 #define MSS_RX_BUFF_SIZE ((MSS_MAX_PACKET_SIZE + 7u) & (~(uint32_t)3))
\r
143 /*******************************************************************************
\r
146 #define MSS_MAC_NONBLOCKING 0u
\r
147 #define MSS_MAC_BLOCKING 0xFFFFFFFFUL
\r
149 /***************************************************************************//**
\r
152 #define MSS_MAC_EVENT_PACKET_SEND 1u
\r
153 #define MSS_MAC_EVENT_PACKET_RECEIVED 2u
\r
155 /***************************************************************************//**
\r
158 #define MSS_PHY_ADDRESS_MIN 0u
\r
159 #define MSS_PHY_ADDRESS_MAX 31u
\r
160 #define MSS_PHY_ADDRESS_AUTO_DETECT 255u
\r
162 /***************************************************************************//**
\r
163 * Listener function type defines the function prototype that might be followed
\r
164 * by MAC_isr which is triggered with each receive and transmit related interrupts.
\r
165 * Listener functions should follow the following prototype:
\r
166 * void MAC_Listener( uint32_t events );
\r
167 * The parameter is used to inform the listener function about the triggering event
\r
168 * or events. Events input to the system are:
\r
169 * #define MSS_MAC_EVENT_PACKET_SEND 1
\r
170 * #define MSS_MAC_EVENT_PACKET_RECEIVED 2
\r
171 * Listener function should be defined by the application using this driver if
\r
172 * needed. This function may be assigned to the driver using MAC_set_callback
\r
173 * routine and may be un assigned again by using the same routine with a NULL pointer
\r
174 * as the event listener function. It is recommended to use this property for interrupt
\r
175 * triggered systems and it is not recommended for polling mechanisms.
\r
177 typedef void (*MSS_MAC_callback_t)(uint32_t events);
\r
179 /***************************************************************************//**
\r
180 * Statistics counter identifiers are used with MAC_get_statistics routine to
\r
181 * receive the count of the requested errors/interrupts occurrences.
\r
183 * MSS_MAC_RX_INTERRUPTS
\r
184 * Used to receive the number of receive interrupts occurred.
\r
186 * MSS_MAC_RX_FILTERING_FAIL
\r
187 * Used to receive the number of received frames which did not pass the
\r
188 * address recognition process.
\r
190 * MSS_MAC_RX_DESCRIPTOR_ERROR
\r
191 * Used to receive the number of occurrences of; no receive buffer was
\r
192 * available when trying to store the received data.
\r
194 * MSS_MAC_RX_RUNT_FRAME
\r
195 * Used to receive the number of occurrences of; the frame is damaged by a
\r
196 * collision or by a premature termination before the end of a collision
\r
199 * MSS_MAC_RX_NOT_FIRST
\r
200 * Used to receive the number of occurrences of; start of the frame is not
\r
201 * the first descriptor of a frame.
\r
203 * MSS_MAC_RX_NOT_LAST
\r
204 * Used to receive the number of occurrences of; end of the frame is not
\r
205 * the first descriptor of a frame.
\r
207 * MSS_MAC_RX_FRAME_TOO_LONG
\r
208 * Used to receive the number of occurrences of; a current frame is longer
\r
209 * than maximum size of 1,518 bytes, as specified by 802.3.
\r
211 * MSS_MAC_RX_COLLISION_SEEN
\r
212 * Used to receive the number of occurrences of; a late collision was seen
\r
213 * (collision after 64 bytes following SFD).
\r
215 * MSS_MAC_RX_CRC_ERROR
\r
216 * Used to receive the number of occurrences of; a CRC error has occurred
\r
217 * in the received frame.
\r
219 * MSS_MAC_RX_FIFO_OVERFLOW
\r
220 * Used to receive the number of frames not accepted due to the receive
\r
223 * MSS_MAC_RX_MISSED_FRAME
\r
224 * Used to receive the number of frames not accepted due to the
\r
225 * unavailability of the receive descriptor.
\r
227 * MSS_MAC_TX_INTERRUPTS
\r
228 * Used to receive the number of transmit interrupts occurred.
\r
230 * MSS_MAC_TX_LOSS_OF_CARRIER
\r
231 * Used to receive the number of occurrences of; a loss of the carrier
\r
232 * during a transmission.
\r
234 * MSS_MAC_TX_NO_CARRIER
\r
235 * Used to receive the number of occurrences of; the carrier was not asserted
\r
236 * by an external transceiver during the transmission.
\r
238 * MSS_MAC_TX_LATE_COLLISION
\r
239 * Used to receive the number of occurrences of; a collision was detected
\r
240 * after transmitting 64 bytes.
\r
242 * MSS_MAC_TX_EXCESSIVE_COLLISION
\r
243 * Used to receive the number of occurrences of; the transmission was aborted
\r
244 * after 16 retries.
\r
246 * MSS_MAC_TX_COLLISION_COUNT
\r
247 * Used to receive the number of collisions occurred.
\r
249 * MSS_MAC_TX_UNDERFLOW_ERROR
\r
250 * Used to receive the number of occurrences of; the FIFO was empty during
\r
251 * the frame transmission.
\r
254 MSS_MAC_RX_INTERRUPTS,
\r
255 MSS_MAC_RX_FILTERING_FAIL,
\r
256 MSS_MAC_RX_DESCRIPTOR_ERROR,
\r
257 MSS_MAC_RX_RUNT_FRAME,
\r
258 MSS_MAC_RX_NOT_FIRST,
\r
259 MSS_MAC_RX_NOT_LAST,
\r
260 MSS_MAC_RX_FRAME_TOO_LONG,
\r
261 MSS_MAC_RX_COLLISION_SEEN,
\r
262 MSS_MAC_RX_CRC_ERROR,
\r
263 MSS_MAC_RX_FIFO_OVERFLOW,
\r
264 MSS_MAC_RX_MISSED_FRAME,
\r
266 MSS_MAC_TX_INTERRUPTS,
\r
267 MSS_MAC_TX_LOSS_OF_CARRIER,
\r
268 MSS_MAC_TX_NO_CARRIER,
\r
269 MSS_MAC_TX_LATE_COLLISION,
\r
270 MSS_MAC_TX_EXCESSIVE_COLLISION,
\r
271 MSS_MAC_TX_COLLISION_COUNT,
\r
272 MSS_MAC_TX_UNDERFLOW_ERROR
\r
273 } mss_mac_statistics_id_t;
\r
275 /******************************* FUNCTIONS ************************************/
\r
277 /***************************************************************************//**
\r
278 * Initializes an Ethernet MAC controller and data structures.
\r
279 * This function will prepare the Ethernet Controller for first time use in a
\r
280 * given hardware/software configuration. This function should be called before
\r
281 * any other Ethernet API functions are called.
\r
283 * Initialization of registers - config registers, enable Tx/Rx interrupts,
\r
284 * enable Tx/Rx, initialize MAC addr, init PHY, autonegotiation, MAC address
\r
285 * filter table (unicast/multicast)/hash init
\r
291 uint8_t phy_address
\r
295 /***************************************************************************//**
\r
296 * Sets the configuration of the Ethernet Controller.
\r
297 * After the MAC_init function has been called, this API function can be
\r
298 * used to configure the various features of the Ethernet Controller.
\r
300 * @param configuration The logical OR of the following values:
\r
301 * - #MSS_MAC_CFG_RECEIVE_ALL
\r
302 * - #MSS_MAC_CFG_TRANSMIT_THRESHOLD_MODE
\r
303 * - #MSS_MAC_CFG_STORE_AND_FORWARD
\r
304 * - #MSS_MAC_CFG_THRESHOLD_CONTROL_[00,01,10,11]
\r
305 * - #MSS_MAC_CFG_FULL_DUPLEX_MODE
\r
306 * - #MSS_MAC_CFG_PASS_ALL_MULTICAST
\r
307 * - #MSS_MAC_CFG_PROMISCUOUS_MODE
\r
308 * - #MSS_MAC_CFG_PASS_BAD_FRAMES
\r
309 * @see MAC_get_configuration()
\r
314 uint32_t configuration
\r
318 /***************************************************************************//**
\r
319 * Returns the configuration of the Ethernet Controller.
\r
320 * After the MAC_init function has been called, this API function can be used to
\r
321 * get the configuration of the Ethernet Controller.
\r
323 * @return The logical OR of the following values:
\r
324 * - #MSS_MAC_CFG_RECEIVE_ALL
\r
325 * - #MSS_MAC_CFG_TRANSMIT_THRESHOLD_MODE
\r
326 * - #MSS_MAC_CFG_STORE_AND_FORWARD
\r
327 * - #MSS_MAC_CFG_THRESHOLD_CONTROL_[00,01,10,11]
\r
328 * - #MSS_MAC_CFG_FULL_DUPLEX_MODE
\r
329 * - #MSS_MAC_CFG_PASS_ALL_MULTICAST
\r
330 * - #MSS_MAC_CFG_PROMISCUOUS_MODE
\r
331 * - #MSS_MAC_CFG_INVERSE_FILTERING
\r
332 * - #MSS_MAC_CFG_PASS_BAD_FRAMES
\r
333 * - #MSS_MAC_CFG_HASH_ONLY_FILTERING_MODE
\r
334 * - #MSS_MAC_CFG_HASH_PERFECT_RECEIVE_FILTERING_MODE
\r
335 * @see MAC_configure()
\r
338 MSS_MAC_get_configuration
\r
344 /***************************************************************************//**
\r
345 Sends a packet from the uIP stack to the Ethernet Controller.
\r
346 The MSS_MAC_tx_packet() function is used to send a packet to the MSS Ethernet
\r
347 MAC. This function writes uip_len bytes of the packet contained in uip_buf into
\r
348 the transmit FIFO and then activates the transmitter for this packet. If space
\r
349 is available in the FIFO, the function will return once pac_len bytes of the
\r
350 packet have been placed into the FIFO and the transmitter has been started.
\r
351 This function will not wait for the transmission to complete.
\r
354 The function returns zero if a timeout occurs otherwise it returns size of the packet.
\r
356 @see MAC_rx_packet()
\r
362 unsigned short usLength
\r
365 /***************************************************************************//**
\r
366 * Returns available packet's size.
\r
368 * @return Size of packet, bigger than 0, if a packet is available,
\r
369 * if not, returns 0.
\r
370 * @see MAC_rx_packet()
\r
373 MSS_MAC_rx_pckt_size
\r
380 /***************************************************************************//**
\r
381 * Prepares the RX descriptor for receiving packets.
\r
384 * @see MAC_rx_packet()
\r
387 MSS_MAC_prepare_rx_descriptor
\r
392 /***************************************************************************//**
\r
393 * Receives a packet from the Ethernet Controller into the uIP stack.
\r
394 * This function reads a packet from the receive FIFO of the controller and
\r
395 * places it into uip_buf.
\r
397 * @return Size of packet if packet fits in uip_buf.
\r
398 * 0 if there is no received packet.
\r
399 * @see MAC_rx_pckt_size()
\r
400 * @see MAC_tx_packet()
\r
409 /***************************************************************************//**
\r
410 Receives a packet from the Ethernet Controller.
\r
411 The MSS_MAC_rx_packet_ptrset() function is very similar to the MSS_MAC_rx_packet()
\r
412 function, in that it receives data from the MSS Ethernet MAC. The difference
\r
413 is that it sets pacData to point to the memory buffer where the MSS Ethernet
\r
414 MAC copied the received packet instead of copying the received packet into a
\r
415 buffer provided by the application. After this function is called and data is
\r
416 used by the user application or copied to another buffer, the
\r
417 MSS_MAC_prepare_rx_descriptor() function must be called to free up the receive
\r
418 memory buffer used by the MSS Ethernet MAC
\r
421 The pacData parameter is a pointer to a memory buffer pointer. The uint8_t
\r
422 pointer pointed to by the pacData parameter will contain the address of the
\r
423 memory buffer containing the received packet after this function returns. The
\r
424 value of pacData is only valid if the return value is larger than zero,
\r
425 indicating that a packet was received.
\r
428 The time_out parameter is the timeout value for the transmission in milliseconds.
\r
429 The time_out parameter value can be one of the following values:
\r
430 \95 Unsigned integer greater than 0 and less than 0x01000000
\r
431 \95 MSS_MAC_BLOCKING
\96 there will be no timeout.
\r
432 \95 MSS_MAC_NONBLOCKING
\96 the function will return immediately if no packets
\r
433 have been received.
\r
436 The function returns the size of the packet if the packet fits in pacData.
\r
437 Returns zero if there is no received packet.
\r
439 @see MAC_rx_pckt_size()
\r
440 @see MAC_tx_packet()
\r
443 MSS_MAC_rx_packet_ptrset
\r
449 /***************************************************************************//**
\r
450 * Returns the status of connection by reading it from the PHY.
\r
452 * @return the logical OR of the following values:
\r
453 * #MSS_MAC_LINK_STATUS_LINK - Link up/down
\r
454 * #MSS_MAC_LINK_STATUS_100MB - Connection is 100Mb/10Mb
\r
455 * #MSS_MAC_LINK_STATUS_FDX - Connection is full/half duplex
\r
456 * @see MAC_auto_setup_link()
\r
459 MSS_MAC_link_status
\r
465 /***************************************************************************//**
\r
466 * Setups the link between PHY and MAC and returns the status of connection.
\r
468 * @return the logical OR of the following values:
\r
469 * #MSS_MAC_LINK_STATUS_LINK - Link up/down
\r
470 * #MSS_MAC_LINK_STATUS_100MB - Connection is 100Mb/10Mb
\r
471 * #MSS_MAC_LINK_STATUS_FDX - Connection is full/half duplex
\r
472 * @see MAC_link_status()
\r
475 MSS_MAC_auto_setup_link
\r
481 /***************************************************************************//**
\r
482 * Sets mac address.
\r
484 * @param new_address Pointer to then new address value (6 bytes of data)
\r
485 * @see MAC_get_mac_address()
\r
488 MSS_MAC_set_mac_address
\r
490 const uint8_t *new_address
\r
494 /***************************************************************************//**
\r
495 * Returns mac address.
\r
497 * @param address Pointer to the parameter to receive the MAC address.
\r
498 * @see MAC_set_mac_address()
\r
501 MSS_MAC_get_mac_address
\r
507 /***************************************************************************//**
\r
508 * Sets mac address filters.
\r
509 * If less than 15 addresses are subscribed, system works on perfect filtering mode
\r
510 * else system works in hash table mode
\r
512 * @param filter_count number of addresses
\r
513 * @param filters Pointer to addresses to be filtered
\r
516 MSS_MAC_set_mac_filters
\r
518 uint16_t filter_count,
\r
519 const uint8_t *filters
\r
522 /***************************************************************************//**
\r
523 * Sets MAC event listener.
\r
524 * Sets the given event listener function to be triggered inside MAC_isr().
\r
525 * Assigning NULL pointer as the listener function will disable it.
\r
527 * @param listener function pointer to a MSS_MAC_callback_t function
\r
531 MSS_MAC_set_callback
\r
533 MSS_MAC_callback_t listener
\r
537 /***************************************************************************//**
\r
538 * Returns description of latest error happened.
\r
540 * @return A string describing the error. This string must not be
\r
541 * modified by the application.
\r
550 /***************************************************************************//**
\r
551 * Returns statistics counter of stat_id identifier.
\r
553 * @param stat_id Identifier of statistics counter.
\r
554 * @return Statistics counter of stat_id identifier.
\r
555 * On error returns 0.
\r
558 MSS_MAC_get_statistics
\r
560 mss_mac_statistics_id_t stat_id
\r
564 * The double Tx has completed. Hand back the Tx buffer to the control of
\r
565 * the MAC hardware.
\r
567 void MSS_MAC_FreeTxBuffers( void );
\r
572 #endif /* __MSS_ETHERNET_MAC_H */
\r