Deleted Added
full compact
emac.c (161196) emac.c (161370)
1/*******************************************************************************
2 *
3 * Filename: emac.c
4 *
5 * Instantiation of routines for MAC/ethernet functions supporting tftp.
6 *
7 * Revision information:
8 *

--- 5 unchanged lines hidden (view full) ---

14 * No warranty, expressed or implied, is included with this software. It is
15 * provided "AS IS" and no warranty of any kind including statutory or aspects
16 * relating to merchantability or fitness for any purpose is provided. All
17 * intellectual property rights of others is maintained with the respective
18 * owners. This software is not copyrighted and is intended for reference
19 * only.
20 * END_BLOCK
21 *
1/*******************************************************************************
2 *
3 * Filename: emac.c
4 *
5 * Instantiation of routines for MAC/ethernet functions supporting tftp.
6 *
7 * Revision information:
8 *

--- 5 unchanged lines hidden (view full) ---

14 * No warranty, expressed or implied, is included with this software. It is
15 * provided "AS IS" and no warranty of any kind including statutory or aspects
16 * relating to merchantability or fitness for any purpose is provided. All
17 * intellectual property rights of others is maintained with the respective
18 * owners. This software is not copyrighted and is intended for reference
19 * only.
20 * END_BLOCK
21 *
22 * $FreeBSD: head/sys/boot/arm/at91/libat91/emac.c 161196 2006-08-10 18:11:22Z imp $
22 * $FreeBSD: head/sys/boot/arm/at91/libat91/emac.c 161370 2006-08-16 23:39:58Z imp $
23 ******************************************************************************/
24
25#include "at91rm9200.h"
26#include "at91rm9200_lowlevel.h"
27#include "emac.h"
28#include "lib.h"
29
30/* ****************************** GLOBALS *************************************/
31
32/* ********************** PRIVATE FUNCTIONS/DATA ******************************/
33
23 ******************************************************************************/
24
25#include "at91rm9200.h"
26#include "at91rm9200_lowlevel.h"
27#include "emac.h"
28#include "lib.h"
29
30/* ****************************** GLOBALS *************************************/
31
32/* ********************** PRIVATE FUNCTIONS/DATA ******************************/
33
34static unsigned localMACSet, serverMACSet;
35static unsigned char localMACAddr[6], serverMACAddr[6];
36static unsigned localMAClow, localMAChigh;
37static unsigned localIPSet, serverIPSet;
34static char serverMACAddr[6];
38static unsigned char localIPAddr[4], serverIPAddr[4];
35static unsigned char localIPAddr[4], serverIPAddr[4];
39static unsigned short serverPort, localPort;
40static int ackBlock;
36static int ackBlock;
41static unsigned lastSize;
42static char *dlAddress;
43
44static unsigned transmitBuffer[1024 / sizeof(unsigned)];
45static unsigned tftpSendPacket[256 / sizeof(unsigned)];
46
37static char *dlAddress;
38
39static unsigned transmitBuffer[1024 / sizeof(unsigned)];
40static unsigned tftpSendPacket[256 / sizeof(unsigned)];
41
47receive_descriptor_t *p_rxBD;
48
49
50/*
51 * .KB_C_FN_DEFINITION_START
52 * unsigned short IP_checksum(unsigned short *p, int len)
53 * This private function calculates the IP checksum for various headers.
54 * .KB_C_FN_DEFINITION_END
55 */
56static unsigned short
57IP_checksum(unsigned short *p, int len)

--- 411 unchanged lines hidden (view full) ---

469 pEmac->EMAC_CTL = AT91C_EMAC_TE | AT91C_EMAC_RE;
470
471 pEmac->EMAC_TAR = (unsigned)transmitBuffer;
472}
473
474
475/* ************************** GLOBAL FUNCTIONS ********************************/
476
42/*
43 * .KB_C_FN_DEFINITION_START
44 * unsigned short IP_checksum(unsigned short *p, int len)
45 * This private function calculates the IP checksum for various headers.
46 * .KB_C_FN_DEFINITION_END
47 */
48static unsigned short
49IP_checksum(unsigned short *p, int len)

--- 411 unchanged lines hidden (view full) ---

461 pEmac->EMAC_CTL = AT91C_EMAC_TE | AT91C_EMAC_RE;
462
463 pEmac->EMAC_TAR = (unsigned)transmitBuffer;
464}
465
466
467/* ************************** GLOBAL FUNCTIONS ********************************/
468
477
478/*
479 * .KB_C_FN_DEFINITION_START
469/*
470 * .KB_C_FN_DEFINITION_START
480 * void SetMACAddress(unsigned low_address, unsigned high_address)
481 * This global function sets the MAC address. low_address is the first
482 * four bytes while high_address is the last 2 bytes of the 48-bit value.
483 * .KB_C_FN_DEFINITION_END
484 */
485void
486SetMACAddress(unsigned char mac[6])
487{
488 AT91PS_PMC pPMC = AT91C_BASE_PMC;
489 AT91PS_EMAC pEmac = AT91C_BASE_EMAC;
490
491 /* enable the peripheral clock before using EMAC */
492 pPMC->PMC_PCER = ((unsigned) 1 << AT91C_ID_EMAC);
493
494 p_memcpy(localMACAddr, mac, 6);
495 localMAClow = (mac[2] << 24) | (mac[3] << 16) | (mac[4] << 8) | mac[5];
496 localMAChigh = (mac[0] << 8) | mac[1];
497 localMACSet = 1;
498
499 AT91C_BASE_PMC->PMC_PCER = 1u << AT91C_ID_EMAC;
500 AT91C_BASE_PIOA->PIO_ASR =
501 AT91C_PA14_ERXER | AT91C_PA12_ERX0 | AT91C_PA13_ERX1 |
502 AT91C_PA8_ETXEN | AT91C_PA16_EMDIO | AT91C_PA9_ETX0 |
503 AT91C_PA10_ETX1 | AT91C_PA11_ECRS_ECRSDV | AT91C_PA15_EMDC |
504 AT91C_PA7_ETXCK_EREFCK;
505 AT91C_BASE_PIOA->PIO_PDR =
506 AT91C_PA14_ERXER | AT91C_PA12_ERX0 | AT91C_PA13_ERX1 |
507 AT91C_PA8_ETXEN | AT91C_PA16_EMDIO | AT91C_PA9_ETX0 |
508 AT91C_PA10_ETX1 | AT91C_PA11_ECRS_ECRSDV | AT91C_PA15_EMDC |
509 AT91C_PA7_ETXCK_EREFCK;
510#ifdef BOOT_KB9202 /* Really !RMII */
511 AT91C_BASE_PIOB->PIO_BSR =
512 AT91C_PB12_ETX2 | AT91C_PB13_ETX3 | AT91C_PB14_ETXER |
513 AT91C_PB15_ERX2 | AT91C_PB16_ERX3 | AT91C_PB17_ERXDV |
514 AT91C_PB18_ECOL | AT91C_PB19_ERXCK;
515 AT91C_BASE_PIOB->PIO_PDR =
516 AT91C_PB12_ETX2 | AT91C_PB13_ETX3 | AT91C_PB14_ETXER |
517 AT91C_PB15_ERX2 | AT91C_PB16_ERX3 | AT91C_PB17_ERXDV |
518 AT91C_PB18_ECOL | AT91C_PB19_ERXCK;
519#endif
520 pEmac->EMAC_CTL = 0;
521
522 pEmac->EMAC_CFG = (pEmac->EMAC_CFG & ~(AT91C_EMAC_CLK)) |
523#ifdef BOOT_TSC
524 AT91C_EMAC_RMII |
525#endif
526 AT91C_EMAC_CLK_HCLK_32 | AT91C_EMAC_CAF;
527 // the sequence write EMAC_SA1L and write EMAC_SA1H must be respected
528 pEmac->EMAC_SA1L = localMAClow;
529 pEmac->EMAC_SA1H = localMAChigh;
530}
531
532
533/*
534 * .KB_C_FN_DEFINITION_START
535 * void SetServerIPAddress(unsigned address)
536 * This global function sets the IP of the TFTP download server.
537 * .KB_C_FN_DEFINITION_END
538 */
539void
540SetServerIPAddress(unsigned address)
541{
542 // force update in case the IP has changed

--- 76 unchanged lines hidden (view full) ---

619 TFTP_ACK_Data(0, ackBlock, 512);
620 printf("\nNAK %u\r\n", ackBlock);
621 }
622 }
623 }
624 if (timeout == 0)
625 printf("TFTP TIMEOUT!\r\n");
626}
471 * void SetServerIPAddress(unsigned address)
472 * This global function sets the IP of the TFTP download server.
473 * .KB_C_FN_DEFINITION_END
474 */
475void
476SetServerIPAddress(unsigned address)
477{
478 // force update in case the IP has changed

--- 76 unchanged lines hidden (view full) ---

555 TFTP_ACK_Data(0, ackBlock, 512);
556 printf("\nNAK %u\r\n", ackBlock);
557 }
558 }
559 }
560 if (timeout == 0)
561 printf("TFTP TIMEOUT!\r\n");
562}
627
628
629/*
630 * .KB_C_FN_DEFINITION_START
631 * void EMAC_Init(void)
632 * This global function initializes variables used in tftp transfers.
633 * .KB_C_FN_DEFINITION_END
634 */
635void
636EMAC_Init(void)
637{
638 p_rxBD = (receive_descriptor_t*)RX_BUFFER_START;
639 localMACSet = 0;
640 serverMACSet = 0;
641 localIPSet = 0;
642 serverIPSet = 0;
643 localPort = SWAP16(0x8002);
644 lastSize = 0;
645}