Esempio n. 1
0
int main()
{
	unsigned char ch = '\0';
  static char lastcommand[CFG_CBSIZE] = { 0, };
	int flag = 0;

	int i = 0;

	clock_init();
	led1_on();

	//init_baudrate();
	led2_on();
	//clock_init();

	initUART();

/*
	serial_putc('c'); 
	serial_putc('d'); 
	serial_putc('o'); 
	printf("11 is %d\n", 11);
*/

	printf("xyz.blk cblk is \n");
	run_command ("download", 0);

	int len = 0;
  for (;;) {
    len = readline (CFG_PROMPT);
		
		if (len > 0)
			strcpy(lastcommand, console_buffer);

    if (len == -1)
      puts ("<INTERRUPT>\n");
    else
			run_command (lastcommand, flag);
}

	//printf1("code\n");
	//printf1("11.1 is %s\n", "kdh");

/*
	ch = '\n';
	serial_putc(ch/10+'0'); 
	serial_putc(ch%10+'0'); 
	serial_putc(' '); 
*/

	//nand_init();

/*
	unsigned char data[2049] = {0};

	nand_read( &data[0], 0, 2048);

	for ( i = 0; i < 20; i++ )
	{
		ch = data[i];
		serial_putc(ch/16 >= 10 ? ch/16 - 10 +'A' : ch/16+'0'); 
		serial_putc(ch%16 >= 10 ? ch%16 - 10 +'A' : ch%16+'0'); 
		serial_putc(' '); 
	}
*/

/*
	LED1_ON();
	init_baudrate();
	clock_init();

	initUART();
	
	serial_putc('c'); 
	serial_putc('o'); 
	serial_putc('d'); 
	serial_putc('e'); 
	serial_putc('\n'); 
	serial_putc('\n'); 

	ch = '\n';
	serial_putc(ch/10+'0'); 
	serial_putc(ch%10+'0'); 
	serial_putc(' '); 

	delay(800000);
	LED1_OFF();
*/

	//printf1("pclk scale is %d\n", get_PCLK());
	
	while(1)
	{
		ch = serial_getc();

		//if (ch <= '9' && ch >= '0')
		if (ch == '\r')
			ch = '\n';
		serial_putc(ch);
	};

	return 0;
};
Esempio n. 2
0
int main(void)
{
	unsigned int i;
	uip_ipaddr_t ipaddr;	/* local IP address */
	struct timer periodic_timer, arp_timer;

	char uart_test[]= "\nWelcome to smart home debugger";

	// system init
	SystemInit();                                      /* setup core clocks */

	// clock init
	clock_init();

	//uart init..
	UARTInit(3, 38400);
	UARTSend(3, (uint8_t *)uart_test, sizeof(uart_test) );	
	

	// two timers for tcp/ip
	timer_set(&periodic_timer, CLOCK_SECOND / 2); /* 0.5s */
	timer_set(&arp_timer, CLOCK_SECOND * 10);	/* 10s */	

	// ethernet init
	tapdev_init();

	// Initialize the uIP TCP/IP stack.
	uip_init();

	uip_ipaddr(ipaddr, 192,168,1,210);
	//uip_ipaddr(ipaddr, 192,168,0,210);
	uip_sethostaddr(ipaddr);	/* host IP address */

	uip_ipaddr(ipaddr, 192,168,1,1);	//this is for the case when the uc is connected to the internet
	//uip_ipaddr(ipaddr, 192,168,0,1); //this is for my local network
	uip_setdraddr(ipaddr);	/* router IP address */

	uip_ipaddr(ipaddr, 255,255,255,0);
	uip_setnetmask(ipaddr);	/* mask */

	// Initialize the HTTP server, listen to port 80.
	//httpd_init();
	scadapp_init();

	

	while(1)
	{
 	/* receive packet and put in uip_buf */
		uip_len = tapdev_read(uip_buf);
    	if(uip_len > 0)		/* received packet */
    	{ 
      		if(BUF->type == htons(UIP_ETHTYPE_IP))	/* IP packet */
      		{
	      		uip_arp_ipin();	
	      		uip_input();
	      		/* If the above function invocation resulted in data that
	         		should be sent out on the network, the global variable
	         		uip_len is set to a value > 0. */
 
	      		if(uip_len > 0)
        		{
	        		uip_arp_out();	
	        		tapdev_send(uip_buf,uip_len);
	      		}
      		}
	      	else if(BUF->type == htons(UIP_ETHTYPE_ARP))	/*ARP packet */
	      	{
	        	uip_arp_arpin();
		      	/* If the above function invocation resulted in data that
		         	should be sent out on the network, the global variable
		         	uip_len is set to a value > 0. */
		      	if(uip_len > 0)
	        	{
		        	tapdev_send(uip_buf,uip_len);	/* ARP ack*/
		      	}
	      	}
    	}
    	else if(timer_expired(&periodic_timer))	/* no packet but periodic_timer time out (0.5s)*/
    	{
      		timer_reset(&periodic_timer);
	  
      		for(i = 0; i < UIP_CONNS; i++)
      		{
      			uip_periodic(i);
		        /* If the above function invocation resulted in data that
		           should be sent out on the network, the global variable
		           uip_len is set to a value > 0. */
		        if(uip_len > 0)
		        {
		          uip_arp_out();
		          tapdev_send(uip_buf,uip_len);
		        }
      		}
#if UIP_UDP
			for(i = 0; i < UIP_UDP_CONNS; i++) {
				uip_udp_periodic(i);
				/* If the above function invocation resulted in data that
				   should be sent out on the network, the global variable
				   uip_len is set to a value > 0. */
				if(uip_len > 0) {
				  uip_arp_out();
				  tapdev_send();
				}
			}
#endif /* UIP_UDP */
	     	/* Call the ARP timer function every 10 seconds. */
			if(timer_expired(&arp_timer))
			{
				timer_reset(&arp_timer);
				uip_arp_timer();
			}
    	}
	}
}
Esempio n. 3
0
int main(void) {
    /* generic hw init */
    hw_init();
    
    /* init uart */
    uart_init();

#ifdef DEBUG_INIT
    printf("AlceOSD hw%dv%d fw%d.%d.%d\r\n", hw_rev >> 4, hw_rev & 0xf, VERSION_MAJOR, VERSION_MINOR, VERSION_DEV);
    if (RCONbits.WDTO)
        printf("watchdog reset\r\n");
    if (RCONbits.EXTR)
        printf("external reset\r\n");
    if (RCONbits.SWR)
        printf("software reset\r\n");
    if (RCONbits.IOPUWR)
        printf("ill opcode / uninit W reset\r\n");
    if (RCONbits.WDTO)
        printf("trap conflict reset\r\n");
#endif

    /* real time clock init */
    clock_init();

    /* adc init */
    adc_init();

    /* init video driver */
    init_video();

    /* try to load config from flash */
    config_init();

    /* init widget modules */
    widgets_init();
    
    /* setup tabs */
    tabs_init();

    /* welcome message */
    console_printf("AlceOSD hw%dv%d fw%d.%d.%d\n", hw_rev >> 4, hw_rev & 0xf, VERSION_MAJOR, VERSION_MINOR, VERSION_DEV);

    /* init home tracking */
    init_home();
    
    /* init flight status tracking */
    init_flight_stats();

    /* init mavlink module */
    mavlink_init();

    /* init uavtalk module */
    uavtalk_init();
    
    /* init frsky module */
    frsky_init();

    /* link serial ports to processes */
    uart_set_config_clients();

    /* enable all interrupts */
    _IPL = 0;
    _IPL3 = 1;

    console_printf("Processes running...\n");
    /* main loop */
    process_run();

    return 0;
}
Esempio n. 4
0
/**
 * \brief Main routine for the cc2538dk platform
 */
int
main(void)
{
  nvic_init();
  ioc_init();
  sys_ctrl_init();
  clock_init();
  lpm_init();
  rtimer_init();
  gpio_init();

  leds_init();
  fade(LEDS_YELLOW);

  process_init();

  watchdog_init();
  button_sensor_init();

  /*
   * Character I/O Initialisation.
   * When the UART receives a character it will call serial_line_input_byte to
   * notify the core. The same applies for the USB driver.
   *
   * If slip-arch is also linked in afterwards (e.g. if we are a border router)
   * it will overwrite one of the two peripheral input callbacks. Characters
   * received over the relevant peripheral will be handled by
   * slip_input_byte instead
   */
#if UART_CONF_ENABLE
  uart_init(0);
  uart_init(1);
  uart_set_input(SERIAL_LINE_CONF_UART, serial_line_input_byte);
#endif

#if USB_SERIAL_CONF_ENABLE
  usb_serial_init();
  usb_serial_set_input(serial_line_input_byte);
#endif

  serial_line_init();

  INTERRUPTS_ENABLE();
  fade(LEDS_GREEN);

  PUTS(CONTIKI_VERSION_STRING);
  PUTS(BOARD_STRING);

  PRINTF(" Net: ");
  PRINTF("%s\n", NETSTACK_NETWORK.name);
  PRINTF(" MAC: ");
  PRINTF("%s\n", NETSTACK_MAC.name);
  PRINTF(" RDC: ");
  PRINTF("%s\n", NETSTACK_RDC.name);

  /* Initialise the H/W RNG engine. */
  random_init(0);

  udma_init();

  process_start(&etimer_process, NULL);
  ctimer_init();

  set_rf_params();

#if CRYPTO_CONF_INIT
  crypto_init();
  crypto_disable();
#endif

  netstack_init();

#if NETSTACK_CONF_WITH_IPV6
  memcpy(&uip_lladdr.addr, &linkaddr_node_addr, sizeof(uip_lladdr.addr));
  queuebuf_init();
  process_start(&tcpip_process, NULL);
#endif /* NETSTACK_CONF_WITH_IPV6 */

  adc_init();

  process_start(&sensors_process, NULL);

  energest_init();
  ENERGEST_ON(ENERGEST_TYPE_CPU);

  autostart_start(autostart_processes);

  watchdog_start();
  fade(LEDS_ORANGE);

  while(1) {
    uint8_t r;
    do {
      /* Reset watchdog and handle polls and events */
      watchdog_periodic();

      r = process_run();
    } while(r > 0);

    /* We have serviced all pending events. Enter a Low-Power mode. */
    lpm_enter();
  }
}
Esempio n. 5
0
/*-----------------------------Low level initialization--------------------*/
static void initialize(void) {

  watchdog_init();
  watchdog_start();

#if CONFIG_STACK_MONITOR
  /* Simple stack pointer highwater monitor. The 'm' command in cdc_task.c
   * looks for the first overwritten magic number.
   */
{
extern uint16_t __bss_end;
uint16_t p=(uint16_t)&__bss_end;
    do {
      *(uint16_t *)p = 0x4242;
      p+=100;
    } while (p<SP-100); //don't overwrite our own stack
}
#endif

  /* Initialize hardware */
  // Checks for "finger", jumps to DFU if present.
  init_lowlevel();
  
  /* Clock */
  clock_init();

  /* Leds are referred to by number to prevent any possible confusion :) */
  /* Led0 Blue Led1 Red Led2 Green Led3 Yellow */
  Leds_init();
  Led1_on();

/* Get a random (or probably different) seed for the 802.15.4 packet sequence number.
 * Some layers will ignore duplicates found in a history (e.g. Contikimac)
 * causing the initial packets to be ignored after a short-cycle restart.
 */
  ADMUX =0x1E;              //Select AREF as reference, measure 1.1 volt bandgap reference.
  ADCSRA=1<<ADEN;           //Enable ADC, not free running, interrupt disabled, fastest clock
  ADCSRA|=1<<ADSC;          //Start conversion
  while (ADCSRA&(1<<ADSC)); //Wait till done
  PRINTD("ADC=%d\n",ADC);
  random_init(ADC);
  ADCSRA=0;                 //Disable ADC
  
#if USB_CONF_RS232
  /* Use rs232 port for serial out (tx, rx, gnd are the three pads behind jackdaw leds */
  rs232_init(RS232_PORT_0, USART_BAUD_57600,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);
  /* Redirect stdout to second port */
  rs232_redirect_stdout(RS232_PORT_0);
#if ANNOUNCE
  PRINTA("\n\n*******Booting %s*******\n",CONTIKI_VERSION_STRING);
#endif
#endif
	
  /* rtimer init needed for low power protocols */
  rtimer_init();

  /* Process subsystem. */
  process_init();

  /* etimer process must be started before USB or ctimer init */
  process_start(&etimer_process, NULL);

  Led2_on();
  /* Now we can start USB enumeration */
  process_start(&usb_process, NULL);

  /* Start CDC enumeration, bearing in mind that it may fail */
  /* Hopefully we'll get a stdout for startup messages, if we don't already */
#if USB_CONF_SERIAL
  process_start(&cdc_process, NULL);
{unsigned short i;
  for (i=0;i<65535;i++) {
    process_run();
    watchdog_periodic();
    if (stdout) break;
  }
#if !USB_CONF_RS232
  PRINTA("\n\n*******Booting %s*******\n",CONTIKI_VERSION_STRING);
#endif
}
#endif
  if (!stdout) Led3_on();
  
#if RF230BB
#if JACKDAW_CONF_USE_SETTINGS
  PRINTA("Settings manager will be used.\n");
#else
{uint8_t x[2];
	*(uint16_t *)x = eeprom_read_word((uint16_t *)&eemem_channel);
	if((uint8_t)x[0]!=(uint8_t)~x[1]) {
        PRINTA("Invalid EEPROM settings detected. Rewriting with default values.\n");
        get_channel_from_eeprom();
    }
}
#endif

  ctimer_init();
  /* Start radio and radio receive process */
  /* Note this starts RF230 process, so must be done after process_init */
  NETSTACK_RADIO.init();

  /* Set addresses BEFORE starting tcpip process */

  memset(&tmp_addr, 0, sizeof(rimeaddr_t));

  if(get_eui64_from_eeprom(tmp_addr.u8));
   
  //Fix MAC address
  init_net();

#if UIP_CONF_IPV6
  memcpy(&uip_lladdr.addr, &tmp_addr.u8, 8);
#endif

  rf230_set_pan_addr(
	get_panid_from_eeprom(),
	get_panaddr_from_eeprom(),
	(uint8_t *)&tmp_addr.u8
  );
  
  rf230_set_channel(get_channel_from_eeprom());
  rf230_set_txpower(get_txpower_from_eeprom());

  rimeaddr_set_node_addr(&tmp_addr); 

  /* Initialize stack protocols */
  queuebuf_init();
  NETSTACK_RDC.init();
  NETSTACK_MAC.init();
  NETSTACK_NETWORK.init();

#if ANNOUNCE
  PRINTA("MAC address %x:%x:%x:%x:%x:%x:%x:%x\n\r",tmp_addr.u8[0],tmp_addr.u8[1],tmp_addr.u8[2],tmp_addr.u8[3],tmp_addr.u8[4],tmp_addr.u8[5],tmp_addr.u8[6],tmp_addr.u8[7]);
  PRINTA("%s %s, channel %u, panid 0x%X",NETSTACK_MAC.name, NETSTACK_RDC.name, rf230_get_channel(), IEEE802154_PANID);
  if (NETSTACK_RDC.channel_check_interval) {
    unsigned short tmp;
    tmp=CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval == 0 ? 1:\
                        NETSTACK_RDC.channel_check_interval());
    if (tmp<65535) PRINTA(", check rate %u Hz",tmp);
  }
  PRINTA("\n");
#endif

#if UIP_CONF_IPV6_RPL
#if RPL_BORDER_ROUTER
  process_start(&tcpip_process, NULL);
  process_start(&border_router_process, NULL);
  PRINTD ("RPL Border Router Started\n");
#else
  process_start(&tcpip_process, NULL);
  PRINTD ("RPL Started\n");
#endif
#if RPL_HTTPD_SERVER
  extern struct process httpd_process;
  process_start(&httpd_process, NULL);
  PRINTD ("Webserver Started\n");
#endif
#endif /* UIP_CONF_IPV6_RPL */

#else  /* RF230BB */
/* The order of starting these is important! */
  process_start(&mac_process, NULL);
  process_start(&tcpip_process, NULL);
#endif /* RF230BB */

  /* Start ethernet network and storage process */
  process_start(&usb_eth_process, NULL);
#if USB_CONF_STORAGE
  process_start(&storage_process, NULL);
#endif

  /* Autostart other processes */
  /* There are none in the default build so autostart_processes will be unresolved in the link. */
  /* The AUTOSTART_PROCESSES macro which defines it can only be used in the .co module. */
  /* See /examples/ravenusbstick/ravenusb.c for an autostart template. */
#if 0
  autostart_start(autostart_processes);
#endif

#if ANNOUNCE
#if USB_CONF_RS232
  PRINTA("Online.\n");
#else
  PRINTA("Online. Type ? for Jackdaw menu.\n");
#endif
#endif

Leds_off();
}
Esempio n. 6
0
void
kernel_bootstrap(void)
{
	kern_return_t	result;
	thread_t	thread;
	char		namep[16];

	printf("%s\n", version); /* log kernel version */

	if (PE_parse_boot_argn("-l", namep, sizeof (namep))) /* leaks logging */
		turn_on_log_leaks = 1;

	PE_parse_boot_argn("trace", &new_nkdbufs, sizeof (new_nkdbufs));
	PE_parse_boot_argn("trace_wake", &wake_nkdbufs, sizeof (wake_nkdbufs));
	PE_parse_boot_argn("trace_panic", &write_trace_on_panic, sizeof(write_trace_on_panic));
	PE_parse_boot_argn("trace_typefilter", &trace_typefilter, sizeof(trace_typefilter));

	scale_setup();

	kernel_bootstrap_log("vm_mem_bootstrap");
	vm_mem_bootstrap();

	kernel_bootstrap_log("cs_init");
	cs_init();

	kernel_bootstrap_log("vm_mem_init");
	vm_mem_init();

	machine_info.memory_size = (uint32_t)mem_size;
	machine_info.max_mem = max_mem;
	machine_info.major_version = version_major;
	machine_info.minor_version = version_minor;


#if CONFIG_TELEMETRY
	kernel_bootstrap_log("telemetry_init");
	telemetry_init();
#endif

#if CONFIG_CSR
	kernel_bootstrap_log("csr_init");
	csr_init();
#endif

	kernel_bootstrap_log("stackshot_lock_init");	
	stackshot_lock_init();

	kernel_bootstrap_log("sched_init");
	sched_init();

	kernel_bootstrap_log("waitq_bootstrap");
	waitq_bootstrap();

	kernel_bootstrap_log("ipc_bootstrap");
	ipc_bootstrap();

#if CONFIG_MACF
	kernel_bootstrap_log("mac_policy_init");
	mac_policy_init();
#endif

	kernel_bootstrap_log("ipc_init");
	ipc_init();

	/*
	 * As soon as the virtual memory system is up, we record
	 * that this CPU is using the kernel pmap.
	 */
	kernel_bootstrap_log("PMAP_ACTIVATE_KERNEL");
	PMAP_ACTIVATE_KERNEL(master_cpu);

	kernel_bootstrap_log("mapping_free_prime");
	mapping_free_prime();						/* Load up with temporary mapping blocks */

	kernel_bootstrap_log("machine_init");
	machine_init();

	kernel_bootstrap_log("clock_init");
	clock_init();

	ledger_init();

	/*
	 *	Initialize the IPC, task, and thread subsystems.
	 */
#if CONFIG_COALITIONS
	kernel_bootstrap_log("coalitions_init");
	coalitions_init();
#endif

	kernel_bootstrap_log("task_init");
	task_init();

	kernel_bootstrap_log("thread_init");
	thread_init();

#if CONFIG_ATM
	/* Initialize the Activity Trace Resource Manager. */
	kernel_bootstrap_log("atm_init");
	atm_init();
#endif

#if CONFIG_BANK
	/* Initialize the BANK Manager. */
	kernel_bootstrap_log("bank_init");
	bank_init();
#endif
	
	/* initialize the corpse config based on boot-args */
	corpses_init();

	/*
	 *	Create a kernel thread to execute the kernel bootstrap.
	 */
	kernel_bootstrap_log("kernel_thread_create");
	result = kernel_thread_create((thread_continue_t)kernel_bootstrap_thread, NULL, MAXPRI_KERNEL, &thread);

	if (result != KERN_SUCCESS) panic("kernel_bootstrap: result = %08X\n", result);

	thread->state = TH_RUN;
	thread->last_made_runnable_time = mach_absolute_time();
	thread_deallocate(thread);

	kernel_bootstrap_log("load_context - done");
	load_context(thread);
	/*NOTREACHED*/
}
Esempio n. 7
0
int main(void)
{

	network_init();
	// network.c
	// enc28j60Init();
	// enc28j60PhyWrite(PHLCON,0x476);

	//CLKPR = (1<<CLKPCE);	//Change prescaler
	//CLKPR = (1<<CLKPS0);	//Use prescaler 2
	//clock_prescale_set(clock_div_2);
	enc28j60Write(ECOCON, 1 & 0x7);	
	// enc28j60.c
	//Get a 25MHz signal from enc28j60

	#ifdef MY_DEBUG
	uartInit();
	uartSetBaudRate(9600);
	rprintfInit(uartSendByte);
	#endif

	int i;
	uip_ipaddr_t ipaddr; // uip.h 
	// typedef u16_t uip_ip4addr_t[2]; 
	// typedef uip_ip4addr_t uip_ipaddr_t;
	struct timer periodic_timer, arp_timer;

	clock_init();


	timer_set(&periodic_timer, CLOCK_SECOND / 2);
	timer_set(&arp_timer, CLOCK_SECOND * 10);

	uip_init();
	// uip.c

	//uip_arp_init();
	// uip_arp.c
	// must be done or sometimes arp doesn't work
	
	struct uip_eth_addr mac = {UIP_ETHADDR0, UIP_ETHADDR1, UIP_ETHADDR2, UIP_ETHADDR3, UIP_ETHADDR4, UIP_ETHADDR5};

	uip_setethaddr(mac);

	simple_httpd_init();

#ifdef __DHCPC_H__
	dhcpc_init(&mac, 6);
#else
    uip_ipaddr(ipaddr, 192,168,0,1); // uip.h
	uip_sethostaddr(ipaddr); // uip.h
	// #define uip_sethostaddr(addr) uip_ipaddr_copy(uip_hostaddr, (addr))
    uip_ipaddr(ipaddr, 192,168,0,1);
    uip_setdraddr(ipaddr);
	// #define uip_setdraddr(addr) uip_ipaddr_copy(uip_draddr, (addr))
    uip_ipaddr(ipaddr, 255,255,255,0);
    uip_setnetmask(ipaddr);
	// #define uip_setnetmask(addr) uip_ipaddr_copy(uip_netmask, (addr))

#endif /*__DHCPC_H__*/


	while(1){

		uip_len = network_read(); 
		// uip.c : u16_t uip_len;
		// network.c : return ((unt16_t) enc28j60PacketReceive(UIP_BUFSIZE, (uint8_t *)uip_buf)); 
		// enc28j60.c : enc28j60PacketReceive
		// uip.c : uint8_t uip_buf[UIP_BUFSIZE+2]; 
		// uipconf.h : UIP_BUFSIZE:300
		if(uip_len > 0) {
			if(BUF->type == htons(UIP_ETHTYPE_IP)){  
			#ifdef MY_DEBUG
			//rprintf("eth in : uip_len = %d, proto = %d\n", uip_len, uip_buf[23]);
			//debugPrintHexTable(uip_len, uip_buf);
			#endif
			// struct uip_eth_hdr {
			//	struct uip_eth_addr dest;
			//	struct uip_eth_addr src;
			//	u16_t type;
			//	};
			// struct uip_eth_addr { // Representation of a 48-bit Ethernet address
			// 	u8_t addr[6];
			// };
			//	http://www.netmanias.com/ko/post/blog/5372/ethernet-ip-tcp-ip/packet-header-ethernet-ip-tcp-ip
			//	UIP_ETHTYPE_IP(0x0800) : IPv4 Packet(ICMP, TCP, UDP)
				uip_arp_ipin();
				#ifdef MY_DEBUG
				//rprintf("ip in : uip_len = %d, proto = %d\n", uip_len, uip_buf[23]);
				//debugPrintHexTable(uip_len, uip_buf+14);
				#endif
				// uip_arp.c
				// #define IPBUF ((struct ethip_hdr *)&uip_buf[0])
				// struct ethip_hdr {
				// 	 struct uip_eth_hdr ethhdr;
				// 	 // IP header
				// 	 u8_t vhl,
				// 	 	tos,
				// 	 	len[2],
				// 	 	ipid[2],
				// 	 	ipoffset[2],
				// 	 	ttl,
				// 	 	proto; // ICMP: 1, TCP: 6, UDP: 17
				// 	 u16_t ipchksum;
				// 	 u16_t srcipaddr[2],
				// 	 destipaddr[2];
				// }
				// if ((IBUF->srcipaddr & uip_netmask) != uip_hostaddr & (uip_netmask)) return;
				// uip_arp_update(IPBUF->srcipaddr, &(IPBUF->ethhdr.src));
				uip_input();
				#ifdef MY_DEBUG
				//rprintf("ip out : uip_len = %d, proto = %d\n", uip_len, uip_buf[23]);
				//debugPrintHexTable(uip_len, uip_buf+14);
				#endif
				// ip out packet
				// eg ICMP 
				// uip_len : 84
				// source ip <-> destination ip
				// type : 8 (Echo (ping) request) -> 0 (Echo (ping) reply)
				// uip.h
				// #define uip_input()        uip_process(UIP_DATA) // UIP_DATA(1) : Tells uIP that there is incoming
				// uip_process : The actual uIP function which does all the work.
				if(uip_len > 0) {
					uip_arp_out();
					#ifdef MY_DEBUG
					//rprintf("ip out : uip_len = %d, proto = %d\n", uip_len, uip_buf[23]);
					//debugPrintHexTable(uip_len, uip_buf);
					#endif
					// Destination MAC Address <=> Source MAC Address
					// w/o Ethernet CRC
					// uip_arp.c

					network_send();
					// network.c
					// if(uip_len <= UIP_LLH_LEN + 40){ // UIP_LLH_LEN : 14
					// 	enc28j60PacketSend(uip_len, (uint8_t *)uip_buf, 0, 0);
					// }else{
					// enc28j60PacketSend(54, (uint8_t *)uip_buf , uip_len - UIP_LLH_LEN - 40, (uint8_t*)uip_appdata);
					// }
				}
			}else if(BUF->type == htons(UIP_ETHTYPE_ARP)){
				// UIP_ETHYPE_ARP(0x0806)
				#ifdef MY_DEBUG
				//rprintf("eth in : uip_len = %d\n", uip_len);
				//debugPrintHexTable(uip_len, uip_buf);
				#endif
				// arp in : 64 bytes
				uip_arp_arpin();
				if(uip_len > 0){ // always uip_len > 0
					#ifdef MY_DEBUG
					//rprintf("arp in : uip_len = %d\n", uip_len);
					//debugPrintHexTable(uip_len, uip_buf);
					#endif
					// arp out : 42 bytes
					// 64 - Ethernet_padding(18) - Ethernet_CRC(4)
					// Send MAC address <--> Target MAC address
					// Send IP address <--> Target IP address
					// uip_arp.c
					network_send();
				}
			}

		}else if(timer_expired(&periodic_timer)) {

			timer_reset(&periodic_timer);

			for(i = 0; i < UIP_CONNS; i++) {
				uip_periodic(i);
                // uip.h
                // #define uip_udp_periodic(conn) do { uip_udp_conn = &uip_udp_conns[conn]; \
                // uip_process(UIP_UDP_TIMER); } while (0) // UIP_UDP_TIMER : 5
                // uip.c; uip_process
                // if(flag == UIP_UDP_TIMER) {
                //  if(uip_udp_conn->lport != 0) {
                //      uip_conn = NULL;
                //      uip_sappdata = uip_appdata = &uip_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN];
                //      uip_len = uip_slen = 0;
                //      uip_flags = UIP_POLL;
                //      UIP_UDP_APPCALL();
                //      goto udp_send;
                //  }
                // } else {
                //  goto drop;
                // }
				if(uip_len > 0) {
					uip_arp_out();
					network_send();
				}
			}

			#if UIP_UDP
			for(i = 0; i < UIP_UDP_CONNS; i++) {
				uip_udp_periodic(i);
				if(uip_len > 0) {
					uip_arp_out();
					network_send();
				}
			}
			#endif /* UIP_UDP */

			if(timer_expired(&arp_timer)) {
				timer_reset(&arp_timer);
				uip_arp_timer();
			}
		}
	}
	return 0;
}
Esempio n. 8
0
int
main(int argc, char **argv)
{
    bool flip_flop = false;

    asm ("di");
    /* Setup clocks */
    CMC = 0x11U;                                        /* Enable XT1, disable X1 */
    CSC = 0x80U;                                        /* Start XT1 and HOCO, stop X1 */
    CKC = 0x00U;
    delay_1sec();
    OSMC = 0x00;                                       /* Supply fsub to peripherals, including Interval Timer */
    uart0_init();

#if __GNUC__
    /* Force linking of custom write() function: */
    write(1, NULL, 0);
#endif

    /* Setup 12-bit interval timer */
    RTCEN = 1;                                              /* Enable 12-bit interval timer and RTC */
    ITMK = 1;                                               /* Disable IT interrupt */
    ITPR0 = 0;                                              /* Set interrupt priority - highest */
    ITPR1 = 0;
    ITMC = 0x8FFFU;                                    /* Set maximum period 4096/32768Hz = 1/8 s, and start timer */
    ITIF = 0;                                               /* Clear interrupt request flag */
    ITMK = 0;                                               /* Enable IT interrupt */
    /* asm ("ei");                                             / * Enable interrupts * / */

    /* Disable analog inputs because they can conflict with the SPI buses: */
    ADPC = 0x01;  /* Configure all analog pins as digital I/O. */
    PMC0 &= 0xF0; /* Disable analog inputs. */

    clock_init();

    /* Initialize Joystick Inputs: */
    PM5 |= BIT(5) | BIT(4) | BIT(3) | BIT(2) | BIT(1); /* Set pins as inputs. */
    PU5 |= BIT(5) | BIT(4) | BIT(3) | BIT(2) | BIT(1); /* Enable internal pull-up resistors. */

    /* Initialize LED outputs: */
#define BIT(n) (1 << (n))
    PM12 &= ~BIT(0); /* LED1 */
    PM4 &= ~BIT(3);  /* LED2 */
    PM1 &= ~BIT(6);  /* LED3 */
    PM1 &= ~BIT(5);  /* LED4 */
    PM0 &= ~BIT(6);  /* LED5 */
    PM0 &= ~BIT(5);  /* LED6 */
    PM3 &= ~BIT(0);  /* LED7 */
    PM5 &= ~BIT(0);  /* LED8 */

#if UIP_CONF_IPV6
#if UIP_CONF_IPV6_RPL
    printf(CONTIKI_VERSION_STRING " started with IPV6, RPL" NEWLINE);
#else
    printf(CONTIKI_VERSION_STRING " started with IPV6" NEWLINE);
#endif
#else
    printf(CONTIKI_VERSION_STRING " started" NEWLINE);
#endif

    /* crappy way of remembering and accessing argc/v */
    contiki_argc = argc;
    contiki_argv = argv;

    process_init();
    process_start(&etimer_process, NULL);
    ctimer_init();

    set_rime_addr();

    queuebuf_init();

    netstack_init();
    printf("MAC %s RDC %s NETWORK %s" NEWLINE, NETSTACK_MAC.name, NETSTACK_RDC.name, NETSTACK_NETWORK.name);

#if WITH_UIP6
    memcpy(&uip_lladdr.addr, serial_id, sizeof(uip_lladdr.addr));

    process_start(&tcpip_process, NULL);
    printf("Tentative link-local IPv6 address ");
    {
        uip_ds6_addr_t *lladdr;
        int i;
        lladdr = uip_ds6_get_link_local(-1);
        for(i = 0; i < 7; ++i) {
            printf("%02x%02x:", lladdr->ipaddr.u8[i * 2],
                   lladdr->ipaddr.u8[i * 2 + 1]);
        }
        /* make it hardcoded... */
        lladdr->state = ADDR_AUTOCONF;

        printf("%02x%02x" NEWLINE, lladdr->ipaddr.u8[14], lladdr->ipaddr.u8[15]);
    }
#else
    process_start(&tcpip_process, NULL);
#endif

    serial_line_init();

    autostart_start(autostart_processes);

    while(1) {
        watchdog_periodic();

        if(NETSTACK_RADIO.pending_packet()) {
            int len;
            packetbuf_clear();
            len = NETSTACK_RADIO.read(packetbuf_dataptr(), PACKETBUF_SIZE);
            if(len > 0) {
                packetbuf_set_datalen(len);
                NETSTACK_RDC.input();
            }
        }

        while(uart0_can_getchar()) {
            char c;
            UART_RX_LED = 1;
            c = uart0_getchar();
            if(uart0_input_handler) {
                uart0_input_handler(c);
            }
        }
        UART_RX_LED = 0;

        process_run();

        etimer_request_poll();

        HEARTBEAT_LED1 = flip_flop;
        flip_flop = !flip_flop;
        HEARTBEAT_LED2 = flip_flop;
    }

    return 0;
}
Esempio n. 9
0
/*------Done in a subroutine to keep main routine stack usage small--------*/
void initialize(void)
{
  //calibrate_rc_osc_32k(); //CO: Had to comment this out

#ifdef RAVEN_LCD_INTERFACE
  /* First rs232 port for Raven 3290 port */
  rs232_init(RS232_PORT_0, USART_BAUD_38400,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);
  /* Set input handler for 3290 port */
  rs232_set_input(0,raven_lcd_serial_input);
#endif

  /* Second rs232 port for debugging */
  rs232_init(RS232_PORT_1, USART_BAUD_57600,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);
  /* Redirect stdout to second port */
  rs232_redirect_stdout(RS232_PORT_1);
  clock_init();
  printf_P(PSTR("\r\n*******Booting %s*******\r\n"),CONTIKI_VERSION_STRING);

 /* Initialize process subsystem */
  process_init();

#ifdef RF230BB
{
  /* Start radio and radio receive process */
  rf230_init();
  sicslowpan_init(sicslowmac_init(&rf230_driver));
//  ctimer_init();
//  sicslowpan_init(lpp_init(&rf230_driver));
//  rime_init(sicslowmac_driver.init(&rf230_driver));
//  rime_init(lpp_init(&rf230_driver));

  /* Set addresses BEFORE starting tcpip process */

  rimeaddr_t addr;
  memset(&addr, 0, sizeof(rimeaddr_t));
  AVR_ENTER_CRITICAL_REGION();
  eeprom_read_block ((void *)&addr.u8,  &mac_address, 8);
  AVR_LEAVE_CRITICAL_REGION();
 
  memcpy(&uip_lladdr.addr, &addr.u8, 8);	
  rf230_set_pan_addr(IEEE802154_PANID, 0, (uint8_t *)&addr.u8);

  rf230_set_channel(24);
  rimeaddr_set_node_addr(&addr); 
  PRINTF("MAC address %x:%x:%x:%x:%x:%x:%x:%x\r\n",addr.u8[0],addr.u8[1],addr.u8[2],addr.u8[3],addr.u8[4],addr.u8[5],addr.u8[6],addr.u8[7]);

 // uip_ip6addr(&ipprefix, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
 // uip_netif_addr_add(&ipprefix, UIP_DEFAULT_PREFIX_LEN, 0, AUTOCONF);
 // uip_nd6_prefix_add(&ipprefix, UIP_DEFAULT_PREFIX_LEN, 0);
 // PRINTF("Prefix %x::/%u\r\n",ipprefix.u16[0],UIP_DEFAULT_PREFIX_LEN);

#if UIP_CONF_ROUTER
  rime_init(rime_udp_init(NULL));
  uip_router_register(&rimeroute);
#endif

  PRINTF("Driver: %s, Channel: %u\r\n", sicslowmac_driver.name, rf230_get_channel()); 
}
#endif /*RF230BB*/

  /* Register initial processes */
  procinit_init(); 

  uip_ip6addr_t ipaddr;
  uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
  uip_netif_addr_add(&ipaddr, UIP_DEFAULT_PREFIX_LEN, 0, AUTOCONF);
  uip_nd6_prefix_add(&ipaddr, UIP_DEFAULT_PREFIX_LEN, 0);

  //Give ourselves a prefix
  init_net();

  print_local_addresses();

  PRINTF("Starting autostart processes");

  /* Autostart processes */
  autostart_start(autostart_processes);

  /*---If using coffee file system create initial web content if necessary---*/
#if COFFEE_FILES
  int fa = cfs_open( "/index.html", CFS_READ);
  if (fa<0) {     //Make some default web content
    printf_P(PSTR("No index.html file found, creating upload.html!\r\n"));
    printf_P(PSTR("Formatting FLASH file system for coffee..."));
    cfs_coffee_format();
    printf_P(PSTR("Done!\r\n"));
    fa = cfs_open( "/index.html", CFS_WRITE);
    int r = cfs_write(fa, &"It works!", 9);
    if (r<0) printf_P(PSTR("Can''t create /index.html!\r\n"));
    cfs_close(fa);
//  fa = cfs_open("upload.html"), CFW_WRITE);
// <html><body><form action="upload.html" enctype="multipart/form-data" method="post"><input name="userfile" type="file" size="50" /><input value="Upload" type="submit" /></form></body></html>
  }
#endif

/*--------------------------Announce the configuration---------------------*/
#define ANNOUNCE_BOOT 1    //adds about 400 bytes to program size
#if ANNOUNCE_BOOT

#if WEBSERVER

  uint8_t i;
  char buf[80];
  unsigned int size;
   eeprom_read_block (buf,server_name, sizeof(server_name));
   buf[sizeof(server_name)]=0;
   printf_P(PSTR("%s"),buf);
   eeprom_read_block (buf,domain_name, sizeof(domain_name));
   buf[sizeof(domain_name)]=0;
   size=httpd_fs_get_size();
#ifndef COFFEE_FILES
   printf_P(PSTR(".%s online with fixed %u byte web content\r\n"),buf,size);
#elif COFFEE_FILES==1
   printf_P(PSTR(".%s online with static %u byte EEPROM file system\r\n"),buf,size);
#elif COFFEE_FILES==2
   printf_P(PSTR(".%s online with dynamic %u KB EEPROM file system\r\n"),buf,size>>10);
#elif COFFEE_FILES==3
   printf_P(PSTR(".%s online with static %u byte program memory file system\r\n"),buf,size);
#elif COFFEE_FILES==4
   printf_P(PSTR(".%s online with dynamic %u KB program memory file system\r\n"),buf,size>>10);
#endif

/* Add prefixes for testing */
#if 0
{  
  uip_ip6addr_t ipaddr;
  uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
  uip_netif_addr_autoconf_set(&ipaddr, &uip_lladdr);
  uip_netif_addr_add(&ipaddr, 16, 0, TENTATIVE);
}
#endif
  for(i = 0; i < UIP_CONF_NETIF_MAX_ADDRESSES; i ++) {
    if(uip_netif_physical_if.addresses[i].state != NOT_USED) {
      httpd_cgi_sprint_ip6(*(uip_ipaddr_t*)&uip_netif_physical_if.addresses[i],buf);
      printf_P(PSTR("IPv6 Address: %s\r\n"),buf);
    }
  }
#else
printf_P(PSTR("Online\r\n"));
#endif /* WEBSERVER */

#endif /* ANNOUNCE_BOOT */

}
Esempio n. 10
0
int main (void)
{
	double batteryLevel;
	heaterOn = 0;
	
	//Power on device, check internal battery
	powerManagerInit(); // initialise power manager + turn power on
	powerOffHeater();
	
	clock_init();
			
	initializeADC();
	
	initializeLedHandler();
	RGBOff();
	RGBShowColor(Blue);
	
	batteryLevel = readInternalBattery();

	
	//if(batteryLevel < 3.3)
	//{
		//RGBShowColor(Red);
		//_delay_ms(500);
		//RGBOff();
		//_delay_ms(500);
		//RGBShowColor(Red);
		//_delay_ms(500);
		//
		////powerOff();
		//
		//return 0;
	//}
	
	Config32KHzRTC(); //Todo:  RTC ook echt om de 1ms en niet wat die nu doet...
	
	initializeRTC();
	InitializeDebug();
	initializeBluetooth();
	
	/* DHT11 enable */
	PORTB.DIRSET = SEN1_EN;
	PORTB.OUTSET = SEN1_EN;
	
	/* Sen 2 */
	PORTB.DIRSET = SEN2_EN;
	PORTB.OUTSET = SEN2_EN;
	
	/* USB status */
	PORTC.DIRCLR = USB_STAT;
	
	
	//initializePWM();
	
	stdout = &mystdout;																	/* onze eigen stdout gebruiken (usart) */
	
	sei();																				/* Interrupts enablen */
	
	PMIC.CTRL |= (PMIC_HILVLEN_bm | PMIC_LOLVLEN_bm);										/* Hi en Lo lvl interrupts */
	
	/* BT config */
	PORTC.DIRCLR = BT_STAT;
	
	PORTC.DIRSET = BT_KEY;
	PORTC.OUTCLR = BT_KEY;
	
	PORTC.DIRSET = BT_EN;
	PORTC.OUTSET = BT_EN;
	
	PORTB.DIRSET = HY_EN;
	//PORTB.OUTSET = HY_EN;
	
	bluetoothRename("snuffelneusWit");
	
	//usartE0_sendstring("AT+NAMEsnuffelneus6.0");
	
	_delay_ms(2000);

	while(1) {
	}
}
Esempio n. 11
0
int
main(int argc, char *argv[])
{
	int port = 2344;
	const char *config = "sys161.conf";
	const char *kernel = NULL;
	int usetcp=0;
	char *argstr = NULL;
	int j, opt;
	size_t argsize=0;
	int debugwait=0;
	int pass_signals=0;
#ifdef USE_TRACE
	int profiling=0;
#endif
	int use_second_console=0;
	const char *second_console = NULL;
	unsigned ncpus;

	/* This must come absolutely first so msg() can be used. */
	console_earlyinit();
	
	if (sizeof(u_int32_t)!=4) {
		/*
		 * Just in case.
		 */
		msg("sys161 requires sizeof(u_int32_t)==4");
		die();
	}

	while ((opt = mygetopt(argc, argv, "c:f:p:Pst:wk:"))!=-1) {
		switch (opt) {
		    case 'c': config = myoptarg; break;
		    case 'f':
#ifdef USE_TRACE
			set_tracefile(myoptarg);
#endif
			break;
		    case 'p': port = atoi(myoptarg); usetcp=1; break;
		    case 'P':
#ifdef USE_TRACE
			profiling = 1;
#endif
			break;
		    case 's': pass_signals = 1; break;
		    case 't': 
#ifdef USE_TRACE
			set_traceflags(myoptarg); 
#endif
			break;
		    case 'w': debugwait = 1; break;
		    case 'k':
		    use_second_console = 1;
		    second_console = myoptarg;
		    break;
		    default: usage(); break;
		}
	}
	if (myoptind==argc) {
		usage();
	}
	kernel = argv[myoptind++];
	
	for (j=myoptind; j<argc; j++) {
		argsize += strlen(argv[j])+1;
	}
	argstr = malloc(argsize+1);
	if (!argstr) {
		msg("malloc failed");
		die();
	}
	*argstr = 0;
	for (j=myoptind; j<argc; j++) {
		strcat(argstr, argv[j]);
		if (j<argc-1) strcat(argstr, " ");
	}

	/* This must come before bus_config in case a network card needs it */
	mkdir(".sockets", 0700);
	
	console_init(pass_signals, use_second_console, second_console);
	clock_init();
	ncpus = bus_config(config);

	initstats(ncpus);
	cpu_init(ncpus);

	if (usetcp) {
		gdb_inet_init(port);
	}
	else {
		unlink(".sockets/gdb");
		gdb_unix_init(".sockets/gdb");
	}

	unlink(".sockets/meter");
	meter_init(".sockets/meter");

	load_kernel(kernel, argstr);

	msg("System/161 %s, compiled %s %s", VERSION, __DATE__, __TIME__);
#ifdef USE_TRACE
	print_traceflags();
	if (profiling) {
		prof_setup();
	}
#endif

	if (debugwait) {
		stoploop();
	}
	
	run();

#ifdef USE_TRACE
	if (profiling) {
		prof_write();
	}
#endif

	bus_cleanup();
	console_cleanup();
	clock_cleanup();
	
	return 0;
}
Esempio n. 12
0
void
init_lowlevel(void)
{
  uint8_t i;
  unsigned char ds2411_id[6];

  /* Second rs232 port for debugging */
  rs232_init(RS232_PORT_1, USART_BAUD_38400,
             USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);

  /* Redirect stdout to second port */
  rs232_redirect_stdout(RS232_PORT_1);

  /* Clock */
  clock_init();

  /* rtimers needed for radio cycling */
  rtimer_init();

  /* Initialize process subsystem */
  process_init();

  /* etimers must be started before ctimer_init */
  process_start(&etimer_process, NULL);

#if RF230BB
  ctimer_init();
  /* Start radio and radio receive process */
  NETSTACK_RADIO.init();

  if(ds2411_read(ds2411_id)) {  /* if serial available, modify adress in EPROM */
    mac_address[0] = 0x02;
    mac_address[1] = 0;
    mac_address[2] = ds2411_id[0];
    mac_address[3] = ds2411_id[1];
    mac_address[4] = ds2411_id[2];
    mac_address[5] = ds2411_id[3];
    mac_address[6] = ds2411_id[4];
    mac_address[7] = ds2411_id[5];
  }

  /* Set addresses BEFORE starting tcpip process */
  linkaddr_t addr;

  memset(&addr, 0, sizeof(linkaddr_t));
  memcpy((void *)&addr.u8, &mac_address, 8);

#if UIP_CONF_IPV6
  memcpy(&uip_lladdr.addr, &addr.u8, 8);
#endif /* UIP_CONF_IPV6 */

  rf230_set_pan_addr(IEEE802154_PANID, 0, (uint8_t *) & addr.u8);

#ifdef CHANNEL_802_15_4
  rf230_set_channel(CHANNEL_802_15_4);
#else /* CHANNEL_802_15_4 */
  rf230_set_channel(26);
#endif /* CHANNEL_802_15_4 */
  linkaddr_set_node_addr(&addr);

  //calibrate_rc_osc_32k(); //CO: Had to comment this out

  /* Initialize hardware */
  PRINTF("MAC address %x:%x:%x:%x:%x:%x:%x:%x\n", addr.u8[0], addr.u8[1],
         addr.u8[2], addr.u8[3], addr.u8[4], addr.u8[5], addr.u8[6],
         addr.u8[7]);

  /* Initialize stack protocols */
  queuebuf_init();
  NETSTACK_RDC.init();
  NETSTACK_MAC.init();
  NETSTACK_NETWORK.init();

#if ANNOUNCE_BOOT
  printf_P(PSTR("%s %s, channel %u"), NETSTACK_MAC.name, NETSTACK_RDC.name,
           rf230_get_channel());
  if(NETSTACK_RDC.channel_check_interval) {     //function pointer is zero for sicslowmac
    unsigned short tmp;

    tmp = CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval == 0 ? 1 :
                          NETSTACK_RDC.channel_check_interval());
    if(tmp < 65535)
      printf_P(PSTR(", check rate %u Hz"), tmp);
  }
  printf_P(PSTR("\n"));
#endif /* ANNOUNCE_BOOT */

#if UIP_CONF_ROUTER
#if ANNOUNCE_BOOT
  printf_P(PSTR("Routing Enabled\n"));
#endif /* ANNOUNCE_BOOT */
  rime_init(rime_udp_init(NULL));
  uip_router_register(&rimeroute);
#endif /* UIP_CONF_ROUTER */
#if UIP_CONF_IPV6
  process_start(&tcpip_process, NULL);
#endif /* UIP_CONF_IPV6 */
#else /*RF230BB */
#if UIP_CONF_IPV6
  /* mac process must be started before tcpip process! */
  process_start(&mac_process, NULL);
  process_start(&tcpip_process, NULL);
#endif /* UIP_CONF_IPV6 */
#endif /* RF230BB */
}
Esempio n. 13
0
int
main(int argc, char **argv)
{

  /* crappy way of remembering and accessing argc/v */
  contiki_argc = argc;
  contiki_argv = argv;

  /* native under windows is hardcoded to use the first one or two args */
  /* for wpcap configuration so this needs to be "removed" from         */
  /* contiki_args (used by the native-border-router) */

  //printf("Cgroups -timer\n");
  /*Initalize "hardware".*/
  init_timer();
  clock_init();
  
  rtimer_init();
  

  //printf("Hello glorious world of cheese\n");

/*
   * Hardware initialization done!
   */

  process_init();
  process_start(&etimer_process, NULL);
  ctimer_init();

  set_rime_addr();

  queuebuf_init();

  netstack_init();
  //printf("MAC %s RDC %s NETWORK %s\n", NETSTACK_MAC.name, NETSTACK_RDC.name, NETSTACK_NETWORK.name);
  printf("Hello Rika, I am cgroups in contiki!\n");

  serial_line_init();
  
  autostart_start(autostart_processes);
  
  /* Make standard output unbuffered. */
  setvbuf(stdout, (char *)NULL, _IONBF, 0);

  select_set_callback(STDIN_FILENO, &stdin_fd);
  /*
   * This is the scheduler loop.
   */
  while(1) {
    fd_set fdr;
    fd_set fdw;
    int maxfd;
    int i;
    int retval;
    struct timeval tv;

    retval = process_run();

    tv.tv_sec = 0;
    tv.tv_usec = retval ? 1 : 1000;

    FD_ZERO(&fdr);
    FD_ZERO(&fdw);
    maxfd = 0;
    for(i = 0; i <= select_max; i++) {
      if(select_callback[i] != NULL && select_callback[i]->set_fd(&fdr, &fdw)) {
        maxfd = i;
      }
    }

    retval = select(maxfd + 1, &fdr, &fdw, NULL, &tv);
    if(retval < 0) {
      perror("select");
    } else if(retval > 0) {
      /* timeout => retval == 0 */
      for(i = 0; i <= maxfd; i++) {
        if(select_callback[i] != NULL) {
          select_callback[i]->handle_fd(&fdr, &fdw);
        }
      }
    }

    etimer_request_poll();
  }

  return 0;
}
Esempio n. 14
0
/*---------------------------------------------------------------------------*/
int
main(void)
{
  
  /*
   * Initialize hardware.
   */
  halInit();
  clock_init();
  
  uart1_init(115200);
  
  // Led initialization
  leds_init();
    
  INTERRUPTS_ON(); 

  PRINTF("\r\nStarting ");
  PRINTF(CONTIKI_VERSION_STRING);
  PRINTF(" on %s\r\n",boardDescription->name);

  /*
   * Initialize Contiki and our processes.
   */
  
  process_init();
  
#if WITH_SERIAL_LINE_INPUT
  uart1_set_input(serial_line_input_byte);
  serial_line_init();
#endif
  
  
  process_start(&etimer_process, NULL);   
  ctimer_init();
  rtimer_init();
  
  netstack_init();
  set_rime_addr();
  
  
PRINTF("ACK enable=%u %s %s, channel check rate=%luHz, check interval %ums, clock second=%u, radio channel %u\r\n",
         ST_RadioAutoAckEnabled(), NETSTACK_MAC.name, NETSTACK_RDC.name,  
         CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0? 1:
                         NETSTACK_RDC.channel_check_interval()), NETSTACK_RDC.channel_check_interval(), CLOCK_SECOND,
         RF_CHANNEL);
  
#if !UIP_CONF_IPV6
  ST_RadioEnableAutoAck(FALSE); // Because frames are not 802.15.4 compatible. 
  ST_RadioEnableAddressFiltering(FALSE);
#endif
  ST_RadioEnableAutoAck(TRUE);

  
  procinit_init(); 
    


  energest_init();
  ENERGEST_ON(ENERGEST_TYPE_CPU);
  
  autostart_start(autostart_processes);
  
  
  watchdog_start();
  
  while(1){
    
    int r;    
    
    do {
      /* Reset watchdog. */
      watchdog_periodic();
      r = process_run();
    } while(r > 0);
    
    
    
    ENERGEST_OFF(ENERGEST_TYPE_CPU);
    //watchdog_stop();    
    ENERGEST_ON(ENERGEST_TYPE_LPM);
    /* Go to idle mode. */
    halSleepWithOptions(SLEEPMODE_IDLE,0);
    /* We are awake. */
    //watchdog_start();
    ENERGEST_OFF(ENERGEST_TYPE_LPM);
    ENERGEST_ON(ENERGEST_TYPE_CPU);  
    
  }
  
}
Esempio n. 15
0
int dram_init(void)
{
	static const struct ddr3_jedec_timings pcm052_ddr_timings = {
		.tinit             = 5,
		.trst_pwron        = 80000,
		.cke_inactive      = 200000,
		.wrlat             = 5,
		.caslat_lin        = 12,
		.trc               = 6,
		.trrd              = 4,
		.tccd              = 4,
		.tbst_int_interval = 4,
		.tfaw              = 18,
		.trp               = 6,
		.twtr              = 4,
		.tras_min          = 15,
		.tmrd              = 4,
		.trtp              = 4,
		.tras_max          = 14040,
		.tmod              = 12,
		.tckesr            = 4,
		.tcke              = 3,
		.trcd_int          = 6,
		.tras_lockout      = 1,
		.tdal              = 10,
		.bstlen            = 3,
		.tdll              = 512,
		.trp_ab            = 6,
		.tref              = 1542,
		.trfc              = 64,
		.tref_int          = 5,
		.tpdex             = 3,
		.txpdll            = 10,
		.txsnr             = 68,
		.txsr              = 506,
		.cksrx             = 5,
		.cksre             = 5,
		.freq_chg_en       = 1,
		.zqcl              = 256,
		.zqinit            = 512,
		.zqcs              = 64,
		.ref_per_zq        = 64,
		.zqcs_rotate       = 1,
		.aprebit           = 10,
		.cmd_age_cnt       = 255,
		.age_cnt           = 255,
		.q_fullness        = 0,
		.odt_rd_mapcs0     = 1,
		.odt_wr_mapcs0     = 1,
		.wlmrd             = 40,
		.wldqsen           = 25,
	};

	static const iomux_v3_cfg_t pcm052_pads[] = {
		PCM052_VF610_PAD_DDR_A15__DDR_A_15,
		PCM052_VF610_PAD_DDR_A14__DDR_A_14,
		PCM052_VF610_PAD_DDR_A13__DDR_A_13,
		PCM052_VF610_PAD_DDR_A12__DDR_A_12,
		PCM052_VF610_PAD_DDR_A11__DDR_A_11,
		PCM052_VF610_PAD_DDR_A10__DDR_A_10,
		PCM052_VF610_PAD_DDR_A9__DDR_A_9,
		PCM052_VF610_PAD_DDR_A8__DDR_A_8,
		PCM052_VF610_PAD_DDR_A7__DDR_A_7,
		PCM052_VF610_PAD_DDR_A6__DDR_A_6,
		PCM052_VF610_PAD_DDR_A5__DDR_A_5,
		PCM052_VF610_PAD_DDR_A4__DDR_A_4,
		PCM052_VF610_PAD_DDR_A3__DDR_A_3,
		PCM052_VF610_PAD_DDR_A2__DDR_A_2,
		PCM052_VF610_PAD_DDR_A1__DDR_A_1,
		PCM052_VF610_PAD_DDR_A0__DDR_A_0,
		PCM052_VF610_PAD_DDR_BA2__DDR_BA_2,
		PCM052_VF610_PAD_DDR_BA1__DDR_BA_1,
		PCM052_VF610_PAD_DDR_BA0__DDR_BA_0,
		PCM052_VF610_PAD_DDR_CAS__DDR_CAS_B,
		PCM052_VF610_PAD_DDR_CKE__DDR_CKE_0,
		PCM052_VF610_PAD_DDR_CLK__DDR_CLK_0,
		PCM052_VF610_PAD_DDR_CS__DDR_CS_B_0,
		PCM052_VF610_PAD_DDR_D15__DDR_D_15,
		PCM052_VF610_PAD_DDR_D14__DDR_D_14,
		PCM052_VF610_PAD_DDR_D13__DDR_D_13,
		PCM052_VF610_PAD_DDR_D12__DDR_D_12,
		PCM052_VF610_PAD_DDR_D11__DDR_D_11,
		PCM052_VF610_PAD_DDR_D10__DDR_D_10,
		PCM052_VF610_PAD_DDR_D9__DDR_D_9,
		PCM052_VF610_PAD_DDR_D8__DDR_D_8,
		PCM052_VF610_PAD_DDR_D7__DDR_D_7,
		PCM052_VF610_PAD_DDR_D6__DDR_D_6,
		PCM052_VF610_PAD_DDR_D5__DDR_D_5,
		PCM052_VF610_PAD_DDR_D4__DDR_D_4,
		PCM052_VF610_PAD_DDR_D3__DDR_D_3,
		PCM052_VF610_PAD_DDR_D2__DDR_D_2,
		PCM052_VF610_PAD_DDR_D1__DDR_D_1,
		PCM052_VF610_PAD_DDR_D0__DDR_D_0,
		PCM052_VF610_PAD_DDR_DQM1__DDR_DQM_1,
		PCM052_VF610_PAD_DDR_DQM0__DDR_DQM_0,
		PCM052_VF610_PAD_DDR_DQS1__DDR_DQS_1,
		PCM052_VF610_PAD_DDR_DQS0__DDR_DQS_0,
		PCM052_VF610_PAD_DDR_RAS__DDR_RAS_B,
		PCM052_VF610_PAD_DDR_WE__DDR_WE_B,
		PCM052_VF610_PAD_DDR_ODT1__DDR_ODT_0,
		PCM052_VF610_PAD_DDR_ODT0__DDR_ODT_1,
		PCM052_VF610_PAD_DDR_DDRBYTE1__DDR_DDRBYTE1,
		PCM052_VF610_PAD_DDR_DDRBYTE0__DDR_DDRBYTE0,
		PCM052_VF610_PAD_DDR_RESETB,
	};

	imx_iomux_v3_setup_multiple_pads(pcm052_pads, ARRAY_SIZE(pcm052_pads));

	ddrmc_ctrl_init_ddr3(&pcm052_ddr_timings, pcm052_cr_settings,
			     pcm052_phy_settings, 1, 2);

	gd->ram_size = get_ram_size((void *)PHYS_SDRAM, PHYS_SDRAM_SIZE);

	return 0;
}

static void setup_iomux_uart(void)
{
	static const iomux_v3_cfg_t uart1_pads[] = {
		NEW_PAD_CTRL(VF610_PAD_PTB4__UART1_TX, VF610_UART_PAD_CTRL),
		NEW_PAD_CTRL(VF610_PAD_PTB5__UART1_RX, VF610_UART_PAD_CTRL),
	};

	imx_iomux_v3_setup_multiple_pads(uart1_pads, ARRAY_SIZE(uart1_pads));
}

#define ENET_PAD_CTRL	(PAD_CTL_PUS_47K_UP | PAD_CTL_SPEED_HIGH | \
			PAD_CTL_DSE_50ohm | PAD_CTL_OBE_IBE_ENABLE)

static void setup_iomux_enet(void)
{
	static const iomux_v3_cfg_t enet0_pads[] = {
		NEW_PAD_CTRL(VF610_PAD_PTA6__RMII0_CLKIN, ENET_PAD_CTRL),
		NEW_PAD_CTRL(VF610_PAD_PTC1__RMII0_MDIO, ENET_PAD_CTRL),
		NEW_PAD_CTRL(VF610_PAD_PTC0__RMII0_MDC, ENET_PAD_CTRL),
		NEW_PAD_CTRL(VF610_PAD_PTC2__RMII0_CRS_DV, ENET_PAD_CTRL),
		NEW_PAD_CTRL(VF610_PAD_PTC3__RMII0_RD1, ENET_PAD_CTRL),
		NEW_PAD_CTRL(VF610_PAD_PTC4__RMII0_RD0, ENET_PAD_CTRL),
		NEW_PAD_CTRL(VF610_PAD_PTC5__RMII0_RXER, ENET_PAD_CTRL),
		NEW_PAD_CTRL(VF610_PAD_PTC6__RMII0_TD1, ENET_PAD_CTRL),
		NEW_PAD_CTRL(VF610_PAD_PTC7__RMII0_TD0, ENET_PAD_CTRL),
		NEW_PAD_CTRL(VF610_PAD_PTC8__RMII0_TXEN, ENET_PAD_CTRL),
	};

	imx_iomux_v3_setup_multiple_pads(enet0_pads, ARRAY_SIZE(enet0_pads));
}

/*
 * I2C2 is the only I2C used, on pads PTA22/PTA23.
 */

static void setup_iomux_i2c(void)
{
	static const iomux_v3_cfg_t i2c_pads[] = {
		VF610_PAD_PTA22__I2C2_SCL,
		VF610_PAD_PTA23__I2C2_SDA,
	};

	imx_iomux_v3_setup_multiple_pads(i2c_pads, ARRAY_SIZE(i2c_pads));
}

#ifdef CONFIG_NAND_VF610_NFC
static void setup_iomux_nfc(void)
{
	static const iomux_v3_cfg_t nfc_pads[] = {
		VF610_PAD_PTD31__NF_IO15,
		VF610_PAD_PTD30__NF_IO14,
		VF610_PAD_PTD29__NF_IO13,
		VF610_PAD_PTD28__NF_IO12,
		VF610_PAD_PTD27__NF_IO11,
		VF610_PAD_PTD26__NF_IO10,
		VF610_PAD_PTD25__NF_IO9,
		VF610_PAD_PTD24__NF_IO8,
		VF610_PAD_PTD23__NF_IO7,
		VF610_PAD_PTD22__NF_IO6,
		VF610_PAD_PTD21__NF_IO5,
		VF610_PAD_PTD20__NF_IO4,
		VF610_PAD_PTD19__NF_IO3,
		VF610_PAD_PTD18__NF_IO2,
		VF610_PAD_PTD17__NF_IO1,
		VF610_PAD_PTD16__NF_IO0,
		VF610_PAD_PTB24__NF_WE_B,
		VF610_PAD_PTB25__NF_CE0_B,
		VF610_PAD_PTB27__NF_RE_B,
		VF610_PAD_PTC26__NF_RB_B,
		VF610_PAD_PTC27__NF_ALE,
		VF610_PAD_PTC28__NF_CLE
	};

	imx_iomux_v3_setup_multiple_pads(nfc_pads, ARRAY_SIZE(nfc_pads));
}
#endif

static void setup_iomux_qspi(void)
{
	static const iomux_v3_cfg_t qspi0_pads[] = {
		VF610_PAD_PTD0__QSPI0_A_QSCK,
		VF610_PAD_PTD1__QSPI0_A_CS0,
		VF610_PAD_PTD2__QSPI0_A_DATA3,
		VF610_PAD_PTD3__QSPI0_A_DATA2,
		VF610_PAD_PTD4__QSPI0_A_DATA1,
		VF610_PAD_PTD5__QSPI0_A_DATA0,
		VF610_PAD_PTD7__QSPI0_B_QSCK,
		VF610_PAD_PTD8__QSPI0_B_CS0,
		VF610_PAD_PTD9__QSPI0_B_DATA3,
		VF610_PAD_PTD10__QSPI0_B_DATA2,
		VF610_PAD_PTD11__QSPI0_B_DATA1,
		VF610_PAD_PTD12__QSPI0_B_DATA0,
	};

	imx_iomux_v3_setup_multiple_pads(qspi0_pads, ARRAY_SIZE(qspi0_pads));
}

#define ESDHC_PAD_CTRL	(PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_HIGH | \
			PAD_CTL_DSE_20ohm | PAD_CTL_OBE_IBE_ENABLE)

struct fsl_esdhc_cfg esdhc_cfg[1] = {
	{ESDHC1_BASE_ADDR},
};

int board_mmc_getcd(struct mmc *mmc)
{
	/* eSDHC1 is always present */
	return 1;
}

int board_mmc_init(bd_t *bis)
{
	static const iomux_v3_cfg_t esdhc1_pads[] = {
		NEW_PAD_CTRL(VF610_PAD_PTA24__ESDHC1_CLK, ESDHC_PAD_CTRL),
		NEW_PAD_CTRL(VF610_PAD_PTA25__ESDHC1_CMD, ESDHC_PAD_CTRL),
		NEW_PAD_CTRL(VF610_PAD_PTA26__ESDHC1_DAT0, ESDHC_PAD_CTRL),
		NEW_PAD_CTRL(VF610_PAD_PTA27__ESDHC1_DAT1, ESDHC_PAD_CTRL),
		NEW_PAD_CTRL(VF610_PAD_PTA28__ESDHC1_DAT2, ESDHC_PAD_CTRL),
		NEW_PAD_CTRL(VF610_PAD_PTA29__ESDHC1_DAT3, ESDHC_PAD_CTRL),
	};

	esdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK);

	imx_iomux_v3_setup_multiple_pads(
		esdhc1_pads, ARRAY_SIZE(esdhc1_pads));

	return fsl_esdhc_initialize(bis, &esdhc_cfg[0]);
}

static void clock_init(void)
{
	struct ccm_reg *ccm = (struct ccm_reg *)CCM_BASE_ADDR;
	struct anadig_reg *anadig = (struct anadig_reg *)ANADIG_BASE_ADDR;

	clrsetbits_le32(&ccm->ccgr0, CCM_REG_CTRL_MASK,
			CCM_CCGR0_UART1_CTRL_MASK);
	clrsetbits_le32(&ccm->ccgr1, CCM_REG_CTRL_MASK,
			CCM_CCGR1_PIT_CTRL_MASK | CCM_CCGR1_WDOGA5_CTRL_MASK);
	clrsetbits_le32(&ccm->ccgr2, CCM_REG_CTRL_MASK,
			CCM_CCGR2_IOMUXC_CTRL_MASK | CCM_CCGR2_PORTA_CTRL_MASK |
			CCM_CCGR2_PORTB_CTRL_MASK | CCM_CCGR2_PORTC_CTRL_MASK |
			CCM_CCGR2_PORTD_CTRL_MASK | CCM_CCGR2_PORTE_CTRL_MASK |
			CCM_CCGR2_QSPI0_CTRL_MASK);
	clrsetbits_le32(&ccm->ccgr3, CCM_REG_CTRL_MASK,
			CCM_CCGR3_ANADIG_CTRL_MASK | CCM_CCGR3_SCSC_CTRL_MASK);
	clrsetbits_le32(&ccm->ccgr4, CCM_REG_CTRL_MASK,
			CCM_CCGR4_WKUP_CTRL_MASK | CCM_CCGR4_CCM_CTRL_MASK |
			CCM_CCGR4_GPC_CTRL_MASK);
	clrsetbits_le32(&ccm->ccgr6, CCM_REG_CTRL_MASK,
			CCM_CCGR6_OCOTP_CTRL_MASK | CCM_CCGR6_DDRMC_CTRL_MASK);
	clrsetbits_le32(&ccm->ccgr7, CCM_REG_CTRL_MASK,
			CCM_CCGR7_SDHC1_CTRL_MASK);
	clrsetbits_le32(&ccm->ccgr9, CCM_REG_CTRL_MASK,
			CCM_CCGR9_FEC0_CTRL_MASK | CCM_CCGR9_FEC1_CTRL_MASK);
	clrsetbits_le32(&ccm->ccgr10, CCM_REG_CTRL_MASK,
			CCM_CCGR10_NFC_CTRL_MASK | CCM_CCGR10_I2C2_CTRL_MASK);

	clrsetbits_le32(&anadig->pll2_ctrl, ANADIG_PLL2_CTRL_POWERDOWN,
			ANADIG_PLL2_CTRL_ENABLE | ANADIG_PLL2_CTRL_DIV_SELECT);
	clrsetbits_le32(&anadig->pll1_ctrl, ANADIG_PLL1_CTRL_POWERDOWN,
			ANADIG_PLL1_CTRL_ENABLE | ANADIG_PLL1_CTRL_DIV_SELECT);

	clrsetbits_le32(&ccm->ccr, CCM_CCR_OSCNT_MASK,
			CCM_CCR_FIRC_EN | CCM_CCR_OSCNT(5));
	clrsetbits_le32(&ccm->ccsr, CCM_REG_CTRL_MASK,
			CCM_CCSR_PLL1_PFD_CLK_SEL(3) | CCM_CCSR_PLL2_PFD4_EN |
			CCM_CCSR_PLL2_PFD3_EN | CCM_CCSR_PLL2_PFD2_EN |
			CCM_CCSR_PLL2_PFD1_EN | CCM_CCSR_PLL1_PFD4_EN |
			CCM_CCSR_PLL1_PFD3_EN | CCM_CCSR_PLL1_PFD2_EN |
			CCM_CCSR_PLL1_PFD1_EN | CCM_CCSR_DDRC_CLK_SEL(1) |
			CCM_CCSR_FAST_CLK_SEL(1) | CCM_CCSR_SYS_CLK_SEL(4));
	clrsetbits_le32(&ccm->cacrr, CCM_REG_CTRL_MASK,
			CCM_CACRR_IPG_CLK_DIV(1) | CCM_CACRR_BUS_CLK_DIV(2) |
			CCM_CACRR_ARM_CLK_DIV(0));
	clrsetbits_le32(&ccm->cscmr1, CCM_REG_CTRL_MASK,
			CCM_CSCMR1_ESDHC1_CLK_SEL(3) |
			CCM_CSCMR1_QSPI0_CLK_SEL(3) |
			CCM_CSCMR1_NFC_CLK_SEL(0));
	clrsetbits_le32(&ccm->cscdr1, CCM_REG_CTRL_MASK,
			CCM_CSCDR1_RMII_CLK_EN);
	clrsetbits_le32(&ccm->cscdr2, CCM_REG_CTRL_MASK,
			CCM_CSCDR2_ESDHC1_EN | CCM_CSCDR2_ESDHC1_CLK_DIV(0) |
			CCM_CSCDR2_NFC_EN);
	clrsetbits_le32(&ccm->cscdr3, CCM_REG_CTRL_MASK,
			CCM_CSCDR3_QSPI0_EN | CCM_CSCDR3_QSPI0_DIV(1) |
			CCM_CSCDR3_QSPI0_X2_DIV(1) |
			CCM_CSCDR3_QSPI0_X4_DIV(3) |
			CCM_CSCDR3_NFC_PRE_DIV(5));
	clrsetbits_le32(&ccm->cscmr2, CCM_REG_CTRL_MASK,
			CCM_CSCMR2_RMII_CLK_SEL(0));
}

static void mscm_init(void)
{
	struct mscm_ir *mscmir = (struct mscm_ir *)MSCM_IR_BASE_ADDR;
	int i;

	for (i = 0; i < MSCM_IRSPRC_NUM; i++)
		writew(MSCM_IRSPRC_CP0_EN, &mscmir->irsprc[i]);
}

int board_phy_config(struct phy_device *phydev)
{
	if (phydev->drv->config)
		phydev->drv->config(phydev);

	return 0;
}

int board_early_init_f(void)
{
	clock_init();
	mscm_init();
	setup_iomux_uart();
	setup_iomux_enet();
	setup_iomux_i2c();
	setup_iomux_qspi();
	setup_iomux_nfc();

	return 0;
}
Esempio n. 16
0
/*---------------------------------------------------------------------------*/
int
main(void)
{
  EEPROM_main();

  int i;
  uip_ipaddr_t ipaddr;
  struct timer periodic_timer, arp_timer;

  memcpy (&uip_ethaddr.addr[0], &eeprom.MAC[0], 6);

  AVR_init();
  egpio_init();

  clock_init();
  mbuf_init();
  adlc_init();
  GICR = (1 << INT0);

  timer_set(&periodic_timer, CLOCK_SECOND / 2);
  timer_set(&arp_timer, CLOCK_SECOND * 10);

  nic_init();


  uip_ipaddr(ipaddr, eeprom.IPAddr[0],eeprom.IPAddr[1],eeprom.IPAddr[2],eeprom.IPAddr[3]);
  uip_sethostaddr(ipaddr);
  uip_ipaddr(ipaddr, eeprom.Gateway[0],eeprom.Gateway[1],eeprom.Gateway[2],eeprom.Gateway[3]);
  uip_setdraddr(ipaddr);
  uip_ipaddr(ipaddr, eeprom.Subnet[0],eeprom.Subnet[1],eeprom.Subnet[2],eeprom.Subnet[3]);
  uip_setnetmask(ipaddr);

  telnetd_init();
  aun_init();
  internet_init();

  egpio_write (EGPIO_STATUS_GREEN);

  while(1) {

// check the econet for complete packets
    adlc_poller();
    aun_poller ();

    uip_len = nic_poll();

    if(uip_len > 0) {

      if(BUF->type == htons(UIP_ETHTYPE_IP)) {
	uip_arp_ipin();
	uip_input();
	/* If the above function invocation resulted in data that
	   should be sent out on the network, the global variable
	   uip_len is set to a value > 0. */
	maybe_send();
      } else if(BUF->type == htons(UIP_ETHTYPE_ARP)) {
	uip_arp_arpin();
	/* If the above function invocation resulted in data that
	   should be sent out on the network, the global variable
	   uip_len is set to a value > 0. */
	if(uip_len > 0) {
	  nic_send(NULL);
	}
      }

    } else if(timer_expired(&periodic_timer)) {
      timer_reset(&periodic_timer);
      for(i = 0; i < UIP_CONNS; i++) {
	uip_periodic(i);
	maybe_send();
      }

#if UIP_UDP
      for(i = 0; i < UIP_UDP_CONNS; i++) {
	uip_udp_periodic(i);
	maybe_send();
      }
#endif /* UIP_UDP */

      /* Call the ARP timer function every 10 seconds. */
      if(timer_expired(&arp_timer)) {
	timer_reset(&arp_timer);
	uip_arp_timer();
      }
    }
  }
}
/*--------------------------------------------------------------------------*/
int
main(int argc, char **argv)
{
  /*
   * Initalize hardware.
   */
  msp430_cpu_init();
  clock_init();
  leds_init();

  leds_on(LEDS_RED);

  uart1_init(BAUD2UBR(115200)); /* Must come before first printf */
#if WITH_UIP
  slip_arch_init(BAUD2UBR(115200));
#endif /* WITH_UIP */

  leds_on(LEDS_GREEN);
  /* xmem_init(); */
  
  rtimer_init();

  lcd_init();

  PRINTF(CONTIKI_VERSION_STRING "\n");
  /*
   * Hardware initialization done!
   */
  
  leds_on(LEDS_RED);
  /* Restore node id if such has been stored in external mem */

  //  node_id_restore();
#ifdef NODEID
  node_id = NODEID;

#ifdef BURN_NODEID
  flash_setup();
  flash_clear(0x1800);
  flash_write(0x1800, node_id);
  flash_done();
#endif /* BURN_NODEID */
#endif /* NODE_ID */

  if(node_id == 0) {
    node_id = *((unsigned short *)0x1800);
  }
  memset(node_mac, 0, sizeof(node_mac));
  node_mac[6] = node_id >> 8;
  node_mac[7] = node_id & 0xff;

  /* for setting "hardcoded" IEEE 802.15.4 MAC addresses */
#ifdef MAC_1
  {
    uint8_t ieee[] = { MAC_1, MAC_2, MAC_3, MAC_4, MAC_5, MAC_6, MAC_7, MAC_8 };
    memcpy(node_mac, ieee, sizeof(uip_lladdr.addr));
  }
#endif

   /*
   * Initialize Contiki and our processes.
   */
  process_init();
  process_start(&etimer_process, NULL);

  ctimer_init();

  set_rime_addr();

  cc2420_init();

  {
    uint8_t longaddr[8];
    uint16_t shortaddr;

    shortaddr = (rimeaddr_node_addr.u8[0] << 8) +
      rimeaddr_node_addr.u8[1];
    memset(longaddr, 0, sizeof(longaddr));
    rimeaddr_copy((rimeaddr_t *)&longaddr, &rimeaddr_node_addr);
    printf("MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
           longaddr[0], longaddr[1], longaddr[2], longaddr[3],
           longaddr[4], longaddr[5], longaddr[6], longaddr[7]);

    cc2420_set_pan_addr(IEEE802154_PANID, shortaddr, longaddr);
  }

  leds_off(LEDS_ALL);

  if(node_id > 0) {
    PRINTF("Node id %u.\n", node_id);
  } else {
    PRINTF("Node id not set.\n");
  }

#if WITH_UIP6
  memcpy(&uip_lladdr.addr, node_mac, sizeof(uip_lladdr.addr));
  /* Setup nullmac-like MAC for 802.15.4 */

  queuebuf_init();

  NETSTACK_RDC.init();
  NETSTACK_MAC.init();
  NETSTACK_NETWORK.init();

  printf("%s %lu %u\n",
         NETSTACK_RDC.name,
         CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1:
                         NETSTACK_RDC.channel_check_interval()),
         CC2420_CONF_CHANNEL);

  process_start(&tcpip_process, NULL);

  printf("IPv6 ");
  {
    uip_ds6_addr_t *lladdr;
    int i;
    lladdr = uip_ds6_get_link_local(-1);
    for(i = 0; i < 7; ++i) {
      printf("%02x%02x:", lladdr->ipaddr.u8[i * 2],
             lladdr->ipaddr.u8[i * 2 + 1]);
    }
    printf("%02x%02x\n", lladdr->ipaddr.u8[14], lladdr->ipaddr.u8[15]);
  }

  if(!UIP_CONF_IPV6_RPL) {
    uip_ipaddr_t ipaddr;
    int i;
    uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
    uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
    uip_ds6_addr_add(&ipaddr, 0, ADDR_TENTATIVE);
    printf("Tentative global IPv6 address ");
    for(i = 0; i < 7; ++i) {
      printf("%02x%02x:",
             ipaddr.u8[i * 2], ipaddr.u8[i * 2 + 1]);
    }
    printf("%02x%02x\n",
           ipaddr.u8[7 * 2], ipaddr.u8[7 * 2 + 1]);
  }

#else /* WITH_UIP6 */

  NETSTACK_RDC.init();
  NETSTACK_MAC.init();
  NETSTACK_NETWORK.init();

  printf("%s %lu %u\n",
         NETSTACK_RDC.name,
         CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0? 1:
                         NETSTACK_RDC.channel_check_interval()),
         CC2420_CONF_CHANNEL);
#endif /* WITH_UIP6 */

#if !WITH_UIP6
  uart1_set_input(serial_line_input_byte);
  serial_line_init();
#endif

#if TIMESYNCH_CONF_ENABLED
  timesynch_init();
  timesynch_set_authority_level(rimeaddr_node_addr.u8[0]);
#endif /* TIMESYNCH_CONF_ENABLED */


  /*  process_start(&sensors_process, NULL);
      SENSORS_ACTIVATE(button_sensor);*/

  energest_init();
  ENERGEST_ON(ENERGEST_TYPE_CPU);

  print_processes(autostart_processes);
  autostart_start(autostart_processes);

  duty_cycle_scroller_start(CLOCK_SECOND * 2);

  /*
   * This is the scheduler loop.
   */
  watchdog_start();
  watchdog_stop(); /* Stop the wdt... */
  while(1) {
    int r;
    do {
      /* Reset watchdog. */
      watchdog_periodic();
      r = process_run();
    } while(r > 0);

    /*
     * Idle processing.
     */
    int s = splhigh();          /* Disable interrupts. */
    /* uart1_active is for avoiding LPM3 when still sending or receiving */
    if(process_nevents() != 0 || uart1_active()) {
      splx(s);                  /* Re-enable interrupts. */
    } else {
      static unsigned long irq_energest = 0;

      /* Re-enable interrupts and go to sleep atomically. */
      ENERGEST_OFF(ENERGEST_TYPE_CPU);
      ENERGEST_ON(ENERGEST_TYPE_LPM);
      /* We only want to measure the processing done in IRQs when we
         are asleep, so we discard the processing time done when we
         were awake. */
      energest_type_set(ENERGEST_TYPE_IRQ, irq_energest);
      watchdog_stop();
      _BIS_SR(GIE | SCG0 | SCG1 | CPUOFF); /* LPM3 sleep. This
                                              statement will block
                                              until the CPU is
                                              woken up by an
                                              interrupt that sets
                                              the wake up flag. */

      /* We get the current processing time for interrupts that was
         done during the LPM and store it for next time around.  */
      dint();
      irq_energest = energest_type_time(ENERGEST_TYPE_IRQ);
      eint();
      watchdog_start();
      ENERGEST_OFF(ENERGEST_TYPE_LPM);
      ENERGEST_ON(ENERGEST_TYPE_CPU);
    }
  }
}
Esempio n. 18
0
void main (void)
{
	unsigned int i;
	unsigned int loop_count;

	gear_num = 1;

	WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT

	//Delay to allow 3.3V rail to fully rise, essential for CAN part
	//because MSP430 will turn on at 1.8V or less
	//Especially if 3.3V voltage supervisor is not installed!
	for(i=0; i<65000; i++)
		asm("nop");

	clock_init();
	__enable_interrupt();                     // Enable interrupts

	initPortPins();                           // Initialize port pins
	initActuators();
	timer_init();
	gear_indication();
	ign_cut = 0;


	for (loop_count = 0; loop_count < 10; loop_count++)
	{
		  __bis_SR_register(GIE); //enable general interrupts

		//1 to N
		gear_status = 3;
		shift_gear();
		in_neutral = 1;
		gear_indication();

		//N to 2
		gear_indication();
		gear_status = 1;
		shift_gear();
		gear_num++;
		gear_indication();

		//UPSHIFTS
		//2 to 3
		gear_indication();
		gear_status = 1;
		shift_gear();
		gear_num++;
		gear_indication();

		//3 to 4
		gear_indication();
		gear_status = 1;
		shift_gear();
		gear_num++;
		gear_indication();

		//4 to 5
		gear_indication();
		gear_status = 1;
		shift_gear();
		gear_num++;
		gear_indication();

		//DOWNSHIFTS
    	//5 to 4
		gear_indication();
		in_neutral = 0;
		gear_status = 2;
		shift_gear();

		if (gear_num <= 1) {
			gear_num = 1;
			gear_indication();
		}
		else {
			gear_num--;
			gear_indication();
		}

		//4 to 3
		gear_indication();
		in_neutral = 0;
		gear_status = 2;
		shift_gear();

		if (gear_num <= 1) {
			gear_num = 1;
			gear_indication();
		}
		else {
			gear_num--;
			gear_indication();
		}

		//3 to 2
		gear_indication();
		in_neutral = 0;
		gear_status = 2;
		shift_gear();

		if (gear_num <= 1) {
			gear_num = 1;
			gear_indication();
		}
		else {
			gear_num--;
			gear_indication();
		}

		//2 to N
		gear_status = 3;
		shift_gear();
		gear_num--;
    	in_neutral = 1;
    	gear_indication();

		//N to 1 -- maybe
    	gear_indication();
		in_neutral = 0;
		gear_status = 2;
		shift_gear();

		if (gear_num <= 1) {
			gear_num = 1;
			gear_indication();
		}
		else {
			gear_num--;
			gear_indication();
		}

	}
}
Esempio n. 19
0
void
dtls_clock_init(void) {
  clock_init();
  dtls_clock_offset = clock_time();
}
Esempio n. 20
0
int notmain ( void )
{
    unsigned int ra;
    unsigned int spi_shift_out;
    unsigned int spi_shift_in;
    unsigned int spi_shift_count;

ASM_DELAY(10000);
    clock_init();
    uart_init();

    //ra=GET32(RCC_APB1ENR);
    //ra|=1<<3; //enable TIM5
    //PUT32(RCC_APB1ENR,ra);

    //PUT32(TIM5BASE+0x00,0x00000000);
    //PUT32(TIM5BASE+0x2C,50);
    //PUT32(TIM5BASE+0x00,0x00000001);

    ra=GET32(RCC_AHB1ENR);
    ra|=1<<0; //enable port A
    ra|=1<<4; //enable port E
    PUT32(RCC_AHB1ENR,ra);

    //PA5 SCK out
    //PA6 MISO in
    //PA7 MOSI out
    //PE3 CS out

    ra=GET32(GPIOA_MODER);
    ra&=~(3<<(5<<1)); //PA5
    ra|= (1<<(5<<1)); //PA5 output
    ra&=~(3<<(6<<1)); //PA6
    ra|= (0<<(6<<1)); //PA6 input
    ra&=~(3<<(7<<1)); //PA7
    ra|= (1<<(7<<1)); //PA7 output
    PUT32(GPIOA_MODER,ra);

    ra=GET32(GPIOA_OTYPER);
    ra&=~(1<<5); //PA5 push-pull
    ra&=~(1<<7); //PA7 push-pull
    PUT32(GPIOA_OTYPER,ra);

    ra=GET32(GPIOA_PUPDR);
    ra&=~(3<<(6<<1)); //PA6
    ra|= (2<<(6<<1)); //PA6 pull down
    //ra|= (0<<(6<<1)); //PA6
    PUT32(GPIOA_PUPDR,ra);

    ra=GET32(GPIOE_MODER);
    ra&=~(3<<(3<<1)); //PE3
    ra|= (1<<(3<<1)); //PE3 output
    PUT32(GPIOE_MODER,ra);

    ra=GET32(GPIOE_OTYPER);
    ra&=~(1<<3); //PE3 push-pull
    PUT32(GPIOE_OTYPER,ra);

    hexstring(GET32(GPIOA_MODER),1);
    hexstring(GET32(GPIOA_OTYPER),1);
    hexstring(GET32(GPIOA_PUPDR),1);
    hexstring(GET32(GPIOE_MODER),1);
    hexstring(GET32(GPIOE_OTYPER),1);

    CS_HIGH;
    SCK_HIGH;
    MOSI_HIGH;

//mosi is sampled on rising edge
//miso changes on falling edge

    hexstring(0x1234,1);

    spi_shift_out=0x2047;

    CS_LOW;
    timdelay();
    timdelay();
    spi_shift_count=16;
    while(spi_shift_count--)
    {
        SCK_LOW;
        timdelay();
        if(spi_shift_out&0x8000) MOSI_HIGH; else MOSI_LOW;
        timdelay();
        SCK_HIGH;
        timdelay();
        spi_shift_out<<=1;
        timdelay();
    }
    CS_HIGH;

    hexstring(0x1234,1);


    ASM_DELAY(250000);


    spi_shift_out=0x8F;

    CS_LOW;
    timdelay();
    timdelay();
    spi_shift_count=8;
    while(spi_shift_count--)
    {
        SCK_LOW;
        timdelay();
        if(spi_shift_out&0x80) MOSI_HIGH; else MOSI_LOW;
        timdelay();
        SCK_HIGH;
        timdelay();
        spi_shift_out<<=1;
        timdelay();
    }
    spi_shift_in=0;
    spi_shift_count=8;
    while(spi_shift_count--)
    {
        SCK_LOW;
        timdelay();
        spi_shift_in<<=1;
        if(GET32(GPIOA_IDR)&(1<<6)) spi_shift_in|=1;
        timdelay();
        SCK_HIGH;
        timdelay();
        timdelay();
    }
    CS_HIGH;

    hexstring(0x1234,1);
    hexstring(spi_shift_in,1);



    spi_shift_out=0xA0;

    CS_LOW;
    timdelay();
    timdelay();
    spi_shift_count=8;
    while(spi_shift_count--)
    {
        SCK_LOW;
        timdelay();
        if(spi_shift_out&0x80) MOSI_HIGH; else MOSI_LOW;
        timdelay();
        SCK_HIGH;
        timdelay();
        spi_shift_out<<=1;
        timdelay();
    }
    spi_shift_in=0;
    spi_shift_count=8;
    while(spi_shift_count--)
    {
        SCK_LOW;
        timdelay();
        spi_shift_in<<=1;
        if(GET32(GPIOA_IDR)&(1<<6)) spi_shift_in|=1;
        timdelay();
        SCK_HIGH;
        timdelay();
        timdelay();
    }
    CS_HIGH;

    hexstring(0x1234,1);
    hexstring(spi_shift_in,1);

    hexstring(spi_read_register(0x23),1);


    while(1)
    {
        hexstring(spi_read_register(0x27),0);
        hexstring(spi_read_register(0x0F),0);
        hexstring(spi_read_register(0x29),0);
        hexstring(spi_read_register(0x2B),0);
        hexstring(spi_read_register(0x2D),1);
    }
    //uart_string("\nHello World!\n");
    //hexstring(spi_shift_in,1);

    return(0);
}
Esempio n. 21
0
uint32_t uIPMain(void)
{
    uint32_t i;
    uip_ipaddr_t ipaddr;
    struct timer periodic_timer, arp_timer, can_sync_timer;

    LED_On(2);

    // Sys timer init 1/100 sec tick
    clock_init(2);

    timer_set(&periodic_timer, CLOCK_SECOND / 10);
    timer_set(&arp_timer, CLOCK_SECOND * 10);
    timer_set(&can_sync_timer, CLOCK_SECOND / 8); //ca. 1x pro sec wird gesynced

    // Initialize the ethernet device driver
    // Init MAC
    // Phy network negotiation
    tapdev_init(); //code in: ENET_TxDscrInit (ethernet.c) & ENET_RxDscrInit (ethernet.c) &  ETH_Start (stm32_eth.c)

    // Initialize the uIP TCP/IP stack.
    uip_init(); //code in uip.c

    // Init Server
    #ifdef TEST_GATEWAY
        uip_ipaddr(ipaddr, 10,0,241,2);
    #else
        uip_ipaddr(ipaddr, 10,0,241,1);
    #endif
    uip_sethostaddr(ipaddr); //ip
    uip_ipaddr(ipaddr, 10,0,240,0);
    uip_setdraddr(ipaddr);  //gw
    uip_ipaddr(ipaddr, 255,255,252,0);
    uip_setnetmask(ipaddr); //nm

    // Initialize the server listen on port 23
    uip_listen(HTONS(23));

    //turn led off, we are now ready for inncoming conenctions
    LED_Off(1);

    CanRxMsg RxMessage;
    int can_last_msg_id = 0;
    uint32_t nCount;

    while(1)
    {
        if(timer_expired(&can_sync_timer))
        {
            nCount++;
            timer_reset(&can_sync_timer);
            #ifndef TEST_GATEWAY
            send_sync( nCount % 2 );
            if( nCount % 2 == 1 )
                LED_On(2);
            else
                LED_Off(2);
            #endif
        }

        // ethernet stuff
        uip_len = tapdev_read(uip_buf);
        if(uip_len > 0) //read input
        {
            if(BUF->type == htons(UIP_ETHTYPE_IP)) //Layer3?
            {
                uip_arp_ipin();
                uip_input();
                /* If the above function invocation resulted in data that
                 should be sent out on the network, the global variable
                 uip_len is set to a value > 0. */
                if(uip_len > 0)
                {
                    uip_arp_out(); //get ARP of destination - or default gw (uip_arp.c)
                    tapdev_send(uip_buf,uip_len);
                }
            }
            else if(BUF->type == htons(UIP_ETHTYPE_ARP)) //Layer2?
            {
                uip_arp_arpin();
                /* If the above function invocation resulted in data that
                should be sent out on the network, the global variable
                uip_len is set to a value > 0. */
                if(uip_len > 0)
                {
                    tapdev_send(uip_buf,uip_len);
                }
            }
        }
        else if(timer_expired(&periodic_timer)) //check if there is data in the send queue of each connection and send it
        {
            timer_reset(&periodic_timer);
            for(i = 0; i < UIP_CONNS; i++)
            {
                uip_periodic(i); //sets uip_conn to the current connections (macro uip.h)
                /* If the above function invocation resulted in data that
                should be sent out on the network, the global variable
                uip_len is set to a value > 0. */
                if(uip_len > 0)
                {
                    uip_arp_out(); //get ARP of destination - or default gw (uip_arp.c)
                    tapdev_send(uip_buf,uip_len);
                }
            }
            #if UIP_UDP
            for(i = 0; i < UIP_UDP_CONNS; i++)
            {
                uip_udp_periodic(i);
                /* If the above function invocation resulted in data that
                should be sent out on the network, the global variable
                uip_len is set to a value > 0. */
                if(uip_len > 0)
                {
                    uip_arp_out(); //get ARP of destination - or default gw (uip_arp.c)
                    tapdev_send();
                }
            }
            #endif /* UIP_UDP */

            /* Call the ARP timer function every 10 seconds. */
            /* It updates the arp-table (removes old entries) */
            if(timer_expired(&arp_timer))
            {
                timer_reset(&arp_timer);
                uip_arp_timer();
            }
        }
    }
    return(TRUE);
}
Esempio n. 22
0
/**
 * \brief Main function for CC26xx-based platforms
 *
 * The same main() is used for both Srf+CC26xxEM as well as for the SensorTag
 */
int
main(void)
{
  /* Set the LF XOSC as the LF system clock source */
  select_lf_xosc();

  /*
   * Make sure to open the latches - this will be important when returning
   * from shutdown
   */
  ti_lib_pwr_ctrl_io_freeze_disable();

  /* Use DCDC instead of LDO to save current */
  ti_lib_pwr_ctrl_source_set(PWRCTRL_PWRSRC_DCDC);

  lpm_init();

  board_init();

  /* Enable flash cache and prefetch. */
  ti_lib_vims_mode_set(VIMS_BASE, VIMS_MODE_ENABLED);
  ti_lib_vims_configure(VIMS_BASE, true, true);

  gpio_interrupt_init();

  /* Clock must always be enabled for the semaphore module */
  HWREG(AUX_WUC_BASE + AUX_WUC_O_MODCLKEN1) = AUX_WUC_MODCLKEN1_SMPH;

  leds_init();

  fade(LEDS_RED);

  cc26xx_rtc_init();
  clock_init();
  rtimer_init();

  watchdog_init();
  process_init();

  random_init(0x1234);

  /* Character I/O Initialisation */
#if CC26XX_UART_CONF_ENABLE
  cc26xx_uart_init();
  cc26xx_uart_set_input(serial_line_input_byte);
#endif

  serial_line_init();

  printf("Starting " CONTIKI_VERSION_STRING "\n");
  printf("With DriverLib v%u.%02u.%02u.%u\n", DRIVERLIB_MAJOR_VER,
         DRIVERLIB_MINOR_VER, DRIVERLIB_PATCH_VER, DRIVERLIB_BUILD_ID);
  printf(BOARD_STRING " using CC%u\n", CC26XX_MODEL_CPU_VARIANT);

  process_start(&etimer_process, NULL);
  ctimer_init();

  energest_init();
  ENERGEST_ON(ENERGEST_TYPE_CPU);

  fade(LEDS_YELLOW);

  printf(" Net: ");
  printf("%s\n", NETSTACK_NETWORK.name);
  printf(" MAC: ");
  printf("%s\n", NETSTACK_MAC.name);
  printf(" RDC: ");
  printf("%s", NETSTACK_RDC.name);

  if(NETSTACK_RDC.channel_check_interval() != 0) {
    printf(", Channel Check Interval: %u ticks",
           NETSTACK_RDC.channel_check_interval());
  }
  printf("\n");

  netstack_init();

  set_rf_params();

#if NETSTACK_CONF_WITH_IPV6
  memcpy(&uip_lladdr.addr, &linkaddr_node_addr, sizeof(uip_lladdr.addr));
  queuebuf_init();
  process_start(&tcpip_process, NULL);
#endif /* NETSTACK_CONF_WITH_IPV6 */

  fade(LEDS_GREEN);

  process_start(&sensors_process, NULL);

  autostart_start(autostart_processes);

  watchdog_start();

  fade(LEDS_ORANGE);

  while(1) {
    uint8_t r;
    do {
      r = process_run();
      watchdog_periodic();
    } while(r > 0);

    /* Drop to some low power mode */
    lpm_drop();
  }
}
/*************************************************************************************************
 * main startup code                                                                             *
 *************************************************************************************************/
void initBoard(void)
{
    clock_init();
    io_init();
}
Esempio n. 24
0
/*---------------------------------------------------------------------------*/
int
main(void)
{
  
  /*
   * Initialize hardware.
   */
  halInit();
  clock_init();
  
  uart1_init(115200);
  
  // Led initialization
  leds_init();
    
  INTERRUPTS_ON(); 

  PRINTF("\r\nStarting ");
  PRINTF(CONTIKI_VERSION_STRING);
  PRINTF(" on %s\r\n",boardDescription->name);

  /*
   * Initialize Contiki and our processes.
   */
  
  process_init();
  
#if WITH_SERIAL_LINE_INPUT
  uart1_set_input(serial_line_input_byte);
  serial_line_init();
#endif
  //etimer_process should be started before ctimer init
  process_start(&etimer_process, NULL);
  //ctimer and rtimer should be initialized before netstack to enable RDC (cxmac, contikimac, lpp)   
  ctimer_init();
  rtimer_init();
  netstack_init();
#if !UIP_CONF_IPV6
  ST_RadioEnableAutoAck(FALSE); // Because frames are not 802.15.4 compatible. 
  ST_RadioEnableAddressFiltering(FALSE);
#endif

  set_rime_addr();
  
  procinit_init();    

  energest_init();
  ENERGEST_ON(ENERGEST_TYPE_CPU);
  
  autostart_start(autostart_processes);
  
  
  watchdog_start();
  
  while(1){
    
    int r;    
    
    do {
      /* Reset watchdog. */
      watchdog_periodic();
      r = process_run();
    } while(r > 0);
    
    
    
    ENERGEST_OFF(ENERGEST_TYPE_CPU);
    //watchdog_stop();    
    ENERGEST_ON(ENERGEST_TYPE_LPM);
    /* Go to idle mode. */
    halSleepWithOptions(SLEEPMODE_IDLE,0);
    /* We are awake. */
    //watchdog_start();
    ENERGEST_OFF(ENERGEST_TYPE_LPM);
    ENERGEST_ON(ENERGEST_TYPE_CPU);  
    
  }
  
}
/*---------------------------------------------------------------------------*/
int
main(int argc, char **argv)
{
  /*
   * Initalize hardware.
   */

  msp430_cpu_init();
  clock_init();
  leds_init();

  leds_on(LEDS_RED);

  clock_wait(2);

  uart1_init(115200); /* Must come before first printf */

#if NETSTACK_CONF_WITH_IPV4
  slip_arch_init(115200);
#endif /* NETSTACK_CONF_WITH_IPV4 */

  clock_wait(1);

  leds_on(LEDS_GREEN);
  //ds2411_init();

  /* XXX hack: Fix it so that the 802.15.4 MAC address is compatible
     with an Ethernet MAC address - byte 0 (byte 2 in the DS ID)
     cannot be odd. */
  //ds2411_id[2] &= 0xfe;

  leds_on(LEDS_BLUE);
  //xmem_init();

  leds_off(LEDS_RED);
  rtimer_init();
  /*
   * Hardware initialization done!
   */

  node_id = NODE_ID;

  /* Restore node id if such has been stored in external mem */
  //node_id_restore();

  /* for setting "hardcoded" IEEE 802.15.4 MAC addresses */
#ifdef IEEE_802154_MAC_ADDRESS
  {
    uint8_t ieee[] = IEEE_802154_MAC_ADDRESS;
    //memcpy(ds2411_id, ieee, sizeof(uip_lladdr.addr));
    //ds2411_id[7] = node_id & 0xff;
  }
#endif

  //random_init(ds2411_id[0] + node_id);

  leds_off(LEDS_BLUE);
  /*
   * Initialize Contiki and our processes.
   */
  process_init();
  process_start(&etimer_process, NULL);

  ctimer_init();

  init_platform();

  set_rime_addr();

  cc2520_init();
  {
    uint8_t longaddr[8];
    uint16_t shortaddr;

    shortaddr = (linkaddr_node_addr.u8[0] << 8) +
      linkaddr_node_addr.u8[1];
    memset(longaddr, 0, sizeof(longaddr));
    linkaddr_copy((linkaddr_t *)&longaddr, &linkaddr_node_addr);

    printf("MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
           longaddr[0], longaddr[1], longaddr[2], longaddr[3],
           longaddr[4], longaddr[5], longaddr[6], longaddr[7]);

    cc2520_set_pan_addr(IEEE802154_PANID, shortaddr, longaddr);
  }
  cc2520_set_channel(RF_CHANNEL);

  printf(CONTIKI_VERSION_STRING " started. ");
  if(node_id > 0) {
    printf("Node id is set to %u.\n", node_id);
  } else {
    printf("Node id is not set.\n");
  }

#if NETSTACK_CONF_WITH_IPV6
  /* memcpy(&uip_lladdr.addr, ds2411_id, sizeof(uip_lladdr.addr)); */
  memcpy(&uip_lladdr.addr, linkaddr_node_addr.u8,
         UIP_LLADDR_LEN > LINKADDR_SIZE ? LINKADDR_SIZE : UIP_LLADDR_LEN);

  /* Setup nullmac-like MAC for 802.15.4 */
/*   sicslowpan_init(sicslowmac_init(&cc2520_driver)); */
/*   printf(" %s channel %u\n", sicslowmac_driver.name, RF_CHANNEL); */

  /* Setup X-MAC for 802.15.4 */
  queuebuf_init();
  NETSTACK_RDC.init();
  NETSTACK_MAC.init();
  NETSTACK_NETWORK.init();

  printf("%s %s, channel check rate %lu Hz, radio channel %u\n",
         NETSTACK_MAC.name, NETSTACK_RDC.name,
         CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1:
                         NETSTACK_RDC.channel_check_interval()),
         RF_CHANNEL);

  process_start(&tcpip_process, NULL);

  printf("Tentative link-local IPv6 address ");
  {
    uip_ds6_addr_t *lladdr;
    int i;
    lladdr = uip_ds6_get_link_local(-1);
    for(i = 0; i < 7; ++i) {
      printf("%02x%02x:", lladdr->ipaddr.u8[i * 2],
             lladdr->ipaddr.u8[i * 2 + 1]);
    }
    printf("%02x%02x\n", lladdr->ipaddr.u8[14], lladdr->ipaddr.u8[15]);
  }

  if(!UIP_CONF_IPV6_RPL) {
    uip_ipaddr_t ipaddr;
    int i;
    uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
    uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
    uip_ds6_addr_add(&ipaddr, 0, ADDR_TENTATIVE);
    printf("Tentative global IPv6 address ");
    for(i = 0; i < 7; ++i) {
      printf("%02x%02x:",
             ipaddr.u8[i * 2], ipaddr.u8[i * 2 + 1]);
    }
    printf("%02x%02x\n",
           ipaddr.u8[7 * 2], ipaddr.u8[7 * 2 + 1]);
  }

#else /* NETSTACK_CONF_WITH_IPV6 */

  NETSTACK_RDC.init();
  NETSTACK_MAC.init();
  NETSTACK_NETWORK.init();

  printf("%s %s, channel check rate %lu Hz, radio channel %u\n",
         NETSTACK_MAC.name, NETSTACK_RDC.name,
         CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0? 1:
                         NETSTACK_RDC.channel_check_interval()),
         RF_CHANNEL);
#endif /* NETSTACK_CONF_WITH_IPV6 */

#if !NETSTACK_CONF_WITH_IPV4 && !NETSTACK_CONF_WITH_IPV6
  uart1_set_input(serial_line_input_byte);
  serial_line_init();
#endif

  leds_off(LEDS_GREEN);

#if TIMESYNCH_CONF_ENABLED
  timesynch_init();
  timesynch_set_authority_level((linkaddr_node_addr.u8[0] << 4) + 16);
#endif /* TIMESYNCH_CONF_ENABLED */

#if NETSTACK_CONF_WITH_IPV4
  process_start(&tcpip_process, NULL);
  process_start(&uip_fw_process, NULL);	/* Start IP output */
  process_start(&slip_process, NULL);

  slip_set_input_callback(set_gateway);

  {
    uip_ipaddr_t hostaddr, netmask;

    uip_init();

    uip_ipaddr(&hostaddr, 172,16,
	       linkaddr_node_addr.u8[0],linkaddr_node_addr.u8[1]);
    uip_ipaddr(&netmask, 255,255,0,0);
    uip_ipaddr_copy(&meshif.ipaddr, &hostaddr);

    uip_sethostaddr(&hostaddr);
    uip_setnetmask(&netmask);
    uip_over_mesh_set_net(&hostaddr, &netmask);
    /*    uip_fw_register(&slipif);*/
    uip_over_mesh_set_gateway_netif(&slipif);
    uip_fw_default(&meshif);
    uip_over_mesh_init(UIP_OVER_MESH_CHANNEL);
    printf("uIP started with IP address %d.%d.%d.%d\n",
           uip_ipaddr_to_quad(&hostaddr));
  }
#endif /* NETSTACK_CONF_WITH_IPV4 */

  energest_init();
  ENERGEST_ON(ENERGEST_TYPE_CPU);

  watchdog_start();
  /* Stop the watchdog */
  watchdog_stop();

#if !PROCESS_CONF_NO_PROCESS_NAMES
  print_processes(autostart_processes);
#else /* !PROCESS_CONF_NO_PROCESS_NAMES */
  putchar('\n'); /* include putchar() */
#endif /* !PROCESS_CONF_NO_PROCESS_NAMES */
  autostart_start(autostart_processes);

  /*
   * This is the scheduler loop.
   */
  while(1) {

    int r;
    do {
      /* Reset watchdog. */
      watchdog_periodic();
      r = process_run();
    } while(r > 0);

    /*
     * Idle processing.
     */
    int s = splhigh();		/* Disable interrupts. */
    /* uart1_active is for avoiding LPM3 when still sending or receiving */
    if(process_nevents() != 0 || uart1_active()) {
      splx(s);                  /* Re-enable interrupts. */
    } else {
      static unsigned long irq_energest = 0;

      /* Re-enable interrupts and go to sleep atomically. */
      ENERGEST_OFF(ENERGEST_TYPE_CPU);
      ENERGEST_ON(ENERGEST_TYPE_LPM);
      /* We only want to measure the processing done in IRQs when we
	 are asleep, so we discard the processing time done when we
	 were awake. */
      energest_type_set(ENERGEST_TYPE_IRQ, irq_energest);
      watchdog_stop();
      _BIS_SR(GIE | SCG0 | SCG1 | CPUOFF); /* LPM3 sleep. This
                                              statement will block
                                              until the CPU is
                                              woken up by an
                                              interrupt that sets
                                              the wake up flag. */

      /* We get the current processing time for interrupts that was
         done during the LPM and store it for next time around.  */
      dint();
      irq_energest = energest_type_time(ENERGEST_TYPE_IRQ);
      eint();
      watchdog_start();
      ENERGEST_OFF(ENERGEST_TYPE_LPM);
      ENERGEST_ON(ENERGEST_TYPE_CPU);
    }
  }
}
Esempio n. 26
0
/*---------------------------------------------------------------------------*/
int
main(void)
{
  
  /*
   * Initialize hardware.
   */
  halInit();
  clock_init();
  
  uart1_init(115200);
  
  // Led initialization
  leds_init();
    
  INTERRUPTS_ON(); 

  PRINTF("\r\nStarting ");
  PRINTF(CONTIKI_VERSION_STRING);
  PRINTF(" on %s\r\n",boardDescription->name);

  /*
   * Initialize Contiki and our processes.
   */
  
  process_init();
  
#if WITH_SERIAL_LINE_INPUT
  uart1_set_input(serial_line_input_byte);
  serial_line_init();
#endif
  /* rtimer and ctimer should be initialized before radio duty cycling layers*/
  rtimer_init();
  /* etimer_process should be initialized before ctimer */
  process_start(&etimer_process, NULL);   
  ctimer_init();
  
  rtimer_init();
  netstack_init();
  set_rime_addr();

  printf("%s %s, channel check rate %lu Hz\n",
         NETSTACK_MAC.name, NETSTACK_RDC.name,
         CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1:
                                  NETSTACK_RDC.channel_check_interval()));
  printf("802.15.4 PAN ID 0x%x, EUI-%d:",
      IEEE802154_CONF_PANID, UIP_CONF_LL_802154?64:16);
  uip_debug_lladdr_print(&rimeaddr_node_addr);
  printf(", radio channel %u\n", RF_CHANNEL);

  procinit_init();    

  energest_init();
  ENERGEST_ON(ENERGEST_TYPE_CPU);
  
  autostart_start(autostart_processes);
   
  watchdog_start();
  
  while(1){
    
    int r;    
    
    do {
      /* Reset watchdog. */
      watchdog_periodic();
      r = process_run();
    } while(r > 0);
    
    
    
    ENERGEST_OFF(ENERGEST_TYPE_CPU);
    //watchdog_stop();    
    ENERGEST_ON(ENERGEST_TYPE_LPM);
    /* Go to idle mode. */
    halSleepWithOptions(SLEEPMODE_IDLE,0);
    /* We are awake. */
    //watchdog_start();
    ENERGEST_OFF(ENERGEST_TYPE_LPM);
    ENERGEST_ON(ENERGEST_TYPE_CPU);  
    
  }
  
}
Esempio n. 27
0
int main(void)
{


	network_init();

	#if MY_DEBUG
	uartInit();
	uartSetBaudRate(9600);
	rprintfInit(uartSendByte);
	#endif

	int i;
	uip_ipaddr_t ipaddr; 
	struct timer periodic_timer, arp_timer;

	clock_init();

	timer_set(&periodic_timer, CLOCK_SECOND / 2);
	timer_set(&arp_timer, CLOCK_SECOND * 10);

	uip_init();
	
	struct uip_eth_addr mac = {UIP_ETHADDR0, UIP_ETHADDR1, UIP_ETHADDR2, UIP_ETHADDR3, UIP_ETHADDR4, UIP_ETHADDR5};

	uip_setethaddr(mac);

    hello_world_init();

#ifdef __DHCPC_H__
	dhcpc_init(&mac, 6);
#else
    uip_ipaddr(ipaddr, 192,168,0,1); 
	uip_sethostaddr(ipaddr);
    uip_ipaddr(ipaddr, 192,168,0,1);
    uip_setdraddr(ipaddr);
    uip_ipaddr(ipaddr, 255,255,255,0);
    uip_setnetmask(ipaddr);
#endif /*__DHCPC_H__*/


	while(1){
		uip_len = network_read(); 
		if(uip_len > 0) {
			if(BUF->type == htons(UIP_ETHTYPE_IP)){  
				uip_arp_ipin();
				uip_input();
				if(uip_len > 0) {
					uip_arp_out();
					network_send();
				}
			}else if(BUF->type == htons(UIP_ETHTYPE_ARP)){
				uip_arp_arpin();
				if(uip_len > 0){
					network_send();
				}
			}

		}else if(timer_expired(&periodic_timer)) {
			timer_reset(&periodic_timer);

			for(i = 0; i < UIP_CONNS; i++) {
				uip_periodic(i);
				if(uip_len > 0) {
					uip_arp_out();
					network_send();
				}
			}

			#if UIP_UDP
			for(i = 0; i < UIP_UDP_CONNS; i++) {
				uip_udp_periodic(i);
				if(uip_len > 0) {
					uip_arp_out();
					network_send();
				}
			}
			#endif /* UIP_UDP */

			if(timer_expired(&arp_timer)) {
				timer_reset(&arp_timer);
				uip_arp_timer();
			}
		}
	}
	return 0;
}
Esempio n. 28
0
/*
 * Routine: board_init
 * Description: Early hardware init.
 */
int board_init(void)
{
	__maybe_unused int err;
	__maybe_unused int board_id;

	/* Do clocks and UART first so that printf() works */
	clock_init();
	clock_verify();

	tegra_gpu_config();

#ifdef CONFIG_TEGRA_SPI
	pin_mux_spi();
#endif

	/* Init is handled automatically in the driver-model case */
#if defined(CONFIG_DM_VIDEO)
	pin_mux_display();
#endif
	/* boot param addr */
	gd->bd->bi_boot_params = (NV_PA_SDRAM_BASE + 0x100);

	power_det_init();

#ifdef CONFIG_SYS_I2C_TEGRA
# ifdef CONFIG_TEGRA_PMU
	if (pmu_set_nominal())
		debug("Failed to select nominal voltages\n");
#  ifdef CONFIG_TEGRA_CLOCK_SCALING
	err = board_emc_init();
	if (err)
		debug("Memory controller init failed: %d\n", err);
#  endif
# endif /* CONFIG_TEGRA_PMU */
#ifdef CONFIG_AS3722_POWER
	err = as3722_init(NULL);
	if (err && err != -ENODEV)
		return err;
#endif
#endif /* CONFIG_SYS_I2C_TEGRA */

#ifdef CONFIG_USB_EHCI_TEGRA
	pin_mux_usb();
#endif

#if defined(CONFIG_DM_VIDEO)
	board_id = tegra_board_id();
	err = tegra_lcd_pmic_init(board_id);
	if (err)
		return err;
#endif

#ifdef CONFIG_TEGRA_NAND
	pin_mux_nand();
#endif

	tegra_xusb_padctl_init(gd->fdt_blob);

#ifdef CONFIG_TEGRA_LP0
	/* save Sdram params to PMC 2, 4, and 24 for WB0 */
	warmboot_save_sdram_params();

	/* prepare the WB code to LP0 location */
	warmboot_prepare_code(TEGRA_LP0_ADDR, TEGRA_LP0_SIZE);
#endif
	return nvidia_board_init();
}
Esempio n. 29
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /*Clock initialization. */
  clock_init();

  /* Flash unlock */
  FLASH_Unlock();


  /*GPIO Initialization. */
  /*GPIOA, GPIOB on APB2 bus clock enable. */
  	  RCC->APB2ENR |= RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPBEN | RCC_APB2ENR_AFIOEN;

  	  /*PA0, PA1, PA2, PA3 in output mode general purpose push-pull. */
  	  GPIOA->CRL =(0x03 << (3 * 4)) | (0x03 << (2 * 4)) | (0x03 << (1 * 4)) | (0x03 << (0 * 4));

  	  /*PB0, PB1 in floating input mode. */
  	  GPIOB->CRL = (0x08 << (1 * 4)) | (0x08 << (0 * 4));

  	  /*why do we do this?. */
  	  GPIOB->ODR |= GPIO_ODR_ODR0 | GPIO_ODR_ODR1;

  	  /*Light up all leds by resetting the output bits. */
  	  GPIOA->BSRR |= GPIO_BSRR_BR0 | GPIO_BSRR_BR1 | GPIO_BSRR_BR2 | GPIO_BSRR_BR3;

  /* Initialize Key Button mounted on STM3210X-EVAL board */       
  //STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_GPIO);

  /* Test if button on the board is pressed during reset. */
  if ((GPIOB->IDR & GPIO_IDR_IDR1) == 0x00)
  { 
    /* If Key is pressed */
    /* Execute the IAP driver in order to re-program the Flash */
    IAP_Init();
    SerialPutString("\r\n======================================================================");
    SerialPutString("\r\n=              (C) COPYRIGHT 2010 STMicroelectronics                 =");
    SerialPutString("\r\n=                                                                    =");
    SerialPutString("\r\n=     In-Application Programming Application  (Version 3.3.0)        =");
    SerialPutString("\r\n=                                                                    =");
    SerialPutString("\r\n=                                   By MCD Application Team          =");
    SerialPutString("\r\n======================================================================");
    SerialPutString("\r\n\r\n");
    Main_Menu ();
  }
  /* Keep the user application running */
  else
  {
    /* Test if user code is programmed starting from address "ApplicationAddress" */
	uint32_t pippo1, pippo2;
	pippo1 = (*(__IO uint32_t*)ApplicationAddress); // 0x08000000   what is this value
	pippo2 = pippo1 & 0x2FFE0000;
    if (pippo2 == 0x20000000)
    { 
      /* Jump to user application */
      /* JumpAddress is not a pointer type. */
      /* ApplicationAddress+4 casted to a pointer to uin32_t. Jump address is the content
       * of the cell pointed by ApplicationAddress
       * Though wouldn't this be correct: JumpAddress = ApplicationAddress+4;
       * or! why does it dereferences it?
       */
      JumpAddress = *(__IO uint32_t*) (ApplicationAddress + 4);

      /*Jump_To_Application now points to the same address = JumpAddress through casting. */
      Jump_To_Application = (pFunction) JumpAddress;

      /* Initialize user application's Stack Pointer */
      /* __set_MSP implemented in CMSIS (as all the functions __* like). */
      __set_MSP(*(__IO uint32_t*) ApplicationAddress);
      Jump_To_Application();
    }
  }

  while (1)
  {}
}
Esempio n. 30
0
/*---------------------------------------------------------------------------*/
int
main(void)
{
  clock_init();
#if UIP_CONF_IPV6
/* A hard coded address overrides the stack default MAC address to allow multiple instances.
 * uip6.c defines it as {0x00,0x06,0x98,0x00,0x02,0x32} giving an ipv6 address of [fe80::206:98ff:fe00:232]
 * We make it simpler,  {0x02,0x00,0x00 + the last three bytes of the hard coded address (if any are nonzero).
 * HARD_CODED_ADDRESS can be defined in the contiki-conf.h file, or here to allow quick builds using different addresses.
 * If HARD_CODED_ADDRESS has a prefix it also applied, unless built as a RPL end node.
 * E.g. bbbb::12:3456 becomes fe80::ff:fe12:3456 and prefix bbbb::/64 if non-RPL
 *      ::10 becomes fe80::ff:fe00:10 and prefix awaits RA or RPL formation
 *      bbbb:: gives an address of bbbb::206:98ff:fe00:232 if non-RPL
*/
//#define HARD_CODED_ADDRESS      "bbbb::20"
#ifdef HARD_CODED_ADDRESS
{
  uip_ipaddr_t ipaddr;
  uiplib_ipaddrconv(HARD_CODED_ADDRESS, &ipaddr);
  if ((ipaddr.u8[13]!=0) || (ipaddr.u8[14]!=0) || (ipaddr.u8[15]!=0)) {
    if (sizeof(uip_lladdr)==6) {  //Minimal-net uses ethernet MAC
      uip_lladdr.addr[0]=0x02;uip_lladdr.addr[1]=0;uip_lladdr.addr[2]=0;
	  uip_lladdr.addr[3]=ipaddr.u8[13];;
	  uip_lladdr.addr[4]=ipaddr.u8[14];
	  uip_lladdr.addr[5]=ipaddr.u8[15];
   }
 }
}
#endif
#endif

  process_init();
/* procinit_init initializes RPL which sets a ctimer for the first DIS */
/* We must start etimers and ctimers,before calling it */
  process_start(&etimer_process, NULL);
  ctimer_init();

  procinit_init();
  autostart_start(autostart_processes);

#if RPL_BORDER_ROUTER
  process_start(&border_router_process, NULL);
  printf("Border Router Process started\n");
#elif UIP_CONF_IPV6_RPL
  printf("RPL enabled\n");
#endif

  /* Set default IP addresses if not specified */
#if !UIP_CONF_IPV6
  uip_ipaddr_t addr;
  
  uip_gethostaddr(&addr);
  if (addr.u8[0]==0) {
    uip_ipaddr(&addr, 10,1,1,1);
  }
  printf("IP Address:  %d.%d.%d.%d\n", uip_ipaddr_to_quad(&addr));
  uip_sethostaddr(&addr);

  uip_getnetmask(&addr);
  if (addr.u8[0]==0) {
    uip_ipaddr(&addr, 255,0,0,0);
    uip_setnetmask(&addr);
  }
  printf("Subnet Mask: %d.%d.%d.%d\n", uip_ipaddr_to_quad(&addr));

  uip_getdraddr(&addr);
  if (addr.u8[0]==0) {
    uip_ipaddr(&addr, 10,1,1,100);
    uip_setdraddr(&addr);
  }
  printf("Def. Router: %d.%d.%d.%d\n", uip_ipaddr_to_quad(&addr));

#else /* UIP_CONF_IPV6 */

#if !UIP_CONF_IPV6_RPL
  uip_ipaddr_t ipaddr;
#ifdef HARD_CODED_ADDRESS
  uiplib_ipaddrconv(HARD_CODED_ADDRESS, &ipaddr);
#else
  uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
#endif
  if ((ipaddr.u16[0]!=0) || (ipaddr.u16[1]!=0) || (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);
#else /* UIP_CONF_ROUTER */
    uip_ds6_prefix_add(&ipaddr, UIP_DEFAULT_PREFIX_LEN, 0);
#endif /* UIP_CONF_ROUTER */
#if !UIP_CONF_IPV6_RPL
    uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
    uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
#endif
  }
#endif

#if !RPL_BORDER_ROUTER  //Border router process prints addresses later
{ uint8_t i;
  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");
	}
  }
}
#endif
#endif /* !UIP_CONF_IPV6 */

  /* Make standard output unbuffered. */
  setvbuf(stdout, (char *)NULL, _IONBF, 0);

    printf("\n*******%s online*******\n",CONTIKI_VERSION_STRING);

  while(1) {
    fd_set fds;
    int n;
    struct timeval tv;
    
    n = process_run();
    /*    if(n > 0) {
      printf("%d processes in queue\n");
      }*/

    tv.tv_sec = 0;
    tv.tv_usec = 1;
    FD_ZERO(&fds);
    FD_SET(STDIN_FILENO, &fds);
    select(1, &fds, NULL, NULL, &tv);

    if(FD_ISSET(STDIN_FILENO, &fds)) {
      char c;
      if(read(STDIN_FILENO, &c, 1) > 0) {
	serial_line_input_byte(c);
      }
    }
    etimer_request_poll();
  }
  
  return 0;
}