Skip to content

Commit

Permalink
[adc_ctrl] Add interrupt source for detecting LP -> NP transition
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Schaffner <[email protected]>
  • Loading branch information
msfschaffner committed Mar 5, 2024
1 parent b365614 commit d8029c4
Show file tree
Hide file tree
Showing 11 changed files with 395 additions and 113 deletions.
61 changes: 56 additions & 5 deletions hw/ip/adc_ctrl/data/adc_ctrl.hjson
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,28 @@
fields: [
{ bits: "NumAdcFilter-1:0",
name: "EN",
desc: "0: filter match wil not generate wakeupe; 1: filter match will generate wakeup",
desc: '''
Filter wakeup source.

0: filter match wil not generate wakeup;
1: filter match will generate wakeup
'''
}
{
bits: "NumAdcFilter:NumAdcFilter",
name: "TRANSITION_EN",
desc: '''
Wakeup due to FSM transition from low power sampling
mode to normal sampling mode.

Note that this wakeup source is primarily intended for debug purposes.
If enabled all the time, this can lead to many wakeups due to false
positives that are ruled out automatically by adc_ctrl after
transitioning from LP -> NP.

0: filter match wil not generate wakeup;
1: filter match will generate wakeup
'''
}
]
}
Expand All @@ -325,10 +346,36 @@
hwaccess: "hro",
resval: "0",
fields: [
{ bits: "8:0",
{ bits: "NumAdcFilter-1:0",
name: "EN",
desc: "0: interrupt source is not enabled; 1: interrupt source is enabled",
desc: '''
Filter interrupt source.

0: interrupt source is not enabled; 1: interrupt source is enabled
'''
}
{
bits: "NumAdcFilter:NumAdcFilter",
name: "TRANSITION_EN",
desc: '''
Interrupt due to FSM transition from low power sampling
mode to normal sampling mode. This is mainly intended for debug.

Note that this interrupt is primarily intended for debug purposes.

0: interrupt source is not enabled; 1: interrupt source is enabled
'''
}
{
bits: "NumAdcFilter+1:NumAdcFilter+1",
name: "ONESHOT_EN",
desc: '''
Interrupt due to oneshot sampling.

0: interrupt source is not enabled; 1: interrupt source is enabled
'''
}

]
}

Expand All @@ -342,11 +389,15 @@
"excl:CsrNonInitTests:CsrExclCheck"],
fields: [
{ bits: "NumAdcFilter-1:0",
name: "filter_match",
name: "FILTER_MATCH",
desc: "0: filter condition is not met; 1: filter condition is met",
}
{ bits: "NumAdcFilter:NumAdcFilter",
name: "oneshot",
name: "TRANSITION",
desc: "0: transition did not occur; 1: transition occurred",
}
{ bits: "NumAdcFilter+1:NumAdcFilter+1",
name: "ONESHOT",
desc: "0: oneshot sample is not done ; 1: oneshot sample is done",
}
]
Expand Down
74 changes: 57 additions & 17 deletions hw/ip/adc_ctrl/doc/registers.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,18 +303,37 @@ ADC value sampled on channel
Enable filter matches as wakeups
- Offset: `0x6c`
- Reset default: `0x0`
- Reset mask: `0xff`
- Reset mask: `0x1ff`

### Fields

```wavejson
{"reg": [{"name": "EN", "bits": 8, "attr": ["rw"], "rotate": 0}, {"bits": 24}], "config": {"lanes": 1, "fontsize": 10, "vspace": 80}}
{"reg": [{"name": "EN", "bits": 8, "attr": ["rw"], "rotate": 0}, {"name": "TRANSITION_EN", "bits": 1, "attr": ["rw"], "rotate": -90}, {"bits": 23}], "config": {"lanes": 1, "fontsize": 10, "vspace": 150}}
```

| Bits | Type | Reset | Name | Description |
|:------:|:------:|:-------:|:-------|:-------------------------------------------------------------------------------|
| 31:8 | | | | Reserved |
| 7:0 | rw | 0x0 | EN | 0: filter match wil not generate wakeupe; 1: filter match will generate wakeup |
| Bits | Type | Reset | Name |
|:------:|:------:|:-------:|:------------------------------------------------|
| 31:9 | | | Reserved |
| 8 | rw | 0x0 | [TRANSITION_EN](#adc_wakeup_ctl--transition_en) |
| 7:0 | rw | 0x0 | [EN](#adc_wakeup_ctl--en) |

### adc_wakeup_ctl . TRANSITION_EN
Wakeup due to FSM transition from low power sampling
mode to normal sampling mode.

Note that this wakeup source is primarily intended for debug purposes.
If enabled all the time, this can lead to many wakeups due to false
positives that are ruled out automatically by adc_ctrl after
transitioning from LP -> NP.

0: filter match wil not generate wakeup;
1: filter match will generate wakeup

### adc_wakeup_ctl . EN
Filter wakeup source.

0: filter match wil not generate wakeup;
1: filter match will generate wakeup

## adc_intr_ctl
Interrupt enable controls.
Expand All @@ -325,36 +344,57 @@ which internal sources are actually registered.
This register uses the same bit enumeration as [`ADC_INTR_STATUS`](#adc_intr_status)
- Offset: `0x70`
- Reset default: `0x0`
- Reset mask: `0x1ff`
- Reset mask: `0x3ff`

### Fields

```wavejson
{"reg": [{"name": "EN", "bits": 9, "attr": ["rw"], "rotate": 0}, {"bits": 23}], "config": {"lanes": 1, "fontsize": 10, "vspace": 80}}
{"reg": [{"name": "EN", "bits": 8, "attr": ["rw"], "rotate": 0}, {"name": "TRANSITION_EN", "bits": 1, "attr": ["rw"], "rotate": -90}, {"name": "ONESHOT_EN", "bits": 1, "attr": ["rw"], "rotate": -90}, {"bits": 22}], "config": {"lanes": 1, "fontsize": 10, "vspace": 150}}
```

| Bits | Type | Reset | Name | Description |
|:------:|:------:|:-------:|:-------|:-------------------------------------------------------------------|
| 31:9 | | | | Reserved |
| 8:0 | rw | 0x0 | EN | 0: interrupt source is not enabled; 1: interrupt source is enabled |
| Bits | Type | Reset | Name |
|:------:|:------:|:-------:|:----------------------------------------------|
| 31:10 | | | Reserved |
| 9 | rw | 0x0 | [ONESHOT_EN](#adc_intr_ctl--oneshot_en) |
| 8 | rw | 0x0 | [TRANSITION_EN](#adc_intr_ctl--transition_en) |
| 7:0 | rw | 0x0 | [EN](#adc_intr_ctl--en) |

### adc_intr_ctl . ONESHOT_EN
Interrupt due to oneshot sampling.

0: interrupt source is not enabled; 1: interrupt source is enabled

### adc_intr_ctl . TRANSITION_EN
Interrupt due to FSM transition from low power sampling
mode to normal sampling mode. This is mainly intended for debug.

Note that this interrupt is primarily intended for debug purposes.

0: interrupt source is not enabled; 1: interrupt source is enabled

### adc_intr_ctl . EN
Filter interrupt source.

0: interrupt source is not enabled; 1: interrupt source is enabled

## adc_intr_status
Debug cable internal status
- Offset: `0x74`
- Reset default: `0x0`
- Reset mask: `0x1ff`
- Reset mask: `0x3ff`

### Fields

```wavejson
{"reg": [{"name": "filter_match", "bits": 8, "attr": ["rw1c"], "rotate": 0}, {"name": "oneshot", "bits": 1, "attr": ["rw1c"], "rotate": -90}, {"bits": 23}], "config": {"lanes": 1, "fontsize": 10, "vspace": 90}}
{"reg": [{"name": "FILTER_MATCH", "bits": 8, "attr": ["rw1c"], "rotate": 0}, {"name": "TRANSITION", "bits": 1, "attr": ["rw1c"], "rotate": -90}, {"name": "ONESHOT", "bits": 1, "attr": ["rw1c"], "rotate": -90}, {"bits": 22}], "config": {"lanes": 1, "fontsize": 10, "vspace": 120}}
```

| Bits | Type | Reset | Name | Description |
|:------:|:------:|:-------:|:-------------|:-----------------------------------------------------------|
| 31:9 | | | | Reserved |
| 8 | rw1c | 0x0 | oneshot | 0: oneshot sample is not done ; 1: oneshot sample is done |
| 7:0 | rw1c | 0x0 | filter_match | 0: filter condition is not met; 1: filter condition is met |
| 31:10 | | | | Reserved |
| 9 | rw1c | 0x0 | ONESHOT | 0: oneshot sample is not done ; 1: oneshot sample is done |
| 8 | rw1c | 0x0 | TRANSITION | 0: transition did not occur; 1: transition occurred |
| 7:0 | rw1c | 0x0 | FILTER_MATCH | 0: filter condition is not met; 1: filter condition is met |

## adc_fsm_state
State of the internal state machine
Expand Down
5 changes: 4 additions & 1 deletion hw/ip/adc_ctrl/rtl/adc_ctrl.sv
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,12 @@ module adc_ctrl
.intr_o(intr_match_done_o),
.adc_i(adc_i),
.adc_o(adc_o),
.fsm_state_o(hw2reg.adc_fsm_state.d)
.aon_fsm_state_o(hw2reg.adc_fsm_state.d)
);




// All outputs should be known value after reset
`ASSERT_KNOWN(IntrKnown, intr_match_done_o)
`ASSERT_KNOWN(WakeKnown, wkup_req_o)
Expand Down
18 changes: 12 additions & 6 deletions hw/ip/adc_ctrl/rtl/adc_ctrl_core.sv
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ module adc_ctrl_core import adc_ctrl_reg_pkg::* ; (
output ast_pkg::adc_ast_req_t adc_o,

// FSM state output for debug purposes.
output fsm_state_e fsm_state_o
output adc_ctrl_pkg::fsm_state_e aon_fsm_state_o
);

logic chn0_val_we, chn1_val_we;//write enable for the latest ADC sample
logic [9:0] chn0_val, chn1_val;

logic [NumAdcFilter-1:0] chn0_match, chn1_match, match;
logic [NumAdcFilter-1:0] match_pulse;
logic aon_fsm_transition;

//write enable for the ADC sample when the interrupt is triggered
logic adc_ctrl_done, oneshot_done;
Expand Down Expand Up @@ -157,7 +158,8 @@ module adc_ctrl_core import adc_ctrl_reg_pkg::* ; (
.chn1_val_o(chn1_val),
.adc_ctrl_done_o(adc_ctrl_done),
.oneshot_done_o(oneshot_done),
.fsm_state_o
.aon_fsm_state_o,
.aon_fsm_transition_o(aon_fsm_transition)
);

// synchronzie from clk_aon into cfg domain
Expand All @@ -173,14 +175,18 @@ module adc_ctrl_core import adc_ctrl_reg_pkg::* ; (

//Instantiate the interrupt module
adc_ctrl_intr u_adc_ctrl_intr (
.clk_i,
.rst_ni,
.clk_aon_i,
.rst_aon_ni,
.aon_filter_match_i(match_pulse),
.clk_i,
.rst_ni,
.cfg_intr_en_i(reg2hw_i.adc_intr_ctl.q),
.cfg_wkup_en_i(reg2hw_i.adc_wakeup_ctl.q),
.aon_fsm_transition_i(aon_fsm_transition),
.cfg_oneshot_done_i(cfg_oneshot_done),
.cfg_intr_en_i(reg2hw_i.adc_intr_ctl.en.q),
.cfg_wkup_en_i(reg2hw_i.adc_wkup_ctl.en.q),
.cfg_intr_transition_en_i(reg2hw_i.adc_intr_ctl.transition_en.q),
.cfg_wkup_transition_en_i(reg2hw_i.adc_wkup_ctl.transition_en.q),
.cfg_oneshot_done_en_i(reg2hw_i.adc_intr_ctl.oneshot_en.q),
.intr_state_i(reg2hw_i.intr_state),
.intr_enable_i(reg2hw_i.intr_enable),
.intr_test_i(reg2hw_i.intr_test),
Expand Down
8 changes: 5 additions & 3 deletions hw/ip/adc_ctrl/rtl/adc_ctrl_fsm.sv
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ module adc_ctrl_fsm
output logic [9:0] chn1_val_o,
output logic adc_ctrl_done_o,
output logic oneshot_done_o,
output fsm_state_e fsm_state_o // FSM state output for debug purposes
output fsm_state_e aon_fsm_state_o, // FSM state output for debug purposes
output logic aon_fsm_transition_o // FSM lp -> np transition indication pulse
);

logic trigger_q;
Expand All @@ -54,7 +55,7 @@ module adc_ctrl_fsm


fsm_state_e fsm_state_q, fsm_state_d;
assign fsm_state_o = fsm_state_q;
assign aon_fsm_state_o = fsm_state_q;

always_ff @(posedge clk_aon_i or negedge rst_aon_ni) begin
if (!rst_aon_ni) begin
Expand Down Expand Up @@ -185,7 +186,6 @@ module adc_ctrl_fsm
assign lp_sample_cnt_thresh = cfg_lp_sample_cnt_i - 1'b1;
assign np_sample_cnt_thresh = cfg_np_sample_cnt_i - 1'b1;


always_comb begin: adc_fsm
fsm_state_d = fsm_state_q;
//outputs
Expand All @@ -202,6 +202,7 @@ module adc_ctrl_fsm
adc_ctrl_done_o = 1'b0;
oneshot_done_o = 1'b0;
ld_match = 1'b0;
aon_fsm_transition_o = 1'b0;

unique case (fsm_state_q)
PWRDN: begin
Expand Down Expand Up @@ -289,6 +290,7 @@ module adc_ctrl_fsm
end else if (lp_sample_cnt_q == lp_sample_cnt_thresh) begin
fsm_state_d = NP_0;
lp_sample_cnt_clr = 1'b1;
aon_fsm_transition_o = 1'b1;
end
end
end
Expand Down
Loading

0 comments on commit d8029c4

Please sign in to comment.