Skip to content

Instantly share code, notes, and snippets.

@gergoerdi
Created July 30, 2017 11:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gergoerdi/37448e22eb92542f6ac8284ae2952bc8 to your computer and use it in GitHub Desktop.
Save gergoerdi/37448e22eb92542f6ac8284ae2952bc8 to your computer and use it in GitHub Desktop.
simavr irq->value from callbacks
#include "sim_avr.h"
#include "avr_ioport.h"
#include "sim_elf.h"
#include <stdio.h>
void ext_cb(struct avr_irq_t* irq, uint32_t val, void* closure)
{
avr_irq_t *trigger = (avr_irq_t*)(closure);
uint32_t extval = irq->value;
uint32_t intval = trigger->value;
printf("ext_cb: arg = %02x external->value = %02x internal->value = %02x\n", val, extval, intval);
}
void int_cb(struct avr_irq_t* irq, uint32_t val, void* closure)
{
avr_irq_t *trigger = (avr_irq_t*)(closure);
uint32_t intval = irq->value;
uint32_t extval = trigger->value;
printf("int_cb: arg = %02x external->value = %02x internal->value = %02x\n", val, extval, intval);
}
int main(int argc, char *argv[])
{
elf_firmware_t f;
elf_read_firmware("../firmware/image.elf", &f);
f.frequency = 16e6;
const char *mmcu = "atmega328p";
avr_t * avr = avr_make_mcu_by_name(mmcu);
if (!avr)
{
fprintf(stderr, "Initializing SimAVR failed\n");
return 1;
}
avr_init(avr);
avr_load_firmware(avr, &f);
static const char *trigger_name = "trigger";
avr_irq_t *external_trigger = avr_alloc_irq(&(avr->irq_pool), 0, 1, &trigger_name);
avr_irq_t *internal_trigger = avr_io_getirq(avr, AVR_IOCTL_IOPORT_GETIRQ('C'), 1);
avr_irq_register_notify(external_trigger, ext_cb, internal_trigger);
avr_irq_register_notify(internal_trigger, int_cb, external_trigger);
avr_connect_irq(internal_trigger, external_trigger);
for (;;)
{
avr_run(avr);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment