added missing function prototypes
This commit is contained in:
@@ -15,17 +15,19 @@
|
|||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint8_t ch; /* which channel is this structure for? */
|
uint8_t ch; /* which channel is this structure for? */
|
||||||
uint8_t lvl; /* Interrupt level for this channel */
|
uint8_t lvl; /* Interrupt level for this channel */
|
||||||
uint8_t pri; /* Interrupt priority for this channel */
|
uint8_t pri; /* Interrupt priority for this channel */
|
||||||
uint8_t reference; /* timeout indicator */
|
uint8_t reference; /* timeout indicator */
|
||||||
uint32_t gms; /* mode select register value */
|
uint32_t gms; /* mode select register value */
|
||||||
uint16_t pre; /* prescale value */
|
uint16_t pre; /* prescale value */
|
||||||
uint16_t cnt; /* prescaled clocks for timeout */
|
uint16_t cnt; /* prescaled clocks for timeout */
|
||||||
} NET_TIMER;
|
} NET_TIMER;
|
||||||
|
|
||||||
|
|
||||||
extern bool timer_init(uint8_t, uint8_t, uint8_t);
|
extern bool timer_init(uint8_t, uint8_t, uint8_t);
|
||||||
|
extern bool timer_set_secs(uint8_t ch, uint32_t secs);
|
||||||
|
extern uint32_t timer_get_reference(uint8_t ch);
|
||||||
|
|
||||||
/* Vector numbers for all the timer channels */
|
/* Vector numbers for all the timer channels */
|
||||||
#define TIMER_VECTOR(x) (126-x)
|
#define TIMER_VECTOR(x) (126-x)
|
||||||
|
|||||||
@@ -16,15 +16,16 @@
|
|||||||
#include "bas_printf.h"
|
#include "bas_printf.h"
|
||||||
#include "bas_string.h"
|
#include "bas_string.h"
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
|
#include "net_timer.h"
|
||||||
|
|
||||||
#define TIMER_NETWORK 0
|
#define TIMER_NETWORK 0
|
||||||
|
|
||||||
/* The one and only TFTP connection */
|
/* The one and only TFTP connection */
|
||||||
TFTP_Connection tcxn;
|
static TFTP_Connection tcxn;
|
||||||
|
|
||||||
/* Progress Indicators */
|
/* Progress Indicators */
|
||||||
char hash[] = {'-','\\','|','/'};
|
static char hash[] = {'-','\\','|','/'};
|
||||||
int ihash = 0;
|
static int ihash = 0;
|
||||||
|
|
||||||
static int tftp_rwrq(void)
|
static int tftp_rwrq(void)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,8 +13,8 @@
|
|||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
void (*handler)(NIF *, NBUF *);
|
void (*handler)(NIF *, NBUF *);
|
||||||
} UDP_BOUND_PORT;
|
} UDP_BOUND_PORT;
|
||||||
|
|
||||||
#define UDP_MAX_PORTS (5) /* plenty for this implementation */
|
#define UDP_MAX_PORTS (5) /* plenty for this implementation */
|
||||||
@@ -26,134 +26,136 @@ static uint16_t udp_port;
|
|||||||
|
|
||||||
void udp_init(void)
|
void udp_init(void)
|
||||||
{
|
{
|
||||||
int index;
|
int index;
|
||||||
|
|
||||||
for (index = 0; index < UDP_MAX_PORTS; ++index)
|
for (index = 0; index < UDP_MAX_PORTS; ++index)
|
||||||
{
|
{
|
||||||
udp_port_table[index].port = 0;
|
udp_port_table[index].port = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
udp_port = DEFAULT_UDP_PORT; /* next free port */
|
udp_port = DEFAULT_UDP_PORT; /* next free port */
|
||||||
}
|
}
|
||||||
|
|
||||||
void udp_prime_port(uint16_t init_port)
|
void udp_prime_port(uint16_t init_port)
|
||||||
{
|
{
|
||||||
udp_port = init_port;
|
udp_port = init_port;
|
||||||
}
|
}
|
||||||
|
|
||||||
void udp_bind_port(uint16_t port, void (*handler)(NIF *, NBUF *))
|
void udp_bind_port(uint16_t port, void (*handler)(NIF *, NBUF *))
|
||||||
{
|
{
|
||||||
int index;
|
int index;
|
||||||
|
|
||||||
for (index = 0; index < UDP_MAX_PORTS; ++index)
|
for (index = 0; index < UDP_MAX_PORTS; ++index)
|
||||||
{
|
{
|
||||||
if (udp_port_table[index].port == 0)
|
if (udp_port_table[index].port == 0)
|
||||||
{
|
{
|
||||||
udp_port_table[index].port = port;
|
udp_port_table[index].port = port;
|
||||||
udp_port_table[index].handler = handler;
|
udp_port_table[index].handler = handler;
|
||||||
return;
|
|
||||||
}
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void udp_free_port(uint16_t port)
|
void udp_free_port(uint16_t port)
|
||||||
{
|
{
|
||||||
int index;
|
int index;
|
||||||
|
|
||||||
for (index = 0; index < UDP_MAX_PORTS; ++index)
|
for (index = 0; index < UDP_MAX_PORTS; ++index)
|
||||||
{
|
{
|
||||||
if (udp_port_table[index].port == port)
|
if (udp_port_table[index].port == port)
|
||||||
{
|
{
|
||||||
udp_port_table[index].port = 0;
|
udp_port_table[index].port = 0;
|
||||||
return;
|
|
||||||
}
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *udp_port_handler(uint16_t port)
|
static void *udp_port_handler(uint16_t port)
|
||||||
{
|
{
|
||||||
int index;
|
int index;
|
||||||
|
|
||||||
for (index = 0; index < UDP_MAX_PORTS; ++index)
|
for (index = 0; index < UDP_MAX_PORTS; ++index)
|
||||||
{
|
{
|
||||||
if (udp_port_table[index].port == port)
|
if (udp_port_table[index].port == port)
|
||||||
{
|
{
|
||||||
return (void *)udp_port_table[index].handler;
|
return (void *)udp_port_table[index].handler;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t udp_obtain_free_port(void)
|
uint16_t udp_obtain_free_port(void)
|
||||||
{
|
{
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
|
|
||||||
port = udp_port;
|
port = udp_port;
|
||||||
if (--udp_port <= 255)
|
if (--udp_port <= 255)
|
||||||
udp_port = DEFAULT_UDP_PORT;
|
udp_port = DEFAULT_UDP_PORT;
|
||||||
|
|
||||||
return port;
|
return port;
|
||||||
}
|
}
|
||||||
|
|
||||||
int udp_send(NIF *nif, uint8_t *dest, int sport, int dport, NBUF *pNbuf)
|
int udp_send(NIF *nif, uint8_t *dest, int sport, int dport, NBUF *pNbuf)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* This function takes data and creates a UDP frame and
|
* This function takes data and creates a UDP frame and
|
||||||
* passes it onto the IP layer
|
* passes it onto the IP layer
|
||||||
*/
|
*/
|
||||||
udp_frame_hdr *udpframe;
|
udp_frame_hdr *udpframe;
|
||||||
|
|
||||||
udpframe = (udp_frame_hdr *) &pNbuf->data[UDP_HDR_OFFSET];
|
udpframe = (udp_frame_hdr *) &pNbuf->data[UDP_HDR_OFFSET];
|
||||||
|
|
||||||
/* Set UDP source port */
|
/* Set UDP source port */
|
||||||
udpframe->src_port = (uint16_t) sport;
|
udpframe->src_port = (uint16_t) sport;
|
||||||
|
|
||||||
/* Set UDP destination port */
|
/* Set UDP destination port */
|
||||||
udpframe->dest_port = (uint16_t) dport;
|
udpframe->dest_port = (uint16_t) dport;
|
||||||
|
|
||||||
/* Set length */
|
/* Set length */
|
||||||
udpframe->length = (uint16_t) (pNbuf->length + UDP_HDR_SIZE);
|
udpframe->length = (uint16_t) (pNbuf->length + UDP_HDR_SIZE);
|
||||||
|
|
||||||
/* No checksum calcualation needed */
|
/* No checksum calcualation needed */
|
||||||
udpframe->chksum = (uint16_t) 0;
|
udpframe->chksum = (uint16_t) 0;
|
||||||
|
|
||||||
/* Add the length of the UDP packet to the total length of the packet */
|
/* Add the length of the UDP packet to the total length of the packet */
|
||||||
pNbuf->length += 8;
|
pNbuf->length += 8;
|
||||||
|
|
||||||
return (ip_send(nif, dest,
|
return (ip_send(nif, dest,
|
||||||
ip_get_myip(nif_get_protocol_info(nif, ETH_FRM_IP)),
|
ip_get_myip(nif_get_protocol_info(nif, ETH_FRM_IP)),
|
||||||
IP_PROTO_UDP,
|
IP_PROTO_UDP,
|
||||||
pNbuf));
|
pNbuf));
|
||||||
}
|
}
|
||||||
|
|
||||||
void udp_handler(NIF *nif, NBUF *pNbuf)
|
void udp_handler(NIF *nif, NBUF *pNbuf)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* This function handles incoming UDP packets
|
* This function handles incoming UDP packets
|
||||||
*/
|
*/
|
||||||
udp_frame_hdr *udpframe;
|
udp_frame_hdr *udpframe;
|
||||||
void (*handler)(NIF *, NBUF *);
|
void (*handler)(NIF *, NBUF *);
|
||||||
|
|
||||||
udpframe = (udp_frame_hdr *) &pNbuf->data[pNbuf->offset];
|
udpframe = (udp_frame_hdr *) &pNbuf->data[pNbuf->offset];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Adjust the length and valid data offset of the packet we are
|
* Adjust the length and valid data offset of the packet we are
|
||||||
* passing on
|
* passing on
|
||||||
*/
|
*/
|
||||||
pNbuf->length -= UDP_HDR_SIZE;
|
pNbuf->length -= UDP_HDR_SIZE;
|
||||||
pNbuf->offset += UDP_HDR_SIZE;
|
pNbuf->offset += UDP_HDR_SIZE;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Traverse the list of bound ports to see if there is a higher
|
* Traverse the list of bound ports to see if there is a higher
|
||||||
* level protocol to pass the packet on to
|
* level protocol to pass the packet on to
|
||||||
*/
|
*/
|
||||||
if ((handler = (void(*)(NIF*, NBUF*)) udp_port_handler(UDP_DEST(udpframe))) != NULL)
|
if ((handler = (void(*)(NIF*, NBUF*)) udp_port_handler(UDP_DEST(udpframe))) != NULL)
|
||||||
handler(nif, pNbuf);
|
handler(nif, pNbuf);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
xprintf("Received UDP packet for non-supported port\n");
|
xprintf("Received UDP packet for non-supported port\n");
|
||||||
nbuf_free(pNbuf);
|
nbuf_free(pNbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user