Skip to content

Commit 7d72469

Browse files
author
Wayne Ren
authored
Merge pull request #14 from fong5855/master
Contribute NCKU_Smart_Power_Saving_System_of_3D_Remote_Interaction Application to embARC Applications
2 parents 670b507 + 49de8e6 commit 7d72469

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+4201
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
obj_emsk*/
2+
*.log
3+
*.swp
4+
trash/
Lines changed: 270 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,270 @@
1+
#include "embARC.h"
2+
3+
#include "board.h"
4+
#include "dev_uart.h"
5+
#include "dev_pinmux.h"
6+
7+
#include "vlsi_uart.h"
8+
#include "vlsi_esp8266.h"
9+
10+
#include "slerp.h"
11+
12+
#include <stdio.h>
13+
#include "embARC_debug.h"
14+
15+
#define WIFI_SSID "\"VLSILAB_2G2\""
16+
#define WIFI_PWD "\"ur pwd\""
17+
18+
#define Q_INTP 4
19+
#define Q_SLERP (Q_INTP + 1)
20+
float R_Q[63 * Q_SLERP] = { 0.5 };
21+
float R_new[63 ] = { 0 };
22+
#define COUNT (BOARD_CPU_CLOCK/1000 * 33)
23+
24+
char esp_data_cmd[] = "AT+CIPSEND=0,252\r\n";
25+
static char http_get[] = "GET /";
26+
static char http_IDP[] = "+IPD,";
27+
28+
struct vlsi_esp* vlsi_esp_ptr;
29+
struct vlsi_esp *vlsi_esp8266;
30+
31+
void uart_init(DEV_UART_PTR* puart_obj)
32+
{
33+
uart_obj = *puart_obj;
34+
35+
int opend = uart_obj->uart_open(USE_BAUD);
36+
if (opend == AT_OK) {
37+
EMBARC_PRINTF("uart2 init done!\r\n");
38+
}
39+
40+
uart_obj->uart_control(UART_CMD_SET_RXCB, uart_cb );
41+
uart_obj->uart_control(UART_CMD_SET_RXINT, 1);
42+
uart_obj->uart_control(UART_CMD_ENA_DEV, NULL);
43+
44+
clear_rx_buf(uart_obj);
45+
46+
}
47+
48+
void esp_init(/** struct vlsi_esp* vlsi_esp8266*/)
49+
{
50+
int f;
51+
vlsi_esp8266_init(vlsi_esp8266, 115200);
52+
f = vlsi_esp8266_test(vlsi_esp8266);
53+
EMBARC_PRINTF("test %d \r\n", f);
54+
board_delay_ms(1000, 1);
55+
56+
57+
f = vlsi_esp8266_mode_set(vlsi_esp8266);
58+
EMBARC_PRINTF("mode set %d \r\n", f);
59+
board_delay_ms(1000, 1);
60+
61+
f = vlsi_esp8266_connect(vlsi_esp8266, WIFI_SSID, WIFI_PWD);
62+
if (f == AT_OK) {
63+
EMBARC_PRINTF("connect OK \r\n");
64+
}
65+
board_delay_ms(1000, 1);
66+
67+
f = vlsi_esp8266_server(vlsi_esp8266);
68+
EMBARC_PRINTF("server %d \r\n", f);
69+
board_delay_ms(1000, 1);
70+
71+
f = vlsi_esp8266_get_ip(vlsi_esp8266);
72+
board_delay_ms(1000, 1);
73+
}
74+
75+
static void timer0_isr(void *ptr)
76+
{
77+
EMBARC_PRINTF("time out\r\n");
78+
EMBARC_PRINTF("vlsi_esp8266 addr: %x", vlsi_esp8266);
79+
timer_int_clear(TIMER_1);
80+
static int i = 0;
81+
82+
vlsi_esp8266_send_datas(vlsi_esp8266, esp_data_cmd, sizeof(esp_data_cmd), (char*)(R_Q+63*i), 252);
83+
i = (i + 1) % Q_SLERP;
84+
}
85+
86+
void test_inter(DEV_UART_PTR* puart_obj)
87+
{
88+
uart_obj = *puart_obj;
89+
}
90+
91+
int main(void)
92+
{
93+
char *conn_buf;
94+
char scan_result[1024];
95+
// set pin
96+
set_pmod_mux(0x151015);
97+
set_uart_map(0x9c);
98+
99+
vlsi_esp8266 = (VLSI_ESP*)malloc(sizeof(VLSI_ESP));
100+
// uart init
101+
102+
DEV_UART_PTR uart_obj = uart_get_dev(2);
103+
104+
int opend = uart_obj->uart_open(USE_BAUD);
105+
if (opend == AT_OK) {
106+
EMBARC_PRINTF("uart2 init done!\r\n");
107+
}
108+
109+
uart_obj->uart_control(UART_CMD_SET_RXCB, uart_cb );
110+
uart_obj->uart_control(UART_CMD_SET_RXINT, 1);
111+
uart_obj->uart_control(UART_CMD_ENA_DEV, NULL);
112+
113+
clear_rx_buf(uart_obj);
114+
115+
// esp8266
116+
/** struct vlsi_esp *vlsi_esp8266; */
117+
/** EMBARC_PRINTF("ptr: %d, vlsi: %d", vlsi_esp_ptr, vlsi_esp8266); */
118+
esp_init(/** vlsi_esp8266 */);
119+
120+
char idp;
121+
122+
EMBARC_PRINTF("WiFi init done... \r\n");
123+
EMBARC_PRINTF("esp8266 addr: %x \r\n", vlsi_esp8266);
124+
125+
126+
// initialize recieve buffer
127+
scan_result[0] = '\0';
128+
129+
/** test_inter(uart_obj); */
130+
// float R_new[63];
131+
//
132+
// /** char scan_result[1024] = { 0 }; */
133+
//
134+
// while (1)
135+
// {
136+
// vlsi_esp8266_read(vlsi_esp_ptr, scan_result, 1000);
137+
//
138+
//
139+
// if (scan_result[0] != 0) {
140+
// uart_obj->uart_write("LINK", 4);
141+
// }
142+
// else
143+
// {
144+
// board_delay_ms(10, 1);
145+
// continue;
146+
// }
147+
//
148+
// EMBARC_PRINTF("initial timer...\r\n");
149+
// int_disable(INTNO_TIMER1);
150+
// timer_stop(TIMER_1);
151+
// int_handler_install(INTNO_TIMER1, timer0_isr);
152+
// int_enable(INTNO_TIMER1);
153+
// timer_start(TIMER_1, TIMER_CTRL_IE | TIMER_CTRL_NH, COUNT);
154+
// EMBARC_PRINTF("initial timer done\r\n");
155+
//
156+
// board_delay_ms(500, 1);
157+
//
158+
// while (true)
159+
// {
160+
// for (size_t i = 0; i < 63; i++)
161+
// {
162+
// R_new[i] = R[i];
163+
// }
164+
//
165+
// for (size_t i = 1; i <= Q_SLERP; i++)
166+
// {
167+
// quaternion_slerp(R_Q, R_new, R_Q + 63 * i, i / Q_SLERP);
168+
// R_Q[i + 60] = ( R_Q[60] + R_new[60] ) * i / Q_SLERP;
169+
// R_Q[i + 61] = ( R_Q[61] + R_new[61] ) * i / Q_SLERP;
170+
// R_Q[i + 62] = ( R_Q[62] + R_new[62] ) * i / Q_SLERP;
171+
// }
172+
//
173+
// for (size_t i = 0; i < 63; i++)
174+
// {
175+
// R_Q[i] = R_new[i];
176+
// }
177+
// }
178+
// }
179+
// return 0;
180+
181+
// char* send_buf = (char*)R;
182+
// while(1)
183+
// {
184+
// vlsi_esp8266_read(vlsi_esp8266, scan_result, 1000);
185+
//
186+
// if (scan_result[0] != 0) {
187+
// uart_obj->uart_write("LINK", 4);
188+
// }
189+
// board_delay_ms(1000, 1);
190+
//
191+
// // if have a call, start the trainsition
192+
// while (scan_result[0] != 0) {
193+
// EMBARC_PRINTF("recieve = %s ", scan_result);
194+
//
195+
// // find who request
196+
// idp = *(strstr(scan_result, http_IDP)+5);
197+
// EMBARC_PRINTF("idp = %c \r\n", idp);
198+
//
199+
// for (int i = 0; i < 1; ++i) {
200+
// vlsi_esp8266_send_datas(vlsi_esp8266, esp_data_cmd, sizeof(esp_data_cmd), send_buf, 252);
201+
// /** EMBARC_PRINTF("send = \n\t(%d, %d, %d, %d)\n\t(%d,%d,%d)", */
202+
// /** (*((float*)(send_buf ))) *100, */
203+
// /** (*((float*)(send_buf+1 ))) *100, */
204+
// /** (*((float*)(send_buf+2 ))) *100, */
205+
// /** (*((float*)(send_buf+3 ))) *100, */
206+
// /** (*((float*)(send_buf+60))) *100, */
207+
// /** (*((float*)(send_buf+61))) *100, */
208+
// /** (*((float*)(send_buf+62))) *100 */
209+
// /** ); */
210+
// board_delay_ms(5, 1);
211+
// }
212+
//
213+
// /* vlsi_esp8266_close(vlsi_esp8266, idp); */
214+
//
215+
// EMBARC_PRINTF("send complete %c \r\n");
216+
// }
217+
// board_delay_ms(100, 1);
218+
// }
219+
//
220+
// return E_OK;
221+
char* send_buf = (char*)R;
222+
while(1)
223+
{
224+
vlsi_esp8266_read(vlsi_esp8266, scan_result, 1000);
225+
226+
if (scan_result[0] != 0) {
227+
uart_obj->uart_write("LINK", 4);
228+
}
229+
board_delay_ms(1000, 1);
230+
231+
// if have a call, start the trainsition
232+
while (scan_result[0] != 0) {
233+
/** EMBARC_PRINTF("recieve = %s ", scan_result); */
234+
/** */
235+
/** // find who request */
236+
/** idp = *(strstr(scan_result, http_IDP)+5); */
237+
/** EMBARC_PRINTF("idp = %c \r\n", idp); */
238+
//vlsi_esp8266_send_datas(vlsi_esp8266, esp_data_cmd, sizeof(esp_data_cmd), send_buf, 252);
239+
//board_delay_ms(5, 1);
240+
//EMBARC_PRINTF("send complete %c \r\n");
241+
242+
for (size_t i = 0; i < 63; i++)
243+
{
244+
R_new[i] = R[i];
245+
}
246+
247+
for (size_t i = 1; i < Q_SLERP; i++)
248+
{
249+
for (int j = 0; j < 15; j++) {
250+
quaternion_slerp(R_Q +4*j, R_new +4*j, R_Q + 63 * i + 4*j, i / (float)Q_SLERP);
251+
}
252+
R_Q[i + 60] = ( R_Q[60] + R_new[60] ) * i /(float) Q_SLERP;
253+
R_Q[i + 61] = ( R_Q[61] + R_new[61] ) * i /(float) Q_SLERP;
254+
R_Q[i + 62] = ( R_Q[62] + R_new[62] ) * i /(float) Q_SLERP;
255+
vlsi_esp8266_send_datas(vlsi_esp8266, "AT+CIPSEND=0,252\r\n", 19, (char*)(R_Q+63*i), 252);
256+
/** vlsi_esp8266_send_datas(vlsi_esp8266, esp_data_cmd, sizeof(esp_data_cmd), (char*)(R_Q+63*i), 252); */
257+
//board_delay_ms(5, 1);
258+
EMBARC_PRINTF("send complete %c \r\n");
259+
}
260+
261+
for (size_t i = 0; i < 63; i++)
262+
{
263+
R_Q[i] = R_new[i];
264+
}
265+
}
266+
board_delay_ms(100, 1);
267+
}
268+
269+
return E_OK;
270+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
## embARC application makefile template ##
2+
### You can copy this file to your application folder
3+
### and rename it to makefile.
4+
##
5+
6+
# Application name
7+
APPL ?= NCKU_Smart_Power_Saving_System_of_3D_Remote_Interaction
8+
9+
# Optimization Level
10+
# Please Refer to toolchain_xxx.mk for this option
11+
OLEVEL ?=O2
12+
13+
##
14+
# Current Board And Core
15+
##
16+
BOARD ?= emsk
17+
BD_VER ?= 22
18+
CUR_CORE ?= arcem7d
19+
20+
##
21+
# select debugging jtag
22+
##
23+
JTAG ?= usb
24+
25+
##
26+
# Set toolchain
27+
##
28+
TOOLCHAIN ?= gnu
29+
30+
##
31+
# Uncomment following options
32+
# if you want to set your own heap and stack size
33+
# Default settings see options.mk
34+
##
35+
#HEAPSZ ?= 8192
36+
#STACKSZ ?= 8192
37+
38+
##
39+
# Uncomment following options
40+
# if you want to add your own library into link process
41+
# For example:
42+
# If you want link math lib for gnu toolchain,
43+
# you need to set the option to -lm
44+
##
45+
#APPL_LIBS ?=
46+
47+
#
48+
# root dir of embARC
49+
#
50+
EMBARC_ROOT = ../../../../..
51+
52+
MID_SEL = common
53+
54+
# application source dirs
55+
APPL_CSRC_DIR = .
56+
APPL_ASMSRC_DIR = .
57+
58+
# application include dirs
59+
APPL_INC_DIR = .
60+
61+
# application defines
62+
APPL_DEFINES =
63+
64+
# include current project makefile
65+
COMMON_COMPILE_PREREQUISITES += makefile
66+
67+
### Options above must be added before include options.mk ###
68+
# include key embARC build system makefile
69+
override EMBARC_ROOT := $(strip $(subst \,/,$(EMBARC_ROOT)))
70+
include $(EMBARC_ROOT)/options/options.mk

0 commit comments

Comments
 (0)