You are on page 1of 30

iSense Ethernet Gateway User Guide

iSense Ethernet Gateway User Guide

Document history

Version Date Changes

1.0 30.08.2011 Initial version

1.1 04.05.2012 Minor corrections

coalesenses 2 / 30
research to innovate
iSense Ethernet Gateway User Guide

Contents

1. General Description ........................................................................................................................ 6


1.1. Handling and Security Instructions .......................................................................................... 7
2. Programming of the Ethernet Gateway .......................................................................................... 8
3. Net10Module API Description ....................................................................................................... 8
3.1. Extended Constructor............................................................................................................... 8
3.2. Standard Constructor ............................................................................................................... 9
3.3. set_led ...................................................................................................................................... 9
3.4. set_button_handler ................................................................................................................. 10
3.5. ethernet................................................................................................................................... 10
3.6. sd_card ................................................................................................................................... 10
4. SDCard API Description .............................................................................................................. 11
4.1. Constructor............................................................................................................................. 11
4.2. is_ready .................................................................................................................................. 11
4.3. is_write_protected .................................................................................................................. 11
4.4. get_number_of_blocks ........................................................................................................... 12
4.5. access ..................................................................................................................................... 12
4.6. access_block .......................................................................................................................... 12
4.7. read......................................................................................................................................... 13
4.8. read_block .............................................................................................................................. 13
4.9. write ....................................................................................................................................... 14
4.10. write_block ....................................................................................................................... 14
5. Enc28J60 API Description ........................................................................................................... 15
5.1. constructor.............................................................................................................................. 15
5.2. send ........................................................................................................................................ 16
5.3. enable ..................................................................................................................................... 16
5.4. enable ..................................................................................................................................... 16
5.5. set_receiver ............................................................................................................................ 16
5.6. address.................................................................................................................................... 17
5.7. max_packet_size .................................................................................................................... 17
6. Ethernet Gateway Module Demo Application.............................................................................. 17
6.1. Obtaining the Ethernet Gateway Module Demo Application ................................................ 17
6.2. Compiling the Ethernet Gateway Demo Application ............................................................ 18
6.2.1. Using Eclipse ............................................................................................................... 18
6.2.2. Using the Command Line ............................................................................................ 21

coalesenses 3 / 30
research to innovate
iSense Ethernet Gateway User Guide

6.3. Flashing the Ethernet Gateway Module Demo Application .................................................. 22


6.4. Ethernet Gateway Module Demo Application functionality.................................................. 22
7. References .................................................................................................................................... 29

coalesenses 4 / 30
research to innovate
iSense Ethernet Gateway User Guide

About this User Guide


In this user guide,
• files and folders are represented in the Arial typeface,
• code fragments, function names etc. are represented in the Courier New typeface,
• GUI elements such as button descriptions etc. are represented in “quotation marks”,
• titles of other documents are presented in Italic type.
This manual assumes that the reader has successfully installed the iSense development environment,
and obtained the iSense standard firmware. For further information on these steps, consult the
Development Environment Setup User Guide [1].
In addition, it is assumed that the user is familiar with the use of iShell. For further information on
iShell, consult the iShell User Guide [3].
For further information on iSense firmware programming concepts and on application development, it
is recommended to read the Writing iSense Applications User Guide [4].

coalesenses 5 / 30
research to innovate
iSense Ethernet Gateway User Guide

1. General Description
The iSense Ethernet Gateway is based on a Jennic JN5148 wireless microcontroller [5], a chip that
combines the controller and the wireless communication transceiver in a single housing.
The controller provides 32 bit RISC computation and runs at a software-scalable frequency between 4
and 32 MHz. It comprises 128kbytes of memory that are shared by program code and data. The
advantage of this choice is that memory consumption of program code and data can be traded.
Opposite to other controllers where the user is limited to a certain amount of data and code memory,
free choices that are only bounded by the sum of both become possible here.
The radio part complies with the IEEE 802.15.4 standard [6]. It achieves a data rate of 250 kBit/s,
provides hardware AES encryption and is ZigBee-ready. Besides IEEE 802.15.4 standard compliant
operation, the radio transceiver provides two additional modes of operation, offering increased data
rates of 500 kBit/s and 667 kBit/s. It reaches a receive sensitivity of -98dBm (at 250 kBit/s) and a
transmit power of up to 10 dBm.
Apart from that the Ethernet Gateway is equipped with an IEEE 802.3i complaint 10BaseT 10Mbit
full-duplex interface which allows to build a gateway between IEEE 802.15.4 wireless sensor
networks and Ethernet based LAN infrastructures. Another benefit is the microSD slot which to allows
to read and write data to a microSD card.
To enable long, but still synchronous sleep and wakeup cycles, the module is equipped with a high
precision clock (error < 3ppm). The Core Module also features software-switchable LEDs for
debugging purposes.
There is a 34 pin connector (X1) on both sides of the module where other modules can be attached to
the Core Module. It can supply up to 500mA to other modules.
The controller can be programmed in various ways. While over-the-air programming (OTAP) is
possible and considered to be the standard procedure, the program can also be transferred via the
gateway module, or using a special programming adapter that mates with corresponding pads on the
module.
While by default powered by a wall mount adapter directly connected to the gateway, it can also be
supplied with power over the Ethernet cable by using an optional power injector, enabled by setting
the jumpers J1/J2.

Figure 1: Mechanical Information

coalesenses 6 / 30
research to innovate
iSense Ethernet Gateway User Guide

X1 System connector for plugging an iSense Core Module or other iSense modules

ETH RJ45 Ethernet Connector

P Power Connector

SD microSD slot

B1 User Button

J1/J2 Power Injector Jumper

1.1. Handling and Security Instructions


Note that all iSense Modules are sensitive to electro-static discharge. Appropriate protection measures
have to be taken.
If not protected by an appropriate housing, all iSense components must be protected from humidity,
mechanical impact, and short circuiting by contact with conductive materials.
Note that all cable plugs and headers are designed to be extremely compact, and are not intended for
frequent plugging and unplugging. Never pull the cables to remove the plugs from the corresponding
modules, always pull the plug itself. If required, use an appropriate tool (or the pulling cord if
available). Even though all plugs/headers are coded, be sure to pay attention to the proper orientation.
Never apply force. Never use cables if their insulation is damaged.
Note that iSense modules are not intended for hot-plugging, (dis-)connecting modules from or to other
modules in operation can result in a reset of the device and other undesired effects.
All delivered components are intended for use in research application. For using these components
within other application domains, consult coalesenses prior to use.
Coalesenses products are not intended for use in life support systems, appliances or systems where
malfunction of these products can reasonably be expected to result in personal injury, death or severe
property or environmental damage. Coalesenses customers using or selling these products for use in
such applications do so at their own risk and agree to fully indemnify coalesenses for any damages
resulting from such use.
Do not connect components or devices to any iSense component that are not manufactured or
distributed by coalesenses without prior consultation of coalesenses. Note that doing so regardless of
consultation will void the warranty and the declaration of CE conformity. Coalesenses customers
connecting third party devices do so at their own risk and agree to fully indemnify coalesenses for any
damages or injury resulting from such use.
Note that the SMA connector is sensitive to mechanical stress. Be sure not to apply forces to the
connector or a connected antenna. Protect the module from shock and vibration.

coalesenses 7 / 30
research to innovate
iSense Ethernet Gateway User Guide

2. Programming of the Ethernet Gateway


The Ethernet Gateway can currently be programmed in two ways. When having an already
programmed Ethernet Gateway it is likely that you are able to program the device wirelessly using
OTAP (Over The Air Programming). How to convenient program devices this way see [2]. The
second method uses the iSense Gateway Module 2 directly connected to the Ethernet Gateway.
Therefor you have to open the housing and connect the devices.

Figure 2: Ethernet Gateway with attached Gateway Module


The Result should look similar to Figure 2. In this configuration you can program the device according
to [3].

3. Net10Module API Description


The Net10Module class in the isense namespace contains all software functionality for operating
the Core Module-specific features, including
• switching the LEDs,
• handling of button events,
The NET10Module class is defined in src/isense/modules/ethernet_module/net10_module.h in
the iSense directory.
The iSense firmware is structured into a large number of software modules that can be (de-)activated
separately. The below API description for each function specifies the required modules that must be
activated to use the functions, and names both the web compilation module name as well as the
according code define. An asterisk (*) indicates that the respective module is activated in the iSense
standard firmware.
Required Modules:

NET10 module* #define ISENSE_ENABLE_NET10_MODULE

3.1. Extended Constructor

Net10Module::Net10Module( Os& os, uint64 mac_address, uint16 rx_length,

coalesenses 8 / 30
research to innovate
iSense Ethernet Gateway User Guide

bool full_duplex );

Description:
Extended constructor of the Net10 module, which allows to set the MAC-Address of the Ethernet
interface, the length of the receive buffer and, and whether or not the interface should operate in full
duplex mode. Instances of SDCard and Enc28J60 are created as well, when activated in the systems
configuration file isense/config.h.
Parameters:

os Reference to the operating system class

mac_address Desired link-layer address of the interface. Only the lower


48bits will be considered.

rx_length Desired length of the receive buffer

full_duplex Sets the interface to full duplex when set to true

3.2. Standard Constructor

Net10Module::Net10Module( Os &os );

Description:
Initializes the Net10Module class. By default, the LEDs are switched off. Instances of SDCard and
Enc28J60 are created as well, when activated in the systems configuration file isense/config.h.
Parameters:

os Reference to the operating system class Os

3.3. set_led

void Net10Module::set_led( uint8 led, bool on );

Description:
Switches on the modules LEDs (regardless of prior state).
Parameters:

led Number of LED to use. Use 0 to switch on LED1 and 1 to switch on LED2.

on Turns the LED on when set to true, turns the LED off when set to false

coalesenses 9 / 30
research to innovate
iSense Ethernet Gateway User Guide

3.4. set_button_handler

bool Net10Module::set_button_handler( ButtonHandler* button_handler );

Description:
Sets the ButtonHandler that will be called when the button B1 is pressed or released. The
ButtonHandler class can be found in isense/button_handler.h
Parameters:

button_handler Instance of the class ButtonHandler that should be called when the
button is pressed or released.

Returns:
true if the ButtonHandler could be registered, false elsewise.

3.5. ethernet

Enc28J60* Net10Module::ethernet( );

Description:
Returns the instance of the Enc28J60 Ethernet module, that was instantiated together with the
Net10Module
Returns:
Pointer to the Enc28J60 instance of the Net10Module instantiated by the constructor
Required modules:

Ethernet Module #define ISENSE_ENABLE_ETHERNET_MODULE

3.6. sd_card

SDCard* Net10Module::sd_card( );

Description:
Returns the instance of the SDCard module that was instantiated together with the Net10Module
Returns:
Pointer to the SDCard instance that was instantiated by the constructor of the Net10Module
Required modules:

Ethernet Module #define ISENSE_ENABLE_ETHERNET_SD_CARD_MODULE

coalesenses 10 / 30
research to innovate
iSense Ethernet Gateway User Guide

4. SDCard API Description


The Ethernet Gateway comes with an integrated microSD slot, which allows to read/write data from/to
a microSD card.
The SDCard class in the isense namespace contains all software functionality for operating the
SD Card-specific features, including
• writing data to a microSD card and,
• reading data from a microSD card
The SDCard class is defined in src/isense/modules/ethernet_module/SD_card.h in the iSense
directory.
Required Modules:

SD Card Module* #define ISENSE_ENABLE_ETHERNET_MODULE_SD_CARD

SPI* #define ISENSE_ENABLE_SPI

GPIO* #define ISENSE_ENABLE_GPIO

4.1. Constructor

SDCard::SDCard( OS& os );

Description:
Standard constructor. NOTE: An instance of SDCard is created when instantiating the
NET10Module. That instance can be obtained using the sd_card method, see 3.6.
Parameters:

os Reference to the current instance of the iSense operating system

4.2. is_ready

bool SDCard::is_ready( );

Description:
Returns if a fully initialized SD Card is in the SD card slot
Returns:
true if a SD-Card is inserted in the SD-Card slot which can be operated, false elsewise

4.3. is_write_protected

bool SDCard::is_write_protected( );

Description:

coalesenses 11 / 30
research to innovate
iSense Ethernet Gateway User Guide

Returns whether or not the SD Card is write protected or not


Returns:
true if the SD-Card in the SD-Card slot is write protected, false elsewise

4.4. get_number_of_blocks

uint32 SDCard::get_number_of_blocks( );

Description:
Returns the number of blocks of the currently inserted SD-Card
Returns:
Number of blocks of the SD-Card

4.5. access

uint8 SDCard::access( uint64 address, uint32 length, uint8* buffer, bool


write );

Description:
Reads or writes data to the SD Card. The returned value is the status code. Its upper 3 bytes are don’t
care bits. A successful write operation is indicated with a value of 5, a successful read operation with
0.
Parameter:

address The address which shall be accessed

length Determines how many bytes should be accessed

buffer Pointer to a buffer to/from which blocks are copied from/to the SD Card

write If true, the access will be a writing operation, otherwise it is a reading


operation

Returns:
Status code indicating whether the desired operation was successful or not. The upper three bits are
don’t care bits, the lower 5 indicate the status. A Value of 5 of the 5 lower bits indicate a successful
write operation, a value of 0 successful reading.

4.6. access_block

uint8 SDCard::access_block( uint32 block, uint32 length, uint8* buffer,


bool write );

Description:
Reads or writes data to the SD Card

coalesenses 12 / 30
research to innovate
iSense Ethernet Gateway User Guide

Parameter:

block The block which shall be accessed

length Determines how many bytes should be accessed. The length must be a
multiple of 512

buffer Pointer to a buffer to/from which blocks are copied from/to the SD card

write If true, the access will be a writing operation, otherwise it is a reading


operation

Returns:
Status code indicating whether the desired block-operation was successful or not. The upper three bits
are don’t care bits, the lower 5 indicate the status. A Value of 5 of the 5 lower bits indicate a
successful write operation, a value of 0 successful reading.

4.7. read

uint8 SDCard::read( uint64 address, uint32 length, uint8* buffer );

Description:
Reads a given number of bytes from a certain address of the SD Card. The method behaves exactly
like access, since it only calls access with the parameter write set to false.
Parameter:

address Start address to read from

length Determines how many bytes should be read

buffer Pointer to a buffer to which blocks are copied from the SD Card

Returns:
Status code indicating whether the desired read-operation was successful or not. The upper three bits
are don’t care bits, the lower 5 indicate the status. A value of 0 indicates success.

4.8. read_block

uint8 SDCard::read_block( uint32 block, uint32 length, uint8* buffer );

Description:
Reads a given number of blocks starting at a certain block from the SD card. The method behaves
exactly like access, since it only calls access with the parameter write set to false.
Parameter:

block The block which shall be accessed

coalesenses 13 / 30
research to innovate
iSense Ethernet Gateway User Guide

length Determines how many bytes should be accessed. The length must be a
multiple of 512

buffer Pointer to a buffer to/from which blocks are copied from/to the SD Card

Returns:
Status code indicating whether the desired read-operation was successful or not. The upper three bits
are don’t care bits, the lower 5 indicate the status. A value of 0 indicates success.

4.9. write

uint8 SDCard::write( uint64 address, uint32 length, uint8* buffer );

Description:
Writes a given number of bytes to a certain address of the SD card. The method behaves exactly like
access, since it only calls access with the parameter write set to true.
Parameter:

address The address to which shall be written

length Determines how many bytes should be read.

buffer Pointer to a buffer to which blocks are copied from the SD Card

Returns:
Status code indicating whether the desired write-operation was successful or not. The upper three bits
are don’t care bits, the lower 5 indicate the status. A value of 5 indicates success.

4.10. write_block

uint8 SDCard::write( uint32 block, uint32 length, uint8* buffer );

Description:
Writes a given number of blocks starting at a certain block to the SD Card. The method behaves
exactly like access, since it only calls access with the parameter write set to true.
Parameter:

block The block to which shall be written

length Determines how many bytes should be written. The length should be a
multiple of 512

buffer Pointer to a buffer to which blocks are copied from the SD Card

Returns:

coalesenses 14 / 30
research to innovate
iSense Ethernet Gateway User Guide

Status code indicating whether the desired block-operation was successful or not. The upper three bits
are don’t care bits, the lower 5 indicate the status. A value of 5 indicates success.

5. Enc28J60 API Description


The Ethernet Gateway comes with an Enc28J60 Ethernet chip, allowing the device to send and receive
packets using existing LAN infrastructure.
The Enc28J60 class in the isense namespace contains all software functionality for operating the
SDCard-specific features, including
• sending packets via Ethernet,
• receiving packets via Ethernet
The ENC28J60 class is defined in src/isense/modules/ethernet_module/enc28j60.h in the
iSense directory.
Beneath the low-level send and receive functionality as described in this document, there also exist a
high level API which enables the Ethernet Gateway to communicate with other network devices using
IPv4 / IPv6 as network layer protocol and TCP / UDP for transport. For further information on how to
use IP-based communication with the Ethernet Gateway please refer to [7].
Required modules:

Enc28J60 Module* #define ISENSE_ENABLE_ETHERNET_MODULE

SPI* #define ISENSE_ENABLE_SPI

GPIO* #define ISENSE_ENABLE_GPIO

5.1. constructor

Enc28J60::Enc28J60( Os& os, uint64 mac_address, uint16 rx_buffer_size,


bool full_duplex );

Description:
Constructor of the Ethernet Module
Parameter:

os Reference to the current Os

mac_address Desired 48-bits MAC-Address for this interface

rx_buffer_size Desired size of the receive buffer (6000 is a good choice)

full_duplex If true the full duplex mode will be turned on, half duplex when false

coalesenses 15 / 30
research to innovate
iSense Ethernet Gateway User Guide

5.2. send

void Enc28J60::send( const uint64 dest_addr, uint16 len, const uint8 buf,
uint8 options, Sender* sender );

Description:
Sends data using the Ethernet controller. The passed data will automatically embedded in an Ethernet
frame and sent to the interface with dest_addr.
Parameters:

dest_addr Destination address of the data

len Length of data to send

buf Pointer to the data to send

options Not considered

sender Not considered

5.3. enable

void Enc28J60::enable( );

Description:
Switches on the Ethernet controller

5.4. enable

void Enc28J60::disable( );

Description:
Switches off the Ethernet controller

5.5. set_receiver

bool Enc28J60::set_receiver( Receiver* receiver );

Description:
Sets an instance of class Receiver, that will be called upon reception of Ethernet packets.
Parameters:

receiver Instance of class Receiver which should get passed received packets

coalesenses 16 / 30
research to innovate
iSense Ethernet Gateway User Guide

Returns:
true if the receiver was registered successful, false elsewise

5.6. address

uint64 Enc28J60::address( );

Description:
Returns the current MAC address of that interface
Returns:
Current MAC-Address of the Ethernet interface. REMEMBER: Only the lower 48bits must be
considered for determining the address, the upper 16bits are usually set to zero.

5.7. max_packet_size

uint32 Enc28J60::max_packet_size( );

Description:
Returns the maximum size of a packet that can be sent over that interface at once
Returns:
Maximum Transmission Unit (MTU) of the link. For Ethernet this value is 1500bytes.

6. Ethernet Gateway Module Demo Application


The Ethernet Gateway Module demo application exemplifies how an application can make use of the
Net10Module and SDCard API. It shows how to
• switch on and off the LEDs,
• set the ButtonHandler to handle events raised by pressing the button B1,
• as well as read and write data to an microSD card
Required modules:

Net10 module #define ISENSE_ENABLE_NET10_MODULE

VSNPRINTF 2 #define ISENSE_ENABLE_VSNPRINTF_2

SD Card module #define ISENSE_ENABLE_ETHERNET_MODULE_SD_CARD

6.1. Obtaining the Ethernet Gateway Module Demo Application


The NET10 Ethernet Gateway Demo Application can be obtained from [7].

coalesenses 17 / 30
research to innovate
iSense Ethernet Gateway User Guide

6.2. Compiling the Ethernet Gateway Demo Application


The next step is compiling the Ethernet Gateway Module Demo Application.

6.2.1. Using Eclipse


If you want to use Eclipse for compiling Ethernet Gateway Demo Application, open Eclipse, and
change to the “C++” perspective.

You can now import the application into Eclipse. Choose “File”  “Import” from the menu bar to
open the “Import” dialog.

Choose “Existing projects into workspace”, and click on “Next”.

coalesenses 18 / 30
research to innovate
iSense Ethernet Gateway User Guide

Click on “Browse…”, and select the directory of the Core Module demo application, i.e.
NET10DemoApplication in the iApps directory.

DemoApplication” project should appear in the projects list of the


After doing so, the “NET10DemoApplication
“Import” dialog.

coalesenses 19 / 30
research to innovate
iSense Ethernet Gateway User Guide

If it doesn’t, the typical reason is that there is already a project called “NET10DemoApplicati
“ DemoApplication” in
Eclipse, i.e.
• you imported the NET10DemoApplication
NET10 before or
• you created or imported a project with the same name before.
Be sure not to check “Copy projects into workspace” in the above dialog. Finish the import by clicking
on the “Finish” button.
NET10DemoApplication” project in the “Project Explorer”.
As a result, you will find the “NET10 Explorer”

coalesenses 20 / 30
research to innovate
iSense Ethernet Gateway User Guide

In addition, the “NET10DemoApplication”


DemoApplication” will appear in the “Make Targets” view. Double click on
“all” to build the demo application for all targets.

As a result, the “Console” view displays the compiler output during the build process. After that, it
should look similar to the output depicted below.

6.2.2. Using the Command Line


If you want to use the command line tools for building the Core Module Demo Application, open a
console window, change to the NET10DemoApplication
NET10 directory in your iApps directory, and type
“make JN5148”.

coalesenses 21 / 30
research to innovate
iSense Ethernet Gateway User Guide

After the build finished, the console output should look similar as shown above.

6.3. Flashing the Ethernet Gateway Module Demo Application


Connect
• an iSense Ethernet Gateway Module and
• an iSense Gateway Module 2 with a USB cable
and plug the cable to the PC.
Start iShell, configure the correct communication port, and change to the “Flash Loader” view. Select
the appropriate binary according to the table below.

Chip Binary file

JN5148 iApps/NET10DemoApplication/bin/JN51
DemoApplication/bin/JN5148/NET10DemoApplication.bin
DemoApplication.bin

6.4. Ethernet Gateway Module Demo Application functionality


The source file of the Core Module demo application is located at
NET10DemoApplication/src/NET10
NET10DemoApplication.cpp.. The class
NET10DemoApplication is derived from isense::Application,, and additionally inherits
from isense::ButtonHandler
Handler.

class UG_NET10DemoApplication
NET10DemoApplication :
public Application,
public ButtonHandler,
public Task
{
public:
UG_NET10DemoApplication
NET10DemoApplication(Os &os);
// inherited from application, called upon device boot
void boot();

coalesenses 22 / 30
research to innovate
iSense Ethernet Gateway User Guide

// Handler called when the button of the NET10 is pressed


void button_down( uint8 button_no );
// inherited from Task, called when registered task is due
void execute( void* userdata );
private:
//Pointer to the NET10 instance
Net10Module* net10_;
//Status of the LEDs
uint8 led_value_;
//Pointer the SDCard instance
SDCard* sd_card_;
//Counts the number of times the button was pressed
uint64* cm_;
};
NET10DemoApplication overwrites isense::Application::boot(), which is called
upon the start up of the iSense sensor node.
void
UG_NET10DemoApplication::
boot (){
os_->allow_sleep( false );
os_->allow_doze( false );
os().debug("NET10DemoApplication::boot");
//create NET10 Module instance
net10_ = new Net10Module( os_ );
if ( net10_ != NULL ) // new was successful
{
//Register application as button handler of the NET10 module
net10_->set_button_handler( this );
//Get SDCard instance from Net10Module
sd_card_ = net10_->sd_card( );
if ( sd_card_ != NULL ) // new was successful
{
os_.add_task_in( Time( 1, 0 ), void,
(void *)USERDATA_SD_CARD_METRICS )
}

}
}
Within the boot() method, a Net10Module object is created. If the allocation was successful, the
application registers itself as ButtonHandler for button events of the Net10Module. Next the
pointer to the SDCard instance is retrieved. An instance of the SDCard is created together with the
Net10Module. If an instance of SDCard exists, a Task will be registered, that will periodically
queriy the SD Card slot until a card is inserted and then output the number of its sectors.
An application can register itself at the OS as a Task to receive a callback immediately, at a certain
time, or after a certain interval. Task callbacks are called in the regular application context. They
cannot interrupt other activities, and hence may be delayed. Task execution can take an arbitrary time,
and is hence suited for longer activities such as complex computations.

class Task : public iSenseObject


{
public:
/**
* This method is called by the os in normal context.
*/
virtual void execute( void* userdata ) = 0;
};

coalesenses 23 / 30
research to innovate
iSense Ethernet Gateway User Guide

Once a class inherits the isense::Task interface and implements the corresponding method, it is a
task and can be registered at the operating system for later callback.
For tasks, the OS provides three methods for registering tasks to be executed as soon as possible, at a
certain time, or after a certain interval from now on.

//-----------------------------------------------------------------------
/** This method enqueues the given task into the queue of tasks
* Its execute method is called during the main control flow
*
* \param task object implementing the Task interface, whose execute
* method is called
* \param userdata an arbitrary pointer that is passed back again
* to the callback
*
* \return true if task was enqueued successfully, false otherwise (e.g.
* if the task queue is full)
*
*/
bool add_task(Task *task, void* userdata);

//-----------------------------------------------------------------------
/** This method enqueues the given task in the queue of lower priority
* tasks. Its execute method is called during the main control flow
*
* \param interval Point in time when the callback will be called
* \param task object implementing the Task interface, whose execute
* method is called
* \param userdata an arbitrary pointer that is passed back again
* to the callback
*
* \return true if task was enqueued successfully, false otherwise (e.g.
* if the task queue is full)
*/
bool add_task_at(Time time, Task *task, void* userdata);

//---------------------------------------------------------------------
/** This method enqueues the given task in the queue of lower priority
* tasks. Its execute method is called during the main control flow
*
* \param interval Time period after which the callback will be called
* \param task object implementing the Task interface, whose execute
* method is called
* \param userdata an arbitrary pointer that is passed back again
* to the callback
*
* \return true if task was enqueued successfully, false otherwise (e.g.
* if the task queue is full)
*/
bool add_task_in(Time interval, Task *task, void* userdata);

All methods for registering tasks at the OS feature a so called userdata parameter. It can be used to
attach additional information to a task, that is then passed to the execute method when it is called. If
you don’t use the feature, simply pass NULL.

The execute method of the NET10DemoApplication looks as follows:

coalesenses 24 / 30
research to innovate
iSense Ethernet Gateway User Guide

void
NET10DemoApplication::
execute (void* userdata )
{
if ( userdata == (void*) USERDATA_SD_CARD_METRICS ){
//Check if a SD-Card is inserted
if ( sd_card_ -> is_ready( ) )
{
os_.debug(“SDCard has %d blocks”,
sd_card_->get_number_of_blocks( ) );
} else {
os_.debug(“SDCard is not inserted or ready”);
os_.add_task_in( Time( 2, 0 ), this,
(void*)USERDATA_SD_CARD_METRICS)
}
}
}

The execute-callback-method will be called the first time 1 second after boot, passing it
USERDATA_SD_CARD_METRICS as userdata parameter. It checks if a SD Card is inserted and if, it will
print the number of blocks of the inserted card. If no card was detected another Task is registered,
that will check the SDCard status again in 2 seconds. This will be repeated until a card is inserted.
An application can register itself at the Net10Module as a ButtonHandler to receive a callback,
when a certain button is pressed. ButtonHandler callbacks are called within a Task context, they
cannot interrupt other activities, and hence may be delayed.

class ButtonHandler : public iSenseObject


{
public:
/**
* This method is called when a button is pressed
*/
virtual void button_down( uint8 button_no ) {};
/**
* This method is called when a button is released
*/
virtual void button_up( uint8 button_no ) {};
};
Once a class (such as the demo application) inherits the isense::ButtonHandler interface and
implements the corresponding methods, it is a button handler and can be registered at for later
callbacks upon button events.
The demo application only implements the button_down method, button-up events are not
considered by this application.
The button_down event of the demo application looks as follows:
void
NET10DemoApplication::
button_down ()
{
//Whenever a button is pressed led_value_ is modified and LEDs are
//turned on/off according to its values
led_value_ = ( led_value_ + 1 ) % 4;
if ( led_value_ & 0x01 ){
net10_ -> set_led( 0, true );
} else {

coalesenses 25 / 30
research to innovate
iSense Ethernet Gateway User Guide

net10_ -> set_led( 0, false );


}
if ( led_value_ & 0x02 ){
net10_ -> set_led( 1, true );
} else {
net10_ -> set_led( 1, false );
}
if ( sd_card_ != NULL && sd_card -> is_ready() ){
//Increment the button counter by one
button_counter_ ++;
char write_data[39];
//Write value of button_counter_ to write_data
uint8 bytes = snprintf( write_data, 39, “button_counter_ =
%lld”, button_counter_ );
//Try to write write_data to SD-Card at address 0, and check if
//writing was successful
uint8 result = sd_card_->access( 0, bytes, (uint8*) write_data,
true );
if ( (result & 0x1F) == RESPONSE_DATA_ACCEPTED ){
os_.debug(“Writing to SDCard successful”);
memset( write_data, 0, 39 );
//Try to read the written data and verify if reading was
//successful
result = sd_card_->access( 0, bytes, (uint8*) write_data,
false );
if ( result == 0 ){
//If reading was successful, print the read data
os_.debug(“\”%s\” read”, write_data );
} else {
os_.fatal( “reading failed” );
}
} else {
os_.fatal( “ERROR! Code: %d”, (result & 0x1F) );
}

When the button of the Ethernet Gateway Module is pressed the led_value_ variable modified and
takes a value between 0 and 3 which represent one of the four possible combinations the two LEDs
can be stated in. After the LEDs have been switched the value of the button_counter_ is
incremented and written to the SD-Card. To verify that writing was successful, the previously written
data is read from the SD-Card and outputted to the iShell Serial Monitor . Any error is printed as well.

NOTE:
To be able to benefit from the SD-Card features without using a file system there are
several tools for the PC which allows for reading and writing from and to the SD-Card.
The simplest way to do so is to use Linux. To completely reset your card open a
Terminal window and figure out the device name of you your SD Card reader in the
/dev/ directory. Use DiskDump (dd) to reset your card. Type in
dd if=/dev/zero of=/dev/<SD Card reader device name>
To read all data from a SD Card use

coalesenses 26 / 30
research to innovate
iSense Ethernet Gateway User Guide

dd if=/dev/<SD Card reader device name> of=<Path of file


to write card contents to>
EXAMPLE:
Assumed that the name of the SDCard reader device is /dev/disk1 the following
examples illustrate the above commands.

Reset SD-Card:
dd if=/dev/zero of=/dev/disk1

Save data from SD-Card to file /home/user/sd_contents.txt:


dd if=/dev/disk1 of=/home/user/sd_contents.txt

You can send character output to the outside world using the methods Os::debug and Os::fatal:

//-------------------------------------------------------
** Logs the given string depending on the log mode to a uart or radio.
*/
void debug( const char *format, ...);

//-------------------------------------------------------
/** Logs the given string depending on the log mode to a uart or radio.
*/
void fatal( const char *format, ...);
They work similar to the well-known sprintf functions in regular C, i.e. integer values etc. can be
printed using the % notation. For example

uint16 i = 128;
os().debug("value of i is %d, hex=%x", i, i);

will output „value of i is 128, hex=0x80“. The destination of the debug output can be set using
Os::set_log_mode, the corresponding constants can be found in iSense/src/isense/os.h.

//-------------------------------------------------------
/** Sets the log mode to the given value, e.g.
* (ISENSE_LOG_MODE_UART0 | ISENSE_LOG_MODE_RADIO)
*/
void set_log_mode( uint8 mode ) {log_mode_ = mode; }

By default, the output destination is set to UART0, i.e. the output is sent to a PC via a connected
iSense Gateway Module.

coalesenses 27 / 30
research to innovate
iSense Ethernet Gateway User Guide

Observing the output of the NET10DemoApplication with iShell yields the above result.

coalesenses 28 / 30
research to innovate
iSense Ethernet Gateway User Guide

7. References
[1] coalesenses Development Environment Setup User Guide, online available at
http://www.coalesenses.com/download/UG_development_environment_setup_v1.9_web.pdf
[2] Flashing iSense devices wirelessly, online available at
http://www.coalesenses.com/download/UG_flashing_isense_devices_wirelessly_1v3.pdf
[3] coalesenses iShell User Guide, online available at
http://www.coalesenses.com/download/UG_ishell_v1.3.pdf
[4] coalesenses Writing iSense Applications User Guide, online available at
http://www.coalesenses.com/download/UG_writing_isense_applications_1v1.pdf
[5] Advanced Data Sheet – JN513x, online available at
http://www.jennic.com/support/view_file.php?fileID=0000000111
[6] IEEE Computer Society, IEEE Standard for Information technology – Telecommunications and
information exchange between systems – Local and metropolitan area networks – Specific
requirements, Part 15.4: Wireless Medium Access Control (MAC) and Physical Layer (PHY)
Specifications for Low-Rate Wireless Personal Area Networks (LR-WPANs),
http://standards.ieee.org/getieee802/download/802.15.4-2003.pdf
[7] Documentations and Demo Applications for iSense Devices are available at
http://www.coalesenses.com/index.php?page=isense-demos

coalesenses 29 / 30
research to innovate
iSense Ethernet Gateway User Guide

coalesenses GmbH
Maria-Goeppert-Str. 1
23562 Lübeck
Germany
www.coalesenses.com
sales@coalesenses.com

coalesenses 30 / 30
research to innovate

You might also like