Saturday, January 19, 2019

Operating Systems Concepts for IoT (Internet of Things)

Fundamentals

A task is a program, program unit, process, or thread (lightweight process). It could be a sequential function with an infinite loop. Usually can be of two types user or kernel.

Why do we need an operating system (OS)?
  • Manage hardware and software resources
  • Power Management
  • Task schedulers
  • Task management
  • supports multitasking
  • Inter-process communications
  • Memory allocation and management
  • Managing I/O devices and peripherals 
    • Analog 
      • motors
      • valves
    • Digital
    • Hardware Interrupts
      • ISR (Interrupt Service Routines)
Task Scheduling Algorithms

  • Time-sharing task scheduling 
    • Pre-emptive
    • Non-preemptive


  • Priority-based Round Robin Scheduling

Timers

  • Internal core timers
  • Software timers
    • One shot timers
    • Auto-reloaded timers

Task Management

  • Managing the Task States
    • Running 
    • Not Running
      • Ready
      • Suspended
      • Blocked
  • Context Switching
Race Condition
  • Undesirable condition when multiple tasks (or threads) try to access and change the shared data simultaneously.
Thread Safety
  • Locking shared resources/data using a critical section
  • Intertask communication
Deadlock

Two tasks are waiting for the same resource held by the other

Deadlock Prevention
- planning resource allocation

Interprocess Communications
- Message Queues
- Interrupts
- Mutex - provides mutual exclusion when concurrent tasks access a shared resource
- semaphore 

Dynamic Memory Allocation
- Heap
- First Fit Memory Allocation

Static Memory Allocation
 - Stack


Characteristics

  • Small Footprint
  • Modularity
  • Extensibility
  • Flexible
  • Easy to use API
  • Portability
  • Tools Support

Should we use an OS in IoT?

  • to build an ecosystem for device drivers.
  • support for extensibility
  • Security

Why ecosystem

  • vendor 
  • open source community
  • user support 
  • community

IoT System

  • managing processor
Types of Operating Systems
  • General Purpose 
    • rich functionality
    • complex functionality
  • Embedded OS for resource constraint device
    • e.g. coffee machines, smart sensors, wireless routers
    • small footprint
    • high reliability
    • for optimized performance
    • e.g. FreeRTOS (real-time OS), Android Things
    • limited file system support





Definition of Data Structures

Definition

data structure is a particular way of organizing and storing data in a computer so that it can be accessed and modified efficiently. More precisely, a data structure is a collection of data values, the relationships among them, and the functions or operations that can be applied to the data.


Understanding data structures is a must for every programmer as it clarifies the working of inner data for a program.

Below are the examples of data structures from real life
  • shopping list
  • bank statement - intentional list of transactions where each transaction is an intentional arrangement of data fields like information, date, amount,  involved parties etc. with a chronological order to
  • telephone directory
  • dictionary
  • thesaurus
  • encyclopedia
  • movie ticket availability
  • railway time table
  • flight schedule
  • mobile phone plans (showing various monthly packages)