-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathhelloworld.c
105 lines (85 loc) · 2.44 KB
/
helloworld.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
#include <stdio.h>
#include "platform.h"
#include "xil_printf.h"
#include "xil_io.h"
#include "xuartps.h"
#include "xbram.h"
#include "xparameters.h"
#include <unistd.h>
#define BRAM(A) ((volatile u32*)px_config->MemBaseAddress)[A]
#define NUM_INPUTS 100 // number of pixel in input image
#define BYTES_PR_INPUT 4 // 32 bit float = 4 bytes
#define BASE_ADDR XPAR_AXI_BRAM_CTRL_0_S_AXI_BASEADDR // from xparameters.h
XBram x_bram;
XBram_Config *px_config;
XUartPs_Config *Config_0;
XUartPs Uart_PS_0;
uint8_t ucAXIInit();
int xuartps_init();
void printBits(unsigned int num);
float IntBitsToFloat(long long int bits);
int main()
{
init_platform();
print("\n\rInitializing..\n\r");
sleep(1);
ucAXIInit();
xuartps_init();
uint8_t BufferPtr_rx[NUM_INPUTS*BYTES_PR_INPUT] = {0x00};
int Status = 0;
uint32_t tempInt;
float tempFloat = 0.0;
print("\n\rReady for weights transfer\n\r");
while(1)
{
Status = 0;
while (Status < NUM_INPUTS*BYTES_PR_INPUT) {
BufferPtr_rx[Status] = XUartPs_RecvByte(XPAR_XUARTPS_0_BASEADDR); // read UART
Status ++;
}
for(int i = 0; i < NUM_INPUTS; i++){
// concatenate 8-bit input messages into 32-bit values
tempInt = ((BufferPtr_rx[i*4+3]<<24) | (BufferPtr_rx[i*4+2]<<16) | (BufferPtr_rx[i*4+1]<<8) | BufferPtr_rx[i*4]);
// prints current values in BRAM
tempFloat = *((float *)&tempInt); // int bits to float
char buffer2[10];
sprintf(buffer2, "%f", tempFloat);
xil_printf("BRAM[%d]:", i);
xil_printf(buffer2);
print("\n\r");
BRAM(i) = tempInt; // write to BRAM
}
}
print("Shutting down");
cleanup_platform();
return 0;
}
uint8_t ucAXIInit(){
/*************************
* BRAM initialization *
*************************/
px_config = XBram_LookupConfig(XPAR_BRAM_0_DEVICE_ID);
if (px_config == (XBram_Config *) NULL) {
return XST_FAILURE;
}
int x_status = XBram_CfgInitialize(&x_bram, px_config,
px_config->CtrlBaseAddress);
if (x_status != XST_SUCCESS) {
return XST_FAILURE;
}
return XST_SUCCESS;
}
int xuartps_init(){
/*************************
* UART 0 initialization *
*************************/
Config_0 = XUartPs_LookupConfig(XPAR_XUARTPS_0_DEVICE_ID);
if (NULL == Config_0) {
return XST_FAILURE;
}
int uart_x_status = XUartPs_CfgInitialize(&Uart_PS_0, Config_0, Config_0->BaseAddress);
if (uart_x_status != XST_SUCCESS) {
return XST_FAILURE;
}
return XST_SUCCESS;
}