diff options
author | Daniel Hellstrom <daniel@gaisler.com> | 2019-04-12 11:01:38 +0200 |
---|---|---|
committer | Daniel Hellstrom <daniel@gaisler.com> | 2021-03-07 16:08:23 +0100 |
commit | da7cb87b4df3047795f0674775131b34469d5fa5 (patch) | |
tree | 04df0983ed8ea1a1b231fe71a32ac2e85e78cc46 /bsps/include/grlib/canbtrs.h | |
parent | grlib,ambapp: added new IP core IDs (diff) | |
download | rtems-da7cb87b4df3047795f0674775131b34469d5fa5.tar.bz2 |
leon,can: introduce common CAN baud-rate calculation function
Reimplemented the baud-rate algorithm from scratch to cope with
GRCAN, GRCANFD and OC_CAN devices.
Update #4306.
Diffstat (limited to 'bsps/include/grlib/canbtrs.h')
-rw-r--r-- | bsps/include/grlib/canbtrs.h | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/bsps/include/grlib/canbtrs.h b/bsps/include/grlib/canbtrs.h new file mode 100644 index 0000000000..7369136931 --- /dev/null +++ b/bsps/include/grlib/canbtrs.h @@ -0,0 +1,94 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * @ingroup can + * @brief Common CAN baud-rate routines for OCCAN/GRCAN/GRCANFD controllers + */ + +/* + * Copyright (C) 2019, 2020 Cobham Gaisler AB + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __GRLIB_CANBTRS_H__ +#define __GRLIB_CANBTRS_H__ + +/** + * @defgroup can CAN + * + * @ingroup RTEMSBSPsSharedGRLIB + * + * @brief CAN routines shared between OCCAN, GRCAN and GRCANFD controllers + * + * @{ + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* CAN Baud-rate parameters, range of valid parameter values */ +struct grlib_canbtrs_ranges { + unsigned int max_scaler; + char has_bpr; + unsigned char divfactor; + unsigned char min_tseg1; + unsigned char max_tseg1; + unsigned char min_tseg2; + unsigned char max_tseg2; +}; + +struct grlib_canbtrs_timing { + unsigned char scaler; + unsigned char ps1; + unsigned char ps2; + unsigned char rsj; + unsigned char bpr; +}; + +/* @brief Calculate CAN baud-rate generation parameters from requested baud-rate + * + * @param baud The CAN baud rate requested + * @param core_hz Input clock [Hz] to CAN core + * @param sampl_pt CAN sample point in %, 80 means 80% + * @param br CAN Baud-rate parameters limitations + * @param[out] timing result is placed here + * + * @retval 0 Baud-rate parameters sucessfully calculated + * @retval negative Failure to generate parameters with less than 5% error + * margin from requested baud-rate + */ +int grlib_canbtrs_calc_timing( + unsigned int baud, + unsigned int core_hz, + unsigned int sampl_pt, + struct grlib_canbtrs_ranges *br, + struct grlib_canbtrs_timing *timing + ); + +#ifdef __cplusplus +} +#endif + +#endif |