Updated API
This commit is contained in:
parent
6357c240c0
commit
81dfaf575c
3 changed files with 80 additions and 34 deletions
|
@ -30,7 +30,7 @@
|
|||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
* $Id: ethernode-rime.c,v 1.5 2007/03/29 22:26:33 adamdunkels Exp $
|
||||
* $Id: ethernode-rime.c,v 1.6 2007/05/22 21:09:19 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
|
@ -39,8 +39,6 @@
|
|||
|
||||
#include "net/rime.h"
|
||||
|
||||
PROCESS(ethernode_rime_process, "Ethernode Rime driver");
|
||||
|
||||
#define DEBUG 0
|
||||
#if DEBUG
|
||||
#include <stdio.h>
|
||||
|
@ -50,39 +48,31 @@ PROCESS(ethernode_rime_process, "Ethernode Rime driver");
|
|||
#endif
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(ethernode_rime_process, ev, data)
|
||||
static void
|
||||
receiver(void)
|
||||
{
|
||||
PROCESS_BEGIN();
|
||||
|
||||
while(1) {
|
||||
process_poll(ðernode_rime_process);
|
||||
PROCESS_WAIT_EVENT();
|
||||
|
||||
/* Poll Ethernet device to see if there is a frame avaliable. */
|
||||
{
|
||||
u16_t len;
|
||||
u8_t len;
|
||||
|
||||
rimebuf_clear();
|
||||
|
||||
len = ethernode_read(rimebuf_dataptr(), RIMEBUF_SIZE);
|
||||
|
||||
if(len > 0) {
|
||||
|
||||
rimebuf_set_datalen(len);
|
||||
|
||||
PRINTF("ethernode_rime_process: received len %d\n", len);
|
||||
rime_input();
|
||||
}
|
||||
}
|
||||
}
|
||||
PROCESS_END();
|
||||
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
rime_driver_send(void)
|
||||
ethernode_rime_send(void)
|
||||
{
|
||||
PRINTF("ethernode_rime: sending %d bytes\n", rimebuf_totlen());
|
||||
ethernode_send_buf(rimebuf_hdrptr(), rimebuf_totlen());
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
ethernode_rime_init(void)
|
||||
{
|
||||
ethernode_set_receiver(receiver);
|
||||
rime_set_output(ethernode_rime_send);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
* $Id: ethernode.c,v 1.7 2007/03/29 22:25:52 adamdunkels Exp $
|
||||
* $Id: ethernode.c,v 1.8 2007/05/22 21:09:19 adamdunkels Exp $
|
||||
*/
|
||||
/**
|
||||
* \file
|
||||
|
@ -44,6 +44,8 @@
|
|||
#include "net/uip-fw.h"
|
||||
#include "ether.h"
|
||||
|
||||
#include "dev/radio.h"
|
||||
|
||||
#include "node.h"
|
||||
|
||||
#include "lib/random.h"
|
||||
|
@ -72,10 +74,26 @@ struct hdr {
|
|||
u8_t seqno;
|
||||
};
|
||||
|
||||
static int ethernode_on(void) {return 0;}
|
||||
static int ethernode_safe_off(void) {return 0;}
|
||||
|
||||
#include "net/ethernode.h"
|
||||
|
||||
const struct radio_driver ethernode_driver =
|
||||
{
|
||||
ethernode_send_buf,
|
||||
ethernode_read,
|
||||
ethernode_set_receiver,
|
||||
ethernode_on,
|
||||
ethernode_safe_off,
|
||||
};
|
||||
|
||||
|
||||
#define HDR_LEN UIP_LLH_LEN
|
||||
|
||||
#define ID_BROADCAST 0x80
|
||||
|
||||
PROCESS(ethernode_process, "Ethernode");
|
||||
/*-------------------------------------------------------------------------------*/
|
||||
static u8_t
|
||||
do_send(u8_t type, u8_t dest, struct hdr *hdr, int len)
|
||||
|
@ -122,7 +140,13 @@ ethernode_init(int port)
|
|||
*/
|
||||
/*-------------------------------------------------------------------------------*/
|
||||
int
|
||||
ethernode_read(u8_t *buf, int bufsize)
|
||||
ethernode_poll(void)
|
||||
{
|
||||
return ether_client_poll();
|
||||
}
|
||||
/*-------------------------------------------------------------------------------*/
|
||||
u16_t
|
||||
ethernode_read(u8_t *buf, u16_t bufsize)
|
||||
{
|
||||
int len;
|
||||
u8_t tmpbuf[2048];
|
||||
|
@ -191,8 +215,8 @@ ethernode_send(void)
|
|||
return UIP_FW_OK;
|
||||
}
|
||||
/*-------------------------------------------------------------------------------*/
|
||||
void
|
||||
ethernode_send_buf(u8_t *buf, int len)
|
||||
int
|
||||
ethernode_send_buf(const u8_t *buf, u16_t len)
|
||||
{
|
||||
char tmpbuf[2048];
|
||||
struct hdr *hdr = (struct hdr *)tmpbuf;
|
||||
|
@ -203,5 +227,32 @@ ethernode_send_buf(u8_t *buf, int len)
|
|||
|
||||
dest = ID_BROADCAST;
|
||||
do_send(TYPE_DATA, dest, hdr, len);
|
||||
return len;
|
||||
}
|
||||
/*-------------------------------------------------------------------------------*/
|
||||
static void (* receiver_callback)(const struct radio_driver *);
|
||||
/*-------------------------------------------------------------------------------*/
|
||||
void
|
||||
ethernode_set_receiver(void (* recv)(const struct radio_driver *))
|
||||
{
|
||||
process_start(ðernode_process, NULL);
|
||||
receiver_callback = recv;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(ethernode_process, ev, data)
|
||||
{
|
||||
PROCESS_BEGIN();
|
||||
|
||||
while(1) {
|
||||
process_poll(ðernode_process);
|
||||
PROCESS_WAIT_EVENT();
|
||||
|
||||
if(ethernode_poll()) {
|
||||
if(receiver_callback) {
|
||||
receiver_callback(ðernode_driver);
|
||||
}
|
||||
}
|
||||
}
|
||||
PROCESS_END();
|
||||
}
|
||||
/*-------------------------------------------------------------------------------*/
|
||||
|
|
|
@ -30,17 +30,22 @@
|
|||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
* $Id: ethernode.h,v 1.2 2007/03/13 13:07:48 adamdunkels Exp $
|
||||
* $Id: ethernode.h,v 1.3 2007/05/22 21:09:19 adamdunkels Exp $
|
||||
*/
|
||||
#ifndef __ETHERNODE_H__
|
||||
#define __ETHERNODE_H__
|
||||
|
||||
#include "contiki.h"
|
||||
|
||||
#include "dev/radio.h"
|
||||
|
||||
void ethernode_init(int port);
|
||||
int ethernode_poll(u8_t *buf, int bufsize);
|
||||
u16_t ethernode_read(u8_t *buf, u16_t bufsize);
|
||||
u8_t ethernode_send(void);
|
||||
void ethernode_send_buf(u8_t *buf, int len);
|
||||
int ethernode_send_buf(const u8_t *buf, u16_t len);
|
||||
void ethernode_periodic(void);
|
||||
void ethernode_set_receiver(void (* recv)(const struct radio_driver *));
|
||||
|
||||
extern const struct radio_driver ethernode_driver;
|
||||
|
||||
#endif /* __ETHERNODE_H__ */
|
||||
|
|
Loading…
Reference in a new issue