Counter Design in Contiki NG Operating System

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:
Contiki NG
Contiki NG

The above code is working on a Mote As Well in Z1 Zolertia Motes as shown below.
Zolertia Z1
Zolertia Z1





Complete Instructions are there in the Video.


Comments

Popular posts from this blog

Installing ns3 in Ubuntu 22.04 | Complete Instructions

Installation of NS2 in Ubuntu 22.04 | NS2 Tutorial 2

How to Create Ubuntu 24.04 Bootable USB Using Rufus [Step-by-Step Guide]