[En-Nut-Discussion] Using the Periodic Interval Timer on the Ethernut 5 without Nut/OS
Robin Leinauer
leinauer at hs-pforzheim.de
Mon Nov 29 13:59:42 CET 2021
Hello everyone,
I'm trying to use the Periodic Interval Timer on the Ethernut 5.0 F without Nut/OS.
I have set up the project according to the following guide: http://www.ethernut.de/de/hardware/enut3/noos.html.
This is my code:
//---------------------------------------------------------------------------------------------------------------------------------------
#include <toolchain.h>
#define MCK 90317000
#define LED_PIN 28
volatile unsigned int timer_ticks = 0;
void spurious_entry(void)__attribute__((naked));
void spurious_entry(void)
{
IRQ_ENTRY();
IRQ_EXIT();
}
void timer_tick(void)__attribute__((naked));
void timer_tick(void)
{
IRQ_ENTRY();
timer_ticks++;
inr(PIT_PIVR); // acknowledge timer interrupt
IRQ_EXIT();
}
void init_timer(void)
{
outr(PIT_MR, (MCK / (16 * 1000) - 1));
outr(AIC_IDCR, _BV(SYSC_ID)); // disable interrupt
outr(AIC_SVR(SYSC_ID), (unsigned int)timer_tick); // set interrupt handler
outr(AIC_SMR(SYSC_ID), AIC_SRCTYPE_INT_LEVEL_SENSITIVE); // define priority
outr(AIC_ICCR, _BV(SYSC_ID)); // clear interrupt
outr(PIT_MR, inr(PIT_MR) | PIT_PITEN | PIT_PITIEN); // enable timer and timer interrupt
outr(AIC_IECR, _BV(SYSC_ID)); // enable interrupt
inr(PIT_PIVR);
}
void init_led(unsigned int pin)
{
outr(PIOA_OER, _BV(pin));
outr(PIOA_PER, _BV(pin));
}
void led_on(unsigned int pin)
{
outr(PIOA_CODR, _BV(pin));
}
void led_off(unsigned int pin)
{
outr(PIOA_SODR, _BV(pin));
}
void NutInit(void)
{
outr(AIC_SPU, (unsigned int)spurious_entry);
outr(AIC_IDCR, 0xffffffff); // disable all interrupts
outr(AIC_ICCR, 0xffffffff); // clear all interrupts
init_timer();
init_led(LED_PIN);
for(;;)
{
led_on(LED_PIN);
if(timer_ticks > 0)break;
}
// is never reached
led_off(LED_PIN);
for(;;);
}
//---------------------------------------------------------------------------------------------------------------------------------------
Everything compiles without errors, but unfortunately the first for-loop never exited during execution, the led never turns off.
What am I doing wrong?
I'm using an Ethernut 5.0 F and loading the image via TFTP.
Thanks and best regards
Robin
More information about the En-Nut-Discussion
mailing list