Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 17 Apr 2006 20:44:34 GMT
From:      Warner Losh <imp@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 95442 for review
Message-ID:  <200604172044.k3HKiYx3050329@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=95442

Change 95442 by imp@imp_hammer on 2006/04/17 20:43:58

	Transition to using a more standard layout.  Move everything that's
	library like into libat91.  This is the first step: making it compile
	and eliminating inc.  More to follow.

Affected files ...

.. //depot/projects/arm/src/sys/boot/arm/at91/boot0/Makefile#3 edit
.. //depot/projects/arm/src/sys/boot/arm/at91/boot0/at91rm9200_lowlevel.c#6 edit
.. //depot/projects/arm/src/sys/boot/arm/at91/boot0/lib.c#2 edit
.. //depot/projects/arm/src/sys/boot/arm/at91/boot0/main.c#4 edit
.. //depot/projects/arm/src/sys/boot/arm/at91/bootiic/debug_io.c#3 edit
.. //depot/projects/arm/src/sys/boot/arm/at91/bootiic/eeprom.c#3 edit
.. //depot/projects/arm/src/sys/boot/arm/at91/bootiic/emac.c#3 edit
.. //depot/projects/arm/src/sys/boot/arm/at91/inc/AT91RM9200.h#4 delete
.. //depot/projects/arm/src/sys/boot/arm/at91/libat91/at91rm9200.h#1 branch
.. //depot/projects/arm/src/sys/boot/arm/at91/ramMonitor/debug_io.c#2 edit

Differences ...

==== //depot/projects/arm/src/sys/boot/arm/at91/boot0/Makefile#3 (text) ====

@@ -4,7 +4,7 @@
 SRCS=arm_init.s at91rm9200_lowlevel.c lib.c main.c xmodem.c
 NO_MAN=
 LDFLAGS=-e 0 -T linker.cfg
-CFLAGS=-O2 -mcpu=arm9 -ffreestanding -I${.CURDIR}/../inc
+CFLAGS=-O2 -mcpu=arm9 -ffreestanding -I${.CURDIR}/../libat91
 CFLAGS+=-DBOOT0_KB9202
 #CFLAGS+=-DBOOT0_TSC
 OBJS+=  ${SRCS:N*.h:R:S/$/.o/g}

==== //depot/projects/arm/src/sys/boot/arm/at91/boot0/at91rm9200_lowlevel.c#6 (text) ====

@@ -27,7 +27,7 @@
  * $FreeBSD: src/sys/boot/arm/at91/boot0/at91rm9200_lowlevel.c,v 1.2 2006/04/13 17:39:34 imp Exp $
  */
 
-#include "AT91RM9200.h"
+#include "at91rm9200.h"
 #include "at91rm9200_lowlevel.h"
 
 #define BAUD	115200

==== //depot/projects/arm/src/sys/boot/arm/at91/boot0/lib.c#2 (text) ====

@@ -34,7 +34,7 @@
  * $FreeBSD: src/sys/boot/arm/at91/boot0/lib.c,v 1.1 2006/04/12 21:22:44 imp Exp $
  */
 
-#include "AT91RM9200.h"
+#include "at91rm9200.h"
 #include "at91rm9200_lowlevel.h"
 
 /*

==== //depot/projects/arm/src/sys/boot/arm/at91/boot0/main.c#4 (text) ====

@@ -24,7 +24,7 @@
  * $FreeBSD: src/sys/boot/arm/at91/boot0/main.c,v 1.2 2006/04/13 17:31:02 imp Exp $
  */
 
-#include "AT91RM9200.h"
+#include "at91rm9200.h"
 #include "lib.h"
 #include "at91rm9200_lowlevel.h"
 

==== //depot/projects/arm/src/sys/boot/arm/at91/bootiic/debug_io.c#3 (text+ko) ====

@@ -1,61 +1,61 @@
-/*******************************************************************************
- *
- * Filename: debug_io.c
- *
- * Instantiation of routines for basic debug uart support.
- *
- * Revision information:
- *
- * 20AUG2004	kb_admin	initial creation
- *
- * BEGIN_KBDD_BLOCK
- * No warranty, expressed or implied, is included with this software.  It is
- * provided "AS IS" and no warranty of any kind including statutory or aspects
- * relating to merchantability or fitness for any purpose is provided.  All
- * intellectual property rights of others is maintained with the respective
- * owners.  This software is not copyrighted and is intended for reference
- * only.
- * END_BLOCK
- ******************************************************************************/
-
-#include "AT91RM9200.h"
-#include "p_string.h"
-
-/*
- * .KB_C_FN_DEFINITION_START
- * void DebugPrint(char *)
- *  This global function writes a string to the debug uart port.
- * .KB_C_FN_DEFINITION_END
- */
-void DebugPrint(char *buffer) {
-
-	if (!buffer) return;
-
-	while(*buffer != '\0')
-		putc(*buffer++);
-}
-
-/*
- * .KB_C_FN_DEFINITION_START
- * void DebugPrintHex(int, int)
- *  This global function displays the value with the number of digits specified.
- * .KB_C_FN_DEFINITION_END
- */
-void DebugPrintHex(int digits, int value) {
-
-	char	dValue[11], *cPtr;
-	int	nextDigit;
-
-	if ((digits < 1) || (digits > 8)) return ;
-
-	cPtr = &dValue[10];
-	*cPtr-- = 0;
-	while (digits--) {
-		nextDigit = 0xF & value;
-		*cPtr-- = ToASCII(nextDigit);
-		value >>= 4;
-	}
-	*cPtr-- = 'x';
-	*cPtr = '0';
-	DebugPrint(cPtr);
-}
+/*******************************************************************************
+ *
+ * Filename: debug_io.c
+ *
+ * Instantiation of routines for basic debug uart support.
+ *
+ * Revision information:
+ *
+ * 20AUG2004	kb_admin	initial creation
+ *
+ * BEGIN_KBDD_BLOCK
+ * No warranty, expressed or implied, is included with this software.  It is
+ * provided "AS IS" and no warranty of any kind including statutory or aspects
+ * relating to merchantability or fitness for any purpose is provided.  All
+ * intellectual property rights of others is maintained with the respective
+ * owners.  This software is not copyrighted and is intended for reference
+ * only.
+ * END_BLOCK
+ ******************************************************************************/
+
+#include "at91rm9200.h"
+#include "p_string.h"
+
+/*
+ * .KB_C_FN_DEFINITION_START
+ * void DebugPrint(char *)
+ *  This global function writes a string to the debug uart port.
+ * .KB_C_FN_DEFINITION_END
+ */
+void DebugPrint(char *buffer) {
+
+	if (!buffer) return;
+
+	while(*buffer != '\0')
+		putc(*buffer++);
+}
+
+/*
+ * .KB_C_FN_DEFINITION_START
+ * void DebugPrintHex(int, int)
+ *  This global function displays the value with the number of digits specified.
+ * .KB_C_FN_DEFINITION_END
+ */
+void DebugPrintHex(int digits, int value) {
+
+	char	dValue[11], *cPtr;
+	int	nextDigit;
+
+	if ((digits < 1) || (digits > 8)) return ;
+
+	cPtr = &dValue[10];
+	*cPtr-- = 0;
+	while (digits--) {
+		nextDigit = 0xF & value;
+		*cPtr-- = ToASCII(nextDigit);
+		value >>= 4;
+	}
+	*cPtr-- = 'x';
+	*cPtr = '0';
+	DebugPrint(cPtr);
+}

==== //depot/projects/arm/src/sys/boot/arm/at91/bootiic/eeprom.c#3 (text+ko) ====

@@ -1,167 +1,167 @@
-/*******************************************************************************
- *
- * Filename: eeprom.c
- *
- * Instantiation of eeprom routines
- *
- * Revision information:
- *
- * 28AUG2004	kb_admin	initial creation - adapted from Atmel sources
- * 12JAN2005	kb_admin	fixed clock generation, write polling, init
- *
- * BEGIN_KBDD_BLOCK
- * No warranty, expressed or implied, is included with this software.  It is
- * provided "AS IS" and no warranty of any kind including statutory or aspects
- * relating to merchantability or fitness for any purpose is provided.  All
- * intellectual property rights of others is maintained with the respective
- * owners.  This software is not copyrighted and is intended for reference
- * only.
- * END_BLOCK
- ******************************************************************************/
-
-#include "at91rm9200_lowlevel.h"
-#include "eeprom.h"
-#include "AT91RM9200.h"
-
-/* ****************************** GLOBALS *************************************/
-
-
-/* ********************** PRIVATE FUNCTIONS/DATA ******************************/
-
-
-/* Use a macro to calculate the TWI clock generator value to save code space. */
-#define TWI_CLK_BASE_DIV	((AT91C_MASTER_CLOCK/(4*AT91C_TWSI_CLOCK)) - 2)
-#define SET_TWI_CLOCK	((0x00010000) | (TWI_CLK_BASE_DIV) | (TWI_CLK_BASE_DIV << 8))
-
-
-/* ************************** GLOBAL FUNCTIONS ********************************/
-
-
-/*
- * .KB_C_FN_DEFINITION_START
- * void InitEEPROM(void)
- *  This global function initializes the EEPROM interface (TWI).  Intended
- * to be called a single time.
- * .KB_C_FN_DEFINITION_END
- */
-void
-InitEEPROM(void)
-{
-
-	AT91PS_TWI twiPtr = (AT91PS_TWI)AT91C_BASE_TWI;
-
-	AT91PS_PIO pPio = (AT91PS_PIO)AT91C_BASE_PIOA;
-	AT91PS_PMC pPMC = (AT91PS_PMC)AT91C_BASE_PMC;
-
-	pPio->PIO_ASR = AT91C_PA25_TWD | AT91C_PA26_TWCK;
-	pPio->PIO_PDR = AT91C_PA25_TWD | AT91C_PA26_TWCK;
-
-	pPio->PIO_MDDR = ~AT91C_PA25_TWD;
-	pPio->PIO_MDER = AT91C_PA25_TWD;
-
-	pPMC->PMC_PCER = 1u << AT91C_ID_TWI;
-
-	twiPtr->TWI_IDR = 0xffffffffu;
-	twiPtr->TWI_CR = AT91C_TWI_SWRST;
-	twiPtr->TWI_CR = AT91C_TWI_MSEN | AT91C_TWI_SVDIS;
-
-	twiPtr->TWI_CWGR = SET_TWI_CLOCK;
-}
-
-
-/*
- * .KB_C_FN_DEFINITION_START
- * void ReadEEPROM(unsigned ee_addr, char *data_addr, unsigned size)
- *  This global function reads data from the eeprom at ee_addr storing data
- * to data_addr for size bytes.  Assume the TWI has been initialized.
- * This function does not utilize the page read mode to simplify the code.
- * .KB_C_FN_DEFINITION_END
- */
-void ReadEEPROM(unsigned ee_addr, char *data_addr, unsigned size) {
-
-	const AT91PS_TWI 	twiPtr = AT91C_BASE_TWI;
-	unsigned int status;
-
-	status = twiPtr->TWI_SR;
-	status = twiPtr->TWI_RHR;
-
-	// Set the TWI Master Mode Register
-	twiPtr->TWI_MMR = (TWSI_EEPROM_ADDRESS << 16) | AT91C_TWI_IADRSZ_2_BYTE | AT91C_TWI_MREAD;
-
-	// Set TWI Internal Address Register
-	twiPtr->TWI_IADR = ee_addr;
-
-	// Start transfer
-	twiPtr->TWI_CR = AT91C_TWI_START;
-
-	status = twiPtr->TWI_SR;
-
-	while (size-- > 1){
-
-		// Wait RHR Holding register is full
-		while (!(twiPtr->TWI_SR & AT91C_TWI_RXRDY));
-
-		// Read byte
-		*(data_addr++) = twiPtr->TWI_RHR;
-	}
-
-	twiPtr->TWI_CR = AT91C_TWI_STOP;
-
-	status = twiPtr->TWI_SR;
-
-	// Wait transfer is finished
-	while (!(twiPtr->TWI_SR & AT91C_TWI_TXCOMP));
-
-	// Read last byte
-	*data_addr = twiPtr->TWI_RHR;
-}
-
-
-/*
- * .KB_C_FN_DEFINITION_START
- * void WriteEEPROM(unsigned ee_addr, char *data_addr, unsigned size)
- *  This global function writes data to the eeprom at ee_addr using data
- * from data_addr for size bytes.  Assume the TWI has been initialized.
- * This function does not utilize the page write mode as the write time is
- * much greater than the time required to access the device for byte-write
- * functionality.  This allows the function to be much simpler.
- * .KB_C_FN_DEFINITION_END
- */
-void WriteEEPROM(unsigned ee_addr, char *data_addr, unsigned size) {
-
-	const AT91PS_TWI 	twiPtr = AT91C_BASE_TWI;
-	unsigned		status;
-	char			test_data;
-
-	while (size--) {
-		if (!(ee_addr & 0x3f))
-			DebugPrint(".");
-
-		// Set the TWI Master Mode Register
-		twiPtr->TWI_MMR = ((TWSI_EEPROM_ADDRESS << 16) | AT91C_TWI_IADRSZ_2_BYTE ) & ~AT91C_TWI_MREAD;
-
-		// Set TWI Internal Address Register
-		twiPtr->TWI_IADR = ee_addr++;
-
-		status = twiPtr->TWI_SR;
-
-		twiPtr->TWI_THR = *(data_addr++);
-
-		twiPtr->TWI_CR = AT91C_TWI_START;
-
-		// Wait transfer is finished
-		while (!(twiPtr->TWI_SR & AT91C_TWI_TXRDY));
-
-		twiPtr->TWI_CR = AT91C_TWI_STOP;
-
-		status = twiPtr->TWI_SR;
-
-		// Wait transfer is finished
-		while (!(twiPtr->TWI_SR & AT91C_TWI_TXCOMP));
-
-		// wait for write operation to complete
-		ReadEEPROM(ee_addr, &test_data, 1);
-	}
-
-	DebugPrint("\n\r");
-}
+/*******************************************************************************
+ *
+ * Filename: eeprom.c
+ *
+ * Instantiation of eeprom routines
+ *
+ * Revision information:
+ *
+ * 28AUG2004	kb_admin	initial creation - adapted from Atmel sources
+ * 12JAN2005	kb_admin	fixed clock generation, write polling, init
+ *
+ * BEGIN_KBDD_BLOCK
+ * No warranty, expressed or implied, is included with this software.  It is
+ * provided "AS IS" and no warranty of any kind including statutory or aspects
+ * relating to merchantability or fitness for any purpose is provided.  All
+ * intellectual property rights of others is maintained with the respective
+ * owners.  This software is not copyrighted and is intended for reference
+ * only.
+ * END_BLOCK
+ ******************************************************************************/
+
+#include "at91rm9200_lowlevel.h"
+#include "eeprom.h"
+#include "at91rm9200.h"
+
+/* ****************************** GLOBALS *************************************/
+
+
+/* ********************** PRIVATE FUNCTIONS/DATA ******************************/
+
+
+/* Use a macro to calculate the TWI clock generator value to save code space. */
+#define TWI_CLK_BASE_DIV	((AT91C_MASTER_CLOCK/(4*AT91C_TWSI_CLOCK)) - 2)
+#define SET_TWI_CLOCK	((0x00010000) | (TWI_CLK_BASE_DIV) | (TWI_CLK_BASE_DIV << 8))
+
+
+/* ************************** GLOBAL FUNCTIONS ********************************/
+
+
+/*
+ * .KB_C_FN_DEFINITION_START
+ * void InitEEPROM(void)
+ *  This global function initializes the EEPROM interface (TWI).  Intended
+ * to be called a single time.
+ * .KB_C_FN_DEFINITION_END
+ */
+void
+InitEEPROM(void)
+{
+
+	AT91PS_TWI twiPtr = (AT91PS_TWI)AT91C_BASE_TWI;
+
+	AT91PS_PIO pPio = (AT91PS_PIO)AT91C_BASE_PIOA;
+	AT91PS_PMC pPMC = (AT91PS_PMC)AT91C_BASE_PMC;
+
+	pPio->PIO_ASR = AT91C_PA25_TWD | AT91C_PA26_TWCK;
+	pPio->PIO_PDR = AT91C_PA25_TWD | AT91C_PA26_TWCK;
+
+	pPio->PIO_MDDR = ~AT91C_PA25_TWD;
+	pPio->PIO_MDER = AT91C_PA25_TWD;
+
+	pPMC->PMC_PCER = 1u << AT91C_ID_TWI;
+
+	twiPtr->TWI_IDR = 0xffffffffu;
+	twiPtr->TWI_CR = AT91C_TWI_SWRST;
+	twiPtr->TWI_CR = AT91C_TWI_MSEN | AT91C_TWI_SVDIS;
+
+	twiPtr->TWI_CWGR = SET_TWI_CLOCK;
+}
+
+
+/*
+ * .KB_C_FN_DEFINITION_START
+ * void ReadEEPROM(unsigned ee_addr, char *data_addr, unsigned size)
+ *  This global function reads data from the eeprom at ee_addr storing data
+ * to data_addr for size bytes.  Assume the TWI has been initialized.
+ * This function does not utilize the page read mode to simplify the code.
+ * .KB_C_FN_DEFINITION_END
+ */
+void ReadEEPROM(unsigned ee_addr, char *data_addr, unsigned size) {
+
+	const AT91PS_TWI 	twiPtr = AT91C_BASE_TWI;
+	unsigned int status;
+
+	status = twiPtr->TWI_SR;
+	status = twiPtr->TWI_RHR;
+
+	// Set the TWI Master Mode Register
+	twiPtr->TWI_MMR = (TWSI_EEPROM_ADDRESS << 16) | AT91C_TWI_IADRSZ_2_BYTE | AT91C_TWI_MREAD;
+
+	// Set TWI Internal Address Register
+	twiPtr->TWI_IADR = ee_addr;
+
+	// Start transfer
+	twiPtr->TWI_CR = AT91C_TWI_START;
+
+	status = twiPtr->TWI_SR;
+
+	while (size-- > 1){
+
+		// Wait RHR Holding register is full
+		while (!(twiPtr->TWI_SR & AT91C_TWI_RXRDY));
+
+		// Read byte
+		*(data_addr++) = twiPtr->TWI_RHR;
+	}
+
+	twiPtr->TWI_CR = AT91C_TWI_STOP;
+
+	status = twiPtr->TWI_SR;
+
+	// Wait transfer is finished
+	while (!(twiPtr->TWI_SR & AT91C_TWI_TXCOMP));
+
+	// Read last byte
+	*data_addr = twiPtr->TWI_RHR;
+}
+
+
+/*
+ * .KB_C_FN_DEFINITION_START
+ * void WriteEEPROM(unsigned ee_addr, char *data_addr, unsigned size)
+ *  This global function writes data to the eeprom at ee_addr using data
+ * from data_addr for size bytes.  Assume the TWI has been initialized.
+ * This function does not utilize the page write mode as the write time is
+ * much greater than the time required to access the device for byte-write
+ * functionality.  This allows the function to be much simpler.
+ * .KB_C_FN_DEFINITION_END
+ */
+void WriteEEPROM(unsigned ee_addr, char *data_addr, unsigned size) {
+
+	const AT91PS_TWI 	twiPtr = AT91C_BASE_TWI;
+	unsigned		status;
+	char			test_data;
+
+	while (size--) {
+		if (!(ee_addr & 0x3f))
+			DebugPrint(".");
+
+		// Set the TWI Master Mode Register
+		twiPtr->TWI_MMR = ((TWSI_EEPROM_ADDRESS << 16) | AT91C_TWI_IADRSZ_2_BYTE ) & ~AT91C_TWI_MREAD;
+
+		// Set TWI Internal Address Register
+		twiPtr->TWI_IADR = ee_addr++;
+
+		status = twiPtr->TWI_SR;
+
+		twiPtr->TWI_THR = *(data_addr++);
+
+		twiPtr->TWI_CR = AT91C_TWI_START;
+
+		// Wait transfer is finished
+		while (!(twiPtr->TWI_SR & AT91C_TWI_TXRDY));
+
+		twiPtr->TWI_CR = AT91C_TWI_STOP;
+
+		status = twiPtr->TWI_SR;
+
+		// Wait transfer is finished
+		while (!(twiPtr->TWI_SR & AT91C_TWI_TXCOMP));
+
+		// wait for write operation to complete
+		ReadEEPROM(ee_addr, &test_data, 1);
+	}
+
+	DebugPrint("\n\r");
+}

==== //depot/projects/arm/src/sys/boot/arm/at91/bootiic/emac.c#3 (text+ko) ====

@@ -1,689 +1,689 @@
-/*******************************************************************************
- *
- * Filename: emac.c
- *
- * Instantiation of routines for MAC/ethernet functions supporting tftp.
- *
- * Revision information:
- *
- * 28AUG2004	kb_admin	initial creation
- * 08JAN2005	kb_admin	added tftp download
- *					also adapted from external sources
- *
- * BEGIN_KBDD_BLOCK
- * No warranty, expressed or implied, is included with this software.  It is
- * provided "AS IS" and no warranty of any kind including statutory or aspects
- * relating to merchantability or fitness for any purpose is provided.  All
- * intellectual property rights of others is maintained with the respective
- * owners.  This software is not copyrighted and is intended for reference
- * only.
- * END_BLOCK
- ******************************************************************************/
-
-#include "AT91RM9200.h"
-#include "emac.h"
-#include "p_string.h"
-#include "at91rm9200_lowlevel.h"
-
-/* ****************************** GLOBALS *************************************/
-
-/* ********************** PRIVATE FUNCTIONS/DATA ******************************/
-
-static unsigned localMACSet, serverMACSet, MAC_init;
-static unsigned char localMACAddr[6], serverMACAddr[6];
-static unsigned localIPSet, serverIPSet;
-static unsigned char localIPAddr[4], serverIPAddr[4];
-static unsigned short	serverPort, localPort;
-static int	ackBlock;
-
-static unsigned	lastAddress, lastSize;
-static char *dlAddress;
-
-static unsigned transmitBuffer[1024 / sizeof(unsigned)];
-static unsigned tftpSendPacket[256 / sizeof(unsigned)];
-
-receive_descriptor_t *p_rxBD;
-
-
-/*
- * .KB_C_FN_DEFINITION_START
- * unsigned short IP_checksum(unsigned short *p, int len)
- *  This private function calculates the IP checksum for various headers.
- * .KB_C_FN_DEFINITION_END
- */
-static unsigned short IP_checksum(unsigned short *p, int len) 
-{
-	unsigned	i, t;
-
-	len &= ~1;
-
-	for (i=0,t=0; i<len; i+=2, ++p)
-		t += SWAP16(*p);
-
-	t = (t & 0xffff) + (t >> 16);
-	return (~t);									
-}
-
-
-/*
- * .KB_C_FN_DEFINITION_START
- * void GetServerAddress(void)
- *  This private function sends an ARP request to determine the server MAC.
- * .KB_C_FN_DEFINITION_END
- */
-static void GetServerAddress(void) {
-
-	arp_header_t	*p_ARP;
-
-	p_ARP = (arp_header_t*)transmitBuffer;
-
-	p_memset((char*)p_ARP->dest_mac, 0xFF, 6);
-
-	p_memcpy((char*)p_ARP->src_mac, (char*)localMACAddr, 6);
-
-	p_ARP->frame_type = SWAP16(PROTOCOL_ARP);
-	p_ARP->hard_type  = SWAP16(1);
-	p_ARP->prot_type  = SWAP16(PROTOCOL_IP);
-	p_ARP->hard_size  = 6;
-	p_ARP->prot_size  = 4;
-	p_ARP->operation  = SWAP16(ARP_REQUEST);
-
-	p_memcpy((char*)p_ARP->sender_mac, (char*)localMACAddr, 6);
-
-	p_memcpy((char*)p_ARP->sender_ip, (char*)localIPAddr, 4);
-
-	p_memset((char*)p_ARP->target_mac, 0, 6);
-
-	p_memcpy((char*)p_ARP->target_ip, (char*)serverIPAddr, 4);
-
-	// wait until transmit is available
-	while (!(*AT91C_EMAC_TSR & AT91C_EMAC_BNQ)) ;
-
-  	*AT91C_EMAC_TSR |= AT91C_EMAC_COMP;
-	*AT91C_EMAC_TAR = (unsigned)transmitBuffer;
-	*AT91C_EMAC_TCR = 0x40;
-}
-
-
-/*
- * .KB_C_FN_DEFINITION_START
- * void Send_TFTP_Packet(char *tftpData, unsigned tftpLength)
- *  This private function initializes and send a TFTP packet.
- * .KB_C_FN_DEFINITION_END
- */
-static void Send_TFTP_Packet(char *tftpData, unsigned tftpLength)
-{
-	transmit_header_t	*macHdr = (transmit_header_t*)tftpSendPacket;
-	ip_header_t		*ipHdr;
-	udp_header_t		*udpHdr;
-	unsigned		t_checksum;
-
-	p_memcpy((char*)macHdr->dest_mac, (char*)serverMACAddr, 6);
-
-	p_memcpy((char*)macHdr->src_mac, (char*)localMACAddr, 6);
-
-	*(unsigned short*)&(macHdr->ip_tos) = SWAP16(PROTOCOL_IP);
-
-	ipHdr = (ip_header_t*)&macHdr->packet_length;
-
-	ipHdr->ip_v_hl = 0x45;
-	ipHdr->ip_tos = 0;
-	ipHdr->ip_len = SWAP16(28 + tftpLength);
-	ipHdr->ip_id = 0;
-	ipHdr->ip_off = SWAP16(0x4000);
-	ipHdr->ip_ttl = 64;
-	ipHdr->ip_p = PROTOCOL_UDP;
-	ipHdr->ip_sum = 0;
-
-	p_memcpy((char*)ipHdr->ip_src, (char*)localIPAddr, 4);
-
-	p_memcpy((char*)ipHdr->ip_dst, (char*)serverIPAddr, 4);
-
-	ipHdr->ip_sum = SWAP16(IP_checksum((unsigned short*)ipHdr, 20));
-
-	udpHdr = (udp_header_t*)(ipHdr + 1);
-
-	udpHdr->src_port  = SWAP16(localPort);
-	udpHdr->dst_port  = SWAP16(serverPort);
-	udpHdr->udp_len   = SWAP16(8 + tftpLength);
-	udpHdr->udp_cksum = 0;
-
-	p_memcpy((char*)udpHdr+8, tftpData, tftpLength);
-
-	t_checksum = IP_checksum((unsigned short*)ipHdr + 6, (16 + tftpLength));
-
-	t_checksum = (~t_checksum) & 0xFFFF;
-	t_checksum += 25 + tftpLength;
-
-	t_checksum = (t_checksum & 0xffff) + (t_checksum >> 16);
-	t_checksum = (~t_checksum) & 0xFFFF;
-
-	udpHdr->udp_cksum = SWAP16(t_checksum);
-
-	while (!(*AT91C_EMAC_TSR & AT91C_EMAC_BNQ)) ;
-
-  	*AT91C_EMAC_TSR |= AT91C_EMAC_COMP;
-	*AT91C_EMAC_TAR = (unsigned)tftpSendPacket;
-	*AT91C_EMAC_TCR = 42 + tftpLength;
-}
-
-
-/*
- * .KB_C_FN_DEFINITION_START
- * void TFTP_RequestFile(char *filename)
- *  This private function sends a RRQ packet to the server.
- * .KB_C_FN_DEFINITION_END
- */
-static void TFTP_RequestFile(char *filename) {
-
-	tftp_header_t	tftpHeader;
-	char		*cPtr, *ePtr, *mPtr;
-	unsigned	length;
-
-	tftpHeader.opcode = SWAP16(TFTP_RRQ_OPCODE);
-
-	cPtr = (char*)&(tftpHeader.block_num);
-
-	ePtr = p_strcpy(cPtr, filename);
-	mPtr = p_strcpy(ePtr, "octet");
-
-	length = mPtr - cPtr;
-	length += 2;
-	
-	Send_TFTP_Packet((char*)&tftpHeader, length);
-}
-
-
-/*
- * .KB_C_FN_DEFINITION_START
- * void TFTP_ACK_Data(char *data, unsigned short block_num, unsigned short len)
- *  This private function sends an ACK packet to the server.
- * .KB_C_FN_DEFINITION_END
- */
-static void TFTP_ACK_Data(char *data, unsigned short block_num, unsigned short len) {
-
-	tftp_header_t	tftpHeader;
-
-	if (block_num == (ackBlock + 1)) {
-		++ackBlock;
-		p_memcpy(dlAddress, data, len);
-		dlAddress += len;
-		lastSize += len;
-	}
-
-	tftpHeader.opcode = SWAP16(TFTP_ACK_OPCODE);
-	tftpHeader.block_num = SWAP16(block_num);
-	Send_TFTP_Packet((char*)&tftpHeader, 4);
-
-	if (len < 512)
-		ackBlock = -2;
-}
-
-
-/*
- * .KB_C_FN_DEFINITION_START
- * void CheckForNewPacket(ip_header_t *pHeader)
- *  This private function polls for received ethernet packets and handles
- * any here.
- * .KB_C_FN_DEFINITION_END
- */
-static void CheckForNewPacket(ip_header_t *pHeader) {
-
-	unsigned short	*pFrameType, *pArpOp;
-	unsigned	i;
-	char		*pData;
-	ip_header_t	*pIpHeader;
-	arp_header_t	*p_ARP;
-	int		process = 0;
-	
-	process = 0;	
-	for (i = 0; i < MAX_RX_PACKETS; ++i) {				
-		if(p_rxBD[i].address & 0x1) {
-			process = 1;	
-			(*AT91C_EMAC_RSR) |= (*AT91C_EMAC_RSR);
-			break;				
-		}
-	}
-		
-	if (!process)
-		return ;
-						
-	process = i;
-		
-	pFrameType = (unsigned short *) ((p_rxBD[i].address & 0xFFFFFFFC) + 12);
-	pData      = (char *)(p_rxBD[i].address & 0xFFFFFFFC);
-
-	switch (SWAP16(*pFrameType)) {
-
-	case PROTOCOL_ARP:
-
-		pArpOp = (unsigned short *) (pData + 20);
-		p_ARP = (arp_header_t*)pData;
-
-		if (SWAP16(*pArpOp) == ARP_REPLY) {
-
-			// check if new server info is available
-			if ((!serverMACSet) &&
-				(!(p_memcmp((char*)p_ARP->sender_ip,
-					(char*)serverIPAddr, 4)))) {
-
-				serverMACSet = 1;
-
-				p_memcpy((char*)serverMACAddr,
-					(char*)p_ARP->sender_mac, 6);
-			}
-		}
-
-		if (SWAP16(*pArpOp) == ARP_REQUEST) {
-
-			// ARP REPLY operation
-			*pArpOp =  SWAP16(ARP_REPLY);				
-
-			// Fill the dest address and src address
-			for (i = 0; i <6; i++) {
-				// swap ethernet dest address and ethernet src address
-				pData[i] = pData[i+6];
-				pData[i+6] = localMACAddr[i];
-				// swap sender ethernet address and target ethernet address
-				pData[i+22] = localMACAddr[i];
-				pData[i+32] = pData[i+6];
-			}									
-
-			// swap sender IP address and target IP address
-			for (i = 0; i<4; i++) {				
-				pData[i+38] = pData[i+28];
-				pData[i+28] = localIPAddr[i];
-			}
-
-			if (!(*AT91C_EMAC_TSR & AT91C_EMAC_BNQ)) break;
-
-		  	*AT91C_EMAC_TSR |= AT91C_EMAC_COMP;
-			*AT91C_EMAC_TAR = (unsigned)pData;
- 			*AT91C_EMAC_TCR = 0x40;
-		}
-	break;
-		
-	case PROTOCOL_IP:
-		pIpHeader = (ip_header_t*)(pData + 14);			
-		p_memcpy((char*)pHeader, (char*)pIpHeader,sizeof(ip_header_t));
-		
-		switch(pIpHeader->ip_p) {
-
-		case PROTOCOL_UDP:
-		{
-			udp_header_t	*udpHdr;
-			tftp_header_t	*tftpHdr;
-
-			udpHdr = (udp_header_t*)((char*)pIpHeader+20);
-			tftpHdr = (tftp_header_t*)((char*)udpHdr + 8);
-
-			if (SWAP16(udpHdr->dst_port) != localPort)
-				break;
-
-			if (SWAP16(tftpHdr->opcode) != TFTP_DATA_OPCODE)
-				break;
-
-			if (ackBlock == -1) {
-				if (SWAP16(tftpHdr->block_num) != 1)
-						break;
-					serverPort = SWAP16(udpHdr->src_port);
-					ackBlock = 0;
-				}
-
-			if (serverPort != SWAP16(udpHdr->src_port))
-				break;
-
-			TFTP_ACK_Data(tftpHdr->data,
-				SWAP16(tftpHdr->block_num),
-				SWAP16(udpHdr->udp_len) - 12);
-		}
-		break;
-
-		default:
-			break;
-		}
-	break;
-						
-	default:
-		break;
-	}
-	p_rxBD[process].address &= ~0x01;
-}
-
-
-/*
- * .KB_C_FN_DEFINITION_START
- * unsigned short AT91F_MII_ReadPhy (AT91PS_EMAC pEmac, unsigned char addr)
- *  This private function reads the PHY device.
- * .KB_C_FN_DEFINITION_END
- */
-static unsigned short AT91F_MII_ReadPhy (AT91PS_EMAC pEmac, unsigned char addr) {
-
-	unsigned value = 0x60020000 | (addr << 18);
-
-	pEmac->EMAC_CTL |= AT91C_EMAC_MPE;
-	pEmac->EMAC_MAN = value;
-  	while(!((pEmac->EMAC_SR) & AT91C_EMAC_IDLE));
-	pEmac->EMAC_CTL &= ~AT91C_EMAC_MPE;
-	return (pEmac->EMAC_MAN & 0x0000ffff);
-}
-
-
-/*
- * .KB_C_FN_DEFINITION_START
- * void MII_GetLinkSpeed(AT91PS_EMAC pEmac)
- *  This private function determines the link speed set by the PHY.
- * .KB_C_FN_DEFINITION_END
- */
-static void MII_GetLinkSpeed(AT91PS_EMAC pEmac) {
-
-	unsigned short stat2; 
-	unsigned update = 0;
-  
-	stat2 = AT91F_MII_ReadPhy(pEmac, MII_STS2_REG);
-
-	if (!(stat2 & 0x400)) {
-		return ;
-
-	} else if (stat2 & 0x4000) {
-
-		update |= AT91C_EMAC_SPD;
-
-		if (stat2 & 0x200) {
-			update |= AT91C_EMAC_FD;
-		}
-
-	} else if (stat2 & 0x200) {
-		update |= AT91C_EMAC_FD;
-	}
-
-	pEmac->EMAC_CFG =
-		(pEmac->EMAC_CFG & ~(AT91C_EMAC_SPD | AT91C_EMAC_FD)) | update;
-}
-
-
-/*
- * .KB_C_FN_DEFINITION_START
- * void AT91F_EmacEntry(void)
- *  This private function initializes the EMAC on the chip.
- * .KB_C_FN_DEFINITION_END
- */
-void AT91F_EmacEntry(void) {
-
-	unsigned	i;
-	char		*pRxPacket = (char*)RX_DATA_START;
-	AT91PS_EMAC	pEmac = AT91C_BASE_EMAC;
-
-	for (i = 0; i < MAX_RX_PACKETS; ++i) {
-
-		p_rxBD[i].address = (unsigned)pRxPacket;
-		p_rxBD[i].size = 0;
-		pRxPacket += RX_PACKET_SIZE;
-	}
-	
-	// Set the WRAP bit at the end of the list descriptor
-	p_rxBD[MAX_RX_PACKETS-1].address |= 0x02;
-
-	pEmac->EMAC_CTL  = 0;
-
-	if(!(pEmac->EMAC_SR & AT91C_EMAC_LINK))
-		MII_GetLinkSpeed(pEmac);
-
-	// the sequence write EMAC_SA1L and write EMAC_SA1H must be respected
-	pEmac->EMAC_SA1L = ((unsigned)localMACAddr[2] << 24) | ((unsigned)localMACAddr[3] << 16) | ((int)localMACAddr[4] << 8) | localMACAddr[5];
-	pEmac->EMAC_SA1H = ((unsigned)localMACAddr[0] << 8) | localMACAddr[1];
-
-	pEmac->EMAC_RBQP = (unsigned) p_rxBD;
-	pEmac->EMAC_RSR  |= (AT91C_EMAC_OVR | AT91C_EMAC_REC | AT91C_EMAC_BNA);
-	pEmac->EMAC_CFG  |= AT91C_EMAC_CAF;
-	pEmac->EMAC_CFG  = (pEmac->EMAC_CFG & ~(AT91C_EMAC_CLK)) |
-		AT91C_EMAC_CLK_HCLK_32;
-	pEmac->EMAC_CTL  |= (AT91C_EMAC_TE | AT91C_EMAC_RE);
-
-	pEmac->EMAC_TAR = (unsigned)transmitBuffer;
-}	
-
-
-/* ************************** GLOBAL FUNCTIONS ********************************/
-
-
-/*
- * .KB_C_FN_DEFINITION_START
- * void SetMACAddress(unsigned low_address, unsigned high_address)
- *  This global function sets the MAC address.  low_address is the first
- * four bytes while high_address is the last 2 bytes of the 48-bit value.
- * .KB_C_FN_DEFINITION_END
- */
-void SetMACAddress(unsigned low_address, unsigned high_address) {
-
-	AT91PS_EMAC	pEmac = AT91C_BASE_EMAC;
-	AT91PS_PMC	pPMC = AT91C_BASE_PMC;
-
-	/* enable the peripheral clock before using EMAC */
-	pPMC->PMC_PCER = ((unsigned) 1 << AT91C_ID_EMAC);
-

>>> TRUNCATED FOR MAIL (1000 lines) <<<



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200604172044.k3HKiYx3050329>