Skip to content

Commit e7223c9

Browse files
authored
Merge pull request #39 from MasterPlayer/free_fall_support
Fix issue #38
2 parents f5dc8e7 + 474b64c commit e7223c9

File tree

8 files changed

+1793
-2
lines changed

8 files changed

+1793
-2
lines changed

src_hw/axi_adxl345.sv

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ module axi_adxl345 #(
216216
logic out_awfull ;
217217

218218
logic [ 7:0] version_major = 8'h01 ; // read only,
219-
logic [ 7:0] version_minor = 8'h0A ; // read only,
219+
logic [ 7:0] version_minor = 8'h0B ; // read only,
220220
logic [ 6:0] i2c_address = DEFAULT_DEVICE_ADDRESS ; // reg[0][14:8]
221221
logic link_on = 1'b0 ;
222222
logic on_work = 1'b0 ; // reg[0][4]
@@ -247,6 +247,7 @@ module axi_adxl345 #(
247247
logic has_dt_intr;
248248
logic has_act_intr;
249249
logic has_inact_intr;
250+
logic has_ff_intr;
250251

251252
always_comb begin : has_dataready_intr_proc
252253
if ((int_source_reg[7] & int_enable_reg[7]))
@@ -284,6 +285,14 @@ module axi_adxl345 #(
284285
has_inact_intr = 1'b0;
285286
end
286287

288+
always_comb begin : has_ff_intr_proc
289+
if (int_source_reg[2] & int_enable_reg[2])
290+
has_ff_intr = 1'b1;
291+
else
292+
has_ff_intr = 1'b0;
293+
end
294+
295+
287296
always_comb begin
288297

289298
int_enable_reg = register[11][2];
@@ -669,7 +678,7 @@ module axi_adxl345 #(
669678
if (has_st_intr | has_dt_intr | has_act_intr | has_inact_intr)
670679
current_state <= TX_WRITE_ACT_TAP_STATUS_PTR_ST;
671680
else
672-
if (has_dataready_intr)
681+
if (has_dataready_intr | has_ff_intr)
673682
current_state <= TX_WRITE_INTR_DATA_PTR_ST;
674683
else
675684
current_state <= IDLE_ST;

src_sw/free_fall_intr/app.c

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

0 commit comments

Comments
 (0)