Contiki OS preparation usage with kit CC256

ryanng90 9 views 28 slides Oct 05, 2024
Slide 1
Slide 1 of 28
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28

About This Presentation

Contiki OS instruction


Slide Content

ContikiContiki
A Lightweight and Flexible Operating A Lightweight and Flexible Operating
System for Tiny Networked SensorsSystem for Tiny Networked Sensors
Presented by: Jeremy SchiffPresented by: Jeremy Schiff

ObjectivesObjectives

LightweightLightweight

Event Driven ModelEvent Driven Model

Has Multi-Threading Support as LibraryHas Multi-Threading Support as Library

Dynamic Loading and Replacement of Dynamic Loading and Replacement of
Individual ServicesIndividual Services

Contiki MotivationsContiki Motivations

No memory protection between appsNo memory protection between apps

Kernel very minimalKernel very minimal

CPU multiplexingCPU multiplexing

Loading ProgramsLoading Programs

All other abstractions by librariesAll other abstractions by libraries

Custom ApplicationsCustom Applications

DifferentiationDifferentiation

TinyOSTinyOS

Statically linked entire applicationsStatically linked entire applications

MagnetOSMagnetOS

Virtual Machine – byte codeVirtual Machine – byte code

MantisMantis

Pure MultiThreadPure MultiThread

ContikiContiki

Dynamic Linking of binariesDynamic Linking of binaries

Event/Thread HybridEvent/Thread Hybrid

Why Loadable ApplicationsWhy Loadable Applications

Smaller file to uploadSmaller file to upload

Less EnergyLess Energy

Less Dissemination Time Less Dissemination Time

Why No Threads?Why No Threads?

Thread stacks must be allocated at creation timeThread stacks must be allocated at creation time

Stack Memory Over-ProvisionedStack Memory Over-Provisioned

No Virtual Memory SystemNo Virtual Memory System

No Memory Protection Mechanisms No Memory Protection Mechanisms

Locking for state exclusionLocking for state exclusion

Stack memory is inaccessible to other threadsStack memory is inaccessible to other threads

EventsEvents

No lockingNo locking

Only one running at a timeOnly one running at a time

Only one stackOnly one stack

Locking rareLocking rare

Hard to express some things as state machineHard to express some things as state machine

Problem: Cryptography takes 2 seconds, everything Problem: Cryptography takes 2 seconds, everything
else blocked.else blocked.

Solution: Preemptive ThreadsSolution: Preemptive Threads

System OverviewSystem Overview

Service – Something that implements Service – Something that implements
functionality for more than one applicationfunctionality for more than one application

Apps have direct access to hardwareApps have direct access to hardware

Single Address SpaceSingle Address Space

Inter-process communication via event postingInter-process communication via event posting

Always Through KernelAlways Through Kernel

Core vs. Loaded ProgramCore vs. Loaded Program

Partitioned at compile timePartitioned at compile time

CoreCore

Single Binary Single Binary

Ideally never modifiedIdeally never modified

ProgramProgram

Easily upgradedEasily upgraded

KernelKernel

Execution via: Kernel Events or Polling EventsExecution via: Kernel Events or Polling Events

No preemption of scheduled events No preemption of scheduled events

Synchronous vs Asynchronous EventsSynchronous vs Asynchronous Events

Synch: Like Function CallSynch: Like Function Call

Asynch: Like posting new eventAsynch: Like posting new event

Asynch reduces stack spaceAsynch reduces stack space

Debugging issuesDebugging issues

Two Level SchedulingTwo Level Scheduling

Events Events

Can’t preempt one anotherCan’t preempt one another

Interrupts Interrupts

Can preempt eventsCan preempt events

Can use “underyling real-time executive” Can use “underyling real-time executive”

Provides realtime guaranteesProvides realtime guarantees

Non-hardwareNon-hardware

Can’t post eventsCan’t post events

Use polling flag insteadUse polling flag instead

Prevent race conditionsPrevent race conditions

Loading ProgramsLoading Programs

Relocation Information in BinaryRelocation Information in Binary

Check for space before loadingCheck for space before loading

Call Initialization FunctionCall Initialization Function

Replace or Starts new ProgramReplace or Starts new Program

Power Save ModePower Save Mode

No explicit Kernel assistanceNo explicit Kernel assistance

Access to event queue size Access to event queue size

ServicesServices

ApplicationApplication

Service LayerService Layer

Service InterfaceService Interface

Service ProcessService Process

ApplicationApplication

Must dynamically linkMust dynamically link


Interact via Service StubInteract via Service Stub

Compiled inCompiled in

Version numberVersion number

Caches Service ProcessIDCaches Service ProcessID

Service LayerService Layer

Works with KernelWorks with Kernel

Provides lookup for specific serviceProvides lookup for specific service

Returns a Service InterfaceReturns a Service Interface

Has pointers to all functions service providesHas pointers to all functions service provides

Contains a version NumberContains a version Number

Interface description implemented by Service ProcessInterface description implemented by Service Process

Version numbers must matchVersion numbers must match

Failure Support? MANTIS thinks about this better.Failure Support? MANTIS thinks about this better.

Service ExampleService Example

Service ReplacementService Replacement

Process ID must be preservedProcess ID must be preserved

Kernel supportedKernel supported

Kernel instructs service to remove itselfKernel instructs service to remove itself

Could lead to problemsCould lead to problems

Kernel provides mechanism to transfer state Kernel provides mechanism to transfer state

Service state also versionedService state also versioned

Service state must be stored in a shared space during Service state must be stored in a shared space during
swap due to reallocations of old version’s spaceswap due to reallocations of old version’s space

Is there a better way to do this - SOS?Is there a better way to do this - SOS?

LibrariesLibraries

Application optionsApplication options

Static link with coreStatic link with core

Static link with librariesStatic link with libraries

Single binarySingle binary

Call a serviceCall a service

Memcpy() vs Atoi()Memcpy() vs Atoi()

MemCpy in CoreMemCpy in Core

CommunicationCommunication

Architecture makes easy to replace Communication Architecture makes easy to replace Communication
Stack Stack

A service like any otherA service like any other

Enables multiple communication stack for comparisonEnables multiple communication stack for comparison

Comm Services use Service Mechanism to call one Comm Services use Service Mechanism to call one
anotheranother

Comm Services use Synchronous events to Comm Services use Synchronous events to
communicates with applicationscommunicates with applications

No copying of buffers because Synch events can’t be No copying of buffers because Synch events can’t be
preemptedpreempted

Communication StackCommunication Stack

Multi-ThreadingMulti-Threading

Optional Library linked inOptional Library linked in

Kernel interactionKernel interaction

Platform IndependentPlatform Independent

Stack Switching / Preemption primitivesStack Switching / Preemption primitives

Platform DependentPlatform Dependent

Multi-Thread APIMulti-Thread API

Over the air ProgrammingOver the air Programming

1 node took 30 seconds1 node took 30 seconds

40 nodes took 30 minutes40 nodes took 30 minutes

1 component for 40 nodes took 2 minutes1 component for 40 nodes took 2 minutes

Used naïve protocolUsed naïve protocol

Code SizeCode Size

Bigger than TinyOS, Smaller than MantisBigger than TinyOS, Smaller than Mantis

Polling Handlers and Increase FlexibilityPolling Handlers and Increase Flexibility

Less compiler optimization possibleLess compiler optimization possible

Preemption DemoPreemption Demo

Start 8 second Start 8 second
process at 5 Seconds process at 5 Seconds
and continually pingand continually ping

~.1 ms latency ~.1 ms latency
increaseincrease

Poll handler caused Poll handler caused
spikesspikes

Mainly Radio Packet Mainly Radio Packet
driverdriver

PortabilityPortability

Custom Code in a portCustom Code in a port

Boot up codeBoot up code

Device DriversDevice Drivers

Architecture specific parts of program loaderArchitecture specific parts of program loader

Stack switching code of the multithreading libraryStack switching code of the multithreading library

Kernel and Service layer need no changesKernel and Service layer need no changes

Questions?Questions?
Tags