Counter Design in Contiki NG OS
$] make TARGET=native
Step 1 - Files needed
myowncounter.h, myowncounter.c and ngcounter.c Makefile.
Inside the folder contiki-ng/examples/myowncounter
Step 2:
//myowncounter.h
#ifndef MYOWNCOUNTER_H
#define MYOWNCOUNTER_H
int next_round(int temp);
#endif
Step 3:
//myowncounter.c
#include "myowncounter.h"
int next_round(int temp)
{
if(temp>59)
temp=1;
else
temp++;
return temp;
}
Step 4:
//ngcounter.c
#include "contiki.h"
#include "sys/etimer.h"
#include "mycounter.h"
#include <stdio.h>
PROCESS(mycounter_process, "My Counter Process");
AUTOSTART_PROCESSES(&mycounter_process);
static struct etimer et;
static int count=0;
PROCESS_THREAD(mycounter_process,ev,data)
{
PROCESS_BEGIN();
while(1)
{
etimer_set(&et, CLOCK_SECOND*2);
PROCESS_WAIT_EVENT_UNTIL(etimer_Expired(&et));
count=next_round(count);
printf("Count Value : %d\n",count);
}
PROCESS_END();
}
Step 5: Makefile
#Makefile Content
CONTIKI_PROJECT = ngcounter
all: $(CONTIKI_PROJECT)
PROJECT_SOURCEFILES += myowncounter.c
CONTIKI = ../..
include $(CONTIKI)/Makefile.include
How to Execute
To run this, Open the Terminal and Go to
$] cd contiki-ng/examples/myowncounter
$] make TARGET=native
It will create a file called ngcounter.native file
$] ./ngcounter.native
You will get the Output Looks this this:
Complete Instructions are there in the Video.
Comments
Post a Comment