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)

Friday, November 16, 2012

Facebook Edgerank Algorithm Explained

the Edgerank algorithm is used in Facebook to determine the order of posts that should be shown on a user's Top News feed. 

Sunday, November 4, 2012

Flyweight Design Pattern

The flyweight design pattern is used to dramatically increase the speed of code when using many similar objects.

To reduce memory usage the flyweight design pattern shares Objects that are the same rather than creating new ones.

Bridge Design Pattern

This pattern is used to build a group of classes that slowly adds functionality from one class to the next. 

Facade Design Pattern

English: Author: Alcides Carlos de Moraes Neto...English: Author: Alcides Carlos de Moraes Neto (wikipedia.10.alcides@spamgourmet.com) (Photo credit: Wikipedia)
The Facade pattern simplify methods so that most of the processing is done in the background. In technical terms it decouples the client from the sub components needed to perform an operation.


Iterator Design Pattern

The Iterator design pattern illustration, UML ...The Iterator design pattern illustration, UML diagram. (Photo credit: Wikipedia)
The iterator pattern is used to access objects that are stored in many different types of collection.
This is done by creating a common interface that all the different collection classes share. Then an iterator is provided to traverse the objects they contain.

Because all different Collection classes share a common interface they can be treated polymorphically and it eliminate duplicate code.


Below is the video tutorial for the Iterator pattern