MRT: How to set up all 4 channels on LPC54608J512?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MRT: How to set up all 4 channels on LPC54608J512?

Jump to solution
3,894 Views
vladimirilyenko
Contributor III

Hi,

I wanted to use MRT on LPC54608J512 for building of 2 timers: 100ms and 2ms.

MRT works perfectly, but only when I use one channel: Channel 0.

But I cannot use more than one channel simultaneously - in SDK for LPCXpresso 54606 (v.2.3.0) I see only one channel - MRT0.

Neither in start-up file "startup_LPC54608.c" nor in Peripherals View I cannot see other 3 MRT channels (MRT1, MRT2, MRT3) - only Channel 0: MRT0.

P.S.

In the header "LPC54608.h" I see also only Channel 0:

...................................................................
/*!
* @}
*/ /* end of group MRT_Register_Masks */


/* MRT - Peripheral instance base addresses */
/** Peripheral MRT0 base address */
#define MRT0_BASE (0x4000D000u)
/** Peripheral MRT0 base pointer */
#define MRT0 ((MRT_Type *)MRT0_BASE)
/** Array initializer of MRT peripheral base addresses */
#define MRT_BASE_ADDRS { MRT0_BASE }
/** Array initializer of MRT peripheral base pointers */
#define MRT_BASE_PTRS { MRT0 }
/** Interrupt vectors for the MRT peripheral type */
#define MRT_IRQS { MRT0_IRQn }

/*!
* @}
*/ /* end of group MRT_Peripheral_Access_Layer */

......................................................

Labels (3)
1 Solution
3,285 Views
carstengroen
Senior Contributor II

Vladimir,

I'm using the MRT of the LPC546xx regularly. I have attached my helper module for that. Beware that I use Keil development system, so there might be small changes (weak implementation etc).

Hope this helps in some way.

Carsten.

MRT.C file

//=============================================================================
// MRT.c                                                           20171118 CHG
//
//=============================================================================
#include "System.h"
#include "fsl_mrt.h"
#include "mrt.h"

//------------------------------------------------------------------------------
// 
//------------------------------------------------------------------------------
__attribute__ ((weak)) void mrtChannel0(void) {
  ;//do nothing if user doesn't overload
}
__attribute__ ((weak)) void mrtChannel1(void) {
  ;//do nothing if user doesn't overload
}
__attribute__ ((weak)) void mrtChannel2(void) {
  ;//do nothing if user doesn't overload
}
__attribute__ ((weak)) void mrtChannel3(void) {
  ;//do nothing if user doesn't overload
}

//----------------------------------------------------------------------------
// MRT IRQ handler. 
//----------------------------------------------------------------------------
void MRT0_IRQHandler(void) {  
     if (MRT_GetStatusFlags(MRT0, kMRT_Channel_0)) {
          MRT_ClearStatusFlags(MRT0, kMRT_Channel_0, kMRT_TimerInterruptFlag);
          mrtChannel0();
     }
     if (MRT_GetStatusFlags(MRT0, kMRT_Channel_1)) {
          MRT_ClearStatusFlags(MRT0, kMRT_Channel_1, kMRT_TimerInterruptFlag);
          mrtChannel1();
     }
     if (MRT_GetStatusFlags(MRT0, kMRT_Channel_2)) {
          MRT_ClearStatusFlags(MRT0, kMRT_Channel_2, kMRT_TimerInterruptFlag);
          mrtChannel2();
     }
     if (MRT_GetStatusFlags(MRT0, kMRT_Channel_3)) {
          MRT_ClearStatusFlags(MRT0, kMRT_Channel_3, kMRT_TimerInterruptFlag);
          mrtChannel3();
     }
     
}

//----------------------------------------------------------------------------
// Arm and start the specified MRT timer channel with a specified timeout (in uSec)
// MRT IRQ will fire when time has elapsed
// If repeat is set to FALSE, timer will stop afterwards
// If set to TRUE, timer will repeat
//----------------------------------------------------------------------------
void startTimerMRT(int channel, int delay, int repeat) {

     switch (channel) {
          case 0: 
               MRT_ClearStatusFlags(MRT0, kMRT_Channel_0, kMRT_TimerInterruptFlag);
               MRT_SetupChannelMode(MRT0, kMRT_Channel_0, repeat?kMRT_RepeatMode:kMRT_OneShotMode);
               MRT_StartTimer(MRT0, kMRT_Channel_0, USEC_TO_COUNT(delay, CLOCK_GetFreq(kCLOCK_BusClk)));
               MRT_EnableInterrupts(MRT0, kMRT_Channel_0, kMRT_TimerInterruptEnable); 
               break;
          case 1: 
               MRT_ClearStatusFlags(MRT0, kMRT_Channel_1, kMRT_TimerInterruptFlag);
               MRT_SetupChannelMode(MRT0, kMRT_Channel_1, repeat?kMRT_RepeatMode:kMRT_OneShotMode);
               MRT_StartTimer(MRT0, kMRT_Channel_1, USEC_TO_COUNT(delay, CLOCK_GetFreq(kCLOCK_BusClk)));
               MRT_EnableInterrupts(MRT0, kMRT_Channel_1, kMRT_TimerInterruptEnable); 
               break;
          case 2: 
               MRT_ClearStatusFlags(MRT0, kMRT_Channel_2, kMRT_TimerInterruptFlag);
               MRT_SetupChannelMode(MRT0, kMRT_Channel_2, repeat?kMRT_RepeatMode:kMRT_OneShotMode);
               MRT_StartTimer(MRT0, kMRT_Channel_2, USEC_TO_COUNT(delay, CLOCK_GetFreq(kCLOCK_BusClk)));
               MRT_EnableInterrupts(MRT0, kMRT_Channel_2, kMRT_TimerInterruptEnable); 
               break;
          case 3: 
               MRT_ClearStatusFlags(MRT0, kMRT_Channel_3, kMRT_TimerInterruptFlag);
               MRT_SetupChannelMode(MRT0, kMRT_Channel_3, repeat?kMRT_RepeatMode:kMRT_OneShotMode);
               MRT_StartTimer(MRT0, kMRT_Channel_3, USEC_TO_COUNT(delay, CLOCK_GetFreq(kCLOCK_BusClk)));
               MRT_EnableInterrupts(MRT0, kMRT_Channel_3, kMRT_TimerInterruptEnable); 
               break;
     }
}


//-----------------------------------------------------------------------------
// 
//-----------------------------------------------------------------------------
void initMRT(void) {
    mrt_config_t mrtConfig;
    MRT_GetDefaultConfig(&mrtConfig);
    MRT_Init(MRT0, &mrtConfig);
    MRT_DisableInterrupts(MRT0, kMRT_Channel_0, kMRT_TimerInterruptEnable);
    MRT_DisableInterrupts(MRT0, kMRT_Channel_1, kMRT_TimerInterruptEnable);
    MRT_DisableInterrupts(MRT0, kMRT_Channel_2, kMRT_TimerInterruptEnable);
    MRT_DisableInterrupts(MRT0, kMRT_Channel_3, kMRT_TimerInterruptEnable);
    NVIC_EnableIRQ(MRT0_IRQn);
}
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

.

MRT.H file

//=============================================================================
// MRT.h                                                           20171118 CHG
//
//=============================================================================
// 
//-----------------------------------------------------------------------------
#ifndef MRT_H
#define MRT_H

//------------------------------------------------------------------------------
// These functions are called (in IRQ context) if MRT channel 0/1/2/3 fires
// Implement in user code
//------------------------------------------------------------------------------
void mrtChannel0(void);
void mrtChannel1(void);
void mrtChannel2(void);
void mrtChannel3(void);

//----------------------------------------------------------------------------
// Arm and start the specified MRT timer channel with a specified timeout (in uSec)
// MRT IRQ will fire when time has elapsed
// If repeat is set to FALSE, timer will stop afterwards
// If set to TRUE, timer will repeat
//----------------------------------------------------------------------------
void startTimerMRT(int channel, int delay, int repeat);

//-----------------------------------------------------------------------------
// 
//-----------------------------------------------------------------------------
void initMRT(void);
                                                                       
#endif
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

View solution in original post

8 Replies
3,286 Views
carstengroen
Senior Contributor II

Vladimir,

I'm using the MRT of the LPC546xx regularly. I have attached my helper module for that. Beware that I use Keil development system, so there might be small changes (weak implementation etc).

Hope this helps in some way.

Carsten.

MRT.C file

//=============================================================================
// MRT.c                                                           20171118 CHG
//
//=============================================================================
#include "System.h"
#include "fsl_mrt.h"
#include "mrt.h"

//------------------------------------------------------------------------------
// 
//------------------------------------------------------------------------------
__attribute__ ((weak)) void mrtChannel0(void) {
  ;//do nothing if user doesn't overload
}
__attribute__ ((weak)) void mrtChannel1(void) {
  ;//do nothing if user doesn't overload
}
__attribute__ ((weak)) void mrtChannel2(void) {
  ;//do nothing if user doesn't overload
}
__attribute__ ((weak)) void mrtChannel3(void) {
  ;//do nothing if user doesn't overload
}

//----------------------------------------------------------------------------
// MRT IRQ handler. 
//----------------------------------------------------------------------------
void MRT0_IRQHandler(void) {  
     if (MRT_GetStatusFlags(MRT0, kMRT_Channel_0)) {
          MRT_ClearStatusFlags(MRT0, kMRT_Channel_0, kMRT_TimerInterruptFlag);
          mrtChannel0();
     }
     if (MRT_GetStatusFlags(MRT0, kMRT_Channel_1)) {
          MRT_ClearStatusFlags(MRT0, kMRT_Channel_1, kMRT_TimerInterruptFlag);
          mrtChannel1();
     }
     if (MRT_GetStatusFlags(MRT0, kMRT_Channel_2)) {
          MRT_ClearStatusFlags(MRT0, kMRT_Channel_2, kMRT_TimerInterruptFlag);
          mrtChannel2();
     }
     if (MRT_GetStatusFlags(MRT0, kMRT_Channel_3)) {
          MRT_ClearStatusFlags(MRT0, kMRT_Channel_3, kMRT_TimerInterruptFlag);
          mrtChannel3();
     }
     
}

//----------------------------------------------------------------------------
// Arm and start the specified MRT timer channel with a specified timeout (in uSec)
// MRT IRQ will fire when time has elapsed
// If repeat is set to FALSE, timer will stop afterwards
// If set to TRUE, timer will repeat
//----------------------------------------------------------------------------
void startTimerMRT(int channel, int delay, int repeat) {

     switch (channel) {
          case 0: 
               MRT_ClearStatusFlags(MRT0, kMRT_Channel_0, kMRT_TimerInterruptFlag);
               MRT_SetupChannelMode(MRT0, kMRT_Channel_0, repeat?kMRT_RepeatMode:kMRT_OneShotMode);
               MRT_StartTimer(MRT0, kMRT_Channel_0, USEC_TO_COUNT(delay, CLOCK_GetFreq(kCLOCK_BusClk)));
               MRT_EnableInterrupts(MRT0, kMRT_Channel_0, kMRT_TimerInterruptEnable); 
               break;
          case 1: 
               MRT_ClearStatusFlags(MRT0, kMRT_Channel_1, kMRT_TimerInterruptFlag);
               MRT_SetupChannelMode(MRT0, kMRT_Channel_1, repeat?kMRT_RepeatMode:kMRT_OneShotMode);
               MRT_StartTimer(MRT0, kMRT_Channel_1, USEC_TO_COUNT(delay, CLOCK_GetFreq(kCLOCK_BusClk)));
               MRT_EnableInterrupts(MRT0, kMRT_Channel_1, kMRT_TimerInterruptEnable); 
               break;
          case 2: 
               MRT_ClearStatusFlags(MRT0, kMRT_Channel_2, kMRT_TimerInterruptFlag);
               MRT_SetupChannelMode(MRT0, kMRT_Channel_2, repeat?kMRT_RepeatMode:kMRT_OneShotMode);
               MRT_StartTimer(MRT0, kMRT_Channel_2, USEC_TO_COUNT(delay, CLOCK_GetFreq(kCLOCK_BusClk)));
               MRT_EnableInterrupts(MRT0, kMRT_Channel_2, kMRT_TimerInterruptEnable); 
               break;
          case 3: 
               MRT_ClearStatusFlags(MRT0, kMRT_Channel_3, kMRT_TimerInterruptFlag);
               MRT_SetupChannelMode(MRT0, kMRT_Channel_3, repeat?kMRT_RepeatMode:kMRT_OneShotMode);
               MRT_StartTimer(MRT0, kMRT_Channel_3, USEC_TO_COUNT(delay, CLOCK_GetFreq(kCLOCK_BusClk)));
               MRT_EnableInterrupts(MRT0, kMRT_Channel_3, kMRT_TimerInterruptEnable); 
               break;
     }
}


//-----------------------------------------------------------------------------
// 
//-----------------------------------------------------------------------------
void initMRT(void) {
    mrt_config_t mrtConfig;
    MRT_GetDefaultConfig(&mrtConfig);
    MRT_Init(MRT0, &mrtConfig);
    MRT_DisableInterrupts(MRT0, kMRT_Channel_0, kMRT_TimerInterruptEnable);
    MRT_DisableInterrupts(MRT0, kMRT_Channel_1, kMRT_TimerInterruptEnable);
    MRT_DisableInterrupts(MRT0, kMRT_Channel_2, kMRT_TimerInterruptEnable);
    MRT_DisableInterrupts(MRT0, kMRT_Channel_3, kMRT_TimerInterruptEnable);
    NVIC_EnableIRQ(MRT0_IRQn);
}
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

.

MRT.H file

//=============================================================================
// MRT.h                                                           20171118 CHG
//
//=============================================================================
// 
//-----------------------------------------------------------------------------
#ifndef MRT_H
#define MRT_H

//------------------------------------------------------------------------------
// These functions are called (in IRQ context) if MRT channel 0/1/2/3 fires
// Implement in user code
//------------------------------------------------------------------------------
void mrtChannel0(void);
void mrtChannel1(void);
void mrtChannel2(void);
void mrtChannel3(void);

//----------------------------------------------------------------------------
// Arm and start the specified MRT timer channel with a specified timeout (in uSec)
// MRT IRQ will fire when time has elapsed
// If repeat is set to FALSE, timer will stop afterwards
// If set to TRUE, timer will repeat
//----------------------------------------------------------------------------
void startTimerMRT(int channel, int delay, int repeat);

//-----------------------------------------------------------------------------
// 
//-----------------------------------------------------------------------------
void initMRT(void);
                                                                       
#endif
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
3,284 Views
vladimirilyenko
Contributor III

Hi Carsten,

thank you for your hint, but nevertheless from my two timers (100ms and 2ms) the shortest one makes the second one useless, because there is no separation between the two channels for MRT interrupt - I have only 1 interrupt and it comes every 2 ms.

 

I've made two software timers: 1 sec. from 100ms (MRT channel 0) and  4 sec. from 2ms (timer on MRT channel 1). If I run for 1 minute  the appended here code , timer0_count (1 sec. timer) counts for 3000 (it works as 20ms timer instead of 1 sec.), and timer1_count (4 sec.timer) counts for 15 - it means that both MRT channels fire every 2 milliseconds - their interrupts are not being distinguished.

If I switch the 2ms timer off, the channel with 100ms timer works as it should – its interrupt fires every 100ms.

If I use two channels - they are both sitting on one interrupt.

What am I doing wrong?

Regards,

0 Kudos
Reply
3,284 Views
vladimirilyenko
Contributor III

Carsten,

thank you very much, now thing are getting much clearer! I'll try it!

3,284 Views
jeremyzhou
NXP Employee
NXP Employee

Hi  Vladimir Ilyenko

Thank you for your interest in NXP Semiconductor products and 
the opportunity to serve you.

You can configure the below parameter to setup the channel of MRT.

/*! @brief List of MRT channels */
typedef enum _mrt_chnl
{
kMRT_Channel_0 = 0U, /*!< MRT channel number 0*/
kMRT_Channel_1, /*!< MRT channel number 1 */
kMRT_Channel_2, /*!< MRT channel number 2 */
kMRT_Channel_3 /*!< MRT channel number 3 */
} mrt_chnl_t;

Have a great day,
TIC

 

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply
3,285 Views
vladimirilyenko
Contributor III

Hi, jeremyzhou

Thank you for your answer, but it doesn't relate to my question.

The enumeration of the channel names that you put here are already included in the driver header "fsl_mrt.h" and already linked to the project.

The problem is not with the names of channels. They are already defined.

The problem is that the channels other than "kMRT_Channel_0" cannot be handled:

there is only interrupt handle for Channel_0 in  file "startup_LPC54608.c" in the SDK:

WEAK void MRT0_IRQHandler(void)
      { MRT0_DriverIRQHandler();
      }

Also I do not see any channels other than Channel_0 in "Peripherals View" (please see the attached pictures in the first post).

P.S.

In the MRT example "lpcxpresso54608_driver_examples_mrt_mrt_example" from SDK, when I try to use the MRT Channel 1: 

/*******************************************************************************

 * Code

 ******************************************************************************/

void MRT0_IRQHandler(void)

{

    /* Clear interrupt flag.*/

    MRT_ClearStatusFlags(MRT0, kMRT_Channel_0, kMRT_TimerInterruptFlag);

   

    mrtIsrFlag0 = true;

   

    /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping

      exception return operation might vector to incorrect interrupt */

#if defined __CORTEX_M && (__CORTEX_M == 4U)

    __DSB();

#endif

}

void MRT1_IRQHandler(void)

{

    /* Clear interrupt flag.*/

    MRT_ClearStatusFlags(MRT1, kMRT_Channel_1, kMRT_TimerInterruptFlag);

 

    mrtIsrFlag1 = true;                            

 

    /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping

      exception return operation might vector to incorrect interrupt */

#if defined __CORTEX_M && (__CORTEX_M == 4U)

    __DSB();

#endif

}

I get the error:

"MRT1 undeclared"

Because only MRT0 has definition in the equate file “LPC54608.h”:

/* MRT - Peripheral instance base addresses */

/** Peripheral MRT0 base address */

#define MRT0_BASE                                (0x4000D000u)

/** Peripheral MRT0 base pointer */

#define MRT0                                     ((MRT_Type *)MRT0_BASE)

/** Array initializer of MRT peripheral base addresses */

#define MRT_BASE_ADDRS                           { MRT0_BASE }

/** Array initializer of MRT peripheral base pointers */

#define MRT_BASE_PTRS                            { MRT0 }

/** Interrupt vectors for the MRT peripheral type */

#define MRT_IRQS                                 { MRT0_IRQn }

Should I edit “LPC54608.h”?

 

 

 

0 Kudos
Reply
3,285 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Vladimir Ilyenko,

Let me clear it.

In the SDK library, the MRT0 stand for the MRT module, however the set of kMRT_Channel_n stand for respective MRT channels which is illustrated as MRT0~3.

In addition. the complete MRT module share one vector interrupt slot in the NVIC.

Hope this is clear.

Have a great day,
TIC

 

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply
3,285 Views
vladimirilyenko
Contributor III

Hi jeremyzhou,

In addition. the complete MRT module share one vector interrupt slot in the NVIC.

Then I do not completely understand this statement from manual:

7.19.5 Multi-Rate Timer (MRT)
The Multi-Rate Timer (MRT) provides a repetitive interrupt timer with four channels. Each
channel can be programmed with an independent time interval, and each channel
operates independently from the other channels.

How these 4 channels can be independent from each other if they all share the same vector interrupt?

If I need e.g. to build 2 timers using MRT and set up one channel on 100ms and another one on 2ms, if they use the same (and only) interrupt vector, I will get interrupt from MRT every 2ms. In this case 100ms Timer will be just lost and useless.

What is the sense then in 4 channels of MRT is more than one channel cannot be used simultaneously?

0 Kudos
Reply
3,285 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Vladimir Ilyenko,

Thanks for your reply.

Let me explain it.

To figure the interrupt request, you can monitor all channel interrupt flags in the global interrupt register or checking the INTFLAG bit in respective Status registers.

Hope it helps.

Have a great day,
TIC

 

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply