C C++ Java Data Structure Python JavaScript CSS Ajax PL/SQL PHP Puzzles C programs C++ programs Java programs

Home » C programming language

The 'Super Loop' Architecture for Embedded C programming

Learn: What is 'Super Loop' in Embedded C programming language? and how it is different from infinite loop?

In an Embedded C Application, there are set of statements which need to be executed forever. Because there are no operating system to return to or an embedded device is running until the power supply is removed.

So, to run set of statements, we need a loop that must not be finished, such kind of loops are known as 'Super Loop' or 'Infinite Loop'.

There is only one difference between 'Super Loop' and 'Infinite Loop': There may only one 'Super Loop' but the 'Infinite Loop' may be infinite (i.e. there is no limit of infinite loops in a program).

Consider the given example (Syntax)

int main()
{
	/*PINs configuration, interrupts, timers initialization etc*/
	initialize();
	
	/*Super/Infinite Loop*/
	while(1)
	{
		/*application's tasks*/
		...;
		anything();
		...;
	}
	
	/*program's execution will never reach here*/
	return 0;
}

In this example, we used while (1) as 'Super Loop', here while is a looping statement and 1 is a non zero value that will also true and programming will run forever.

Note: Since, program's execution will not reach to end of the program, hence return 0 will never be executed, we can also use void main() instead of int main() and then there is no need to use return 0.

initialize()

Here, initialize() is not a standard library function, we just wrote this function as an example. That mean at this section before ‘Super Loop’ you can place initialization related codes (like initialisations of interrupts, times, pins configuration, memory and other attached devices).

anything()

Here, anything() is also not a standard library function, at this section you can actual code that you want to execute again and again to keep running the device.

Benefits of 'Super Loop'

These are some of the benefits of using super loop in an Embedded Application.

  • 'Super Loop' runs give statements within the scope forever.
  • It is very simple to use, edit, debug and understand.
  • Less or no dependencies on the hardware.








COMMENTS