Skip to content

Commit 7465d98

Browse files
authored
Merge pull request #32 from MasterPlayer/sw_processing
Fix issue #31
2 parents 8dac176 + 2638d9d commit 7465d98

File tree

7 files changed

+1666
-0
lines changed

7 files changed

+1666
-0
lines changed

src_sw/activity_intr/app.c

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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, ACTIVITY, 0x00);
42+
43+
axi_adxl_set_act_ctl(&adxl_device, DC_COUPLE, MASK_X | MASK_Y);
44+
axi_adxl_set_thresh_act(&adxl_device, 0x10);
45+
46+
axi_adxl_int_enable(&adxl_device, ACTIVITY);
47+
48+
while(1){
49+
50+
}
51+
cleanup_platform();
52+
return 0;
53+
}
54+
55+
56+
57+
58+
int scugic_initialize(XScuGic *ptr, axi_adxl* adxl_ptr){
59+
60+
int status = 0;
61+
62+
XScuGic_Config *cfg;
63+
64+
cfg = XScuGic_LookupConfig(XPAR_SCUGIC_0_DEVICE_ID);
65+
if (!cfg){
66+
return XST_FAILURE;
67+
}
68+
69+
status = XScuGic_CfgInitialize(ptr, cfg, cfg->CpuBaseAddress);
70+
if (status != XST_SUCCESS){
71+
return XST_FAILURE;
72+
}
73+
74+
XScuGic_SetPriorityTriggerType(ptr, XPAR_FABRIC_AXI_ADXL345_VHD_0_ADXL_IRQ_INTR, 0x00, 0x3);
75+
76+
status = XScuGic_Connect(ptr, XPAR_FABRIC_AXI_ADXL345_VHD_0_ADXL_IRQ_INTR, (Xil_InterruptHandler)adxl_intr_handler, adxl_ptr);
77+
if (status != XST_SUCCESS){
78+
return XST_FAILURE;
79+
}
80+
81+
XScuGic_Enable(ptr, XPAR_FABRIC_AXI_ADXL345_VHD_0_ADXL_IRQ_INTR);
82+
83+
Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT, (Xil_ExceptionHandler)XScuGic_InterruptHandler, ptr);
84+
Xil_ExceptionEnable();
85+
86+
return status ;
87+
}
88+
89+
90+
91+
void adxl_intr_handler(void *callback){
92+
axi_adxl *ptr = (axi_adxl*)callback;
93+
adxl_cfg_ack(ptr->cfg);
94+
95+
// axi_adxl_debug(ptr);
96+
97+
g_coord g;
98+
99+
axi_adxl_get_gravity(ptr, &g);
100+
101+
printf("[x] : %3.3f \t[y] : %3.3f \t [z] %3.3f\r\n", g.x, g.y, g.z);
102+
return;
103+
}
104+

0 commit comments

Comments
 (0)