Delay function using OSIF

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Delay function using OSIF

跳至解决方案
10,893 次查看
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 项奖励
回复
1 解答
10,813 次查看
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

在原帖中查看解决方案

4 回复数
10,863 次查看
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 项奖励
回复
10,845 次查看
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 项奖励
回复
10,814 次查看
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,788 次查看
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 项奖励
回复