OsIf S32K312 Issue

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

OsIf S32K312 Issue

1,043 Views
mononendu
Contributor I

Hi!

I'm using S32K312 for a project and I want to create a timer using the sysTick. I have chosen the configuration like the following:

Use System Timer - checked

Operating System Type - Baremetal

Core Frequency - 48000000


Now I'm using the OsIf_Timer_System_Internal_GetCounter() to get the systemTick for next processing of timer.

My timer code module file looks like this:

*! \file
 *
 *  \brief SW Timer implementation
 *
 *  \author
 *
 *   This module makes use of a System Tick in millisconds and provides
 *   an abstraction for SW timers
 *
 */
 
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include "OsIf.h"
#include "timer.h"
#include "rfal_platform.h"
 
/*
******************************************************************************
* LOCAL DEFINES
******************************************************************************
*/
 
/*
******************************************************************************
* LOCAL VARIABLES
******************************************************************************
*/
 
static uint32_t timerStopwatchTick;
 
/*
******************************************************************************
* GLOBAL FUNCTIONS
******************************************************************************
*/
 
 
/*******************************************************************************/
//uint32_t timerCalculateTimer( uint16_t time )
uint32_t timerCalculateTimer( uint32_t time )
{
//uint32_t timeValue = OsIf_MicrosToTicks(((uint32_t)time*1000),OSIF_COUNTER_SYSTEM);
uint32_t timeValue = (uint32_t)time;
return ( platformGetSysTick() + timeValue);
}
 
 
/*******************************************************************************/
bool timerIsExpired( uint32_t timer )//100 //300
{
  uint32_t uDiff;
  int32_t sDiff;
  
  uDiff = ((timer - platformGetSysTick()));   /* Calculate the diff between the timers */
  sDiff = uDiff;                            /* Convert the diff to a signed var      */
  /* Having done this has two side effects: 
   * 1) all differences smaller than -(2^31) ms (~25d) will become positive
   *    Signaling not expired: acceptable!
   * 2) Time roll-over case will be handled correctly: super!
   */
  
  /* Check if the given timer has expired already */
  if( sDiff < 0 )
  {
    return true;
  }
  
  return false;
}
 
 
/*******************************************************************************/
//void timerDelay( uint16_t tOut )
void timerDelay( uint32_t tOut )
{
  uint32_t t;
  
  /* Calculate the timer and wait blocking until is running */
  t = timerCalculateTimer( tOut );
  while( timerIsRunning(t) ); //#define timerIsRunning(t)  !( timerIsExpired( uint32_t timer )) 
}
 
 
/*******************************************************************************/
void timerStopwatchStart( void )
{
  timerStopwatchTick = platformGetSysTick();
}
 
 
/*******************************************************************************/
uint32_t timerStopwatchMeasure( void )
{
  return (uint32_t)(platformGetSysTick() - timerStopwatchTick);
}


This code file is a part of ST NFC sw drop, and we have to adapt to the NXP environment. 
platformGetSysTick() macro is there for OsIf_Timer_System_Internal_GetCounter(). 

I was trying to use the timerDelay() to get 1 ms delay, but whatever I do provide as an argument to this function, I'm always getting 100ms as a delay. I'm trying to get LED_High and LED_Low and trap the change in CRO. 

RTD: AUTOSAR_2.0.0
SDK: PlatformSDK_S32K3_2022_03_S32K312_M7


I need some suggestion, how to tackle this issue.

0 Kudos
Reply
3 Replies

979 Views
mononendu
Contributor I

Hi! Thanks for the response. We are trying to use the OsIf_Timer_System_Internal_GetCounter() to get the base reference to our timer functions. We have selected the system frequency as 48MHz from the osif_1 Drivers layer.

mononendu_0-1707727699634.png


But the counters are so high that a direct utilization of this is not giving me any output. I used one multiplier for the input argument value, (time = time*160000), and I'm able to reach to 100ms without any noise in the signal that's trapped in CRO.

I had to update this timerIsExpired function to achieve this, it's updated as per the following.

bool timerIsExpired( timer_t timer )
{
volatile timer_t test = 0;
// Get the current system tick value
timer_t tick_val = platformGetSysTick();
 
// Calculate the difference between the timer and the tick value
volatile timer_t diff = (tick_val >= timer) ? (tick_val - timer) : (TIMER_MAX_VALUE - timer + tick_val + 1);
 
test = (diff <= (TIMER_MAX_VALUE / 2));
// Check if the difference exceeds the threshold for expiration
return test;
}


This is the only modification, rest are same as mentioned earlier. I want to figure out how to utilize the OsIf_Timer_System_Internal_GetCounter(), without any further changes to the code. 

0 Kudos
Reply

971 Views
VaneB
NXP TechSupport
NXP TechSupport

Hi @mononendu 

The easiest option I can see is to create delay loop(s) even if the count value is very high. Or PIT (Periodic Interrupt Timer) can be used.

There is this RTD example: Pit_Ip_Example.

0 Kudos
Reply

1,021 Views
VaneB
NXP TechSupport
NXP TechSupport

Hi @mononendu 

You mentioned that the code is an adaptation of the ST NFC software. If possible, could you please provide more details about the functions related to the "timerDelay" function? This is to understand the functionality you are looking to implement. 

 

B.R.

VaneB

0 Kudos
Reply