-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
735 lines (573 loc) · 19.7 KB
/
main.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
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
#define NEURON
#define START_NEURON 1
#define RESET_NEURON 2
#define SET_SPIKE 3
#define SET_TEST_SPIKE 4
#define CLEAR_BUFFERED_SPIKE 5
//AXI GPIO driver
#include "xgpio.h"
//send data over UART
#include "xil_printf.h"
//information about AXI peripherals
#include "xparameters.h"
#include "xllfifo.h"
#include "xllfifo_hw.h"
#include "xstream_test.h"
#include "xstream_test_hw.h"
#include "xneuron.h"
#include "xneuron_hw.h"
#include "xstatus.h"
#include "xuartlite.h"
#include "xuartlite_l.h"
/*******************************Endianness************************************
* Always use little endian. For example, a hex value x1234, when it is splitted
* into 4 bytes in an array, msb stores in array[3], lsb stores in array[0].
* When transmit through uart, send array[0] first.
* Endianess reference: https://www.embeddedrelated.com/showarticle/174.php
******************************************************************************/
// reference: https://stackoverflow.com/questions/3784263/converting-an-int-into-a-4-byte-char-array-c
// split a integer into bytes e.g.
// msb in byte[3], lsb in byte[0]
// d'512 = b'1000000000
// split it into 4 bytes, it will be
// byte[3] = b00000000, byte[2] = b00000000, byte[1] = b00000010, byte[0] = b00000000
void uint2byte(u32 value, u8 *bytes)
{
bytes[3] = (value >> 24) & 0xFF;
bytes[2] = (value >> 16) & 0xFF;
bytes[1] = (value >> 8) & 0xFF;
bytes[0] = value & 0xFF;
}
//convert an array of u8 to u32
//assumes lsb in bytes[0], msb in bytes[3]
u32 byte2uint(u8 *bytes)
{
u32 value = bytes[0] | (u32)bytes[1] << 8 | (u32)bytes[2] << 16 | (u32)bytes[3] << 24;
return value;
}
unsigned int send_done()
{
for (int i = 0; i < 4; i++)
XUartLite_SendByte(XPAR_AXI_UARTLITE_0_BASEADDR, 255);
}
//field 0 for header, field 1-4 for data.
// allow to specify each byte
unsigned int send_discrete_packet(XUartLite *InstancePtr, u8 field0, u8 field1, u8 field2, u8 field3, u8 field4)
{
unsigned int SentCount = 0;
u8 SendBuffer[5] = {field0, field1, field2, field3, field4};
SentCount = XUartLite_Send(InstancePtr, SendBuffer, 5);
if (SentCount != 5)
return XST_FAILURE;
return SentCount;
}
//provide a u32 value, split it in 4 bytes and send it.
//first byte specify te type, reset 4 bytes are actual data
// uint2byte stores msb of data in data_byte[4], lsb in data_byte[1]
unsigned int send_packet(XUartLite *InstancePtr, u8 packet_type, u32 data)
{
u8 data_byte [5];
data_byte[0] = packet_type;
uint2byte(data, data_byte+1);
xil_printf("send:%d\n", data);
for(int i = 0; i != 5; i++)
xil_printf("data[%d]:%d" , i, data_byte[i]);
xil_printf("\n");
unsigned int SentCount = 0;
SentCount = XUartLite_Send(InstancePtr, data_byte+1, 4);
xil_printf("SentCount:%d\n" , SentCount);
if (SentCount != 5)
return XST_FAILURE;
return SentCount;
}
int initfifo(XLlFifo *InstancePtr, u16 DeviceId){
XLlFifo_Config *Config;
int Status = XST_SUCCESS;
// Initialize the driver
Config = XLlFfio_LookupConfig(DeviceId);
if (!Config) {
xil_printf("No config found for %d\n", DeviceId);
return XST_FAILURE;
}
Status = XLlFifo_CfgInitialize(InstancePtr, Config, Config->BaseAddress);
if (Status != XST_SUCCESS) {
xil_printf("Initialization failed\n");
return Status;
}
// Check reset value
Status = XLlFifo_Status(InstancePtr);
XLlFifo_IntClear(InstancePtr,0xffffffff);
Status = XLlFifo_Status(InstancePtr);
if(Status != 0x0) {
xil_printf("\n ERROR : Reset value of ISR0 : 0x%x\t"
"Expected : 0x0 \n",
XLlFifo_Status(InstancePtr));
return XST_FAILURE;
}
return Status;
}
int read_fifo(XLlFifo *InstancePtr)
{
int i;
static u32 ReceiveLength;
ReceiveLength = (XLlFifo_iRxGetLen(InstancePtr))/4;
for ( i=0; i < ReceiveLength; i++)
{
u32 RxWord = XLlFifo_RxGetWord(InstancePtr);
if(XLlFifo_iRxOccupancy(InstancePtr))
{
RxWord = XLlFifo_RxGetWord(InstancePtr);
}
xil_printf("%d,", RxWord);
}
}
int recv (XLlFifo *InstancePtr){
int i;
static u32 ReceiveLength;
xil_printf(" Receiving data ....\n");
// Read Recv length
ReceiveLength = (XLlFifo_iRxGetLen(InstancePtr))/4;
xil_printf("Recv length %d \n", ReceiveLength);
// Start receiving
for ( i=0; i < ReceiveLength; i++){
u32 RxWord = XLlFifo_RxGetWord(InstancePtr);
if(XLlFifo_iRxOccupancy(InstancePtr)){
RxWord = XLlFifo_RxGetWord(InstancePtr);
}
xil_printf("receive %d,", RxWord);
// int a = RxWord >> 8;
//
// u32 b = RxWord >> 8;
//
// xil_printf("shift : %d, %u, %d, ", a, b, b);
}
// check the cr bit of isr to see if can generate correct signal
//
// while(XLlFifo_IsRxDone(InstancePtr) != TRUE)
// {
// int len = (XLlFifo_iRxGetLen(InstancePtr))/4;
// xil_printf("length %d\n", len);
//
// u32 RxWord = XLlFifo_RxGetWord(InstancePtr);
// if(XLlFifo_iRxOccupancy(InstancePtr)){
// RxWord = XLlFifo_RxGetWord(InstancePtr);
// }
// xil_printf("receive %d,", RxWord);
// }
// comment out, don't check rc bit(receive complete)
// Although all packets can be received successfully, rc bit is not correct,
// reason is not clear, so ignore it
// Status = XLlFifo_IsRxDone(InstancePtr);
// if(Status != TRUE){
// xil_printf("Failing in receive complete ... \n");
// return -1;
// }
return ReceiveLength;
}
#ifdef NEURON
int main()
{
int status;
//xil_printf("################## start of program ######################\n");
// XGpio gpio;
// u32 btn, led;
//test uart
//xil_printf("-----------------uart test--------------------\n");
/********************************init uart*************************************/
int init_uart_result = 1;
int uart_selftest_result = 1;
XUartLite UartLite;
status = XUartLite_Initialize(&UartLite, XPAR_AXI_UARTLITE_0_DEVICE_ID);
if (status != XST_SUCCESS)
init_uart_result = 0;
xil_printf("uart init:%d\n", init_uart_result);
status = XUartLite_SelfTest(&UartLite);
if (status != XST_SUCCESS)
uart_selftest_result = 0;
xil_printf("uart selftest:%d\n", uart_selftest_result);
/************************initialize stream fifo of neuron**********************/
int init_neuron_test_fifo_result = 1;
XLlFifo neuron_test_fifo;
//initialize stream fifo
status = initfifo(&neuron_test_fifo, XPAR_NEURON_TEST_FIFO_DEVICE_ID);
if (status != XST_SUCCESS)
init_neuron_test_fifo_result = 0;
xil_printf("neuron test fifo init:%d\n", init_neuron_test_fifo_result);
//init psp fifo
int init_psp_fifo = 1;
XLlFifo psp_fifo;
//initialize stream fifo
status = initfifo(&psp_fifo, XPAR_PSP_FIFO_DEVICE_ID);
if (status != XST_SUCCESS)
init_psp_fifo = 0;
xil_printf("psp fifo init:%d\n", init_psp_fifo);
//init voltage fifo
int init_voltage_fifo = 1;
XLlFifo voltage_fifo;
//initialize stream fifo
status = initfifo(&voltage_fifo, XPAR_VOLTAGE_FIFO_DEVICE_ID);
if (status != XST_SUCCESS)
init_voltage_fifo = 0;
xil_printf("voltage fifo init:%d\n", init_voltage_fifo);
//initialize neuron
int init_neuron_result = 1;
XNeuron neuron_inst;
int neuron_init_status = XNeuron_Initialize(&neuron_inst, XPAR_NEURON_0_DEVICE_ID);
if (neuron_init_status != XST_SUCCESS)
init_neuron_result = 0;
xil_printf("neuron init: %d\n", init_neuron_result);
u64 spike_63_0 = 0;
u64 spike_127_64 = 0;
u64 one = 1;
send_done();
//main loop
u8 recv_data[4] = {0};
while(1)
{
int action = 0;
while(1)
{
//XUartLite_RecvByte is a blocking function, it blocks until receive a word from uart
for (int i = 0; i < 4; i++)
recv_data[i] = XUartLite_RecvByte(XPAR_AXI_UARTLITE_0_BASEADDR);
//xil_printf("receive:%d,%d,%d,%d\n",recv_data[0],recv_data[1],recv_data[2],recv_data[3]);
if (recv_data[3] == START_NEURON)
{
action = START_NEURON;
break;
}
else if(recv_data[3] == RESET_NEURON)
{
action = RESET_NEURON;
break;
}
else if(recv_data[3] == SET_SPIKE)
{
action = SET_SPIKE;
break;
}
else if (recv_data[3] == SET_TEST_SPIKE)
{
action = SET_TEST_SPIKE;
break;
}
else if(recv_data[3] == CLEAR_BUFFERED_SPIKE)
{
action = CLEAR_BUFFERED_SPIKE;
break;
}
else
{
xil_printf("loopback\n");
u8 sendbuf[4];
int sendcnt = 0;
for (int i = 0; i < 4; i++)
sendbuf[i] = i;
for (int i = 0; i < 4; i++)
XUartLite_SendByte(XPAR_AXI_UARTLITE_0_BASEADDR, 15);
}
}
if (action == START_NEURON)
{
int neuron_done = XNeuron_IsDone(&neuron_inst);
int neuron_idle = XNeuron_IsIdle(&neuron_inst);
int neuron_ready = XNeuron_IsReady(&neuron_inst);
// xil_printf("done: %d,idle:%d,ready:%d\n", neuron_done, neuron_idle, neuron_ready);
//xil_printf("check input spike before set\n %d \n",spike_63_0);
XNeuron_Set_input_spike_63_0_V(&neuron_inst, spike_63_0);
XNeuron_Set_input_spike_127_64_V(&neuron_inst, spike_127_64);
// spike_63_0 = XNeuron_Get_input_spike_63_0_V(&neuron_inst);
//xil_printf("spike buffer 63-0: %u, %u \n",(u32)(spike_63_0>>32), spike_63_0);
// spike_127_64 = XNeuron_Get_input_spike_127_64_V(&neuron_inst);
// xil_printf("spike buffer:%u,%u,%u,%u\n",(u32)(spike_127_64>>32), spike_127_64, (u32)(spike_63_0>>32), spike_63_0);
//start neuron
// xil_printf("start\n");
XNeuron_Start(&neuron_inst);
//check neuron status
MB_Sleep(1);
neuron_done = XNeuron_IsDone(&neuron_inst);
neuron_idle = XNeuron_IsIdle(&neuron_inst);
neuron_ready = XNeuron_IsReady(&neuron_inst);
// xil_printf("done:%d,idle:%d,ready:%d\n", neuron_done, neuron_idle, neuron_ready);
// xil_printf("psp:");
//recv(&psp_fifo);
read_fifo(&psp_fifo);
xil_printf("\n");
// xil_printf("voltage:");
//recv(&voltage_fifo);
read_fifo(&voltage_fifo);
//clear input after run one step
XNeuron_Set_input_spike_63_0_V(&neuron_inst, 0);
XNeuron_Set_input_spike_127_64_V(&neuron_inst, 0);
spike_63_0 = 0;
spike_127_64 = 0;
send_done();
}
else if (action == RESET_NEURON)
{
// xil_printf("reset\n");
XNeuron_Set_reset_neuron(&neuron_inst, 1);
XNeuron_Start(&neuron_inst);
XNeuron_Set_reset_neuron(&neuron_inst, 0);
}
else if(action == SET_TEST_SPIKE)
{
XNeuron_Set_input_spike_63_0_V(&neuron_inst, 65535);
// xil_printf("set test spike\n");
spike_63_0 = XNeuron_Get_input_spike_63_0_V(&neuron_inst);
// xil_printf("check input spike:%d\n",spike_63_0);
}
else if(action == SET_SPIKE)
{
//reference: https://stackoverflow.com/questions/47981/how-do-you-set-clear-and-toggle-a-single-bit
if(recv_data[2] < 64)
spike_63_0 |= one << recv_data[2];
else
spike_127_64 |= one << (recv_data[2] - 64);
// xil_printf("input spike 63-0:%u,%u\n",(u32)(spike_63_0>>32), spike_63_0);
// xil_printf("input spike 127-64:%u,%u\n",(u32)(spike_127_64>>32), spike_127_64);
}
else if (action == CLEAR_BUFFERED_SPIKE)
{
spike_63_0 = 0;
spike_127_64 = 0;
}
//memset(recv_data, 0, sizeof(recv_data));
}
}
#else
int main()
{
int status;
xil_printf("################## start of program ######################\n");
XGpio gpio;
u32 btn, led;
//test uart
xil_printf("-----------------uart test--------------------\n");
//init uart
XUartLite UartLite;
status = XUartLite_Initialize(&UartLite, XPAR_AXI_UARTLITE_0_DEVICE_ID);
if (status != XST_SUCCESS)
xil_printf("failed to init uart \n");
status = XUartLite_SelfTest(&UartLite);
if (status != XST_SUCCESS)
xil_printf("uart self test failed \n");
u32 testvalue = 18760;
//test send_packet function
unsigned int sentcount = send_packet(&UartLite, 1, testvalue);
xil_printf("\n");
// initialize stream fifo of stream_test
// stream fifo instance
XLlFifo FifoInstance;
//initialize stream fifo
xil_printf("----------initialize stream_fifo of stream_test module---------\n");
status = initfifo(&FifoInstance, XPAR_STREAM_TEST_FIFO_DEVICE_ID);
if (status == XST_SUCCESS)
xil_printf("initialize stream_test fifo: successful\n");
xil_printf("\n");
// verify stream_test functionality
xil_printf("-------------------verify stream_test----------------------\n");
XStream_test stream_test;
int stream_test_init_status = XStream_test_Initialize(&stream_test,XPAR_STREAM_TEST_0_DEVICE_ID);
XStream_test_Config* stream_test_cfg = XStream_test_LookupConfig(XPAR_STREAM_TEST_0_DEVICE_ID);
int stream_test_cfginit_status = XStream_test_CfgInitialize(&stream_test, stream_test_cfg);
if (stream_test_cfginit_status == XST_SUCCESS)
xil_printf("initialize stream_test cfg: successful\n");
else
xil_printf("initialize stream_test cfg: failed\n");
if (stream_test_init_status == XST_SUCCESS)
xil_printf("initialize stream_test: successful\n");
else
xil_printf("initialize stream_test: failed\n");
//disable restart
xil_printf("disable stream_test autostart\n");
XStream_test_DisableAutoRestart(&stream_test);
//set input value of stream_test
int stream_test_a = 5;
xil_printf("set input a: %d\n", stream_test_a);
XStream_test_Set_a_V(&stream_test, stream_test_a);
int stream_test_b = 3;
xil_printf("set input b: %d\n", stream_test_b);
XStream_test_Set_b_V(&stream_test, stream_test_b);
//check if input is set correctly
xil_printf("check if a and b are set correctly \n");
u32 val_a = XStream_test_Get_a_V(&stream_test);
u32 val_b = XStream_test_Get_b_V(&stream_test);
xil_printf("value a: %d, value b: %d \n", val_a, val_b);
//start stream_test
xil_printf("start stream_test\n", val_a, val_b);
XStream_test_Start(&stream_test);
//get result from stream_test
u32 ret = XStream_test_Get_return(&stream_test);
xil_printf("get return value of stream_test\n");
xil_printf("return %d \n", ret);
//check the status of stream_test
xil_printf("check the status of stream_test \n");
u32 stream_test_done = XStream_test_IsDone(&stream_test);
u32 stream_test_idle = XStream_test_IsIdle(&stream_test);
u32 stream_test_ready = XStream_test_IsReady(&stream_test);
xil_printf("stream test done: %d, idle: %d, ready: %d\n", stream_test_done, stream_test_idle, stream_test_ready);
//read stream fifo of stream_test
xil_printf("read stream_test fifo\n");
recv(&FifoInstance);
xil_printf("\n\n");
xil_printf("-----------------------verify neuron functionality---------------------\n");
//initialize stream fifo of neuron
XLlFifo neuron_test_fifo;
//initialize stream fifo
status = initfifo(&neuron_test_fifo, XPAR_NEURON_TEST_FIFO_DEVICE_ID);
if (status == XST_SUCCESS)
xil_printf("initialize neuron_test fifo: successful\n");
//init psp fifo
XLlFifo psp_fifo;
//initialize stream fifo
status = initfifo(&psp_fifo, XPAR_PSP_FIFO_DEVICE_ID);
if (status == XST_SUCCESS)
xil_printf("initialize psp fifo: successful\n");
//init voltage fifo
XLlFifo voltage_fifo;
//initialize stream fifo
status = initfifo(&voltage_fifo, XPAR_VOLTAGE_FIFO_DEVICE_ID);
if (status == XST_SUCCESS)
xil_printf("initialize psp fifo: successful\n");
// test neuron module
xil_printf("initialize neuron\n");
//initialize neuron
XNeuron neuron_inst;
int neuron_init_status = XNeuron_Initialize(&neuron_inst, XPAR_NEURON_0_DEVICE_ID);
if (neuron_init_status != XST_SUCCESS)
xil_printf("initialize neuron: failed \n");
else
xil_printf("initialize neuron: successful \n");
//initialize neuron cfg
// XNeuron_Config* neuron_cfg_pointer = XNeuron_LookupConfig(XPAR_NEURON_0_DEVICE_ID);
// int neuron_cfg_init_status = XNeuron_CfgInitialize(&neuron_inst, neuron_cfg_pointer);
// if (neuron_cfg_init_status != XST_SUCCESS)
// xil_printf("initialize neuron cfg failed \n");
// else
// xil_printf("initialize neuron cfg successfully \n");
XNeuron_DisableAutoRestart(&neuron_inst);
int neuron_done = XNeuron_IsDone(&neuron_inst);
int neuron_idle = XNeuron_IsIdle(&neuron_inst);
int neuron_ready = XNeuron_IsReady(&neuron_inst);
xil_printf("check neuron status\n");
xil_printf("done: %d, idle: %d, ready: %d \n", neuron_done, neuron_idle, neuron_ready);
//test neuron
//set input
XNeuron_Set_test_var(&neuron_inst, 1);
//check if input set successfully
int test_var = XNeuron_Get_test_var(&neuron_inst);
xil_printf("test_var: %d \n", test_var);
XNeuron_Set_input_spike_63_0_V(&neuron_inst, 65535);
u64 spike_63_0 = XNeuron_Get_input_spike_63_0_V(&neuron_inst);
xil_printf("check input spike\n %d \n",spike_63_0);
//start neuron
xil_printf("start neuron \n");
XNeuron_Start(&neuron_inst);
//check neuron status
sleep(1);
neuron_done = XNeuron_IsDone(&neuron_inst);
neuron_idle = XNeuron_IsIdle(&neuron_inst);
neuron_ready = XNeuron_IsReady(&neuron_inst);
XNeuron_Set_input_spike_63_0_V(&neuron_inst, 0);
xil_printf("done: %d, idle: %d, ready: %d \n", neuron_done, neuron_idle, neuron_ready);
//sleep
//xil_printf("read neuron test fifo \n");
//read neuron test fifo
//recv(&neuron_test_fifo);
xil_printf("\n\n");
xil_printf("read psp\n");
recv(&psp_fifo);
xil_printf("\n");
xil_printf("read voltage\n");
recv(&voltage_fifo);
for (int i = 0; i != 5; i++)
{
xil_printf("round %d\n", i);
neuron_done = XNeuron_IsDone(&neuron_inst);
neuron_idle = XNeuron_IsIdle(&neuron_inst);
neuron_ready = XNeuron_IsReady(&neuron_inst);
xil_printf("done: %d, idle: %d, ready: %d \n", neuron_done, neuron_idle, neuron_ready);
XNeuron_Set_test_var(&neuron_inst, 5);
test_var = XNeuron_Get_test_var(&neuron_inst);
xil_printf("test_var: %d \n", test_var);
xil_printf("start neuron \n");
XNeuron_Start(&neuron_inst);
sleep(1);
xil_printf("\n");
//xil_printf("read test\n");
//recv(&neuron_test_fifo);
xil_printf("\n");
xil_printf("read psp\n");
recv(&psp_fifo);
xil_printf("\n");
xil_printf("read voltage\n");
recv(&voltage_fifo);
xil_printf("\n");
neuron_done = XNeuron_IsDone(&neuron_inst);
neuron_idle = XNeuron_IsIdle(&neuron_inst);
neuron_ready = XNeuron_IsReady(&neuron_inst);
xil_printf("done: %d, idle: %d, ready: %d \n", neuron_done, neuron_idle, neuron_ready);
}
xil_printf("\n-----------------------test reset psp---------------------\n");
XNeuron_Set_reset_neuron(&neuron_inst, 1);
XNeuron_Start(&neuron_inst);
XNeuron_Set_reset_neuron(&neuron_inst, 0);
XNeuron_Set_test_var(&neuron_inst, 1);
//check if input set successfully
test_var = XNeuron_Get_test_var(&neuron_inst);
xil_printf("test_var: %d \n", test_var);
XNeuron_Set_input_spike_63_0_V(&neuron_inst, 65535);
spike_63_0 = XNeuron_Get_input_spike_63_0_V(&neuron_inst);
xil_printf("check input spike\n %d \n",spike_63_0);
//start neuron
xil_printf("start neuron \n");
XNeuron_Start(&neuron_inst);
//check neuron status
sleep(1);
neuron_done = XNeuron_IsDone(&neuron_inst);
neuron_idle = XNeuron_IsIdle(&neuron_inst);
neuron_ready = XNeuron_IsReady(&neuron_inst);
XNeuron_Set_input_spike_63_0_V(&neuron_inst, 0);
xil_printf("done: %d, idle: %d, ready: %d \n", neuron_done, neuron_idle, neuron_ready);
//sleep
//xil_printf("read neuron test fifo \n");
//read neuron test fifo
//recv(&neuron_test_fifo);
xil_printf("\n\n");
xil_printf("read psp\n");
recv(&psp_fifo);
xil_printf("\n");
xil_printf("read voltage\n");
recv(&voltage_fifo);
for (int i = 0; i != 5; i++)
{
xil_printf("round %d\n", i);
neuron_done = XNeuron_IsDone(&neuron_inst);
neuron_idle = XNeuron_IsIdle(&neuron_inst);
neuron_ready = XNeuron_IsReady(&neuron_inst);
xil_printf("done: %d, idle: %d, ready: %d \n", neuron_done, neuron_idle, neuron_ready);
XNeuron_Set_test_var(&neuron_inst, 5);
test_var = XNeuron_Get_test_var(&neuron_inst);
xil_printf("test_var: %d \n", test_var);
xil_printf("start neuron \n");
XNeuron_Start(&neuron_inst);
sleep(2);
xil_printf("\n");
//xil_printf("read test\n");
//recv(&neuron_test_fifo);
xil_printf("\n");
xil_printf("read psp\n");
recv(&psp_fifo);
xil_printf("\n");
xil_printf("read voltage\n");
recv(&voltage_fifo);
xil_printf("\n");
neuron_done = XNeuron_IsDone(&neuron_inst);
neuron_idle = XNeuron_IsIdle(&neuron_inst);
neuron_ready = XNeuron_IsReady(&neuron_inst);
xil_printf("done: %d, idle: %d, ready: %d \n", neuron_done, neuron_idle, neuron_ready);
}
xil_printf("end program \n");
}
#endif