Exemplo n.º 1
0
void kmain(void)
{

	init_bss();
	init_ro();

	setup_kernel_memory();
	setup_pages();
	setup_ints();
	setup_tss();
	setup_paging();
	setup_faults();
	setup_fs();
	setup_syscalls();

	init_devs();

	char vendor[12];
	if (has_cpuid()) {
		cpuid_string(0, vendor);
		dprintf("CPU Vendor ID: %s\n");
	}

	fexec("/prgm/start", 0, NULL, NULL);
	start_scheduler();

	asm volatile ("sti");
	asm volatile ("hlt");

	/* We should never reach this */
	assert(0);
}
Exemplo n.º 2
0
void send()
{ 
    wildfire_packet_t * wp;
    net_packet_t * np;
    uint16_t sample;
    uint8_t sends;
    
    sends = 0;

    init_devs();
    mos_thread_set_suspend_state(SUSPEND_STATE_SLEEP);  //sets power save mode

    //just wait while in init state
    while (state != GO)
    {
	mos_mdelay(500);
    }

    while (1)
    {
	if (state == SLEEPNODE)
	{

	    disable_wind_speed();   //must disable the ext interrupts for power save sleep
	    //mos_thread_set_suspend_state(SUSPEND_STATE_SLEEP);  //sets power save mode
	    mos_thread_sleep(SLEEP_INTERVAL - 1000); //extra 1000 to make sure it wakes up early
	    //mos_thread_set_suspend_state(SUSPEND_STATE_IDLE); //idle mode
	    
	    while (state != GO)  //awake, but not ready yet.. so just wait
		mos_mdelay(250);
	    sends = 0;

	}

	//first populate the buffer with the net packet since this will
	//always be the header
	np = (net_packet_t *)&(sendBuf.data[0]);
	np->type = DATA;
	np->src = myID;
	np->dest = baseID;
	np->next_hop = myParentID;
	np->last_hop = myID;
	np->seqno = mySeqNo;
	np->pkt_dtb = myDTB;
	np->sender_dtb = myDTB;
	sendBuf.size = sizeof(net_packet_t);
	
	//for data packets, we now populate the buffer with the 
	//wildfire packet information.  Adding it to the end.
	wp = (wildfire_packet_t *)&(sendBuf.data[sendBuf.size]);
	//temp
	dev_open(DEV_MICA2_TEMP);
	dev_read(DEV_MICA2_TEMP, &sample, sizeof(sample));
	dev_close(DEV_MICA2_TEMP);
	wp->temp = convert_temp(sample);

	//battery
	dev_open(DEV_MICA2_BATTERY);
	dev_read(DEV_MICA2_BATTERY, &sample, sizeof(sample));
	dev_close(DEV_MICA2_BATTERY);
	wp->battery = sample;

	//humidity
	humidity_on();
	mos_mdelay(200); //settling time
	dev_open(DEV_ADC);
	dev_ioctl(DEV_ADC, ADC_SET_CHANNEL, AVR_ADC_CH_2);
	dev_read(DEV_ADC, &sample, sizeof(sample));
	dev_close(DEV_ADC);
	humidity_off();
	wp->humidity = convert_humidity(sample, wp->battery);

	//wind direction
	wind_dir_on();
	dev_open(DEV_ADC);
	dev_ioctl(DEV_ADC, ADC_SET_CHANNEL, AVR_ADC_CH_1);
	dev_read(DEV_ADC, &sample, sizeof(sample));
	dev_close(DEV_ADC);
	wind_dir_off();
	wp->wind_direction = convert_direction(sample);

	//wind speed
	wp->wind_speed = wind_speed;

	sendBuf.size += sizeof(wildfire_packet_t);

	//debug info:
        /*	printf("type\tsrc\tdest\tnext\tlast\tseq\tpktdtb\ts_dtb\n");
  printf("%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n", np->type, np->src, np->dest, np->next_hop, np->last_hop, np->seqno, np->pkt_dtb, np->sender_dtb);

  printf("temp\thmdty\tw_dir\tw_spd\tbat\n");
  printf("%d\t%d\t%d\t%d\t%d\n", wp->temp, wp->humidity, wp->wind_direction, wp->wind_speed, wp->battery);
        */    
    
	if (rate == 0 || sends < rate*myDTB)
	{
	    com_send(IFACE_RADIO, &sendBuf);
	    mySeqNo++;
	    sends++;
	}
	if (mySeqNo > 254)
	    mySeqNo = 0;
	mos_mdelay(1000);
    }
}