Skip to main content

logicaffeine_compile/codegen_sva/protocols/
mod.rs

1//! Pre-Verified Protocol Templates
2//!
3//! Parameterizable SVA properties for standard hardware protocols.
4//! Each template produces SvaProperty + English spec string.
5
6pub mod riscv;
7
8use super::SvaAssertionKind;
9
10/// A protocol template — produces parameterized SVA properties.
11#[derive(Debug, Clone)]
12pub struct ProtocolProperty {
13    pub name: String,
14    pub spec: String,
15    pub sva_body: String,
16    pub kind: SvaAssertionKind,
17}
18
19/// AXI4 write channel handshake properties.
20pub fn axi4_write_handshake(clock: &str) -> Vec<ProtocolProperty> {
21    vec![
22        ProtocolProperty {
23            name: "AXI_AW_Handshake".into(),
24            spec: "Always, if AWVALID is asserted, then eventually AWREADY responds.".into(),
25            sva_body: "AWVALID |-> s_eventually(AWREADY)".into(),
26            kind: SvaAssertionKind::Assert,
27        },
28        ProtocolProperty {
29            name: "AXI_W_Follows_AW".into(),
30            spec: "Always, if the address handshake completes, then eventually WVALID is asserted."
31                .into(),
32            sva_body: "(AWVALID && AWREADY) |-> s_eventually(WVALID)".into(),
33            kind: SvaAssertionKind::Assert,
34        },
35        ProtocolProperty {
36            name: "AXI_B_Follows_W".into(),
37            spec:
38                "Always, if the write data handshake completes, then eventually BVALID is asserted."
39                    .into(),
40            sva_body: "(WVALID && WREADY) |-> s_eventually(BVALID)".into(),
41            kind: SvaAssertionKind::Assert,
42        },
43    ]
44}
45
46/// APB setup/access phase properties.
47pub fn apb_protocol(clock: &str) -> Vec<ProtocolProperty> {
48    vec![
49        ProtocolProperty {
50            name: "APB_Setup_Phase".into(),
51            spec: "Always, if PSEL is asserted without PENABLE, then PENABLE follows next cycle."
52                .into(),
53            sva_body: "(PSEL && !PENABLE) |=> PENABLE".into(),
54            kind: SvaAssertionKind::Assert,
55        },
56        ProtocolProperty {
57            name: "APB_Ready_In_Access".into(),
58            spec: "Always, if PSEL and PENABLE are both asserted, eventually PREADY responds."
59                .into(),
60            sva_body: "(PSEL && PENABLE) |-> s_eventually(PREADY)".into(),
61            kind: SvaAssertionKind::Assert,
62        },
63    ]
64}
65
66/// UART transmit properties.
67pub fn uart_tx(clock: &str) -> Vec<ProtocolProperty> {
68    vec![ProtocolProperty {
69        name: "UART_TX_Busy".into(),
70        spec: "Always, if tx_start is asserted, then tx_busy holds until transmission completes."
71            .into(),
72        sva_body: "tx_start |-> s_eventually(tx_busy)".into(),
73        kind: SvaAssertionKind::Assert,
74    }]
75}
76
77/// SPI properties.
78pub fn spi_protocol(clock: &str) -> Vec<ProtocolProperty> {
79    vec![ProtocolProperty {
80        name: "SPI_MOSI_Stable".into(),
81        spec: "Always, when chip select is active, MOSI is stable on the clock edge.".into(),
82        sva_body: "!ss |-> $stable(mosi)".into(),
83        kind: SvaAssertionKind::Assert,
84    }]
85}
86
87/// I2C properties.
88pub fn i2c_protocol(clock: &str) -> Vec<ProtocolProperty> {
89    vec![
90        ProtocolProperty {
91            name: "I2C_Start_Condition".into(),
92            spec: "A start condition is SDA falling while SCL is high.".into(),
93            sva_body: "$fell(sda) && scl".into(),
94            kind: SvaAssertionKind::Cover,
95        },
96        ProtocolProperty {
97            name: "I2C_Stop_Condition".into(),
98            spec: "A stop condition is SDA rising while SCL is high.".into(),
99            sva_body: "$rose(sda) && scl".into(),
100            kind: SvaAssertionKind::Cover,
101        },
102    ]
103}