[AVR] Add CRC HAL file for CRC module.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@15909 27425a3e-05d8-49a3-a47f-9c15f0e5edd8
This commit is contained in:
parent
50e9ab03a3
commit
7773ef599d
|
@ -0,0 +1,156 @@
|
||||||
|
/*
|
||||||
|
ChibiOS - Copyright (C) 2006..2022 Theodore Ateba
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file hal_crc.c
|
||||||
|
* @brief CRC Driver code.
|
||||||
|
*
|
||||||
|
* @addtogroup CRCv1
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "hal.h"
|
||||||
|
|
||||||
|
/* Custom Driver must directly include the low level driver. */
|
||||||
|
#include "hal_crc_lld.h"
|
||||||
|
|
||||||
|
#if HAL_USE_CRC || defined(__DOXYGEN__)
|
||||||
|
|
||||||
|
/*===========================================================================*/
|
||||||
|
/* Driver local definitions. */
|
||||||
|
/*===========================================================================*/
|
||||||
|
|
||||||
|
/*===========================================================================*/
|
||||||
|
/* Driver exported variables. */
|
||||||
|
/*===========================================================================*/
|
||||||
|
|
||||||
|
/*===========================================================================*/
|
||||||
|
/* Driver local variables and types. */
|
||||||
|
/*===========================================================================*/
|
||||||
|
|
||||||
|
/*===========================================================================*/
|
||||||
|
/* Driver local functions. */
|
||||||
|
/*===========================================================================*/
|
||||||
|
|
||||||
|
/*===========================================================================*/
|
||||||
|
/* Driver exported functions. */
|
||||||
|
/*===========================================================================*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief CRC Driver initialization.
|
||||||
|
* @note This function is not implicitly invoked by @p halInit(). So we
|
||||||
|
* need to explicitly initialize the driver by calling this function.
|
||||||
|
*
|
||||||
|
* @init
|
||||||
|
*/
|
||||||
|
void crcInit(void) {
|
||||||
|
|
||||||
|
crc_lld_init();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Initializes the standard part of a @p CRCDriver structure.
|
||||||
|
*
|
||||||
|
* @param[out] crcp pointer to the @p CRCDriver object
|
||||||
|
*
|
||||||
|
* @init
|
||||||
|
*/
|
||||||
|
void crcObjectInit(CRCDriver *crcp) {
|
||||||
|
|
||||||
|
crc_lld_object_init(crcp);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Configures and activates the CRC peripheral.
|
||||||
|
*
|
||||||
|
* @param[in] crcp pointer to the @p CRCDriver object
|
||||||
|
* @param[in] config pointer to the @p CRCConfig object
|
||||||
|
* @return The operation status.
|
||||||
|
*
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
msg_t crcStart(CRCDriver *crcp, CRCConfig *config) {
|
||||||
|
|
||||||
|
osalDbgCheck((crcp != NULL) && (config != NULL));
|
||||||
|
|
||||||
|
osalSysLock();
|
||||||
|
osalDbgAssert((crcp->state == CRC_STOP) || (crcp->state == CRC_READY),
|
||||||
|
"invalid state");
|
||||||
|
|
||||||
|
crcp->config = config;
|
||||||
|
|
||||||
|
crc_lld_start(crcp, config);
|
||||||
|
crcp->state = CRC_READY;
|
||||||
|
|
||||||
|
osalSysUnlock();
|
||||||
|
|
||||||
|
return HAL_RET_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Deactivates the CRC peripheral.
|
||||||
|
*
|
||||||
|
* @param[in] crcp pointer to the @p CRCDriver object
|
||||||
|
*
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
void crcStop(CRCDriver *crcp) {
|
||||||
|
|
||||||
|
osalDbgCheck(crcp != NULL);
|
||||||
|
|
||||||
|
osalSysLock();
|
||||||
|
|
||||||
|
osalDbgAssert((crcp->state == CRC_STOP) || (crcp->state == CRC_READY),
|
||||||
|
"invalid state");
|
||||||
|
|
||||||
|
crc_lld_stop(crcp);
|
||||||
|
crcp->config = NULL;
|
||||||
|
crcp->state = CRC_STOP;
|
||||||
|
|
||||||
|
osalSysUnlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Resets CRC module.
|
||||||
|
*
|
||||||
|
* @param[in] crcp pointer to the @p CRCDriver object
|
||||||
|
* @param[in] rt type of reset to perform, all to zeros or all to ones
|
||||||
|
*
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
void crcReset(CRCDriver *crcp, crcreset_t rt) {
|
||||||
|
|
||||||
|
osalDbgCheck(crcp != NULL);
|
||||||
|
|
||||||
|
osalSysLock();
|
||||||
|
osalDbgAssert(crcp->state == CRC_READY, "not ready");
|
||||||
|
crc_lld_reset(crcp, rt);
|
||||||
|
osalSysUnlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t crcComputeCRC16OnData(CRCDriver *crcp, uint8_t *srcp, size_t size) {
|
||||||
|
|
||||||
|
uint16_t retVal = 0;
|
||||||
|
|
||||||
|
osalDbgCheck(crcp != NULL);
|
||||||
|
|
||||||
|
osalSysLock();
|
||||||
|
retVal = crc_lld_compute_crc16_on_data(crcp, srcp, size);
|
||||||
|
osalSysUnlock();
|
||||||
|
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* HAL_USE_CRC */
|
||||||
|
|
||||||
|
/** @} */
|
|
@ -0,0 +1,82 @@
|
||||||
|
/*
|
||||||
|
ChibiOS - Copyright (C) 2006..2022 Theodore Ateba
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file hal_crc.h
|
||||||
|
* @brief CRC Driver macros and structures.
|
||||||
|
*
|
||||||
|
* @addtogroup CRC
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef HAL_CRC_H
|
||||||
|
#define HAL_CRC_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#if (HAL_USE_CRC == TRUE) || defined(__DOXYGEN__)
|
||||||
|
|
||||||
|
/*===========================================================================*/
|
||||||
|
/* Driver constants. */
|
||||||
|
/*===========================================================================*/
|
||||||
|
|
||||||
|
/*===========================================================================*/
|
||||||
|
/* Driver pre-compile time settings. */
|
||||||
|
/*===========================================================================*/
|
||||||
|
|
||||||
|
/*===========================================================================*/
|
||||||
|
/* Derived constants and error checks. */
|
||||||
|
/*===========================================================================*/
|
||||||
|
|
||||||
|
/*===========================================================================*/
|
||||||
|
/* Driver data structures and types. */
|
||||||
|
/*===========================================================================*/
|
||||||
|
|
||||||
|
#include "hal_crc_lld.h"
|
||||||
|
|
||||||
|
/*===========================================================================*/
|
||||||
|
/* Driver macros. */
|
||||||
|
/*===========================================================================*/
|
||||||
|
|
||||||
|
/*===========================================================================*/
|
||||||
|
/* External declarations. */
|
||||||
|
/*===========================================================================*/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
void crcInit(void);
|
||||||
|
void crcObjectInit(CRCDriver *crcp);
|
||||||
|
|
||||||
|
msg_t crcStart(CRCDriver *crcp, CRCConfig * config);
|
||||||
|
void crcStop(CRCDriver *crcp);
|
||||||
|
|
||||||
|
void crcReset(CRCDriver *crcp, crcreset_t rt);
|
||||||
|
|
||||||
|
/* @TODO: uint16_t crcComputeCRC16OnMemory(CRCDriver *crcp, uint8_t *src, size_t size); */
|
||||||
|
/* @TODO: uint32_t crcComputeCRC32OnMemory(CRCDriver *crcp, uint8_t *src, size_t size); */
|
||||||
|
|
||||||
|
/* @TODO: uint16_t crcComputeCRC16OnDMA(CRCDriver *crcp, uint8_t *src, size_t size); */
|
||||||
|
/* @TODO: uint32_t crcComputeCRC32OnDMA(CRCDriver *crcp, uint8_t *src, size_t size); */
|
||||||
|
|
||||||
|
uint16_t crcComputeCRC16OnData(CRCDriver *crcp, uint8_t *srcp, size_t size);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* HAL_USE_CRC == TRUE */
|
||||||
|
|
||||||
|
#endif /* HAL_CRC_H */
|
||||||
|
|
||||||
|
/** @} */
|
|
@ -116,8 +116,6 @@ typedef struct {
|
||||||
} CHECKSUM3;
|
} CHECKSUM3;
|
||||||
} xmega_crc_t;
|
} xmega_crc_t;
|
||||||
|
|
||||||
/** @} */
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
/* Driver macros. */
|
/* Driver macros. */
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
|
Loading…
Reference in New Issue