-
Notifications
You must be signed in to change notification settings - Fork 0
/
said.c
441 lines (382 loc) · 13 KB
/
said.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
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
/*
* said.c
*
* Created on: 2024-06-21
* Author: GDR
*/
#include "cy_pdl.h"
#include "cyhal.h"
#include "cybsp.h"
#include "stdio.h"
#include "said.h"
#include <amsOsram_sources/Selectives/osp2/inc/osp2.h>
#include <amsOsram_sources/Hal/CY_Gpios/inc/pin.h>
// Tests several of the basic SAID features
void said(void)
{
osp2_error_t err;
uint16_t last;
uint8_t temp;
uint8_t stat;
uint8_t flags;
uint32_t id;
uint16_t red;
uint16_t green;
uint16_t blue;
uint8_t rcur;
uint8_t gcur;
uint8_t bcur;
uint8_t daytimes;
uint8_t com;
uint8_t buf[8];
err = 0;
printf("\n\rASSUMPTION: MCU-OSIRE-OSIRE-SAID(RGB,RGB,I2C)-OSIRE-OSIRE\n\r");
printf("\n\rINIT\n\r");
err|=osp2_exec_reset();
if(err)
{
printf("reset command fail.\n\r");
goto exit_with_error;
}
err|=osp2_send_initbidir(1,&last,&temp,&stat);
if(err)
{
printf("initbidir command fail.\n\r");
goto exit_with_error;
}
/*Making sure we have RAB5-OSIRE mounted*/
if(last < 5)
{
printf("RAB5-OSIRE adapter board not detected.\n\r");
goto exit_with_error;
}
else
{
osp2_send_identify(3,&id);
if(id != 0x40)
{
printf("RAB5-OSIRE adapter board not detected.\n\r");
goto exit_with_error;
}
}
printf("\n\rSETUP (enable CRC)\n\r");
err|=osp2_send_setsetup(1, OSP2_SETUP_FLAGS_OSIRE_DFLT | OSP2_SETUP_FLAGS_CRCEN );
err|=osp2_send_setsetup(2, OSP2_SETUP_FLAGS_OSIRE_DFLT | OSP2_SETUP_FLAGS_CRCEN );
err|=osp2_send_setsetup(3, OSP2_SETUP_FLAGS_SAID_DFLT | OSP2_SETUP_FLAGS_CRCEN );
err|=osp2_send_setsetup(4, OSP2_SETUP_FLAGS_OSIRE_DFLT | OSP2_SETUP_FLAGS_CRCEN );
err|=osp2_send_setsetup(5, OSP2_SETUP_FLAGS_OSIRE_DFLT | OSP2_SETUP_FLAGS_CRCEN );
err|=osp2_send_readsetup(1,&flags );
printf("Device 1 setup flags: 0x%2X\n\r", flags);
err|=osp2_send_readsetup(2,&flags );
printf("Device 2 setup flags: 0x%2X\n\r", flags);
err|=osp2_send_readsetup(3,&flags );
printf("Device 3 setup flags: 0x%2X\n\r", flags);
err|=osp2_send_readsetup(4,&flags );
printf("Device 4 setup flags: 0x%2X\n\r", flags);
err|=osp2_send_readsetup(5,&flags );
printf("Device 5 setup flags: 0x%2X\n\r", flags);
printf("\n\rSTATUS CHECK\n\r");
err|=osp2_send_clrerror(0); // all SAIDs have the V flag (overvoltage) after reset, clear those
err|=osp2_send_readtempstat(3, &temp, &stat);
printf("\n\rID'S\n\r");
err|=osp2_send_readotp(3,0x00,buf,3);
err|=osp2_send_identify(1,&id);
printf("Device 1 ID: 0x%2X\n\r", (unsigned int)id);
err|=osp2_send_identify(2,&id);
printf("Device 2 ID: 0x%2X\n\r", (unsigned int)id);
err|=osp2_send_identify(3,&id);
printf("Device 3 ID: 0x%2X\n\r", (unsigned int)id);
err|=osp2_send_identify(4,&id);
printf("Device 4 ID: 0x%2X\n\r", (unsigned int)id);
err|=osp2_send_identify(5,&id);
printf("Device 5 ID: 0x%2X\n\r", (unsigned int)id);
printf("\n\rPWM ON\n\r");
err|=osp2_send_setpwm (1, 0x0200,0x0002,0x0020,0b000);
err|=osp2_send_setpwm (2, 0x0200,0x0002,0x0020,0b000);
err|=osp2_send_setpwmchn(3,0,0x3333,0x2222,0x1111);
err|=osp2_send_setpwmchn(3,1,0x3333,0x2222,0x1111);
err|=osp2_send_setpwm (4, 0x0200,0x0002,0x0020,0b000);
err|=osp2_send_setpwm (5, 0x0200,0x0002,0x0020,0b000);
err|=osp2_send_readpwm(1,&red, &green, &blue, &daytimes );
err|=osp2_send_readpwm(2,&red, &green, &blue, &daytimes );
err|=osp2_send_readpwmchn(3,0, &red, &green, &blue );
err|=osp2_send_readpwmchn(3,1, &red, &green, &blue );
err|=osp2_send_readpwm(4,&red, &green, &blue, &daytimes );
err|=osp2_send_readpwm(5,&red, &green, &blue, &daytimes );
err|=osp2_send_goactive(0);
printf("\n\rSYNC\n\r");
err|=osp2_send_readcurchn(3,1, &flags, &rcur, &gcur, &bcur);
err|=osp2_send_setcurchn(3,1, OSP2_CURCHN_FLAGS_SYNCEN, 0, 0, 0);
err|=osp2_send_setpwmchn(3,1, 0x3333,0x2222,0x1111); // swap blue to green
err|=osp2_send_sync(0);
printf("\n\rTEMP\n\r");
err|=osp2_send_readtemp(1, &temp);
printf("Device 1 Temperature Register: %d\n\r", temp);
err|=osp2_send_readtemp(2, &temp);
printf("Device 2 Temperature Register: %d\n\r", temp);
err|=osp2_send_readtemp(3, &temp);
printf("Device 3 Temperature Register: %d\n\r", temp);
err|=osp2_send_readtemp(4, &temp);
printf("Device 4 Temperature Register: %d\n\r", temp);
err|=osp2_send_readtemp(5, &temp);
printf("Device 5 Temperature Register: %d\n\r", temp);
printf("\n\rCOM STATUS\n\r");
err|=osp2_send_readcomst(1, &com);
printf("Device 1 com status: %d\n\r", com);
err|=osp2_send_readcomst(2, &com);
printf("Device 2 com status: %d\n\r", com);
err|=osp2_send_readcomst(3, &com);
printf("Device 3 com status: %d\n\r", com);
err|=osp2_send_readcomst(4, &com);
printf("Device 4 com status: %d\n\r", com);
err|=osp2_send_readcomst(5, &com);
printf("Device 5 com status: %d\n\r", com);
printf("\n\rSTATUS CHECK\n\r");
err|=osp2_send_readtempstat(1, &temp, &stat);
if( stat & OSP2_SETUP_FLAGS_OSIRE_ERRORS ) { printf("ERROR status\n\r"); err|=OSP2_ERROR_STATUSFLAGS; }
err|=osp2_send_readtempstat(2, &temp, &stat);
if( stat & OSP2_SETUP_FLAGS_OSIRE_ERRORS ) { printf("ERROR status\n\r"); err|=OSP2_ERROR_STATUSFLAGS; }
err|=osp2_send_readtempstat(3, &temp, &stat);
if( stat & OSP2_SETUP_FLAGS_SAID_ERRORS ) { printf("ERROR status\n\r"); err|=OSP2_ERROR_STATUSFLAGS; }
err|=osp2_send_readtempstat(4, &temp, &stat);
if( stat & OSP2_SETUP_FLAGS_OSIRE_ERRORS ) { printf("ERROR status\n\r"); err|=OSP2_ERROR_STATUSFLAGS; }
err|=osp2_send_readtempstat(5, &temp, &stat);
if( stat & OSP2_SETUP_FLAGS_OSIRE_ERRORS ) { printf("ERROR status\n\r"); err|=OSP2_ERROR_STATUSFLAGS; }
printf("\n\rFORCE ARG ERROR\n\r");
err|=osp2_send_setsetup(3, OSP2_SETUP_FLAGS_SAID_DFLT | OSP2_SETUP_FLAGS_CRCEN | OSP2_SETUP_FLAGS_CE );
err|=osp2_send_readsetup(3,&flags );
printf("## setpwm to SAID is a comm error, that will switch to SLEEP and thus LEDs off\n\r");
err|=osp2_send_setpwm(3,0x3333,0x2222,0x1111,0b000);
err|=osp2_send_readstat(3, &stat);
err|=osp2_send_readstat(3, &stat);
printf("## error cleared, switch SAID to active\n\r");
err|=osp2_send_goactive(3);
printf("\n\rOTP TEST\n\r");
osp2_exec_i2cenable_set(3,1);
osp2_exec_otpdump(3);
if( err==OSP2_ERROR_NONE )
{
printf("\n\rSAID tests: PASS\n\r");
}
else
{
exit_with_error:
printf("\n\rSAID tests: FAILED\n\r");
}
}
/* A simple animation on RAB5-OSIRE SAID */
void sidelookers_animate(void)
{
static _Bool init = false;
static int chn=0;
static int col=0;
uint8_t flags;
uint8_t rcur;
uint8_t gcur;
uint8_t bcur;
uint16_t last;
uint8_t stat,temp;
if(!init)
{
osp2_exec_reset();
osp2_send_initbidir(1,&last,&temp,&stat);
// cur 0 1 2 3 4
// chn0 3mA 6mA 12mA 24mA 48mA
// chn1 1.5mA 3mA 6mA 12mA 24mA
/* Set LED4 current (channel 0) */
flags = 0;
rcur = 2;
gcur = 2;
bcur = 2;
osp2_send_setcurchn(3, 0, flags, rcur, gcur, bcur);
/*Set LED3 current (channel 1)*/
flags = 0;
rcur = 3;
gcur = 3;
bcur = 3;
osp2_send_setcurchn(3, 1, flags, rcur, gcur, bcur);
/* Every SAID boots with over voltage, clear that flag */
osp2_send_clrerror(0);
osp2_send_readstat(3, &stat);
/*Activate the SAID*/
osp2_send_goactive(3);
init = true;
}
/*Animation*/
if(chn<2)
{
if(col<3)
{
uint16_t red = col==0 ? 0x3FFF : 0;
uint16_t green = col==1 ? 0x3FFF : 0;
uint16_t blue = col==2 ? 0x3FFF : 0;
osp2_send_setpwmchn(3,chn,red,green,blue);
col++;
}
else
{
col=0;
osp2_send_setpwmchn(3,chn,0,0,0);
chn++;
}
}
else
{
chn=0;
}
}
// This tests the difference between authenticated and test mode
void testmode(void)
{
osp2_error_t err = OSP2_ERROR_NONE;
uint16_t last;
uint8_t stat,temp;
uint8_t buf[8];
printf("\n\rRESET, INIT, STATUS\n\r");
err|=osp2_exec_reset();
err|=osp2_send_initbidir(1,&last,&temp,&stat);
//err|=osp2_send_initloop(1,&last,&temp,&stat);
err|= osp2_send_readstat(3, &stat); // Clear UV then check status (testmode bit)
err|= osp2_send_readstat(3, &stat); printf("testmode %s\n",stat & OSP2_STATUS_FLAGS_TESTMODE ? "yes":"no");
printf("\n\rEnable TESTMODE, STATUS\n\r");
err|= osp2_send_testpw(3,0x4247525F4143ULL); // Enable authenticated mode
err|= osp2_send_readstat(3, &stat); printf("testmode %s\n",stat & OSP2_STATUS_FLAGS_TESTMODE ? "yes":"no");
err|= osp2_send_settestdata(3,0b00001); // Enable test mode
err|= osp2_send_readstat(3, &stat); printf("testmode %s\n",stat & OSP2_STATUS_FLAGS_TESTMODE ? "yes":"no");
err|= osp2_exec_otpdump(3);
// err|= osp2_send_setcurchn(2, 0, 0, 4, 4, 4);
// err|= osp2_send_setcurchn(2, 1, 0, 4, 4, 4);
err|= osp2_send_setotp(2,0x0D,buf,7);
err|= osp2_exec_otpdump(2);
err|= osp2_send_readtempstat(2,&temp, &stat);
printf("\n\rDisable TESTMODE, STATUS\n\r");
err|= osp2_send_settestdata(3,0b11111); // Disable test mode
err|= osp2_send_readstat(3, &stat); printf("testmode %s\n",stat & OSP2_STATUS_FLAGS_TESTMODE ? "yes":"no");
err|= osp2_send_testpw(3,0); // Disable authenticated mode
err|= osp2_send_readstat(2, &stat); printf("testmode %s\n",stat & OSP2_STATUS_FLAGS_TESTMODE ? "yes":"no");
if( err==OSP2_ERROR_NONE ) {
printf("\n\rdone-with-success\n\r");
set_led_green(1);
} else {
printf("\n\rDONE-WITH-ERROR\n\r");
set_led_red(1);
}
}
/* Reads the data from RDK4 I2C slave */
void said_i2c_test(uint8_t addr)
{
#define on_error_gotoexit() do { if( err!=OSP2_ERROR_NONE ) goto exit; } while(0)
uint8_t rdk4_addr = 0x08; // I2C address of RDK4 Slave I2C Device
osp2_error_t err = OSP2_ERROR_NONE;
uint16_t last;
uint8_t temp;
uint8_t stat;
int enable;
uint32_t id;
uint8_t buf[4];
printf("\n\rI2C test in progress...\n\r");
/* Configure SAID for I2C (with several checks) */
osp2_exec_reset();
err = osp2_send_initbidir(1, &last, &temp, &stat);
on_error_gotoexit();
if (addr > last)
{
err = OSP2_ERROR_ADDR;
goto exit;
}
err = osp2_send_clrerror(0);
on_error_gotoexit();
err = osp2_send_setsetup(addr,OSP2_SETUP_FLAGS_SAID_DFLT | OSP2_SETUP_FLAGS_CRCEN);
on_error_gotoexit();
err = osp2_send_identify(addr, &id);
on_error_gotoexit();
if (id != 0x00000040)
{
err = OSP2_ERROR_ID;
goto exit;
}
osp2_exec_i2cenable_get(addr, &enable);
on_error_gotoexit();
if (!enable)
{
err = OSP2_ERROR_MISSI2CBRIDGE;
goto exit;
}
err = osp2_send_setcurchn(addr, /*chan*/2, /*flags*/0, 4, 4, 4);
on_error_gotoexit();
err = osp2_send_seti2ccfg(addr, OSP2_I2CCFG_FLAGS_DEFAULT,
OSP2_I2CCFG_SPEED_DEFAULT);
on_error_gotoexit();
err = osp2_exec_i2cread8(addr, rdk4_addr, 0x00, buf, 4);
if (err != OSP2_ERROR_I2CNACK && err != OSP2_ERROR_I2CTIMEOUT && err != OSP2_ERROR_NONE)
{
on_error_gotoexit();
}
printf("The I2C data from RDK4 slave: 0x%2X%2X%2X%2X\n\r",
(unsigned int) buf[0], (unsigned int) buf[1],
(unsigned int) buf[2], (unsigned int) buf[3]);
err = OSP2_ERROR_NONE;
exit: if (err == OSP2_ERROR_NONE)
{
printf("I2C test successful\n\r");
}
else
{
printf("I2C test failure\n\r");
}
}
void parallel (void)
{
uint16_t last;
uint8_t temp;
uint8_t stat;
// uint32_t id;
// uint8_t com;
osp2_exec_reset();
osp2_send_initbidir(1,&last,&temp,&stat);
osp2_send_initbidir(0x080,&last,&temp,&stat);
osp2_send_initbidir(0x100,&last,&temp,&stat);
// osp2_send_identify(1,&id);
// osp2_send_identify(0x080,&id);
//osp2_send_identify(0x100,&id);
// osp2_send_identify(0x101,&id);
// osp2_send_identify(2,&id);
osp2_send_clrerror(0);
osp2_send_goactive(0);
// osp2_send_readcomst(1, &com);
//osp2_send_readcomst(0x080, &com);
//osp2_send_readcomst(0x100, &com);
// osp2_send_setpwmchn(0x100,1,0x1FFF,0x1FFF,0x1FFF);
// osp2_send_setpwmchn(0x100,2,0x1FFF,0x1FFF,0x1FFF);
//osp2_send_setpwmchn(0x100,0,0x1FFF,0x1FFF,0x1FFF);
// osp2_send_setpwmchn(0x101,1,0x1FFF,0x1FFF,0x1FFF);
// osp2_send_setpwmchn(0x101,2,0x1FFF,0x1FFF,0x1FFF);
osp2_send_setpwmchn(0,0,0x1FFF,0x1FFF,0x1FFF);
//osp2_send_setpwmchn(0x100,0,0x1FFF,0x1FFF,0x1FFF);
osp2_send_readstat(1, &stat);
osp2_send_readstat(2, &stat);
osp2_send_readstat(0x080, &stat);
osp2_send_readstat(0x100, &stat);
osp2_send_readstat(0x101, &stat);
}
/* Sets THE PWM of both E5515 LEDs*/
void PWM(void)
{
uint16_t last;
uint8_t temp;
uint8_t stat;
uint8_t flags;
uint16_t pwm = 0x3FFF;
uint8_t com;
osp2_exec_reset();
osp2_send_initbidir(1,&last,&temp,&stat);
osp2_send_clrerror(0);
osp2_send_goactive(0);
osp2_send_setsetup(RAB5_SAID_ADDR, OSP2_SETUP_FLAGS_OSIRE_DFLT | OSP2_SETUP_FLAGS_CRCEN | OSP2_SETUP_FLAGS_LOS);
osp2_send_readsetup(RAB5_SAID_ADDR,&flags );
osp2_send_setpwm (RAB5_SAID_ADDR, 0x0080,0x0002,0x0020,0b000);
osp2_send_setpwmchn(RAB5_SAID_ADDR,0,pwm,pwm,pwm);
osp2_send_setpwmchn(RAB5_SAID_ADDR,1,pwm,pwm,pwm);
osp2_send_readstat(RAB5_SAID_ADDR, &stat);
osp2_send_readcomst(RAB5_SAID_ADDR, &com);
}