Skip to content
Snippets Groups Projects
Commit 026ae946 authored by Markus Scheck's avatar Markus Scheck
Browse files

clean up unused code

parent 961ac870
No related branches found
No related tags found
No related merge requests found
Showing
with 20 additions and 325 deletions
...@@ -4,20 +4,24 @@ ...@@ -4,20 +4,24 @@
int main(void) { int main(void) {
// enable serial port for output
Serial.begin(9600); Serial.begin(9600);
// init hardware timer
timer_init(); timer_init();
// init pin change interrupt
init_pc(); init_pc();
// enable interrupts // enable interrupts
sei(); sei();
// start time measurement
timer_start(); timer_start();
PORTA = 0xff; // set high PORTA = 0xff; // trigger own interrupt
// timer will be stopped in pc interrupt // timer will be stopped in pc interrupt
while(1) { while(1) {
} }
} }
...@@ -6,16 +6,18 @@ ...@@ -6,16 +6,18 @@
//initialize pin change interrupt and data directions //initialize pin change interrupt and data directions
inline void init_pc(void) { inline void init_pc(void) {
// enable/ setup output port // setup output ports
// toggle full port to not waste time on bit masking
DDRA = 0xff; // all out DDRA = 0xff; // all out
PORTA = 0x00; // all low PORTA = 0x00; // all low
// enable input port // enable input port (Pinchange)
// enable interrupt // enable interrupt
EICRA |= (1<<ISC30)|(1<<ISC31); EICRA |= (1<<ISC30)|(1<<ISC31);
EIMSK |= (1<<INT3); EIMSK |= (1<<INT3);
} }
// Interrupt handler
ISR(INT3_vect) { ISR(INT3_vect) {
Serial.println(timer_stop()); Serial.println(timer_stop());
} }
...@@ -26,19 +26,22 @@ inline void timer_start(void) { ...@@ -26,19 +26,22 @@ inline void timer_start(void) {
TCCR1B |= TIMER_MASK; TCCR1B |= TIMER_MASK;
//enable interrupts //enable interrupts
sei(); sei();
} }
// return current timer ticks
inline uint32_t timer_ticks(void) { inline uint32_t timer_ticks(void) {
return TCNT1 ^ (overflow_count << 16); return TCNT1 ^ (overflow_count << 16);
} }
// stop timer
inline uint32_t timer_stop(void) { inline uint32_t timer_stop(void) {
// stop timer clock // stop timer clock
TCCR1B &= ~(TIMER_MASK); TCCR1B &= ~(TIMER_MASK);
return timer_ticks(); return timer_ticks();
} }
// count overflow to enlarge tier register in software
ISR(TIMER1_OVF_vect) { ISR(TIMER1_OVF_vect) {
overflow_count++; overflow_count++;
} }
#include "timer_1.h"
#include "pinchange.h"
#include <avr/io.h>
int main(void) {
Serial.begin(9600);
timer_init();
init_pc();
// enable interrupts
sei();
timer_start();
PORTA = 0xff; // set high
// timer will be stopped in pc interrupt
while(1) {
}
}
// all functions inline to save execution time
inline void init_pc(void);
// This module uses PIN CHANGE INTERRUPT INT3
#include <avr/interrupt.h>
#include <avr/io.h>
#include "timer_1.h"
//initialize pin change interrupt and data directions
inline void init_pc(void) {
// enable/ setup output port
DDRA = 0xff; // all out
PORTA = 0x00; // all low
// enable input port
// enable interrupt
EICRA |= (1<<ISC30)|(1<<ISC31);
EIMSK |= (1<<INT3);
}
ISR(INT3_vect) {
Serial.println(timer_stop());
}
// all functions inline to save execution time
// initialize timer for time measurement
inline void timer_init(void);
// start time measurement
inline void timer_start(void);
// stop time measurement, return ticks
inline uint32_t timer_stop(void);
// get timer ticks
inline uint32_t timer_ticks(void);
// This module uses TIMER1 to keep track of time
#include "timer_1.h"
#include <avr/interrupt.h>
uint32_t overflow_count;
#define TIMER_MASK (1<<CS10)
inline void timer_init(void) {
// enable overflow interrupt
TIMSK1 |= (1<<TOIE1);
}
inline void timer_start(void) {
//disable interrupts globally
cli();
//clear out timer counting register
TCNT1 = 0;
//clear overflow count
overflow_count = 0;
// set up clock source
// we have a 16MHz Clock
// and a 16 Bit timer
// Use a prescaler of 256 -> 16/256 = 62.5kHz
TCCR1B |= TIMER_MASK;
//enable interrupts
sei();
}
inline uint32_t timer_ticks(void) {
return TCNT1 ^ (overflow_count << 16);
}
inline uint32_t timer_stop(void) {
// stop timer clock
TCCR1B &= ~(TIMER_MASK);
return timer_ticks();
}
ISR(TIMER1_OVF_vect) {
overflow_count++;
}
#include "timer_1.h"
#include "pinchange.h"
#include <avr/io.h>
int main(void) {
//init pin change interrupt
init_pc();
// enable interrupts
sei();
while(1) {
}
}
// all functions inline to save execution time
inline void init_pc(void);
// This module uses PIN CHANGE INTERRUPT INT3
#include <avr/interrupt.h>
#include <avr/io.h>
#include "timer_1.h"
//initialize pin change interrupt and data directions
inline void init_pc(void) {
// enable/ setup output port
DDRA = 0xff; // all out
PORTA = 0x00; // all low
// enable input port
// enable interrupt
EICRA |= (1<<ISC30)|(1<<ISC31);
EIMSK |= (1<<INT3);
}
ISR(INT3_vect) {
//Set PORTA high
PORTA = 0xff;
//Disable for next run
PORTA = 0x00;
}
// all functions inline to save execution time
// initialize timer for time measurement
inline void timer_init(void);
// start time measurement
inline void timer_start(void);
// stop time measurement, return ticks
inline uint32_t timer_stop(void);
// get timer ticks
inline uint32_t timer_ticks(void);
// This module uses TIMER1 to keep track of time
#include "timer_1.h"
#include <avr/interrupt.h>
uint32_t overflow_count;
#define TIMER_MASK (1<<CS10)
inline void timer_init(void) {
// enable overflow interrupt
TIMSK1 |= (1<<TOIE1);
}
inline void timer_start(void) {
//disable interrupts globally
cli();
//clear out timer counting register
TCNT1 = 0;
//clear overflow count
overflow_count = 0;
// set up clock source
// we have a 16MHz Clock
// and a 16 Bit timer
// Use a prescaler of 256 -> 16/256 = 62.5kHz
TCCR1B |= TIMER_MASK;
//enable interrupts
sei();
}
inline uint32_t timer_ticks(void) {
return TCNT1 ^ (overflow_count << 16);
}
inline uint32_t timer_stop(void) {
// stop timer clock
TCCR1B &= ~(TIMER_MASK);
return timer_ticks();
}
ISR(TIMER1_OVF_vect) {
overflow_count++;
}
#include "timer_1.h"
#include "pinchange.h"
#include <avr/io.h>
int main(void) {
Serial.begin(9600);
timer_init();
init_pc();
// enable interrupts
sei();
timer_start();
PORTA = 0xff; // set high
// timer will be stopped in pc interrupt
while(1) {
}
}
// all functions inline to save execution time
inline void init_pc(void);
// This module uses PIN CHANGE INTERRUPT INT3
#include <avr/interrupt.h>
#include <avr/io.h>
#include "timer_1.h"
//initialize pin change interrupt and data directions
inline void init_pc(void) {
// enable/ setup output port
DDRA = 0xff; // all out
PORTA = 0x00; // all low
// enable input port
// enable interrupt
EICRA |= (1<<ISC30)|(1<<ISC31);
EIMSK |= (1<<INT3);
}
ISR(INT3_vect) {
Serial.println(timer_stop());
}
// all functions inline to save execution time
// initialize timer for time measurement
inline void timer_init(void);
// start time measurement
inline void timer_start(void);
// stop time measurement, return ticks
inline uint32_t timer_stop(void);
// get timer ticks
inline uint32_t timer_ticks(void);
// This module uses TIMER1 to keep track of time
#include "timer_1.h"
#include <avr/interrupt.h>
uint32_t overflow_count;
#define TIMER_MASK (1<<CS10)
inline void timer_init(void) {
// enable overflow interrupt
TIMSK1 |= (1<<TOIE1);
}
inline void timer_start(void) {
//disable interrupts globally
cli();
//clear out timer counting register
TCNT1 = 0;
//clear overflow count
overflow_count = 0;
// set up clock source
// we have a 16MHz Clock
// and a 16 Bit timer
// Use a prescaler of 256 -> 16/256 = 62.5kHz
TCCR1B |= TIMER_MASK;
//enable interrupts
sei();
}
inline uint32_t timer_ticks(void) {
return TCNT1 ^ (overflow_count << 16);
}
inline uint32_t timer_stop(void) {
// stop timer clock
TCCR1B &= ~(TIMER_MASK);
return timer_ticks();
}
ISR(TIMER1_OVF_vect) {
overflow_count++;
}
...@@ -7,28 +7,27 @@ includes ...@@ -7,28 +7,27 @@ includes
variables variables
{ {
message 0x01 sendCAN; message 0x01 sendCAN;
int64 data1;
int64 data2;
int64 id1;
int64 id2;
int count = 0, errcount=0, rcount = 0; int count = 0, errcount=0, rcount = 0;
char outbuf[20]; char outbuf[20];
msTimer t; msTimer t;
} }
// send a can frame with random payload
void sendCAN_f() { void sendCAN_f() {
sendCAN.dlc = 1; sendCAN.dlc = 1;
sendCAN.byte(0) = random(255); sendCAN.byte(0) = random(255);
output(sendCAN); output(sendCAN);
setTimer(t, 10); setTimer(t, 10); // call timer to send the next one
} }
// if necessary, send a frame
on timer t { on timer t {
count++; count++;
if (count < 1024) if (count < 1024)
sendCAN_f(); sendCAN_f();
if (count == 1024) { if (count == 1024) {
// Measurement done, look at CANoes Error Trace to see how many errors occured
write("done, check trace analysis"); write("done, check trace analysis");
} }
} }
...@@ -37,13 +36,6 @@ on start { ...@@ -37,13 +36,6 @@ on start {
sendCAN_f(); sendCAN_f();
} }
on message CAN1.* {
data1 = this.byte(0);
id1 = this.id;
}
on message CAN2.* { on message CAN2.* {
data2 = this.byte(0);
id1 = this.id;
rcount++; rcount++;
} }
\ No newline at end of file
File deleted
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment