mirror of
https://github.com/oliverschmidt/contiki.git
synced 2024-12-21 19:29:18 +00:00
platform/minimal-net: Implement better idle behavior.
The minimal-net target, as currently written, wakes up the CPU every millisecond to check for packets, and will only react in real-time to input from stdin. If you are running this on a laptop battery, your battery will quickly drain. This change allows the CPU to idle when there is literally nothing to do while still being responsive to input from stein and/or incoming packets. This fix should significantly improve performance while significantly improving power usage. Win-win. Also added `_xassert()` implementation so that the contiki- provided `assert()` macro will work properly when used on this platform.
This commit is contained in:
parent
0a88373add
commit
092b6f3baa
@ -59,7 +59,6 @@ tapdev_output(void)
|
||||
static void
|
||||
pollhandler(void)
|
||||
{
|
||||
process_poll(&tapdev_process);
|
||||
uip_len = tapdev_poll();
|
||||
|
||||
if(uip_len > 0) {
|
||||
|
@ -38,5 +38,6 @@
|
||||
PROCESS_NAME(tapdev_process);
|
||||
|
||||
uint8_t tapdev_output(void);
|
||||
int tapdev_fd(void);
|
||||
|
||||
#endif /* __TAPDEV_DRV_H__ */
|
||||
|
@ -69,6 +69,13 @@ static unsigned long lasttime;
|
||||
|
||||
#define BUF ((struct uip_eth_hdr *)&uip_buf[0])
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
tapdev_fd(void)
|
||||
{
|
||||
return fd;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
remove_route(void)
|
||||
|
@ -85,6 +85,13 @@ static unsigned long lasttime;
|
||||
static void do_send(void);
|
||||
uint8_t tapdev_send(uip_lladdr_t *lladdr);
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
tapdev_fd(void)
|
||||
{
|
||||
return fd;
|
||||
}
|
||||
|
||||
|
||||
uint16_t
|
||||
tapdev_poll(void)
|
||||
@ -161,6 +168,7 @@ tapdev_init(void)
|
||||
/* gdk_input_add(fd, GDK_INPUT_READ,
|
||||
read_callback, NULL);*/
|
||||
|
||||
atexit(&tapdev_exit);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
|
@ -33,6 +33,8 @@
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <signal.h>
|
||||
#include <time.h>
|
||||
#include <sys/select.h>
|
||||
#include <unistd.h>
|
||||
@ -40,6 +42,7 @@
|
||||
|
||||
#include "contiki.h"
|
||||
#include "contiki-net.h"
|
||||
#include "lib/assert.h"
|
||||
|
||||
#include "dev/serial-line.h"
|
||||
|
||||
@ -267,9 +270,15 @@ main(void)
|
||||
(ipaddr.u16[2] != 0) ||
|
||||
(ipaddr.u16[3] != 0)) {
|
||||
#if UIP_CONF_ROUTER
|
||||
uip_ds6_prefix_add(&ipaddr, UIP_DEFAULT_PREFIX_LEN, 0, 0, 0, 0);
|
||||
if(!uip_ds6_prefix_add(&ipaddr, UIP_DEFAULT_PREFIX_LEN, 0, 0, 0, 0)) {
|
||||
fprintf(stderr,"uip_ds6_prefix_add() failed.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
#else /* UIP_CONF_ROUTER */
|
||||
uip_ds6_prefix_add(&ipaddr, UIP_DEFAULT_PREFIX_LEN, 0);
|
||||
if(!uip_ds6_prefix_add(&ipaddr, UIP_DEFAULT_PREFIX_LEN, 0)) {
|
||||
fprintf(stderr,"uip_ds6_prefix_add() failed.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
#endif /* UIP_CONF_ROUTER */
|
||||
|
||||
uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
|
||||
@ -290,14 +299,17 @@ main(void)
|
||||
|
||||
#if UIP_CONF_IPV6 && !RPL_BORDER_ROUTER /* Border router process prints addresses later */
|
||||
{
|
||||
uint8_t i;
|
||||
int i = 0;
|
||||
int interface_count = 0;
|
||||
for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
|
||||
if(uip_ds6_if.addr_list[i].isused) {
|
||||
printf("IPV6 Addresss: ");
|
||||
sprint_ip6(uip_ds6_if.addr_list[i].ipaddr);
|
||||
printf("\n");
|
||||
printf("IPV6 Addresss: ");
|
||||
sprint_ip6(uip_ds6_if.addr_list[i].ipaddr);
|
||||
printf("\n");
|
||||
interface_count++;
|
||||
}
|
||||
}
|
||||
assert(0 < interface_count);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -305,14 +317,40 @@ main(void)
|
||||
fd_set fds;
|
||||
int n;
|
||||
struct timeval tv;
|
||||
clock_time_t next_event;
|
||||
|
||||
n = process_run();
|
||||
next_event = etimer_next_expiration_time() - clock_time();
|
||||
|
||||
#if DEBUG_SLEEP
|
||||
if(n > 0)
|
||||
printf("sleep: %d events pending\n",n);
|
||||
else
|
||||
printf("sleep: next event @ T-%.03f\n",(double)next_event / (double)CLOCK_SECOND);
|
||||
#endif
|
||||
|
||||
#ifdef __CYGWIN__
|
||||
/* wpcap doesn't appear to support select, so
|
||||
* we can't idle the process on windows. */
|
||||
next_event = 0;
|
||||
#endif
|
||||
|
||||
if(next_event > (CLOCK_SECOND * 2))
|
||||
next_event = CLOCK_SECOND * 2;
|
||||
tv.tv_sec = n ? 0 : (next_event / CLOCK_SECOND);
|
||||
tv.tv_usec = n ? 0 : ((next_event % 1000) * 1000);
|
||||
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 1000;
|
||||
FD_ZERO(&fds);
|
||||
FD_SET(STDIN_FILENO, &fds);
|
||||
#ifdef __CYGWIN__
|
||||
select(1, &fds, NULL, NULL, &tv);
|
||||
#else
|
||||
FD_SET(tapdev_fd(), &fds);
|
||||
if(0 > select(tapdev_fd() + 1, &fds, NULL, NULL, &tv)) {
|
||||
perror("Call to select() failed.");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
#endif
|
||||
|
||||
if(FD_ISSET(STDIN_FILENO, &fds)) {
|
||||
char c;
|
||||
@ -320,6 +358,7 @@ main(void)
|
||||
serial_line_input_byte(c);
|
||||
}
|
||||
}
|
||||
process_poll(&tapdev_process);
|
||||
etimer_request_poll();
|
||||
}
|
||||
|
||||
@ -338,6 +377,14 @@ uip_log(char *m)
|
||||
printf("uIP: '%s'\n", m);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
_xassert(const char *file, int line)
|
||||
{
|
||||
fprintf(stderr, "%s:%u: failed assertion\n", file, line);
|
||||
abort();
|
||||
}
|
||||
|
||||
|
||||
unsigned short
|
||||
sensors_light1(void)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user