Skip to content

Commit 845673e

Browse files
authored
Overrun support
#43
2 parents d7cca0b + 7377402 commit 845673e

File tree

8 files changed

+1885
-7
lines changed

8 files changed

+1885
-7
lines changed

src_hw/axi_adxl345.sv

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ module axi_adxl345 #(
225225
logic out_awfull ;
226226

227227
logic [ 7:0] version_major = 8'h01 ; // read only,
228-
logic [ 7:0] version_minor = 8'h0C ; // read only,
228+
logic [ 7:0] version_minor = 8'h0D ; // read only,
229229
logic [ 6:0] i2c_address = DEFAULT_DEVICE_ADDRESS ; // reg[0][14:8]
230230
logic link_on = 1'b0 ;
231231
logic on_work = 1'b0 ; // reg[0][4]
@@ -258,6 +258,7 @@ module axi_adxl345 #(
258258
logic has_inact_intr;
259259
logic has_ff_intr;
260260
logic has_wm_intr;
261+
logic has_ovrrn_intr;
261262

262263
logic [5:0] entries = '{default:0};
263264

@@ -311,6 +312,13 @@ module axi_adxl345 #(
311312
has_wm_intr = 1'b0;
312313
end
313314

315+
always_comb begin : has_ovrrn_intr_proc
316+
if (int_source_reg[0] & int_enable_reg[0])
317+
has_ovrrn_intr = 1'b1;
318+
else
319+
has_ovrrn_intr = 1'b0;
320+
end
321+
314322

315323
always_comb begin
316324

@@ -718,7 +726,7 @@ module axi_adxl345 #(
718726
if (has_dataready_intr | has_ff_intr)
719727
current_state <= TX_WRITE_INTR_DATA_PTR_ST;
720728
else
721-
if (has_wm_intr)
729+
if (has_wm_intr | has_ovrrn_intr)
722730
current_state <= TX_WRITE_WM_FIFO_STS_PTR_ST;
723731
else
724732
current_state <= IDLE_ST;
@@ -788,8 +796,6 @@ module axi_adxl345 #(
788796
end
789797
end
790798

791-
792-
793799
CHECK_INTR_DEASSERT:
794800
if (ADXL_INTERRUPT)
795801
current_state <= INT_PROCESSING_ST;
@@ -1424,7 +1430,7 @@ module axi_adxl345 #(
14241430
8'h05 : reg_data_out_cfg <= write_transactions;
14251431
8'h06 : reg_data_out_cfg <= read_transactions;
14261432
8'h07 : reg_data_out_cfg <= CLK_PERIOD;
1427-
8'h08 : reg_data_out_cfg <= {24'h0, sample_address};
1433+
8'h08 : reg_data_out_cfg <= {23'h0, has_ovrrn_intr, sample_address};
14281434
8'h09 : reg_data_out_cfg <= '{default:0}; // reserved
14291435
8'h0a : reg_data_out_cfg <= '{default:0}; // reserved
14301436
8'h0b : reg_data_out_cfg <= '{default:0}; // reserved
@@ -1789,7 +1795,7 @@ module axi_adxl345 #(
17891795
end else begin
17901796
case (current_state)
17911797
RX_WM_DATA_ST:
1792-
if (S_AXIS_TVALID & has_wm_intr) begin
1798+
if (S_AXIS_TVALID & (has_wm_intr | has_ovrrn_intr)) begin
17931799
sample_address <= sample_address + 1;
17941800
end
17951801

@@ -1800,7 +1806,7 @@ module axi_adxl345 #(
18001806
end
18011807

18021808
always_ff @(posedge CLK) begin
1803-
if (S_AXIS_TVALID & has_wm_intr) begin
1809+
if (S_AXIS_TVALID & (has_wm_intr | has_ovrrn_intr)) begin
18041810
register_samples[sample_address][7:0] <= S_AXIS_TDATA;
18051811
end
18061812
end

src_sw/overrun_intr/app.c

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

0 commit comments

Comments
 (0)