#include <stdlib.h>
#include <stdio.h>
-
+#include <libgen.h>
+#if __APPLE__
+#include <GLUT/glut.h>
+#else
#include <GL/glut.h>
+#endif
#include <pthread.h>
#include "sim_avr.h"
#include "avr_ioport.h"
#include "sim_elf.h"
#include "sim_gdb.h"
+#include "sim_vcd_file.h"
#include "button.h"
button_t button;
int do_button_press = 0;
avr_t * avr = NULL;
+avr_vcd_t vcd_file;
uint8_t pin_state = 0; // current port B
float pixsize = 64;
{
if (key == 'q')
exit(0);
- static uint8_t buf[64];
+ //static uint8_t buf[64];
switch (key) {
case 'q':
case 0x1f: // escape
case ' ':
do_button_press++; // pass the message to the AVR thread
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;
}
}
button_press(&button, 1000000);
}
}
+ return NULL;
}
{
elf_firmware_t f;
const char * fname = "atmega48_ledramp.axf";
-
+ //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.mmcu.f_cpu, f.mmcu.name);
+ printf("firmware %s f=%d mmcu=%s\n", fname, (int)f.frequency, f.mmcu);
- avr = avr_make_mcu_by_name(f.mmcu.name);
+ avr = avr_make_mcu_by_name(f.mmcu);
if (!avr) {
- fprintf(stderr, "%s: AVR '%s' now known\n", argv[0], f.mmcu.name);
+ 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_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));
- // 'raise' it, it's a "pullup"
- avr_raise_irq(button.irq + IRQ_BUTTON_OUT, 1);
// connect all the pins on port B to our callback
for (int i = 0; i < 8; i++)
* Pressing "r" and "s" during the demo will start and stop recording
* the pin changes
*/
- avr_vcd_init(avr, "gtkwave_output.vcd", &vcd_file, 1000 /* usec */);
+ 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" );