takashi kadono / Mbed OS Nucleo446_SSD1331

Dependencies:   ssd1331

Committer:
kadonotakashi
Date:
Thu Oct 11 02:27:46 2018 +0000
Revision:
3:f3764f852aa8
Parent:
0:8fdf9a60065b
Nucreo 446 + SSD1331 test version;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kadonotakashi 0:8fdf9a60065b 1 /** \addtogroup hal */
kadonotakashi 0:8fdf9a60065b 2 /** @{*/
kadonotakashi 0:8fdf9a60065b 3 /* mbed Microcontroller Library
kadonotakashi 0:8fdf9a60065b 4 * Copyright (c) 2018 ARM Limited
kadonotakashi 0:8fdf9a60065b 5 *
kadonotakashi 0:8fdf9a60065b 6 * Licensed under the Apache License, Version 2.0 (the "License");
kadonotakashi 0:8fdf9a60065b 7 * you may not use this file except in compliance with the License.
kadonotakashi 0:8fdf9a60065b 8 * You may obtain a copy of the License at
kadonotakashi 0:8fdf9a60065b 9 *
kadonotakashi 0:8fdf9a60065b 10 * http://www.apache.org/licenses/LICENSE-2.0
kadonotakashi 0:8fdf9a60065b 11 *
kadonotakashi 0:8fdf9a60065b 12 * Unless required by applicable law or agreed to in writing, software
kadonotakashi 0:8fdf9a60065b 13 * distributed under the License is distributed on an "AS IS" BASIS,
kadonotakashi 0:8fdf9a60065b 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
kadonotakashi 0:8fdf9a60065b 15 * See the License for the specific language governing permissions and
kadonotakashi 0:8fdf9a60065b 16 * limitations under the License.
kadonotakashi 0:8fdf9a60065b 17 */
kadonotakashi 0:8fdf9a60065b 18 #ifndef MBED_CRC_HAL_API_H
kadonotakashi 0:8fdf9a60065b 19 #define MBED_CRC_HAL_API_H
kadonotakashi 0:8fdf9a60065b 20
kadonotakashi 0:8fdf9a60065b 21 #include <stdbool.h>
kadonotakashi 0:8fdf9a60065b 22 #include <stddef.h>
kadonotakashi 0:8fdf9a60065b 23 #include <stdint.h>
kadonotakashi 0:8fdf9a60065b 24
kadonotakashi 0:8fdf9a60065b 25 /** CRC Polynomial value
kadonotakashi 0:8fdf9a60065b 26 *
kadonotakashi 0:8fdf9a60065b 27 * Different polynomial values supported
kadonotakashi 0:8fdf9a60065b 28 */
kadonotakashi 0:8fdf9a60065b 29 typedef enum crc_polynomial {
kadonotakashi 0:8fdf9a60065b 30 POLY_OTHER = 0,
kadonotakashi 0:8fdf9a60065b 31 POLY_8BIT_CCITT = 0x07, // x8+x2+x+1
kadonotakashi 0:8fdf9a60065b 32 POLY_7BIT_SD = 0x9, // x7+x3+1;
kadonotakashi 0:8fdf9a60065b 33 POLY_16BIT_CCITT = 0x1021, // x16+x12+x5+1
kadonotakashi 0:8fdf9a60065b 34 POLY_16BIT_IBM = 0x8005, // x16+x15+x2+1
kadonotakashi 0:8fdf9a60065b 35 POLY_32BIT_ANSI = 0x04C11DB7, // x32+x26+x23+x22+x16+x12+x11+x10+x8+x7+x5+x4+x2+x+1
kadonotakashi 0:8fdf9a60065b 36 POLY_32BIT_REV_ANSI = 0xEDB88320
kadonotakashi 0:8fdf9a60065b 37 } crc_polynomial_t;
kadonotakashi 0:8fdf9a60065b 38
kadonotakashi 0:8fdf9a60065b 39 typedef struct crc_mbed_config {
kadonotakashi 0:8fdf9a60065b 40 /** CRC Polynomial. Example polynomial: 0x21 = 0010_0011 = x^5+x+1 */
kadonotakashi 0:8fdf9a60065b 41 uint32_t polynomial;
kadonotakashi 0:8fdf9a60065b 42 /** CRC Bit Width */
kadonotakashi 0:8fdf9a60065b 43 uint32_t width;
kadonotakashi 0:8fdf9a60065b 44 /** Initial seed value for the computation. */
kadonotakashi 0:8fdf9a60065b 45 uint32_t initial_xor;
kadonotakashi 0:8fdf9a60065b 46 /** Final xor value for the computation. */
kadonotakashi 0:8fdf9a60065b 47 uint32_t final_xor;
kadonotakashi 0:8fdf9a60065b 48 /** Reflect bits on input. */
kadonotakashi 0:8fdf9a60065b 49 bool reflect_in;
kadonotakashi 0:8fdf9a60065b 50 /** Reflect bits in final result before returning. */
kadonotakashi 0:8fdf9a60065b 51 bool reflect_out;
kadonotakashi 0:8fdf9a60065b 52 } crc_mbed_config_t;
kadonotakashi 0:8fdf9a60065b 53
kadonotakashi 0:8fdf9a60065b 54 #ifdef DEVICE_CRC
kadonotakashi 0:8fdf9a60065b 55
kadonotakashi 0:8fdf9a60065b 56 #ifdef __cplusplus
kadonotakashi 0:8fdf9a60065b 57 extern "C" {
kadonotakashi 0:8fdf9a60065b 58 #endif
kadonotakashi 0:8fdf9a60065b 59
kadonotakashi 0:8fdf9a60065b 60 /**
kadonotakashi 0:8fdf9a60065b 61 * \defgroup hal_crc Hardware CRC
kadonotakashi 0:8fdf9a60065b 62 *
kadonotakashi 0:8fdf9a60065b 63 * The Hardware CRC HAL API provides a low-level interface to the Hardware CRC
kadonotakashi 0:8fdf9a60065b 64 * module of a target platform.
kadonotakashi 0:8fdf9a60065b 65 *
kadonotakashi 0:8fdf9a60065b 66 * # Defined behaviour
kadonotakashi 0:8fdf9a60065b 67 *
kadonotakashi 0:8fdf9a60065b 68 * * Function hal_crc_is_supported() returns true if platform supports hardware
kadonotakashi 0:8fdf9a60065b 69 * CRC for the given polynomial/width - verified by test ::crc_is_supported_test.
kadonotakashi 0:8fdf9a60065b 70 * * Function hal_crc_is_supported() returns false if platform does not support hardware
kadonotakashi 0:8fdf9a60065b 71 * CRC for the given polynomial/width - verified by test ::crc_is_supported_test.
kadonotakashi 0:8fdf9a60065b 72 * * Function hal_crc_is_supported() returns false if given pointer to configuration
kadonotakashi 0:8fdf9a60065b 73 * structure is undefined (NULL) - verified by test ::crc_is_supported_invalid_param_test.
kadonotakashi 0:8fdf9a60065b 74 * * If CRC module does not support one of the following settings: initial_xor, final_xor
kadonotakashi 0:8fdf9a60065b 75 * reflect_in, reflect_out, then these operations should be handled by the driver
kadonotakashi 0:8fdf9a60065b 76 * - Verified by test ::crc_calc_single_test.
kadonotakashi 0:8fdf9a60065b 77 * * Platform which supports hardware CRC must be able to handle at least one of the predefined
kadonotakashi 0:8fdf9a60065b 78 * polynomial/width configurations that can be constructed in the MbedCRC class: POLY_8BIT_CCITT,
kadonotakashi 0:8fdf9a60065b 79 * POLY_7BIT_SD, POLY_16BIT_CCITT, POLY_16BIT_IBM, POLY_32BIT_ANSI
kadonotakashi 0:8fdf9a60065b 80 * - verified by test ::crc_is_supported_test, ::crc_calc_single_test.
kadonotakashi 0:8fdf9a60065b 81 * * Function hal_crc_compute_partial_start() configures CRC module with the given configuration
kadonotakashi 0:8fdf9a60065b 82 * - Verified by test ::crc_calc_single_test.
kadonotakashi 0:8fdf9a60065b 83 * * Calling hal_crc_compute_partial_start() without finalising the
kadonotakashi 0:8fdf9a60065b 84 * CRC calculation overrides the current configuration - Verified by test ::crc_reconfigure_test.
kadonotakashi 0:8fdf9a60065b 85 * * Function hal_crc_compute_partial() writes data to the CRC module - verified by test ::crc_calc_single_test.
kadonotakashi 0:8fdf9a60065b 86 * * Function hal_crc_compute_partial() can be call multiple times in succession in order to
kadonotakashi 0:8fdf9a60065b 87 * provide additional data to CRC module - verified by test ::crc_calc_multi_test.
kadonotakashi 0:8fdf9a60065b 88 * * Function hal_crc_compute_partial() does nothing if pointer to buffer is undefined or
kadonotakashi 0:8fdf9a60065b 89 * data length is equal to 0 - verified by test ::crc_compute_partial_invalid_param_test.
kadonotakashi 0:8fdf9a60065b 90 * * Function hal_crc_get_result() returns the checksum result from the CRC module
kadonotakashi 0:8fdf9a60065b 91 * - verified by tests ::crc_calc_single_test, ::crc_calc_multi_test, ::crc_reconfigure_test.
kadonotakashi 0:8fdf9a60065b 92 *
kadonotakashi 0:8fdf9a60065b 93 * # Undefined behaviour
kadonotakashi 0:8fdf9a60065b 94 *
kadonotakashi 0:8fdf9a60065b 95 * * Calling hal_crc_compute_partial_start() function with invalid (unsupported) polynomial.
kadonotakashi 0:8fdf9a60065b 96 * * Calling hal_crc_compute_partial() or hal_crc_get_result() functions before hal_crc_compute_partial_start().
kadonotakashi 0:8fdf9a60065b 97 * * Calling hal_crc_get_result() function multiple times.
kadonotakashi 0:8fdf9a60065b 98 *
kadonotakashi 0:8fdf9a60065b 99 * # Non-functional requirements
kadonotakashi 0:8fdf9a60065b 100 *
kadonotakashi 0:8fdf9a60065b 101 * * CRC configuration provides the following settings:
kadonotakashi 0:8fdf9a60065b 102 * * polynomial - CRC Polynomial,
kadonotakashi 0:8fdf9a60065b 103 * * width - CRC bit width,
kadonotakashi 0:8fdf9a60065b 104 * * initial_xor - seed value for the computation,
kadonotakashi 0:8fdf9a60065b 105 * * final_xor - final xor value for the computation,
kadonotakashi 0:8fdf9a60065b 106 * * reflect_in - reflect bits on input,
kadonotakashi 0:8fdf9a60065b 107 * * reflect_out - reflect bits in final result before returning.
kadonotakashi 0:8fdf9a60065b 108 *
kadonotakashi 0:8fdf9a60065b 109 * # Potential bugs
kadonotakashi 0:8fdf9a60065b 110 *
kadonotakashi 0:8fdf9a60065b 111 * @{
kadonotakashi 0:8fdf9a60065b 112 */
kadonotakashi 0:8fdf9a60065b 113
kadonotakashi 0:8fdf9a60065b 114 /**
kadonotakashi 0:8fdf9a60065b 115 * \defgroup hal_crc_tests crc hal tests
kadonotakashi 0:8fdf9a60065b 116 * The crc HAL tests ensure driver conformance to defined behaviour.
kadonotakashi 0:8fdf9a60065b 117 *
kadonotakashi 0:8fdf9a60065b 118 * To run the crc hal tests use the command:
kadonotakashi 0:8fdf9a60065b 119 *
kadonotakashi 0:8fdf9a60065b 120 * mbed test -t <toolchain> -m <target> -n tests-mbed_hal-crc*
kadonotakashi 0:8fdf9a60065b 121 *
kadonotakashi 0:8fdf9a60065b 122 */
kadonotakashi 0:8fdf9a60065b 123
kadonotakashi 0:8fdf9a60065b 124 /** Determine if the current platform supports hardware CRC for given polynomial
kadonotakashi 0:8fdf9a60065b 125 *
kadonotakashi 0:8fdf9a60065b 126 * The purpose of this function is to inform the CRC Platform API whether the
kadonotakashi 0:8fdf9a60065b 127 * current platform has a hardware CRC module and that it can support the
kadonotakashi 0:8fdf9a60065b 128 * requested polynomial.
kadonotakashi 0:8fdf9a60065b 129 *
kadonotakashi 0:8fdf9a60065b 130 * Supported polynomials are restricted to the named polynomials that can be
kadonotakashi 0:8fdf9a60065b 131 * constructed in the MbedCRC class, POLY_8BIT_CCITT, POLY_7BIT_SD,
kadonotakashi 0:8fdf9a60065b 132 * POLY_16BIT_CCITT, POLY_16BIT_IBM and POLY_32BIT_ANSI.
kadonotakashi 0:8fdf9a60065b 133 *
kadonotakashi 0:8fdf9a60065b 134 * The current platform must support the given polynomials default parameters
kadonotakashi 0:8fdf9a60065b 135 * in order to return a true response. These include: reflect in, reflect out,
kadonotakashi 0:8fdf9a60065b 136 * initial xor and final xor. For example, POLY_32BIT_ANSI requires an initial
kadonotakashi 0:8fdf9a60065b 137 * and final xor of 0xFFFFFFFF, and reflection of both input and output. If any
kadonotakashi 0:8fdf9a60065b 138 * of these settings cannot be configured, the polynomial is not supported.
kadonotakashi 0:8fdf9a60065b 139 *
kadonotakashi 0:8fdf9a60065b 140 * This function is thread safe; it safe to call from multiple contexts if
kadonotakashi 0:8fdf9a60065b 141 * required.
kadonotakashi 0:8fdf9a60065b 142 *
kadonotakashi 0:8fdf9a60065b 143 * \param config Contains CRC configuration parameters for initializing the
kadonotakashi 0:8fdf9a60065b 144 * hardware CRC module. For example, polynomial and initial seed
kadonotakashi 0:8fdf9a60065b 145 * values.
kadonotakashi 0:8fdf9a60065b 146 *
kadonotakashi 0:8fdf9a60065b 147 * \return True if running if the polynomial is supported, false if not.
kadonotakashi 0:8fdf9a60065b 148 */
kadonotakashi 0:8fdf9a60065b 149 bool hal_crc_is_supported(const crc_mbed_config_t *config);
kadonotakashi 0:8fdf9a60065b 150
kadonotakashi 0:8fdf9a60065b 151 /** Initialize the hardware CRC module with the given polynomial
kadonotakashi 0:8fdf9a60065b 152 *
kadonotakashi 0:8fdf9a60065b 153 * After calling this function, the CRC HAL module is ready to receive data
kadonotakashi 0:8fdf9a60065b 154 * using the hal_crc_compute_partial() function. The CRC module on the board
kadonotakashi 0:8fdf9a60065b 155 * is configured internally with the specified configuration and is ready
kadonotakashi 0:8fdf9a60065b 156 * to receive data.
kadonotakashi 0:8fdf9a60065b 157 *
kadonotakashi 0:8fdf9a60065b 158 * The platform configures itself based on the default configuration
kadonotakashi 0:8fdf9a60065b 159 * parameters of the input polynomial.
kadonotakashi 0:8fdf9a60065b 160 *
kadonotakashi 0:8fdf9a60065b 161 * This function must be called before calling hal_crc_compute_partial().
kadonotakashi 0:8fdf9a60065b 162 *
kadonotakashi 0:8fdf9a60065b 163 * This function must be called with a valid polynomial supported by the
kadonotakashi 0:8fdf9a60065b 164 * platform. The polynomial must be checked for support using the
kadonotakashi 0:8fdf9a60065b 165 * hal_crc_is_supported() function.
kadonotakashi 0:8fdf9a60065b 166 *
kadonotakashi 0:8fdf9a60065b 167 * Calling hal_crc_compute_partial_start() multiple times without finalizing the
kadonotakashi 0:8fdf9a60065b 168 * CRC calculation with hal_crc_get_result() overrides the current
kadonotakashi 0:8fdf9a60065b 169 * configuration and state, and the intermediate result of the computation is
kadonotakashi 0:8fdf9a60065b 170 * lost.
kadonotakashi 0:8fdf9a60065b 171 *
kadonotakashi 0:8fdf9a60065b 172 * This function is not thread safe. A CRC calculation must not be started from
kadonotakashi 0:8fdf9a60065b 173 * two different threads or contexts at the same time; calling this function
kadonotakashi 0:8fdf9a60065b 174 * from two different contexts may lead to configurations being overwritten and
kadonotakashi 0:8fdf9a60065b 175 * results being lost.
kadonotakashi 0:8fdf9a60065b 176 *
kadonotakashi 0:8fdf9a60065b 177 * \param config Contains CRC configuration parameters for initializing the
kadonotakashi 0:8fdf9a60065b 178 * hardware CRC module. For example, polynomial and initial seed
kadonotakashi 0:8fdf9a60065b 179 * values.
kadonotakashi 0:8fdf9a60065b 180 */
kadonotakashi 0:8fdf9a60065b 181 void hal_crc_compute_partial_start(const crc_mbed_config_t *config);
kadonotakashi 0:8fdf9a60065b 182
kadonotakashi 0:8fdf9a60065b 183 /** Writes data to the current CRC module.
kadonotakashi 0:8fdf9a60065b 184 *
kadonotakashi 0:8fdf9a60065b 185 * Writes input data buffer bytes to the CRC data register. The CRC module
kadonotakashi 0:8fdf9a60065b 186 * must interpret the data as an array of bytes.
kadonotakashi 0:8fdf9a60065b 187 *
kadonotakashi 0:8fdf9a60065b 188 * The final transformations are not applied to the data; the CRC module must
kadonotakashi 0:8fdf9a60065b 189 * retain the intermediate result so that additional calls to this function
kadonotakashi 0:8fdf9a60065b 190 * can be made, appending the additional data to the calculation.
kadonotakashi 0:8fdf9a60065b 191 *
kadonotakashi 0:8fdf9a60065b 192 * To obtain the final result of the CRC calculation, hal_crc_get_result() is
kadonotakashi 0:8fdf9a60065b 193 * called to apply the final transformations to the data.
kadonotakashi 0:8fdf9a60065b 194 *
kadonotakashi 0:8fdf9a60065b 195 * If the function is passed an undefined pointer, or the size of the buffer is
kadonotakashi 0:8fdf9a60065b 196 * specified to be 0, this function does nothing and returns.
kadonotakashi 0:8fdf9a60065b 197 *
kadonotakashi 0:8fdf9a60065b 198 * This function can be called multiple times in succession. This can be used
kadonotakashi 0:8fdf9a60065b 199 * to calculate the CRC result of streamed data.
kadonotakashi 0:8fdf9a60065b 200 *
kadonotakashi 0:8fdf9a60065b 201 * This function is not thread safe. There is only one instance of the CRC
kadonotakashi 0:8fdf9a60065b 202 * module active at a time. Calling this function from multiple contexts
kadonotakashi 0:8fdf9a60065b 203 * appends different data to the same, single instance of the module, which causes an
kadonotakashi 0:8fdf9a60065b 204 * erroneous value to be calculated.
kadonotakashi 0:8fdf9a60065b 205 *
kadonotakashi 0:8fdf9a60065b 206 * \param data Input data stream to be written into the CRC calculation
kadonotakashi 0:8fdf9a60065b 207 * \param size Size of the data stream in bytes
kadonotakashi 0:8fdf9a60065b 208 */
kadonotakashi 0:8fdf9a60065b 209 void hal_crc_compute_partial(const uint8_t *data, const size_t size);
kadonotakashi 0:8fdf9a60065b 210
kadonotakashi 0:8fdf9a60065b 211 /* Reads the checksum result from the CRC module.
kadonotakashi 0:8fdf9a60065b 212 *
kadonotakashi 0:8fdf9a60065b 213 * Reads the final checksum result for the final checksum value. The returned
kadonotakashi 0:8fdf9a60065b 214 * value is cast as an unsigned 32-bit integer. The actual size of the returned
kadonotakashi 0:8fdf9a60065b 215 * result depends on the polynomial used to configure the CRC module.
kadonotakashi 0:8fdf9a60065b 216 *
kadonotakashi 0:8fdf9a60065b 217 * Additional transformations that are used in the default configuration of the
kadonotakashi 0:8fdf9a60065b 218 * input polynomial are applied to the result before it is returned from this
kadonotakashi 0:8fdf9a60065b 219 * function. These transformations include: the final xor being appended to the
kadonotakashi 0:8fdf9a60065b 220 * calculation, and the result being reflected if required.
kadonotakashi 0:8fdf9a60065b 221 *
kadonotakashi 0:8fdf9a60065b 222 * Calling this function multiple times is undefined. The first call to this
kadonotakashi 0:8fdf9a60065b 223 * function returns the final result of the CRC calculation. The return
kadonotakashi 0:8fdf9a60065b 224 * value on successive calls is undefined because the contents of the register after
kadonotakashi 0:8fdf9a60065b 225 * accessing them is platform-specific.
kadonotakashi 0:8fdf9a60065b 226 *
kadonotakashi 0:8fdf9a60065b 227 * This function is not thread safe. There is only one instance of the CRC
kadonotakashi 0:8fdf9a60065b 228 * module active at a time. Calling this function from multiple contexts may
kadonotakashi 0:8fdf9a60065b 229 * return incorrect data or affect the current state of the module.
kadonotakashi 0:8fdf9a60065b 230 *
kadonotakashi 0:8fdf9a60065b 231 * \return The final CRC checksum after the reflections and final calculations
kadonotakashi 0:8fdf9a60065b 232 * have been applied.
kadonotakashi 0:8fdf9a60065b 233 */
kadonotakashi 0:8fdf9a60065b 234 uint32_t hal_crc_get_result(void);
kadonotakashi 0:8fdf9a60065b 235
kadonotakashi 0:8fdf9a60065b 236 /**@}*/
kadonotakashi 0:8fdf9a60065b 237
kadonotakashi 0:8fdf9a60065b 238 #ifdef __cplusplus
kadonotakashi 0:8fdf9a60065b 239 };
kadonotakashi 0:8fdf9a60065b 240 #endif
kadonotakashi 0:8fdf9a60065b 241
kadonotakashi 0:8fdf9a60065b 242 #endif // DEVICE_CRC
kadonotakashi 0:8fdf9a60065b 243 #endif // MBED_CRC_HAL_API_H
kadonotakashi 0:8fdf9a60065b 244
kadonotakashi 0:8fdf9a60065b 245 /**@}*/