From c1ff9a7181ebb170c9c3dac35929e06f20bf6b09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Fr=C3=B6schle?= Date: Tue, 24 Dec 2013 10:41:43 +0000 Subject: [PATCH] further implemented bootp protocol --- include/bootp.h | 29 ++-- include/nbuf.h | 154 +++++++++---------- include/net.h | 4 +- include/net_timer.h | 3 +- include/tftp.h | 2 - net/bootp.c | 190 ++++++------------------ net/net_timer.c | 355 ++++++++++++++++++++++---------------------- sys/interrupts.c | 214 +++++++++++++------------- 8 files changed, 427 insertions(+), 524 deletions(-) diff --git a/include/bootp.h b/include/bootp.h index 08eaa17..ec62e40 100644 --- a/include/bootp.h +++ b/include/bootp.h @@ -8,12 +8,28 @@ #ifndef _BOOTP_H_ #define _BOOTP_H_ -/********************************************************************/ +#define BOOTP_SERVER_PORT 67 +#define BOOTP_CLIENT_PORT 68 + +/* protocol header information */ +#define BOOTP_HDR_OFFSET (ETH_HDR_LEN + IP_HDR_SIZE + UDP_HDR_SIZE) + +/* timeout in seconds */ +#define BOOTP_TIMEOUT 2 + +/* BOOTP connection status */ + +struct bootp_connection +{ + bool open; /* connection established flag */ + NIF *nif; /* pointer to network interface */ + IP_ADDR server_ip; /* server IP address */ +}; /* * This data definition is defined for Ethernet only! */ -typedef struct +struct bootp_packet { uint8_t type; /* bootp operation type */ uint8_t htype; /* hardware type */ @@ -29,9 +45,9 @@ typedef struct uint8_t sname[64]; /* server name */ uint8_t file[128]; /* name of bootfile */ uint8_t vend[64]; /* vendor specific (see below) */ -} bootp_frame_hdr; +}; -#define BOOTP_HDR_LEN sizeof(bootp_frame_hdr) +#define BOOTP_PACKET_LEN (BOOTP_HDR_OFFSET + sizeof(struct bootp_packet)) /* possible values for type field */ #define BOOTP_TYPE_BOOTREQUEST 1 @@ -46,11 +62,6 @@ typedef struct /* values for flags - only broadcast flag in use */ #define BOOTP_FLAGS_BROADCAST 1 -#define BOOTP_TIMEOUT (1) /* Timeout in seconds */ - -/* Protocol Header information */ -#define BOOTP_HDR_OFFSET ETH_HDR_LEN - extern void bootp_request(NIF *, uint8_t *); extern void bootp_handler(NIF *, NBUF *); //extern void bootp_init(BOOTP_INFO *); diff --git a/include/nbuf.h b/include/nbuf.h index ca6da52..62acf02 100644 --- a/include/nbuf.h +++ b/include/nbuf.h @@ -1,85 +1,69 @@ -/* - * File: nbuf.h - * Purpose: Definitions for network buffer management - * - * Notes: These routines implement a network buffer scheme - */ - -#ifndef _NBUF_H_ -#define _NBUF_H_ - -/********************************************************************/ -/* - * Include the Queue structure definitions - */ -#include "queue.h" - -/* - * Number of network buffers to use - */ -#define NBUF_MAX 30 - -/* - * Size of each buffer in bytes - */ -#ifndef NBUF_SZ -#define NBUF_SZ 1520 -#endif - -/* - * Defines to identify all the buffer queues - * - FREE must always be defined as 0 - */ -#define NBUF_FREE 0 /* available buffers */ -#define NBUF_TX_RING 1 /* buffers in the Tx BD ring */ -#define NBUF_RX_RING 2 /* buffers in the Rx BD ring */ -#define NBUF_SCRATCH 3 /* misc */ -#define NBUF_MAXQ 4 /* total number of queueus */ - -/* - * Buffer Descriptor Format - * - * Fields: - * next Pointer to next node in the queue - * data Pointer to the data buffer - * offset Index into buffer - * length Remaining bytes in buffer from (data + offset) - */ -typedef struct -{ - QNODE node; - uint8_t *data; - uint16_t offset; - uint16_t length; -} NBUF; - -/* - * Functions to manipulate the network buffers. - */ -int -nbuf_init(void); - -void -nbuf_flush(void); - -NBUF * -nbuf_alloc (void); - -void -nbuf_free(NBUF *); - -NBUF * -nbuf_remove(int); - -void -nbuf_add(int, NBUF *); - -void -nbuf_reset(void); - -void -nbuf_debug_dump(void); - -/********************************************************************/ - -#endif /* _NBUF_H_ */ +/* + * File: nbuf.h + * Purpose: Definitions for network buffer management + * + * Notes: These routines implement a network buffer scheme + */ + +#ifndef _NBUF_H_ +#define _NBUF_H_ + +/********************************************************************/ +/* + * Include the Queue structure definitions + */ +#include "queue.h" + +/* + * Number of network buffers to use + */ +#define NBUF_MAX 30 + +/* + * Size of each buffer in bytes + */ +#ifndef NBUF_SZ +#define NBUF_SZ 1520 +#endif + +/* + * Defines to identify all the buffer queues + * - FREE must always be defined as 0 + */ +#define NBUF_FREE 0 /* available buffers */ +#define NBUF_TX_RING 1 /* buffers in the Tx BD ring */ +#define NBUF_RX_RING 2 /* buffers in the Rx BD ring */ +#define NBUF_SCRATCH 3 /* misc */ +#define NBUF_MAXQ 4 /* total number of queueus */ + +/* + * Buffer Descriptor Format + * + * Fields: + * next Pointer to next node in the queue + * data Pointer to the data buffer + * offset Index into buffer + * length Remaining bytes in buffer from (data + offset) + */ +typedef struct +{ + QNODE node; + uint8_t *data; + uint16_t offset; + uint16_t length; +} NBUF; + +/* + * Functions to manipulate the network buffers. + */ +extern int nbuf_init(void); +extern void nbuf_flush(void); +extern NBUF *nbuf_alloc (void); +extern void nbuf_free(NBUF *); +extern NBUF *nbuf_remove(int); +extern void nbuf_add(int, NBUF *); +extern void nbuf_reset(void); +extern void nbuf_debug_dump(void); + + +#endif /* _NBUF_H_ */ diff --git a/include/net.h b/include/net.h index b7bb149..2631bb4 100644 --- a/include/net.h +++ b/include/net.h @@ -1,6 +1,6 @@ /* * File: net.h - * Purpose: Network definitions and prototypes for dBUG. + * Purpose: Network definitions and prototypes for BaS. * * Notes: */ @@ -24,7 +24,7 @@ /********************************************************************/ -int net_init(void); +extern int net_init(void); /********************************************************************/ diff --git a/include/net_timer.h b/include/net_timer.h index 740526e..26824fb 100644 --- a/include/net_timer.h +++ b/include/net_timer.h @@ -1,9 +1,8 @@ /* * File: net_timer.h - * Purpose: Provide a timer use by the dBUG network as a timeout + * Purpose: Provide a timer use by the BaS network as a timeout * indicator * - * Notes: */ #ifndef _TIMER_H_ diff --git a/include/tftp.h b/include/tftp.h index d9b98b5..a3f72d1 100644 --- a/include/tftp.h +++ b/include/tftp.h @@ -8,8 +8,6 @@ #ifndef _TFTP_H_ #define _TFTP_H_ -/********************************************************************/ - #define TFTP_RRQ (1) #define TFTP_WRQ (2) #define TFTP_DATA (3) diff --git a/net/bootp.c b/net/bootp.c index 8d9b5b8..f460e4d 100644 --- a/net/bootp.c +++ b/net/bootp.c @@ -9,9 +9,14 @@ #include "bootp.h" #include #include +#include "bas_printf.h" #define TIMER_NETWORK 0 +static struct bootp_connection connection; +#define XID 0x1234 /* this is arbitrary */ +#define MAX_TRIES 5 /* since UDP can fail */ + void bootp_request(NIF *nif, uint8_t *pa) { /* @@ -19,172 +24,75 @@ void bootp_request(NIF *nif, uint8_t *pa) * address "pa" */ uint8_t *addr; - NBUF *pNbuf; - bootp_frame_hdr *bootpframe; + IP_ADDR broadcast = {255, 255, 255, 255}; + NBUF *nbuf; + struct bootp_packet *p; int i, result; - pNbuf = nbuf_alloc(); - if (pNbuf == NULL) + nbuf = nbuf_alloc(); + if (nbuf == NULL) { - #if defined(DEBUG_PRINT) - xprintf("%s: arp_request couldn't allocate Tx buffer\r\n", __FUNCTION__); - #endif - return; + xprintf("%s: couldn't allocate Tx buffer\r\n", __FUNCTION__); + return; } - bootpframe = (bootp_frame_hdr *) &pNbuf->data[BOOTP_HDR_OFFSET]; + p = (struct bootp_packet *) &nbuf->data[BOOTP_HDR_OFFSET]; /* Build the BOOTP request packet */ - bootpframe->type = BOOTP_TYPE_BOOTREQUEST; - bootpframe->htype = BOOTP_HTYPE_ETHERNET; - bootpframe->hlen = BOOTP_HLEN_ETHERNET; - bootpframe->hops = 0; - bootpframe->xid = 0x1234; - bootpframe->secs = 1; - bootpframe->flags = BOOTP_FLAGS_BROADCAST; - bootpframe->cl_addr = 0x0; - bootpframe->yi_addr = 0x0; - bootpframe->gi_addr = 0x0; + p->type = BOOTP_TYPE_BOOTREQUEST; + p->htype = BOOTP_HTYPE_ETHERNET; + p->hlen = BOOTP_HLEN_ETHERNET; + p->hops = 0; + p->xid = XID; + p->secs = 1; + p->flags = BOOTP_FLAGS_BROADCAST; + p->cl_addr = 0x0; + p->yi_addr = 0x0; + p->gi_addr = 0x0; addr = &nif->hwa[0]; for (i = 0; i < 6; i++) - bootpframe->ch_addr[i] = addr[i]; + p->ch_addr[i] = addr[i]; - pNbuf->length = BOOTP_HDR_LEN; + nbuf->length = BOOTP_PACKET_LEN; - /* Send the BOOTP request */ - result = nif->send(nif, nif->broadcast, nif->hwa, ETH_FRM_IP, pNbuf); + for (i = 0; i < MAX_TRIES; i++) + { + /* Send the BOOTP request */ + result = udp_send(connection.nif, broadcast, BOOTP_CLIENT_PORT, + BOOTP_SERVER_PORT, nbuf); + if (result == true) + break; + } if (result == 0) - nbuf_free(pNbuf); + nbuf_free(nbuf); } -void bootp_handler(NIF *nif, NBUF *pNbuf) +void bootp_handler(NIF *nif, NBUF *nbuf) { /* - * ARP protocol handler + * BOOTP protocol handler */ uint8_t *addr; - bootp_frame_hdr *rx_bootpframe, *tx_bootpframe; + struct bootp_packet *rx_p; + udp_frame_hdr *udpframe; - rx_bootpframe = (bootp_frame_hdr *) &pNbuf->data[pNbuf->offset]; + rx_p = (struct bootp_packet *) &nbuf->data[nbuf->offset]; + udpframe = (udp_frame_hdr *) &nbuf->data[nbuf->offset - UDP_HDR_SIZE]; -#ifdef _NOT_USED_ - /* - * Check for an appropriate ARP packet - */ - if ((pNbuf->length < ARP_HDR_LEN) || - (rx_arpframe->ar_hrd != ETHERNET) || - (rx_arpframe->ar_hln != 6) || - (rx_arpframe->ar_pro != ETH_FRM_IP) || - (rx_arpframe->ar_pln != 4)) + /* check packet if it is valid and if it is really intended for us */ + + if (rx_p->type == BOOTP_TYPE_BOOTREPLY && rx_p->xid == XID) { - nbuf_free(pNbuf); - return; + /* seems to be valid */ + } - - /* - * Check to see if it was addressed to me - if it was, keep this - * ARP entry in the table permanently; if not, mark it so that it - * can be displaced later if necessary - */ - addr = ip_get_myip(nif_get_protocol_info(nif,ETH_FRM_IP)); - if ((rx_arpframe->ar_tpa[0] == addr[0]) && - (rx_arpframe->ar_tpa[1] == addr[1]) && - (rx_arpframe->ar_tpa[2] == addr[2]) && - (rx_arpframe->ar_tpa[3] == addr[3]) ) + else { - longevity = ARP_ENTRY_PERM; - } - else - longevity = ARP_ENTRY_TEMP; + /* not valid */ + return; +} - /* - * Add ARP info into the table - */ - arp_merge(arptab, - rx_arpframe->ar_pro, - rx_arpframe->ar_hln, - &rx_arpframe->ar_sha[0], - rx_arpframe->ar_pln, - &rx_arpframe->ar_spa[0], - longevity - ); - - switch (rx_arpframe->opcode) - { - case ARP_REQUEST: - /* - * Check to see if request is directed to me - */ - if ((rx_arpframe->ar_tpa[0] == addr[0]) && - (rx_arpframe->ar_tpa[1] == addr[1]) && - (rx_arpframe->ar_tpa[2] == addr[2]) && - (rx_arpframe->ar_tpa[3] == addr[3]) ) - { - /* - * Reuse the current network buffer to assemble an ARP reply - */ - tx_arpframe = (arp_frame_hdr *)&pNbuf->data[ARP_HDR_OFFSET]; - - /* - * Build new ARP frame from the received data - */ - tx_arpframe->ar_hrd = ETHERNET; - tx_arpframe->ar_pro = ETH_FRM_IP; - tx_arpframe->ar_hln = 6; - tx_arpframe->ar_pln = 4; - tx_arpframe->opcode = ARP_REPLY; - tx_arpframe->ar_tha[0] = rx_arpframe->ar_sha[0]; - tx_arpframe->ar_tha[1] = rx_arpframe->ar_sha[1]; - tx_arpframe->ar_tha[2] = rx_arpframe->ar_sha[2]; - tx_arpframe->ar_tha[3] = rx_arpframe->ar_sha[3]; - tx_arpframe->ar_tha[4] = rx_arpframe->ar_sha[4]; - tx_arpframe->ar_tha[5] = rx_arpframe->ar_sha[5]; - tx_arpframe->ar_tpa[0] = rx_arpframe->ar_spa[0]; - tx_arpframe->ar_tpa[1] = rx_arpframe->ar_spa[1]; - tx_arpframe->ar_tpa[2] = rx_arpframe->ar_spa[2]; - tx_arpframe->ar_tpa[3] = rx_arpframe->ar_spa[3]; - - /* - * Now copy in the new information - */ - addr = &nif->hwa[0]; - tx_arpframe->ar_sha[0] = addr[0]; - tx_arpframe->ar_sha[1] = addr[1]; - tx_arpframe->ar_sha[2] = addr[2]; - tx_arpframe->ar_sha[3] = addr[3]; - tx_arpframe->ar_sha[4] = addr[4]; - tx_arpframe->ar_sha[5] = addr[5]; - - addr = ip_get_myip(nif_get_protocol_info(nif,ETH_FRM_IP)); - tx_arpframe->ar_spa[0] = addr[0]; - tx_arpframe->ar_spa[1] = addr[1]; - tx_arpframe->ar_spa[2] = addr[2]; - tx_arpframe->ar_spa[3] = addr[3]; - - /* - * Save the length of my packet in the buffer structure - */ - pNbuf->length = ARP_HDR_LEN; - - nif->send(nif, - &tx_arpframe->ar_tha[0], - &tx_arpframe->ar_sha[0], - ETH_FRM_ARP, - pNbuf); - } - else - nbuf_free(pNbuf); - break; - case ARP_REPLY: - /* - * The ARP Reply case is already taken care of - */ - default: - nbuf_free(pNbuf); - break; - } -#endif /* _NOT_USED_ */ return; } diff --git a/net/net_timer.c b/net/net_timer.c index 491b14a..3bde409 100644 --- a/net/net_timer.c +++ b/net/net_timer.c @@ -1,176 +1,179 @@ -/* - * File: net_timer.c - * Purpose: Provide a timer use by the dBUG network as a timeout - * indicator - * - * Notes: - */ -#include "net_timer.h" -#include -#include -#include "MCF5475.h" -#include "interrupts.h" - -#if defined(MACHINE_FIREBEE) -#include "firebee.h" -#elif defined(MACHINE_M5484LITE) -#include "m5484l.h" -#else -#error unknown machine! -#endif - -static NET_TIMER net_timer[4] = {{0, 0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0, 0}}; - - -int timer_default_isr(void *not_used, NET_TIMER *t) -{ - (void) not_used; - - /* - * Clear the pending event - */ - MCF_GPT_GMS(t->ch) = 0; - - /* - * Clear the reference - the desired seconds have expired - */ - t->reference = 0; - - return 1; -} - -void timer_irq_enable(uint8_t ch) -{ - /* - * Setup the appropriate ICR - */ - MCF_INTC_ICR(TIMER_VECTOR(ch) - 64) = - (uint8_t)(0 - | MCF_INTC_ICR_IP(net_timer[ch].pri) - | MCF_INTC_ICR_IL(net_timer[ch].lvl)); - - /* - * Unmask the FEC interrupt in the interrupt controller - */ - if (ch == 3) - MCF_INTC_IMRH &= ~MCF_INTC_IMRH_INT_MASK59; - else if (ch == 2) - MCF_INTC_IMRH &= ~MCF_INTC_IMRH_INT_MASK60; - else if (ch == 1) - MCF_INTC_IMRH &= ~MCF_INTC_IMRH_INT_MASK61; - else - MCF_INTC_IMRH &= ~MCF_INTC_IMRH_INT_MASK62; -} - -bool timer_set_secs(uint8_t ch, uint32_t secs) -{ - uint16_t timeout; - - /* - * Reset the timer - */ - MCF_GPT_GMS(ch) = 0; - - /* - * Get the timeout in seconds - */ - timeout = (uint16_t)(secs * net_timer[ch].cnt); - - /* - * Set the reference indicating that we have not yet reached the - * desired timeout - */ - net_timer[ch].reference = 1; - - /* - * Enable timer interrupt to the processor - */ - timer_irq_enable(ch); - - /* - * Enable the timer using the pre-calculated values - */ - MCF_GPT_GCIR(ch) = (0 - | MCF_GPT_GCIR_CNT(timeout) - | MCF_GPT_GCIR_PRE(net_timer[ch].pre) - ); - MCF_GPT_GMS(ch) = net_timer[ch].gms; - - return true; -} - -uint32_t timer_get_reference(uint8_t ch) -{ - return (uint32_t) net_timer[ch].reference; -} - -bool timer_init(uint8_t ch, uint8_t lvl, uint8_t pri) -{ - /* - * Initialize the timer to expire after one second - * - * This routine should only be called by the project (board) specific - * initialization code. - */ - if (!((ch <= 3) && (lvl <= 7) && (lvl >= 1) && (pri <= 7))) - return false; - - /* - * Reset the timer - */ - MCF_GPT_GMS(ch) = 0; - - /* - * Save off the channel, and interrupt lvl/pri information - */ - net_timer[ch].ch = ch; - net_timer[ch].lvl = lvl; - net_timer[ch].pri = pri; - - /* - * Register the timer interrupt handler - */ - if (!isr_register_handler(ISR_DBUG_ISR, - TIMER_VECTOR(ch), - (int (*)(void *,void *)) timer_default_isr, - NULL, - (void *) &net_timer[ch]) - ) - { - return false; - } - - /* - * Calculate the require CNT value to get a 1 second timeout - * - * 1 sec = CNT * Clk Period * PRE - * CNT = 1 sec / (Clk Period * PRE) - * CNT = Clk Freq / PRE - * - * The system clock frequency is defined as SYSTEM_CLOCK and - * is given in MHz. We need to multiple it by 1000000 to get the - * true value. If we assume PRE to be the maximum of 0xFFFF, - * then the CNT value needed to achieve a 1 second timeout is - * given by: - * - * CNT = SYSTEM_CLOCK * (1000000/0xFFFF) - */ - net_timer[ch].pre = 0xFFFF; - net_timer[ch].cnt = (uint16_t) (SYSCLK * (1000000 / 0xFFFF)); - - /* - * Save off the appropriate mode select register value - */ - net_timer[ch].gms = (0 - | MCF_GPT_GMS_TMS_GPIO - | MCF_GPT_GMS_IEN - | MCF_GPT_GMS_SC - | MCF_GPT_GMS_CE - ); - - return true; -} - +/* + * File: net_timer.c + * Purpose: Provide a timer use by the BaS network as a timeout + * indicator + * + * Notes: + */ +#include "net_timer.h" +#include +#include +#include "MCF5475.h" +#include "interrupts.h" + +#if defined(MACHINE_FIREBEE) +#include "firebee.h" +#elif defined(MACHINE_M5484LITE) +#include "m5484l.h" +#else +#error unknown machine! +#endif + +static NET_TIMER net_timer[4] = +{ + {0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0} +}; + + +int timer_default_isr(void *not_used, NET_TIMER *t) +{ + (void) not_used; + + /* + * Clear the pending event + */ + MCF_GPT_GMS(t->ch) = 0; + + /* + * Clear the reference - the desired seconds have expired + */ + t->reference = 0; + + return 1; +} + +void timer_irq_enable(uint8_t ch) +{ + /* + * Setup the appropriate ICR + */ + MCF_INTC_ICR(TIMER_VECTOR(ch) - 64) = + (uint8_t)(0 + | MCF_INTC_ICR_IP(net_timer[ch].pri) + | MCF_INTC_ICR_IL(net_timer[ch].lvl)); + + /* + * Unmask the FEC interrupt in the interrupt controller + */ + if (ch == 3) + MCF_INTC_IMRH &= ~MCF_INTC_IMRH_INT_MASK59; + else if (ch == 2) + MCF_INTC_IMRH &= ~MCF_INTC_IMRH_INT_MASK60; + else if (ch == 1) + MCF_INTC_IMRH &= ~MCF_INTC_IMRH_INT_MASK61; + else + MCF_INTC_IMRH &= ~MCF_INTC_IMRH_INT_MASK62; +} + +bool timer_set_secs(uint8_t ch, uint32_t secs) +{ + uint16_t timeout; + + /* + * Reset the timer + */ + MCF_GPT_GMS(ch) = 0; + + /* + * Get the timeout in seconds + */ + timeout = (uint16_t)(secs * net_timer[ch].cnt); + + /* + * Set the reference indicating that we have not yet reached the + * desired timeout + */ + net_timer[ch].reference = 1; + + /* + * Enable timer interrupt to the processor + */ + timer_irq_enable(ch); + + /* + * Enable the timer using the pre-calculated values + */ + MCF_GPT_GCIR(ch) = (0 + | MCF_GPT_GCIR_CNT(timeout) + | MCF_GPT_GCIR_PRE(net_timer[ch].pre) + ); + MCF_GPT_GMS(ch) = net_timer[ch].gms; + + return true; +} + +uint32_t timer_get_reference(uint8_t ch) +{ + return (uint32_t) net_timer[ch].reference; +} + +bool timer_init(uint8_t ch, uint8_t lvl, uint8_t pri) +{ + /* + * Initialize the timer to expire after one second + * + * This routine should only be called by the project (board) specific + * initialization code. + */ + if (!((ch <= 3) && (lvl <= 7) && (lvl >= 1) && (pri <= 7))) + return false; + + /* + * Reset the timer + */ + MCF_GPT_GMS(ch) = 0; + + /* + * Save off the channel, and interrupt lvl/pri information + */ + net_timer[ch].ch = ch; + net_timer[ch].lvl = lvl; + net_timer[ch].pri = pri; + + /* + * Register the timer interrupt handler + */ + if (!isr_register_handler(ISR_DBUG_ISR, + TIMER_VECTOR(ch), + (int (*)(void *,void *)) timer_default_isr, + NULL, + (void *) &net_timer[ch]) + ) + { + return false; + } + + /* + * Calculate the require CNT value to get a 1 second timeout + * + * 1 sec = CNT * Clk Period * PRE + * CNT = 1 sec / (Clk Period * PRE) + * CNT = Clk Freq / PRE + * + * The system clock frequency is defined as SYSTEM_CLOCK and + * is given in MHz. We need to multiple it by 1000000 to get the + * true value. If we assume PRE to be the maximum of 0xFFFF, + * then the CNT value needed to achieve a 1 second timeout is + * given by: + * + * CNT = SYSTEM_CLOCK * (1000000/0xFFFF) + */ + net_timer[ch].pre = 0xFFFF; + net_timer[ch].cnt = (uint16_t) (SYSCLK * (1000000 / 0xFFFF)); + + /* + * Save off the appropriate mode select register value + */ + net_timer[ch].gms = (0 + | MCF_GPT_GMS_TMS_GPIO + | MCF_GPT_GMS_IEN + | MCF_GPT_GMS_SC + | MCF_GPT_GMS_CE + ); + + return true; +} + diff --git a/sys/interrupts.c b/sys/interrupts.c index 4ac9a1f..ec28b77 100644 --- a/sys/interrupts.c +++ b/sys/interrupts.c @@ -52,10 +52,10 @@ int register_interrupt_handler(uint8_t source, uint8_t level, uint8_t priority, { xprintf("%s: interrupt source %d not defined\r\n", __FUNCTION__, source); return -1; - } + } lp = MCF_INTC_ICR_IL(level) | MCF_INTC_ICR_IP(priority); - + /* check if this combination is already set somewhere */ for (i = 1; i < 64; i++) { @@ -88,11 +88,11 @@ int register_interrupt_handler(uint8_t source, uint8_t level, uint8_t priority, typedef struct { - int vector; - int type; - int (*handler)(void *, void *); - void *hdev; - void *harg; + int vector; + int type; + int (*handler)(void *, void *); + void *hdev; + void *harg; } ISRENTRY; ISRENTRY isrtab[UIF_MAX_ISR_ENTRY]; @@ -100,126 +100,126 @@ ISRENTRY isrtab[UIF_MAX_ISR_ENTRY]; void isr_init(void) { - int index; - - for (index = 0; index < UIF_MAX_ISR_ENTRY; index++) - { - isrtab[index].vector = 0; - isrtab[index].type = 0; - isrtab[index].handler = 0; - isrtab[index].hdev = 0; - isrtab[index].harg = 0; - } + int index; + + for (index = 0; index < UIF_MAX_ISR_ENTRY; index++) + { + isrtab[index].vector = 0; + isrtab[index].type = 0; + isrtab[index].handler = 0; + isrtab[index].hdev = 0; + isrtab[index].harg = 0; + } } int isr_register_handler ( - int type, int vector, - int (*handler)(void *, void *), void *hdev, void *harg) + int type, int vector, + int (*handler)(void *, void *), void *hdev, void *harg) { - /* - * This function places an interrupt handler in the ISR table, - * thereby registering it so that the low-level handler may call it. - * - * The two parameters are intended for the first arg to be a - * pointer to the device itself, and the second a pointer to a data - * structure used by the device driver for that particular device. - */ - int index; + /* + * This function places an interrupt handler in the ISR table, + * thereby registering it so that the low-level handler may call it. + * + * The two parameters are intended for the first arg to be a + * pointer to the device itself, and the second a pointer to a data + * structure used by the device driver for that particular device. + */ + int index; - if ((vector == 0) || - ((type != ISR_DBUG_ISR) && (type != ISR_USER_ISR)) || - (handler == NULL)) - { - return true; - } + if ((vector == 0) || + ((type != ISR_DBUG_ISR) && (type != ISR_USER_ISR)) || + (handler == NULL)) + { + return true; + } - for (index = 0; index < UIF_MAX_ISR_ENTRY; index++) - { - if ((isrtab[index].vector == vector) && - (isrtab[index].type == type)) - { - /* only one entry of each type per vector */ - return 0; - } + for (index = 0; index < UIF_MAX_ISR_ENTRY; index++) + { + if ((isrtab[index].vector == vector) && + (isrtab[index].type == type)) + { + /* only one entry of each type per vector */ + return 0; + } - if (isrtab[index].vector == 0) - { - isrtab[index].vector = vector; - isrtab[index].type = type; - isrtab[index].handler = handler; - isrtab[index].hdev = hdev; - isrtab[index].harg = harg; - return 1; - } - } - return false; /* no available slots */ + if (isrtab[index].vector == 0) + { + isrtab[index].vector = vector; + isrtab[index].type = type; + isrtab[index].handler = handler; + isrtab[index].hdev = hdev; + isrtab[index].harg = harg; + return 1; + } + } + return false; /* no available slots */ } void isr_remove_handler(int type, int (*handler)(void *, void *)) { - /* - * This routine removes from the ISR table all - * entries that matches 'type' and 'handler'. - */ - int index; + /* + * This routine removes from the ISR table all + * entries that matches 'type' and 'handler'. + */ + int index; - for (index = 0; index < UIF_MAX_ISR_ENTRY; index++) - { - if ((isrtab[index].handler == handler) && - (isrtab[index].type == type)) - { - isrtab[index].vector = 0; - isrtab[index].type = 0; - isrtab[index].handler = 0; - isrtab[index].hdev = 0; - isrtab[index].harg = 0; - } - } + for (index = 0; index < UIF_MAX_ISR_ENTRY; index++) + { + if ((isrtab[index].handler == handler) && + (isrtab[index].type == type)) + { + isrtab[index].vector = 0; + isrtab[index].type = 0; + isrtab[index].handler = 0; + isrtab[index].hdev = 0; + isrtab[index].harg = 0; + } + } } bool isr_execute_handler(int vector) { - /* - * This routine searches the ISR table for an entry that matches - * 'vector'. If one is found, then 'handler' is executed. - */ - int index; - bool retval = false; + /* + * This routine searches the ISR table for an entry that matches + * 'vector'. If one is found, then 'handler' is executed. + */ + int index; + bool retval = false; - /* - * First locate a dBUG Interrupt Service Routine handler. - */ - for (index = 0; index < UIF_MAX_ISR_ENTRY; index++) - { - if ((isrtab[index].vector == vector) && - (isrtab[index].type == ISR_DBUG_ISR)) - { - if (isrtab[index].handler(isrtab[index].hdev,isrtab[index].harg)) - { - retval = true; - break; - } - } - } + /* + * First locate a BaS Interrupt Service Routine handler. + */ + for (index = 0; index < UIF_MAX_ISR_ENTRY; index++) + { + if ((isrtab[index].vector == vector) && + (isrtab[index].type == ISR_DBUG_ISR)) + { + if (isrtab[index].handler(isrtab[index].hdev,isrtab[index].harg)) + { + retval = true; + break; + } + } + } - /* - * Try to locate a user-registered Interrupt Service Routine handler. - */ - for (index = 0; index < UIF_MAX_ISR_ENTRY; index++) - { - if ((isrtab[index].vector == vector) && - (isrtab[index].type == ISR_USER_ISR)) - { - if (isrtab[index].handler(isrtab[index].hdev,isrtab[index].harg)) - { - retval = true; - break; - } - } - } + /* + * Try to locate a user-registered Interrupt Service Routine handler. + */ + for (index = 0; index < UIF_MAX_ISR_ENTRY; index++) + { + if ((isrtab[index].vector == vector) && + (isrtab[index].type == ISR_USER_ISR)) + { + if (isrtab[index].handler(isrtab[index].hdev,isrtab[index].harg)) + { + retval = true; + break; + } + } + } - return retval; + return retval; }