Embedded / Project Experience

AUTOMOTIVE EMBEDDED SYSTEMS

 



Embedded Systems Role in Automobiles and Their Working


The Value of the Mechanical Engineer in an Embedded Controls Industry


Glimpse of Architecture:

An Architecture for In-Vehicle Infotainment Systems | Dr Dobb's

GENERAL :
 
Embedded - Autosar :
The primary goal of the AUTOSAR partnership is the standardization of a common methodology, basic system functions and functional interfaces.
This enables development partners to integrate, exchange, re-use and transfer functions within a vehicle network and substantially improves their efficiency of development.

HAL: Hardware abstraction layer. Its a vendor specific layer, allowing to interact with the hardware devices.

PageSize: It determines the size of the page in the memory.
Usually it varies from 4,8,16,32,64. For Arm64, the supported pagesize is 64KB with levels.
Details on Memory Address:  
Logical Address is generated by CPU while a program is running. The logical address is virtual address as it does not exist physically, therefore, it is also known as Virtual Address. This address is used as a reference to access the physical memory location by CPU.
Physical Address identifies a physical location of required data in a memory. The user never directly deals with the physical address but can access by its corresponding logical address. The user program generates the logical address and thinks that the program is running in this logical address but the program needs physical memory for its execution, therefore, the logical address must be mapped to the physical address by MMU before they are used.

Shell:
https://www.quora.com/What-is-the-difference-between-C-shell-CSH-Korn-shell-KSH-Bourne-shell-SH-and-Bourne-Again-shell-bash-in-shell-scripting 

MEMORY LAYOUT :



BRIEF:
The initialized data segment consists of all the global and static variables that are initialized when a file gets compiled. 
The uninitialized data segment consists of all global and static variables that are initialized to zero or do not have explicit initialization in source code.
The stack is a segment of memory where data like your local variables and function calls get added and/or removed in a last-in-first-out (LIFO) manner.
The heap is the segment of memory that is not set to a constant size before compilation and can be controlled dynamically by the programmer.
malloc, realloc, calloc and/or free all uses heap.

Stack vs Heap:
Stack:
- Memory is allocated in a contiguous block.
- Allocation and Deallocation is Automatic by compiler instructions.
- Access time is Faster
- Main issue is Shortage of memory
- Regarding Flexibility, stack is Fixed size
- Data type structure is Linear

Heap:
- Memory is allocated in any random order.
- Allocation and Deallocation is Manual by programmer.
- Access time is Slower
- Main issue is Memory fragmentation
- Regarding Flexibility, in heap Resizing is possible
- Data type structure is Hierarchical


NETWORK :

                                            ------   NETWORK OSI LAYER    ------



TCP vs UDP:
TCP :
It is a connection oriented protocol. packets are sequenced.
Reliable, guaranting the delivery of packets to the destination.
TCP doesn’t supports Broadcasting.
TCP has a (20-80) bytes variable length header.
TCP provides extensive error checking mechanisms. It is because it provides flow control and acknowledgment of data.
Sequencing of data is a feature of Transmission Control Protocol (TCP). this means that packets arrive in-order at the receiver.
TCP is comparatively slower than UDP.
Retransmission of lost packets is possible in TCP, but not in UDP.
TCP is used by HTTP, HTTPs, FTP, SMTP and Telnet.

UDP :
It is a connectionless oriented protocol. packets are not sequenced.
Not-reliable, as the delivery of the data cannot to guaranteed.
UDP supports Broadcasting.
UDP has a 8 bytes fixed length header.
UDP has only the basic error checking mechanism using checksums.
There is no sequencing of data in UDP. If ordering is required, it has to be managed by the application layer.
UDP is faster, simpler and more efficient than TCP.
There is no retransmission of lost packets in User Datagram Protocol (UDP).
UDP is used by DNS, DHCP, TFTP, SNMP, RIP, and VoIP.

 
RPC in NETWORKING : 
 
SOMEIP:

BUILD VSOMEIP:
vsomeip is delivered from GENIVI standard.
https://github.com/GENIVI/vsomeip/tree/master/documentation 
Filed or attributes given in json file : 
https://github.com/GENIVI/vsomeip/blob/master/documentation/vsomeipUserGuide
https://www.autosar.org/fileadmin/user_upload/standards/foundation/1-0/AUTOSAR_PRS_SOMEIPProtocol.pdf
https://github.com/GENIVI/vsomeip/tree/master

cd vsomeip
<.>/vsomeip$ mkdir build
<.>/vsomeip$ cd build
<.>/vsomeip/build$ cmake ..
<.>/vsomeip/build$ make

Dependency: 
check the README.md file for the dependency list.
Data forwarding:
There are 2 ways to fwd the data. Routing and non-routing.
Routing: Every events (notify & subscribe) will go through the routing (vsomeipd)/daemon.
Non-routing: Method request will happen without daemon/vsomeipd. It is a client to client communication.

So, if request - response is working and not event type -> the vsomeipd has not got the multicast / routing info before it has started.

SOMEIP SETUP:
QNX:
- used starter's cmake file for building the someip. But, it is requesting the BOOST libraries.
- cmake ../ -DCMAKE_TOOLCHAIN_FILE=/work/someip/qnx7_aarch64.cmake -DCMAKE_INSTALL_DIR=/work/someip/boost/pavi
- Built BOOST for QNX alone
- To build boost follow: https://www.boost.org/doc/libs/1_46_1/more/getting_started/unix-variants.html#or-build-custom-binaries 
Install bjam with qcc. Then install bootstrap with qcc.
generated files in seperate directory and copied back to below paths:
- /opt/qnx700/host/linux/x86_64/usr/include/boost
- /opt/qnx700/target/qnx7/usr/include/
- /opt/qnx700/target/qnx7/x86/usr/include/
- /opt/qnx700/target/qnx7/x86_64/usr/include/
- Faced errors like missing nanosleep not declared in boost scope. clock, socket, close, fcntl etc
- Added the boost patch changes.
- patch -p1 < path_to_patch
- in QNX, target means the aarch64le etc like that.
commands:
QNX:
- source /opt/qnx700/qnxsdp-env.sh
TEST application based on vsomeip:
- cmake ../ -DCMAKE_TOOLCHAIN_FILE=./qnx7_aarch64.cmake -DENABLE_SIGNAL_HANDLING=1
BOOST Arm64:
- ./bootstrap.sh --prefix=/work/someip/packages/boost-qnx/
- ./b2 -j8 install -d+2 threading=multi address-model=64 abi=aapcs binary-format=elf toolset=qcc cxxflags="-V5.4.0,gcc_ntoaarch64le_gpp -shared -lang-c++ -fexceptions" linkflags="-V5.4.0,gcc_ntoaarch64le_gpp -std=c++11 -fexceptions" archiveflags="-V5.4.0,gcc_ntoaarch64le_gpp" target-os=qnxnto --without-python --without-context --without-coroutine
 
BOOST x64 QNX :
-  ./b2 -j8 install -d+2 threading=multi address-model=64 abi=aapcs binary-format=elf toolset=qcc cxxflags="-V5.4.0,gcc_ntox86_64_gpp -shared -lang-c++ -fexceptions" linkflags="-V5.4.0,gcc_ntox86_64_gpp -std=c++11 -fexceptions" archiveflags="-V5.4.0,gcc_ntox86_64_gpp" target-os=qnxnto --without-python --without-context --without-coroutine
- in the above command, if you use link=static. then only static libraries will be generated.(x64)  
- ./b2 -j8 install -d+2 threading=multi address-model=64 abi=aapcs binary-format=elf --without-python --without-context --without-coroutine
 
SOMEIP:
- cmake ../ -DCMAKE_TOOLCHAIN_FILE=./qnx7_aarch64.cmake 
- DCMAKE_INSTALL_PREFIX:PATH=/work/someip/packages/someip-qnx/ -DBOOST_DIR=/work/someip/packages/boost-qnx/ 
- (x64QNX) cmake ../ -DCMAKE_TOOLCHAIN_FILE=./x64.cmake 
- DCMAKE_INSTALL_PREFIX:PATH=/work/someip/packages/someip-qnx/ -DBOOST_DIR=/work/someip/packages/boost-qnx/ 
- make
- make install
CAPI-CORE: & CAPI-SOMEIP
- cmake ../ -DCMAKE_TOOLCHAIN_FILE=./qnx7_aarch64.cmake 
- DCMAKE_INSTALL_PREFIX=/work/someip/packages/commonapi-core-runtime-qnx/ 
- DBOOST_DIR=/work/someip/packages/boost-qnx/ 
- cmake ../ -DCMAKE_TOOLCHAIN_FILE=./qnx7_aarch64.cmake 
- DCMAKE_INSTALL_PREFIX=/work/someip/packages/commonapi-someip-runtime-qnx/ 
- DBOOST_DIR=/work/someip/packages/boost-qnx/ -DVSOMEIP_DIR=/work/someip/packages/someip-qnx/ -DCommonAPI_DIR=/work/someip/packages/commonapi-core-runtime-qnx 
Above installation path/prefix has to be altered respectively.
- then make and make install
ASIO:
https://think-async.com/Asio/AsioAndBoostAsio.html
https://think-async.com/Asio/
copied asio to /work/someip/package folder. Made ASIO_STANDALONE=1 in detail/config.hpp file in asio commented logging build from CMAKELists.txt
- commented logging/logger*.hpp and cpp.
- removed boost::asio to asio
- removed Connection test:
 
ANDROID:
- ip route add 224.224.224.245 dev eth0 -- Android
- echo 1 > /proc/sys/net/ipv4/ip_forward
- source .sh file
 
QNX:
- export necessary variables.
$ su root
$ sysctl -w net.inet.ip.forwarding=1
$ route -n add 224.224.224.245 192.168.1.1
$ netstat -r
$ route delete <destination> <gateway>
Environment connection:
export VSOMEIP_CONFIGURATION=/data/local/tmp/config/service.json
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/data/local/tmp/libs:/system/lib
VSOMEIP_APPLICATION_NAME=calculator_service ./CalculatorService
VSOMEIP_APPLICATION_NAME=maxbytes_service ./MaxBytesService
export VSOMEIP_CONFIGURATION=/data/local/tmp/config/service.json
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/data/local/tmp/libs
VSOMEIP_APPLICATION_NAME=maxbytes_client ./MaxBytesClient 
QNX:
export VSOMEIP_CONFIGURATION=/pavi/service.json
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/pavi/libs
DLT:
https://github.com/GENIVI/dlt-daemon/issues/52   ----> For setting the dlt in Qualcomm QNX.
COMMONAPI:
- download the commonAPI from genivi. apply patch.
- first build the core and then some-ip.
- cmake ../ -DCMAKE_TOOLCHAIN_FILE=./qnx7_aarch64.cmake 
- DCMAKE_INSTALL_DIR=/work/someip/boost/pavi -read readme
 
 
OS CONCEPTS :
Scheduler:
The goal of process scheduling policies is to use CPU resources wisely, increase throughput, reduce wait time, increase response and turnaround times.
FCFS -> first come first serve
RR -> Round Robin 
SJF -> Shortest job first
priority queue

KERNEL CONCEPTS / BOOT PROCESS:

vmlinuz is Linux kernel executable located /boot/vmlinuz. vmlinuz is a compressed Linux kernel, and it is bootable.
vmlinuz files contains the proper Linux kernel. initrd files are CPIO images, filesystem images. 
The boot loader is responsible for loading both the kernel image and the initrd image into memory. 
They both will be in memory, before the boot loader hands control over to the kernel.

App Armor: It is a Linux kernel security module that allows the system administrator to restrict programs' capabilities with per-program profiles. Profiles can allow capabilities like network access, raw socket access, and the permission to read, write, or execute files on matching paths.
This is specifically used, when you want to profile for the security requirements.

INFRASTRUCTURE CONCEPTS : 

CMAKE

CMAKE creation for project specific: 
https://gitlab.kitware.com/cmake/community/wikis/doc/tutorials/How-to-create-a-ProjectConfig.cmake-file

ANDROID:
NDK:
- Download android-ndk-r17c-linux-x86_64.zip from link below.
https://developer.android.com/ndk/downloads/older_releases.html
https://insight.visteon.com/wiki/JLR-RICM_(Android_RSE) 

DLT doxygen - https://pfefferz.github.io/dlt-daemon-doxygen-built/index.html 

-------------------------------------

GIT COMANDS:
git clone <repo.git> 
git checkout <existingBranchName>
git checkout -b <newBranchname>
git fetch --all // to fech all the latest branches
git branch -a
git pull
git pull --rebase
git diff
git diff <filename>
git status
git add . -> all files from that directory and sub-directory. if compiled files are there, then better do individual add
git commit -m "Updated Gateway, Timesync, HealtManager"
git push
git push origin/remoteBranchName CheckedoutBranchName

git blame
git fetch --prune -> deletes the local branches, not in the remote branches

git reset --hard //to reset local changes
git branch -r // recursively list all the git branches

git checkout -- .                // discards the unstaged files(not new files)
git checkout <filenames>  // discards the unstaged files(not new files)


GIT FORK AND PULL:
- fork a repository from the web portal. This will created a repo like ssh:git**.com:/USER_NAME/*.git
git remote -v                    to see what is the remote branch (it should be pointing to fork branch)
git remote add upstream <USER_NAME git repo>         this will add the upstream in remote
git remote -v                    to re-confirm , whether upstream is added or not
git pull  / git reset --hard        to clear the existing contents and make ready to accept
git fetch upstream            to pull the changes from the original repo to forked repo
git checkout master        mention the branch u want to sync on
git merge upstream/master
git reset --hard upstream/master-next ---- if forced update to be done
git push origin master-next 
git log                               to re-confirm, whether all the changes were pulled or not.

Git global setup
git config --global user.name "PKRISHN9"
git config --global user.email "pkrishn9@visteon.com"

~~~~~~~~~~~ GIT REBASE START ~~~~~~~~~~~~~~~~~~
-> if the new branch created is "branchSample" << sync the code to master >> 
git log
git checkout branchSample
git rebase master       -->  it will happen in first shot, if minimal changes are present>>
git am --show-current-patch
git status
git branch --> it will show the branch for which rebase is hapenning
git diff <filename>   -> Check the individual files, if requires manual edit, do the required changes
git add .
git status
git rebase --continue
~~~~~~~~~~~ GIT REBASE END ~~~~~~~~~~~~~~~~~~

Arm is an hypervisor architecture:
https://developer.arm.com/architectures/learn-the-architecture/armv8-a-virtualization/trapping-and-emulation-of-instructions 

RPMsg:
https://www.kynetics.com/docs/2018/Linux_rpmsg_char_driver/  
(or)   
https://www.kernel.org/doc/Documentation/rpmsg.txt


SYSLOG:
StandardOutput=syslog in systemd code
Also search /var/log/syslog
Find out where they are opening handle.
Check the logger code for Linux + qnx

https://stackoverflow.com/questions/44023742/redirect-stdout-stderr-using-dup2-then-resinstate-later
try as standalone and print fd

Starter | logger

https://stackoverflow.com/questions/22394819/how-to-redirect-a-child-processs-output-to-syslog standalone
 
REFERENCE:
Source: Internet and other books