### Compile and Link with MetaWare Development Toolkit (Windows) Source: https://arc-labs.readthedocs.io/en/latest/getting_started/getting_started This command demonstrates how to compile and link a C file using the MetaWare C Compiler (ccac) on Windows. It assumes you are in the demos directory of the MetaWare installation. ```batch cd C:\ARC\MetaWare\arc\demos ccac queens.c ``` -------------------------------- ### Build Secondary Bootloader for EMSK (GNU ARCEM7D) Source: https://arc-labs.readthedocs.io/en/latest/labs/level1/lab6 Compiles the secondary bootloader binary for the EM Starter Kit using the GNU toolchain for the ARC EM7D core. This command assumes you are in the bootloader example directory and have the embARC root path set up. ```bash cd /example/baremetal/bootloader make BOARD=emsk BD_VER=22 CUR_CORE=arcem7d TOOLCHAIN=gnu bin ``` -------------------------------- ### Compile and run EM Starter Kit example Source: https://arc-labs.readthedocs.io/en/latest/labs/level1/lab5 This snippet shows the commands to compile and run the lab5_emsk example on the EM Starter Kit using the GNU toolchain. It navigates to the directory and executes the make command with specific board configurations. ```shell cd /arc_labs/lab5_emsk make BOARD=emsk BD_VER=22 CUR_CORE=arcem7d TOOLCHAIN=gnu run ``` -------------------------------- ### Clone ARC labs repository Source: https://arc-labs.readthedocs.io/en/latest/getting_started/getting_started This snippet shows how to clone the ARC labs repository using git to the root folder of embARC OSP. This is the primary step for obtaining the source code. ```shell cd path/to/embarc_osp git clone https://github.com/foss-for-synopsys-dwc-arc-processors/arc_labs.git arc_labs ``` -------------------------------- ### Cloning embARC OSP Repository using Git Source: https://arc-labs.readthedocs.io/en/latest/getting_started/getting_started This code snippet shows how to clone the embARC OSP source code repository from GitHub using Git. It includes commands for both Windows and Linux environments to ensure the repository is cloned into the user's home directory. ```git # On Windows cd %userprofile% # On Linux cd ~ git clone https://github.com/foss-for-synopsys-dwc-arc-processors/embarc_osp.git embarc_osp ``` -------------------------------- ### Compile and run IoT Development Kit example Source: https://arc-labs.readthedocs.io/en/latest/labs/level1/lab5 This snippet demonstrates the commands to compile and run the lab5_iotdk example on the IoT Development Kit using the GNU toolchain. It involves changing the directory and executing a make command with relevant board and toolchain settings. ```shell cd /arc_labs/lab5_iotdk make BOARD=iotdk TOOLCHAIN=gnu run ``` -------------------------------- ### HTTP Request Example for Sending Data Source: https://arc-labs.readthedocs.io/en/latest/labs/level2/lab10 An example of an HTTP GET request to retrieve a favicon, commonly used to initiate or test a connection. It includes headers like Host, Connection, User-Agent, Accept, Referer, and Accept-Encoding. ```http GET /favicon.ico HTTP/1.1 Host: 192.168.137.236 Connection: keep-alive User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Accept: image/webp,image/apng,image/*,*/*;q=0.8 Referer: http://192.168.137.236/ Accept-Encoding: gzip, deflate Accept-Language: zh-CN,zh;q=0.9 ``` -------------------------------- ### Navigate to Blinky Example Directory Source: https://arc-labs.readthedocs.io/en/latest/labs/level1/lab2 This command shows how to change the current directory to the 'blinky' example folder within the embARC OSP package. This is a prerequisite for building and running the example. ```bash cd example\baremetal\blinky ``` -------------------------------- ### Build and Run Blinky Example with ARC GNU Toolchain Source: https://arc-labs.readthedocs.io/en/latest/labs/level1/lab2 Demonstrates how to build and run the 'blinky' example using the ARC GNU Toolchain. It specifies commands for different board versions (EMSK 2.3, EMSK 2.2) and the IoTDK, including board and core configurations. ```makefile # For EMSK 2.3 make TOOLCHAIN=gnu BOARD=emsk BD_VER=23 CUR_CORE=arcem11d run # For EMSK 2.2 make TOOLCHAIN=gnu BOARD=emsk BD_VER=22 CUR_CORE=arcem7d run # For IoTDK make TOOLCHAIN=gnu BOARD=iotdk run ``` -------------------------------- ### Run AWS IoT Smart Home Demo Source: https://arc-labs.readthedocs.io/en/latest/labs/level3/lab11 Command to build and run the AWS IoT smart home demonstration on the EMSK board using the GNU toolchain. This command initiates the build process and deploys the application. ```bash make TOOLCHAIN=gnu BD_VER=22 CUR_CORE=arcem7d run ``` -------------------------------- ### Debug Blinky Example with ARC GNU Toolchain Source: https://arc-labs.readthedocs.io/en/latest/labs/level1/lab2 Provides commands to debug the 'blinky' example using the ARC GNU Toolchain. It includes specific commands for different board versions (EMSK 2.3, EMSK 2.2) and the IoTDK, initiating a GUI debugging session. ```makefile # For emsk 2.3 make TOOLCHAIN=gnu BOARD=emsk BD_VER=23 CUR_CORE=arcem11d gui # For emsk 2.2 make TOOLCHAIN=gnu BOARD=emsk BD_VER=22 CUR_CORE=arcem7d gui # For IoTDK make TOOLCHAIN=gnu BOARD=iotdk gui ``` -------------------------------- ### ESP8266 AT Command Sequence for WiFi and Server Setup Source: https://arc-labs.readthedocs.io/en/latest/labs/level2/lab10 This sequence of AT commands is used with an ESP8266 module to connect to a WiFi network, set up a server, and retrieve the IP address. It includes commands for setting WiFi mode, joining an access point, configuring server parameters, and getting the local IP. ```text =========================== Init ============================ [at_parser_init]57: obj->psio 0x800066c8 -> 0x80001330 [at_send_cmd]87: command is NULL, send AT test command [at_send_cmd]131: at_out: "AT\n" (4) [at_get_reply]154: "AT\n\nOK" (9) ============================ Set Mode ============================ [at_send_cmd]131: at_out: "AT+CWMODE_CUR?\n" (16) [at_get_reply]154: "\nAT+CWMODE_CUR?\n+CWMODE_CUR:1\n\nOK" (38) CWMODE_CUR = 1 [at_send_cmd]131: at_out: "AT+CWMODE_CUR=3\n" (17) [at_get_reply]154: "\nAT+CWMODE_CUR=3\n\nOK" (24) ============================ Connect WiFi ============================ [at_send_cmd]131: at_out: "AT+CWLAP\n" (10) [at_get_reply]154: "\nAT+CWLAP\n+CWLAP:(0,\"synopsys-guest\",-71,\"6c:f3:7f:a8:a1:21\",1,-27,0)\n+CWLAP:(5,\"Synopsys\",-70,\"6c:f3:7f:a8:a1:22\",1,-27,0)\n+CWLAP:(0,\"synopsys-guest\",-94,\"d8:c7:c8:43:5b:81\",1,-19,0)\n+CWLAP:(5,\"Synopsys\",-95,\"d8:c7:c8:43:5b:83\",1,-21,0)\n+CWLAP:(0,\"iFuture\",-94,\"d4:68:ba:06:65:4a\",1,-16,0)\n+CWLAP:(4,\"iFuture_City\",-93,\"d4:68:ba:0e:65:09\",3,-4,0)\n+CWLAP:(3,\"embARC\",-62,\"5e:e0:c5:4f:df:80\",6,32767,0)\n\nOK" (416) Searching for WIFI "embARC" ...... WIFI "embARC" found! Try to connect [at_send_cmd]131: at_out: "AT+CWMODE_CUR=1\n" (17) [at_get_reply]154: "\nAT+CWMODE_CUR=1\n\nOK" (24) [at_send_cmd]131: at_out: "AT+CWJAP_CUR=\"embARC\",\"qazwsxedc\"\n" (35) [at_get_reply]154: "\nAT+CWJAP_CUR=\"embARC\",\"qazwsxedc\"\nWIFI DISCONNECT WIFI CONNECTED WIFI GOT IP\n\nOK" (88) WIFI "embARC" connect succeed ============================ Connect Server ============================ [at_send_cmd]131: at_out: "AT+CIPMUX=1\n" (13) [at_get_reply]154: "\nAT+CIPMUX=1\n\nOK" (20) [at_send_cmd]131: at_out: "AT+CIPSERVER=1,80\n" (19) [at_get_reply]154: "\nAT+CIPSERVER=1,80\nno change\n\nOK" (37) ============================ Show IP ============================ [at_send_cmd]131: at_out: "AT+CIFSR\n" (10) [at_get_reply]154: "\nAT+CIFSR\n+CIFSR:STAIP,\"192.168.137.236\"\n+CIFSR:STAMAC,\"5c:cf:7f:0b:5f:9a\"\n\nOK" (84) ``` -------------------------------- ### FreeRTOS System Initialization and Task Creation Example in C Source: https://arc-labs.readthedocs.io/en/latest/labs/level2/lab9 Demonstrates the initialization of FreeRTOS tasks, a binary semaphore, and a queue. It includes task creation with specified priorities and stack sizes, semaphore creation and yielding, and queue creation. The main function suspends and resumes tasks to manage execution flow. ```c #include "embARC.h" #include "embARC_debug.h" #include static void task1(void *par); static void task2(void *par); static void task3(void *par); #define TSK_PRIOR_1 (configMAX_PRIORITIES-1) #define TSK_PRIOR_2 (configMAX_PRIORITIES-2) #define TSK_PRIOR_3 (configMAX_PRIORITIES-3) // Semaphores static SemaphoreHandle_t sem1_id; // Queues static QueueHandle_t dtq1_id; // Task IDs static TaskHandle_t task1_handle = NULL; static TaskHandle_t task2_handle = NULL; static TaskHandle_t task3_handle = NULL; int main(void) { vTaskSuspendAll(); // Create Tasks if (xTaskCreate(task1, "task1", 128, (void *)1, TSK_PRIOR_1, &task1_handle) != pdPASS){ /*!< FreeRTOS xTaskCreate() API function */ EMBARC_PRINTF("Create task1 Failed\r\n"); return -1; } else { EMBARC_PRINTF("Create task1 Successfully\r\n"); } if (xTaskCreate(task2, "task2", 128, (void *)2, TSK_PRIOR_2, &task2_handle) != pdPASS){ /*!< FreeRTOS xTaskCreate() API function */ EMBARC_PRINTF("Create task2 Failed\r\n"); return -1; } else { EMBARC_PRINTF("Create task2 Successfully\r\n"); } if (xTaskCreate(task3, "task3", 128, (void *)3, TSK_PRIOR_3, &task3_handle) != pdPASS){ /*!< FreeRTOS xTaskCreate() API function */ EMBARC_PRINTF("Create task3 Failed\r\n"); return -1; } else { EMBARC_PRINTF("Create task3 Successfully\r\n"); } // Create Semaphores sem1_id = xSemaphoreCreateBinary(); xSemaphoreGive(sem1_id); // Create Queues dtq1_id = xQueueCreate(8, sizeof(uint32_t)); xTaskResumeAll(); vTaskSuspend(NULL); return 0; } static void task1(void *par) { uint32_t led_val = 0; static portTickType xLastWakeTime; const portTickType xFrequency = pdMS_TO_TICKS(10); // Use current time to init xLastWakeTime, mind the difference with vTaskDelay() xLastWakeTime = xTaskGetTickCount(); while (1) { /* call Freertos system function for 10ms delay */ vTaskDelayUntil( &xLastWakeTime,xFrequency ); //####Insert code here### } } static void task2(void *par) { uint32_t led_val = 0x0001; static portTickType xLastWakeTime; const portTickType xFrequency = pdMS_TO_TICKS(100); // Use current time to init xLastWakeTime, mind the difference with vTaskDelay() xLastWakeTime = xTaskGetTickCount(); while (1) { /* call Freertos system function for 100ms delay */ vTaskDelayUntil( &xLastWakeTime,xFrequency ); //####Insert code here### } } static void task3(void *par) { uint32_t led_val = 0; static portTickType xLastWakeTime; const portTickType xFrequency = pdMS_TO_TICKS(200); // Use current time to init xLastWakeTime, mind the difference with vTaskDelay() xLastWakeTime = xTaskGetTickCount(); while (1) { /* call Freertos system function for 100ms delay */ vTaskDelayUntil( &xLastWakeTime,xFrequency ); //####Insert code here### } } ``` -------------------------------- ### Build and Run ARC Timer Lab Source: https://arc-labs.readthedocs.io/en/latest/labs/level1/lab3 Provides the command to navigate to the ARC timer lab directory and build/run the example on an ARC EM Starter Kit using the GNU toolchain. ```bash cd /arc_labs/labs/lab_timer # for emsk make BOARD=emsk BD_VER=22 CUR_CORE=arcem7d TOOLCHAIN=gnu run ``` -------------------------------- ### Build and Run Timer Interrupt Example (GNU Toolchain) Source: https://arc-labs.readthedocs.io/en/latest/labs/level1/lab4 This command builds and runs a timer interrupt handling example for the emsk board using the ARC EM Starter Kit (emsk) with the ARC EM7D core and the GNU toolchain. It navigates to the lab directory and executes the make command. ```bash cd /arc_labs/labs/lab4_interrupt/part1 # for emsk make BOARD=emsk BD_VER=22 CUR_CORE=arcem7d TOOLCHAIN=gnu run ``` -------------------------------- ### Setting Debug Configurations in MetaWare Source: https://arc-labs.readthedocs.io/en/latest/labs/level1/lab1 Guides users on how to configure debugging sessions within the MetaWare Development Toolkit. This involves opening the Debug Configurations dialog, creating a new launch configuration, and verifying project details. ```text Click the **Run** > **Debug Configurations…** menu option to open the **Debug Configurations** dialog. Double-click **C/C++ Application** or right-click **New** to create a new launch configuration. If a project is selected in the Project Explorer view all data is automatically entered, take a moment to verify its accuracy or change as needed. Here you do not need to make any changes, just click **Debug** to enter the debugging interface. ``` -------------------------------- ### Program Secondary Bootloader to SPI Flash on EMSK using ntshell Source: https://arc-labs.readthedocs.io/en/latest/labs/level1/lab6 This section outlines the steps to program a pre-compiled secondary bootloader binary onto the SPI Flash of an EMSK board. It involves copying the binary to an SD card, entering ntshell mode on the board, and using the `spirw` command for flashing and verification. ```bash Run _spirw_ to show help Run _spirw -i_ to check SPI Flash ID, it should be **Device ID = ef4018** Run _spirw -w em7d_2bt.bin 0x17f00000 0x17f00004_ to program spiflash Check the output message to see if it has been programmed successfully ``` -------------------------------- ### Build Secondary Bootloader for IoTDK (MW ARCEM9D) Source: https://arc-labs.readthedocs.io/en/latest/labs/level1/lab6 Compiles the secondary bootloader binary for the IoT Development Kit using the embARC framework for the ARC EM9D core. This process requires modifying the makefile to exclude application memory configuration. ```bash remove **APPL_DEFINES += -DUSE_APPL_MEM_CONFIG** in makefile, build and run the `/example/baremetal/bootloader` example, and enter to ntshell command mode. ``` -------------------------------- ### Program Secondary Bootloader to SPI Flash on IoTDK using ntshell Source: https://arc-labs.readthedocs.io/en/latest/labs/level1/lab6 This section details the procedure for programming a secondary bootloader onto the IoT Development Kit's SPI Flash. It involves preparing an SD card with the bootloader binary and a configuration file, then using the `flash` command within ntshell for eflash and bootspi programming. ```bash Run _flash -h_ to show help Run _flash -eflsh simple_bootloader.bin_ to program eflash Run _flash -bootspi simple_bootloader.bin_ to program bootspi flash Check the output message to see if it was programmed successfully ``` -------------------------------- ### Main Function: Timer0 Initialization and Interrupt Configuration Source: https://arc-labs.readthedocs.io/en/latest/labs/level1/lab4 This C code shows the main function for setting up Timer0 interrupts. It disables the timer and interrupt, installs the ISR, sets its priority, and then enables both. The timer is started with specific control flags and a period for 1ms interrupts. The main loop continuously prints the elapsed time. ```c int main(void) { int_disable(INTNO_TIMER0); arc_timer_stop(TIMER_0); int_handler_install(INTNO_TIMER0, timer0_isr); int_pri_set(INTNO_TIMER0, INT_PRI_MIN); EMBARC_PRINTF("\r\nThis is a example about timer interrupt.\r\n"); EMBARC_PRINTF("\r\n/******** TEST MODE START ********/\r\n\r\n"); int_enable(INTNO_TIMER0); arc_timer_start(TIMER_0, TIMER_CTRL_IE | TIMER_CTRL_NH, COUNT); while(1) { timer0_delay_ms(1000); EMBARC_PRINTF("\r\n %ds.\r\n",second); second ++; } return E_SYS; } ``` -------------------------------- ### HTTP Request and Response Handling with ESP8266 Source: https://arc-labs.readthedocs.io/en/latest/labs/level2/lab10 This log shows the process of sending an HTTP GET request to a server and receiving a response. It involves using AT commands to send data and manage the connection, demonstrating client-server interaction. ```text ============================ send ============================ The message is: 0,CONNECT 1,CONNECT +IPD,0,384:GET / HTTP/1.1 Host: 192.168.137.236 Connection: keep-alive Upgrade-Insecure-Requests: 1 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8 Accept-Encoding: gzip, deflate Accept-Language: zh-CN,zh;q=0.9 Send Start [at_send_cmd]131: at_out: "AT+CIPSEND=0,44\n" (17) [at_get_reply]154: "AT+CIPSEND=0,44\n\nOK" (22) [at_get_reply]154: ">\nRecv 44 bytes\n\nSEND OK" (30) [at_send_cmd]131: at_out: "AT+CIPSEND=0,93\n" (17) [at_get_reply]154: "\nAT+CIPSEND=0,93\n\nOK" (24) [at_get_reply]154: ">\nRecv 93 bytes\n\nSEND OK" (30) [at_send_cmd]131: at_out: "AT+CIPSEND=0,93\n" (17) [at_get_reply]154: "\nAT+CIPSEND=0,93\n\nOK" (24) [at_get_reply]154: ">\nRecv 93 bytes\n\nSEND OK" (30) [at_send_cmd]131: at_out: "AT+CIPCLOSE=0\n" (15) [at_get_reply]154: "\nAT+CIPCLOSE=0\n0,CLOSED\n\nOK" (32) ``` -------------------------------- ### Gmake Command for ARC DSP Compilation Source: https://arc-labs.readthedocs.io/en/latest/labs/level2/lab_dsp1 Example command to compile C code using the gmake build system with specific Metaware compiler options for ARC DSP extensions and optimization level O2. ```bash gmake BOARD=iotdk BD_VER=10 CUR_CORE=arcem9d TOOLCHAIN=mw ADT_COPT="-Hfxapi -Xdsp2" OLEVEL=O2 ``` -------------------------------- ### C Code Example for DSP Optimization Source: https://arc-labs.readthedocs.io/en/latest/labs/level2/lab_dsp1 A C code snippet demonstrating a multiply-accumulate operation within a loop, intended for optimization using Metaware's DSP extensions. ```c #include short test(short *a, short *b) { int i; long acc = 0; for(i = 0; i < 10; i++) acc += ( ((long)(*a++)) * *b++) <<1 ; return (short) (acc); } short a[] = {1,2,3,4,5, 6,7,8,9,10}; short b[] = {11,12,13,14,15, 16,17,18,19,20}; int main(int argc, char *argv[]) { short c = test(a,b); printf("result=%d",c); return 0; } ``` -------------------------------- ### ESP8266 WiFi Server Implementation in C Source: https://arc-labs.readthedocs.io/en/latest/labs/level2/lab10 This C code initializes the ESP8266 module, connects it to a specified WiFi network, and sets up an HTTP server on port 80. It listens for incoming GET requests and responds with a simple HTML page. Dependencies include embARC libraries for hardware interaction and AT commands. ```c #include "embARC.h" #include "embARC_debug.h" #include "board.h" #include "esp8266.h" #include #include #define WIFI_SSID "\"embARC\"" #define WIFI_PWD "\"qazwsxedc\"" static char http_get[] = "GET /"; static char http_IDP[] = "+IPD,"; static char http_html_header[] = "HTTP/1.x 200 OK\r\nContent-type: text/html\r\n\r\n"; static char http_html_body_1[] = "ESP8266_AT_HttpServer

Welcome to this Website

"; static char http_html_body_2[] = "

This Website is used to test the AT command about HttpServer of ESP8266.

"; static char http_server_buf[1024]; int main(void) { char *conn_buf; //ESP8266 Init EMBARC_PRINTF("============================ Init ============================\n"); ESP8266_DEFINE(esp8266); esp8266_init(esp8266, UART_BAUDRATE_115200); at_test(esp8266->p_at); board_delay_ms(100, 1); //Set Mode EMBARC_PRINTF("============================ Set Mode ============================\n"); esp8266_wifi_mode_get(esp8266, false); board_delay_ms(100, 1); esp8266_wifi_mode_set(esp8266, 3, false); board_delay_ms(100, 1); //Connect WiFi EMBARC_PRINTF("============================ Connect WiFi ============================\n"); do { esp8266_wifi_scan(esp8266, http_server_buf); EMBARC_PRINTF("Searching for WIFI %s ……..\n", WIFI_SSID); board_delay_ms(100, 1); } while (strstr(http_server_buf, WIFI_SSID)==NULL); EMBARC_PRINTF("WIFI %s found! Try to connect\n", WIFI_SSID); while (esp8266_wifi_connect(esp8266, WIFI_SSID, WIFI_PWD, false) != AT_OK) { EMBARC_PRINTF("WIFI %s connect failed\n", WIFI_SSID); board_delay_ms(100, 1); } EMBARC_PRINTF("WIFI %s connect succeed\n", WIFI_SSID); //Creat Server EMBARC_PRINTF("============================ Connect Server ============================\n"); esp8266_tcp_server_open(esp8266, 80); //Show IP EMBARC_PRINTF("============================ Show IP ============================\n"); esp8266_address_get(esp8266); board_delay_ms(1000, 1); while (1) { memset(http_server_buf, 0, sizeof(http_server_buf)); at_read(esp8266->p_at ,http_server_buf ,1000); board_delay_ms(200, 1); //EMBARC_PRINTF("Alive\n"); if (strstr(http_server_buf, http_get) != NULL) { EMBARC_PRINTF("============================ send ============================\n"); EMBARC_PRINTF("\nThe message is:\n%s\n", http_server_buf); conn_buf = strstr(http_server_buf, http_IDP) + 5; *(conn_buf+1) = 0; EMBARC_PRINTF("Send Start\n"); board_delay_ms(10, 1); esp8266_connect_write(esp8266, http_html_header, conn_buf, (sizeof(http_html_header)-1)); board_delay_ms(100, 1); esp8266_connect_write(esp8266, http_html_body_1, conn_buf, (sizeof(http_html_body_1)-1)); board_delay_ms(300, 1); esp8266_connect_write(esp8266, http_html_body_2, conn_buf, (sizeof(http_html_body_2)-1)); board_delay_ms(300, 1); esp8266_CIPCLOSE(esp8266, conn_buf); EMBARC_PRINTF("Send Finish\n"); } } return E_OK; } ``` -------------------------------- ### Start BLE Advertisement with RN4020 in embARC OSP Source: https://arc-labs.readthedocs.io/en/latest/labs/level2/lab7 Initiates BLE advertisement using the RN4020 module via the embARC OSP library. This function is called after the module has been configured. ```c rn4020_advertise(rn4020_ble); ``` -------------------------------- ### Build and Run Command for EMSK Board Source: https://arc-labs.readthedocs.io/en/latest/labs/level1/lab4 This command demonstrates how to build and run the timer interrupt example on the EMSK development board using GNU toolchain. It specifies the board, board version, core, and toolchain. ```shell $ cd /arc_labs/labs/lab4_interrupt/part2 # for emsk $ make BOARD=emsk BD_VER=22 CUR_CORE=arcem7d TOOLCHAIN=gnu run ``` -------------------------------- ### Programming ARC Timer0 with embARC OSP Source: https://arc-labs.readthedocs.io/en/latest/labs/level1/lab3 Shows how to program Timer0 on ARC processors using the `arc/arc_timer.h` API from embARC OSP. This includes initializing, starting, stopping, and reading timer values to measure code execution time. ```c #include "arc/arc_timer.h" // Initialize Timer0 timer_init(TIMER0, TIMER_RESET, TIMER_NO_WAKEUP); // Start Timer0 timer_start(TIMER0); // ... code to measure ... // Stop Timer0 timer_stop(TIMER0); // Read Timer0 count value unsigned int timer_count = timer_get_current_count(TIMER0); ``` -------------------------------- ### Define Memory Blocks and Section Mapping - Linker Script Source: https://arc-labs.readthedocs.io/en/latest/labs/level2/lab8 This linker script defines a new memory block named 'MyBlock' with a starting address and size. It then maps the 'modify_seg' section into this 'MyBlock', controlling where the code resides in memory. ```linker-script MEMORY { // Note: overlap of code and data spaces is not recommended since it makes // Address validity checking impossible with the debugger and simulator MyBlock: ORIGIN = 0x00002000, LENGTH = 32K MEMORY_BLOCK1: ORIGIN = 0x0010000, LENGTH = 64K MEMORY_BLOCK2: ORIGIN = 0x0020000, LENGTH = 128K } SECTIONS { GROUP: { modify_seg: {} }>MyBlock ...... ``` -------------------------------- ### Timer0 Interrupt Service Routine (ISR) Example Source: https://arc-labs.readthedocs.io/en/latest/labs/level1/lab4 This C code demonstrates a basic interrupt service routine for Timer0. It clears the timer interrupt flag and increments a global counter. This pattern can be used for other interrupt handlers. ```c static void timer0_isr(void *ptr) { arc_timer_int_clear(TIMER_0); t0++; } ``` -------------------------------- ### IoTDK Main Function for Timer Interrupt Nesting Source: https://arc-labs.readthedocs.io/en/latest/labs/level1/lab4 Configures and starts Timer0 and Timer1 with specific interrupt priorities and ISRs. The main loop dynamically alters interrupt priorities to demonstrate and manage interrupt nesting, periodically reconfiguring timers based on the 'hits' and 'nesting_flag' states. ```c int main(void) { arc_timer_stop(TIMER_0); arc_timer_stop(TIMER_1); int_disable(INTNO_TIMER0); int_disable(INTNO_TIMER1); int_handler_install(INTNO_TIMER0, timer0_isr); int_pri_set(INTNO_TIMER0, INT_PRI_MAX); int_handler_install(INTNO_TIMER1, timer1_isr); int_pri_set(INTNO_TIMER1, INT_PRI_MIN); EMBARC_PRINTF("\r\nThe test will start in 1s.\r\n"); int_enable(INTNO_TIMER0); int_enable(INTNO_TIMER1); arc_timer_start(TIMER_0, TIMER_CTRL_IE | TIMER_CTRL_NH, MAX_COUNT); arc_timer_start(TIMER_1, TIMER_CTRL_IE | TIMER_CTRL_NH, MAX_COUNT/100); while(1) { if((hits >= 5) && (nesting_flag == 1)) { arc_timer_stop(TIMER_0); arc_timer_stop(TIMER_1); int_disable(INTNO_TIMER0); int_disable(INTNO_TIMER1); int_pri_set(INTNO_TIMER0, INT_PRI_MIN); int_pri_set(INTNO_TIMER1, INT_PRI_MAX); nesting_flag = 0; int_enable(INTNO_TIMER0); int_enable(INTNO_TIMER1); arc_timer_start(TIMER_0, TIMER_CTRL_IE | TIMER_CTRL_NH, MAX_COUNT); arc_timer_start(TIMER_1, TIMER_CTRL_IE | TIMER_CTRL_NH, MAX_COUNT/10); } else if((hits >= 10) && (nesting_flag == 0)) { arc_timer_stop(TIMER_0); arc_timer_stop(TIMER_1); int_disable(INTNO_TIMER0); int_disable(INTNO_TIMER1); int_pri_set(INTNO_TIMER0, INT_PRI_MAX); int_pri_set(INTNO_TIMER1, INT_PRI_MIN); hits = 0; nesting_flag = 1; int_enable(INTNO_TIMER0); int_enable(INTNO_TIMER1); arc_timer_start(TIMER_0, TIMER_CTRL_IE | TIMER_CTRL_NH, MAX_COUNT); arc_timer_start(TIMER_1, TIMER_CTRL_IE | TIMER_CTRL_NH, MAX_COUNT/100); } } return E_SYS; } ``` -------------------------------- ### Building a Project in MetaWare Source: https://arc-labs.readthedocs.io/en/latest/labs/level1/lab1 Details the process of building a project in the MetaWare Development Toolkit. It describes how to initiate the build process and monitor its progress and results in the Console view. ```text In the Project Explorer view, select project `demo`. Click **Project** > **Build Project** or click the icon on the toolbar. In the MetaWare Development Toolkit main interface, you can see in the **Console** view the output and results of the build command. Click on its tab to bring the view forward if it is not currently visible. If for some reason it’s not present, you can open it by selecting **Window** > **Show View** > **Console**. When the message `Finished building target: demo.elf` is displayed, the compilation is successful, and the compiled executable file demo.elf can be seen in the Project Explorer. ``` -------------------------------- ### Importing a File System in MetaWare Source: https://arc-labs.readthedocs.io/en/latest/labs/level1/lab1 Demonstrates how to import a file system, specifically the 'CoreTest.c' file, into a project within the MetaWare Development Toolkit. This process involves using the Import wizard and selecting 'File system' to specify the source directory and files. ```text In the Project Explorer, click and select **Import**. In the Implort wizard, select **File system** from the **General** tab, then click **Next**. As shown in the following figure, in the From directory fileld, type or browse to select the directory contain the file CoreTest.c. Recent directories that have been imported from are shown on the From directory field’s combo box. In the left pane, check a folder that will import its entire contents into the Workbench, and in the right pane check the file CoreTest.c. Click **Finish** when done, the file CoreTest.c is now shown in the one of the navigation views in the project `demo`. ``` -------------------------------- ### Debugging Executable File in MetaWare Source: https://arc-labs.readthedocs.io/en/latest/labs/level1/lab1 Provides instructions for debugging an executable file ('demo.elf') in the MetaWare Development Toolkit. It covers switching to the Debug perspective, setting breakpoints in C or assembly code, and using execution commands for single-step debugging. ```text You may be prompted to switch to the **Debug** perspective. Click **Yes**. The Debug perspective appears with the required windows open. And the windows can be source code window, assembly code window, register window, global variable window, breakpoint window, function window, and so on. In the C code window, right-click the code line number on the left side of the window, select **Toggle Breakpoint** or double-click the line number to set a breakpoint on. In the assembly code window, double-click a line of code to set a breakpoint on. You’ll see a blue circle there indicating the breakpoint is set. After the breakpoint is set, click **Run** > **Resume** or you can use the **Resume** button on the toolbar of the Debug view to run the program. The program runs directly to the nearest breakpoint. You can observe the current program execution and the relevant status information of the processor through the various windows as described in previous step. If you want to know more about the details of program execution and the instruction behavior of the processor, you can use the following three execution commands to perform single-step debugging. The icon can choose to step through a C language statement or an assembly instruction to match the status information of each window. It can be very convenient for program debugging. If you want to end the current debugging process, click . If you want to return to the main MetaWare Development Toolkit page, click C/C++ . ``` -------------------------------- ### Run BLE Communication Project Source: https://arc-labs.readthedocs.io/en/latest/labs/level2/lab7 Executes the BLE communication project on the IoT Development Kit using the GNU toolchain. This command requires the `make` utility and specifies the target board and toolchain. ```bash make BOARD=iotdk TOOLCHAIN=gnu run ``` -------------------------------- ### FreeRTOS Task 3 Implementation Guidance (C) Source: https://arc-labs.readthedocs.io/en/latest/labs/level2/lab9 Guidance for implementing Task 3 to retrieve a new value from a queue and assign it to a variable 'led_val'. It suggests using the `xQueueReceive()` FreeRTOS API function. This task has a delay of 200ms. ```c /* call Freertos system function for 100ms delay */ vTaskDelayUntil( &xLastWakeTime,xFrequency ); //####Insert code here### // Example implementation for task 3: // uint32_t received_value; // if (xQueueReceive(dtq1_id, &received_value, portMAX_DELAY) == pdPASS) { // led_val = received_value; // } ``` -------------------------------- ### FreeRTOS Task 1 Implementation Guidance (C) Source: https://arc-labs.readthedocs.io/en/latest/labs/level2/lab9 Guidance for implementing Task 1 to check queue values for legality and send a reset signal if invalid. It suggests using `xSemaphoreGive()` to release a signal and `xQueuePeek()` to read an item without removing it. This task has a delay of 10ms. ```c /* call Freertos system function for 10ms delay */ vTaskDelayUntil( &xLastWakeTime,xFrequency ); //####Insert code here### // Example implementation for task 1: // uint32_t peeked_value; // if (xQueuePeek(dtq1_id, &peeked_value, 0) == pdPASS) { // // Check if peeked_value is legal // if (peeked_value == ILLEGAL_VALUE) { // Assuming ILLEGAL_VALUE is defined // xSemaphoreGive(sem1_id); // Send reset signal // } // } ``` -------------------------------- ### Configuring Build Settings in MetaWare Source: https://arc-labs.readthedocs.io/en/latest/labs/level1/lab1 Explains how to access and modify build settings for a project in the MetaWare Development Toolkit. This includes setting compiler optimization and debugging levels, as well as processor-specific compilation options. ```text From the Project Explorer view, right-click the project `demo` and choose Properties. Click **C/C++ Build** > **Settings** > **Tool Settings** menu options. The **Tool Settings** dialog opens. Select **Optimization/Debugging** to set the compiler optimization and debugging level. For example, set the optimization level to turn off optimization, and set the debugging level to load all debugging information. Select **Processor/Extensions** to set the compilation options corresponding to the target processor hardware properties, such as the version of the processor, whether to support extended instructions such as shift, multiplication, floating-point operations, and so on whether to include Timer0/1. As shown in the following figure, this setting indicates that the target processor supports common extended instructions. Select **MetaWare ARC EM C/C++** and check the settings compilation options. Click **OK** when done. ``` -------------------------------- ### AT Commands for Sending Data and Closing Connection Source: https://arc-labs.readthedocs.io/en/latest/labs/level2/lab10 Demonstrates the sequence of AT commands used to send data over a network connection and subsequently close it. It includes AT+CIPSEND for sending data and AT+CIPCLOSE for terminating the connection, along with expected responses. ```at_commands AT+CIPSEND=1,44 OK > Recv 44 bytes SEND OK AT+CIPSEND=1,93 OK > Recv 93 bytes SEND OK AT+CIPSEND=1,93 OK > Recv 93 bytes SEND OK AT+CIPCLOSE=1 1,CLOSED OK ``` -------------------------------- ### Build Output Log Source: https://arc-labs.readthedocs.io/en/latest/labs/level2/lab9 The log shows the successful compilation and build of the embARC project, indicating the compiler version and build timestamp. It also confirms the successful creation of three tasks within the FreeRTOS environment. ```text embARC Build Time: Mar 9 2018, 17:57:50 Compiler Version: Metaware, 4.2.1 Compatible Clang 4.0.1 (branches/release_40) Create task1 Successfully Create task2 Successfully Create task3 Successfully ``` -------------------------------- ### Matrix Multiplication using DSPLIB in C Source: https://arc-labs.readthedocs.io/en/latest/labs/level2/lab_dsp3 This C code demonstrates matrix multiplication using the DSPLIB library. It requires including 'dsplib.h', and matrices must be declared as global variables. The code initializes matrices, performs multiplication using `dsp_mat_mult_q15`, and prints the results. Ensure matrices contain appropriate q15 values for accurate results. ```c #include "embARC.h" #include "embARC_debug.h" #include #include "dsplib.h" #define MATRIX_SIZE 20 #define MAX_NUM 1000 #define LOOPS 100000 /* ********************************************* */ /* Matrix manipulation functions */ /* randomize matrix with values up to 'max_value */ //void rand_sq_mat(short x[][MATRIX_SIZE], int SIZE, int max_value) ; /* multiply two square matrices of same size*/ void mul_sq_mat(short x[][MATRIX_SIZE], short y[][MATRIX_SIZE], short z[][MATRIX_SIZE], int size) ; /* print square matrix through UART*/ void print_sq_mat(short* x, int SIZE); /* ********************************************* */ __xy q15_t a[MATRIX_SIZE*MATRIX_SIZE]; __xy q15_t b[MATRIX_SIZE*MATRIX_SIZE]; __xy q15_t c[MATRIX_SIZE*MATRIX_SIZE]; int main(int argc, char *argv[]) { int n =MATRIX_SIZE; matrix_q15_t matA, matB, matC; //rand_sq_mat(a,n, MAX_NUM); //rand_sq_mat(b,n, MAX_NUM); for (int i =0; i< MATRIX_SIZE*MATRIX_SIZE; i++) { a[i]=16384; } for (int i =0; i< MATRIX_SIZE*MATRIX_SIZE; i++) { b[i]=16383; } print_sq_mat(a,n); print_sq_mat(b,n); dsp_mat_init_q15(&matA, MATRIX_SIZE, MATRIX_SIZE, a); dsp_mat_init_q15(&matB, MATRIX_SIZE, MATRIX_SIZE, b); dsp_mat_init_q15(&matC, MATRIX_SIZE, MATRIX_SIZE, c); dsp_status status; unsigned int led_status = 0x40 ; led_status = 0x7F; EMBARC_PRINTF("*** Start ***\n\r"); for (int i =0; i< 8; i++) { for (int j = 1; j < LOOPS/8; j++ ) { status = dsp_mat_mult_q15(&matA, &matB, &matC); }; led_write(led_status, BOARD_LED_MASK); led_status = led_status >> 1; } if ( status == DSP_ERR_OK ) EMBARC_PRINTF("done\n"); else EMBARC_PRINTF("something wrong"); print_sq_mat(c,n); EMBARC_PRINTF("*** Exit ***\n\r"); return 0; } //void rand_sq_mat(short x[][MATRIX_SIZE], int SIZE, int max_value) { // for (int i=0;i