Introduction
Many people have heard of the word IoT (Internet of Things), more and more people in the decoration began to choose smart Home, many people also buy smart speakers to do smart home control, presumably the future must be AI + Internet of things era.
To develop and mature a technology, we must reduce the threshold and improve the speed of iteration. Traditional embedded development is too fragmented, and many times the development method of copying, pasting, and modifying code is used. It is difficult to develop more advanced applications if you do not provide an out-of-the-box development platform that allows bricks to cascade on top of one another.
So a platform like this is needed:
- Provides sufficient hardware abstraction capabilities
- Provides a friendly programming interface and debug interface
The combination of IoT features also:
- Flexible control of non-standard custom hardware
- Operating equipment adapted to limited resources
As a result, IoT operating systems emerged.
Many companies have started to lay out IoT operating systems such as Rt-thread, Huawei's LiteOS, etc.
Chino OS
The Chino OS is an open source IoT operating system designed and developed by a development team including me. GitHub Address: Github.com/chino-os/chino-os
Chino is written primarily in the C + + language, with a dedicated GNU toolchain and C Runtime Library, using Devicetree to describe the hardware configuration. Currently the system has the following features:
- Multitasking (6 priority, Round Robin Scheduler)
- Thread synchronization (mutex, recurisve mutex, Semaphore, Event)
- interprocess communication (Mailslot)
- A unified drive model
- Network Support (LwIP-based Socket API)
Chino pre-defined a set of drive interfaces that provide a unified API layer for application developers, leaving most of the developer's needs free of specific hardware differences. Some devices are abstracted from the following table:
category |
Subclass |
Example Driver |
Interrupt Controller |
|
cortex-m3, Nvic |
io/bus |
gpio |
stm32f10x, Gpio |
I²C |
stm32f10x, I²c |
SPI |
stm32f10x, SPI |
serial |
stm32f10x, UART |
SDIO |
stm32f10x, SDIO |
storage |
EEPROM |
AT24C02 |
Flash |
gd25q128 |
SD memory card |
SD V2.0 mass Storage |
display |
TFT LCD |
ili9486l |
network |
Ethernet |
enc28j60 |
sensor |
Accelerometer |
ADXL345 |
Chino currently supports x86_64, CORTEX-M3 architectures that can be run on PC and STM32 development boards. Future plans support more architectures such as ESP32, RISCV32/64 and more.
Chino operation on the stm32f103 Development Board
code Example 1. GPIO Light Small Lamp
Bright small lights can be said to be embedded development of Hello world.
1Auto Access = Oa_read |Oa_write;2Auto Gpio = G_objectmgr->getdirectory (Wkd_device). Open ("Gpio3", access). Moveas<gpiocontroller>();3Auto Pin0 = Gpio->openpin (0, access);4Pin0->Setdrivemode (gpiopindrivemode::output);5 6 while(true)7 {8Pin0->Write (gpiopinvalue::low);9G_processmgr->sleepcurrentthread (1s);TenPin0->Write (gpiopinvalue::high); OneG_processmgr->sleepcurrentthread (1s); A}
Program request read and Write permissions open the GPIO controller named "Gpio3", then open the No. 0 pin and set the driver mode for the pin to output.
Then the interval 1s toggles the output high and low level.
This code hides the specifics of the hardware and can be run without the need to modify the code on any hardware with GPIO.
2. Read and write Flash
1Auto Flash1 = G_objectmgr->getdirectory (Wkd_device). Open ("Flash1", access). Moveas<flashstorage>();2 {3gsl::span<Constuint8_t> writebuffers[] ={buffer};4Flash1->write (0, {writebuffers});5 }6 {7gsl::span<uint8_t> readbuffers[] ={buffer};8Kassert (Flash1->read (0, {readbuffers}) = =std::size (buffer));9G_logger->putstring ("gd25q128 read:\n");TenG_logger->dumphex (buffer, std::size (buffer)); One}
This code is simple: write the data and then read the data after you open flash. The only thing to note is that the IO portion of Chino uses bufferlist to read and write data, so it can support multiple noncontiguous memory segments to read and write, with no replication overhead.
3. TCP Echo
1Auto eth0 = G_networkmgr->installnetworkdevice (G_objectmgr->getdirectory (Wkd_device). Open ("eth0", Oa_read | Oa_write). Moveas<ethernetcontroller>());2Eth0->SetAsDefault ();3Eth0->Setup ();4G_networkmgr->Run ();5 6Auto bindaddr = std::make_shared<ipendpoint> (Ipaddress::ipv4any, the);7Auto Socket = makeobject<socket>(Addressfamily::ipv4, Sockettype::stream, protocoltype::tcp);8Socket->Bind (bindaddr);9Socket->listen (1);Ten OneAuto client = socket->Accept (); A while(true) - { - Constuint8_t text[] ="hello\n"; thegsl::span<ConstUint8_t> buffers[] = {{text,6} }; - - Try - { +Client->Send ({buffers}); -G_processmgr->sleepcurrentthread (1s); + } A Catch (...) at { - Break; - } -}
The program opens an Ethernet controller named "eth0" and registers it with the network subsystem.
Then create a TCP Socket and listen for 80 ports.
Accept a client connection and loop out the hello until the connection is closed and exit the loop.
Series Description
As the first article of Chino operating system development log, this paper briefly summarizes the development progress and basic programming model of Chino. Future articles will describe in detail the latest developments in the design and development of each subsystem.
You are welcome to make criticisms and suggestions to help Chino develop better.
Finally again attached Chino project address: Github.com/chino-os/chino-os, I hope you more star, more mention issue.