提交SMOD ATSC IMX APP版本 V122

This commit is contained in:
2026-07-16 14:35:59 +08:00
commit 7601c270d5
485 changed files with 255032 additions and 0 deletions
+24
View File
@@ -0,0 +1,24 @@
Analog Devices, Inc. ("ADI")
Source Code Software License Agreement
20130524-CISC-CTSLA
DOWNLOADING, REPRODUCING, DISTRIBUTING OR OTHERWISE USING THE SOFTWARE CONSTITUTES ACCEPTANCE OF THIS LICENSE. THE SOFTWARE MAY NOT BE USED EXCEPT AS EXPRESSLY AUTHORIZED UNDER THIS LICENSE.
The software is protected by copyright law and international copyright treaties.
License: Subject to the terms and conditions of this license, the software may be reproduced, modified and distributed in source code and object code form.
Conditions:
Any distribution of the software must include a complete copy of this license and retain all copyright and other proprietary notices. The software that is distributed (including modified versions of the software) shall be subject to the terms and conditions of this license.
The software may not be combined or merged with other software in any manner that would cause the software to become subject to terms and conditions which differ from those of this license.
Licensee shall not use the name or any trademark of ADI (including those of its licensors) or any contributor to endorse or promote products without prior written consent of the owner of the name or trademark. The term “contributor” means any person or entity that modifies or distributes the software.
Modified versions of the Software must be conspicuously marked as such.
Use of the software may or may not infringe patent rights of one or more patent holders. This license does not alleviate the obligation to obtain separate licenses from patent holders to use the software.
All rights not expressly granted hereunder are reserved.
This license shall be governed by the laws of Massachusetts, without regard to its conflict of laws rules. The software shall only be used in compliance with all applicable laws and regulations, including without limitation export control laws.
WARRANTY DISCLAIMER: THE SOFTWARE AND ANY RELATED INFORMATION AND/OR ADVICE IS PROVIDED ON AN “AS IS” BASIS, WITHOUT REPRESENTATIONS, GUARANTEES OR WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED, ORAL OR WRITTEN, INCLUDING WITHOUT LIMITATION, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. There is no obligation to provide software support or updates. The Software is not fault-tolerant and is not intended for use in high risk applications, including without limitation in the operation of nuclear facilities, aircraft navigation or control systems, air traffic control, life support machines, weapons systems or any other application in which the failure of the software could lead to death, personal injury, or severe physical or environmental damages. The software is not authorized to be used under such circumstances.
LIMITATION OF LIABILITY: TO THE MAXIMUM EXTENT PERMITTED BY LAW ADI (INCLUDING ITS LICENSORS) AND CONTRIBUTORS SHALL NOT BE LIABLE FOR ANY DAMAGES ARISING FROM OR RELATED TO THE SOFTWARE, ITS USE OR ANY RELATED INFORMATION AND/OR SERVICES, INCLUDING BUT NOT LIMITED TO ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, PUNITIVE, EXEMPLARY, CONSEQUENTIAL OR ANALOGOUS DAMAGES (INCLUDING WITHOUT LIMITATION ANY DAMAGES RESULTING FROM LOSS OF USE, DATA, REVENUE, PROFITS, OR SAVINGS, COMPUTER DAMAGE OR ANY OTHER CAUSE), UNDER ANY LEGAL THEORY (INCLUDING WITHOUT LIMITATION CONTRACT, WARRANTY, TORT, NEGLIGENCE, STRICT OR PRODUCT LIABILITY), EVEN IF IT HAS BEEN INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. Some jurisdictions do not permit the exclusion or limitation of liability for consequential, incidental or other damages, and, as such, some portion of the above limitation may not apply. In such jurisdictions, liability is limited to the greatest extent permitted by law.
Third Party Software: The software may be accompanied by or include software made available by one or more third parties (“Third Party Software”). Each portion of Third Party Software is subject to its own separate software license terms and conditions (“Third Party Licenses”). The Third Party Licenses for Third Party Software delivered with the software are set forth or identified (by url or otherwise) in (i) Appendix A to this license (if any), (ii) the applicable software header or footer text, (iii) a text file located in the directory of the applicable Third Party Software component and/or (iv) such other location customarily used for licensing terms. The use of each portion of Third Party Software is subject to the Third Party Licenses, and you agree that your use of any Third Party Software is bound by the applicable Third Party License. You agree to review and comply with all applicable Third Party Licenses prior to any use or distribution of any Third Party Software. Third Party Software is provided on an “as is” basis without any representation, warranty or liability of any kind. ADI (including its licensors) and contributors shall have no liability or responsibility for the operation or performance of the Third Party Software and shall not be liable for any damages, costs, or expenses, direct or indirect, arising out of the performance or failure to perform of the Third Party Software. ADI (including its licensors) and contributors shall be entitled to the benefit of any and all limitations of liability and disclaimers of warranties contained in the Third Party Licenses. For the avoidance of doubt, this license does not alter, limit or expand the terms and conditions of, or rights granted to you pursuant to, Third Party Licenses
+546
View File
@@ -0,0 +1,546 @@
/**
* \file adi_hal.c
* \brief Contains ADI Hardware Abstraction functions
* End user must provide implementation based on their
* application and hardware platform.
*
* This file provides the ADI Evaluation platform implementation
* that will not be compiled unless the compiler option ADI_ZYNQ_PLATFORM
* is defined at compile time.
*
* Copyright 2015-2017 Analog Devices Inc.
* Released under the AD9378-AD9379 API license, for more information see the "LICENSE.txt" file in this zip file.
*/
#include "adi_hal.h"
#include "unistd.h"
#include "stdio.h"
#ifdef ADI_ZYNQ_PLATFORM
#include "zynq_platform.h"
#endif
//#include "../common.h"
#include "../inc/type.h"
#include "../adrv9009/adrv9009.h"
adiHalErr_t ADIHAL_setTimeout(void *devHalInfo, uint32_t halTimeout_ms)
{
adiHalErr_t retVal = ADIHAL_OK;
#ifdef ADI_ZYNQ_PLATFORM
if(devHalInfo == NULL)
{
return (ADIHAL_GEN_SW);
}
zynqAdiDev_t *devHalData = (zynqAdiDev_t *)devHalInfo;
devHalData->waitTimeout = halTimeout_ms;
HAL_writeToLogFile("ADIHAL_setTimeout at index %d to ", devHalData->devIndex, halTimeout_ms);
#endif
return retVal;
}
adiHalErr_t ADIHAL_openHw(void *devHalInfo, uint32_t halTimeout_ms)
{
adiHalErr_t retVal = ADIHAL_OK;
#ifdef ADI_ZYNQ_PLATFORM
int32_t error = 0;
zynqAdiDev_t *devHalData = (zynqAdiDev_t *)devHalInfo;
if(devHalInfo == NULL)
{
return (ADIHAL_GEN_SW);
}
devHalData->waitTimeout = halTimeout_ms;
switch(devHalData->devIndex)
{
/* SPI Devices*/
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
error = HAL_initSpiDriver(devHalData->spiSettings);
break;
default:
HAL_writeToLogFile("ERROR: ADIHAL_openHw: Unknown device index %d", devHalData->devIndex);
return (ADIHAL_GEN_SW);
}
HAL_writeToLogFile("ADIHAL_openHw: device index %d", devHalData->devIndex);
if (error != 0)
{
devHalData->spiErrCode = error;
HAL_writeToLogFile("ERROR: ADIHAL_openHw: HAL_initSpiDriver() failed with error %d for device %d", error, devHalData->devIndex);
retVal = ADIHAL_SPI_FAIL;
}
#endif
return (retVal);
}
adiHalErr_t ADIHAL_closeHw(void *devHalInfo)
{
adiHalErr_t retVal = ADIHAL_OK;
#ifdef ADI_ZYNQ_PLATFORM
int32_t error = 0;
zynqAdiDev_t *devHalData = (zynqAdiDev_t *)devHalInfo;
if(devHalInfo == NULL)
{
return (ADIHAL_GEN_SW);
}
switch(devHalData->devIndex)
{
/* SPI Devices */
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
error = HAL_closeSpiDriver(devHalData->spiSettings);
break;
default:
HAL_writeToLogFile("ERROR: ADIHAL_closeHw(): Unknown device index %d", devHalData->devIndex);
return (ADIHAL_GEN_SW);
}
HAL_writeToLogFile("ADIHAL_closeHw: device index %d", devHalData->devIndex);
if (error != 0)
{
devHalData->spiErrCode = error;
HAL_writeToLogFile("ERROR: ADIHAL_closeHw: HAL_closeSpiDriver() failed with error %d for device %d", error, devHalData->devIndex);
return (ADIHAL_SPI_FAIL);
}
#endif
return(retVal);
}
adiHalErr_t ADIHAL_resetHw(void *devHalInfo)
{
adiHalErr_t retVal = ADIHAL_OK;
int *pChipNo = (int *)devHalInfo;
retVal = (adiHalErr_t)ad9009_reset(*pChipNo);
#ifdef ADI_ZYNQ_PLATFORM
int32_t error = 0;
zynqAdiDev_t *devHalData = (zynqAdiDev_t *)devHalInfo;
if(devHalInfo == NULL)
{
return (ADIHAL_GEN_SW);
}
HAL_writeToLogFile("ADIHAL_resetHw at index %d", devHalData->devIndex);
error = HAL_resetHw(devHalData->devIndex);
if (error != 0)
{
devHalData->gpioErrCode = error;
HAL_writeToLogFile("ERROR: ADIHAL_resetHw: HAL_resetHw() failed with error %d for device %d", error, devHalData->devIndex);
return (ADIHAL_GPIO_FAIL);
}
#endif
return (retVal);
}
adiHalErr_t ADIHAL_spiWriteByte(void *devHalInfo, uint16_t addr, uint8_t data)
{
adiHalErr_t retVal = ADIHAL_OK;
int *pChipNo = (int*)devHalInfo;
u32 wr_value = data;
//retVal = (adiHalErr_t)write_ad9009(*pChipNo, addr, wr_value);
retVal = (adiHalErr_t)ad9009_write_spi(*pChipNo, addr, &wr_value, 1);
#ifdef ADI_ZYNQ_PLATFORM
int32_t error = 0;
zynqAdiDev_t *devHalData = (zynqAdiDev_t *)devHalInfo;
if(devHalInfo == NULL)
{
return (ADIHAL_GEN_SW);
}
error = HAL_SPIWriteByte(devHalData->spiSettings, addr, data);
if (error < 0)
{
devHalData->spiErrCode = error;
HAL_writeToLogFile("ERROR: ADIHAL_spiWriteByte(): HAL_SPIWriteByte() for device %d, chipSelect %d, returned error %d\n",
devHalData->devIndex, devHalData->spiSettings->chipSelectIndex, error);
return (ADIHAL_SPI_FAIL);
}
if (devHalData->logLevel & ADIHAL_LOG_SPI)
{
HAL_writeToLogFile("SPIWrite: CS:%2d, ADDR:0x%03X, DATA:0x%02X \n", devHalData->spiSettings->chipSelectIndex, addr, data);
}
#endif
return (retVal);
}
/*#if 0
#include "stdio.h"
#include <unistd.h>
#include <sys/time.h>
#include <unistd.h>
void usr_print_current_time(void)
{
struct timeval tv;
gettimeofday(&tv, NULL);
printf("time: %d.%d\n",tv.tv_sec,tv.tv_usec/1000);
}
int get_current_time_ms(void)
{
struct timeval tv;
gettimeofday(&tv, NULL);
return (tv.tv_sec*1000+tv.tv_usec/1000);
//printf("time: %d.%d\n",tv.tv_sec,tv.tv_usec/1000);
}
//#include "fpga.h"
void test_fpga_write_time()
{
// fpga write need 10ms
int time_start=0;
int time_stop=0;
int count=500;
time_start = get_current_time_ms();
for (u32 i = 0; i < count; i++)
{
//fpga_write(0x110, 0, 1);;
}
time_stop = get_current_time_ms();
printf("{time_cal fpga_write} count=%d total_time=%dms avg_time=%dms\n", count, time_stop - time_start, (time_stop - time_start)/count);
}
int time_start=0;
int time_stop=0;
#endif*/
adiHalErr_t ADIHAL_spiWriteBytes(void *devHalInfo, uint16_t *addr, uint8_t *data, uint32_t count)
{
adiHalErr_t retVal = ADIHAL_OK;
//test_fpga_write_time();
//printf("[%s,%d] start. count=%d addr=0x%x\n", __FUNCTION__, __LINE__, count, addr);
//usr_print_current_time();
//time_start = get_current_time_ms();
for (u32 i = 0; i < count; i++)
{
//printf("[%s,%d] start. count=%d addr=0x%x\n", __FUNCTION__, __LINE__, 1, addr);
if (ADIHAL_OK != (retVal = (adiHalErr_t)ADIHAL_spiWriteByte(devHalInfo, *(addr + i), *(data + i))))
//printf("[%s,%d] w_err. count=%d addr=0x%x\n", __FUNCTION__, __LINE__, 1, addr);
break;
//printf("[%s,%d] w_okk. count=%d addr=0x%x\n", __FUNCTION__, __LINE__, 1, addr);
}
//time_stop = get_current_time_ms();
//printf("{time_cal} count=%d total_time=%dms avg_time=%dms\n", count, time_stop - time_start, (time_stop - time_start)/count);
#ifdef ADI_ZYNQ_PLATFORM
int32_t error = 0;
zynqAdiDev_t *devHalData = (zynqAdiDev_t *)devHalInfo;
uint32_t i = 0;
if(devHalInfo == NULL)
{
return (ADIHAL_GEN_SW);
}
error = HAL_SPIWriteBytes(devHalData->spiSettings, addr, data, count);
if (error < 0)
{
devHalData->spiErrCode = error;
HAL_writeToLogFile("ERROR: ADIHAL_spiWriteBytes(): HAL_SPIWriteBytes() for device %d, chipSelect %d, returned error %d\n",
devHalData->devIndex, devHalData->spiSettings->chipSelectIndex, error);
return (ADIHAL_SPI_FAIL);
}
if (devHalData->logLevel & ADIHAL_LOG_SPI)
{
for(i = 0; i < count; i++)
{
HAL_writeToLogFile("SPIWrite: CS:%2d, ADDR:0x%03X, DATA:0x%02X \n", devHalData->spiSettings->chipSelectIndex, addr[i], data[i]);
}
}
#endif
return (retVal);
}
adiHalErr_t ADIHAL_spiReadByte(void *devHalInfo, uint16_t addr, uint8_t *readdata)
{
adiHalErr_t retVal = ADIHAL_OK;
int *pChipNo = (int *)devHalInfo;
unsigned int value;
//retVal = (adiHalErr_t)read_ad9009_value(*pChipNo, addr, &value);
//ad9009_read_spi(int num, u32 addr, u32 *pdata, u32 count)
retVal = (adiHalErr_t)ad9009_read_spi(*pChipNo, addr, &value, 1);
*readdata = value;
#ifdef ADI_ZYNQ_PLATFORM
int32_t error = 0;
zynqAdiDev_t *devHalData = (zynqAdiDev_t *)devHalInfo;
if(devHalInfo == NULL)
{
return (ADIHAL_GEN_SW);
}
error = HAL_SPIReadByte(devHalData->spiSettings, addr, readdata);
if (error < 0)
{
devHalData->spiErrCode = error;
HAL_writeToLogFile("ERROR: HAL_SPIReadByte() returned error %d, reading from device %d, ChipSelect:%d\n",
error, devHalData->devIndex, devHalData->spiSettings->chipSelectIndex);
return (ADIHAL_SPI_FAIL);
}
if (devHalData->logLevel & ADIHAL_LOG_SPI)
{
HAL_writeToLogFile("SPIRead: CS:%2d, ADDR:0x%03X, ReadData:0x%02X\n",
devHalData->devIndex, addr, *readdata);
}
#endif
return (retVal);
}
adiHalErr_t ADIHAL_spiReadBytes(void *devHalInfo, uint16_t *addr, uint8_t *readdata, uint32_t count)
{
adiHalErr_t retVal = ADIHAL_OK;
for (int i = 0; i < count; i++)
{
if (ADIHAL_OK != (retVal = ADIHAL_spiReadByte(devHalInfo, *(addr + i), readdata + i)))
break;
}
#ifdef ADI_ZYNQ_PLATFORM
int32_t error = 0;
zynqAdiDev_t *devHalData = (zynqAdiDev_t *)devHalInfo;
uint32_t i = 0;
if(devHalInfo == NULL)
{
return (ADIHAL_GEN_SW);
}
error = HAL_SPIReadBytes(devHalData->spiSettings, addr, readdata, count);
if (error < 0)
{
devHalData->spiErrCode = error;
HAL_writeToLogFile("ERROR: ADIHAL_spiWriteBytes(): HAL_SPIReadBytes() for device %d, chipSelect %d, returned error %d\n",
devHalData->devIndex, devHalData->spiSettings->chipSelectIndex, error);
return (ADIHAL_SPI_FAIL);
}
if (devHalData->logLevel & ADIHAL_LOG_SPI)
{
for(i = 0; i < count; i++)
{
HAL_writeToLogFile("SPIRead: CS:%2d, ADDR:0x%03X, ReadData:0x%02X\n",
devHalData->devIndex, addr[i], readdata[i]);
}
}
#endif
return (retVal);
}
adiHalErr_t ADIHAL_spiWriteField(void *devHalInfo,
uint16_t addr, uint8_t fieldVal, uint8_t mask, uint8_t startBit)
{
adiHalErr_t retVal = ADIHAL_OK;
uint8_t readVal = 0;
if (ADIHAL_OK != (retVal = ADIHAL_spiReadByte(devHalInfo, addr, &readVal)))
return retVal;
readVal = (readVal & ~mask) | ((fieldVal << startBit) & mask);
retVal = ADIHAL_spiWriteByte(devHalInfo, addr, readVal);
#ifdef ADI_ZYNQ_PLATFORM
uint8_t readVal = 0;
int32_t error = 0;
zynqAdiDev_t *devHalData = (zynqAdiDev_t *)devHalInfo;
if(devHalInfo == NULL)
{
return (ADIHAL_GEN_SW);
}
error = HAL_SPIReadByte(devHalData->spiSettings, addr, &readVal);
if (error < 0)
{
devHalData->spiErrCode = error;
HAL_writeToLogFile("ERROR: HAL_SPIReadByte() returned error %d in ADIHAL_spiWriteField()\n", error);
return (ADIHAL_SPI_FAIL);
}
readVal = (readVal & ~mask) | ((fieldVal << startBit) & mask);
error = HAL_SPIWriteByte(devHalData->spiSettings, addr, readVal);
if (error < 0 )
{
devHalData->spiErrCode = error;
HAL_writeToLogFile("ERROR: HAL_SPIWriteByte() returned error %d in ADIHAL_spiWriteField()\n", error);
return (ADIHAL_SPI_FAIL);
}
if (devHalData->logLevel & ADIHAL_LOG_SPI)
{
HAL_writeToLogFile("SPIWriteField: CS:%2d, ADDR:0x%03X, FIELDVAL:0x%02X, MASK:0x%02X, STARTBIT:%d\n",
devHalData->devIndex,addr, fieldVal, mask, startBit);
}
#endif
return (retVal);
}
adiHalErr_t ADIHAL_spiReadField(void *devHalInfo, uint16_t addr, uint8_t *fieldVal, uint8_t mask, uint8_t startBit)
{
adiHalErr_t retVal = ADIHAL_OK;
uint8_t readVal = 0;
if (ADIHAL_OK != (retVal = ADIHAL_spiReadByte(devHalInfo, addr, &readVal)))
return retVal;
*fieldVal = ((readVal & mask) >> startBit);
#ifdef ADI_ZYNQ_PLATFORM
uint8_t readVal = 0;
int32_t error = 0;
zynqAdiDev_t *devHalData = (zynqAdiDev_t *)devHalInfo;
if(devHalInfo == NULL)
{
return (ADIHAL_GEN_SW);
}
error = HAL_SPIReadByte(devHalData->spiSettings, addr, &readVal);
if (error < 0)
{
devHalData->spiErrCode = error;
HAL_writeToLogFile("ERROR: HAL_SPIReadByte() returned error %d in ADIHAL_spiReadField()\n", error);
return (ADIHAL_SPI_FAIL);
}
*fieldVal = ((readVal & mask) >> startBit);
if(devHalData->logLevel & ADIHAL_LOG_SPI)
{
HAL_writeToLogFile("SPIReadField: CS:%2d, ADDR:0x%03X, MASK:0x%02X, STARTBIT:%d, FieldVal:0x%02X\n",
devHalData->devIndex,addr, mask, startBit, *fieldVal);
}
#endif
return (retVal);
}
adiHalErr_t ADIHAL_wait_us(void *devHalInfo, uint32_t time_us)
{
adiHalErr_t retVal = ADIHAL_OK;
usleep(time_us);
#ifdef ADI_ZYNQ_PLATFORM
int32_t error = 0;
zynqAdiDev_t *devHalData = (zynqAdiDev_t *)devHalInfo;
if(devHalInfo == NULL)
{
return (ADIHAL_GEN_SW);
}
error = HAL_wait_us(time_us);
if (error != 0)
{
devHalData->timerErrCode = error;
HAL_writeToLogFile("ERROR: HAL_wait_us() returned error %d in ADIHAL_wait_us()\n", error);
return (ADIHAL_TIMER_FAIL);
}
#endif
return (retVal);
}
adiHalErr_t ADIHAL_writeToLog(void *devHalInfo, adiLogLevel_t logLevel, uint32_t errorCode, const char *comment)
{
adiHalErr_t retVal = ADIHAL_OK;
#ifdef ADI_ZYNQ_PLATFORM
zynqAdiDev_t *devHalData = (zynqAdiDev_t *)devHalInfo;
int32_t error = 0;
if(devHalInfo == NULL)
{
return (ADIHAL_GEN_SW);
}
if((devHalData->logLevel & ADIHAL_LOG_ERR) && (logLevel == ADIHAL_LOG_ERR))
{
error = HAL_writeToLogFile("ERROR: %d: %s", (int)errorCode, comment);
}
else if((devHalData->logLevel & ADIHAL_LOG_WARN) && (logLevel == ADIHAL_LOG_WARN))
{
error = HAL_writeToLogFile("WARNING: %d: %s", (int)errorCode, comment);
}
else if((devHalData->logLevel & ADIHAL_LOG_MSG) && (logLevel == ADIHAL_LOG_MSG))
{
error = HAL_writeToLogFile("MESSAGE: %d: %s",(int)errorCode, comment);
}
else
{
error = HAL_writeToLogFile("Undefined Log Level: 0x%X: %d: %s", logLevel, (int)errorCode, comment);
}
if(error != 0)
{
retVal = ADIHAL_WARNING;
}
#endif
return (retVal);
}
adiHalErr_t ADIHAL_setLogLevel(void *devHalInfo, uint16_t logLevel)
{
adiHalErr_t retVal = ADIHAL_OK;
#ifdef ADI_ZYNQ_PLATFORM
zynqAdiDev_t *devHalData = (zynqAdiDev_t *)devHalInfo;
if(devHalInfo == NULL)
{
return (ADIHAL_GEN_SW);
}
devHalData->logLevel = logLevel;
#endif
return retVal;
+579
View File
@@ -0,0 +1,579 @@
/**
* \file adi_hal.h
* \brief Contains Talise ADI HAL function prototypes type definitions for adi_hal.c
*
* Copyright 2015-2017 Analog Devices Inc.
* Released under the AD9378-AD9379 API license, for more information see the "LICENSE.txt" file in this zip file.
*/
#ifndef _ADI_HAL_H_
#define _ADI_HAL_H_
/* include standard types and definitions */
#include <stdint.h>
#include <stddef.h>
/*========================================
* Enums and structures
*=======================================*/
/**
* \brief Enum of possible Errors Detected by HAL layer to be communicated
* to ADI APIs.
*/
typedef enum
{
ADIHAL_OK = 0, /*!< HAL function successful. No error Detected */
ADIHAL_SPI_FAIL, /*!< HAL SPI operation failure. SPI controller Down */
ADIHAL_GPIO_FAIL, /*!< HAL GPIO function Failure */
ADIHAL_TIMER_FAIL, /*!< HAL Timer function Failure */
ADIHAL_WAIT_TIMEOUT, /*!< HAL function Timeout */
ADIHAL_GEN_SW, /*!< HAL function failed due to general invalid HAL data*/
ADIHAL_WARNING /*!< HAL function warning that non critical error was detected*/
} adiHalErr_t;
/**
* \brief An enumerated type in bit mask format to list the log message
* categories or groups.
*/
typedef enum
{
ADIHAL_LOG_NONE = 0x0, /*!< HAL Log enum to represent all types of log messages not selected */
ADIHAL_LOG_MSG = 0x1, /*!< HAL Log enum to represent a log message type*/
ADIHAL_LOG_WARN = 0x2, /*!< HAL Log enum to represent a warning message type*/
ADIHAL_LOG_ERR = 0x4, /*!< HAL Log enum to represent a error message type*/
ADIHAL_LOG_SPI = 0x8, /*!< HAL Log enum to represent a spi transaction type*/
ADIHAL_LOG_ALL = 0xF /*!< HAL Log enum to represent all types of log messages selected */
} adiLogLevel_t;
/*========================================
* Prototypes
*=======================================*/
#ifdef __cplusplus
extern "C" {
#endif
/* 3 Bytes per SPI transaction * 341 transactions = ~1024 byte buffer size */
/* Minimum HAL_SPIWRITEARRAY_BUFFERSIZE = 18 */
#define HAL_SPIWRITEARRAY_BUFFERSIZE 341
/*============================================================================
* ADI Device Hardware Control Functions
*===========================================================================*/
/**
* \brief Performs a platform hardware initialization for the ADI Device
*
* This function shall initialize all external hardware resources required by
* ADI Device for correct functionality such as SPI drivers, GPIOs,
* clocks (if necessary), as per the target platform and target ADI Device.
* At minimum any SPI driver for the ADI Device must be initialized here in order
* for the SPI writes within the API to function.
*
* The API based on the required operation shall set the value timeout parameter.
* Once this value is set it shall be the timeout requirement for all HAL operations.
* It is the responsibility of the HAL implementation to maintain this
* timeout value as a reference. The HAL implementation must use this value
* to ensure the HAL function do not block longer than this time interval.
*
* Returns an error of type adiHalErr_t. Error returned will depend on platform
* specific implementation. API expects ADIHAL_OK if function completed successfully.
* Any other value represents an error or warning to the API. Error return list
* below provides possible errors from customer implementation.
*
* \pre This API should be called before calling any other ADIHAL functions.
*
* <B>Dependencies</B>
* --Application and Platform Specific modules defined by devHalInfo
*
* \param devHalInfo A void pointer to the targeted device state container.
* The Platform HAL defined structure containing
* hardware settings describing the device of interest.
*
* \param halTimeout_ms A positive integer value to set the HAL function timeout
* interval.
*
* \retval ADIHAL_OK if function completed successfully.
* \retval ADIHAL_SPI_FAIL if function failed to open SPI driver for the device
* \retval ADIHAL_GPIO_FAIL, if function failed to access GPIO resources
* \retval ADIHAL_TIMER_FAIL, if function failed to access timer resources
* \retval ADIHAL_GEN_SW if device references is unknown.
* \retval ADIHAL_WARNING if function failed to access non-critical resource eg logging
*/
adiHalErr_t ADIHAL_openHw(void *devHalInfo, uint32_t halTimeout_ms);
/**
* \brief Closes any platform hardware drivers, handles, etc that were necessary
* for the ADI Device.
*
* This function shall shutdown all external hardware resources required by
* ADI Device for correct functionality such as SPI drivers, GPIOs, clocks as
* as per the targeted platform and target ADI Device.
* It should close and free any resources assigned in ADIHAL_openHw(void *devHalInfo)
*
* Returns an error of type adiHalErr_t. Error returned will depend on platform
* specific implementation. API expects ADIHAL_OK if function completed successfully.
* Any other value represents an error or warning to the API. Error return list
* below provides possible errors from customer implementation.
*
* \pre This function is called last to terminate the use of device instance and its
* hardware resources. ADIHAL_openHw for the same device instance prior to calling
* ADIHAL_closeHw
*
* <B>Dependencies</B>
* --Application and Platform Specific modules defined by devHalInfo
*
* \param devHalInfo Pointer to Platform HAL defined structure containing
* hardware settings describing the device of interest.
*
* \retval ADIHAL_OK if function completed successfully.
* \retval ADIHAL_SPI_FAIL if function failed to close SPI driver for the device
* \retval ADIHAL_GPIO_FAIL, if function failed to release GPIO resources
* \retval ADIHAL_GEN_SW if device references is unknown.
* \retval ADIHAL_WARNING if function failed to access non-critical resource eg logging
*/
adiHalErr_t ADIHAL_closeHw(void *devHalInfo);
/**
* \brief Sets the a timeout duration for the HAL functions.
*
* This function shall set the timeout duration for the HAL functions. If the
* HAL operation exceed this time the function shall return with the
* ADIHAL_WAIT_TIMEOUT error. This value shall be set by the API based on the
* desired required operation. Once this value is set it shall be the timeout
* requirement for all HAL operations.
*
* Returns an error of type adiHalErr_t. Error returned will depend on platform
* specific implementation. API expects ADIHAL_OK if function completed successfully.
* Any other value represents an error or warning to the API. Error return list
* below provides possible errors from customer implementation.
*
* \pre This function can be called at anytime to change the timeout duration
* for the HAL functions. However, it is typically used during initialization.
*
* <B>Dependencies</B>
* --Application and Platform Specific modules defined by devHalInfo
*
* \param devHalInfo Pointer to Platform HAL defined structure containing
* hardware settings describing the device of interest.
* \param halTimeout_ms A positive integer value to set the HAL function timeout
* interval.
*
* \retval ADIHAL_OK if function completed successfully.
* \retval ADIHAL_GEN_SW if device references is unknown. eg devHalInfo
*/
adiHalErr_t ADIHAL_setTimeout(void *devHalInfo, uint32_t halTimeout_ms);
/**
* \brief Performs a hardware reset on the ADI Device
*
* ADI Devices have a RESETB pin. This function shall toggle the appropriate
* ADI Device RESETB pin according to the specifications outlined in the ADI
* Device Data Sheet for the targeted Device.
*
* ADI does not define the structure members in devHalInfo. The user
* developing the platform layer of code is required to reset the correct
* device based on some identifying information within their devHalInfo
* structure such as a spi chip select or other device id in devHalInfo.
*
* Returns an error of type adiHalErr_t. Error returned will depend on platform
* specific implementation. API expects ADIHAL_OK if function completed successfully.
* Any other value represents an error or warning to the API. Error return list
* below provides possible errors from customer implementation.
*
* \pre This function may be called at any time to reset the device after the required
* GPIO drivers and resources are opened by the ADIHAL_openHw function call.
* and not after ADIHAL_closeHW.
*
*
* <B>Dependencies</B>
* --Application and Platform Specific modules defined by devHalInfo
*
*
* \param devHalInfo Pointer to Platform HAL defined structure containing
* hardware settings describing the device of interest and required
* hardware references to toggle RESETB pin of the ADI device.
*
*
* \retval ADIHAL_OK if function completed successfully.
* \retval ADIHAL_GEN_SW if device references is unknown.
* \retval ADIHAL_GPIO_FAIL if GPIO hardware to toggle ADI reset pin unavailable
* \retval ADIHAL_WAIT_TIMEOUT if HAL timeout expired before reset pin toggle could be completed.
* \retval ADIHAL_WARNING if function failed to access non-critical resource eg logging
*/
adiHalErr_t ADIHAL_resetHw(void *devHalInfo);
/**
* \brief Performs a Single SPI write to an ADI Device
*
* This function shall perform a single SPI write to an ADI Device. The SPI
* write implementation must support 15 bit addressing and 8-bit data bytes.
*
* Returns an error of type adiHalErr_t. Error returned will depend on platform
* specific implementation. API expects ADIHAL_OK if function completed successfully.
* Any other value represents an error or warning to the API. Error return list
* below provides possible errors from customer implementation.
*
* \pre This function may only be used after the required SPI drivers and resources
* are opened by the ADIHAL_openHw() function call and not after ADIHAL_closeHW.
*
* <B>Dependencies</B>
* --Application and Platform Specific modules
*
* \param devHalInfo Pointer to Platform HAL defined structure containing
* hardware settings describing the device of interest.
*
* \param addr 15-bit SPI register Address (MSB bit in lower layers sets
* read/write bit)
*
* \param data 8-bit data value to write to the SPI address specified.
*
* \retval ADIHAL_OK if function completed successfully.
* \retval ADIHAL_GEN_SW if device references is unknown.
* \retval ADIHAL_SPI_FAIL if function failed to complete SPI transaction
* \retval ADIHAL_WAIT_TIMEOUT if HAL timeout expired before SPI transaction could be completed.
* \retval ADIHAL_WARNING if function failed to access non-critical resource eg logging
*/
adiHalErr_t ADIHAL_spiWriteByte(void *devHalInfo, uint16_t addr, uint8_t data);
/**
* \brief Writes an array of SPI writes to an ADI Device
*
* This function allows improved performance to write large sets of SPI
* registers to a single device by passing the SPI Write address and data to
* the platform driver in an array instead of many individual calls.
*
* If the platform layer SPI driver has no way to write an array to the SPI
* driver, have this function call ADIHAL_spiWriteByte in a for loop.
*
* Each address element corresponds to the same index element in the data
* array. addr[0] is the SPI address for data[0], addr[1] is the SPI addr
* for data[1], etc.
*
* Returns an error of type adiHalErr_t. Error returned will depend on platform
* specific implementation. API expects ADIHAL_OK if function completed successfully.
* Any other value represents an error or warning to the API. Error return list
* below provides possible errors from customer implementation.
*
* \pre This function may only be used after the required SPI drivers and resources
* are opened by the ADIHAL_openHw() function call and not after ADIHAL_closeHW.
*
* <B>Dependencies</B>
* --Application and Platform Specific modules
*
* \param devHalInfo Pointer to Platform HAL defined structure containing
* hardware settings describing the device of interest.
*
* \param addr An array of 15-bit addresses of SPI register to write.
* 15-bit SPI register Addresses (MSB bit in lower layers sets
* read/write bit)
*
* \param data An array of 8-bit data values to write to the SPI addresses in
* the addr array.
*
* \param count The number of SPI Writes to transfer. Must be smaller or equal
* to the size of the addr and data arrays.
*
* \retval ADIHAL_OK if function completed successfully.
* \retval ADIHAL_GEN_SW if device references is unknown.
* \retval ADIHAL_SPI_FAIL if function failed to complete SPI transaction
* \retval ADIHAL_WAIT_TIMEOUT if HAL timeout expired before SPI transaction could be completed.
* \retval ADIHAL_WARNING if function failed to access non-critical resource eg logging
*/
adiHalErr_t ADIHAL_spiWriteBytes(void *devHalInfo, uint16_t *addr, uint8_t *data, uint32_t count);
/**
* \brief Performs a Single SPI Read from an ADI Device
*
* This function shall perform a single SPI read from an ADI Device. The SPI
* read implementation must support 16 bit addressing and 8-bit data bytes.
*
* Returns an error of type adiHalErr_t. Error returned will depend on platform
* specific implementation. API expects ADIHAL_OK if function completed successfully.
* Any other value represents an error or warning to the API. Error return list
* below provides possible errors from customer implementation.
*
* \pre This function may only be used after the required SPI drivers and resources
* are opened by the ADIHAL_openHw() function call and not after ADIHAL_closeHW.
*
* <B>Dependencies</B>
* --Application and Platform Specific modules
*
* \param devHalInfo Pointer to Platform HAL defined structure containing
* hardware settings describing the device of interest.
*
* \param addr The 16-bit address to read from the SPI device. Actual address
* can not exceed 15-bits since MSB bit is used for Read/Write bit
* in platform layer.
*
* \param readdata The 8-bit data value returned from SPI register addr
*
* \retval ADIHAL_OK if function completed successfully.
* \retval ADIHAL_GEN_SW if device references is unknown.
* \retval ADIHAL_SPI_FAIL if function failed to complete SPI transaction
* \retval ADIHAL_WAIT_TIMEOUT if HAL timeout expired before SPI transaction could be completed.
* \retval ADIHAL_WARNING if function failed to access non-critical resource eg logging
*/
adiHalErr_t ADIHAL_spiReadByte(void *devHalInfo, uint16_t addr, uint8_t *readdata);
/**
* \brief Performs a Multi SPI Read from an ADI Device
*
* This function shall perform multi SPI read from an ADI Device. The SPI
* read implementation must support 16 bit addressing and 8-bit data bytes.
*
* Returns an error of type adiHalErr_t. Error returned will depend on platform
* specific implementation. API expects ADIHAL_OK if function completed successfully.
* Any other value represents an error or warning to the API. Error return list
* below provides possible errors from customer implementation.
*
* \pre This function may only be used after the required SPI drivers and resources
* are opened by the ADIHAL_openHw() function call and not after ADIHAL_closeHW.
*
* <B>Dependencies</B>
* --Application and Platform Specific modules
*
* \param devHalInfo Pointer to Platform HAL defined structure containing
* hardware settings describing the device of interest.
*
* \param *addr An array of 15-bit addresses of SPI registers to read from.
* 15-bit SPI register Addresses (MSB bit in lower layers sets
* read/write bit)
*
* \param *readdata The 8-bit data value returned from SPI register addr
*
* \param count The number of SPI Reads to transfer. Must be equal
* to the size of the addr and data arrays.
*
* \retval ADIHAL_OK if function completed successfully.
* \retval ADIHAL_GEN_SW if device references is unknown.
* \retval ADIHAL_SPI_FAIL if function failed to complete SPI transaction
* \retval ADIHAL_WAIT_TIMEOUT if HAL timeout expired before SPI transaction could be completed.
* \retval ADIHAL_WARNING if function failed to access non-critical resource eg logging
*/
adiHalErr_t ADIHAL_spiReadBytes(void *devHalInfo, uint16_t *addr, uint8_t *readdata, uint32_t count);
/**
* \brief Performs a write to the specified field in a SPI register.
*
* This function shall perform a Read/Modify/Write of a single SPI read from an
* bits in the register, and writing the value back to the SPI register.
* ADI Device. The mask and startBit parameters allow modifying some or all
*
* The mask is expected to be applied to the complete 8-bit read back SPI
* register value. The startBit parameter is used to shift the fieldVal
* parameter to the correct starting bit in the SPI register.
*
* Desired Operation:
* readVal = Read 8-bit SPI register value
*
* Modify
* Clear bits in readVal for enabled mask bits (readVal & ~mask)
* Set bits in field based on mask and startBit ((fieldVal << startBit) & mask)
*
* Write the modified value back to the SPI register
*
* Returns an error of type adiHalErr_t. Error returned will depend on platform
* specific implementation. API expects ADIHAL_OK if function completed successfully.
* Any other value represents an error or warning to the API. Error return list
* below provides possible errors from customer implementation.
*
* \pre This function may only be used after the required SPI drivers and resources
* are opened by the ADIHAL_openHw() function call and not after ADIHAL_closeHW.
*
* <B>Dependencies</B>
* --Application and Platform Specific modules
*
* \param devHalInfo Pointer to Platform HAL defined structure containing
* hardware settings describing the device of interest.
*
* \param addr The 16-bit address to read/modify/write from the SPI device.
* Actual address can not exceed 15-bits since MSB bit is used for
* Read/Write bit in platform layer.
*
* \param fieldVal 8-bit value to update in a bitfield (subset) of the SPI register
*
* \param mask 8-bit mask of bits to modify (if a bit = 1, that bit can be modified)
* \param startBit starting bit of the fieldVal in the SPI reg. Bit shifts
* the fieldVal up to that bit before masking and modifying the SPI
* reg.
*
* \retval ADIHAL_OK if function completed successfully.
* \retval ADIHAL_GEN_SW if device references is unknown.
* \retval ADIHAL_SPI_FAIL if function failed to complete SPI transaction
* \retval ADIHAL_WAIT_TIMEOUT if HAL timeout expired before SPI transaction could be completed.
* \retval ADIHAL_WARNING if function failed to access non-critical resource eg logging
*/
adiHalErr_t ADIHAL_spiWriteField(void *devHalInfo, uint16_t addr, uint8_t fieldVal, uint8_t mask, uint8_t startBit);
/**
* \brief Performs a read from a particular bit field in a SPI register.
*
* This function shall perform a single SPI read from an ADI Device. Before
* the SPI read value is returned, it is masked and bit-shifted to return
* only a desired subset of bits - the desired bit field.
*
* Any necessary SPI drivers or resources are expected to have already been
* opened by the ADIHAL_openHw() function call.
*
* The mask parameter is applied to the entire 8-bit SPI read back value. The
* startBit parameter shifts the desired subset of bits down to the zero bit
* position.
*
* Desired Operation:
* readVal = SPI read of a 8-bit SPI register
* return (readVal & mask) >> startBit
*
* Returns an error of type adiHalErr_t. Error returned will depend on platform
* specific implementation. API expects ADIHAL_OK if function completed successfully.
* Any other value represents an error or warning to the API. Error return list
* below provides possible errors from customer implementation.
*
* \pre This function may only be used after the required SPI drivers and resources
* are opened by the ADIHAL_openHw() function call and not after ADIHAL_closeHW.
*
* <B>Dependencies</B>
* --Application and Platform Specific modules
*
* \param devHalInfo Pointer to Platform HAL defined structure containing
* hardware settings describing the device of interest.
*
* \param addr The 16-bit address to read/modify/write from the SPI device.
* Actual address can not exceed 15-bits since MSB bit is used for
* Read/Write bit in platform layer.
*
* \param fieldVal 8-bit value: Readback value of a bitfield (subset) of the
* SPI register masked and shifted down to the bit 0 position
*
* \param mask 8-bit mask of bits to readback (if a bit = 1, that bit can be read)
* \param startBit starting LSB bit of the fieldVal in the SPI reg. Bit shifts
* the fieldVal down to that bit before returning in fieldVal
*
* \retval ADIHAL_OK if function completed successfully.
* \retval ADIHAL_GEN_SW if device references is unknown.
* \retval ADIHAL_SPI_FAIL if function failed to complete SPI transaction
* \retval ADIHAL_WAIT_TIMEOUT if HAL timeout expired before SPI transaction could be completed.
* \retval ADIHAL_WARNING if function failed to access non-critical resource eg logging
*/
adiHalErr_t ADIHAL_spiReadField(void *devHalInfo, uint16_t addr, uint8_t *fieldVal, uint8_t mask, uint8_t startBit);
/**
* \brief Delay or sleep for the specified number of microseconds.
*
* Performs a thread blocking/sleeping delay of the specified time in us.
* Function should wait at least for the specified amount of time.
*
* Returns an error of type adiHalErr_t. Error returned will depend on platform
* specific implementation. API expects ADIHAL_OK if function completed successfully.
* Any other value represents an error or warning to the API. Error return list
* below provides possible errors from customer implementation.
*
* \pre This function can be used at any time to create a delay
*
* <B>Dependencies</B>
* --Application and Platform Specific modules
*
*
* \param devHalInfo Pointer to Platform HAL defined structure containing
* hardware settings describing the device of interest.
*
* \param time_us The amount of time in microseconds to block - thread sleep for
*
* \retval ADIHAL_OK if function completed successfully.
* \retval ADIHAL_GEN_SW if device references is unknown.
* \retval ADIHAL_TIMER_FAIL if function delay function failed to complete
* \retval ADIHAL_WARNING if function failed to access non-critical resource eg logging
*
*/
adiHalErr_t ADIHAL_wait_us(void *devHalInfo, uint32_t time_us);
/*========================================
* Optional Logging Functions
*
*=======================================*/
/**
* \brief Writes a character array to a log file to facilitate debugging
*
* This function uses the logLevel parameter to specify what type of
* message / warning / error to write to the log file. This function
* uses enums in adiLogLevel_t to set the log level.
* ADIHAL_LOG_NONE = 0x0,
* ADIHAL_LOG_MSG = 0x1,
* ADIHAL_LOG_WARN = 0x2,
* ADIHAL_LOG_ERR = 0x4,
* ADIHAL_LOG_SPI = 0x8,
* ADIHAL_LOG_ALL = 0xF
*
* The user implementation may choose to allow a feature to filter
* the level of message to log. This could allow only logging errors
* for instance.
*
* Returns an error of type adiHalErr_t. Error returned will depend on platform
* specific implementation. API expects ADIHAL_OK if function completed successfully.
* Any other value represents an error or warning to the API. Error return list
* below provides possible errors from customer implementation.
*
* \pre This function should be used when setting up and configuring the system
*
* <B>Dependencies</B>
* --Application and Platform Specific modules
*
* \param devHalInfo Pointer to Platform HAL defined structure containing
* hardware settings describing the device of interest.
*
* \param halLogLevel The type of message to log.
*
* \retval ADIHAL_OK if function completed successfully.
* \retval ADIHAL_GEN_SW if device references is unknown.
*/
adiHalErr_t ADIHAL_setLogLevel(void *devHalInfo, uint16_t halLogLevel);
/**
* \brief Writes a character array to a log file to facilitate debugging
*
* This function uses the logLevel parameter to specify what type of
* message / warning / error to write to the log file. This function
* uses enums in adiLogLevel_t to set the log level.
*
* The user implementation may choose to allow a feature to filter
* the level of message to log. This could allow only logging errors
* for instance.
*
* Returns an error of type adiHalErr_t. Error returned will depend on platform
* specific implementation. API expects ADIHAL_OK if function completed successfully.
* Any other value represents an error or warning to the API. Error return list
* below provides possible errors from customer implementation.
*
* \pre This function can be used at anytime once the required logging resources
* are opened by the ADIHAL_openHw() function call and not after ADIHAL_closeHW.
* The log level should also be set prior to calling this function via
* ADIHAL_setLogLevel.
*
* <B>Dependencies</B>
* --Application and Platform Specific modules
*
* \param devHalInfo Pointer to Platform HAL defined structure containing
* hardware settings describing the device of interest.
*
* \param logLevel The type of message to log. ADIHAL_LOG_MSG,
* ADIHAL_LOG_WARN, ADIHAL_LOG_ERR, ADIHAL_LOG_SPI,
*
* \param errorCode An error code value to designate a particular error
* \param comment The character array describing the error
*
* \retval ADIHAL_OK if function completed successfully.
* \retval ADIHAL_GEN_SW if device references is unknown.
* \retval ADIHAL_WARNING if log message cannot be completed
*/
adiHalErr_t ADIHAL_writeToLog(void *devHalInfo, adiLogLevel_t logLevel, uint32_t errorCode, const char *comment);
#ifdef __cplusplus
}
#endif
#endif
Binary file not shown.
+21
View File
@@ -0,0 +1,21 @@
ADIHALLIB = adihallib.a
CC = gcc
ARFLAGS = -rv
CFLAGS = -Wall -Werror -pedantic -I.
EXT = c
SRC = adi_hal.$(EXT)
OBJS = $(SRC:.$(EXT)=.o)
.c.o:
$(CC) $(CFLAGS) -c $<
$(ADIHALLIB): $(OBJS)
ar $(ARFLAGS) $(ADIHALLIB) $(OBJS)
$(OBJS): ./adi_hal.h
clean:
rm *.o
rm *.a