Skip to content

Commit 33f9bbc

Browse files
committed
update
1 parent c488012 commit 33f9bbc

File tree

9 files changed

+7315
-16
lines changed

9 files changed

+7315
-16
lines changed

arc_design_contest/2018/NCTU_Smart Pillow/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ set_pmod_mux(mux_regs, PM1_UR_UART_0 | PM1_LR_SPI_S \
113113
```
114114
* dw_uart_obj.h
115115
* dw_uart_obj.c
116+
117+
In order to calculate **CPU Loading**
118+
We need to modify following files
119+
* task.h
120+
* task.c
116121
### Run This Application
117122

118123
Here take **EMSK2.2 - ARC EM7DFPU**
Lines changed: 346 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,346 @@
1+
/* ------------------------------------------
2+
* Copyright (c) 2016, 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+
* \version 2016.05
30+
* \date 2014-07-03
31+
* \author Huaqi Fang(Huaqi.Fang@synopsys.com)
32+
--------------------------------------------- */
33+
34+
/**
35+
* \defgroup BOARD_EMSK_DRV_DW_UART_OBJ EMSK DW UART Object
36+
* \ingroup BOARD_EMSK_DRIVER
37+
* \brief EMSK Designware UART Objects
38+
* \details
39+
* Realize the EMSK board uart object using Designware uart device driver,
40+
* only need to realize some Designware uart structures combine with EMSK uart
41+
* hardware resource. just like cpp class instantiation.
42+
*/
43+
44+
/**
45+
* \file
46+
* \ingroup BOARD_EMSK_DRV_DW_UART_OBJ
47+
* \brief designware uart object instantiation on emsk
48+
*/
49+
50+
/**
51+
* \addtogroup BOARD_EMSK_DRV_DW_UART_OBJ
52+
* @{
53+
*/
54+
#include "arc.h"
55+
#include "arc_builtin.h"
56+
#include "embARC_toolchain.h"
57+
#include "embARC_error.h"
58+
59+
#include "arc_exception.h"
60+
61+
#include "dw_uart.h"
62+
#include "dw_uart_obj.h"
63+
64+
#include "../../emsk.h"
65+
66+
#define PERIPHERAL_BASE _arc_aux_read(AUX_DMP_PERIPHERAL)
67+
#define DW_UART_FIFO_LEN 32
68+
/**
69+
* \name EMSK DesignWare UART 0 Object Instantiation
70+
* @{
71+
*/
72+
#if (USE_DW_UART_0)
73+
static void dw_uart_0_isr(void *ptr);
74+
#define DW_UART_0_RELBASE (REL_REGBASE_UART0) /*!< designware uart 0 relative baseaddr */
75+
#define DW_UART_0_INTNO (INTNO_UART0) /*!< designware uart 0 interrupt number */
76+
77+
DEV_UART dw_uart_0; /*!< designware uart object */
78+
DW_UART_CTRL dw_uart_0_ctrl = { /*!< designware uart 0 ctrl */
79+
0, CLK_BUS_APB, DW_UART_0_INTNO, (INT_HANDLER)dw_uart_0_isr,
80+
DW_UART_FIFO_LEN, DW_UART_FIFO_LEN, 0
81+
};
82+
83+
/** designware uart 0 open */
84+
static int32_t dw_uart_0_open (uint32_t baud)
85+
{
86+
return dw_uart_open(&dw_uart_0, baud);
87+
}
88+
/** designware uart 0 close */
89+
static int32_t dw_uart_0_close (void)
90+
{
91+
return dw_uart_close(&dw_uart_0);
92+
}
93+
/** designware uart 0 control */
94+
static int32_t dw_uart_0_control (uint32_t ctrl_cmd, void *param)
95+
{
96+
return dw_uart_control(&dw_uart_0, ctrl_cmd, param);
97+
}
98+
/** designware uart 0 write */
99+
static int32_t dw_uart_0_write (const void *data, uint32_t len)
100+
{
101+
return dw_uart_write(&dw_uart_0, data, len);
102+
}
103+
/** designware uart 0 close */
104+
static int32_t dw_uart_0_read (void *data, uint32_t len)
105+
{
106+
return dw_uart_read(&dw_uart_0, data, len);
107+
}
108+
/** designware uart 0 interrupt rountine */
109+
static void dw_uart_0_isr(void *ptr)
110+
{
111+
dw_uart_isr(&dw_uart_0, ptr);
112+
}
113+
/** install designware uart 0 to system */
114+
static void dw_uart_0_install(void)
115+
{
116+
uint32_t uart_abs_base = 0;
117+
DEV_UART *dw_uart_ptr = &dw_uart_0;
118+
DEV_UART_INFO *dw_uart_info_ptr = &(dw_uart_0.uart_info);
119+
DW_UART_CTRL *dw_uart_ctrl_ptr = &dw_uart_0_ctrl;
120+
121+
/**
122+
* get absolute designware base address
123+
*/
124+
uart_abs_base = (uint32_t)PERIPHERAL_BASE + DW_UART_0_RELBASE;
125+
dw_uart_ctrl_ptr->dw_uart_regbase = uart_abs_base;
126+
127+
/** uart info init */
128+
dw_uart_info_ptr->uart_ctrl = (void *)dw_uart_ctrl_ptr;
129+
dw_uart_info_ptr->opn_cnt = 0;
130+
dw_uart_info_ptr->status = 0;
131+
dw_uart_info_ptr->baudrate = UART_BAUDRATE_115200; /* default 115200bps */
132+
133+
/** uart dev init */
134+
dw_uart_ptr->uart_open = dw_uart_0_open;
135+
dw_uart_ptr->uart_close = dw_uart_0_close;
136+
dw_uart_ptr->uart_control = dw_uart_0_control;
137+
dw_uart_ptr->uart_write = dw_uart_0_write;
138+
dw_uart_ptr->uart_read = dw_uart_0_read;
139+
140+
}
141+
#endif /* USE_DW_UART_0 */
142+
/** @} end of name */
143+
144+
/**
145+
* \name EMSK DesignWare UART 1 Object Instantiation
146+
* @{
147+
*/
148+
#if (USE_DW_UART_1)
149+
static void dw_uart_1_isr(void *ptr);
150+
#define DW_UART_1_RELBASE (REL_REGBASE_UART1) /*!< designware uart 1 relative baseaddr */
151+
#define DW_UART_1_INTNO (INTNO_UART1) /*!< designware uart 1 interrupt number */
152+
153+
DEV_UART dw_uart_1; /*!< designware uart 1 object */
154+
DW_UART_CTRL dw_uart_1_ctrl = { /*!< designware uart 1 ctrl */
155+
0, CLK_BUS_APB, DW_UART_1_INTNO, (INT_HANDLER)dw_uart_1_isr,
156+
DW_UART_FIFO_LEN, DW_UART_FIFO_LEN, 0
157+
};
158+
159+
/** designware uart 1 open */
160+
static int32_t dw_uart_1_open (uint32_t baud)
161+
{
162+
return dw_uart_open(&dw_uart_1, baud);
163+
}
164+
/** designware uart 1 close */
165+
static int32_t dw_uart_1_close (void)
166+
{
167+
return dw_uart_close(&dw_uart_1);
168+
}
169+
/** designware uart 1 control */
170+
static int32_t dw_uart_1_control (uint32_t ctrl_cmd, void *param)
171+
{
172+
return dw_uart_control(&dw_uart_1, ctrl_cmd, param);
173+
}
174+
/** designware uart 1 write */
175+
static int32_t dw_uart_1_write (const void *data, uint32_t len)
176+
{
177+
return dw_uart_write(&dw_uart_1, data, len);
178+
}
179+
/** designware uart 1 close */
180+
static int32_t dw_uart_1_read (void *data, uint32_t len)
181+
{
182+
return dw_uart_read(&dw_uart_1, data, len);
183+
}
184+
/** designware uart 1 interrupt routine */
185+
static void dw_uart_1_isr(void *ptr)
186+
{
187+
dw_uart_isr(&dw_uart_1, ptr);
188+
}
189+
/** install designware uart 1 to system */
190+
static void dw_uart_1_install(void)
191+
{
192+
uint32_t uart_abs_base = 0;
193+
DEV_UART *dw_uart_ptr = &dw_uart_1;
194+
DEV_UART_INFO *dw_uart_info_ptr = &(dw_uart_1.uart_info);
195+
DW_UART_CTRL *dw_uart_ctrl_ptr = &dw_uart_1_ctrl;
196+
197+
/**
198+
* get absolute designware base address
199+
*/
200+
uart_abs_base = (uint32_t)PERIPHERAL_BASE + DW_UART_1_RELBASE;
201+
dw_uart_ctrl_ptr->dw_uart_regbase = uart_abs_base;
202+
203+
/** uart info init */
204+
dw_uart_info_ptr->uart_ctrl = (void *)dw_uart_ctrl_ptr;
205+
dw_uart_info_ptr->opn_cnt = 0;
206+
dw_uart_info_ptr->status = 0;
207+
dw_uart_info_ptr->baudrate = UART_BAUDRATE_115200; /* default 115200bps */
208+
209+
/** uart dev init */
210+
dw_uart_ptr->uart_open = dw_uart_1_open;
211+
dw_uart_ptr->uart_close = dw_uart_1_close;
212+
dw_uart_ptr->uart_control = dw_uart_1_control;
213+
dw_uart_ptr->uart_write = dw_uart_1_write;
214+
dw_uart_ptr->uart_read = dw_uart_1_read;
215+
}
216+
#endif /* USE_DW_UART_1 */
217+
/** @} end of name */
218+
219+
220+
/**
221+
* \name EMSK DesignWare UART 2 Object Instantiation
222+
* @{
223+
*/
224+
#if (USE_DW_UART_2)
225+
static void dw_uart_2_isr(void *ptr);
226+
#define DW_UART_2_RELBASE (REL_REGBASE_UART2) /*!< designware uart 2 relative baseaddr */
227+
#define DW_UART_2_INTNO (INTNO_UART2) /*!< designware uart 2 interrupt number */
228+
229+
DEV_UART dw_uart_2; /*!< designware uart 2 object */
230+
DW_UART_CTRL dw_uart_2_ctrl = { /*!< designware uart 2 ctrl */
231+
0, CLK_BUS_APB, DW_UART_2_INTNO, (INT_HANDLER)dw_uart_2_isr,
232+
DW_UART_FIFO_LEN, DW_UART_FIFO_LEN, 0
233+
};
234+
235+
/** designware uart 2 open */
236+
static int32_t dw_uart_2_open (uint32_t baud)
237+
{
238+
return dw_uart_open(&dw_uart_2, baud);
239+
}
240+
/** designware uart 2 close */
241+
static int32_t dw_uart_2_close (void)
242+
{
243+
return dw_uart_close(&dw_uart_2);
244+
}
245+
/** designware uart 2 control */
246+
static int32_t dw_uart_2_control (uint32_t ctrl_cmd, void *param)
247+
{
248+
return dw_uart_control(&dw_uart_2, ctrl_cmd, param);
249+
}
250+
/** designware uart 2 write */
251+
static int32_t dw_uart_2_write (const void *data, uint32_t len)
252+
{
253+
return dw_uart_write(&dw_uart_2, data, len);
254+
}
255+
/** designware uart 2 close */
256+
static int32_t dw_uart_2_read (void *data, uint32_t len)
257+
{
258+
return dw_uart_read(&dw_uart_2, data, len);
259+
}
260+
/** designware uart 2 interrupt routine */
261+
static void dw_uart_2_isr(void *ptr)
262+
{
263+
dw_uart_isr(&dw_uart_2, ptr);
264+
}
265+
/** install designware uart 2 to system */
266+
static void dw_uart_2_install(void)
267+
{
268+
uint32_t uart_abs_base = 0;
269+
DEV_UART *dw_uart_ptr = &dw_uart_2;
270+
DEV_UART_INFO *dw_uart_info_ptr = &(dw_uart_2.uart_info);
271+
DW_UART_CTRL *dw_uart_ctrl_ptr = &dw_uart_2_ctrl;
272+
273+
/**
274+
* get absolute designware base address
275+
*/
276+
uart_abs_base = (uint32_t)PERIPHERAL_BASE + DW_UART_2_RELBASE;
277+
dw_uart_ctrl_ptr->dw_uart_regbase = uart_abs_base;
278+
279+
/** uart info init */
280+
dw_uart_info_ptr->uart_ctrl = (void *)dw_uart_ctrl_ptr;
281+
dw_uart_info_ptr->opn_cnt = 0;
282+
dw_uart_info_ptr->status = 0;
283+
dw_uart_info_ptr->baudrate = UART_BAUDRATE_115200; /* default 115200bps */
284+
285+
/** uart dev init */
286+
dw_uart_ptr->uart_open = dw_uart_2_open;
287+
dw_uart_ptr->uart_close = dw_uart_2_close;
288+
dw_uart_ptr->uart_control = dw_uart_2_control;
289+
dw_uart_ptr->uart_write = dw_uart_2_write;
290+
dw_uart_ptr->uart_read = dw_uart_2_read;
291+
}
292+
#endif /* USE_DW_UART_2 */
293+
/** @} end of name */
294+
295+
296+
/** get one designware device structure */
297+
DEV_UART_PTR uart_get_dev(int32_t uart_id)
298+
{
299+
static uint32_t install_flag = 0;
300+
301+
/* intall device objects */
302+
if (install_flag == 0) {
303+
install_flag = 1;
304+
dw_uart_all_install();
305+
}
306+
307+
switch (uart_id) {
308+
#if (USE_DW_UART_0)
309+
case DW_UART_0_ID:
310+
return &dw_uart_0;
311+
break;
312+
#endif
313+
#if (USE_DW_UART_1)
314+
case DW_UART_1_ID:
315+
return &dw_uart_1;
316+
break;
317+
#endif
318+
#if (USE_DW_UART_2)
319+
case DW_UART_2_ID:
320+
return &dw_uart_2;
321+
break;
322+
#endif
323+
default:
324+
break;
325+
}
326+
return NULL;
327+
}
328+
329+
/**
330+
* \brief install all uart objects
331+
* \note \b MUST be called during system init
332+
*/
333+
void dw_uart_all_install(void)
334+
{
335+
#if (USE_DW_UART_0)
336+
dw_uart_0_install();
337+
#endif
338+
#if (USE_DW_UART_1)
339+
dw_uart_1_install();
340+
#endif
341+
#if (USE_DW_UART_2)
342+
dw_uart_2_install();
343+
#endif
344+
}
345+
346+
/** @} end of group BOARD_EMSK_DRV_DW_UART_OBJ */

0 commit comments

Comments
 (0)