예제 #1
0
void main()
{
   //T1CONL=0x30;
   //T1CONH=0xA0;
   
   setup_timer_0 (RTCC_INTERNAL|RTCC_DIV_16);
   set_timer0(0);
   led_io=0;
   enable_interrupts(INT_TIMER0);
   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);
   setup_io_dieukhien();
   Speaker_io=0;
   setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
   lcd_init();
   delay_ms(10);
   init_DS1307();
   delay_ms(10);
   init_ext_eeprom();
   delay_ms(10);
   LED_LCD_IO=0;
   LED_LCD=1;
   Init_595();
   menu_system=0;
   load_eeprom();
   off_all_van();
   while(true)
   {
      switch_menu();
   }
}
예제 #2
0
파일: loader.c 프로젝트: jncronin/jca
void main()
{
	uint32_t e_phoff;
	uint32_t e_phentsize = 0;
	uint32_t e_phnum = 0;
	uint32_t e_entry = 0;

	load_eeprom(28, 4, &e_phoff);
	load_eeprom(42, 2, &e_phentsize);
	load_eeprom(44, 2, &e_phnum);
	load_eeprom(24, 4, &e_entry);

	for(uint32_t ph_idx = 0; ph_idx < e_phnum; ph_idx++)
	{
		struct Elf32_Phdr ph;
		load_eeprom(e_phoff + ph_idx * e_phentsize,
				sizeof(struct Elf32_Phdr),
				&ph);

		if(ph.p_type == 1)
		{
			// PT_LOAD
			uintptr_t addr = ph.p_vaddr;
			
			if(ph.p_filesz)
			{
				load_eeprom(ph.p_offset, ph.p_filesz,
						(void *)addr);
				addr += ph.p_filesz;
			}
			for(int i = 0; i < ph.p_memsz - ph.p_filesz; i++, addr++)
				*(uint8_t *)addr = 0;
		}
	}

	((void (*)())e_entry)();



	while(1);
}
예제 #3
0
static void
main_thread(void *pdata) {
    QueueSetHandle_t qs;
    QueueSetMemberHandle_t active;

    ASSERT((qs = xQueueCreateSet(SERIAL_RX_SIZE * 3)));
    serial_start(cli_serial, 115200, qs);
    serial_start(&Serial4, 57600, qs);
    serial_start(&Serial5, cfg.gps_baud_rate ? cfg.gps_baud_rate : 57600, qs);
    cli_set_output(cli_serial);
    log_start(cli_serial);
    cl_enabled = 1;

    load_eeprom();
    cfg.flags &= ~FLAG_HOLDOVER_TEST;
    if (cfg.flags & FLAG_GPSEXT) {
        gps_serial = &Serial5;
    } else {
        gps_serial = &Serial4;
    }
    if (!cfg.holdover) {
        cfg.holdover = 60;
    }
    if (!cfg.loopstats_interval) {
        cfg.loopstats_interval = 60;
    }
    ppscapture_start();
    vtimer_start();
    tcpip_start();
    test_reset();
    cli_banner();
    if (!(cfg.flags & FLAG_GPSEXT)) {
        ublox_configure();
        if (HAS_FEATURE(PPSEN) && (cfg.flags & FLAG_PPSEN)) {
            GPIO_OFF(PPSEN);
        }
    }
    cl_enabled = 0;
    while (1) {
        watchdog_main = 5;
        active = xQueueSelectFromSet(qs, pdMS_TO_TICKS(1000));
        if (active == cli_serial->rx_q) {
            int16_t val = serial_get(cli_serial, TIMEOUT_NOBLOCK);
            ASSERT(val >= 0);
            cli_feed(val);
        } else if (active == gps_serial->rx_q) {
            int16_t val = serial_get(gps_serial, TIMEOUT_NOBLOCK);
            ASSERT(val >= 0);
            gps_byte_received(val);
            if (cfg.flags & FLAG_GPSOUT) {
                char tmp = val;
                serial_write(&Serial5, &tmp, 1);
            }
#if 0
        } else if (active == Serial5.rx_q) {
            char tmp = serial_get(&Serial5, TIMEOUT_NOBLOCK);
            serial_write(&Serial4, &tmp, 1);
#endif
        }
    }
}
예제 #4
0
파일: heating_ctr.c 프로젝트: znuh/unsorted
int main(void) {
	char buf[36];
	uint8_t ee_timer = 0;
	
	PORTB = (1<<PB7)|(1<<PB4);
	DDRB = (1<<PB7)|(1<<PB4);

	PORTD = 0;
	DDRD = 0;
	
	UBRRH=0;
	UBRRL = 12; // 9,6 kBaud
	
	UCSRA = (1<<U2X);
	UCSRB = (1<<TXEN);
	UCSRC = (3<<UCSZ0); // 8 bit, 1 stopbit
	
	TCCR0A = (1<<WGM01)|(1<<WGM00);
	TCCR0B = (1<<WGM02)|(7<<CS00);
	OCR0A = 49;
	
	TCCR1A = 0;
	TCCR1B = (5<<CS10);
	TCCR1C = 0;
	
	TIMSK = (1<<TOIE1) | (1<<TOIE0);
	
	MCUCR = (1<<ISC01);
	GIMSK = (1<<INT0);
	
	set_sleep_mode(SLEEP_MODE_IDLE);
	
	buf[0]='*';
	buf[1+8] = buf[1+8+1+8] = buf[1+8+1+8+1+8] = ',';
	buf[1+8+1+8+1+8+2] = ',';

	buf[30]='#';
	buf[31]='\r';
	buf[32]='\n';
	buf[33]=0;
	
	load_eeprom();
	
	while(1) {
		
		cli();
		
		if(events & EVT_TIMER) {
			uint32_t cnt_copy 	= cnt;
			uint32_t mark_copy 	= mark_cnt;
			uint8_t evts_copy 	= events;
			uint32_t echo;
			
			events = 0;
			
			sei();
			
			PORTB &= ~(1<<PB7);	// LED on

			echo = ping();
			
			u32tostr((uint8_t*)buf+1, cnt_copy);
			u32tostr((uint8_t*)buf+1+8+1, mark_copy);
			u32tostr((uint8_t*)buf+1+8+1+8+1, echo);
			
			// error indicator - inverted input
			buf[28] = (PINB & (1<<PB0)) ? '0' : '1';
			if(buf[28]&1) {
				PORTB &= ~(1<<PB4);	// ERROR-LED on
			}
			else {
				PORTB |= (1<<PB4);	// ERROR-LED off
			}
			
			buf[30]=0;
			cksum((uint8_t *)buf);
			
			uart_send(buf);
			
			/* eeprom write pending? */
			if(ee_timer) {
				ee_timer--;
				
				if(!ee_timer)
					write_eeprom(cnt_copy);
			}
			else if(evts_copy & EVT_CNTR)
				ee_timer = EE_WRDIV; 	// counter changed -> schedule eeprom write
			
			PORTB |= (1<<PB7);	// LED off
		}
		else
			sei();
		
		sleep_mode();
	}
	
	return 0;
}
예제 #5
0
파일: xbox.c 프로젝트: JayFoxRox/xqemu
/* PC hardware initialisation */
static void xbox_init(MachineState *machine)
{
    uint8_t *eeprom_data = load_eeprom();
    xbox_init_common(machine, eeprom_data, NULL, NULL);
}
예제 #6
0
int
main(int argc, char *argv[])
{
	int ret = 1, i, idx, fd, num_apps = 0;
	char *dev_file = "/dev/uhid0", *banner, *file;
	struct stat sb;
	dldev_t dev;
	appinfo *app = NULL;
	u8 *data;
	u16 len;

	/* for data security */
	/*
	umask(S_IRWXG | S_IRWXO);
	*/

	while((i = getopt(argc, argv, "hd:")) != -1){
		switch(i){
		case 'd':
			dev_file = optarg;
			break;
		case 'h':
		default:
			usage();
			break;
		}
	}
	argc -= optind;
	argv += optind;

#ifdef USB_USBHID
	dev.usb.file = dev_file;
#endif

	BEGIN_OPT()
#if 0
		APP_OPT("rom", -3)
		APP_OPT("eeprom", -2)
#endif
		APP_OPT("wristapp", -1)
		APP_OPT("contact", APP_CONTACT)
		APP_OPT("note", APP_NOTE)
		APP_OPT("appt", APP_APPT)
		APP_OPT("alarm", APP_ALARM)
		APP_OPT("schedule", APP_SCHEDULE)
		APP_OPT("occasion", APP_OCCASION)
		APP_OPT("chrono", APP_CHRONO)
		APP_OPT("countdn", APP_TIMER)
		APP_OPT("interval", APP_TIMER | 0x100)
#if 0
		APP_OPT("synchro", APP_SYNCHRO)
#endif
		APP_OPT("option", APP_OPTION)
	END_OPT()

	if(!num_apps)
		usage();

	if(open_dev(&dev)){
		ERROR("open_dev");
		goto exit;
	}

	tucp_progress(1);

	if(start_session(&dev)){
		ERROR("read_app_info");
		goto exit;
	}

/******************************************************************************/
#ifdef DEBUG
	for(i = 0; i < NUM_APPS; i++){
		if(!dev.app[i].acd.app_idx)
			continue;
		printf("%2d: %d%d%d%d%d%d%d%d %02x %02x %04x %04x %04x %04x %04x %04x %s\n", i,
				dev.app[i].acd.app_idx,
				dev.app[i].acd.code_loc,
				dev.app[i].acd.db_loc,
				dev.app[i].acd.code_invalid,
				dev.app[i].acd.db_modified,
				dev.app[i].acd.db_invalid,
				dev.app[i].acd.passwd_req,
				dev.app[i].acd.mode_name,

				dev.app[i].acb.app_type,
				dev.app[i].acb.app_inst,
				dev.app[i].acb.asd_addr,
				dev.app[i].acb.add_addr,
				dev.app[i].acb.state_mgr_addr,
				dev.app[i].acb.refresh_addr,
				dev.app[i].acb.banner_addr,
				dev.app[i].acb.code_addr,
				dev.app[i].banner
		);
	}
#endif
/******************************************************************************/

	for(i = 0; i < num_apps; i++){
		if(app[i].file[0])
			fprintf(stderr, "%s\n", app[i].file);
		else
			continue;

		banner = NULL;
		file = app[i].file;

		switch(app[i].app){
#if 0
		case -3:
			if(load_rom(&dev, &data, &len)){
				ERROR("load_rom");
				goto end;
			}
			break;
		case -2:
			if(load_eeprom(&dev, &data, &len)){
				ERROR("load_eeprom");
				goto end;
			}
			break;
#endif
		case -1:
			banner = file;
			for(; *file && *file != '='; file++);
			if(*file)
				*file++ = 0;
			if(!(*file)){
				ERROR("%s: no file name specified", banner);
				goto end;
			}
			for(; *banner; banner++)
				*banner = toupper(*banner);
			banner = app[i].file;
			break;
		case APP_CONTACT:
			banner = "CONTACT";
			break;
		case APP_NOTE:
			banner = "NOTE";
			break;
		case APP_APPT:
			banner = "APPT";
			break;
		case APP_ALARM:
			banner = "ALARM";
			break;
		case APP_SCHEDULE:
			banner = "SCHEDULE";
			break;
		case APP_OCCASION:
			banner = "OCCASION";
			break;
		case APP_CHRONO:
			banner = "CHRONO";
			break;
		case APP_TIMER:
			banner = "COUNTDN TIMER";
			break;
		case APP_TIMER | 0x100:
			banner = "INTERVAL TIMER";
			break;
#if 0
		case APP_SYNCHRO:
			banner = "SYNCHRO";
			break;
#endif
		case APP_OPTION:
			break;
		}

		if(stat(file, &sb)){
			ERROR("%s: stat failed", file);
			goto end;
		}
		len = sb.st_size;
		if((fd = open(file, O_RDONLY)) < 0){
			ERROR("%s: open failed", file);
			goto end;
		}
		data = (u8*)malloc(len);
		if(read(fd, data, len) != len){
			ERROR("%s: read failed", file);
			goto end;
		}
		close(fd);

		if(banner){
			if((idx = find_app(&dev, banner)) < 0){
				ERROR("%s application not found", banner);
				goto end;
			}
			if(load_add(&dev, idx, data)){
				ERROR("load_add");
				goto end;
			}
		}else{
			len = 15;
			if(write_abs_addr(&dev, dev.sysmap.opt_addr, int_mem,
						data, len)){
				ERROR("write_abs_addr");
				goto end;
			}
		}
		free(data);
	}

/******************************************************************************/
end:
	if(end_session(&dev)){
		ERROR("end_session");
		goto exit;
	}

	tucp_progress(0);

	ret = 0;
exit:
	close_dev(&dev);

	exit(ret);
}