Skip to the content.

Embedded Notebook

Nothing, just Mike and Johnny’s notebook



ABOUT US

Some Words About This Notebook

Because two people are contributing to this notebook, there are differences in styles

Mike’s articles written as if you have already known the basic and the knowledge only remind but not clearly for you to understand from zero

Some huge parts will be separated to another files

C++
Python
Robot Operating System

We are not familiar with web applications so our GitHub Webpage is for fun, our main target is knowledge

Table of contents

1. C

1.1. C keywords

auto double int struct
break else long switch
case enum register typedef
char extern return union
continue for signed void
do if static while
default goto sizeof volatile
const float short unsigned

1.2. Variables declaration

type-qualifier(s) type-modifier data-type variable-name = initial-value;
type-qualifier: const, volatile, restrict
type-modifier: short, long, unsigned, signed
data-type: integer (int), floating point (double, float), enumerated, derived (array, struct, union, pointer), void

1.3. Memory Layout

Memory layout from low to high addresses in C includes:

Notice: memory layout in C is not memory layout in computer, this will be discussed in Operating Systems part

1.4. Volatile keyword

volatile: used to indicate to the compiler that a variable’s value may change unexpectedly
volatile is usually used when you turn on compiler’s optimization function

1.5. Pointer:

pointer is variables that hold address
pointer point to any type have same size
In C, we don’t have reference parameter so we can use pointer to substitute

1.6. Function pointer:

function pointer is a pointer to const because function address place on code segment which is read-only
syntax: data-type (*function-name)(parameter)
e.g. void (*pointer_function)(): pointer function point to a function with no parameter and return void

1.7. Struct & Union & Enum

struct, union and enum are user-define data types
struct is used to group related variables (members) into one
struct in C need to use typedef to don’t use struct keyword whenever declare a new struct variable. In C++, it is not necessary
union allows to store different data types to same memory
enum is usually used to assign name to integral constants
data structure alignment is the term that means compiler “padding” into space between 2 data “naturally aligned”, this mechanism help compiler better performance. We should arrange data in struct reasonable to optimize memory and performance

1.8. Extern & Static

extern is used to notify to the compiler that variable is memory allocated and don’t need to allocate again, it is usually used in multi-source file projects
static have 2 meaning:

1.9. Compilation Model

Preprocessing: preprocessor will replace preprocessor directives (#)
Compiling: compiler will compile code to assembly code (.s/.asm)
Assembling: assembler will change assembly code to machine code in object code files(.o)
Linking: linker will link object code files together to shared library or executable file
A little bit about preprocessing and linking: preprocessing replaces header file (.h) but it usually only contains declarations not definitions and the linking link the definitions to these declarations

1.10. Static & Shared Library

Static library is linked in compile time
Shared/Dynamic library is linked in run time

1.11. Function Invoker

When you invoke a function, there are 2 important additional parts called prologue and epilogue
prologue is the concealed code run before the function is invoked, it is responsible to take the function’s parameter to save to stack
epilogue is the concealed code run after the function is invoked, it is responsible for returning the function’s result to the function invoker and removing the parameter saved to stack
function, prologue and epilogue take the same memory size no matter how many times the function is invoked which means the more you call the function, the more memory is saved
But there is a paradox in programming that the advantage in memory comes with the disadvantage in speed
The worst case is the function is too short that is shorter than prologue/epilogue

1.12. Inline Function

inline is used to define a macro-like function, meaning that the function’s instructions will be replaced directly to its invoke in preprocessor step
This helps improve speed but paying by program size

1.13. Dynamic Memory Allocation

As discuss in 1.3. Memory Layout there is a memory layer for dynamic memory allocation called heap. So how we manage dynamic memory allocation
There are some keyworks to manage dynamic memory

2. Computer Architect

2.1. Von Neumann & Harvard

Von Neumann is the computer architect that have intercommunity bus for program memory and data memory
Harvard is the opposite, so it have better performance

2.2. Little endian & Big endian

endian is a storage mechanism so it is opposite to our thinking
Little endian is from LSB to MSB and Big endian is the opposite

2.3. Memory Architect

There are two memory types in computer: volatile and non-volatile
volatile with representation is RAM, also called memory, loses contents when power is off, a temporary workspace for data because it is high-speed
Some volatile memory:

non-volatile with representation is ROM, also called storage, preserves contents when power is off, used to store data
Some non-volatile memory (their name say all about them):

There are also some additional memory types:

Memory component speed ordered from fastest to slowest: register, cache, main memory, non-volatile memory, hard-disk drives, optical disk, magnetic tapes

3. Embedded

3.1. Digital & Analog

Our world is analog but computer’s world is digital
analog refers to a continuously changing representation of a continuously variable quantity
digital refers to representing these variable quantities in terms of actual numbers, or digits
So we have to do something for computers to understand our world, there will be discuss in ADC & DAC part

3.2. Embedded Systems

Embedded system is computer system with a dedicated function embedded as a part of a complete device and have limited resources as memory, peripheral, speed, …
They have some features as: small size, low per-unit cost, low power consumption, …

3.3. Cypher-Physical Systems

Stay tuned !

This part will be added later

3.4. Sensors & Actuators

Sensors are devices that measure physical quantities
sensor can be seem as input of a system, it responsible to “read from physical world”
Actuators are devices that modify physical quantities
actuator can be seem as output of a system, it responsible to “write to physical world”

3.5. Internet of Things

Stay tuned !

This part will be added later

4. Micro-controller

Micro-processor & Micro-controller

Micro-processor:
Micro-controller

GPIO

General-Purpose Input/Output Ports handles both incoming and outgoing digital signal
They can be INPUT or OUTPUT, LOW or HIGH
Also, they can be configurated for other functions, called alternate function
Pull-up resistor is pulled HIGH the GPIO when the button is not pressed and pulled LOW the GPIO when the button is pressed
Pull-down resistor is the opposite to pull-up
Open-drain make the GPIO can only be LOW or floating, so we have to use external pull-up resistor.

Interrupt

Timers

ADC & DAC

Analog to Digital Converter and Digital to Analog Converter are very important components in electronic equipments
ADC and DAC architect won’t be mention here, let’s go to their parameters

PWM

Pulse Width Modulation

Protocol & Interface

A protocol usually come together with that protocol’s interface so there are many people have ambiguous between protocol and interface. So, how are they different ?
protocol is a set of rules for devices to communicate with others as preamble, data length, conditions, crc, … and they need to be agreed by all devices
interface is the way devices connect to others as wires, radio waves, …

Some Couple Term In Protocols

Synchronous and Asynchronous: these are two important term in communication, they imply to clock. Synchronous transmissions are synchronized by a clock and asynchronous transmissions are not
Wire and Wireless: just wire and wireless
Serial and Parallel: data transmission serial or parallel (e.g. one wire or multi wires)
Simplex, Half-duplex and Full-duplex: in simplex mode the signal is sent in one direction (only one device can sent data), in half-duplex the signal is sent in both directions but one at a time, in full-duplex signal is sent in both directions at the same time
Master and Slave: master will be the clock controller
Server and Client: client is requester and server serves

USART

Universal Synchronous/Asynchronous Receiver-Transmitter protocol:

UART is asynchronous and USART is synchronous, their name said about it
In UART there are some definitions that must be the same on devices:

I have never used USART so I don’t have information about it exclude it is synchronous
In addition, there is another mode called Multiprocessor UART, maybe I will add it later

I2C

Inter-Integrated Circuit, also called Two Wire Interface protocol:

SPI

Serial Peripheral Interface protocol:

CAN

Controller Area Network protocol:

WiFi

Bluetooth

MQTT

DMA

Direct Memory Access

Bootloader

5. Operating System

5.1. OS Definition

Operating System is software or it can be seem as the intermediate between user and hardware that runs on a computing device and manages the hardware and software components that make up a functional computing system

5.2. OS Functions

Hardware management
Provide interface for users
Application installation
Connect hardware
Interaction between application and hardware
CPU scheduling
Process coordination and synchronization
Resource management
Access control and protect system
Integrity maintenance, error control and recovery

5.3. OS Types

Base on processing:

5.4. OS Components

Process/thread management
Primary memory management
File management
I/O system management
Secondary memory management
Protect system
Command line interpreter system

5.5. Process

Process is the active application instant, application become process when executable file loaded into memory (called process image)
Process layout is as same as Memory Layout In C Program
Process initialization step: allocate identifier, allocate memory for process load, initialize Process Control Block (PCB), setup necessary relation (e.g. arrange PCB to queue)
PCB is one of the most important data structure in OS to manage and control the execution of processes, it typically contains the following components:

Thread is a segment of a process or a lightweight process, threads share memory, data, resources together
There are 3 thread mapping model

OS Scheduling

Scheduling in OS is process scheduling with PCB: process scheduling is a crucial function in OS and PCB in OS plays a vital role in this function
Scheduler include several types:

Scheduling algorimth

6. RTOS

Stay tuned !

7. Linux Embedded

Stay tuned !

Undistributed

These parts will be completed or distributed soon



FEEDBACK

EMAIL