Delay function using OSIF

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

Delay function using OSIF

Jump to solution
10,902 Views
semiconductor_user
Contributor III

IDE : s32ds for platform v3.5

MCU : s32k324 

here i want to use delay function by for 100ms for that i want to use OsIf but in configuration side i'm face issue, that screenshort i atteched below

please share example code for configuration osif and use delay function

or step for this procedure from configuration and which API will need.

please share in details so that i can easily understand and it will benificial for other more developers

0 Kudos
Reply
1 Solution
10,822 Views
Julián_AragónM
NXP TechSupport
NXP TechSupport

Hi @semiconductor_user

You can implement the following code changes in a Siul2_Port_Ip_Example_S32K344 to blink a led:

#define TIME_TYPE OSIF_COUNTER_SYSTEM

void OsIfDelay(uint32 timeoutMs);
void OsIfDelay(uint32 timeoutMs)
{
	uint32 curTime = 0u;
	uint32 endTime = 0u;
	uint32 timeoutCnt = 0u;

	curTime = OsIf_GetCounter(OSIF_COUNTER_SYSTEM);
	timeoutCnt = OsIf_MicrosToTicks(timeoutMs * 1000u, TIME_TYPE);

	while(1)
	{
		endTime += OsIf_GetElapsed(&curTime, TIME_TYPE);

		if(timeoutCnt <= endTime)
		{
			break;
		}
	}
}


/**
* @brief        Main function of the example
* @details      Initialize the used drivers and uses the OsIf
*               drivers to toggle a LED.
*/
int main(void)
{
	Siul2_Port_Ip_Init(NUM_OF_CONFIGURED_PINS_PortContainer_0_BOARD_InitPeripherals, g_pin_mux_InitConfigArr_PortContainer_0_BOARD_InitPeripherals);
	OsIf_Init(NULL);

	Siul2_Dio_Ip_WritePin(LED_Q172_PORT, LED_Q172_PIN, 1U);

	while(1)
	{
		OsIfDelay(1000);
		Siul2_Dio_Ip_TogglePins(LED_Q172_PORT, 1 << LED_Q172_PIN);
	}
}

Best regards,
Julián

View solution in original post

4 Replies
10,872 Views
Julián_AragónM
NXP TechSupport
NXP TechSupport

Hi @semiconductor_user,

In order to use the TimerClockRef, you need to add the Mcu module in the MCAL layer, which will generate the clock reference point:

Julin_AragnM_0-1725383376858.png

If you have no need for the MCAL layer, you can also add the "TimerClockFreq" input:

Julin_AragnM_0-1725387751368.png

The default frequency for the system timer is 48MHz. You can use the "OsIf_Init(NULL)" function to initialize the module, and the APIs included in "OsIf_Timer.c" to create a delay function: 

  • OsIf_GetCounter
  • OsIf_MicrosToTicks
  • OsIf_GetElapsed

Best regards,
Julián

0 Kudos
Reply
10,854 Views
semiconductor_user
Contributor III

thank you @Julián_AragónM Julián_AragónM for reasponse

i done configuration for that i added Mcu module in MCAL Layer so got McuClockRefpoint.

now as you say using this API i can write delay function 

  • OsIf_GetCounter
  • OsIf_MicrosToTicks
  • OsIf_GetElapsed 

i'm trying to write function but not getting clearity. do you have example code or screenshort then please share here otherwise guide me 

0 Kudos
Reply
10,823 Views
Julián_AragónM
NXP TechSupport
NXP TechSupport

Hi @semiconductor_user

You can implement the following code changes in a Siul2_Port_Ip_Example_S32K344 to blink a led:

#define TIME_TYPE OSIF_COUNTER_SYSTEM

void OsIfDelay(uint32 timeoutMs);
void OsIfDelay(uint32 timeoutMs)
{
	uint32 curTime = 0u;
	uint32 endTime = 0u;
	uint32 timeoutCnt = 0u;

	curTime = OsIf_GetCounter(OSIF_COUNTER_SYSTEM);
	timeoutCnt = OsIf_MicrosToTicks(timeoutMs * 1000u, TIME_TYPE);

	while(1)
	{
		endTime += OsIf_GetElapsed(&curTime, TIME_TYPE);

		if(timeoutCnt <= endTime)
		{
			break;
		}
	}
}


/**
* @brief        Main function of the example
* @details      Initialize the used drivers and uses the OsIf
*               drivers to toggle a LED.
*/
int main(void)
{
	Siul2_Port_Ip_Init(NUM_OF_CONFIGURED_PINS_PortContainer_0_BOARD_InitPeripherals, g_pin_mux_InitConfigArr_PortContainer_0_BOARD_InitPeripherals);
	OsIf_Init(NULL);

	Siul2_Dio_Ip_WritePin(LED_Q172_PORT, LED_Q172_PIN, 1U);

	while(1)
	{
		OsIfDelay(1000);
		Siul2_Dio_Ip_TogglePins(LED_Q172_PORT, 1 << LED_Q172_PIN);
	}
}

Best regards,
Julián

10,797 Views
semiconductor_user
Contributor III

thank you so much for support. it is working perfact.

and i attached document below, which can help to community.

0 Kudos
Reply