Back to Getting Started

Back to Examples

Event Example

KoliadaES follows an event-driven based programming paradigm where a main loop triggers a call back to the event handler containing methods or subroutines for the Application Firmware. Events can be triggered by an interrupt request handlers via push button, or as a timer handler using TIMER. For more info on events and how they are setup refer here

Before you proceed with this tutorial, you must have the latest KoliadaESDK(TM) and KoliadaES environment setup. For more information on the setup check out Koliada Getting started. This example will run on any processor board that has UART serial communication and whereas this tutorial uses the PIEP CC2541, you can use any compatible processor board.

Fig. 1: TOP VIEW

Before working on this example, make sure you have set the latest KoliadaESDK(TM). For information on KoliadaESDK(TM) setup see here.

Note: After making sure the SDK is setup correctly, the BuildConfig needs be built & flashed only if you have changed any board configuration. You can find an example BoardConfig project here: KoliadaESDK(TM)/examples/BoardConfig.

In this particular example there are no I/O configuration changes, and we can move on to build and flash the TestEvent application.

You find the source for TestEvent here KoliadaESDK(TM)/examples/TestEvent.

Now build the project and hit 'Download to Target'.

You should see the following output on your serial terminal

Fig. 2: Output of Testevent Example

The output shows the TestEvent program being loaded which then the program exits out of the application and back to KoliadaES.

void TestEvent()
	{
	printf(">>%s\n", __func__);
 
	debug("testEvent: %p\n", testEvent);
	dump((PTR) testEvent, 16, 2);
 
	// create an event
	// the memory for an event is in user space
	// objectCreate initializes testEvent as a member of class EVENT
	objectCreate(testEvent);
 
	// trace the event
	objectTrace(testEvent, true);
 
	// print some data
	debug("%s ", objectType(testEvent));
	debug("%s ", objectName(testEvent));
	debug("is %u bytes\n", objectSize(testEvent) * __sizeof_word);
 
	// connect a handler to an event
	// the handler is the function that will be called whenever the event 'fires'
	// multiple handler capability per event is implementation specific
	OnEvent(testEvent, (HANDLER) testEventHandler);
 
	// post an event with some args
	// this causes to the event to 'fire' and passes the args to the event handler
	// the number of event args is implementation specific but is always at least 4 words
	PostEvent(testEvent, 42, 43, 44, 45);
 
	// wait for the event to 'fire'
	// events are handled 'asynchronously' in 'firing' order
	// some implementations may allow re-prioritizing handling order
//	WaitEvent(testEvent, 0);
	WaitEvent(ANY, 0);
 
	// WaitEvent can optionally return the args that were Posted via PostEvent above
	// WaitEvent can also wait for ANY_EVENT to fire (rather than a specific event)
	// Wait multple events (wait for an array of events) is implementation dependent
 
	// delete the event
	objectDelete(testEvent);
 
	// we're done
	// return a value to the monitor
	printf("<<%s\n", __func__);
	}

We can walkthrough TestEvent.c now.

The objectCreate(testEvent); creates a event under the name testEvent. On this event (OnEvent(testEvent, (HANDLER) testEventHandler);) the testEventHandler will be called. To get the size of the event that was created use ( objectSize(testEvent) * __sizeof_word). The event can be triggered automatically through the program data or manually in this case by using the (PostEvent(testEvent, 42, 43, 44, 45);).

DefineEvent(testEvent);
void testEventHandler(EVENT e, int arg0, int arg1, int arg2, int arg3)
	{
	// called each time the the event is 'posted'
	printf("%s(%p, %d, %d, %d, %d)\n", __FUNC__, e, arg0, arg1, arg2, arg3);
	}

The TestEventHandler is called every time the testEvent is posted and it prints out the eventhandler args that were passed through the postevent.

More Examples

More Boards

      Copyright © 2018-2019 Koliada, LLC
  • piep/examples/testevent.txt
  • Last modified: 2019/04/16 00:47
  • by venkat