cancel
Showing results for 
Search instead for 
Did you mean: 

a loop which iterates infinitely for x seconds - stm32mp157c-dk2

IYetk
Associate III

Hi,

In my M4 program within while loop, I have made a for loop which iterates infinitely for 0.75 seconds like this but didnt work at all. I used time.h for that.

Are we allowed to make this kind of loop within the while loop in M4 program ?

Do you have any idea why it didnt work ?

    clock_t begin;
    double time_spent;
    unsigned int i;
 
    begin = clock();
    for (i=0;1;i++)
     {
          /*do my staff */
          if (VirtUart0RxMsg) {
              Check_Delay(VirtUart0ChannelBuffRx, VirtUart0ChannelRxSize);
              VIRT_UART_Transmit(&huart0, VirtUart0ChannelBuffRx, VirtUart0ChannelRxSize);
               VirtUart0RxMsg = RESET;
          }
 
          time_spent = (double)(clock() - begin) / CLOCKS_PER_SEC;
          if (time_spent>=0.75)
              break;
          }
     }

1 ACCEPTED SOLUTION

Accepted Solutions
IYetk
Associate III

I used the contents of HAL_Delay() function to make a loop which iterates an amount of seconds.

This issue can be closed.

View solution in original post

6 REPLIES 6
PatrickF
ST Employee

Hello,

Maybe a basic SW issue, but I think you need to provide more details.

Do you try to debug it ? Do the loop hang on some function ? Is the loop exit too early ? Did you check the clock() value returned ?

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.
IYetk
Associate III

I will debug it and write you the details...

yakabmarci
Senior

how can something iterate infinitely for a finite amount of seconds?

You are right. There is a misunderstanding here.

I just mean "a loop which iterates an amount of seconds"

IYetk
Associate III

I used the contents of HAL_Delay() function to make a loop which iterates an amount of seconds.

This issue can be closed.

I used the contents of HAL_Delay() function to make a loop which iterates an amount of seconds.

This issue can be closed.