Tuesday, September 26, 2017

Hot skills in Embedded and IoT

Based on my observation in the job market, the following skills are currently in demand in embedded systems surrounding IoT development:

  1. 802.11 (WiFi)
  2. Bluetooth, especially Bluetooth 4.0 + Low Energy (BLE) or newer
  3. Zigbee (IEEE 802.15.4)
  4. Z-Wave: Based on ITU G.9959 (PHY) and Z-Wave Application layer
  5. Bonjour (mDNS/DNS-SD)
  6. SSDP (Simple Service Discovery Protocol)
  7. OCF (Open Connectivity Foundation's uPnP Device Control Protocol)
  8. TCP/UDP
  9. TLS (Transport Layer Security)
  10. CoAP (Constrained Application Protocol; RFC-7252)
  11. HTTP, especially RESt API
  12. MQTT (Mosquitto)
  13. MultiThread
  14. Websockets
  15. RESTful (Representational State Transfer) architecture
  16. Rust (Rust is a programming language that’s focused on safety, speed, and concurrency)
  17. Jenkins
  18. XML
  19. LWM2M
  20. SQS
  21. AMQP
  22. Kafka
  23. AWS (Amazon Web Service)
  24. Microsoft Azure
  25. I2C
  26. SPI
  27. Asynchronous serial/UART programming
  28. Linux Kernel and Driver development



Thursday, September 21, 2017

Pointer to certain address in memory

In embedded system where we are working with microcontroller, many times we find a scenario where we need to access a memory-mapped register in the MCU.  How do we do that in generic way (for example with GCC compiler)?

The answer is to write it like below:

volatile <type> *<varname> = (<type> *)<address>

For example:

#include <stdio.h>

volatile char *var = (char *)0x1000;

int main()
{
    if (*var != 0)
        puts("NOT NULL!");
}

rendered into x86 assembly (64-bit Intel CPU) as:
...
...
.LC0:
        .string "NOT NULL!"

main:
movq var(%rip), %rax      # rax = address of var
movzbl (%rax), %eax         # eax = *var
testb %al, %al
jne .L9
xorl %eax, %eax
ret
.L9:
pushq %rax
movl $.LC0, %edi
call puts
xorl %eax, %eax
popq %rdx
ret

...
.LCOLDE1:
.section .text.startup
.LHOTE1:
.globl var
.data
.align 8
.type var, @object
.size var, 8
var:
.quad 4096           # or 0x1000

Wednesday, September 20, 2017

Deleting duplicate entries and sorting the rest

I learned an interesting (and very easy) way to remove duplicate entries as well as to sort them. Basically, in C++ it is achieved by creating a new set and initialize with values from the vector.  We shift all the hardwork to the std library to do this.

#include <iostream>
#include <vector>
#include <set>


void print(std::vector<int> &v)
{
    std::cout << "[";
    for(std::vector<int>::iterator it = v.begin(); it != v.end(); ++it)
    {
        std::cout << *it << ",";
    }
    std::cout << "]" << std::endl;
}


void print(std::set<int> &v)
{
    std::cout << "{";
    for(std::set<int>::iterator it = v.begin(); it != v.end(); ++it)
    {
        std::cout << *it << ",";
    }
    std::cout << "}" << std::endl;
}



int main()
{
    int inits[] = {1,10,3,2,2,4,4,5,6,7,8,8,9};
    std::vector<int> vec(inits, inits + sizeof(inits)/sizeof(inits[0]));
    print(vec);
    std::set<int> ves(vec.begin(), vec.end()); // both sorted & unique already
    print(ves);
}