Author Topic: Problem with DMA timer and GCC  (Read 14918 times)

Offline akorud

  • Newbie
  • *
  • Posts: 31
    • View Profile
Problem with DMA timer and GCC
« on: October 17, 2008, 11:11:35 AM »
Hi, I'm stopped with strange problem - the following code:
Code: [Select]
static void test(void) {
fnDebugMsg("x\r\n");
}

static void node_schedule_write_timer(int delay) {
  DMA_TIMER_SETUP dma_timer_setup;       
  uMemset(&dma_timer_setup, 0, sizeof(dma_timer_setup));
  dma_timer_setup.int_type = DMA_TIMER_INTERRUPT;
  dma_timer_setup.int_handler = test;
  dma_timer_setup.channel = 1;                                         // DMA timer channel 1
  dma_timer_setup.int_priority = DMA_TIMER1_INTERRUPT_PRIORITY;        // define interrupt priority
  dma_timer_setup.mode = (DMA_TIMER_INTERNAL_CLOCK | DMA_TIMER_SINGLE_SHOT_INTERRUPT);
  dma_timer_setup.count_delay = DMA_TIMER_MS_DELAY(1, 1, 5000);
  fnConfigureInterrupt((void *)&dma_timer_setup);                      // enter interrupt for DMA timer test
}
Works fine compiled in CW but hangs on interrupt route exit in GCC. Interrupt route is executed (original interrupt routing is more complicated, I've shrink it for debug purposes). Hang is immediately after exit and the only way of recovery is watchdog reset.
Assembler code:
CW (works):
Code: [Select]
0000bbf8 <_test>:
    bbf8:       41f9 0001 522e  lea 1522e <_@527>,%a0
    bbfe:       4eb9 0000 5e80  jsr 5e80 <_fnDebugMsg>
    bc04:       4e75            rts
and GCC (hangs):
Code: [Select]
000116f8 <test>:
   116f8: 4e56 0000      linkw %fp,#0
   116fc: 4879 0001 8167 pea 18167 <dbm_to_mw_table+0x296>
   11702: 4eb9 0000 6e7c jsr 6e7c <fnDebugMsg>
   11708: 588f            addql #4,%sp
   1170a: 4e5e            unlk %fp
   1170c: 4e75            rts
Does anybody have an idea how can I go further with debugging it? The problem is more than strange because PIT timer and interrupt works fine at the same time.

Regards,
--
Andriy
« Last Edit: October 17, 2008, 11:36:30 AM by akorud »

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3239
    • View Profile
    • uTasker
Re: Problem with DMA timer and GCC
« Reply #1 on: October 17, 2008, 11:37:39 AM »
Hi Andriy

Please try the following.

In m5223x.c add a forward declaration for the main DMA time interrupt routines:

    #ifdef _GNU                                                          // GNU interrupt list
....
        #ifdef SUPPORT_DMA_TIMER                                         // {70}
            static void _dma_timer_int_0(void)  __attribute__((interrupt_handler));
            static void _dma_timer_int_1(void)  __attribute__((interrupt_handler));
            static void _dma_timer_int_2(void)  __attribute__((interrupt_handler));
            static void _dma_timer_int_3(void)  __attribute__((interrupt_handler));
        #endif
....
    #endif


GCC needs to have the routine declared as an interrupt in this manor (CW uses a different technique which does not require the forward declaration). I never tested with GCC and so this is my mistake - the compiler was not handling it as an interrupt but as a normal subroutine and this will fail.

Please confirm that this cures it for you (I have already modified the reference code but not tested).

Sorry! Regards.

Mark
« Last Edit: October 17, 2008, 02:49:18 PM by mark »

Offline akorud

  • Newbie
  • *
  • Posts: 31
    • View Profile
Re: Problem with DMA timer and GCC
« Reply #2 on: October 17, 2008, 12:09:21 PM »
Thanks!!! This is the solution. Now entire my project works fine with GCC.

regards,
--
Andriy