File: multicore.c

package info (click to toggle)
simulavr 1.0.0%2Bgit20160221.e53413b-1
  • links: PTS
  • area: main
  • in suites: buster
  • size: 5,748 kB
  • sloc: cpp: 35,491; python: 6,991; ansic: 3,567; makefile: 1,072; sh: 653; asm: 414; tcl: 320
file content (52 lines) | stat: -rw-r--r-- 1,429 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
 * Example code for multicore example with python interface
 */
 
#include <avr/interrupt.h>

#ifdef DUAL_B

// Code for core B: count events on port B2

volatile char cnt_irq = 0;         // IRQ counter
volatile char cnt_res = 0;         // measurement value for time distance between events

ISR(INT0_vect) {
  cnt_irq++;                       // increment event counter
  cnt_res = TCNT0;                 // save timer value = time distance to last event
  TCNT0 = 0;                       // reset timer value
}

void init() {
  MCUCR = _BV(ISC00) | _BV(ISC01); // rising edge will generate interrupt
  GICR |= _BV(INT0);               // enable INT0
  GIFR |= _BV(INTF0);              // reset former irq request
  TCNT0 = 0;                       // Timer 0 as counter with internal clock
  TCCR0 = 0x0 + 0x04 + 0x0;        // wgm=0, cs=4, com=0
  sei();                           // enable interrupts
}

#endif

#ifdef DUAL_A

// Code for core A: generate 250Hz signal on port B3

void init() {
  TCNT0 = 0;                       // reset timer
  OCR0 = 124;                      // Timer 0 by CLK/64, 2ms on 4MHz, CTC mode,
                                   // 4ms period on OC0 out
  TCCR0 = 0x08 + 0x03 + 0x10;      // wgm=2, cs=3, com=1
  DDRB = 0x8;                      // PB3=out
}

#endif

// Mainloop
int main() {
  init();
  for(;;);
  return 0;
}

// EOF