This beast is really awesome. For about $6 (on eBay), we can get a full functional IoT system using ESP32 application SoC made by a Chinese company called Espressif. The CPU core is based on XTensa architecture. XTensa is a CPU/MCU architecture designed by a Silicon Valley-based company named Cadence Tensilica. Cadence Tensilica, according to
Wikipedia, was founded by the former co-founder of the MIPS Technologies (one of the first player in RISC CPU architecture), Chris Rowen.
Espressif bought the IP rights to use in their own SoC products such as in ESP32 series. ESP32 itself is an evolutional product of its predecessor, ESP8266. A lot of features in this tiny SoC, such as WiFi & Bluetooth, cryptographic co-processor, Hall sensor, generous amount of ADC inputs (but multiplexed with other GPIOs), 2 DAC outputs, SPI, I2S, I2C, ultra-low power coprocessor, Ethernet MAC MII interface (but we need to add PHY interface to connect to a medium), temperature sensor, touch sensors, CAN, 4 MB flash, etc.
Another interesting and cool thing is there a bunch of toolkits, SDK etc., including FreeRTOS support. Configuring the device can be as easy with menu-driven a-la Linux Kernel.
The Extensa ISA is actually a hybrid of RISC and CISC ISA. As detailed in the documents at
Github, about it has about 80 RISC instructions with length 24 or 16-bit (unlike common RISC instructions which uniformly 32 bits). The architecture let the SoC designers customize it to add several extended CISC instructions to speed up and save memory space. The CPU endianness is also changeable between Little and Big endian.
The extended instructions, among others, are to support MAC (Multiply-Accumulate) which is common in DSP applications and other media processing operations. Another thing is the support for coprocessors.
Below is an example to blink the onboard LED (GPIO2) with FreeRTOS:
/* Blink Example
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#include "sdkconfig.h"
/* Can run 'make menuconfig' to choose the GPIO to blink,
or you can edit the following line and set a number here.
*/
#define BLINK_GPIO CONFIG_BLINK_GPIO
void blink_task(void *pvParameter)
{
/* Configure the IOMUX register for pad BLINK_GPIO (some pads are
muxed to GPIO on reset already, but some default to other
functions and need to be switched to GPIO. Consult the
Technical Reference for a list of pads and their default
functions.)
*/
gpio_pad_select_gpio(BLINK_GPIO);
/* Set the GPIO as a push/pull output */
gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);
while(1) {
/* Blink off (output low) */
gpio_set_level(BLINK_GPIO, 0);
vTaskDelay(1000 / portTICK_PERIOD_MS);
/* Blink on (output high) */
gpio_set_level(BLINK_GPIO, 1);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}
void app_main()
{
xTaskCreate(&blink_task, "blink_task", configMINIMAL_STACK_SIZE, NULL, 5, NULL);
}
As described in
https://www.freertos.org/a00125.html, the format of task creation API is:
BaseType_t xTaskCreate( TaskFunction_t pvTaskCode,
const char * const pcName,
unsigned short usStackDepth,
void *pvParameters,
UBaseType_t uxPriority,
TaskHandle_t *pxCreatedTask
)
Each task is assigned a priority from 0 to ( configMAX_PRIORITIES - 1 ), where 0 is the lowest priority and configMAX_PRIORITIES is defined within FreeRTOSConfig.h:
/* This has impact on speed of search for highest priority */
#ifdef SMALL_TEST
#define configMAX_PRIORITIES ( 7 )
#else
#define configMAX_PRIORITIES ( 25 )
#endif
Low priority numbers denote low priority tasks. The idle task has priority zero (tskIDLE_PRIORITY).