Verification of A CAN Bus Model in SystemC With
Verification of A CAN Bus Model in SystemC With
functional coverage
Gilles B. Defo, Christoph Kuznik, Wolfgang Müller
University of Paderborn/C-LAB
Faculty of Electrical Engineering
Computer Science and Mathematics
33102 Paderborn, Germany
{defo, kuznik, wolfgang}@c-lab.de
Abstract—Many heterogeneous embedded systems, for exam- respect to the user-defined metrics. The task to verify the
ple industrial automation and automotive applications, require actual simulation behavior of the DUT functionality with the
hard-real time constraints to be exhaustively verified - which expected one still has to be accomplished by implementing a
is a challenging task for the verification engineer. To cope
with complexity, verification techniques working on different testbench. So, functional coverage can tell if a property was
abstraction levels are best practice. SystemC is a versatile executed at the right time, in the right order and context.
C++ based design and verification language, offering various In the ideal case of a close coupling of a testbench and
mechanisms and constructs required for embedded systems functional coverage analysis, the information can even be
modeling. Using the add-on SystemC Verification Library (SCV) processed at runtime to steer the constrained random stimuli
elemental constrained-random stimuli techniques may be used
for verification. However, SCV has several drawbacks such as generation. While the IEEE 1800 SystemVerilog [2] standard
lack of functional coverage. In this paper we present a functional and other Hardware Verification Languages (HVL) such as e
coverage library that implements parts of the IEEE 1800-2005 incorporate functional coverage language features, these are
SystemVerilog standard and allows capturing functional coverage neither available in the IEEE 1666 SystemC standard [3]
throughout the design and verification process with SystemC. nor in any publicly available SystemC library. To overcome
Moreover, we will demonstrate the usability of the approach with
a case study working on a CAN bus model written in SystemC. this, we developed a SystemC functional coverage library and
testbench and applied it to a SystemC model of a Controller
I. I NTRODUCTION Area Network (CAN) based on the standard described in [4].
In several domains like industry automation and automo- In this article, we first introduce our SystemC implementa-
tive systems, the verification of hard real-time constraints tion of the IEEE 1800-2005 SystemVerilog coverage language
and verification of functional and non-functional properties features in Section II. The fundamentals of the CAN Controller
for integrated system behaviors is essential. For example, bus model are introduced in Section III. Section IV outlines
machine-aided assembly lines, where process steps of auto- the testbench architecture and components of the implemented
matic units and human workers intertwine with each other Controller Area Network (CAN) case study. Thereafter, sce-
require a safe and deterministic behavior for the team play. narios of the verification environment are discussed in detail
In automotive applications multiple field busses running in in Section V. Section VI compares our approach with existing
parallel, exchanging messages with each other need to be standards and related work in the area of functional coverage
verified to guarantee safety-critical behavior. Verifying these within SystemC before we close with a conclusion in Section
systems is a time consuming and tedious task. To cope with VII.
always more complexity and to boost productivity, more effi-
cient verification techniques and technologies were introduced II. S YSTEM C C OVERAGE L IBRARY
through the last years like the notion of functional verification
[1] which supports features such as verification of assertions, The SystemC functional coverage (SCFC) library partly
constrained-based random test pattern generation, and func- implements the covergroup concept of the IEEE 1800-
tional coverage. This article, focuses on the implementation 2005 SystemVerilog standard [2] via a singleton Factory class
of a functional coverage library in SystemC and applies it on implemented in SystemC. In details, the library supports the
the verification of a CAN bus case study. definition of:
Functional coverage is a user defined metric to investigate • bins to collect hits for variable ranges of the coverpoint
to which extend the functionality of a given design under • default bins to capture all non-specified values
test (DUT) has been verified by simulation runs. As such, • ignore bins, i.e., values to ignore and disregard for
functional coverage keeps track of value assignments and coverage computation
changes of expressions and conditions within the code. Thus, • illegal bins, where a bin hit calls sc_stop()
it is not verified if the DUT is working properly rather than • transition bins to define value sequences and evaluation
just gives information of the quality of the test pattern with with help of user-defined sample function
CAN controller
The corresponding implementation of the illegal and
IML
ignore concept within the SCFC library is shown in Figure
5. To define a cross-coverpoint, a coverpoint has to be declared
first. Using the methods new_illegal_SVCrossBins Clock Message Buffer
EML
and new_ignore_SVCrossBins the respective bins are txb
created. Moreover, the cross product is limited using the
intersect operator and an expression consisting of boolean
operators !, &&, and ||, which are also supported by the
rxfifo
BSP
SystemC library. Transition bins are support in two ways. First,
ACF
it is possible to define a custom sample function whereas return
value true leads to a bin hit. Second, transition vectors are
assigned to a transition bin and are elaborated with a vector
matching class.
In summary, our SystemC functional coverage implementa-
tion allows the definition of coverpoints with bins, transition CAN bus
A. Stimulus generation
The stimulus generator creates specific or completely ran-
domized messages for the Design Under Test based on the
parameterization. It offers the possibility to generate both
standard and extended CAN frames along CAN Specification
2.0 (see [4]. The choice is made based on a value that indicates
with what percentage standard CAN frames will be generated
throughout the simulation process. 100% means that only
standard CAN frames shall be generated. This value can be
set by a specific function within the testbench. Furthermore,
Fig. 7. Structure of a CAN message
it is possible to set a fixed ID for the CAN message that is
generated. Here, the use of the stimulus generator is inspired
standard and an extended CAN message format. As it can be by the SystemC Verification Library (SCV). Its application
seen, the main difference lies in the size of the arbitration is as follows: After its instantiation it can be parameterized
and the control field. Furthermore, Bit Timing Logic (BTL) using appropriate function calls. New CAN frame objects
which is a module that handles bit timing in CAN systems are created by the function call next() and can be directly
is not implemented. Instead, the assumption is made that referenced in the generator. Furthermore, CAN frames which
all controllers in the network are triggered by the same do not need stuff bits can also be generated by using the
clock. Therefore, no synchronization is needed. For further next no stuff() function call. Stuff bits are special bits needed
information of the module Bit Timing Logic see [4]. Due to for synchronization purposes during data transmission on a
the absence of the BTL module, no overload frames are sent CAN bus. After five consecutive bits of the same value an
by the BSP. inverted bit has to be inserted. For the generation of Stuff-
bit-free CAN frames, the fields Arbitration, Control and Data
IV. CAN T ESTBENCH
are created without stuff bits. Thereafter, the CRC check is
The general architecture of the implemented CAN is given simulated to verify that no stuff bits are really expected. If
in Figure 8. It comprises six components: this is the case, the message is stored in the generator and
B. Transfer function
Fig. 9. transfer function
The transfer function module receives all CAN frames
generated by the stimulus generator as input. These are then received controller message:
taken to compute the expected output of the DUT in order data -- > 01011110
to compare it with the actual output produced by the DUT
later within the LA (Logging and Acceptance evaluation) arbitration -- > 548(1000100100)
module. Another task of the transfer function is to compute generation_time -- > -
the transmission durations of the frames in clock ticks and
start_time --> 5
stores them in the scoreboard of the LA module. Hereby, the
length of the frame including the stuff bits that are inserted
during transmission and the arbitration on the CAN bus are Fig. 10. logging and acceptance evaluation
considered. The computation of the frame length is done by
the so-called StuffbitChecker.
The StuffBitChecker is part of the transfer function module. E. Logging and Acceptance evaluation
It automatically checks the number of stuff bits of each frame The LA module in the testbench is used for system analysis
generated by the stimulus generator and stores it with its and for logging of generated and received CAN frames.
position. For this, it iterates through the relevant fields of the These are the messages produced by the generator and the
frame (SOF, ARB, CTRL, DATA, CRC). Furthermore, CRC- received by the receiving controller within the DUT are
Check is simulated for the computation of Stuff bits present logged. The second task of the LA module is the comparison
in the CRC field. Afterward the results of the computation can and verification of the output provided by the Transfer function
be accessed by the LA Module or by the Coverage monitor. module with the actual output of the DUT. Figures 9 and
All frames present in the system are stored in a vector and 10 depict such a log-file generated by the LA module. As
processed according to their respective IDs. This guarantees shown in the figure, only the dynamic part (i.e., parts that
that only those messages compete as in the arbitration phase were automatically generated) of the messages are logged with
of the CAN network. some additional timing information.
Figure 9 shows the message produced by the stimulus
generator, and simulated by the transfer function. This file
C. Driver
contains the generation time, the calculated arrival time in
Since the message objects produced by the stimulus gener- clock ticks and the ID controller sending of this message.
ator are standard data types (int, char), and because of the Figure 10 shows the message after its transmission over the
fact that the CAN model uses sc_logic vectors to store the CAN bus. It contains the time stamp at which the controller
individual message elements, the driver module makes use of started the message transfer and the time stamp at which
a message converter to convert the generated values into CAN- the message was received. These log files can be used for
frames before driving them to the DUT. manual review of DUT behavior. Furthermore, the LA module
monitors the bus traffic in order to rebuild the transmitted
D. Coverage monitor CAN-frames. Hereby, the main focus is to test and verify the
behavior of the BSP module by investigating aspects such
The coverage monitor is used in the testbench model to as the recognition of stuff bits and correct behavior during
gather coverage information for message objects produced by the arbitration phase. These are stored in a map with the
the generator and for messages received from the DUT. For appropriate CAN frame along with the position of stuff bits
this, we define a functional coverage metric with help of our for each message. The stuff bits identified by the BSP module
functional coverage library and make use of it in several test are compared with those calculated by the transfer function
scenarios. The coverage metric monitors the desired values and taken into account during the acceptance evaluation. The
and performs a functional coverage analysis. An example is frames calculated by the transfer function and the frames
to cover the IDs of the generated CAN frames of the stimulus transmitted on the CAN bus are stored in a scoreboard and
generator. A termination condition can be set based on the can later be used to conduct the acceptance evaluation. In
information from the coverage analysis like for instance when order to check the reliability of the design under the conditions
a specific number of IDs within a certain interval have been provided by the test cases, it is possible to alter various metrics
generated. such as the percentage of error free message receptions or the
Fig. 12. Constructor of test scenario V-E Fig. 14. sample() method of test scenario V-E
always set to true once the transfer function has determined on the stuff_bit_count_sig signal which is driven
the stuff bits of a generated CAN message. by the transfer function and contains the amount of stuff
Additionally, two SC_METHOD are defined which will be bits generated for the latest generated CAN message. The
executed every clock cycle. In order to generate meaningful transitions bin makes use of that value in order to check
traffic for the CAN bus model, one method is utilized to if they are covered. After these steps, the coverage library
generate and transmit new messages, as depicted in Figure is instantiated, configured by setting database filename, and
13. initialized.
Fig. 13. CAN message randomizer of test scenario V-E Fig. 15. Verification Environment (transition bins) in test scenario V-E