[En-Nut-Discussion] Using the Periodic Interval Timer on the Ethernut 5 without Nut/OS
Dusan Ferbas
dferbas at solarmonitor.cz
Mon Nov 29 15:59:52 CET 2021
Hi Robin,
I am not familiar with SAM9 platform and I do not know your conf file.
I suggest to compile a simple app example with Ethernut50f.conf and
compare map file to your project map file.
Mainly if routines from nut/arch/arm/board/ethernut5.c are present,
which confirms a correct LD script was applied.
Dusan Ferbas
Solar Monitor s.r.o. | Žižkova 562 | 511 01 Turnov | Czech Republic
Tel.: +420 481 313 661 | Mobile: +420 603 147 723
On 29.11.2021 13:59, Robin Leinauer wrote:
> 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
> _______________________________________________
> http://lists.egnite.de/mailman/listinfo/en-nut-discussion
More information about the En-Nut-Discussion
mailing list