This Website is used to test the AT command about HttpServer of ESP8266.
"; 49 | 50 | 51 | static char http_server_buf[1024]; 52 | 53 | int main(void) 54 | { 55 | char *conn_buf; 56 | 57 | //ESP8266 Init 58 | EMBARC_PRINTF("============================ Init ============================\n"); 59 | 60 | ESP8266_DEFINE(esp8266); 61 | esp8266_init(esp8266, UART_BAUDRATE_115200); 62 | at_test(esp8266->p_at); 63 | board_delay_ms(100, 1); 64 | 65 | //Set Mode 66 | EMBARC_PRINTF("============================ Set Mode ============================\n"); 67 | 68 | esp8266_wifi_mode_get(esp8266, false); 69 | board_delay_ms(100, 1); 70 | esp8266_wifi_mode_set(esp8266, 3, false); 71 | board_delay_ms(100, 1); 72 | 73 | //Connect WiFi 74 | EMBARC_PRINTF("============================ Connect WiFi ============================\n"); 75 | 76 | do { 77 | esp8266_wifi_scan(esp8266, http_server_buf); 78 | EMBARC_PRINTF("Searching for WIFI %s ......\n", WIFI_SSID); 79 | board_delay_ms(100, 1); 80 | } while (strstr(http_server_buf, WIFI_SSID)==NULL); 81 | 82 | EMBARC_PRINTF("WIFI %s found! Try to connect\n", WIFI_SSID); 83 | 84 | while (esp8266_wifi_connect(esp8266, WIFI_SSID, WIFI_PWD, false) != AT_OK) { 85 | EMBARC_PRINTF("WIFI %s connect failed\n", WIFI_SSID); 86 | board_delay_ms(100, 1); 87 | } 88 | 89 | EMBARC_PRINTF("WIFI %s connect succeed\n", WIFI_SSID); 90 | 91 | //Creat Server 92 | EMBARC_PRINTF("============================ Connect Server ============================\n"); 93 | 94 | esp8266_tcp_server_open(esp8266, 80); 95 | 96 | //Show IP 97 | EMBARC_PRINTF("============================ Show IP ============================\n"); 98 | 99 | esp8266_address_get(esp8266); 100 | board_delay_ms(1000, 1); 101 | 102 | while (1) { 103 | memset(http_server_buf, 0, sizeof(http_server_buf)); 104 | at_read(esp8266->p_at ,http_server_buf ,1000); 105 | board_delay_ms(200, 1); 106 | //EMBARC_PRINTF("Alive\n"); 107 | 108 | if (strstr(http_server_buf, http_get) != NULL) { 109 | EMBARC_PRINTF("============================ send ============================\n"); 110 | 111 | EMBARC_PRINTF("\nThe message is:\n%s\n", http_server_buf); 112 | 113 | conn_buf = strstr(http_server_buf, http_IDP) + 5; 114 | *(conn_buf+1) = 0; 115 | 116 | EMBARC_PRINTF("Send Start\n"); 117 | board_delay_ms(10, 1); 118 | 119 | esp8266_connect_write(esp8266, http_html_header, conn_buf, (sizeof(http_html_header)-1)); 120 | board_delay_ms(100, 1); 121 | 122 | esp8266_connect_write(esp8266, http_html_body_1, conn_buf, (sizeof(http_html_body_1)-1)); 123 | board_delay_ms(300, 1); 124 | 125 | esp8266_connect_write(esp8266, http_html_body_2, conn_buf, (sizeof(http_html_body_2)-1)); 126 | board_delay_ms(300, 1); 127 | 128 | esp8266_CIPCLOSE(esp8266, conn_buf); 129 | 130 | EMBARC_PRINTF("Send Finish\n"); 131 | } 132 | } 133 | 134 | return E_OK; 135 | } -------------------------------------------------------------------------------- /labs/lab10_temp_monitor/esp8266_wifi/makefile: -------------------------------------------------------------------------------- 1 | # Application name 2 | APPL ?= esp8266_http_server 3 | 4 | # Optimization Level 5 | # Please Refer to toolchain_xxx.mk for this option 6 | OLEVEL ?= O2 7 | 8 | ## 9 | # Current Board And Core 10 | ## 11 | BOARD ?= emsk 12 | BD_VER ?= 22 13 | CUR_CORE ?= arcem7d 14 | 15 | ## 16 | # select debugging jtag 17 | ## 18 | JTAG ?= usb 19 | 20 | ## 21 | # Set toolchain 22 | ## 23 | TOOLCHAIN ?= gnu 24 | 25 | # 26 | # root dir of embARC 27 | # 28 | EMBARC_ROOT = ../../.. 29 | # Selected OS 30 | OS_SEL ?= freertos 31 | 32 | MID_SEL = common 33 | 34 | # application source dirs 35 | APPL_CSRC_DIR = . 36 | APPL_ASMSRC_DIR = . 37 | 38 | # application include dirs 39 | APPL_INC_DIR = . 40 | 41 | # include current project makefile 42 | COMMON_COMPILE_PREREQUISITES += makefile 43 | 44 | ### Options above must be added before include options.mk ### 45 | # include key embARC build system makefile 46 | override EMBARC_ROOT := $(strip $(subst \,/,$(EMBARC_ROOT))) 47 | include $(EMBARC_ROOT)/options/options.mk -------------------------------------------------------------------------------- /labs/lab10_temp_monitor/pmwifi/FreeRTOSConfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | FreeRTOS V8.0.0 - Copyright (C) 2014 Real Time Engineers Ltd. 3 | All rights reserved 4 | 5 | VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. 6 | 7 | *************************************************************************** 8 | * * 9 | * FreeRTOS provides completely free yet professionally developed, * 10 | * robust, strictly quality controlled, supported, and cross * 11 | * platform software that has become a de facto standard. * 12 | * * 13 | * Help yourself get started quickly and support the FreeRTOS * 14 | * project by purchasing a FreeRTOS tutorial book, reference * 15 | * manual, or both from: http://www.FreeRTOS.org/Documentation * 16 | * * 17 | * Thank you! * 18 | * * 19 | *************************************************************************** 20 | 21 | This file is part of the FreeRTOS distribution. 22 | 23 | FreeRTOS is free software; you can redistribute it and/or modify it under 24 | the terms of the GNU General Public License (version 2) as published by the 25 | Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception. 26 | 27 | >>! NOTE: The modification to the GPL is included to allow you to distribute 28 | >>! a combined work that includes FreeRTOS without being obliged to provide 29 | >>! the source code for proprietary components outside of the FreeRTOS 30 | >>! kernel. 31 | 32 | FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY 33 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 34 | FOR A PARTICULAR PURPOSE. Full license text is available from the following 35 | link: http://www.freertos.org/a00114.html 36 | 37 | 1 tab == 4 spaces! 38 | 39 | *************************************************************************** 40 | * * 41 | * Having a problem? Start by reading the FAQ "My application does * 42 | * not run, what could be wrong?" * 43 | * * 44 | * http://www.FreeRTOS.org/FAQHelp.html * 45 | * * 46 | *************************************************************************** 47 | 48 | http://www.FreeRTOS.org - Documentation, books, training, latest versions, 49 | license and Real Time Engineers Ltd. contact details. 50 | 51 | http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, 52 | including FreeRTOS+Trace - an indispensable productivity tool, a DOS 53 | compatible FAT file system, and our tiny thread aware UDP/IP stack. 54 | 55 | http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High 56 | Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS 57 | licenses offer ticketed support, indemnification and middleware. 58 | 59 | http://www.SafeRTOS.com - High Integrity Systems also provide a safety 60 | engineered and independently SIL3 certified version for use in safety and 61 | mission critical applications that require provable dependability. 62 | 63 | 1 tab == 4 spaces! 64 | */ 65 | 66 | #ifndef FREERTOS_CONFIG_H 67 | #define FREERTOS_CONFIG_H 68 | 69 | #includeNow the temperature is ????? *C.
"; 69 | static const char http_html_hdr[] = "HTTP/1.1 200 OK\r\nContent-type: text/html\r\n\r\n"; 70 | static const char http_index_html_1[] = "Now the temperature is "; 71 | static const char http_index_html_2[] = " *C.
"; 72 | 73 | 74 | /** 75 | * \brief call FreeRTOS API, create and start tasks 76 | */ 77 | int main(void) 78 | { 79 | 80 | vTaskSuspendAll(); 81 | 82 | // Create Tasks 83 | //####Insert code here### 84 | 85 | // Create Queues 86 | //####Insert code here### 87 | 88 | xTaskResumeAll(); 89 | 90 | vTaskSuspend(NULL); 91 | 92 | return 0; 93 | } 94 | 95 | 96 | static void task_send(void *par) 97 | { 98 | float temp_val = 0.0; 99 | struct netconn *conn, *newconn; 100 | err_t err; 101 | 102 | /* Create a new TCP connection handle */ 103 | /* Bind to port 80 (HTTP) with default IP address */ 104 | conn = netconn_new(NETCONN_TCP); 105 | netconn_bind(conn, IP_ADDR_ANY, 80); 106 | 107 | /* Put the connection into LISTEN state */ 108 | netconn_listen(conn); 109 | 110 | do 111 | { 112 | err = netconn_accept(conn, &newconn); 113 | 114 | if (err == ERR_OK) 115 | { 116 | xQueuePeek(dtq1_id, (void *)(&temp_val), portMAX_DELAY); 117 | board_delay_ms(1,1); 118 | http_index_number = gcvt((double)(temp_val), 3, http_index_number); 119 | 120 | http_server_netconn_serve(newconn); 121 | netconn_delete(newconn); 122 | } 123 | 124 | } 125 | while(err == ERR_OK); 126 | 127 | LWIP_DEBUGF(HTTPD_DEBUG,("http_server_netconn_thread: netconn_accept received error %d, shutting down",err)); 128 | 129 | netconn_close(conn); 130 | netconn_delete(conn); 131 | } 132 | 133 | 134 | static void task_temp(void *par) 135 | { 136 | float temp_val = 0.0; 137 | 138 | static portTickType xLastWakeTime; 139 | const portTickType xFrequency = pdMS_TO_TICKS(1000); 140 | 141 | // 使用当前时间初始化变量xLastWakeTime ,注意这和vTaskDelay()函数不同 142 | xLastWakeTime = xTaskGetTickCount(); 143 | 144 | //初始化TCN75 145 | //####Insert code here### 146 | 147 | while (1) 148 | { 149 | /* 调用系统延时函数,周期性阻塞1000ms */ 150 | vTaskDelayUntil( &xLastWakeTime,xFrequency ); 151 | 152 | //读取TCN75 153 | //####Insert code here### 154 | 155 | xQueueReset(dtq1_id); 156 | board_delay_ms(1, 1); 157 | xQueueSend(dtq1_id, (void *)(&temp_val), portMAX_DELAY); 158 | } 159 | } 160 | 161 | 162 | /** Serve one HTTP connection accepted in the http thread */ 163 | static void http_server_netconn_serve(struct netconn *conn) 164 | { 165 | struct netbuf *inbuf; 166 | char *buf; 167 | u16_t buflen; 168 | err_t err; 169 | 170 | /* Read the data from the port, blocking if nothing yet there. 171 | We assume the request (the part we care about) is in one netbuf */ 172 | err = netconn_recv(conn, &inbuf); 173 | 174 | if(err == ERR_OK) 175 | { 176 | netbuf_data(inbuf, (void**)&buf, &buflen); 177 | 178 | /* Is this an HTTP GET command? (only check the first 5 chars, since 179 | there are other formats for GET, and we're keeping it very simple )*/ 180 | if(buflen>=5 && buf[0]=='G' && buf[1]=='E' && buf[2]=='T' && buf[3]==' ' && buf[4]=='/' ) 181 | { 182 | memset(http_index_html, 0, sizeof(http_index_html)-1); 183 | 184 | strcat (http_index_html, http_index_html_1); 185 | strcat (http_index_html, http_index_number); 186 | strcat (http_index_html, http_index_html_2); 187 | 188 | /* Send the HTML header 189 | * subtract 1 from the size, since we dont send the \0 in the string 190 | * NETCONN_NOCOPY: our data is const static, so no need to copy it */ 191 | netconn_write(conn, http_html_hdr, sizeof(http_html_hdr)-1, NETCONN_NOCOPY); 192 | 193 | /* Send our HTML page */ 194 | netconn_write(conn, http_index_html, sizeof(http_index_html)-1, NETCONN_NOCOPY); 195 | 196 | } 197 | } 198 | /* Close the connection (server closes in HTTP) */ 199 | netconn_close(conn); 200 | /* Delete the buffer (netconn_recv gives us ownership, 201 | so we have to make sure to deallocate the buffer) */ 202 | netbuf_delete(inbuf); 203 | } 204 | -------------------------------------------------------------------------------- /labs/lab10_temp_monitor/pmwifi/makefile: -------------------------------------------------------------------------------- 1 | # Application name 2 | APPL ?= lab_10_wifi 3 | 4 | # Optimization Level 5 | # Please Refer to toolchain_xxx.mk for this option 6 | OLEVEL ?= O2 7 | 8 | ## 9 | # Current Board And Core 10 | ## 11 | BOARD ?= emsk 12 | BD_VER ?= 11 13 | CUR_CORE ?= arcem6 14 | 15 | ## 16 | # select debugging jtag 17 | ## 18 | JTAG ?= usb 19 | 20 | ## 21 | # Set toolchain 22 | ## 23 | TOOLCHAIN ?= gnu 24 | 25 | 26 | EXT_DEV_LIST += wifi/mrf24g sensor/temperature/tcn75 27 | 28 | STACKSZ = 4096 29 | 30 | # 31 | # root dir of embARC 32 | # 33 | EMBARC_ROOT = ../../../.. 34 | 35 | # Selected OS 36 | OS_SEL ?= freertos 37 | # Select Middleware Packages 38 | MID_SEL = common lwip lwip-contrib 39 | LWIP_CONTRIB_APPS ?= httpserver 40 | 41 | # application source dirs 42 | APPL_CSRC_DIR = . 43 | APPL_ASMSRC_DIR = . 44 | 45 | # application include dirs 46 | APPL_INC_DIR = . 47 | 48 | # include current project makefile 49 | COMMON_COMPILE_PREREQUISITES += makefile 50 | 51 | ### Options above must be added before include options.mk ### 52 | # include key embARC build system makefile 53 | override EMBARC_ROOT := $(strip $(subst \,/,$(EMBARC_ROOT))) 54 | include $(EMBARC_ROOT)/options/options.mk 55 | -------------------------------------------------------------------------------- /labs/lab1_core_test/CoreTest.c: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------ 2 | * Copyright (c) 2018, Synopsys, Inc. All rights reserved. 3 | 4 | * Redistribution and use in source and binary forms, with or without modification, 5 | * are permitted provided that the following conditions are met: 6 | 7 | * 1) Redistributions of source code must retain the above copyright notice, this 8 | * list of conditions and the following disclaimer. 9 | 10 | * 2) Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation and/or 12 | * other materials provided with the distribution. 13 | 14 | * 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software without 16 | * specific prior written permission. 17 | 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | * 29 | --------------------------------------------- */ 30 | 31 | #ifdef _DEBUG 32 | #include "stdio.h" 33 | #endif 34 | 35 | #define POINTX {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} 36 | #define POINTY {2, 4, 6, 8, 10, 12, 14, 16, 18, 20} 37 | #define POINTS 10 38 | 39 | #define GetError(x, y, Px, Py) \ 40 | ( (x-Px)*(x-Px) + (y-Py)*(y-Py) ) 41 | 42 | int main(int argc, char* argv[]) { 43 | int pPointX[] = POINTX; 44 | int pPointY[] = POINTY; 45 | 46 | int x, y; 47 | int index, error, minindex, minerror; 48 | 49 | x = 4; 50 | y = 5; 51 | 52 | minerror = GetError(x, y, pPointX[0], pPointY[0]); 53 | minindex = 0; 54 | 55 | for(index = 1; index < POINTS; index++) { 56 | error = GetError(x, y, pPointX[index], pPointY[index]); 57 | 58 | if (error < minerror) { 59 | minerror = error; 60 | minindex = index; 61 | } 62 | } 63 | 64 | #ifdef _DEBUG 65 | printf("minindex = %d, minerror = %d.\n", minindex, minerror); 66 | printf("The point is (%d, %d).\n", pPointX[minindex], pPointY[minindex]); 67 | getchar(); 68 | #endif 69 | 70 | return 0; 71 | } 72 | 73 | -------------------------------------------------------------------------------- /labs/lab3_timer/makefile: -------------------------------------------------------------------------------- 1 | # Application name 2 | APPL ?= lab3_timer 3 | 4 | ## 5 | # Current Board And Core 6 | ## 7 | BOARD ?= iotdk 8 | BD_VER ?= 10 9 | CUR_CORE ?= arcem9d 10 | 11 | 12 | ## 13 | # Set toolchain 14 | ## 15 | TOOLCHAIN ?= gnu 16 | 17 | # 18 | # root dir of embARC 19 | # 20 | EMBARC_ROOT = ../../.. 21 | 22 | MID_SEL = common 23 | 24 | # application source dirs 25 | APPL_CSRC_DIR = . 26 | APPL_ASMSRC_DIR = . 27 | 28 | # application include dirs 29 | APPL_INC_DIR = . 30 | 31 | # include current project makefile 32 | COMMON_COMPILE_PREREQUISITES += makefile 33 | 34 | ### Options above must be added before include options.mk ### 35 | # include key embARC build system makefile 36 | override EMBARC_ROOT := $(strip $(subst \,/,$(EMBARC_ROOT))) 37 | include $(EMBARC_ROOT)/options/options.mk 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /labs/lab3_timer/timer.c: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------ 2 | * Copyright (c) 2018, Synopsys, Inc. All rights reserved. 3 | 4 | * Redistribution and use in source and binary forms, with or without modification, 5 | * are permitted provided that the following conditions are met: 6 | 7 | * 1) Redistributions of source code must retain the above copyright notice, this 8 | * list of conditions and the following disclaimer. 9 | 10 | * 2) Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation and/or 12 | * other materials provided with the distribution. 13 | 14 | * 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software without 16 | * specific prior written permission. 17 | 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | * 29 | --------------------------------------------- */ 30 | 31 | #include "embARC.h" 32 | #include "embARC_debug.h" 33 | 34 | #include "arc/arc_timer.h" 35 | #include "arc/arc.h" 36 | #include "arc/arc_builtin.h" 37 | 38 | #define BOARD_CPU_CLOCK CLK_CPU 39 | #define MAX_COUNT 0x0fffffff 40 | /** main entry for testing arc timer**/ 41 | int main(void) 42 | { 43 | 44 | /*Check the timer configuration information through the Timer BCR register.*/ 45 | uint32_t bcr = arc_aux_read(AUX_BCR_TIMERS); 46 | int timer0_flag = (bcr >> 8) & 1; 47 | int timer1_flag = (bcr >> 9) & 1; 48 | int RTC_flag = (bcr >> 10) & 1; 49 | if (timer0_flag) { 50 | EMBARC_PRINTF("Does this timer0 exist? YES\r\n"); 51 | /*Read auxiliary register configuration information*/ 52 | EMBARC_PRINTF("timer0's operating mode:0x%08x\r\n",arc_aux_read(AUX_TIMER0_CTRL)); 53 | EMBARC_PRINTF("timer0's limit value :0x%08x\r\n",arc_aux_read(AUX_TIMER0_LIMIT)); 54 | EMBARC_PRINTF("timer0's current cnt_number:0x%08x\r\n",arc_aux_read(AUX_TIMER0_CNT)); 55 | } else { 56 | EMBARC_PRINTF("\r\nDoes this timer0 exist? NO\r\n"); 57 | } 58 | 59 | if (timer1_flag) { 60 | EMBARC_PRINTF("\r\nDoes this timer1 exist? YES\r\n"); 61 | /*Read auxiliary register configuration information*/ 62 | EMBARC_PRINTF("timer1's operating mode:0x%08x\r\n",arc_aux_read(AUX_TIMER1_CTRL)); 63 | EMBARC_PRINTF("timer1's limit value :0x%08x\r\n",arc_aux_read(AUX_TIMER1_LIMIT)); 64 | EMBARC_PRINTF("timer1's current cnt_number:0x%08x\r\n",arc_aux_read(AUX_TIMER1_CNT)); 65 | } else { 66 | EMBARC_PRINTF("\r\nDoes this timer1 exist? NO\r\n"); 67 | } 68 | 69 | if (RTC_flag) { 70 | EMBARC_PRINTF("\r\nDoes this RTC_timer exist? YES\r\n"); 71 | /*Read auxiliary register configuration information*/ 72 | EMBARC_PRINTF("RTC_timer's operating mode:0x%08x\r\n",arc_aux_read(AUX_RTC_CTRL)); 73 | EMBARC_PRINTF("timer1's current tick:0x%08x\r\n",arc_aux_read(AUX_RTC_LOW)); 74 | } else { 75 | EMBARC_PRINTF("\r\nDoes this RTC_timer exist? NO\r\n"); 76 | } 77 | 78 | /*Configure the timer through auxiliary registers*/ 79 | if (timer0_flag) { 80 | /* Stop it first since it might be enabled before */ 81 | arc_aux_write(AUX_TIMER0_CTRL, 0); 82 | arc_aux_write(AUX_TIMER0_LIMIT,0); 83 | arc_aux_write(AUX_TIMER0_CNT, 0); 84 | /*This is a example about timer0's timer function.*/ 85 | uint32_t mode = TIMER_CTRL_NH;/*Timing without triggering interruption.*/ 86 | uint32_t val = MAX_COUNT; 87 | arc_aux_write(AUX_TIMER0_CNT, 0); 88 | arc_aux_write(AUX_TIMER0_LIMIT, val); 89 | /*start the specific timer*/ 90 | arc_aux_write(AUX_TIMER0_CTRL, mode); 91 | uint32_t start_cnt = arc_aux_read(AUX_TIMER0_CNT); 92 | EMBARC_PRINTF("\r\nThe start_cnt number is:%d",start_cnt); 93 | 94 | EMBARC_PRINTF("\r\n/******** TEST MODE START ********/\r\n"); 95 | EMBARC_PRINTF("\r\nThis is TEST CODE.\r\n"); 96 | EMBARC_PRINTF("\r\nThis is TEST CODE.\r\n"); 97 | EMBARC_PRINTF("\r\nThis is TEST CODE.\r\n"); 98 | board_delay_ms(100, 1); 99 | EMBARC_PRINTF("\r\n/******** TEST MODE END ********/\r\n"); 100 | 101 | uint32_t end_cnt = arc_aux_read(AUX_TIMER0_CNT); 102 | EMBARC_PRINTF("The end_cnt number is:%d\r\n", end_cnt); 103 | uint32_t time = (end_cnt-start_cnt)/(BOARD_CPU_CLOCK/1000); 104 | EMBARC_PRINTF("\r\nTotal time of TEST CODE BLOCK operation:%d\r\n",time); 105 | } else { 106 | EMBARC_PRINTF("timer 0 is not present\r\n"); 107 | } 108 | 109 | return E_SYS; 110 | } 111 | -------------------------------------------------------------------------------- /labs/lab4_interrupt/part1/main.c: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------ 2 | * Copyright (c) 2017, Synopsys, Inc. All rights reserved. 3 | 4 | * Redistribution and use in source and binary forms, with or without modification, 5 | * are permitted provided that the following conditions are met: 6 | 7 | * 1) Redistributions of source code must retain the above copyright notice, this 8 | * list of conditions and the following disclaimer. 9 | 10 | * 2) Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation and/or 12 | * other materials provided with the distribution. 13 | 14 | * 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software without 16 | * specific prior written permission. 17 | 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | * 29 | --------------------------------------------- */ 30 | 31 | 32 | /* embARC HAL */ 33 | #include "embARC.h" 34 | #include "embARC_debug.h" 35 | 36 | #define COUNT BOARD_CPU_CLOCK/1000 37 | 38 | volatile static int t0 = 0; 39 | volatile static int second = 1; 40 | 41 | /** arc timer 0 interrupt routine */ 42 | static void timer0_isr(void *ptr) 43 | { 44 | arc_timer_int_clear(TIMER_0); 45 | t0++; 46 | } 47 | 48 | /** arc timer 0 interrupt delay */ 49 | void timer0_delay_ms(int ms) 50 | { 51 | t0 = 0; 52 | while(t0 < ms); 53 | } 54 | 55 | /** main entry for testing arc fiq interrupt */ 56 | int main(void) 57 | { 58 | int_disable(INTNO_TIMER0); 59 | arc_timer_stop(TIMER_0); 60 | 61 | int_handler_install(INTNO_TIMER0, timer0_isr); 62 | int_pri_set(INTNO_TIMER0, INT_PRI_MIN); 63 | 64 | EMBARC_PRINTF("\r\nThis is a example about timer interrupt.\r\n"); 65 | 66 | int_enable(INTNO_TIMER0); 67 | arc_timer_start(TIMER_0, TIMER_CTRL_IE | TIMER_CTRL_NH, COUNT); 68 | 69 | while(1) 70 | { 71 | timer0_delay_ms(1000); 72 | EMBARC_PRINTF("\r\n %ds.\r\n",second); 73 | second ++; 74 | } 75 | return E_SYS; 76 | } 77 | 78 | -------------------------------------------------------------------------------- /labs/lab4_interrupt/part1/makefile: -------------------------------------------------------------------------------- 1 | # Application name 2 | APPL ?= lab4_interrupt 3 | 4 | ## 5 | # Current Board And Core 6 | ## 7 | BOARD ?= emsk 8 | BD_VER ?= 22 9 | CUR_CORE ?= arcem7d 10 | 11 | ## 12 | # Set toolchain 13 | ## 14 | TOOLCHAIN ?= gnu 15 | 16 | # 17 | # root dir of embARC 18 | # 19 | EMBARC_ROOT = ../../../.. 20 | 21 | MID_SEL = common 22 | 23 | # application source dirs 24 | APPL_CSRC_DIR = . 25 | APPL_ASMSRC_DIR = . 26 | 27 | # application include dirs 28 | APPL_INC_DIR = . 29 | 30 | # include current project makefile 31 | COMMON_COMPILE_PREREQUISITES += makefile 32 | 33 | ### Options above must be added before include options.mk ### 34 | # include key embARC build system makefile 35 | override EMBARC_ROOT := $(strip $(subst \,/,$(EMBARC_ROOT))) 36 | include $(EMBARC_ROOT)/options/options.mk 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /labs/lab4_interrupt/part2/main.c: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------ 2 | * Copyright (c) 2018, Synopsys, Inc. All rights reserved. 3 | 4 | * Redistribution and use in source and binary forms, with or without modification, 5 | * are permitted provided that the following conditions are met: 6 | 7 | * 1) Redistributions of source code must retain the above copyright notice, this 8 | * list of conditions and the following disclaimer. 9 | 10 | * 2) Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation and/or 12 | * other materials provided with the distribution. 13 | 14 | * 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software without 16 | * specific prior written permission. 17 | 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | * 29 | --------------------------------------------- */ 30 | /* embARC HAL */ 31 | #include "embARC.h" 32 | #include "embARC_debug.h" 33 | 34 | #define MAX_COUNT 0xfffff 35 | 36 | volatile static uint8_t timer_flag = 0; 37 | volatile static uint8_t hits = 0; 38 | 39 | volatile static uint8_t nesting_flag = 1; 40 | 41 | /** arc timer 0 interrupt routine */ 42 | static void timer0_isr(void *ptr) 43 | { 44 | arc_timer_int_clear(TIMER_0); 45 | 46 | timer_flag = 0; 47 | 48 | board_delay_ms(10, 1); 49 | 50 | if(timer_flag) { 51 | EMBARC_PRINTF("Interrupt nesting!\r\n"); 52 | } else { 53 | EMBARC_PRINTF("Interrupt\r\n"); 54 | } 55 | 56 | hits++; 57 | } 58 | 59 | /** arc timer 1 interrupt routine */ 60 | static void timer1_isr(void *ptr) 61 | { 62 | arc_timer_int_clear(TIMER_1); 63 | 64 | timer_flag = 1; 65 | } 66 | 67 | /** main entry for testing arc fiq interrupt */ 68 | int main(void) 69 | { 70 | arc_timer_stop(TIMER_0); 71 | arc_timer_stop(TIMER_1); 72 | 73 | int_disable(INTNO_TIMER0); 74 | int_disable(INTNO_TIMER1); 75 | 76 | int_handler_install(INTNO_TIMER0, timer0_isr); 77 | int_pri_set(INTNO_TIMER0, INT_PRI_MAX); 78 | 79 | int_handler_install(INTNO_TIMER1, timer1_isr); 80 | int_pri_set(INTNO_TIMER1, INT_PRI_MIN); 81 | 82 | EMBARC_PRINTF("\r\nThe test will start in 1s.\r\n"); 83 | EMBARC_PRINTF("\r\n/******** TEST MODE START ********/\r\n\r\n"); 84 | 85 | int_enable(INTNO_TIMER0); 86 | int_enable(INTNO_TIMER1); 87 | 88 | arc_timer_start(TIMER_0, TIMER_CTRL_IE | TIMER_CTRL_NH, MAX_COUNT); 89 | arc_timer_start(TIMER_1, TIMER_CTRL_IE | TIMER_CTRL_NH, MAX_COUNT/100); 90 | 91 | while(1) 92 | { 93 | if((hits >= 5) && (nesting_flag == 1)) { 94 | arc_timer_stop(TIMER_0); 95 | arc_timer_stop(TIMER_1); 96 | 97 | int_disable(INTNO_TIMER0); 98 | int_disable(INTNO_TIMER1); 99 | 100 | int_pri_set(INTNO_TIMER0, INT_PRI_MIN); 101 | int_pri_set(INTNO_TIMER1, INT_PRI_MAX); 102 | 103 | nesting_flag = 0; 104 | 105 | int_enable(INTNO_TIMER0); 106 | int_enable(INTNO_TIMER1); 107 | 108 | arc_timer_start(TIMER_0, TIMER_CTRL_IE | TIMER_CTRL_NH, MAX_COUNT); 109 | arc_timer_start(TIMER_1, TIMER_CTRL_IE | TIMER_CTRL_NH, MAX_COUNT/10); 110 | } else if((hits >= 10) && (nesting_flag == 0)) { 111 | arc_timer_stop(TIMER_0); 112 | arc_timer_stop(TIMER_1); 113 | 114 | int_disable(INTNO_TIMER0); 115 | int_disable(INTNO_TIMER1); 116 | 117 | int_pri_set(INTNO_TIMER0, INT_PRI_MAX); 118 | int_pri_set(INTNO_TIMER1, INT_PRI_MIN); 119 | 120 | hits = 0; 121 | nesting_flag = 1; 122 | 123 | int_enable(INTNO_TIMER0); 124 | int_enable(INTNO_TIMER1); 125 | 126 | arc_timer_start(TIMER_0, TIMER_CTRL_IE | TIMER_CTRL_NH, MAX_COUNT); 127 | arc_timer_start(TIMER_1, TIMER_CTRL_IE | TIMER_CTRL_NH, MAX_COUNT/100); 128 | } 129 | } 130 | return E_SYS; 131 | } 132 | -------------------------------------------------------------------------------- /labs/lab4_interrupt/part2/makefile: -------------------------------------------------------------------------------- 1 | # Application name 2 | APPL ?= lab4_interrupt 3 | 4 | ## 5 | # Current Board And Core 6 | ## 7 | BOARD ?= emsk 8 | BD_VER ?= 22 9 | CUR_CORE ?= arcem7d 10 | 11 | ## 12 | # Set toolchain 13 | ## 14 | TOOLCHAIN ?= gnu 15 | 16 | # 17 | # root dir of embARC 18 | # 19 | EMBARC_ROOT = ../../../.. 20 | 21 | MID_SEL = common 22 | 23 | # application source dirs 24 | APPL_CSRC_DIR = . 25 | APPL_ASMSRC_DIR = . 26 | 27 | # application include dirs 28 | APPL_INC_DIR = . 29 | 30 | # include current project makefile 31 | COMMON_COMPILE_PREREQUISITES += makefile 32 | 33 | ### Options above must be added before include options.mk ### 34 | # include key embARC build system makefile 35 | override EMBARC_ROOT := $(strip $(subst \,/,$(EMBARC_ROOT))) 36 | include $(EMBARC_ROOT)/options/options.mk 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /labs/lab5_emsk/main.c: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------ 2 | * Copyright (c) 2018, Synopsys, Inc. All rights reserved. 3 | 4 | * Redistribution and use in source and binary forms, with or without modification, 5 | * are permitted provided that the following conditions are met: 6 | 7 | * 1) Redistributions of source code must retain the above copyright notice, this 8 | * list of conditions and the following disclaimer. 9 | 10 | * 2) Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation and/or 12 | * other materials provided with the distribution. 13 | 14 | * 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software without 16 | * specific prior written permission. 17 | 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | * 29 | --------------------------------------------- */ 30 | 31 | /* embARC HAL */ 32 | #include "embARC.h" 33 | #include "embARC_debug.h" 34 | 35 | #define LED_MASK BOARD_LED_MASK 36 | #define BTN_MASK BOARD_BTN_MASK 37 | #define SWT_MASk BOARD_SWT_MASK 38 | 39 | 40 | /** 41 | * \brief Test hardware board without any peripheral 42 | */ 43 | int main(void) 44 | { 45 | uint16_t led_val = 0x0000; 46 | uint16_t btn_val = 0x0000; 47 | uint16_t swt_val = 0x0000; 48 | uint16_t pri_cnt = 0x0000; 49 | 50 | while (1) 51 | { 52 | led_val = 0x0000; 53 | btn_val = button_read(BOARD_BTN_MASK); 54 | swt_val = switch_read(BOARD_SWT_MASK); 55 | 56 | led_val = (btn_val<<4) + swt_val; 57 | 58 | led_write(led_val, BOARD_LED_MASK); 59 | 60 | board_delay_ms(10, 1); 61 | 62 | if(pri_cnt >= 100) 63 | { 64 | pri_cnt = 0; 65 | EMBARC_PRINTF("\r\nThe Button is 0x%x\r\n",btn_val); 66 | EMBARC_PRINTF("The Switch is 0x%x\r\n",swt_val); 67 | } 68 | else 69 | { 70 | pri_cnt ++; 71 | } 72 | } 73 | 74 | return E_SYS; 75 | } 76 | 77 | /** @} */ -------------------------------------------------------------------------------- /labs/lab5_emsk/makefile: -------------------------------------------------------------------------------- 1 | # Application name 2 | APPL ?= lab5_emsk 3 | 4 | # Optimization Level 5 | # Please Refer to toolchain_xxx.mk for this option 6 | OLEVEL ?= O2 7 | 8 | ## 9 | # Current Board And Core 10 | ## 11 | BOARD ?= emsk 12 | BD_VER ?= 22 13 | CUR_CORE ?= arcem7d 14 | 15 | ## 16 | # select debugging jtag 17 | ## 18 | JTAG ?= usb 19 | 20 | ## 21 | # Set toolchain 22 | ## 23 | TOOLCHAIN ?= gnu 24 | 25 | 26 | # 27 | # root dir of embARC 28 | # 29 | EMBARC_ROOT = ../../.. 30 | 31 | MID_SEL = 32 | 33 | # application source dirs 34 | APPL_CSRC_DIR = . 35 | APPL_ASMSRC_DIR = . 36 | 37 | # application include dirs 38 | APPL_INC_DIR = . 39 | 40 | # include current project makefile 41 | COMMON_COMPILE_PREREQUISITES += makefile 42 | 43 | ### Options above must be added before include options.mk ### 44 | # include key embARC build system makefile 45 | override EMBARC_ROOT := $(strip $(subst \,/,$(EMBARC_ROOT))) 46 | include $(EMBARC_ROOT)/options/options.mk -------------------------------------------------------------------------------- /labs/lab5_iotdk/main.c: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------ 2 | * Copyright (c) 2018, Synopsys, Inc. All rights reserved. 3 | 4 | * Redistribution and use in source and binary forms, with or without modification, 5 | * are permitted provided that the following conditions are met: 6 | 7 | * 1) Redistributions of source code must retain the above copyright notice, this 8 | * list of conditions and the following disclaimer. 9 | 10 | * 2) Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation and/or 12 | * other materials provided with the distribution. 13 | 14 | * 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software without 16 | * specific prior written permission. 17 | 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | * 29 | --------------------------------------------- */ 30 | 31 | /* embARC HAL */ 32 | #include "embARC.h" 33 | #include "embARC_debug.h" 34 | 35 | #define IOTDK_LED_ID DFSS_GPIO_4B2_ID 36 | #define IOTDK_LED_PIN 0 37 | 38 | 39 | /** 40 | * \brief Test hardware board without any peripheral 41 | */ 42 | int main(void) 43 | { 44 | DEV_GPIO_PTR gpio_led; 45 | 46 | io_arduino_config(ARDUINO_PIN_0, ARDUINO_GPIO, IO_PINMUX_ENABLE); 47 | 48 | gpio_led = gpio_get_dev(IOTDK_LED_ID); 49 | if (gpio_led->gpio_open((1 << IOTDK_LED_PIN)) == E_OPNED) 50 | { 51 | gpio_led->gpio_control(GPIO_CMD_SET_BIT_DIR_OUTPUT, 52 | (void *)(1 << IOTDK_LED_PIN)); 53 | } 54 | 55 | while (1) 56 | { 57 | gpio_led->gpio_write(1, 1 << IOTDK_LED_PIN); 58 | board_delay_ms(10, 1); 59 | gpio_led->gpio_write(0, 1 << IOTDK_LED_PIN); 60 | board_delay_ms(190, 1); 61 | } 62 | 63 | return E_SYS; 64 | } 65 | 66 | /** @} */ -------------------------------------------------------------------------------- /labs/lab5_iotdk/makefile: -------------------------------------------------------------------------------- 1 | # Application name 2 | APPL ?= lab5_iotdk 3 | 4 | # Optimization Level 5 | # Please Refer to toolchain_xxx.mk for this option 6 | OLEVEL ?= O2 7 | 8 | ## 9 | # Current Board And Core 10 | ## 11 | BOARD ?= iotdk 12 | BD_VER ?= 10 13 | CUR_CORE ?= arcem9d 14 | 15 | ## 16 | # select debugging jtag 17 | ## 18 | JTAG ?= usb 19 | 20 | ## 21 | # Set toolchain 22 | ## 23 | TOOLCHAIN ?= gnu 24 | 25 | 26 | # 27 | # root dir of embARC 28 | # 29 | EMBARC_ROOT = ../../.. 30 | 31 | MID_SEL = 32 | 33 | # application source dirs 34 | APPL_CSRC_DIR = . 35 | APPL_ASMSRC_DIR = . 36 | 37 | # application include dirs 38 | APPL_INC_DIR = . 39 | 40 | # include current project makefile 41 | COMMON_COMPILE_PREREQUISITES += makefile 42 | 43 | ### Options above must be added before include options.mk ### 44 | # include key embARC build system makefile 45 | override EMBARC_ROOT := $(strip $(subst \,/,$(EMBARC_ROOT))) 46 | include $(EMBARC_ROOT)/options/options.mk 47 | -------------------------------------------------------------------------------- /labs/lab6_ble_rn4020/main.c: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------ 2 | * Copyright (c) 2018, Synopsys, Inc. All rights reserved. 3 | 4 | * Redistribution and use in source and binary forms, with or without modification, 5 | * are permitted provided that the following conditions are met: 6 | 7 | * 1) Redistributions of source code must retain the above copyright notice, this 8 | * list of conditions and the following disclaimer. 9 | 10 | * 2) Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation and/or 12 | * other materials provided with the distribution. 13 | 14 | * 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software without 16 | * specific prior written permission. 17 | 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | * 29 | --------------------------------------------- */ 30 | 31 | #include "embARC.h" 32 | #include "embARC_debug.h" 33 | 34 | #include "board.h" 35 | #include "device/ip_hal/dev_uart.h" 36 | #include "rn4020.h" 37 | 38 | #define RN4020_PRV_SERV_HIGH_UUID 0x1122334455667788 39 | #define RN4020_PRV_SERV_LOW_UUID 0x9900AABBCCDDEEFF 40 | #define RN4020_PRV_CHAR_HIGH_UUID 0x0102030405060708 41 | #define RN4020_PRV_CHAR_LOW_UUID 0x09000A0B0C0D0E0F 42 | 43 | int32_t rn4020_set_prv_uuid(RN4020_DEF_PTR rn4020, uint64_t high_uuid, uint64_t low_uuid) 44 | { 45 | uint8_t i; 46 | uint8_t uuid_data[16]; 47 | 48 | for(i = 0; i < 16; i++) 49 | { 50 | if(i < 8) uuid_data[i] = (high_uuid >> ((7-i) << 3)) & 0xff; 51 | else uuid_data[i] = (low_uuid >> ((15-i) << 3)) & 0xff; 52 | } 53 | 54 | return rn4020_add_prv_service(rn4020, uuid_data); 55 | 56 | } 57 | 58 | int32_t rn4020_set_prv_char(RN4020_DEF_PTR rn4020, uint64_t high_uuid, uint64_t low_uuid, 59 | uint8_t property, uint8_t size, uint8_t security) 60 | { 61 | uint8_t i; 62 | uint8_t uuid_data[16]; 63 | 64 | for(i = 0; i < 16; i++) 65 | { 66 | if(i < 8) uuid_data[i] = (high_uuid >> ((7-i) << 3)) & 0xff; 67 | else uuid_data[i] = (low_uuid >> ((15-i) << 3)) & 0xff; 68 | } 69 | 70 | return rn4020_add_prv_char(rn4020, uuid_data, property, size, security); 71 | 72 | } 73 | 74 | int main(void) 75 | { 76 | 77 | uint32_t battery = 100; 78 | 79 | RN4020_DEFINE(rn4020_ble, DFSS_UART_3_ID, DFSS_GPIO_4B0_ID, 2, DFSS_GPIO_4B0_ID, 1, DFSS_GPIO_4B0_ID, 3); 80 | 81 | EMBARC_PRINTF("rn4020 test application\r\n"); 82 | 83 | rn4020_setup(rn4020_ble); 84 | rn4020_reset_to_factory(rn4020_ble); 85 | 86 | /* Set device Name */ 87 | rn4020_set_dev_name(rn4020_ble, "IoT DK"); 88 | 89 | /* Set device services */ 90 | rn4020_set_services(rn4020_ble, RN4020_SERVICE_DEVICE_INFORMATION | 91 | RN4020_SERVICE_BATTERY | 92 | RN4020_SERVICE_USER_DEFINED); 93 | 94 | rn4020_set_features(rn4020_ble, RN4020_FEATURE_SERVER_ONLY); 95 | rn4020_clear_private(rn4020_ble); 96 | 97 | /* Set private service UUID and private characteristic */ 98 | rn4020_set_prv_uuid(rn4020_ble, RN4020_PRV_SERV_HIGH_UUID, RN4020_PRV_SERV_LOW_UUID); 99 | rn4020_set_prv_char(rn4020_ble, RN4020_PRV_CHAR_HIGH_UUID, RN4020_PRV_CHAR_LOW_UUID, 0x18, 0x06, RN4020_PRIVATE_CHAR_SEC_NONE); 100 | 101 | /* Reboot RN4020 to make changes effective */ 102 | rn4020_reset(rn4020_ble); 103 | 104 | rn4020_refresh_handle_uuid_table(rn4020_ble); 105 | 106 | rn4020_advertise(rn4020_ble); 107 | 108 | 109 | while (1) { 110 | 111 | rn4020_battery_set_level(rn4020_ble, battery--); 112 | 113 | board_delay_ms(1000, 0); 114 | if (battery < 30) { 115 | battery = 100; 116 | } 117 | } 118 | 119 | return E_SYS; 120 | } 121 | 122 | -------------------------------------------------------------------------------- /labs/lab6_ble_rn4020/makefile: -------------------------------------------------------------------------------- 1 | # Application name 2 | APPL ?= Ble_Rn4020_Test 3 | 4 | # Optimization Level 5 | # Please Refer to toolchain_xxx.mk for this option 6 | OLEVEL ?= O2 7 | 8 | ## 9 | # Current Board And Core 10 | ## 11 | BOARD ?= iotdk 12 | BD_VER ?= 10 13 | CUR_CORE ?= arcem9d 14 | 15 | ## 16 | # select debugging jtag 17 | ## 18 | JTAG ?= usb 19 | 20 | ## 21 | # Set toolchain 22 | ## 23 | TOOLCHAIN ?= mw 24 | #TOOLCHAIN ?= gnu 25 | 26 | EXT_DEV_LIST += ble/rn4020 27 | # 28 | # root dir of embARC 29 | # 30 | EMBARC_ROOT = ../../.. 31 | 32 | MID_SEL = common 33 | 34 | # application source dirs 35 | APPL_CSRC_DIR = . 36 | APPL_ASMSRC_DIR = . 37 | 38 | # application include dirs 39 | APPL_INC_DIR = . 40 | 41 | # include current project makefile 42 | COMMON_COMPILE_PREREQUISITES += makefile 43 | 44 | ### Options above must be added before include options.mk ### 45 | # include key embARC build system makefile 46 | override EMBARC_ROOT := $(strip $(subst \,/,$(EMBARC_ROOT))) 47 | include $(EMBARC_ROOT)/options/options.mk -------------------------------------------------------------------------------- /labs/lab7_ble_hm10/main.c: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------ 2 | * Copyright (c) 2018, Synopsys, Inc. All rights reserved. 3 | 4 | * Redistribution and use in source and binary forms, with or without modification, 5 | * are permitted provided that the following conditions are met: 6 | 7 | * 1) Redistributions of source code must retain the above copyright notice, this 8 | * list of conditions and the following disclaimer. 9 | 10 | * 2) Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation and/or 12 | * other materials provided with the distribution. 13 | 14 | * 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software without 16 | * specific prior written permission. 17 | 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | * 29 | --------------------------------------------- */ 30 | 31 | #include "embARC.h" 32 | #include "embARC_debug.h" 33 | 34 | #include "board.h" 35 | #include "device/ip_hal/dev_uart.h" 36 | #include "hm1x.h" 37 | 38 | #define MAX_COUNT 0xfffff 39 | 40 | uint8_t isr_flag = 0; 41 | 42 | void init_ble_hm_10(HM1X_DEF_PTR obj, uint32_t baudrate, uint32_t mode, uint32_t type, uint32_t role) 43 | { 44 | EMBARC_PRINTF("Init HM1X with baudrate %dbps\r\n", baudrate); 45 | hm1x_init(obj, baudrate); 46 | 47 | hm1x_flush(obj); 48 | 49 | while (hm1x_test_command(obj)) { 50 | EMBARC_PRINTF("test command Failed\r\n"); 51 | } 52 | EMBARC_PRINTF("test command Successfully\r\n"); 53 | 54 | while (hm1x_restart(obj)) { 55 | EMBARC_PRINTF("Restart Failed\r\n"); 56 | } 57 | EMBARC_PRINTF("Restart Successfully\r\n"); 58 | 59 | while (hm1x_set_mode(obj, mode)) { 60 | EMBARC_PRINTF("SET MODE Failed\r\n"); 61 | } 62 | EMBARC_PRINTF("SET MODE to %d\r\n", mode); 63 | 64 | while(hm1x_set_type(obj, type)) { 65 | EMBARC_PRINTF("SET TYPE Failed\r\n"); 66 | } 67 | EMBARC_PRINTF("SET TYPE to %d\r\n", type); 68 | 69 | while(hm1x_set_role(obj, role)) { 70 | EMBARC_PRINTF("SET ROLE Failed\r\n"); 71 | } 72 | EMBARC_PRINTF("SET ROLE to %d\r\n", role); 73 | } 74 | 75 | static void timer0_isr(void *ptr) 76 | { 77 | static uint32_t led_val = 1; 78 | arc_timer_int_clear(TIMER_0); 79 | 80 | if (isr_flag == 1) { 81 | if(led_val >= 0x0100) { 82 | led_val = 0x0001; 83 | } else { 84 | led_val <<= 1; 85 | } 86 | 87 | led_write(led_val, BOARD_LED_MASK); 88 | } 89 | } 90 | 91 | void init_run_timer(void) 92 | { 93 | int_disable(INTNO_TIMER0); 94 | arc_timer_stop(TIMER_0); 95 | 96 | int_handler_install(INTNO_TIMER0, timer0_isr); 97 | int_pri_set(INTNO_TIMER0, INT_PRI_MIN); 98 | 99 | int_enable(INTNO_TIMER0); 100 | arc_timer_start(0, TIMER_CTRL_IE | TIMER_CTRL_NH, MAX_COUNT); 101 | } 102 | 103 | uint8_t compare_chars(uint8_t* buf, uint8_t* cmd, uint8_t num) 104 | { 105 | uint8_t i = 0; 106 | uint8_t cnt = 0; 107 | 108 | for (i = 0; i < num; ++i) { 109 | if(buf[i] == cmd[i]) { 110 | cnt++; 111 | } 112 | } 113 | 114 | if(cnt == num) { 115 | return 1; 116 | } else { 117 | return 0; 118 | } 119 | } 120 | 121 | void LED_ALL_FUN(void) 122 | { 123 | isr_flag = 0; 124 | 125 | led_write(BOARD_LED_MASK, BOARD_LED_MASK); 126 | } 127 | 128 | void LED_OFF_FUN(void) 129 | { 130 | isr_flag = 0; 131 | 132 | led_write(~BOARD_LED_MASK, BOARD_LED_MASK); 133 | } 134 | 135 | void LED_WRI_FUN(uint8_t* num_buf, uint8_t* num_cmd) 136 | { 137 | uint8_t i = 0; 138 | uint8_t k = 0; 139 | uint32_t led_val = 0; 140 | 141 | isr_flag = 0; 142 | 143 | for(k = 0; k < 3; ++k) 144 | { 145 | for (i = 0; i < 16; ++i) 146 | { 147 | if(num_buf[k] == num_cmd[i]) 148 | { 149 | led_val += i; 150 | } 151 | } 152 | led_val <<= 4; 153 | } 154 | led_val >>= 4; 155 | led_write(led_val, BOARD_LED_MASK); 156 | } 157 | 158 | void LED_RUN_FUN(void) 159 | { 160 | isr_flag = 1; 161 | } 162 | 163 | void LED_RED_FUN(void) 164 | { 165 | uint32_t led_val = 0; 166 | 167 | led_val = led_read(BOARD_LED_MASK); 168 | EMBARC_PRINTF("The Led is 0x0%x\r\n",led_val); 169 | } 170 | 171 | int main(void) 172 | { 173 | uint8_t rcv_buf[20]; 174 | int32_t rcv_cnt = 0; 175 | 176 | uint8_t cmd_buf[20]; 177 | int32_t cmd_cnt = 0; 178 | 179 | uint8_t rcv_flag = 0; 180 | uint8_t pre_flag = 0; 181 | 182 | uint8_t LED_ALL_CMD[6] = {'L','E','D','A','L','L'}; 183 | uint8_t LED_OFF_CMD[6] = {'L','E','D','O','F','F'}; 184 | uint8_t LED_WRI_CMD[6] = {'L','E','D','W','R','I'}; 185 | uint8_t LED_RUN_CMD[6] = {'L','E','D','R','U','N'}; 186 | uint8_t LED_RED_CMD[6] = {'L','E','D','R','E','D'}; 187 | 188 | uint8_t Num_CMD[16] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'}; 189 | 190 | uint8_t LED_ALL_FLAG = 0; 191 | uint8_t LED_OFF_FLAG = 0; 192 | uint8_t LED_WRI_FLAG = 0; 193 | uint8_t LED_RUN_FLAG = 0; 194 | uint8_t LED_RED_FLAG = 0; 195 | 196 | HM1X_DEFINE(hm1x, HM_1X_UART_ID); 197 | init_ble_hm_10(hm1x, UART_BAUDRATE_9600, BLE_HM1X_MODE_0, BLE_HM1X_TYPE_0, BLE_HM1X_SLAVE_ROLE); 198 | init_run_Timer(); 199 | 200 | EMBARC_PRINTF("\r\n/*****Enter THE TEST MODE*****/\r\n"); 201 | 202 | while (1) 203 | { 204 | LED_ALL_FLAG = 0; 205 | LED_OFF_FLAG = 0; 206 | LED_WRI_FLAG = 0; 207 | LED_RUN_FLAG = 0; 208 | LED_RED_FLAG = 0; 209 | 210 | rcv_cnt = hm1x_read(hm1x, rcv_buf, sizeof(rcv_buf)); 211 | rcv_buf[rcv_cnt] = '\0'; 212 | 213 | if (rcv_cnt) { 214 | rcv_flag = 1; 215 | } else { 216 | rcv_flag = 0; 217 | } 218 | 219 | if(rcv_flag) { 220 | for (int i = 0; i < rcv_cnt; ++i) { 221 | cmd_buf[cmd_cnt + i] = rcv_buf[i]; 222 | } 223 | cmd_cnt += rcv_cnt; 224 | //EMBARC_PRINTF("The count is %d\r\n", cmd_cnt); 225 | } 226 | 227 | if((rcv_flag == 0) && (pre_flag == 1)) { 228 | if(cmd_cnt == 6) { 229 | LED_ALL_FLAG = compare_chars(cmd_buf, LED_ALL_CMD, 6); 230 | LED_OFF_FLAG = compare_chars(cmd_buf, LED_OFF_CMD, 6); 231 | LED_RUN_FLAG = compare_chars(cmd_buf, LED_RUN_CMD, 6); 232 | LED_RED_FLAG = compare_chars(cmd_buf, LED_RED_CMD, 6); 233 | } else if(cmd_cnt == 9) { 234 | LED_WRI_FLAG = compare_chars(cmd_buf, LED_WRI_CMD, 6); 235 | } 236 | else { 237 | EMBARC_PRINTF("\r\nThe command is wrong. The count is %d\r\n", cmd_cnt); 238 | } 239 | 240 | cmd_buf[cmd_cnt] = '\r'; 241 | cmd_buf[cmd_cnt+1] = '\n'; 242 | cmd_buf[cmd_cnt+2] = '\0'; 243 | hm1x_write(hm1x, cmd_buf, cmd_cnt+2); 244 | 245 | cmd_cnt = 0; 246 | } 247 | 248 | pre_flag = rcv_flag; 249 | board_delay_ms(10, 1); 250 | 251 | if(LED_ALL_FLAG) { 252 | EMBARC_PRINTF("\r\nLED_ALL_FUN\r\n"); 253 | LED_ALL_FUN(); 254 | } else if (LED_OFF_FLAG) { 255 | EMBARC_PRINTF("\r\nLED_OFF_FUN\r\n"); 256 | LED_OFF_FUN(); 257 | } 258 | else if (LED_WRI_FLAG) { 259 | EMBARC_PRINTF("\r\nLED_WRI_FUN\r\n"); 260 | LED_WRI_FUN(cmd_buf+6, Num_CMD); 261 | } 262 | else if (LED_RUN_FLAG) { 263 | EMBARC_PRINTF("\r\nLED_RUN_FUN\r\n"); 264 | LED_RUN_FUN(); 265 | } else if (LED_RED_FLAG) { 266 | EMBARC_PRINTF("\r\nLED_RED_FUN\r\n"); 267 | LED_RED_FUN(); 268 | } 269 | 270 | } 271 | return E_SYS; 272 | } 273 | 274 | -------------------------------------------------------------------------------- /labs/lab7_ble_hm10/makefile: -------------------------------------------------------------------------------- 1 | # Application name 2 | APPL ?= Ble_Test 3 | 4 | # Optimization Level 5 | # Please Refer to toolchain_xxx.mk for this option 6 | OLEVEL ?= O2 7 | 8 | ## 9 | # Current Board And Core 10 | ## 11 | BOARD ?= emsk 12 | BD_VER ?= 22 13 | CUR_CORE ?= arcem7d 14 | 15 | ## 16 | # select debugging jtag 17 | ## 18 | JTAG ?= usb 19 | 20 | ## 21 | # Set toolchain 22 | ## 23 | TOOLCHAIN ?= mw 24 | #TOOLCHAIN ?= gnu 25 | 26 | EXT_DEV_LIST += ble/hm1x 27 | # 28 | # root dir of embARC 29 | # 30 | EMBARC_ROOT = ../../.. 31 | 32 | MID_SEL = common 33 | 34 | # application source dirs 35 | APPL_CSRC_DIR = . 36 | APPL_ASMSRC_DIR = . 37 | 38 | # application include dirs 39 | APPL_INC_DIR = . 40 | 41 | # include current project makefile 42 | COMMON_COMPILE_PREREQUISITES += makefile 43 | 44 | ### Options above must be added before include options.mk ### 45 | # include key embARC build system makefile 46 | override EMBARC_ROOT := $(strip $(subst \,/,$(EMBARC_ROOT))) 47 | include $(EMBARC_ROOT)/options/options.mk -------------------------------------------------------------------------------- /labs/lab7_ble_rn4020/main.c: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------ 2 | * Copyright (c) 2018, Synopsys, Inc. All rights reserved. 3 | 4 | * Redistribution and use in source and binary forms, with or without modification, 5 | * are permitted provided that the following conditions are met: 6 | 7 | * 1) Redistributions of source code must retain the above copyright notice, this 8 | * list of conditions and the following disclaimer. 9 | 10 | * 2) Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation and/or 12 | * other materials provided with the distribution. 13 | 14 | * 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software without 16 | * specific prior written permission. 17 | 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | * 29 | --------------------------------------------- */ 30 | 31 | #include "embARC.h" 32 | #include "embARC_debug.h" 33 | 34 | #include "board.h" 35 | #include "device/ip_hal/dev_uart.h" 36 | #include "rn4020.h" 37 | 38 | #define RN4020_PRV_SERV_HIGH_UUID 0x1122334455667788 39 | #define RN4020_PRV_SERV_LOW_UUID 0x9900AABBCCDDEEFF 40 | #define RN4020_PRV_CHAR_HIGH_UUID 0x0102030405060708 41 | #define RN4020_PRV_CHAR_LOW_UUID 0x09000A0B0C0D0E0F 42 | 43 | int32_t rn4020_set_prv_uuid(RN4020_DEF_PTR rn4020, uint64_t high_uuid, uint64_t low_uuid) 44 | { 45 | uint8_t i; 46 | uint8_t uuid_data[16]; 47 | 48 | for(i = 0; i < 16; i++) 49 | { 50 | if(i < 8) uuid_data[i] = (high_uuid >> ((7-i) << 3)) & 0xff; 51 | else uuid_data[i] = (low_uuid >> ((15-i) << 3)) & 0xff; 52 | } 53 | 54 | return rn4020_add_prv_service(rn4020, uuid_data); 55 | 56 | } 57 | 58 | int32_t rn4020_set_prv_char(RN4020_DEF_PTR rn4020, uint64_t high_uuid, uint64_t low_uuid, 59 | uint8_t property, uint8_t size, uint8_t security) 60 | { 61 | uint8_t i; 62 | uint8_t uuid_data[16]; 63 | 64 | for(i = 0; i < 16; i++) 65 | { 66 | if(i < 8) uuid_data[i] = (high_uuid >> ((7-i) << 3)) & 0xff; 67 | else uuid_data[i] = (low_uuid >> ((15-i) << 3)) & 0xff; 68 | } 69 | 70 | return rn4020_add_prv_char(rn4020, uuid_data, property, size, security); 71 | 72 | } 73 | 74 | int main(void) 75 | { 76 | 77 | uint32_t battery = 100; 78 | 79 | RN4020_DEFINE(rn4020_ble, DFSS_UART_3_ID, DFSS_GPIO_4B0_ID, 2, DFSS_GPIO_4B0_ID, 1, DFSS_GPIO_4B0_ID, 3); 80 | 81 | EMBARC_PRINTF("rn4020 test application\r\n"); 82 | 83 | rn4020_setup(rn4020_ble); 84 | rn4020_reset_to_factory(rn4020_ble); 85 | 86 | /* Set device Name */ 87 | rn4020_set_dev_name(rn4020_ble, "IoT DK"); 88 | 89 | /* Set device services */ 90 | rn4020_set_services(rn4020_ble, RN4020_SERVICE_DEVICE_INFORMATION | 91 | RN4020_SERVICE_BATTERY | 92 | RN4020_SERVICE_USER_DEFINED); 93 | 94 | rn4020_set_features(rn4020_ble, RN4020_FEATURE_SERVER_ONLY); 95 | rn4020_clear_private(rn4020_ble); 96 | 97 | /* Set private service UUID and private characteristic */ 98 | rn4020_set_prv_uuid(rn4020_ble, RN4020_PRV_SERV_HIGH_UUID, RN4020_PRV_SERV_LOW_UUID); 99 | rn4020_set_prv_char(rn4020_ble, RN4020_PRV_CHAR_HIGH_UUID, RN4020_PRV_CHAR_LOW_UUID, 0x18, 0x06, RN4020_PRIVATE_CHAR_SEC_NONE); 100 | 101 | /* Reboot RN4020 to make changes effective */ 102 | rn4020_reset(rn4020_ble); 103 | 104 | rn4020_refresh_handle_uuid_table(rn4020_ble); 105 | 106 | rn4020_advertise(rn4020_ble); 107 | 108 | 109 | while (1) { 110 | 111 | rn4020_battery_set_level(rn4020_ble, battery--); 112 | 113 | board_delay_ms(1000, 0); 114 | if (battery < 30) { 115 | battery = 100; 116 | } 117 | } 118 | 119 | return E_SYS; 120 | } 121 | 122 | -------------------------------------------------------------------------------- /labs/lab7_ble_rn4020/makefile: -------------------------------------------------------------------------------- 1 | # Application name 2 | APPL ?= Ble_Rn4020_Test 3 | 4 | # Optimization Level 5 | # Please Refer to toolchain_xxx.mk for this option 6 | OLEVEL ?= O2 7 | 8 | ## 9 | # Current Board And Core 10 | ## 11 | BOARD ?= iotdk 12 | BD_VER ?= 10 13 | CUR_CORE ?= arcem9d 14 | 15 | ## 16 | # select debugging jtag 17 | ## 18 | JTAG ?= usb 19 | 20 | ## 21 | # Set toolchain 22 | ## 23 | TOOLCHAIN ?= mw 24 | #TOOLCHAIN ?= gnu 25 | 26 | EXT_DEV_LIST += ble/rn4020 27 | # 28 | # root dir of embARC 29 | # 30 | EMBARC_ROOT = ../../.. 31 | 32 | MID_SEL = common 33 | 34 | # application source dirs 35 | APPL_CSRC_DIR = . 36 | APPL_ASMSRC_DIR = . 37 | 38 | # application include dirs 39 | APPL_INC_DIR = . 40 | 41 | # include current project makefile 42 | COMMON_COMPILE_PREREQUISITES += makefile 43 | 44 | ### Options above must be added before include options.mk ### 45 | # include key embARC build system makefile 46 | override EMBARC_ROOT := $(strip $(subst \,/,$(EMBARC_ROOT))) 47 | include $(EMBARC_ROOT)/options/options.mk -------------------------------------------------------------------------------- /labs/lab8_linker/link.cmd: -------------------------------------------------------------------------------- 1 | 2 | MEMORY { 3 | // Note: overlap of code and data spaces is not recommended since it makes 4 | // Address validity checking impossible with the debugger and simulator 5 | MyBlock: ORIGIN = 0x00002000, LENGTH = 32K 6 | MEMORY_BLOCK1: ORIGIN = 0x0010000, LENGTH = 64K 7 | MEMORY_BLOCK2: ORIGIN = 0x0020000, LENGTH = 128K 8 | } 9 | 10 | SECTIONS { 11 | GROUP: { 12 | modify_seg: {} 13 | }>MyBlock 14 | 15 | GROUP: { 16 | * (TEXT): {} 17 | }>MEMORY_BLOCK1 18 | 19 | GROUP: { 20 | .sdata?: {} 21 | .sbss?: { * {.sbss} } 22 | _SDA_BASE_=SIZEOF(.sdata)+SIZEOF(.sbss)<= 255?ADDR(.sdata):ADDR(.sdata)+256; 23 | * (LIT): {} 24 | *(DATA): {} 25 | *(BSS): {} 26 | .stack SIZE(DEFINED _STACKSIZE?_STACKSIZE:65536): {} 27 | .heap? SIZE(DEFINED _HEAPSIZE?_HEAPSIZE:0): {} 28 | }> MEMORY_BLOCK2 29 | } 30 | -------------------------------------------------------------------------------- /labs/lab8_linker/main.c: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------ 2 | * Copyright (c) 2018, Synopsys, Inc. All rights reserved. 3 | 4 | * Redistribution and use in source and binary forms, with or without modification, 5 | * are permitted provided that the following conditions are met: 6 | 7 | * 1) Redistributions of source code must retain the above copyright notice, this 8 | * list of conditions and the following disclaimer. 9 | 10 | * 2) Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation and/or 12 | * other materials provided with the distribution. 13 | 14 | * 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software without 16 | * specific prior written permission. 17 | 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | * 29 | --------------------------------------------- */ 30 | #pragma Code ("modify_seg") 31 | 32 | void modify(int list[], int size) 33 | { 34 | int out, in, temp; 35 | 36 | for(out=0; out