# FreeRTOS on XMOS
###### tags: `xcore` `xmos`
[SMP Demo for the XMOS XCORE.AI Explorer Board](https://freertos.org/smp-demo-for-xmos-xcore-ai-explorer-board.html)
https://github.com/FreeRTOS/FreeRTOS-SMP-Demos
* The project files for this demo
`FreeRTOS/Demo/XCORE.AI_xClang/RTOSDemo directory`
* FreeRTOS Port files compiled in the project
`FreeRTOS/Source/portable/ThirdParty/xClang/XCORE.AI`
* Common I/O interfaces
GPIO
UART
I2C
I2S
PDM microphones
QSPI flash
SPI
USB
Clock control
* xcore features
Intertile channel communication
Software defined memory (xcore.ai only)
Software defined L2 Cache (xcore.ai only)
* External parts
Silicon Labs WF200 series WiFi transceiver
* Software Services
DHCP server
Dispatcher
FAT filesystem
HTTP parser
JSON parser
MQTT client
SNTP client
TLS
USB stack
WiFi connection manager
---
These drivers are all found in the SDK under the path **modules/rtos/modules/drivers (fwk_rtos/modules/drivers)**.
Abstraction layer is found under the path **modules/rtos/modules/osal (fwk_rtos/modules/osal)**.
These services are all found in the SDK under the path **modules/rtos/modules/sw_services (fwk_rtos/modules/sw_services)**.
A fully functional example application that can be found in the SDK under the path **examples/freertos/explorer_board (xcore_sdk/examples/freertos/explorer_board)**.
Additional code to initialize the SoC platform for this example is provided by a board support configuration library **modules/rtos/modules/board_support/XCORE-AI-EXPLORER_2V0/platform (fwk_rtos/modules/bsp_config/XCORE-AI-EXPLORER_2V0/platform)**.
The bsp_configs provided with the XCORE SDK in **modules/rtos/modules/bsp_config (fwk_rtos/modules/bsp_config)** are an excellent starting point.
* Set XTC environment
* Looking files
* /FreeRTOS/Demo/XCORE.AI_xClang/RTOSDemo/src/FreeRTOSConfig.h
```c
#define configNUM_CORES
...
#define configRUN_MULTIPLE_PRIORITIES
#define configUSE_CORE_AFFINITY
```
* /FreeRTOS-SMP-Demos/FreeRTOS/Demo/XCORE.AI_xClang/RTOSDemo/src/testing_main.h
```c
#define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY 1
```
* /FreeRTOS-SMP-Demos/FreeRTOS/Demo/XCORE.AI_xClang/RTOSDemo/src/XCORE-AI-EXPLORER.xn
```xml
<Packages>
<Package id="0" Type="XS3-UnA-1024-QF60A">
<Nodes>
<Node Id="0" InPackageId="0" Type="XS3-L16A-1024" Oscillator="24MHz" SystemFrequency="600MHz" ReferenceFrequency="100MHz">
<Boot>
<Source Location="bootFlash"/>
</Boot>
<Extmem sizeMbit="1024" Frequency="300MHz">
<Padctrl clk="0x30" cke="0x30" cs_n="0x30" we_n="0x30" cas_n="0x30" ras_n="0x30" addr="0x30" ba="0x30" dq="0x31" dqs="0x31" dm="0x30"/>
</Extmem>
<Tile Number="0" Reference="tile[0]">
<Port Location="XS1_PORT_1B" Name="PORT_SQI_CS"/>
<Port Location="XS1_PORT_1C" Name="PORT_SQI_SCLK"/>
<Port Location="XS1_PORT_4B" Name="PORT_SQI_SIO"/>
<!-- SPI ports -->
<Port Location="XS1_PORT_1A" Name="PORT_SSB"/>
<Port Location="XS1_PORT_1C" Name="PORT_SQI_SCLK_0"/>
<Port Location="XS1_PORT_1D" Name="PORT_SPI_MOSI"/>
<Port Location="XS1_PORT_1P" Name="PORT_SPI_MISO"/>
<!-- I2C ports -->
<Port Location="XS1_PORT_1N" Name="PORT_I2C_SCL"/>
<Port Location="XS1_PORT_1O" Name="PORT_I2C_SDA"/>
<!-- LED -->
<Port Location="XS1_PORT_4F" Name="PORT_LEDS"/>
</Tile>
<Tile Number="1" Reference="tile[1]">
<!-- Mic related ports -->
<Port Location="XS1_PORT_1G" Name="PORT_PDM_CLK"/>
<Port Location="XS1_PORT_1F" Name="PORT_PDM_DATA"/>
<!-- Audio ports -->
<Port Location="XS1_PORT_1D" Name="PORT_MCLK_IN_OUT"/>
<Port Location="XS1_PORT_1C" Name="PORT_I2S_BCLK"/>
<Port Location="XS1_PORT_1B" Name="PORT_I2S_LRCLK"/>
<Port Location="XS1_PORT_1A" Name="I2S_MIC_DATA"/>
<Port Location="XS1_PORT_1K" Name="I2S_DATA_IN"/>
</Tile>
</Node>
</Nodes>
</Package>
</Packages>
```
* /FreeRTOS-SMP-Demos/FreeRTOS/Demo/XCORE.AI_xClang/RTOSDemo/src/partest/partest.c
```c
static int led_seq = 0;
typedef enum {
LED_BLACK = 0xFF,
LED_RED = 0xFD,
LED_GREEN = 0xFB,
LED_BLUE = 0xF7,
LED_YELLOW = 0xF9,
LED_PURPLE = 0xF5,
LED_AQUA = 0xF3,
LED_WHITE = 0xF1,
};
uint8_t led_color[] = {
LED_BLACK, LED_RED, LED_GREEN, LED_BLUE,
LED_YELLOW, LED_PURPLE, LED_AQUA, LED_WHITE
};
...
DEFINE_RTOS_INTERRUPT_CALLBACK( pxLEDUpdateISR, pvData )
{
led_bitmap = led_color[led_seq] & 0xFFFF;
if(xCmd.led==1)
led_seq = (led_seq+1)%8;
}
```