-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconductor_tool_demo.c
350 lines (311 loc) · 9.72 KB
/
conductor_tool_demo.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
/* Copyright (C) 2023-2024 Alif Semiconductor - All Rights Reserved.
* Use, distribution and modification of this code is permitted under the
* terms stated in the Alif Semiconductor Software License Agreement
*
* You should have received a copy of the Alif Semiconductor Software
* License Agreement with this file. If not, please write to:
* [email protected], or visit: https://alifsemi.com/license
*
*/
#include "uart_tracelib.h"
#include "global_map.h"
#include "board.h"
#include "Driver_GPIO.h"
#include "pinconf.h"
#include <inttypes.h>
#include <stdio.h>
#include <stdatomic.h>
#include <time.h>
#include "RTE_Components.h"
#include CMSIS_device_header
/*
* Version info
*/
#define VERSION_MAJOR (1)
#define VERSION_MINOR (0)
/* LED0 gpio pins */
#define GPIO12_PORT 12 /*< Use LED0_R,LED0_B GPIO port >*/
#define GPIO7_PORT 7 /*< Use LED0_G GPIO port >*/
#define PIN3 3 /*< LED0_R gpio pin >*/
#define PIN4 4 /*< LED0_G gpio pin >*/
#define PIN0 0 /*< LED0_B gpio pin >*/
/* LED1 gpio pins */
#define GPIO6_PORT 6 /*< Use LED1_R,LED1_B,LED1_R GPIO port >*/
#define PIN2 2 /*< LED1_R gpio pin >*/
#define PIN4 4 /*< LED1_G gpio pin >*/
#define PIN6 6 /*< LED1_B gpio pin >*/
#if M55_HE
/* GPIO port used for LED0_R & LED0_B */
extern ARM_DRIVER_GPIO ARM_Driver_GPIO_(GPIO12_PORT);
ARM_DRIVER_GPIO *gpioDrv12 = &ARM_Driver_GPIO_(GPIO12_PORT);
/* GPIO port used for LED0_G */
extern ARM_DRIVER_GPIO ARM_Driver_GPIO_(GPIO7_PORT);
ARM_DRIVER_GPIO *gpioDrv7 = &ARM_Driver_GPIO_(GPIO7_PORT);
#else
/* GPIO port used for LED1_R, LED1_B & LED1_G */
extern ARM_DRIVER_GPIO ARM_Driver_GPIO_(GPIO6_PORT);
ARM_DRIVER_GPIO *gpioDrv6 = &ARM_Driver_GPIO_(GPIO6_PORT);
#endif
void wait_second()
{
for (int i = 0; i < 10; i++) {
sys_busy_loop_us(100*1000);
}
}
/**
\fn void led_blink_app(void)
\brief LED blinky function
\param[in] none
\return none
*/
void led_blink_app (void)
{
/*
* gpio12 pin3 can be used as Red LED of LED0.
* gpio7 pin4 can be used as Green LED of LED0.
* gpio12 pin0 can be used as Blue LED of LED0.
*
* gpio6 pin2 can be used as Red LED of LED1.
* gpio6 pin4 can be used as Green LED of LED1.
* gpio6 pin6 can be used as Blue LED of LED1.
*
* This demo application is about.
* - HE Core blinks LED0, HP Core blink LED1
* - Blink LED0_R and LED1_R, then LED0_B and LED1_B, then LED0_G and LED1_G simultaneously in rotation.
*/
int32_t ret = 0;
#if M55_HE
uint8_t LED0_R = PIN3;
uint8_t LED0_G = PIN4;
uint8_t LED0_B = PIN0;
ret = gpioDrv12->Initialize(LED0_R, NULL);
ret |= gpioDrv7->Initialize(LED0_G, NULL);
ret |= gpioDrv12->Initialize(LED0_B, NULL);
#else
uint8_t LED1_R = PIN2;
uint8_t LED1_G = PIN4;
uint8_t LED1_B = PIN6;
ret = gpioDrv6->Initialize(LED1_R, NULL);
ret |= gpioDrv6->Initialize(LED1_G, NULL);
ret |= gpioDrv6->Initialize(LED1_B, NULL);
#endif
if (ret != ARM_DRIVER_OK) {
printf("ERROR: Failed to initialize\n");
goto error_uninitialize;
}
#if M55_HE
ret = gpioDrv12->PowerControl(LED0_R, ARM_POWER_FULL);
ret |= gpioDrv7->PowerControl(LED0_G, ARM_POWER_FULL);
ret |= gpioDrv12->PowerControl(LED0_B, ARM_POWER_FULL);
#else
ret = gpioDrv6->PowerControl(LED1_R, ARM_POWER_FULL);
ret |= gpioDrv6->PowerControl(LED1_G, ARM_POWER_FULL);
ret |= gpioDrv6->PowerControl(LED1_B, ARM_POWER_FULL);
#endif
if (ret != ARM_DRIVER_OK) {
printf("ERROR: Failed to powered full\n");
return;
}
#if M55_HE
ret = gpioDrv12->SetDirection(LED0_R, GPIO_PIN_DIRECTION_OUTPUT);
ret |= gpioDrv7->SetDirection(LED0_G, GPIO_PIN_DIRECTION_OUTPUT);
ret |= gpioDrv12->SetDirection(LED0_B, GPIO_PIN_DIRECTION_OUTPUT);
#else
ret = gpioDrv6->SetDirection(LED1_R, GPIO_PIN_DIRECTION_OUTPUT);
ret |= gpioDrv6->SetDirection(LED1_G, GPIO_PIN_DIRECTION_OUTPUT);
ret |= gpioDrv6->SetDirection(LED1_B, GPIO_PIN_DIRECTION_OUTPUT);
#endif
if (ret != ARM_DRIVER_OK) {
printf("ERROR: Failed to configure\n");
return;
}
while (1)
{
/* Toggle Red LED */
#if M55_HE
ret = gpioDrv12->SetValue(LED0_R, GPIO_PIN_OUTPUT_STATE_HIGH);
#else
ret = gpioDrv6->SetValue(LED1_R, GPIO_PIN_OUTPUT_STATE_HIGH);
#endif
if (ret != ARM_DRIVER_OK) {
printf("ERROR: Failed to toggle LEDs\n");
goto error_power_off;
}
/* wait for 1 Sec */
wait_second();
#if M55_HE
ret = gpioDrv12->SetValue(LED0_R, GPIO_PIN_OUTPUT_STATE_LOW);
#else
ret = gpioDrv6->SetValue(LED1_R, GPIO_PIN_OUTPUT_STATE_LOW);
#endif
if (ret != ARM_DRIVER_OK) {
printf("ERROR: Failed to toggle LEDs\n");
goto error_power_off;
}
/* wait for 1 Sec */
wait_second();
/* Toggle Green LED */
#if M55_HE
ret = gpioDrv7->SetValue(LED0_G, GPIO_PIN_OUTPUT_STATE_HIGH);
#else
ret = gpioDrv6->SetValue(LED1_G, GPIO_PIN_OUTPUT_STATE_HIGH);
#endif
if (ret != ARM_DRIVER_OK) {
printf("ERROR: Failed to toggle LEDs\n");
goto error_power_off;
}
/* wait for 1 Sec */
wait_second();
#if M55_HE
ret = gpioDrv7->SetValue(LED0_G, GPIO_PIN_OUTPUT_STATE_LOW);
#else
ret = gpioDrv6->SetValue(LED1_G, GPIO_PIN_OUTPUT_STATE_LOW);
#endif
if (ret != ARM_DRIVER_OK) {
printf("ERROR: Failed to toggle LEDs\n");
goto error_power_off;
}
/* wait for 1 Sec */
wait_second();
/* Toggle Blue LED */
#if M55_HE
ret = gpioDrv12->SetValue(LED0_B, GPIO_PIN_OUTPUT_STATE_HIGH);
#else
ret = gpioDrv6->SetValue(LED1_B, GPIO_PIN_OUTPUT_STATE_HIGH);
#endif
if (ret != ARM_DRIVER_OK) {
printf("ERROR: Failed to toggle LEDs\n");
goto error_power_off;
}
/* wait for 1 Sec */
wait_second();
#if M55_HE
ret = gpioDrv12->SetValue(LED0_B, GPIO_PIN_OUTPUT_STATE_LOW);
#else
ret = gpioDrv6->SetValue(LED1_B, GPIO_PIN_OUTPUT_STATE_LOW);
#endif
if (ret != ARM_DRIVER_OK) {
printf("ERROR: Failed to toggle LEDs\n");
goto error_power_off;
}
/* wait for 1 Sec */
wait_second();
}
error_power_off:
#if M55_HE
ret = gpioDrv12->PowerControl(LED0_R, ARM_POWER_OFF);
ret |= gpioDrv7->PowerControl(LED0_G, ARM_POWER_OFF);
ret |= gpioDrv12->PowerControl(LED0_B, ARM_POWER_OFF);
#else
ret = gpioDrv6->PowerControl(LED1_R, ARM_POWER_OFF);
ret |= gpioDrv6->PowerControl(LED1_G, ARM_POWER_OFF);
ret |= gpioDrv6->PowerControl(LED1_B, ARM_POWER_OFF);
#endif
if (ret != ARM_DRIVER_OK) {
printf("ERROR: Failed to power off \n");
} else {
printf("LEDs power off \n");
}
error_uninitialize:
#if M55_HE
ret = gpioDrv12->Uninitialize(LED0_R);
ret |= gpioDrv7->Uninitialize(LED0_G);
ret |= gpioDrv12->Uninitialize(LED0_B);
#else
ret = gpioDrv6->Uninitialize(LED1_R);
ret |= gpioDrv6->Uninitialize(LED1_G);
ret |= gpioDrv6->Uninitialize(LED1_B);
#endif
if (ret != ARM_DRIVER_OK) {
printf("Failed to Un-initialize \n");
} else {
printf("Un-initialized \n");
}
}
static void uart_callback(uint32_t event)
{
(void)event;
}
static void init_system()
{
BOARD_Pinmux_Init();
}
/* ESCLK_SEL Register: 0x10, R/W, Clock Select Register for M55-HP and M55-HE
bits 1-0 (0x03): Select PLL clock frequency for RTSS_HP_CLK
0x0: Select 100 MHz PLL clock
0x1: Select 200 MHz PLL clock
0x2: Select 300 MHz PLL clock
0x3: Select 400 MHz PLL clock
bits 5-4 (0x30): Select PLL clock frequency for RTSS_HE_CLK
0x0: Select 60 MHz PLL clock
0x1: Select 80 MHz PLL clock
0x2: Select 120 MHz PLL clock
0x3: Select 160 MHz PLL clock */
void print_clocks()
{
uint32_t *clk_reg = (uint32_t*)(CGU_BASE + 0x10);
uint32_t he_clk;
uint32_t hp_clk;
switch ((*clk_reg) & 0x03)
{
case 0:
hp_clk = 100;
break;
case 1:
hp_clk = 200;
break;
case 2:
hp_clk = 300;
break;
case 3:
default:
hp_clk = 400;
break;
}
switch ((*clk_reg) & 0x30)
{
case 0x00:
he_clk = 60;
break;
case 0x10:
he_clk = 80;
break;
case 0x20:
he_clk = 120;
break;
case 0x30:
default:
he_clk = 160;
break;
}
printf("\nHP clock frequency = %" PRIu32 "Mhz\n", hp_clk);
printf("HE clock frequency = %" PRIu32 "Mhz\n", he_clk);
}
int main()
{
init_system();
tracelib_init(NULL, uart_callback);
#if M55_HE
printf("\nConductor Tool Demo app v%" PRIu32 ".%" PRIu32 " on M55_HE\n\n", (uint32_t)VERSION_MAJOR, (uint32_t)VERSION_MINOR);
#else
printf("\nConductor Tool Demo app v%" PRIu32 ".%" PRIu32 " on M55_HP\n\n", (uint32_t)VERSION_MAJOR, (uint32_t)VERSION_MINOR);
#endif
#if MEMORY_STITCHING
printf("Trying to read from relocated SRAM1 (0x%08" PRIx32 ")\n", (uint32_t)0x02400000);
volatile uint32_t *data = (uint32_t*)0x02400000;
printf("Data from SRAM1: 0x%08" PRIx32 "\n", *data);
#else
#if M55_HE
printf("Trying to read SRAM1 (0x%08" PRIx32 ")\n", (uint32_t)SRAM1_BASE);
volatile uint32_t *data = (uint32_t*)SRAM1_BASE;
printf("Data from SRAM1: 0x%08" PRIx32 "\n", *data);
#else
printf("Trying to read SRAM0 (0x%08" PRIx32 ")\n", (uint32_t)SRAM0_BASE);
volatile uint32_t *data = (uint32_t*)SRAM0_BASE;
printf("Data from SRAM0: 0x%08" PRIx32 "\n", *data);
#endif
#endif
print_clocks();
led_blink_app();
return 0;
}