int main( void ) { avr_init(); pulse_init(); puts( "$Id: tach.c,v 2.0 2002/09/22 02:10:18 tramm Exp $" ); putnl(); while( 1 ) { puthex( high_bits ); puthex( time() ); putc( ':' ); puthexs( pulse_0 ); putc( ' ' ); puthexs( pulse_1 ); putnl(); pulse_1 = pulse_0 = 0; msleep( 8192 ); } return 0; }
int avr_open_(device_t dev) { if (avr_initialized == FALSE) { avr_init(); avr_initialized = TRUE; } return DRIVER_NO_ERROR; }
int main(void) { // initialise MCU avr_init(); // turn on the red status led ASAP to show boot process avr_set_bit(PORTD, STATUS_LED); // we're using the XBee module, connected to the UART serial_init(); // turn off the red status led ASAP to show boot process has ended avr_clear_bit(PORTD, STATUS_LED); // prepare for using sleep_ms sleep_init(); // the endless loop while(TRUE) { // show we're awake avr_set_bit(PORTC, STATUS_LED); // visually printf( "Awake for 1 second ...\n"); // remotely _delay_ms(1000); printf( "Going to sleep for 10 seconds...\n"); avr_clear_bit(PORTC, STATUS_LED); sleep_ms(10000L); } return(0); }
avr_t * m128rfa1_create(struct drumfish_cfg *config) { avr_t *avr; avr = avr_make_mcu_by_name("atmega128rfa1"); if (!avr) { fprintf(stderr, "Failed to create AVR core 'atmega128rfa1'\n"); return NULL; } /* Setup any additional init/deinit routines */ avr->special_init = m128rfa1_init; avr->special_deinit = m128rfa1_deinit; avr->special_data = config; /* Initialize our AVR */ avr_init(avr); /* Our chips always run at 16mhz */ avr->frequency = 16000000; /* Set our fuses */ avr->fuse[0] = 0xE6; // low avr->fuse[1] = 0x1C; // high avr->fuse[2] = 0xFE; // extended //avr->lockbits = 0xEF; // lock bits /* Check to see if we initialized our flash */ if (!avr->flash) { fprintf(stderr, "Failed to initialize flash correctly.\n"); return NULL; } /* Based on fuse values, we'll always want to boot from the bootloader * which will always start at 0x1f800. */ avr->pc = PC_START; avr->codeend = avr->flashend; /* Setup our UARTs */ if (uart_pty_init(avr, &uart_pty[0], '0')) { fprintf(stderr, "Unable to start UART0.\n"); return NULL; } uart_pty_connect(&uart_pty[0]); if (uart_pty_init(avr, &uart_pty[1], '1')) { fprintf(stderr, "Unable to start UART1.\n"); return NULL; } uart_pty_connect(&uart_pty[1]); return avr; }
int main(int argc, char *argv[]) { // elf_firmware_t f; const char * pwd = dirname(argv[0]); avr = avr_make_mcu_by_name("at90usb162"); if (!avr) { fprintf(stderr, "%s: Error creating the AVR core\n", argv[0]); exit(1); } strcpy(avr_flash_path, "simusb_flash.bin"); // register our own functions avr->special_init = avr_special_init; avr->special_deinit = avr_special_deinit; //avr->reset = NULL; avr_init(avr); avr->frequency = 8000000; // this trick creates a file that contains /and keep/ the flash // in the same state as it was before. This allow the bootloader // app to be kept, and re-run if the bootloader doesn't get a // new one { char path[1024]; uint32_t base, size; snprintf(path, sizeof(path), "%s/../%s", pwd, "at90usb162_cdc_loopback.hex"); uint8_t * boot = read_ihex_file(path, &size, &base); if (!boot) { fprintf(stderr, "%s: Unable to load %s\n", argv[0], path); exit(1); } printf("Booloader %04x: %d\n", base, size); memcpy(avr->flash + base, boot, size); free(boot); avr->pc = base; avr->codeend = avr->flashend; } // even if not setup at startup, activate gdb if crashing avr->gdb_port = 1234; if (0) { //avr->state = cpu_Stopped; avr_gdb_init(avr); } vhci_usb_init(avr, &vhci_usb); vhci_usb_connect(&vhci_usb, '0'); while (1) { avr_run(avr); } }
int main (int argc, char **argv) { /* produce AVR's FSM headers. */ if (ANGFSM_OPTIONS (argc, argv)) return 0; avr_init (argc, argv); main_init (); main_loop (); return 0; }
int main(void) { avr_init(); serial_init(); gps_init(); // gps_on_receive_position(new_position_handler); printf("boot and init completed.\nentering tracking loop...\n"); while(1) { gps_receive(); } return(0); }
int main (int argc, char **argv) { avr_init (argc, argv); sei (); uart0_init (); proto_send0 ('z'); while (1) { uint8_t c = uart0_getc (); proto_accept (c); } }
avr_t *tests_init_avr(const char *elfname) { tests_cycle_count = 0; map_stderr(); elf_firmware_t fw; if (elf_read_firmware(elfname, &fw)) fail("Failed to read ELF firmware \"%s\"", elfname); avr_t *avr = avr_make_mcu_by_name(fw.mmcu); if (!avr) fail("Creating AVR failed."); avr_init(avr); avr_load_firmware(avr, &fw); return avr; }
int main(int argc, char *argv[]) { elf_firmware_t f; const char * fname = "atmega1280_i2ctest.axf"; printf("Firmware pathname is %s\n", fname); elf_read_firmware(fname, &f); printf("firmware %s f=%d mmcu=%s\n", fname, (int)f.frequency, f.mmcu); avr = avr_make_mcu_by_name(f.mmcu); if (!avr) { fprintf(stderr, "%s: AVR '%s' not known\n", argv[0], f.mmcu); exit(1); } avr_init(avr); avr_load_firmware(avr, &f); // initialize our 'peripheral', setting the mask to allow read and write i2c_eeprom_init(avr, &ee, 0xa0, 0x01, NULL, 1024); i2c_eeprom_attach(avr, &ee, AVR_IOCTL_TWI_GETIRQ(0)); ee.verbose = 1; // even if not setup at startup, activate gdb if crashing avr->gdb_port = 1234; if (0) { //avr->state = cpu_Stopped; avr_gdb_init(avr); } /* * VCD file initialization * * This will allow you to create a "wave" file and display it in gtkwave * Pressing "r" and "s" during the demo will start and stop recording * the pin changes */ // avr_vcd_init(avr, "gtkwave_output.vcd", &vcd_file, 100000 /* usec */); // avr_vcd_add_signal(&vcd_file, // avr_io_getirq(avr, AVR_IOCTL_TWI_GETIRQ(0), TWI_IRQ_STATUS), 8 /* bits */ , // "TWSR" ); printf( "\nDemo launching:\n"); int state = cpu_Running; while ((state != cpu_Done) && (state != cpu_Crashed)) state = avr_run(avr); }
int main( void ) { int cycle_count = 0; uint8_t servo_pos = 0; avr_init(); adc_init( 0x70 ); puts( "$Id: sweep.c,v 2.0 2002/09/22 02:10:18 tramm Exp $" ); putnl(); while( 1 ) { accel_task( adc_task ); if( ++cycle_count % 32 ) continue; puthex( high_bits ); puthex( time() ); putc( ':' ); puts( " Ax=" ); puthex( a_x ); puts( " Ay=" ); puthex( a_y ); puts( " pos=" ); puthexs( servo_pos ); servo_set( 0, servo_pos ); servo_set( 1, servo_pos ); servo_set( 2, servo_pos ); servo_set( 3, servo_pos ); servo_set( 4, servo_pos ); servo_set( 5, servo_pos ); servo_set( 6, servo_pos ); servo_set( 7, servo_pos ); servo_pos += 8; putnl(); } return 0; }
int main(void) { avr_init(); //acd_init(); //A - wej�cie //DDRA=0x00; //B - wyj�cie - opcjonalne z diod� //DDRB=0xFF; //C - wyj�cie - tranzystory //DDRC=0xFF; //PORTC=0x00; //D - wej�cie - nieu�ywany //DDRD=0x00; return 0; }
/** Entry point. */ int main (int argc, char **argv) { avr_init (argc, argv); /* Pull-ups. */ PORTB = 0xe0; PORTC = 0xfc; PORTD = 0x80; timer_init (); uart0_init (); twi_proto_init (); cs_init (); aux_init (); eeprom_read_params (); proto_send0 ('z'); sei (); while (1) main_loop (); return 0; }
int main(void) { avr_init(); avr_adc_init(); xbee_init(); xbee_wait_for_association(); avr_clear_bit(LIGHT_SENSOR_PORT, LIGHT_SENSOR_PIN); union { uint16_t reading; uint8_t bytes[2]; } light; while(TRUE) { light.reading = avr_adc_read(LIGHT_SENSOR_PIN); xbee_send_bytes(light.bytes, 2); _delay_ms(60000L); } return(0); }
int main( void ) { avr_init(); puts( "echo: Send me data" ); putnl(); while( 1 ) { uint8_t c; while( getchar( &c ) < 0 ) ; puthex( time() ); puts( ": read: " ); putc( c ); putnl(); } return 0; }
void main(void) { #else int main(void) { #endif /* Ensure that the Watchdog is not running. */ wdt_disable(); /* Initialize system. */ if (true != avr_init()) { error_handler(); } else if (true != eep_init()) { eep_deinit(); error_handler(); } else if (true != cmd_if_init()) { cmd_if_deinit(); error_handler(); } /* Disable modules that are not needed any more. */ eep_deinit(); LED_ORANGE_ON(); /* Enable interrupts. */ sei(); /* Endless application loop. */ for(;;) { /* Dispatch events from the event queue. */ vrt_dispatch_event(); /* Poll modules that require this. */ vrt_timer_task(); usb_task(); air_capture_task(); cmd_if_task(); } }
int main(void) { avr_init(); /* all devices initialize themselves as slaves in TWI*/ USI_TWI_Slave_Initialise(TWI_BROADCAST_ADDRESS); /* main loop */ while(1) { if (uart_dataReceived) { // if we have received anything over UART USI_TWI_Master_Initialise(); // Initialize ourselves as TWI master uint8_t buffer[2]; buffer[0] = (TWI_BROADCAST_ADDRESS << TWI_ADR_BITS) | /* address */ (FALSE << TWI_READ_BIT); /* write operation */ buffer[1] = uart_data; /* The data we received over UART has to be sent * over TWI. */ sendUart(uart_data); while (!USI_TWI_Start_Transceiver_With_Data(buffer, 2)); /* Transmit, and * re-transmit * till * successful. */ sendUart(uart_data); uart_dataReceived = false; /* we've consumed the data from UART.. */ /* reinitialize ourself as a slave in TWI*/ USI_TWI_Slave_Initialise(TWI_BROADCAST_ADDRESS); } else if (USI_TWI_Data_In_Receive_Buffer()) { /* have we * received * anything * over TWI? */ // temporary: USI_TWI_Master_Initialise(); // Initialize ourselves as TWI master uint8_t buffer[2]; buffer[0] = (TWI_BROADCAST_ADDRESS << TWI_ADR_BITS) | /* address */ (FALSE << TWI_READ_BIT); /* write operation */ buffer[1] = 0xf3; /* The data we received over UART has to be sent * over TWI. */ while (!USI_TWI_Start_Transceiver_With_Data(buffer, 2)); /* Transmit, and * re-transmit * till * successful. */ buffer[0] = (TWI_BROADCAST_ADDRESS << TWI_ADR_BITS) | /* address */ (FALSE << TWI_READ_BIT); /* write operation */ buffer[1] = 0x08; /* The data we received over UART has to be sent * over TWI. */ while (!USI_TWI_Start_Transceiver_With_Data(buffer, 2)); /* Transmit, and * re-transmit * till * successful. */ // temporary till here uint8_t TWI_data = USI_TWI_Receive_Byte(); // Receive that data sendUart(TWI_data); // Transmit it over UART } } }
int main(int argc, char *argv[]) { elf_firmware_t f = {{0}}; long f_cpu = 0; int trace = 0; int gdb = 0; int log = 1; char name[16] = ""; uint32_t loadBase = AVR_SEGMENT_OFFSET_FLASH; int trace_vectors[8] = {0}; int trace_vectors_count = 0; if (argc == 1) display_usage(basename(argv[0])); for (int pi = 1; pi < argc; pi++) { if (!strcmp(argv[pi], "--list-cores")) { list_cores(); } else if (!strcmp(argv[pi], "-h") || !strcmp(argv[pi], "--help")) { display_usage(basename(argv[0])); } else if (!strcmp(argv[pi], "-m") || !strcmp(argv[pi], "-mcu")) { if (pi < argc-1) strcpy(name, argv[++pi]); else display_usage(basename(argv[0])); } else if (!strcmp(argv[pi], "-f") || !strcmp(argv[pi], "-freq")) { if (pi < argc-1) f_cpu = atoi(argv[++pi]); else display_usage(basename(argv[0])); } else if (!strcmp(argv[pi], "-t") || !strcmp(argv[pi], "-trace")) { trace++; } else if (!strcmp(argv[pi], "-ti")) { if (pi < argc-1) trace_vectors[trace_vectors_count++] = atoi(argv[++pi]); } else if (!strcmp(argv[pi], "-g") || !strcmp(argv[pi], "-gdb")) { gdb++; } else if (!strcmp(argv[pi], "-v")) { log++; } else if (!strcmp(argv[pi], "-ee")) { loadBase = AVR_SEGMENT_OFFSET_EEPROM; } else if (!strcmp(argv[pi], "-ff")) { loadBase = AVR_SEGMENT_OFFSET_FLASH; } else if (argv[pi][0] != '-') { char * filename = argv[pi]; char * suffix = strrchr(filename, '.'); if (suffix && !strcasecmp(suffix, ".hex")) { if (!name[0] || !f_cpu) { fprintf(stderr, "%s: -mcu and -freq are mandatory to load .hex files\n", argv[0]); exit(1); } ihex_chunk_p chunk = NULL; int cnt = read_ihex_chunks(filename, &chunk); if (cnt <= 0) { fprintf(stderr, "%s: Unable to load IHEX file %s\n", argv[0], argv[pi]); exit(1); } printf("Loaded %d section of ihex\n", cnt); for (int ci = 0; ci < cnt; ci++) { if (chunk[ci].baseaddr < (1*1024*1024)) { f.flash = chunk[ci].data; f.flashsize = chunk[ci].size; f.flashbase = chunk[ci].baseaddr; printf("Load HEX flash %08x, %d\n", f.flashbase, f.flashsize); } else if (chunk[ci].baseaddr >= AVR_SEGMENT_OFFSET_EEPROM || chunk[ci].baseaddr + loadBase >= AVR_SEGMENT_OFFSET_EEPROM) { // eeprom! f.eeprom = chunk[ci].data; f.eesize = chunk[ci].size; printf("Load HEX eeprom %08x, %d\n", chunk[ci].baseaddr, f.eesize); } } } else { if (elf_read_firmware(filename, &f) == -1) { fprintf(stderr, "%s: Unable to load firmware from file %s\n", argv[0], filename); exit(1); } } } } if (strlen(name)) strcpy(f.mmcu, name); if (f_cpu) f.frequency = f_cpu; avr = avr_make_mcu_by_name(f.mmcu); if (!avr) { fprintf(stderr, "%s: AVR '%s' not known\n", argv[0], f.mmcu); exit(1); } avr_init(avr); avr_load_firmware(avr, &f); if (f.flashbase) { printf("Attempted to load a bootloader at %04x\n", f.flashbase); avr->pc = f.flashbase; } avr->log = (log > LOG_TRACE ? LOG_TRACE : log); avr->trace = trace; for (int ti = 0; ti < trace_vectors_count; ti++) { for (int vi = 0; vi < avr->interrupts.vector_count; vi++) if (avr->interrupts.vector[vi]->vector == trace_vectors[ti]) avr->interrupts.vector[vi]->trace = 1; } // even if not setup at startup, activate gdb if crashing avr->gdb_port = 1234; if (gdb) { avr->state = cpu_Stopped; avr_gdb_init(avr); } signal(SIGINT, sig_int); signal(SIGTERM, sig_int); for (;;) { int state = avr_run(avr); if ( state == cpu_Done || state == cpu_Crashed) break; } avr_terminate(avr); }
int main(int argc, char *argv[]) { elf_firmware_t f; //const char * fname = "atmega48_ledramp.axf"; const char * fname = argv[1]; char path[256]; // sprintf(path, "%s/%s", dirname(argv[0]), fname); // printf("Firmware pathname is %s\n", path); elf_read_firmware(fname, &f); printf("firmware %s f=%d mmcu=%s\n", fname, (int)f.frequency, f.mmcu); avr = avr_make_mcu_by_name(f.mmcu); if (!avr) { fprintf(stderr, "%s: AVR '%s' now known\n", argv[0], f.mmcu); exit(1); } avr_init(avr); avr_load_firmware(avr, &f); // initialize our 'peripheral' button_init(avr, &button, "button"); // "connect" the output irw of the button to the port pin of the AVR avr_connect_irq( button.irq + IRQ_BUTTON_OUT, avr_io_getirq(avr, AVR_IOCTL_IOPORT_GETIRQ('C'), 0)); // connect all the pins on port B to our callback for (int i = 0; i < 8; i++) avr_irq_register_notify( avr_io_getirq(avr, AVR_IOCTL_IOPORT_GETIRQ('B'), i), pin_changed_hook, NULL); // even if not setup at startup, activate gdb if crashing avr->gdb_port = 1234; if (0) { //avr->state = cpu_Stopped; avr_gdb_init(avr); } /* * VCD file initialization * * This will allow you to create a "wave" file and display it in gtkwave * Pressing "r" and "s" during the demo will start and stop recording * the pin changes */ avr_vcd_init(avr, "gtkwave_output.vcd", &vcd_file, 100000 /* usec */); avr_vcd_add_signal(&vcd_file, avr_io_getirq(avr, AVR_IOCTL_IOPORT_GETIRQ('B'), IOPORT_IRQ_PIN_ALL), 8 /* bits */ , "portb" ); avr_vcd_add_signal(&vcd_file, avr_io_getirq(avr, AVR_IOCTL_IOPORT_GETIRQ('C'), IOPORT_IRQ_PIN0), 1, "portc"); avr_vcd_add_signal(&vcd_file, button.irq + IRQ_BUTTON_OUT, 1 /* bits */ , "button" ); // 'raise' it, it's a "pullup" avr_raise_irq(button.irq + IRQ_BUTTON_OUT, 1); printf( "Demo launching: 'LED' bar is PORTB, updated every 1/64s by the AVR\n" " firmware using a timer. If you press 'space' this presses a virtual\n" " 'button' that is hooked to the virtual PORTC pin 0 and will\n" " trigger a 'pin change interrupt' in the AVR core, and will 'invert'\n" " the display.\n" " Press 'q' to quit\n\n" " Press 'r' to start recording a 'wave' file\n" " Press 's' to stop recording\n" ); /* * OpenGL init, can be ignored */ glutInit(&argc, argv); /* initialize GLUT system */ glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); glutInitWindowSize(8 * pixsize, 1 * pixsize); /* width=400pixels height=500pixels */ window = glutCreateWindow("Glut"); /* create window */ // Set up projection matrix glMatrixMode(GL_PROJECTION); // Select projection matrix glLoadIdentity(); // Start with an identity matrix glOrtho(0, 8 * pixsize, 0, 1 * pixsize, 0, 10); glScalef(1,-1,1); glTranslatef(0, -1 * pixsize, 0); glutDisplayFunc(displayCB); /* set window's display callback */ glutKeyboardFunc(keyCB); /* set window's key callback */ glutTimerFunc(1000 / 24, timerCB, 0); // the AVR run on it's own thread. it even allows for debugging! pthread_t run; pthread_create(&run, NULL, avr_run_thread, NULL); glutMainLoop(); }
int main(int argc, char *argv[]) { elf_firmware_t f; const char * fname = "wordClock-erl"; char path[256]; // sprintf(path, "%s/%s", dirname(argv[0]), fname); // printf("Firmware pathname is %s\n", path); elf_read_firmware(fname, &f); strcpy( f.mmcu, "atmega168" ); // hack f.frequency = 16000000; printf("firmware %s f=%d mmcu=%s\n", fname, (int)f.frequency, f.mmcu); avr = avr_make_mcu_by_name(f.mmcu); if (!avr) { fprintf(stderr, "%s: AVR '%s' now known\n", argv[0], f.mmcu); exit(1); } avr_init(avr); avr_load_firmware(avr, &f); // initialize our 'peripheral' // button_init(avr, &button, "button"); // "connect" the output irw of the button to the port pin of the AVR /* avr_connect_irq( button.irq + IRQ_BUTTON_OUT, avr_io_getirq(avr, AVR_IOCTL_IOPORT_GETIRQ('C'), 0)); */ // connect all the pins on port B to our callback #if 0 for (int i = 0; i < 8; i++) avr_irq_register_notify( avr_io_getirq(avr, AVR_IOCTL_IOPORT_GETIRQ('B'), i), pin_changed_hook, NULL); #endif // even if not setup at startup, activate gdb if crashing avr->gdb_port = 1234; if (0) { //avr->state = cpu_Stopped; avr_gdb_init(avr); } /* * VCD file initialization * * This will allow you to create a "wave" file and display it in gtkwave * Pressing "r" and "s" during the demo will start and stop recording * the pin changes * * Initially set to 100 000 usec = 100 ms. I think it is how often * to flush its' log. */ avr_vcd_init(avr, "gtkwave_output.vcd", &vcd_file, 100 /* usec */); /* want MOSI, SCLK, XLAT, BLANK */ avr_vcd_add_signal( &vcd_file, avr_io_getirq(avr, AVR_IOCTL_SPI_GETIRQ(0), SPI_IRQ_OUTPUT), 8, "MOSI" ); avr_vcd_add_signal(&vcd_file, avr_io_getirq(avr, AVR_IOCTL_IOPORT_GETIRQ('B'), 1 ), 1, "XLAT" ); avr_vcd_add_signal(&vcd_file, avr_io_getirq(avr, AVR_IOCTL_IOPORT_GETIRQ('B'), 2 ), 1, "BLANK" ); avr_vcd_add_signal(&vcd_file, avr_io_getirq(avr, AVR_IOCTL_IOPORT_GETIRQ('B'), 5 ), 1, "SCLK" ); #if 0 avr_vcd_add_signal(&vcd_file, button.irq + IRQ_BUTTON_OUT, 1 /* bits */ , "button" ); // 'raise' it, it's a "pullup" avr_raise_irq(button.irq + IRQ_BUTTON_OUT, 1); #endif avr_vcd_start( &vcd_file ); printf( "Demo launching. " ); #if 0 /* * OpenGL init, can be ignored */ glutInit(&argc, argv); /* initialize GLUT system */ glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); glutInitWindowSize(8 * pixsize, 1 * pixsize); /* width=400pixels height=500pixels */ window = glutCreateWindow("Glut"); /* create window */ // Set up projection matrix glMatrixMode(GL_PROJECTION); // Select projection matrix glLoadIdentity(); // Start with an identity matrix glOrtho(0, 8 * pixsize, 0, 1 * pixsize, 0, 10); glScalef(1,-1,1); glTranslatef(0, -1 * pixsize, 0); glutDisplayFunc(displayCB); /* set window's display callback */ glutKeyboardFunc(keyCB); /* set window's key callback */ glutTimerFunc(1000 / 24, timerCB, 0); #endif // the AVR run on it's own thread. it even allows for debugging! pthread_t run; pthread_create(&run, NULL, avr_run_thread, NULL); sleep( 60 ); // wait 5 seconds, then exit. avr_vcd_stop(&vcd_file); /* glutMainLoop(); */ }
int main(int argc, char* argv[]) { int r = 0; char* elf_file = NULL; int gdb_port = 0; for (char** arg = &argv[1]; *arg != NULL; ++arg) { if (strcmp("-d", *arg) == 0) gdb_port = atoi(*(++arg)); else elf_file = *arg; } if (elf_file == NULL) { fprintf(stderr, "Give me a .elf file to load\n"); return 1; } elf_firmware_t f; elf_read_firmware(elf_file, &f); avr_t* avr = avr_make_mcu_by_name("atmega328p"); if (!avr) { fprintf(stderr, "Unsupported cpu atmega328p\n"); return 1; } avr_init(avr); if (gdb_port != 0) { avr->gdb_port = gdb_port; avr_gdb_init(avr); } avr->frequency = 16000000; avr_load_firmware(avr, &f); pcd8544_init(avr, &lcd); avr_connect_irq(avr_io_getirq(avr, AVR_IOCTL_IOPORT_GETIRQ('C'), 2), lcd.irq + IRQ_PCD8544_DC); avr_connect_irq(avr_io_getirq(avr, AVR_IOCTL_IOPORT_GETIRQ('C'), 1), lcd.irq + IRQ_PCD8544_CS); avr_connect_irq(avr_io_getirq(avr, AVR_IOCTL_IOPORT_GETIRQ('C'), 0), lcd.irq + IRQ_PCD8544_RST); avr_connect_irq(avr_io_getirq(avr, AVR_IOCTL_SPI_GETIRQ(0), SPI_IRQ_OUTPUT), lcd.irq + IRQ_PCD8544_SPI_IN); gb_keypad_init(avr, &keypad); for (int i = 0; i < keydefs_length; i++) { const keydef_t *k = keydefs + i; avr_connect_irq(keypad.irq + k->keypad_key, avr_io_getirq(avr, AVR_IOCTL_IOPORT_GETIRQ(k->port), k->pin)); // Start with the pin high avr_ioport_t* port = (avr_ioport_t*) avr->io[k->avr_port].w.param; key_io[i].pin_mask = (1<<k->pin); key_io[i].pull_value = &port->external.pull_value; port->external.pull_mask |= key_io[i].pin_mask; port->external.pull_value |= key_io[i].pin_mask; gb_keypad_press(&keypad, k->keypad_key, 1); } if (display_init()) { lcd_ram_mutex = SDL_CreateMutex(); SDL_Thread* avr_thread = SDL_CreateThread(avr_run_thread, "avr-thread", avr); main_loop(); SDL_LockMutex(lcd_ram_mutex); quit_flag = 1; SDL_UnlockMutex(lcd_ram_mutex); int avr_thread_return; SDL_WaitThread(avr_thread, &avr_thread_return); SDL_DestroyMutex(lcd_ram_mutex); } else { r = 1; fprintf(stderr, "%s\n", display_error_message()); } display_destroy(); return r; }
int main(int argc, char *argv[]) { struct avr_flash flash_data; char boot_path[1024] = "ATmegaBOOT_168_atmega328.ihex"; uint32_t boot_base, boot_size; char * mmcu = "atmega328p"; uint32_t freq = 16000000; int debug = 0; int verbose = 0; /* * To allow other programs to know that the model is * online and ready for programming, we create a file * called emu_online.txt * * At the beginning we clean up the file and then write * to it later on once the emulator is running. */ char * emu_online_file = "emu_online.txt"; int emu_online_flag = 0; for (int i = 1; i < argc; i++) { if (!strcmp(argv[i] + strlen(argv[i]) - 4, ".hex")) strncpy(boot_path, argv[i], sizeof(boot_path)); else if (!strcmp(argv[i], "-d")) debug++; else if (!strcmp(argv[i], "-v")) verbose++; else if (strstr(argv[i], ".ihex") != NULL) strcpy( boot_path, argv[1] ); else { fprintf(stderr, "%s: invalid argument %s\n", argv[0], argv[i]); exit(1); } } if( access(emu_online_file, F_OK) != -1 ){ remove(emu_online_file); } avr = avr_make_mcu_by_name(mmcu); if (!avr) { fprintf(stderr, "%s: Error creating the AVR core\n", argv[0]); exit(1); } uint8_t * boot = read_ihex_file(boot_path, &boot_size, &boot_base); if (!boot) { fprintf(stderr, "%s: Unable to load %s\n", argv[0], boot_path); exit(1); } if (boot_base > 32*1024*1024) { mmcu = "atmega2560"; freq = 20000000; } printf("%s booloader 0x%05x: %d bytes\n", mmcu, boot_base, boot_size); snprintf(flash_data.avr_flash_path, sizeof(flash_data.avr_flash_path), "simduino_%s_flash.bin", mmcu); flash_data.avr_flash_fd = 0; // register our own functions avr->custom.init = avr_special_init; avr->custom.deinit = avr_special_deinit; avr->custom.data = &flash_data; avr_init(avr); avr->frequency = freq; memcpy(avr->flash + boot_base, boot, boot_size); free(boot); avr->pc = boot_base; /* end of flash, remember we are writing /code/ */ avr->codeend = avr->flashend; avr->log = 1 + verbose; // even if not setup at startup, activate gdb if crashing avr->gdb_port = 1234; if (debug) { avr->state = cpu_Stopped; avr_gdb_init(avr); } uart_pty_init(avr, &uart_pty); uart_pty_connect(&uart_pty, '0'); while (1) { int state = avr_run(avr); if ( state == cpu_Done || state == cpu_Crashed) break; if( emu_online_flag == 0){ fopen(emu_online_file, "w+"); emu_online_flag = 1; } } }
void atmega128_init(struct atmega128* const mega) { mega->uart0_rx_fifo_state = 0; mega->uart1_rx_fifo_state = 0; struct avr* const avr = &(mega->avr); struct avr_dmem* const dmem = &(avr->dmem); struct avr_pmem* const pmem = &(avr->pmem); // give access to arrays dmem->mem = mega->dmem; dmem->callbacks = mega->callbacks; dmem->size = ATMEGA128_DMEM_SIZE; pmem->mem = mega->pmem; pmem->decoded = mega->decoded; pmem->size = ATMEGA128_PMEM_SIZE; // initialise the config variables avr->pc_size = ATMEGA128_PC_SIZE; dmem->io_resisters_start = ATMEGA128_IO_REGISTERS_START; dmem->io_resisters_end = ATMEGA128_IO_REGISTERS_END; dmem->io_resisters_length = ATMEGA128_IO_REGISTERS_LENGTH; dmem->sreg_loc = ATMEGA128_SREG_LOC; dmem->sp_loc = ATMEGA128_STACK_POINTER_LOC; dmem->sp_size = ATMEGA128_STACK_POINTER_SIZE; dmem->x_loc = ATMEGA128_X_LOC; dmem->y_loc = ATMEGA128_Y_LOC; dmem->z_loc = ATMEGA128_Z_LOC; dmem->rampx_loc = ATMEGA128_RAMPX_LOC; dmem->rampy_loc = ATMEGA128_RAMPY_LOC; dmem->rampz_loc = ATMEGA128_RAMPZ_LOC; dmem->rampd_loc = ATMEGA128_RAMPD_LOC; dmem->eind_loc = ATMEGA128_EIND_LOC; avr_init(avr); avr->sleep_cb = &atmega128_sleep_cb; avr->sleep_cb_arg = mega; // initialise version specific callbacks dmem->callbacks[ATMEGA128_UDR0_LOC - ATMEGA128_IO_REGISTERS_START].write_callback = &atmega128_udr0_write_cb; dmem->callbacks[ATMEGA128_UDR0_LOC - ATMEGA128_IO_REGISTERS_START].write_callback_arg = mega; dmem->callbacks[ATMEGA128_UDR0_LOC - ATMEGA128_IO_REGISTERS_START].read_callback = &atmega128_udr0_read_cb; dmem->callbacks[ATMEGA128_UDR0_LOC - ATMEGA128_IO_REGISTERS_START].read_callback_arg = mega; dmem->callbacks[ATMEGA128_UCSR0A_LOC - ATMEGA128_IO_REGISTERS_START].write_callback = &atmega128_ucsr0a_write_cb; dmem->callbacks[ATMEGA128_UCSR0A_LOC - ATMEGA128_IO_REGISTERS_START].write_callback_arg = mega; dmem->callbacks[ATMEGA128_UCSR0B_LOC - ATMEGA128_IO_REGISTERS_START].write_callback = &atmega128_ucsr0b_write_cb; dmem->callbacks[ATMEGA128_UCSR0B_LOC - ATMEGA128_IO_REGISTERS_START].write_callback_arg = mega; dmem->callbacks[ATMEGA128_SREG_LOC - ATMEGA128_IO_REGISTERS_START].write_callback = &atmega128_sreg_write_cb; dmem->callbacks[ATMEGA128_SREG_LOC - ATMEGA128_IO_REGISTERS_START].write_callback_arg = mega; // initialise version specific registers atmega128_init_regs(dmem); }
int main(int argc, char *argv[]) { int state; elf_firmware_t f; const char *fname = "../BasicMotorControl.elf"; const char *mmcu = "atmega328p"; if (elf_read_firmware(fname, &f) != 0) { exit(1); } f.frequency = 16000000; printf("firmware %s f=%d mmcu=%s\n", fname, (int)f.frequency, mmcu); avr = avr_make_mcu_by_name(mmcu); if (!avr) { fprintf(stderr, "%s: AVR '%s' not known\n", argv[0], mmcu); exit(1); } avr_init(avr); avr_load_firmware(avr, &f); #if 0 /* even if not setup at startup, activate gdb if crashing */ avr->gdb_port = 1234; avr->state = cpu_Stopped; avr_gdb_init(avr); #endif /* VCD file initialization */ avr_vcd_init(avr, "wave.vcd", &vcd_file, 10000 /* usec */); avr_vcd_add_signal(&vcd_file, avr_io_getirq(avr, AVR_IOCTL_IOPORT_GETIRQ('B'), 0), 1, "B0" ); avr_vcd_add_signal(&vcd_file, avr_io_getirq(avr, AVR_IOCTL_IOPORT_GETIRQ('B'), 1), 1, "B1" ); avr_vcd_add_signal(&vcd_file, avr_io_getirq(avr, AVR_IOCTL_IOPORT_GETIRQ('B'), 2), 1, "B2" ); avr_vcd_add_signal(&vcd_file, avr_io_getirq(avr, AVR_IOCTL_IOPORT_GETIRQ('B'), 3), 1, "B3" ); avr_vcd_start(&vcd_file); /* IRQ callback hooks */ avr_irq_register_notify( avr_io_getirq(avr, AVR_IOCTL_IOPORT_GETIRQ('B'), 0), pin_changed_hook, NULL); avr_irq_register_notify( avr_io_getirq(avr, AVR_IOCTL_IOPORT_GETIRQ('B'), 1), pin_changed_hook, NULL); avr_irq_register_notify( avr_io_getirq(avr, AVR_IOCTL_IOPORT_GETIRQ('B'), 2), pin_changed_hook, NULL); avr_irq_register_notify( avr_io_getirq(avr, AVR_IOCTL_IOPORT_GETIRQ('B'), 3), pin_changed_hook, NULL); /* show some info */ show_ports(avr); /* install signal handlers */ signal(SIGINT, sig_int); signal(SIGTERM, sig_int); /* main loop */ printf("*** Entering main loop ***\n"); while (1) { state = avr_run(avr); if (state == cpu_Done || state == cpu_Crashed) { printf("CPU State %d\n", state); break; } } avr_vcd_stop(&vcd_file); avr_terminate(avr); return 0; }
void main(void) { #else int main(void) { #endif uint32_t blcc; // Prevent optimizing of bootloader revision in progmem volatile uint16_t tmp2 = ATmega3290p_bl_rev; // Disable watchdog watchdog_disable(); // Configuring LCD with Extern clock (TOSC, 32.768kHz) // 32786 Hz 32786 Hz // frame_rate = ------------------ = ------------- = 32 Hz // 8 * .prescl * .div 8 * 16 * 8 // lcd_config_t lcd_config = LCD_DEFAULT_CONFIG; // Initialization if (true != avr_init()) { // Generic MCU initialization error_handler(); } else if (df_init() != 0) { // Data flash initialization error_handler(); } else if (lcd_init(lcd_config) != 0) { // Display error_handler(); } else if (led_init() != 0) { // Led error_handler(); } /* start timer 2*/ ASSR |= (1<<AS2); // Asynchronous operation TCCR2A &= ~((1<<CS22)|(1<<CS21)|(1<<CS20)); TCCR2A |= (1<<CS20); // Check shorting of "Factory default pins" uint8_t prr = PRR; PRR &= ~(1 << PRADC); DIDR1 &= ~((1 << AIN1D)|(1 << AIN0D)); PRR = prr; BOOT_DDR |= (1 << BOOT_TX); // Tx output BOOT_PORT &= ~(1 << BOOT_TX); // Tx low BOOT_DDR &= ~(1 << BOOT_RX); // Rx input BOOT_PORT |= (1 << BOOT_RX); // Rx pullup on if ((BOOT_PIN & (1 << BOOT_RX)) != (1 << BOOT_RX)) { // Rx pin low? /* Check that RX goes high when TX is pulled high. */ BOOT_PORT |= (1 << BOOT_TX); // Set Tx high nop(); nop(); nop(); nop(); if ((BOOT_PIN & (1 << BOOT_RX)) == (1 << BOOT_RX)) { // Rx high? intvecs_to_boot(); // move interrutp vectors to boot section, and start boot loader sei(); // Check supply voltage if (supply_voltage_read() < 2600) { lcd_puts("LOW BAT"); error_handler(); } BLCC_WRITE(BLCC_NORMAL_APP_START); // write communication channel in case abnormal exit of boot loader (power off etc.) lcd_symbol_set(LCD_SYMBOL_RAVEN); lcd_puts("WRITING"); led_status_set(LED_FAST_BLINK); do_fw_upgrade(M3290P_FLASH_FD_IMG_ADR); // Signal ATmega3290p application program that FW upgrade is complete // This makes the application program continue upgrade ATmega1284p after booting BLCC_WRITE(BLCC_LOAD_FACTORY_DEFAULT); app_start(); // start application program } } // Read bootloader communication channel in EEPROM and take proper action BLCC_READ(blcc); if (blcc == BLCC_FW_UPGRADE_START_REQUEST_FROM_APP) { intvecs_to_boot(); // move interrutp vectors to boot section, and start boot loader sei(); // Check supply voltage if (supply_voltage_read() < 2600) { lcd_puts("LOW BAT"); error_handler(); } BLCC_WRITE(BLCC_NORMAL_APP_START); // write communication channel in case abnormal exit of boot loader (power off etc.) lcd_symbol_set(LCD_SYMBOL_RAVEN); lcd_puts("WRITING"); led_status_set(LED_FAST_BLINK); do_fw_upgrade(M3290P_FLASH_USR_IMG_ADR); // Signal ATmega3290p application program that FW upgrade is complete BLCC_WRITE(BLCC_FW_UPGRADE_COMPLETE); reboot(); } else if (blcc == BLCC_FW_UPGRADE_COMPLETE) { BLCC_WRITE(BLCC_FW_UPGRADE_COMPLETE); sei(); app_start(); // start application program } else if (blcc == BLCC_RESTART_REQUEST_FROM_APP) { /* Start application program*/ BLCC_WRITE(BLCC_NORMAL_APP_START); sei(); app_start(); } else { /*else, start application program*/ BLCC_WRITE(BLCC_NORMAL_APP_START); sei(); app_start(); } }
int main(void) { // INIT MCU avr_init(); uint32_t prev_time = 0; float uptime_float = 0; //char msg[64] = "Unknown time\r\n"; // Print program metrics /* USARTE0_WriteString_P(str_prog_name);// Название программы USARTE0_WriteString_P(PSTR("Compiled at: ")); USARTE0_WriteString_P(compile_time); // Время компиляции USARTE0_WriteString_P(PSTR(" ")); USARTE0_WriteString_P(compile_date); // Дата компиляции USARTE0_WriteString_P(PSTR("\r\n")); */ //Working via printf printf_P(str_prog_name);// Название программы printf_P(PSTR("Compiled at: ")); printf_P(compile_time); // Время компиляции printf_P(PSTR(" ")); printf_P(compile_date); // Дата компиляции printf_P(PSTR("\r\n")); // FreeRam DEBUG //sprintf_P(msg, PSTR(">>>Free RAM is: %u bytes\r\n\r\n"), freeRam()); //USARTE0_WriteString(msg); printf_P(PSTR(">>>Free RAM is: %u bytes\r\n\r\n"), freeRam()); //***************************Profiling micros: BEGIN //Accurate Measure time interval from 1us till ~ 65.5ms uint16_t _micros; // Profiling time for 10us _micros = TCD0.CNT; _delay_us(10); _micros = TCD0.CNT - _micros; printf_P(PSTR(">>>10us is: %u us\r\n"), _micros); // Profiling time for 100us _micros = TCD0.CNT; _delay_us(100); _micros = TCD0.CNT - _micros; printf_P(PSTR(">>>100us is: %u us\r\n"), _micros); // Profiling time for 1ms _micros = TCD0.CNT; _delay_ms(1); _micros = TCD0.CNT - _micros; printf_P(PSTR(">>>1ms is: %u us\r\n"), _micros); // Profiling time for 65ms _micros = TCD0.CNT; _delay_ms(65); _micros = TCD0.CNT - _micros; printf_P(PSTR(">>>65ms is: %u us\r\n"), _micros); //***************************Profiling micros: END //**************************Bench IO speed BENCH_IO_std_XMEGA_profile(); BENCH_IO_std_XMEGA(); //!! 2 cycle per instruction MIDDLE SPEED //BENCH_IO_tgl_XMEGA(); //!! 2 cycle per instruction MIDDLE SPEED //BENCH_IO_VirtualPort_XMEGA(); //!! 1 cycle per instruction FASTEST //BENCH_IO_std_MEGA(); //!! 5 cycle per instruction SLOWEST while(1); for(;;) { //Nothing to do //asm("nop"); // Print OUT second tick & Received from RX if (prev_time != uptime) { // Here every second //!! Uptime Handle prev_time = uptime; //sprintf(msg, "Uptime is: %lu sec\r\n", prev_time); //USARTE0_WriteString(msg); printf_P(PSTR("Uptime is: %lu sec\r\n"), prev_time); uptime_float += 0.01; //!! Don't forget correct <makefile> PRINTF_LIB for: /* PRINTF_LIB = $(PRINTF_LIB_FLOAT) */ printf_P(PSTR("Uptime float is: %.2f \r\n"), uptime_float); //!! Received from RX Handle // Check received index if (USARTE0_rx_buf_idx > 0) { cli(); // Disable IRQ static char rx_buf[rx_buf_MAX+1]; uint8_t idx = USARTE0_rx_buf_idx; memset(rx_buf, 0, sizeof(rx_buf)); // Fill RX_Buffer with Zeros memcpy(rx_buf, USARTE0_rx_buf, idx); // Transfer RX data to Temporary buffer USARTE0_rx_buf_idx = 0; // Set zero Received RX counter sei(); // Enable IRQ // Print OUT RX Received data //sprintf(msg, ">>RX: %s\r\n", rx_buf); //USARTE0_WriteString(msg); printf_P(PSTR(">>RX: %s\r\n"), rx_buf); } } /* // Not used because USARTE0_RX via IRQ else { // Check receive data from USARTE0 RX if (USARTE0_RX_Available()) { //Print OUT recieved from USARTE0 RX rx_char[0] = USARTE0_ReadChar(); sprintf(msg, ">> %s\r\n", rx_char); USARTE0_WriteString(msg); } } */ } return(0); }
int main (int argc, char *argv[]) { elf_firmware_t firmware; const char *firmware_path = "../../../firmwares/blink-led.elf"; int rc = elf_read_firmware (firmware_path, &firmware); if (rc == -1) exit (1); printf ("firmware %s f=%d mmcu=%s\n", firmware_path, (int) firmware.frequency, firmware.mmcu); firmware.frequency = 16e6; avr = avr_make_mcu_by_name ("atmega2560"); // firmware.mmcu if (!avr) { fprintf (stderr, "%s: AVR '%s' not known\n", argv[0], firmware.mmcu); exit (1); } avr_init (avr); avr_load_firmware (avr, &firmware); avr->log = LOG_TRACE; avr->trace = 1; // connect all the pins on port B to our callback for (int i = 0; i < 8; i++) avr_irq_register_notify (avr_io_getirq (avr, AVR_IOCTL_IOPORT_GETIRQ ('B'), i), pin_changed_hook, NULL); /* * VCD file initialization * * This will allow you to create a "wave" file and display it in gtkwave Pressing "r" and "s" * during the demo will start and stop recording the pin changes */ avr_vcd_init (avr, "gtkwave_output.vcd", &vcd_file, 100000); // us avr_vcd_add_signal (&vcd_file, avr_io_getirq (avr, AVR_IOCTL_IOPORT_GETIRQ ('B'), IOPORT_IRQ_PIN_ALL), 8, // bits "porth"); printf (" Press 'q' to quit\n\n" " Press 'r' to start recording a 'wave' file\n" " Press 's' to stop recording\n"); // the AVR run on it's own thread. it even allows for debugging! pthread_t run; pthread_create (&run, NULL, avr_run_thread, NULL); while (1) { switch (getchar()) { case 'q': exit(0); break; case 'r': printf ("Starting VCD trace\n"); avr_vcd_start (&vcd_file); break; case 's': printf ("Stopping VCD trace\n"); avr_vcd_stop (&vcd_file); break; } fflush(stdin); fflush(stdout); // sleep (10); // s } }
void main(void) { #else int main(void) { #endif /* Ensure that the watchdog is not running. */ wdt_disable(); /* Initialize AVR peripheral modules. */ (bool)avr_init(); /* Check if the RX and TX pins are shorted. If they are shorted, the RZUSBSTICK * shall start the bootloader. If not, continue to verify if the application * requested to enter the bootloader. */ /* Check if the application has requested to enter the bootloader. */ if ((BOOT_PIN & (1 << BOOT_RX)) != (1 << BOOT_RX)) { /* Check that RX goes high when TX is pulled high. */ BOOT_PORT |= (1 << BOOT_TX); nop(); nop(); nop(); nop(); if ((BOOT_PIN & (1 << BOOT_RX)) != (1 << BOOT_RX)) { start_application(); } } else { /* Check if the application has requested to enter the bootloader. */ uint8_t volatile magic_value = 0xAA; EEGET(magic_value, EE_BOOT_MAGIC_ADR); if (EE_BOOT_MAGIC_VALUE != magic_value) { start_application(); } else { EEPUT(EE_BOOT_MAGIC_ADR, 0xFF); } } /* Set the interrupt vectors to the bootloader, initialize the LEDs and the * VRT kernel. */ ENTER_CRITICAL_REGION(); uint8_t temp_mcucr = MCUCR; MCUCR = (1 << IVCE); MCUCR = (1 << IVSEL); MCUCR = temp_mcucr; LEAVE_CRITICAL_REGION(); LED_INIT(); vrt_init(); if (true != eep_init()) { error_handler(); } else if (true != cmd_if_init()) { error_handler(); } LED_ORANGE_ON(); /* Enable Interrupts. */ sei(); /* Enter the endless application loop. */ for (;;) { vrt_dispatch_event(); usb_task(); } }
int main(int argc, char *argv[]) { elf_firmware_t f; const char *fname="../src/binw2.elf"; const char *mmcu="attiny13"; elf_read_firmware(fname, &f); snprintf(f.mmcu, sizeof(f.mmcu) - 1, "%s", mmcu); f.frequency = 4800000; printf("firmware %s f=%d mmcu=%s\n", fname, (int)f.frequency, f.mmcu); avr = avr_make_mcu_by_name(f.mmcu); if (!avr) { fprintf(stderr, "%s: AVR '%s' not known\n", argv[0], f.mmcu); exit(1); } avr_init(avr); avr_load_firmware(avr, &f); // initialize our 'peripheral' button_init(avr, &button, "button"); // "connect" the output irq of the button to the port pin of the AVR avr_connect_irq( button.irq + IRQ_BUTTON_OUT, avr_io_getirq(avr, AVR_IOCTL_IOPORT_GETIRQ('B'), IOPORT_IRQ_PIN4)); avr_irq_register_notify( avr_io_getirq(avr, AVR_IOCTL_IOPORT_GETIRQ('B'), IOPORT_IRQ_DIRECTION_ALL), ddr_hook, NULL); avr_irq_register_notify( avr_io_getirq(avr, AVR_IOCTL_IOPORT_GETIRQ('B'), IOPORT_IRQ_PIN_ALL), pin_changed_hook, "portb"); // even if not setup at startup, activate gdb if crashing avr->gdb_port = 1234; //if (0) { // //avr->state = cpu_Stopped; // avr_gdb_init(avr); //} /* * VCD file initialization * * This will allow you to create a "wave" file and display it in gtkwave * Pressing "r" and "s" during the demo will start and stop recording * the pin changes */ avr_vcd_init(avr, "gtkwave_output.vcd", &vcd_file, 100000 /* usec */); avr_vcd_add_signal(&vcd_file, avr_io_getirq(avr, AVR_IOCTL_IOPORT_GETIRQ('B'), IOPORT_IRQ_PIN_ALL), 8 /* bits */ , "portb" ); avr_vcd_add_signal(&vcd_file, button.irq + IRQ_BUTTON_OUT, 1 /* bits */ , "button" ); // 'raise' it, it's a "pullup" avr_raise_irq(button.irq + IRQ_BUTTON_OUT, 0); printf( "Launching binw2 simulation\n" " Press 'space' to press virtual button attached to pin %d\n" " Press 'q' to quit\n" " Press 'r' to start recording a 'wave' file\n" " Press 's' to stop recording\n", IOPORT_IRQ_PIN4); /* * OpenGL init, can be ignored */ glutInit(&argc, argv); /* initialize GLUT system */ glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); glutInitWindowSize(5 * SZ_PIXSIZE, 7 * SZ_PIXSIZE); window = glutCreateWindow("Glut"); /* create window */ // Set up projection matrix glMatrixMode(GL_PROJECTION); // Select projection matrix glLoadIdentity(); // Start with an identity matrix glOrtho(0, 5 * SZ_PIXSIZE, 0, 7 * SZ_PIXSIZE, 0, 10); //glScalef(1, -1, 1); //glTranslatef(0, -7 * SZ_PIXSIZE, 0); glutDisplayFunc(displayCB); /* set window's display callback */ glutKeyboardFunc(keyCB); /* set window's key callback */ glutTimerFunc(1000 / 24, timerCB, 0); // the AVR run on it's own thread. it even allows for debugging! pthread_t run; pthread_create(&run, NULL, avr_run_thread, NULL); glutMainLoop(); }
int main(void) { avr_init(); u08 even; // u16 i; //u08 temp; command = 45; // actualTemp = 85; // u16 temp; for(;;) { // Tasks here. // Command line reception of commands... // pass characters received on the uart (serial port) // into the cmdline processor // while(uartReceiveByte(&c)){ // vt100SetCursorPos(1, 0); // uartSendByte(c); // cmdlineInputFunc(c); // // } // bounce the character, keep to the top 3 rows... // run the cmdline execution functions vt100SetCursorPos(3, 0); cmdlineMainLoop(); // Command line reception ends here if (APP_STATUS_REG & BV(DO_SAMPLE)) { readMAX6675(&tempData); // get data to tempData variable CLEAR_SAMPLE_FLAG; //debug, invert pin PIND ^= BV(PD5); //update PID // output = pid_Controller(command, tempData, &PID_data); //invert PID // output = PHASE_ANGLE_LIMIT_HIGH - output; } if(APP_STATUS_REG & BV(DO_PID)) { #ifdef REG_PID //update PID output = pid_Controller(command, tempData, &PID_data); #ifndef CMDLINE #ifndef RX_DBG rprintf("PID raw: "); rprintfNum(10, 6, TRUE, ' ', output); rprintfCRLF(); #endif //invert & limit PID if(output > 29700) output = 700; //output = PHASE_ANGLE_LIMIT_HIGH - output; #ifndef RX_DBG rprintf("PID scaled: "); rprintfNum(10, 6, TRUE, ' ', output); rprintfCRLF(); #endif #endif #endif #ifdef REG_PD #endif // actualTemp +=10; // OCR0A = output; CLEAR_PID_FLAG; // } /* if((temp = 0xFFFF-output) > 30000) { temp = 30000;} else if (temp < 1000) { temp = 1000;} */ // Limit to within 1 half-phase: if((output > PHASE_ANGLE_LIMIT_HIGH) || (output < 0)){ #ifndef CMDLINE #ifndef RX_DBG rprintf("Max out");rprintfCRLF(); #endif #endif output = PHASE_ANGLE_LIMIT_HIGH; // don't fire the triac at all! SET_HOLD_FIRE; // set flag to not fire triac } else { CLEAR_HOLD_FIRE; // set flag to fire triac } if ((output < PHASE_ANGLE_LIMIT_LOW)){ // || (output < 0)) #ifndef CMDLINE #ifndef RX_DBG rprintf("Min out");rprintfCRLF(); #endif #endif output = PHASE_ANGLE_LIMIT_LOW; // fire the triac at zerocrozz to get complete halfwave } #ifndef WALK_PHASEANGLE OCR1A = output; #endif //OCR1A = PHASE_ANGLE_LIMIT_LOW; //OCR1A = PHASE_ANGLE_LIMIT_HIGH; } #ifdef DEBUG_SER // uartPrintfNum(10, 6, TRUE, ' ', 1234); --> " +1234" // uartPrintfNum(16, 6, FALSE, '.', 0x5AA5); --> "..5AA5" // rprintfNum(10, 4, FALSE, ' ', tempData);// rprintfCRLF(); #ifndef CMDLINE #ifndef RX_DBG if(sensorDisconnected) { rprintfProgStrM("Disconnected Probe!\r\n"); } else { rprintf("Process Value: "); rprintfNum(10, 4, FALSE, ' ', tempData); rprintfCRLF(); rprintf("Target Value: "); rprintfNum(10, 4, FALSE, ' ', command); rprintfCRLF(); // rprintf("PID Phaselimit: "); // rprintfNum(10, 6, TRUE, ' ', output); rprintfCRLF(); rprintf("OCR1A: "); rprintfNum(10, 6, FALSE, ' ', OCR1A); rprintfCRLF(); //----------- // rprintf("dummy: "); // rprintfNum(10, 6, TRUE, ' ', _DUMMY); rprintfCRLF(); rprintf("E "); rprintfNum(10, 4, TRUE, ' ', _ERROR); rprintfCRLF(); rprintf("P "); rprintfNum(10, 8, TRUE, ' ', _PTERM); rprintfCRLF(); rprintf("I "); rprintfNum(10, 8, TRUE, ' ', _ITERM); rprintfCRLF(); rprintf("D "); rprintfNum(10, 8, TRUE, ' ', _DTERM); rprintfCRLF(); //----------- } vt100SetCursorPos(3, 0); if(even++ == 10){ vt100ClearScreen(); vt100SetCursorPos(3,0); even = 0; } #endif //#ifndef RX_DBG #endif //#ifndef CMDLINE #endif //#ifdef DEBUG_SER } return(0); }