Skip to content

Commit d7cca0b

Browse files
authored
Watermark Interrupt processing in hw support
Watermark Interrupt processing in hw support
2 parents e7223c9 + 7f665b6 commit d7cca0b

File tree

9 files changed

+2268
-71
lines changed

9 files changed

+2268
-71
lines changed

src_hw/axi_adxl345.sv

Lines changed: 333 additions & 48 deletions
Large diffs are not rendered by default.

src_sw/watermark_intr/app.c

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
#include <stdio.h>
2+
#include "platform.h"
3+
#include "xil_printf.h"
4+
#include "axi_adxl.h"
5+
#include <time.h>
6+
#include <xscugic.h>
7+
8+
#include <xparameters.h>
9+
10+
11+
int scugic_initialize(XScuGic *ptr, axi_adxl* adxl_ptr);
12+
void adxl_intr_handler(void *callback);
13+
14+
int main(){
15+
16+
init_platform();
17+
18+
axi_adxl adxl_device;
19+
XScuGic gic;
20+
21+
axi_adxl_init(&adxl_device, 0x40030000, 0x40040000);
22+
23+
scugic_initialize(&gic, &adxl_device);
24+
25+
int status = axi_adxl_enable(&adxl_device, 0x53, 10);
26+
if (status != ADXL_OK){
27+
printf("[MAIN] : enable device return code [%d]\r\n", status);
28+
}
29+
30+
status = axi_adxl_calibration(&adxl_device);
31+
if (status != ADXL_OK){
32+
printf("[MAIN] : calibration device return code [%d]\r\n", status);
33+
}
34+
35+
status = axi_adxl_disable_requesting(&adxl_device);
36+
if (status != ADXL_OK){
37+
xil_printf("[MAIN] : disable requests return code : [%d]\r\n", status);
38+
return 0;
39+
}
40+
41+
axi_adxl_set_int_map(&adxl_device, WATERMARK, 0x00);
42+
axi_adxl_set_fifo_samples(&adxl_device, 0x1F);
43+
axi_adxl_set_fifo_mode(&adxl_device, FIFO);
44+
axi_adxl_int_enable(&adxl_device, WATERMARK);
45+
46+
47+
volatile int change_mode = 0;
48+
volatile int mode = 0;
49+
while(1){
50+
if (change_mode){
51+
52+
axi_adxl_change_bw(&adxl_device, mode);
53+
54+
change_mode = 0;
55+
}
56+
57+
}
58+
59+
cleanup_platform();
60+
return 0;
61+
}
62+
63+
64+
65+
66+
int scugic_initialize(XScuGic *ptr, axi_adxl* adxl_ptr){
67+
68+
int status = 0;
69+
70+
XScuGic_Config *cfg;
71+
72+
cfg = XScuGic_LookupConfig(XPAR_SCUGIC_0_DEVICE_ID);
73+
if (!cfg){
74+
return XST_FAILURE;
75+
}
76+
77+
status = XScuGic_CfgInitialize(ptr, cfg, cfg->CpuBaseAddress);
78+
if (status != XST_SUCCESS){
79+
return XST_FAILURE;
80+
}
81+
82+
XScuGic_SetPriorityTriggerType(ptr, XPAR_FABRIC_AXI_ADXL345_VHD_0_ADXL_IRQ_INTR, 0x00, 0x3);
83+
84+
status = XScuGic_Connect(ptr, XPAR_FABRIC_AXI_ADXL345_VHD_0_ADXL_IRQ_INTR, (Xil_InterruptHandler)adxl_intr_handler, adxl_ptr);
85+
if (status != XST_SUCCESS){
86+
return XST_FAILURE;
87+
}
88+
89+
XScuGic_Enable(ptr, XPAR_FABRIC_AXI_ADXL345_VHD_0_ADXL_IRQ_INTR);
90+
91+
Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT, (Xil_ExceptionHandler)XScuGic_InterruptHandler, ptr);
92+
Xil_ExceptionEnable();
93+
94+
return status ;
95+
}
96+
97+
int iter = 0;
98+
99+
void adxl_intr_handler(void *callback){
100+
axi_adxl *ptr = (axi_adxl*)callback;
101+
102+
uint8_t entries = (adxl_dev_get_fifo_status(ptr->dev) & FIFO_STATUS_ENTRIES_MASK);
103+
104+
printf("[%2d]\r\n", entries);
105+
106+
for (int i = 0; i < entries; i++){
107+
printf("\t[x] : %4d \t[y] : %4d \t [z] : %4d\r\n", ptr->cfg->axis[i].x, ptr->cfg->axis[i].y, ptr->cfg->axis[i].z);
108+
}
109+
110+
adxl_cfg_ack(ptr->cfg);
111+
112+
113+
// g_coord g;
114+
//
115+
// axi_adxl_get_gravity(ptr, &g);
116+
//
117+
// printf("[x] : %3.3f \t[y] : %3.3f \t [z] %3.3f\r\n", g.x, g.y, g.z);
118+
return;
119+
}
120+

0 commit comments

Comments
 (0)