• 沒有找到結果。

Nano­RK And Zigduino

N/A
N/A
Protected

Academic year: 2022

Share "Nano­RK And Zigduino"

Copied!
48
0
0

加載中.... (立即查看全文)

全文

(1)

Nano­RK And

Zigduino

wnfa ta course

­­hikaru4

(2)

Today's outline

Zigduino v.s. Firefly

Atmel processor and the program chip

Atmega128rfa1, FTDI chip...

I/O Interface on the board

GPIO, ADC, UART, SPI, I2C...

Nano­RK

Nano­RK OS Architecture

Nano­RK HOW­TOs

Tips and Tricks

Lab2 announcement.

(3)

Zigduino

(4)

History

Firefly

CMU

Firefly1.0

Firefly2.2

Firefly2.3

no longer manufacture

Firefly3.0

Not release yet

atmega128rfa1

Zigduino

logos­

electro.com

Arduino­compatible

Arduino is an open­

source electronics  prototyping platform.

Atmega128rfa1

The same one as  firefly3's

(5)

Zigduino

Atmega128rfa1

FTDI

Clock Speed 16 MHz

Flash Memory 128 KB 

SRAM  16 KB

EEPROM 4 KB

Radio 802.15.4(zigbee)

(6)

I/O interface

GPIO(pin2~10)

ADC(analog in 0~6)

UART(RX, TX pin0,1)

SPI(11 (MOSI),    12 (MISO),       13 (SCK))

I2C(I2C SDA, SCL)

(7)

GPIO

General Purpose  Input/Output

Pin2~10

Digital input

Digital output

Control direction  by some selector

(8)

GPIO

Tri­state Buffer Port

Memory­Mapped IO

Control Registers

Data Direction Register (DDR, TRIS)

Internal Pull Up Register (PLP)

Reading / Writing to the Port

(9)

GPIO

Example

LED, buzzer,

7­segment display

http://www.youtube.com/watch?v=fIjj6yDIe40

Switch, button

http://www.youtube.com/watch?v=qxJvsL6ES0k

(10)

ADC

Analog to Digital  Converter

ANALOG IN 0~6

Analog input

Converts an Analog  Signal to a Digital One

10 bit Resolution

(11)

ADC

Example

Sensor: Light sensor, temperature sensor....

(12)

UART

Universal Asynchronous Receiver / Transmitter

RX, TX (pin0,1)

Serial port 

communication

(13)

UART

RX­>TX

TX­>RX

Baud rate

(14)

UART

Example

Open log, T07AW, GPS module...

(15)

SPI and I2C

SPI(11 (MOSI),    12 (MISO),       13 (SCK))

I2C(I2C SDA, SCL)

Serial bus protocol

(16)

SPI(Serial Peripheral Interface)

4 Wire Serial Bus from Motorola

MISO/MOSI <=> RX/TX

SCLK => baud rate

SS => slave select

(17)

I2C(Inter­Integrated Circuit)

Multi­drop 2 wire  serial bus protocol from Philips

SCL: Serial Clock

SDA:Serial Data Line

Two Bi­directional Open­Drain Lines

Data transfer is initiated with the START bit (S) when SDA is pulled low while SCL stays high. Then, SDA sets the transferred bit while SCL is low (blue) and the data is sampled (received) when SCL rises (green). When the transfer is complete, a STOP bit (P) is sent by releasing the data line to allow it to be pulled up while SCL is constantly high.

(18)

Nano­RK

(19)

What is nano­RK?

A Real­time Operating System for sensor  nodes for use in wireless sensor networks

Priority­Based Preemptive Multitasking

Resource Reservations

(20)

Nano­RK feature

C GNU tool­chain

Classical Preemptive Operating System Multitasking  Abstractions

Real­Time Priority Based Scheduling

Built­in Fault Handling

Energy Efficient Scheduling based on a­prior task­set  knowledge

Tickless Timer

Small Footprint (<2K RAM, 16K ROM, including link  layer) 

(21)

Nano­RK Motivation

Why Priority­based scheduling?

Time­triggered task interleaving can become  daunting...

Period  Execution Time Network Radio Sporadic 10ms

Audio Sensor 200 hz 10us Smart Camera  1 hz  300ms Global Positioning  5 hz 10ms

(22)

Nano­RK Reservations

CPU Utilization

Time Allowed Per Period

For example, a task can run for 10ms of time  every 250ms

Network Utilization

Packets In and Out Per Period

Sensors & Actuators Usage

Sensor Readings Per Period

(23)

Nano­RK Architecture 

(24)

Nano­RK Time Management

~1ms OS Tick Resolution

Variable Tick Timer (interrupts occur as required, not  every quantum)

wait_until_xxx() functions

Suspend task until the event or timeout happens

If there is no wait_until_xxx() call, then your reserve  will be violated

If reserves are disabled, then this can starve low  priority tasks and will waste battery power

(25)

Creating a Nano­RK Task

NRK_STK TaskOne_Stack[NRK_APP_STACKSIZE];

nrk_task_type TaskOne;

void Task1(void);

...TaskOne.task = Task1;

nrk_task_set_stk( &TaskOne, TaskOne_Stack, NRK_APP_STACKSIZE);

TaskOne.prio = 2;

TaskOne.FirstActivation = TRUE;

TaskOne.Type = BASIC_TASK;

TaskOne.SchType = PREEMPTIVE;

TaskOne.period.secs = 0;

TaskOne.period.nano_secs = 100*NANOS_PER_MS;

TaskOne.cpu_reserve.secs = 0;

TaskOne.cpu_reserve.nano_secs = 10*NANOS_PER_MS;

TaskOne.offset.secs = 0;

TaskOne.offset.nano_secs= 0;

nrk_activate_task (&TaskOne);

(26)

Nano­RK Fault Handling

Task Time Violations

OS will enforce time bounds given to a task

Canary Stack Check

Check if user­specified stack has been overflowed

Not 100%, but incurs low overhead and better than nothing

Unexpected Restarts

Capture restart that occurs without power­down

Resource Over­use

Manage sensors / actuators

Low Voltage Detection

Watchdog Timer

(27)

Configure Nano­RK (nrk_cfg.h)

#define NRK_REPORT_ERRORS // print error over serial

#define NRK_HALT_ON_ERROR // stop the kernel on error

#define NRK_STACK_CHECK // Enable Canary Stack Check

#define NRK_NO_POWER_DOWN // zigduino need this define

#define NRK_MAX_TASKS 2

// Max number of tasks in your application

#define NRK_MAX_RESOURCE_CNT 1

// The number of semaphores in the system.

#define NRK_TASK_IDLE_STK_SIZE 64 // Idle task stack size min=32

#define NRK_APP_STACKSIZE 128

#define NRK_KERNEL_STACKSIZE 128

(28)

Take a break

Next coming:

Soldering

Nano­RK how­tos

API, debug tips

Nano­RK learning by doing

(29)

Soldering

Some tutorial

http://www.youtube.com/watch?v=q_­xLuGPhzk

http://v.youku.com/v_show/id_XMjMwMTUyNDU2.html

(30)

Nano­RK API Quick Guide

How to find the API you need?

Take a look of sample code

In folder: nano­RK/project/

Go official API document

http://www.nanork.org/wiki/Documentation

Trace the source code

http://mvnl.csie.ntu.edu.tw/nano­RK/HTML/

Write one!!! (you will need the datasheet)

http://ppt.cc/Q2~L

(31)

Nano­RK API Quick Guide

Example:

svn://mvnl.csie.ntu.edu.tw/wn11fall/lab/examples/

led_blink

nrk_gpio_direction()

nrk_gpio_set(), nrk_gpio_clr(), nrk_gpio_toggle()

basic_tasks

nrk_task_type

(32)

Nano­RK Debug?

printf() is your good friend

You will need a serial console.

Unix like: minicom

Windows: teraterm, putty, hyperterm...

Remember printf is slow.

LED is your good friend

pin13 = L, RFRX, RFTX

plug more LEDs on GPIO

much faster then printf() 

(33)

Nano­RK Tips and Tricks

Tip 1. NO MORE UP arrow!!!

“$ make clean && make && make  program || make program”

Save your time from typing and typing  again during debugging.

(Or press UP arrow again and again).

(34)

Nano­RK Tips and Tricks

Tip 2. NO MORE vim makefile!!!!

“$ make clean ROOT_DIR=~/nano­RK”

“$ make ROOT_DIR=~/nano­RK”

“$ make program ROOT_DIR=~/nano­Rk/nano­RK  PROGRAMMING_PORT=/dev/ttyUSB0”

Don't waste your time to edit the makefile anymore.

(35)

Nano­RK Tips and Tricks

Tip 3. No MORE ctrl+a o!!!!!

“$ LANG=C ;minicom ­o ­D /dev/ttyUSB0”

Don't waste your time to setup the minicom  anymore.

(36)

Nano­RK Tips and Tricks

Tip 4. Where is my warning/error??????

“$ make 2>&1 | grep main.c:”

“$ make 2>&1 | egrep 'main.c:|

myinclude.c'”

Get your warning/error messages only.

(37)

Lab2

Zigbee RSSI localization

(38)

Lab2:  zigbee RSSI localization

Path loss exponent : step by step

Get distance from RSSI

Localization

The nodes we set at CSIE 2F

What you need to do

Path loss exponent

Localization algorithm

(39)

Path loss exponent

Free space:

Pr = 

4d

2

Pt , Pr ∝  1 d

2

10logPr = −2⋅10logdc

PrdBm = −2⋅ddBunitc

(40)

Path loss exponent

Log­distance path loss model:

Pr ∝  1 d

n

10logPr = −n10logdc

PrdBm = −nddBunitc

(41)

Receive power v.s. Path loss

Path loss:

PL = Pt

Pr ∝ dn

10logPL = n10logdc

PLdB = nddBunitc

(42)

Path loss exponent

Pr ∝  1 d

n PrdBm = −nddBunitc

(43)

RSSI to distance

Pr ∝  1 d

n PrdBm = −nddBunitc

(44)

localization

(45)

The node we set at CSIE 2F

(46)

What you need to do?

Path loss analysis

Measurement the RSSI with different distance

Take log scale

Draw the regression line of path loss

(47)

What you need to do?

Design the localization algorithm

Base on RSSI

Real time localization

Demo

We will announce the free time slots of the TAs.

(48)

Q&A

Any questions?

參考文獻

相關文件

• The memory storage unit holds instructions and data for a running program.. • A bus is a group of wires that transfer data from one part to another (data,

The transfer will probably be chunked (HTTP v1.1). When the sheet is done, the scanner will decrement SideCount, increment SideNumber and transition to Pending because

FIGURE 5. Item fit p-values based on equivalence classes when the 2LC model is fit to mixed-number data... Item fit plots when the 2LC model is fitted to the mixed-number

Courtesy: Ned Wright’s Cosmology Page Burles, Nolette &amp; Turner, 1999?. Total Mass Density

The Mahīśāsaka Vinaya says, “When the karman for the ordination by the bhikṣuṇīs alone is complete, gather the ten bhikṣuṇī teachers to bring the disciples

* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2005..

• A sequence of numbers between 1 and d results in a walk on the graph if given the starting node.. – E.g., (1, 3, 2, 2, 1, 3) from

The remaining positions contain //the rest of the original array elements //the rest of the original array elements.