您的位置:首页 > 房产 > 建筑 > 在公司的一些笔记

在公司的一些笔记

2024/12/23 5:16:03 来源:https://blog.csdn.net/qq_43448818/article/details/139804095  浏览:    关键词:在公司的一些笔记

6.19

  1. 记住挂载在windows上的账户是DAHUATECH\401593,不是401593
  2. Windows与linux不能同时挂载在虚拟盘上

6.21

/*******************************************************************************
pdc_ledSy7806e.c*
* Description: 提供I2C访问sy7806e。
*
*       1.  硬件说明。
*
*       2.  程序结构说明。
*
*       3.  使用说明。
*
*       4.  局限性说明。
*           ……
*       5.  其他说明。
*            ……
*
* Modification:
*    Date    : 2023-12-11
*    Revision:
*    Author  :
*    Contents:
*******************************************************************************//* ========================================================================== */
/*                              头文件区                                      */
/* ========================================================================== */#include "osa.h"
#include "prc.h"
#include "pdc.h"
#include "pdc_priv.h"
#include "pdc_ledI2cpriv.h"
#include "pdc_ledSy7806e.h"static Uint32 value_1 = 0x0;
/* ========================================================================== */
/*                          函数声明区                                        */
/* ========================================================================== *//* ========================================================================== */
/*                          全局变量定义区                                    */
/* ========================================================================== *//* Pca9534控制结构体 */
typedef struct
{OSA_MutexHandle     hLock;
} Sy7806e_Obj;Int32 LED_sy7806eI2cRead(PRC_I2cDevHandle hI2cDev, Uint32 addr, Uint32 *value)
{PRC_I2cXferParams xferParams[2];Uint8 txbuf[1];Uint8 rxbuf[1];txbuf[0] = addr;if (NULL == value){return OSA_EFAIL;}xferParams[0].pBuffer  = txbuf;xferParams[0].bufLen   = 1;xferParams[0].flags    = 0;xferParams[0].dataBits = 8;xferParams[0].timeout  = 1000;xferParams[1].pBuffer  = rxbuf;xferParams[1].bufLen   = 1;xferParams[1].flags    = PRC_I2C_RD;xferParams[1].dataBits = 8;xferParams[1].timeout  = 1000;if (OSA_isNull(hI2cDev)){   OSA_DEBUG("SY7806E_READ hi2cDev is NULL\n");return OSA_EFAIL;}if (PRC_i2cTransfer(hI2cDev, xferParams, 2) < 0){OSA_ERROR("Fail to read\n");return OSA_EFAIL;}else{OSA_memCpySize(value, rxbuf, sizeof(rxbuf));}return OSA_SOK;
}Int32 LED_sy7806eI2cWrite(PRC_I2cDevHandle hI2cDev, Uint32 addr, Uint32 value)
{PRC_I2cXferParams xferParams;Uint8 txbuf[2];txbuf[0] = addr;txbuf[1] = value;xferParams.pBuffer  = txbuf;xferParams.bufLen   = 2;xferParams.flags    = 0;xferParams.dataBits = 8;xferParams.timeout  = 1000;if (PRC_i2cTransfer(hI2cDev, &xferParams, 1) < 0){OSA_ERROR("Fail to write\n");return OSA_EFAIL;}return OSA_SOK;
}
/*******************************************************************************
*  函数名   : CE_MCUI2C_i2cInit
*  描  述   : 初始化I2C通讯
*  输  入   : -pstObj  :   MCUI2C_ObjModule对象
*  输  出   : 无。
*  返回值   : OSA_SOK   :   成功OSA_EFAIL :   失败
*******************************************************************************/Int32 LED_sy7806eI2cInit(PRC_I2cDevHandle hI2cDev)
{Int32 status = 0;if(!hI2cDev){OSA_ERROR("LED_sy7806eI2cInit error, hI2cDev is null\n");return OSA_EFAIL;}value_1 = 0xa0;return OSA_SOK;}/*******************************************************************************
*  函数名   : CE_MCUI2C_i2cInit
*  描  述   : 初始化I2C通讯
*  输  入   : -pstObj  :   MCUI2C_ObjModule对象
*  输  出   : 无。
*  返回值   : OSA_SOK   :   成功OSA_EFAIL :   失败
*******************************************************************************/
Int32 LED_sy7806eI2cSetState(PRC_I2cDevHandle hI2cDev, PDC_LedSetParams *pLedParams)
{static Int32 tempcode = 0;//一次初始化
/*出现连续两条相同命令时不需要进行操作,tempcode不需要更新*/if (pLedParams->code == tempcode){return OSA_SOK;}#define ILL_SUM 168Int32 status = 0;Int32 pValue = 0;if((!hI2cDev) || (!pLedParams)){OSA_ERROR("LED_sy7806eI2cSetState error, hI2cDev or pLedParams is null\n");}// LED_sy7806eI2cRead(hI2cDev, 0x4, &pValue);//中间态过渡,不能直接设置灯的模式不然灯反应过慢pValue = pValue & ~(0x3 << 2);//2.3.0pValue = pValue | (0x2 << 2);//3.1pValue = pValue & ~(0x1 << 5);//5.0pValue = pValue | (0x0 << 5);//4.0pValue &= !0x3;  //   0.1.0LED_sy7806eI2cWrite(hI2cDev, 0x1, pValue); //使能寄存器/*频闪使用IR模式*/if(pLedParams->state == LED_STATE_ON) //常亮的预设值{value_1 = value_1 & ~(0x3 << 2);//2.3 0value_1 = value_1 | (0x2 << 2);//3 1value_1 = value_1 & ~(0x1 << 5);//5 0value_1 = value_1 | (0x0 << 5);}else if(pLedParams->state == LED_STATE_FLASH)//频闪预设置{value_1 = value_1 & ~(0x3 << 2); // IR modevalue_1 = value_1 | (0x1 << 2); //2 1  ???value_1 = value_1 & ~(0x1 << 5);// 5 0value_1 = value_1 | (0x1 << 5);//5 1}switch (pLedParams->code)//亮度的设置{case LED_White_left_I2C:case LED_Red_left_I2C:if(!pLedParams->illuminance || LED_STATE_OFF == pLedParams->state)//亮度为0,灯状态为0{value_1 = value_1 & ~(0x1 << 0);//关LED1}else//灯亮{value_1 = value_1 | (0x1 << 0);//开LED1if(LED_STATE_FLASH == pLedParams->state){LED_sy7806eI2cRead(hI2cDev, 0x4, &pValue);//读取LED2频闪值/*频闪的时候LED1+LED2电流不能过大*/if((pValue&0x7f) + (pLedParams->illuminance&0x7f) >= ILL_SUM)  //2000mA / 11.725  - 2 = 168 {pLedParams->illuminance = ILL_SUM - (pValue&0x7f);}LED_sy7806eI2cWrite(hI2cDev, 0x3, pLedParams->illuminance);//LED1 频闪}else if(LED_STATE_ON == pLedParams->state){LED_sy7806eI2cWrite(hI2cDev, 0x5, pLedParams->illuminance);//控制LED1常亮模式的亮度}}break;case LED_White_right_I2C:case LED_Red_right_I2C:if(!pLedParams->illuminance || LED_STATE_OFF == pLedParams->state)//亮度为0或者关灯{value_1 = value_1 & ~(0x1 << 1);//关LED2}else{value_1 = value_1 | (0x1 << 1);//开LED2/*频闪的时候LED1+LED2电流不能过大*/if(LED_STATE_FLASH == pLedParams->state)//控制LED2频闪模式亮度{LED_sy7806eI2cRead(hI2cDev, 0x3, &pValue); //读取LED1频闪的值if((pValue&0x7f) + (pLedParams->illuminance&0x7f) >= ILL_SUM)  //2000ms / 11.725  - 2 = 168 {pLedParams->illuminance = ILL_SUM - (pValue&0x7f);}LED_sy7806eI2cWrite(hI2cDev, 0x4, pLedParams->illuminance);}else if(LED_STATE_ON == pLedParams->state)//控制LED2常亮模式亮度{LED_sy7806eI2cWrite(hI2cDev, 0x6, pLedParams->illuminance);}}break;default:break;};LED_sy7806eI2cWrite(hI2cDev, 0x1, value_1);  //模式的设置tempcode = pLedParams->code ;//存放上一条执行过的命令,tempcode更新return OSA_SOK;}
/*******************************************************************************
*  函数名   : CE_MCUI2C_i2cDeinit
*  描  述   : 反初始化I2C通讯
*  输  入   : -pstObj  :   MCUI2C_ObjModule对象
*  输  出   : 无。
*  返回值   : OSA_SOK   :   成功OSA_EFAIL :   失败
*******************************************************************************/
Int32 LED_sy7806eI2cDeInit(PRC_I2cDevHandle hI2cDev)
{LED_sy7806eI2cWrite(hI2cDev, 0x1, 0x80);return OSA_SOK;
}

6.21 

1、打包

2、环境的

3、设置输出

set light 命令

set light 0 2 100        id:模式 (0:关 1亮  2:频闪) 亮度


测试流程

1、先将代码写好,记得写打印

2、编译,编译后生成ko文件,在目录Z:\xzj\PDC\Trunk\bin\ambacv28


3、打包
将生成的文件移动到  Z:\xzj\Pack_cv28\Images\user_cv28\lib\modules
另外还缺少库文件 可以看图片中的日期,除了pdc.ko外还有很多文件
使用打包命令,会在打包程序中生成图片中的文件包

4、使用tftp传输bin文件到相机中
看图片中的设置

使用一个网卡连接到相机,将网卡的ip设置成192.168.100

使用tftp将打包后的镜像文件传输到相机中
5、使用命令set 对相机进行操作


 

/*******************************************************************************
pdc_ledSy7806e.c*
* Description: 提供I2C访问sy7806e。
*
*       1.  硬件说明。
*
*       2.  程序结构说明。
*
*       3.  使用说明。
*
*       4.  局限性说明。
*           ……
*       5.  其他说明。
*            ……
*
* Modification:
*    Date    : 2023-12-11
*    Revision:
*    Author  :
*    Contents:
*******************************************************************************//* ========================================================================== */
/*                              头文件区                                      */
/* ========================================================================== */#include "osa.h"
#include "prc.h"
#include "pdc.h"
#include "pdc_priv.h"
#include "pdc_ledI2cpriv.h"
#include "pdc_ledSy7806e.h"static Uint32 value_1 = 0x0;
/* ========================================================================== */
/*                          函数声明区                                        */
/* ========================================================================== *//* ========================================================================== */
/*                          全局变量定义区                                    */
/* ========================================================================== *//* Pca9534控制结构体 */
typedef struct
{OSA_MutexHandle     hLock;
} Sy7806e_Obj;Int32 LED_sy7806eI2cRead(PRC_I2cDevHandle hI2cDev, Uint32 addr, Uint32 *value)
{PRC_I2cXferParams xferParams[2];Uint8 txbuf[1];Uint8 rxbuf[1];txbuf[0] = addr;if (NULL == value){return OSA_EFAIL;}xferParams[0].pBuffer  = txbuf;xferParams[0].bufLen   = 1;xferParams[0].flags    = 0;xferParams[0].dataBits = 8;xferParams[0].timeout  = 1000;xferParams[1].pBuffer  = rxbuf;xferParams[1].bufLen   = 1;xferParams[1].flags    = PRC_I2C_RD;xferParams[1].dataBits = 8;xferParams[1].timeout  = 1000;if (OSA_isNull(hI2cDev)){   OSA_DEBUG("SY7806E_READ hi2cDev is NULL\n");return OSA_EFAIL;}if (PRC_i2cTransfer(hI2cDev, xferParams, 2) < 0){OSA_ERROR("Fail to read\n");return OSA_EFAIL;}else{OSA_memCpySize(value, rxbuf, sizeof(rxbuf));}return OSA_SOK;
}Int32 LED_sy7806eI2cWrite(PRC_I2cDevHandle hI2cDev, Uint32 addr, Uint32 value)
{PRC_I2cXferParams xferParams;Uint8 txbuf[2];txbuf[0] = addr;txbuf[1] = value;xferParams.pBuffer  = txbuf;xferParams.bufLen   = 2;xferParams.flags    = 0;xferParams.dataBits = 8;xferParams.timeout  = 1000;if (PRC_i2cTransfer(hI2cDev, &xferParams, 1) < 0){OSA_ERROR("Fail to write\n");return OSA_EFAIL;}return OSA_SOK;
}
/*******************************************************************************
*  函数名   : CE_MCUI2C_i2cInit
*  描  述   : 初始化I2C通讯
*  输  入   : -pstObj  :   MCUI2C_ObjModule对象
*  输  出   : 无。
*  返回值   : OSA_SOK   :   成功OSA_EFAIL :   失败
*******************************************************************************/Int32 LED_sy7806eI2cInit(PRC_I2cDevHandle hI2cDev)
{Int32 status = 0;if(!hI2cDev){OSA_ERROR("LED_sy7806eI2cInit error, hI2cDev is null\n");return OSA_EFAIL;}value_1 = 0xa0;return OSA_SOK;}/*******************************************************************************
*  函数名   : CE_MCUI2C_i2cInit
*  描  述   : 初始化I2C通讯
*  输  入   : -pstObj  :   MCUI2C_ObjModule对象
*  输  出   : 无。
*  返回值   : OSA_SOK   :   成功OSA_EFAIL :   失败
*******************************************************************************/
Int32 LED_sy7806eI2cSetState(PRC_I2cDevHandle hI2cDev, PDC_LedSetParams *pLedParams)
{static Int32 tempcode = 0;//一次初始化
/*出现连续两条相同命令时不需要进行操作,tempcode不需要更新*/if (pLedParams->code == tempcode){return OSA_SOK;}#define ILL_SUM 168Int32 status = 0;Int32 pValue = 0;if((!hI2cDev) || (!pLedParams)){OSA_ERROR("LED_sy7806eI2cSetState error, hI2cDev or pLedParams is null\n");}// LED_sy7806eI2cRead(hI2cDev, 0x4, &pValue);//中间态过渡,不能直接设置灯的模式不然灯反应过慢pValue = pValue & ~(0x3 << 2);//2.3.0pValue = pValue | (0x2 << 2);//3.1pValue = pValue & ~(0x1 << 5);//5.0pValue = pValue | (0x0 << 5);//4.0pValue &= !0x3;  //   0.1.0LED_sy7806eI2cWrite(hI2cDev, 0x1, pValue); //使能寄存器/*频闪使用IR模式*/if(pLedParams->state == LED_STATE_ON) //常亮的预设值{value_1 = value_1 & ~(0x3 << 2);//2.3 0value_1 = value_1 | (0x2 << 2);//3 1value_1 = value_1 & ~(0x1 << 5);//5 0value_1 = value_1 | (0x0 << 5);}else if(pLedParams->state == LED_STATE_FLASH)//频闪预设置{value_1 = value_1 & ~(0x3 << 2); // IR modevalue_1 = value_1 | (0x1 << 2); //2 1  ???value_1 = value_1 & ~(0x1 << 5);// 5 0value_1 = value_1 | (0x1 << 5);//5 1}switch (pLedParams->code)//模式设置{case LED_White_left_I2C:case LED_Red_left_I2C:if(!pLedParams->illuminance || LED_STATE_OFF == pLedParams->state)//亮度为0,灯状态为0{value_1 = value_1 & ~(0x1 << 0);//关LED1}else//灯亮{value_1 = value_1 | (0x1 << 0);//开LED1if(LED_STATE_FLASH == pLedParams->state){LED_sy7806eI2cRead(hI2cDev, 0x4, &pValue);//读取LED2频闪值/*频闪的时候LED1+LED2电流不能过大*/if((pValue&0x7f) + (pLedParams->illuminance&0x7f) >= ILL_SUM)  //2000mA / 11.725  - 2 = 168 {pLedParams->illuminance = ILL_SUM - (pValue&0x7f);}LED_sy7806eI2cWrite(hI2cDev, 0x3, pLedParams->illuminance);//LED1 频闪}else if(LED_STATE_ON == pLedParams->state){LED_sy7806eI2cWrite(hI2cDev, 0x5, pLedParams->illuminance);//控制LED1常亮模式的亮度}}break;case LED_White_right_I2C:case LED_Red_right_I2C:if(!pLedParams->illuminance || LED_STATE_OFF == pLedParams->state)//亮度为0或者关灯{value_1 = value_1 & ~(0x1 << 1);//关LED2}else{value_1 = value_1 | (0x1 << 1);//开LED2/*频闪的时候LED1+LED2电流不能过大*/if(LED_STATE_FLASH == pLedParams->state)//控制LED2频闪模式亮度{LED_sy7806eI2cRead(hI2cDev, 0x3, &pValue); //读取LED1频闪的值if((pValue&0x7f) + (pLedParams->illuminance&0x7f) >= ILL_SUM)  //2000ms / 11.725  - 2 = 168 {pLedParams->illuminance = ILL_SUM - (pValue&0x7f);}LED_sy7806eI2cWrite(hI2cDev, 0x4, pLedParams->illuminance);}else if(LED_STATE_ON == pLedParams->state)//控制LED2常亮模式亮度{LED_sy7806eI2cWrite(hI2cDev, 0x6, pLedParams->illuminance);}}break;default:break;};LED_sy7806eI2cWrite(hI2cDev, 0x1, value_1);tempcode = pLedParams->code ;//存放上一条执行过的命令,tempcode更新return OSA_SOK;}
/*******************************************************************************
*  函数名   : CE_MCUI2C_i2cDeinit
*  描  述   : 反初始化I2C通讯
*  输  入   : -pstObj  :   MCUI2C_ObjModule对象
*  输  出   : 无。
*  返回值   : OSA_SOK   :   成功OSA_EFAIL :   失败
*******************************************************************************/
Int32 LED_sy7806eI2cDeInit(PRC_I2cDevHandle hI2cDev)
{LED_sy7806eI2cWrite(hI2cDev, 0x1, 0x80);return OSA_SOK;
}
/*******************************************************************************
* pdc_led.c
*
* Copyright (C) 2011-2013 ZheJiang Dahua Technology CO.,LTD.
*
* Author : Huang Zhendi <huang_zhendi@dahuatech.com>
*          Yang Zhiqiang <yang_zhiqiang@dahuatech.com>
* Version: V1.0.0  2012-05-21 Create
*
* Description: 提供设备中LED控制功能
*       1.  硬件说明。
*           提供LED控制功能
*
*       2.  程序结构说明。
*           通过字符设备PDC_MISC_NAME的ioctl命令与应用通信。
*
*       3.  使用说明。
*           应用字符设备PDC_MISC_NAME的ioctl命令读写告警。
*
*       4.  局限性说明。
*           ……
*       5.  其他说明。
*            ……
* Modification:
*    Date    : 2012.10.26
*    Revision:
*    Author  : huang_zhendi
*    Contents:
*******************************************************************************//* ========================================================================== */
/*                              头文件区                                      */
/* ========================================================================== */#include "osa.h"
#include "prc.h"
#include "pdc_priv.h"/* ========================================================================== */
/*                           宏和类型定义区                                   */
/* ========================================================================== */#define LED_TURN_CYCLES  100    /* LED灯状态查询周期,单位是毫秒。*//* ========================================================================== */
/*                          数据结构定义区                                    */
/* ========================================================================== */typedef struct
{Uint16 turnType;        /* LED灯亮灯模式: 0-不闪烁 1-闪烁 *//* 以下参数在LED为闪烁时有效 *//* 记录LED灯亮灯时的状态,双色灯,1-绿色,2-黄色,3-红色; 单色灯: 1*/Uint16 state;Uint16 currState;       /* LED灯当前状态 0-灭 1-亮 */Uint16 reserved;Uint32 turnOnTime;      /* 闪烁时的亮灯时间 */Uint32 turnOffTime;     /* 闪烁时的灭灯时间 */Uint32 remainTime;      /* 闪灯剩余时间 */
} LED_State;/* LED控制结构体 */
typedef struct
{Uint32              ledCfgNum;   /* LED灯配置个数 */PDC_LedCfg         *pLedCfg;     /* 指向LED灯控制配置。*/LED_State          *pLedState;   /* 保存定时器状态数组 */OSA_ThrHandle       hLedCheckThr;         /* LED灯亮灭查询控制线程句柄 */OSA_MutexHandle     hLedMutex;   /* 保护Led灯信息MISC_GpioInfo->pLedCfg */Uint32              flashLightNum;PRC_PwmHandle       hPwm[PDC_PWM_MAX];PRC_PwmInitParams   initParams[PDC_PWM_MAX];PRC_DacInitParams   initParams_dac[PDC_DAC_MAX];PRC_I2cDevInitParams initParams_i2c[PDC_I2C_MAX];PRC_I2cDevHandle    hI2c[PDC_I2C_MAX];I2C_LED_CbParams    cbParams[PDC_I2C_MAX];/* 当该标志置1,标志LED已经被强制全部灭掉。 */Uint32              closeAll;
} LED_Obj;/* ========================================================================== */
/*                          函数申明区                                        */
/* ========================================================================== *//* ========================================================================== */
/*                          全局变量定义区                                    */
/* ========================================================================== *//* LED控制结构体 */
static LED_Obj gLedObj;/* ========================================================================== */
/*                          函数定义区                                        */
/* ========================================================================== *//*******************************************************************************
*  函数名   : LED_set
*  描  述   : 设置LED状态
*  输  入   : pLeds: LED灯控制结构体
*             state: 单色灯: 0-关闭, 1-点亮
*                    双色灯: 0-关闭,1-绿色,2-黄色,3-红色
*  输  出   : 无。
*  返回值   : OSA_EFAIL: 失败
*             OSA_SOK  : 成功
*******************************************************************************/
static void LED_set(PDC_LedCfg *pLeds, Uint32 state)
{if (pLeds->ledSetWay >= PDC_LED_SET_WAY_NR){OSA_ERROR("can not support this led set way!\n");return ;}/* 两个管脚均有效,则为双色灯。*/if (pLeds->gpioCfg2 != PDC_CFG_GPIO_INVA){switch (state){case 0:if (pLeds->level == 1){PRC_gpioSetLevel(pLeds->gpioCfg1, 1);PRC_gpioSetLevel(pLeds->gpioCfg2, 1);}else{PRC_gpioSetLevel(pLeds->gpioCfg1, 0);PRC_gpioSetLevel(pLeds->gpioCfg2, 0);}break;case 1:if (pLeds->level == 1){PRC_gpioSetLevel(pLeds->gpioCfg1, 1);PRC_gpioSetLevel(pLeds->gpioCfg2, 0);}else{PRC_gpioSetLevel(pLeds->gpioCfg1, 0);PRC_gpioSetLevel(pLeds->gpioCfg2, 1);}break;case 2:if (pLeds->level == 1){PRC_gpioSetLevel(pLeds->gpioCfg1, 0);PRC_gpioSetLevel(pLeds->gpioCfg2, 0);}else{PRC_gpioSetLevel(pLeds->gpioCfg1, 1);PRC_gpioSetLevel(pLeds->gpioCfg2, 1);}break;case 3:if (pLeds->level == 1){PRC_gpioSetLevel(pLeds->gpioCfg1, 0);PRC_gpioSetLevel(pLeds->gpioCfg2, 1);}else{PRC_gpioSetLevel(pLeds->gpioCfg1, 1);PRC_gpioSetLevel(pLeds->gpioCfg2, 0);}break;default:OSA_ERROR("Invalid LED state\n");break;}}else{OSA_DEBUG("LED:gpioCfg:%d ,gpioCfg1:%d \n" ,pLeds->gpioCfg1, !state);switch (state){case 0:  // 关if (pLeds->level == 1){PRC_gpioSetLevel(pLeds->gpioCfg1, 1);}else{PRC_gpioSetLevel(pLeds->gpioCfg1, 0);}break;case 1: // 开if (pLeds->level == 1){PRC_gpioSetLevel(pLeds->gpioCfg1, 0);}else{PRC_gpioSetLevel(pLeds->gpioCfg1, 1);}break;case 2: // 频闪,直接走turnOn模式break;case 3: // 闪一次if (pLeds->level == 1){PRC_gpioSetLevel(pLeds->gpioCfg1, 0);OSA_msleep(20);PRC_gpioSetLevel(pLeds->gpioCfg1, 1);}else{PRC_gpioSetLevel(pLeds->gpioCfg1, 1);OSA_msleep(20);PRC_gpioSetLevel(pLeds->gpioCfg1, 0);}break;default:OSA_ERROR("Invalid LED state\n");break;}}
}/*******************************************************************************
*  函数名   : LED_flashLightCreate
*  描  述   : 创建并初始化闪光灯的PWM控制设备
*  输  入   : 无。
*  输  出   : 无。
*  返回值   : OSA_EFAIL: 失败
*             OSA_SOK  : 成功
*******************************************************************************/
static Int32 LED_flashLightCreate(void)
{Int32               status;PDC_smartIrCfg      *pSmartIrCfg = NULL;LED_Obj             *pLedObj = &gLedObj;/* 获取SmartIR配置 */status = PDC_cfgGet(PDC_MODULE_SMARTIR, (Ptr *)&pSmartIrCfg);if ( OSA_isFail(status) ){OSA_WARN("Get smartIr cfg failed!\n");return  OSA_EFAIL;}pLedObj->flashLightNum = 0;while ((pSmartIrCfg->smartIrType <= PDC_SMARTIR_NR) && (pSmartIrCfg->smartIrType == PDC_SMARTIR_SOCPWM)){if (PDC_IROWNER_SMARTIR == pSmartIrCfg->lightOwner){pSmartIrCfg++;continue;}/* 将读取的配置写入缓存 */pLedObj->initParams[pLedObj->flashLightNum].pwmId = pSmartIrCfg->typeCfg.socPwmCfg.pwmParms.pwmId;pLedObj->initParams[pLedObj->flashLightNum].mode  = pSmartIrCfg->typeCfg.socPwmCfg.pwmParms.mode;pLedObj->initParams[pLedObj->flashLightNum].activeLevel= pSmartIrCfg->typeCfg.socPwmCfg.pwmParms.activeLevel;/*第一次引用时创建并使能PWM功能 */status = PRC_pwmCreate(&pLedObj->initParams[pLedObj->flashLightNum], &pLedObj->hPwm[pLedObj->flashLightNum]);if (OSA_isFail(status)){OSA_ERROR("Fail to init PWM%d\n", pLedObj->initParams[pLedObj->flashLightNum].pwmId);return  OSA_EFAIL;}status = PRC_pwmDisable(pLedObj->hPwm[pLedObj->flashLightNum]);if(OSA_isFail(status) ){OSA_ERROR("Fail to disable PWM%d.\n", pLedObj->initParams[pLedObj->flashLightNum].pwmId);return  OSA_EFAIL;}OSA_INFOCYAN("flashLight init pwmId: %d,mode: %d,activeLevel: %d\n",pLedObj->initParams[pLedObj->flashLightNum].pwmId,pLedObj->initParams[pLedObj->flashLightNum].mode,pLedObj->initParams[pLedObj->flashLightNum].activeLevel);pLedObj->flashLightNum++;pSmartIrCfg++;}return  OSA_SOK;
}/*******************************************************************************
*  函数名   : LED_DacLightCreate
*  描  述   : 创建并初始化闪光灯的PWM控制设备
*  输  入   : 无。
*  输  出   : 无。
*  返回值   : OSA_EFAIL: 失败
*             OSA_SOK  : 成功
*******************************************************************************/
static Int32 LED_DacLightCreate(void)
{Int32               status;PDC_smartIrCfg      *pSmartIrCfg = NULL;LED_Obj             *pLedObj = &gLedObj;PDC_dacParams pData;/* 获取SmartIR配置 */status = PDC_cfgGet(PDC_MODULE_SMARTIR, (Ptr *)&pSmartIrCfg);if ( OSA_isFail(status) ){OSA_WARN("Get smartIr cfg failed!\n");return  OSA_EFAIL;}pLedObj->flashLightNum = 0;while (pSmartIrCfg->smartIrType < PDC_SMARTIR_NR){if (PDC_IROWNER_SMARTIR == pSmartIrCfg->lightOwner){pSmartIrCfg++;continue;}// 将读取的配置写入缓存pLedObj->initParams_dac[pLedObj->flashLightNum].chipId = pSmartIrCfg->typeCfg.dacIrCfg.chipId;pLedObj->initParams_dac[pLedObj->flashLightNum].channel  = pSmartIrCfg->typeCfg.dacIrCfg.channel;pLedObj->initParams_dac[pLedObj->flashLightNum].value= pSmartIrCfg->typeCfg.dacIrCfg.activeLevel;pData.chn=pLedObj->initParams_dac[pLedObj->flashLightNum].channel;pData.data=0;//status = PDC_dacOutput(pLedObj->initParams_dac[pLedObj->flashLightNum].chipId,&pData);OSA_INFOCYAN("DacLight init chipId: %d,channel: %d,activeLevel: %d\n",pLedObj->initParams_dac[pLedObj->flashLightNum].chipId,pLedObj->initParams_dac[pLedObj->flashLightNum].channel,pLedObj->initParams_dac[pLedObj->flashLightNum].value);pLedObj->flashLightNum++;pSmartIrCfg++;}return  OSA_SOK;
}Int32 PDC_i2cDevRegister(Uint32 ledDevId, I2C_LED_CbParams *pParams)
{OSA_INFO("PDC_i2cDevRegister: ledDevId = %d\n", ledDevId);if (OSA_isNull(pParams)){OSA_ERROR("Null cfg params!\n");return OSA_EFAIL;}switch (ledDevId){case PDC_SY7806E:pParams->LED_i2cInit   = LED_sy7806eI2cInit;pParams->LED_i2cSetState   = LED_sy7806eI2cSetState;pParams->LED_i2cDeInit = LED_sy7806eI2cDeInit;OSA_INFO("LED device is SY7806E\n");break;default:OSA_ERROR("No suitable LED device, ledDevId=%d\n", ledDevId);return OSA_EFAIL;}return OSA_SOK;
}/*******************************************************************************
*  函数名   : LED_I2cLightCreate
*  描  述   : 创建并初始化闪光灯的I2C控制设备
*  输  入   : 无。
*  输  出   : 无。
*  返回值   : OSA_EFAIL: 失败
*             OSA_SOK  : 成功
*******************************************************************************/
static Int32 LED_I2cLightCreate(void)
{Int32               status;PDC_smartIrCfg      *pSmartIrCfg = NULL;LED_Obj             *pLedObj = &gLedObj;PRC_I2cDevInitParams *i2cInitParams;PRC_I2cDevHandle    *phI2c;PRC_GpioParams      param;/* 获取SmartIR配置 */status = PDC_cfgGet(PDC_MODULE_SMARTIR, (Ptr *)&pSmartIrCfg);if ( OSA_isFail(status) ){OSA_WARN("Get smartIr cfg failed!\n");return  OSA_EFAIL;}pLedObj->flashLightNum = 0;while (pSmartIrCfg->smartIrType < PDC_SMARTIR_NR){if (PDC_IROWNER_SMARTIR == pSmartIrCfg->lightOwner){pSmartIrCfg++;continue;}// 将读取的配置写入缓存pLedObj->initParams_i2c[pLedObj->flashLightNum].busId = pSmartIrCfg->typeCfg.i2cIrCfg.busId;pLedObj->initParams_i2c[pLedObj->flashLightNum].opMode  = pSmartIrCfg->typeCfg.i2cIrCfg.opMode;pLedObj->initParams_i2c[pLedObj->flashLightNum].address= pSmartIrCfg->typeCfg.i2cIrCfg.address;i2cInitParams = &pLedObj->initParams_i2c[pLedObj->flashLightNum];phI2c = &pLedObj->hI2c[pLedObj->flashLightNum];if (PRC_i2cDevCreate(i2cInitParams, phI2c) < 0){OSA_ERROR("Fail to init I2C%d Device%d\n", i2cInitParams->busId, i2cInitParams->address);return OSA_EFAIL;}OSA_memSet(&param, 0, sizeof(PRC_GpioParams));param.dir = PRC_GPIO_DIR_OUT;param.mode = PDC_cfgGetGpioMode(pSmartIrCfg->typeCfg.i2cIrCfg.engpio);PRC_gpioGetPin(pSmartIrCfg->typeCfg.i2cIrCfg.engpio, &param);PRC_gpioSetLevel(pSmartIrCfg->typeCfg.i2cIrCfg.engpio, pSmartIrCfg->typeCfg.i2cIrCfg.enlevel);OSA_INFOCYAN("I2cLight init busId: %d,opMode: %d,address: 0x%x\n",pLedObj->initParams_i2c[pLedObj->flashLightNum].busId,pLedObj->initParams_i2c[pLedObj->flashLightNum].opMode,pLedObj->initParams_i2c[pLedObj->flashLightNum].address);status = PDC_i2cDevRegister(pSmartIrCfg->typeCfg.i2cIrCfg.address, &pLedObj->cbParams[pLedObj->flashLightNum]);if(status == OSA_SOK){if(pLedObj->cbParams[pLedObj->flashLightNum].LED_i2cInit)pLedObj->cbParams[pLedObj->flashLightNum].LED_i2cInit(*phI2c);elsereturn OSA_EFAIL;}else{PRC_i2cDevDelete(*phI2c);OSA_ERROR("Fail to regist Device 0x%x\n", pSmartIrCfg->typeCfg.i2cIrCfg.address);return OSA_EFAIL;}pLedObj->flashLightNum++;pSmartIrCfg++;}return  OSA_SOK;}/*******************************************************************************
*  函数名   : LED_flashLightRelease
*  描  述   : 释放闪光灯的PWM控制设备
*  输  入   : 无。
*  输  出   : 无。
*  返回值   : OSA_EFAIL: 失败
*             OSA_SOK  : 成功
*******************************************************************************/
static Int32 LED_flashLightRelease(void)
{Int32       status = OSA_SOK;LED_Obj     *pLedObj = &gLedObj;Uint32      i;for (i = 0; i < pLedObj->flashLightNum; i++){/*最后一次引用删除时,disable掉PWM接口,并删除PWM控制器*/status = PRC_pwmDisable(pLedObj->hPwm[i]);if( OSA_isFail(status) ){OSA_ERROR("Fail to disable PWM%d.\n",pLedObj->initParams[i].pwmId);return  OSA_SOK;}status = PRC_pwmDelete(pLedObj->hPwm[i]);if( OSA_isFail(status) ){OSA_ERROR("Fail to delete PWM%d !\n",pLedObj->initParams[i].pwmId);return  OSA_EFAIL;}}return  OSA_SOK;
}/*******************************************************************************
*  函数名   : LED_DacLightRelease
*  描  述   : 释放闪光灯的PWM控制设备
*  输  入   : 无。
*  输  出   : 无。
*  返回值   : OSA_EFAIL: 失败
*             OSA_SOK  : 成功
*******************************************************************************/
static Int32 LED_DacLightRelease(void)
{Int32       status = OSA_SOK;LED_Obj     *pLedObj = &gLedObj;Uint32      i;PDC_dacParams pData;for (i = 0; i < pLedObj->flashLightNum; i++){pData.chn=pLedObj->initParams_dac[pLedObj->flashLightNum].channel;pData.data=0;status = PDC_dacOutput(pLedObj->initParams_dac[pLedObj->flashLightNum].chipId,&pData);OSA_INFOCYAN("DacLight init chipId: %d,mode: %d,activeLevel: %d\n",pLedObj->initParams_dac[pLedObj->flashLightNum].chipId,pLedObj->initParams_dac[pLedObj->flashLightNum].channel,pLedObj->initParams_dac[pLedObj->flashLightNum].value);}return  OSA_SOK;
}/*******************************************************************************
*  函数名   : LED_I2cLightRelease
*  描  述   : 释放闪光灯的I2C控制设备
*  输  入   : 无。
*  输  出   : 无。
*  返回值   : OSA_EFAIL: 失败
*             OSA_SOK  : 成功
*******************************************************************************/
static Int32 LED_I2cLightRelease(void)
{Int32       status = OSA_SOK;LED_Obj     *pLedObj = &gLedObj;Uint32      i;PRC_I2cDevHandle    *phI2c;for (i = 0; i < pLedObj->flashLightNum; i++){phI2c = &pLedObj->hI2c[pLedObj->flashLightNum];if(pLedObj->cbParams[pLedObj->flashLightNum].LED_i2cDeInit)pLedObj->cbParams[pLedObj->flashLightNum].LED_i2cDeInit(*phI2c);PRC_i2cDevDelete(*phI2c);OSA_INFOCYAN("DacLight init chipId: %d,mode: %d,activeLevel: %d\n",pLedObj->initParams_dac[pLedObj->flashLightNum].chipId,pLedObj->initParams_dac[pLedObj->flashLightNum].channel,pLedObj->initParams_dac[pLedObj->flashLightNum].value);}return  OSA_SOK;
}/*******************************************************************************
*  函数名   : LED_set
*  描  述   : 设置LED状态
*  输  入   : freq: 频率,详细见prc_pwm.h中相关接口定义
*             dutyRation: 占空比,详细见prc_pwm.h中相关接口定义
*  输  出   : 无。
*  返回值   : OSA_EFAIL: 失败
*             OSA_SOK  : 成功
*******************************************************************************/
static Int32 LED_flashLightSetState(Uint32 id, Uint32 freq, Uint32 dutyRation)
{Int32       status = OSA_SOK;LED_Obj     *pLedObj = &gLedObj;OSA_DEBUG("LED_flashLightSetState id %d, freq %d, dutyRation %d\n", id, freq, dutyRation);if(pLedObj->initParams[id].activeLevel == 0){dutyRation = 10000 - dutyRation;}if (0 == freq){freq = 10000;}status = PRC_pwmDisable(pLedObj->hPwm[id]);if(OSA_isFail(status) ){OSA_ERROR("Fail to disable PWM%d.\n", pLedObj->initParams[id].pwmId);return OSA_EFAIL;}status = PRC_pwmSetFreq(pLedObj->hPwm[id], freq);if (OSA_isFail(status)){OSA_ERROR("Fail to set PWM%d ,freq%d\n", pLedObj->initParams[id].pwmId,freq);return OSA_EFAIL;}status = PRC_pwmSetDutyRation(pLedObj->hPwm[id], dutyRation);if (OSA_isFail(status)){OSA_ERROR("Fail to set PWM%d, dutyRation%d\n",pLedObj->initParams[id].pwmId,dutyRation);return OSA_EFAIL;}status = PRC_pwmEnable(pLedObj->hPwm[id]);if (OSA_isFail(status)){OSA_ERROR("Fail to Enable PWM%d\n", pLedObj->initParams[id].pwmId);return OSA_EFAIL;}return OSA_SOK;
}/*******************************************************************************
*  函数名   : LED_ledCheckThead
*  描  述   : LED闪烁检查线程
*  输  入   : pUserArgs: 定时器创建时传入的用户参数
*  输  出   : 无。
*  返回值   : OSA_EFAIL: 失败
*             OSA_SOK  : 成功
*******************************************************************************/
static Int32 LED_ledCheckThead(Ptr pUserArgs)
{Uint32      i;LED_Obj     *pLedObj;PDC_LedCfg  *pLedCfgs;LED_State   *pLedState;Uint32      dutyRation = 0;Uint32      dutydiff = 0;pLedObj   = (LED_Obj *)pUserArgs;PDC_smartIrCfg      *pSmartIrCfg = NULL;Int32               status;/* 非SOCpwm模式不启动线程 */status = PDC_cfgGet(PDC_MODULE_SMARTIR, (Ptr *)&pSmartIrCfg);if ( OSA_isSuccess(status) && (pSmartIrCfg->smartIrType == PDC_SMARTIR_DAC88347 || pSmartIrCfg->smartIrType == PDC_SMARTIR_I2C) ){OSA_INFO("Get smartIr cfg is Dac light ,LED_ledCheckThead dirct return!\n");return  OSA_SOK;}while(!OSA_thrShouldStop()){pLedCfgs = pLedObj->pLedCfg;pLedState = pLedObj->pLedState;/* 如果LED有效,并且是闪烁状态 */for (i = 0; i<pLedObj->ledCfgNum; i++){if (pLedObj->closeAll){if ( (pLedCfgs->code > LED_GPIO_TPYE)&& (pLedCfgs->code < LED_PWM_TPYE)) // pwm控制的led{LED_flashLightSetState(pLedCfgs->smartIrIndex, pLedCfgs->frequence, 0);PRC_pwmDisable(pLedObj->hPwm[pLedCfgs->smartIrIndex]);}else{LED_set(pLedCfgs, 0);}}else{if (pLedState->turnType == 1){if (pLedState->currState){if (pLedState->remainTime == 0){pLedState->remainTime = pLedState->turnOffTime;if ( (pLedCfgs->code > LED_GPIO_TPYE)&& (pLedCfgs->code < LED_PWM_TPYE)) // pwm控制的led{LED_flashLightSetState(pLedCfgs->smartIrIndex, pLedCfgs->frequence, 0);PRC_pwmDisable(pLedObj->hPwm[pLedCfgs->smartIrIndex]);}else{LED_set(pLedCfgs, 0);}pLedState->currState = 0;}else{pLedState->remainTime--;}}else{if (pLedState->remainTime == 0){pLedState->remainTime = pLedState->turnOnTime;if ( (pLedCfgs->code > LED_GPIO_TPYE)&& (pLedCfgs->code < LED_PWM_TPYE)) // pwm控制的led{if (pLedState->state >= 100){dutyRation = 10000;}else{dutyRation = pLedState->state * 100;}if(pLedCfgs->highThreshold > pLedCfgs->lowThreshold){dutydiff = pLedCfgs->highThreshold - pLedCfgs->lowThreshold;dutyRation *= dutydiff;dutyRation /= 100;dutyRation += pLedCfgs->lowThreshold * 100;}LED_flashLightSetState(pLedCfgs->smartIrIndex, pLedCfgs->frequence, dutyRation);}else{LED_set(pLedCfgs, pLedState->state);}pLedState->currState = 1;}else{pLedState->remainTime--;}}}}pLedCfgs++;pLedState++;}msleep(100);}return OSA_SOK;
}/*******************************************************************************
*  函数名   : LED_setState
*  描  述   : 设置指定LED灯,目前LED灯低电平有点亮。
*  输  入   : pLedParams: 设置参数。
*  输  出   : 无
*  返回值   : OSA_EFAIL: 失败
*             OSA_SOK  : 成功
*******************************************************************************/
Int32 LED_setState(PDC_LedSetParams *pLedParams)
{Uint32          i,dutyRation;Int32           status;Uint32          dutydiff = 0;Uint32          ledCtr;LED_Obj         *pLedObj;PDC_LedCfg      *pLedCfgs;LED_State       *pLedState;LED_State       *pBackLedState;PDC_LedCfg      *pBackLedCfgs;Int32            SmartirStatus;PDC_smartIrCfg      *pSmartIrCfg = NULL;//Int32 chipId;PDC_dacParams pData;pLedObj         = &gLedObj;/* 获取SmartIR配置 */SmartirStatus = PDC_cfgGet(PDC_MODULE_SMARTIR, (Ptr *)&pSmartIrCfg);OSA_assertNotNull(pLedParams);if (OSA_isNull(pLedParams)){OSA_ERROR("Input params is null!\n");return OSA_EFAIL;}pLedState = pLedObj->pLedState;pLedCfgs  = pLedObj->pLedCfg;pBackLedState = pLedObj->pLedState;pBackLedCfgs  = pLedObj->pLedCfg;OSA_DEBUG("LED:state:%d code:%d\n",pLedParams->state,pLedParams->code);if (pLedObj->closeAll){return OSA_SOK;}/* code为-1时,认为是要关闭所有的LED灯,在reboot时需要关闭所以LED灯 */ if (pLedParams->code == -1){pLedObj->closeAll = 1;return OSA_SOK;}if (pLedParams->code == LED_All)     /* 对所有灯操作 */{for (i = 0; i < pLedObj->ledCfgNum; i++){LED_set(pLedCfgs, (Uint32)pLedParams->state);pLedState->currState = (Uint32)pLedParams->state;pLedState++;pLedCfgs++;}return OSA_SOK;}/* 如果没有成功获取过配置,则ledCfgNum为0,不会进如循环。*/for (i = 0; i < pLedObj->ledCfgNum; i++){if (pLedCfgs->code == pLedParams->code){break;}pLedState++;pLedCfgs++;}/* 没有找到对应的code。*/if (i == pLedObj->ledCfgNum){// TODO: 由于应用目前无法获知LED灯信息,引脚不存在的情况暂时不做错误处理。OSA_DEBUG("The led 0x%x isn't exist !\n",pLedParams->code);return OSA_SOK;}/* 闪烁方式 */if (pLedParams->offCycle || pLedParams->onCycle){pLedState->turnType = 1;pLedState->state = (Uint16)pLedParams->state;pLedState->turnOnTime = pLedParams->onCycle  / LED_TURN_CYCLES;pLedState->turnOffTime = pLedParams->offCycle / LED_TURN_CYCLES;}else{if ( (pLedCfgs->code > LED_GPIO_TPYE)&& (pLedCfgs->code < LED_PWM_TPYE)) // pwm控制的led{pLedState->turnType = 0;if( OSA_isSuccess(SmartirStatus) && pSmartIrCfg->smartIrType == PDC_SMARTIR_DAC88347){/* 闪光灯亮度可调的设备,在pdc层直接操作pwm*/if (0 == pLedParams->state){/*要关闭pwm 先将占空比设置为百分0 再关闭*/pData.chn=pLedObj->initParams_dac[pLedCfgs->smartIrIndex].channel;pData.data=0;status = PDC_dacOutput(pLedObj->initParams_dac[pLedCfgs->smartIrIndex].chipId,&pData);if (OSA_isFail(status)){OSA_ERROR("Fail to PDC_dacOutput 0! DAC CH:%d.\n",pLedObj->initParams_dac[pLedCfgs->smartIrIndex].channel);return OSA_EFAIL;}}else{/* 比列缩小百分之99,以防应用需要比列 */if (pLedParams->state >= 99){dutyRation = 99;}else{dutyRation = pLedParams->state ;}/*由于并不是占空比为0时才不亮 这里做一下web进度条调节到底层的映射*//*若在配置文件中配置了占空比调节范围 那么进行占空比映射*/if(pLedCfgs->highThreshold > pLedCfgs->lowThreshold){dutydiff = pLedCfgs->highThreshold - pLedCfgs->lowThreshold;dutyRation *= dutydiff;dutyRation /= 100;dutyRation += pLedCfgs->lowThreshold ;}pData.chn=pLedObj->initParams_dac[pLedCfgs->smartIrIndex].channel;pData.data=dutyRation;status = PDC_dacOutput(pLedObj->initParams_dac[pLedCfgs->smartIrIndex].chipId,&pData);if (OSA_isFail(status)){OSA_ERROR("Fail to PDC_dacOutput duty %u! DAC CH:%d.\n",dutyRation, pLedObj->initParams_dac[pLedCfgs->smartIrIndex].channel);return OSA_EFAIL;}return OSA_SOK;}}else{/* 闪光灯亮度可调的设备,在pdc层直接操作pwm*/if (0 == pLedParams->state){/*要关闭pwm 先将占空比设置为百分0 再关闭*/status = LED_flashLightSetState(pLedCfgs->smartIrIndex, pLedCfgs->frequence, 0);if (OSA_isFail(status)){OSA_ERROR("Fail to LED_flashLightSetState duty 0! PWM%d.\n",pLedObj->initParams[pLedCfgs->smartIrIndex].pwmId);return OSA_EFAIL;}status = PRC_pwmDisable(pLedObj->hPwm[pLedCfgs->smartIrIndex]);if (OSA_isFail(status)){OSA_ERROR("Fail to disable PWM%d.\n",pLedObj->initParams[pLedCfgs->smartIrIndex].pwmId);return OSA_EFAIL;}}else{/* 5000 4路全开到95以上会死机 */if (pLedParams->state >= 90){dutyRation = 9000;}else{dutyRation = pLedParams->state * 100;}/*由于并不是占空比为0时才不亮 这里做一下web进度条调节到底层的映射*//*若在配置文件中配置了占空比调节范围 那么进行占空比映射*/if(pLedCfgs->highThreshold > pLedCfgs->lowThreshold){dutydiff = pLedCfgs->highThreshold - pLedCfgs->lowThreshold;dutyRation *= dutydiff;dutyRation /= 100;dutyRation += pLedCfgs->lowThreshold * 100;}else if(pLedCfgs->highThreshold < pLedCfgs->lowThreshold){dutyRation = 9000 - dutyRation;dutydiff = pLedCfgs->lowThreshold - pLedCfgs->highThreshold;dutyRation *= dutydiff;dutyRation /= 100;dutyRation += pLedCfgs->highThreshold * 100;}status = LED_flashLightSetState(pLedCfgs->smartIrIndex, pLedCfgs->frequence, dutyRation);if (OSA_isFail(status)){OSA_ERROR("Fail to LED_flashLightSetState duty %u! PWM%d.\n",dutyRation, pLedObj->initParams[pLedCfgs->smartIrIndex].pwmId);return OSA_EFAIL;}return OSA_SOK;}}}else if ( (pLedCfgs->code > LED_PWM_TPYE)&& (pLedCfgs->code < LED_I2C_TPYE)) // i2c控制的led{PDC_LedSetParams pLedParam;OSA_memCpySize(&pLedParam, pLedParams, sizeof(PDC_LedSetParams));OSA_INFO("code = %d\n", pLedParams->code);OSA_INFO("state = %d\n", pLedParams->state);OSA_INFO("illuminance = %d\n", pLedParams->illuminance);if (pLedParams->illuminance >= 100){dutyRation = 100;}else{dutyRation = pLedParams->illuminance;}/*由于并不是占空比为0时才不亮 这里做一下web进度条调节到底层的映射*//*若在配置文件中配置了占空比调节范围 那么进行占空比映射*/if((0 !=pLedParams->illuminance) && (pLedCfgs->highThreshold > pLedCfgs->lowThreshold)){dutydiff = pLedCfgs->highThreshold - pLedCfgs->lowThreshold;dutyRation *= dutydiff;dutyRation /= 100;dutyRation += pLedCfgs->lowThreshold ;}pLedParam.illuminance = dutyRation;if(pLedObj->hI2c[pLedCfgs->smartIrIndex] && pLedObj->cbParams[pLedCfgs->smartIrIndex].LED_i2cSetState){pLedObj->cbParams[pLedCfgs->smartIrIndex].LED_i2cSetState(pLedObj->hI2c[pLedCfgs->smartIrIndex], &pLedParam);}}     else{pLedState->turnType = 0;for (i = 0; i < pLedObj->ledCfgNum; i++){if ((NULL == pBackLedState) || (NULL == pBackLedCfgs)){OSA_ERROR("pBackLedState or pBackLedCfgs is null!\n");return OSA_EFAIL;}if ((pBackLedCfgs->ledNum == pLedCfgs->ledNum) &&(pBackLedCfgs->code != pLedCfgs->code)){if ((NULL != pBackLedState) && (pBackLedState->turnType == 1)){pLedState->currState = (Uint16)pLedParams->state;return OSA_SOK;}if ((pLedParams->state == 0) &&(NULL != pBackLedState) &&(pBackLedState->currState == 1)){if (pBackLedCfgs->level){LED_set(pBackLedCfgs, pBackLedState->currState);}else{if (0 == pBackLedState->currState){ledCtr = 1;}else{ledCtr = 0;}LED_set(pBackLedCfgs, ledCtr);}pLedState->currState = (Uint16)pLedParams->state;return OSA_SOK;}}pBackLedState++;pBackLedCfgs++;}
#if 0if (pLedCfgs->level){LED_set(pLedCfgs, (Uint32)pLedParams->state);}else{if (0 == pLedParams->state){ledCtr = 1;}else{ledCtr = 0;}LED_set(pLedCfgs, ledCtr);}
#elseLED_set(pLedCfgs, (Uint32)pLedParams->state);
#endifpLedState->currState = (Uint16)pLedParams->state;}}return OSA_SOK;
}/*******************************************************************************
*  函数名   : LED_getPins
*  描  述   : 获取LED模块所属的GPIO引脚
*  输  入   : pLedObj:  LED灯控制结构体
*             pLedCfgs: LED灯配置信息
*  输  出   : 无。
*  返回值   : OSA_EFAIL: 失败
*             OSA_SOK  : 成功
*******************************************************************************/
static Int32 LED_getPins(LED_Obj *pLedObj, PDC_LedCfg *pLedCfgs)
{Int32               status;Int32               SmartirStatus;PDC_LedCfg          *pLedCfgsNew;PRC_GpioParams      param;Uint32              init = 1;PDC_smartIrCfg      *pSmartIrCfg = NULL;/* 获取SmartIR配置 */SmartirStatus = PDC_cfgGet(PDC_MODULE_SMARTIR, (Ptr *)&pSmartIrCfg);/* 申请内存保存配置 */if(pLedObj->ledCfgNum == 0){OSA_ERROR("dev has no led !\n");return OSA_EFAIL;}pLedCfgsNew = OSA_memCalloc(pLedObj->ledCfgNum * sizeof(PDC_LedCfg));if (OSA_isNull(pLedCfgsNew)){OSA_ERROR("Mem alloc failed !\n");return OSA_EFAIL;}pLedObj->pLedCfg = pLedCfgsNew;OSA_clear(&param);param.dir  = PRC_GPIO_DIR_OUT;/* 获取和设置所有的GPIO */while (pLedCfgs->code != LED_INVLIDATE){if( LED_FlashLight == pLedCfgs->code|| (pLedCfgs->code >= LED_White_PWM&& pLedCfgs->code < LED_PWM_TPYE)|| ( (LED_FillInLight == pLedCfgs->code) &&(pLedCfgs->gpioCfg1 == PDC_CFG_GPIO_INVA) &&(pLedCfgs->gpioCfg2 == PDC_CFG_GPIO_INVA))|| ( (LED_InfraredLight == pLedCfgs->code) &&(pLedCfgs->gpioCfg1 == PDC_CFG_GPIO_INVA) &&(pLedCfgs->gpioCfg2 == PDC_CFG_GPIO_INVA))|| (pLedCfgs->code > LED_PWM_TPYE&& pLedCfgs->code < LED_I2C_TPYE)){if (init){if( OSA_isSuccess(SmartirStatus) && (pSmartIrCfg->smartIrType == PDC_SMARTIR_DAC88347) ){status =  LED_DacLightCreate();}else if( OSA_isSuccess(SmartirStatus) && (pSmartIrCfg->smartIrType == PDC_SMARTIR_I2C) ){OSA_INFO("LED_I2cLightCreate\n");status = LED_I2cLightCreate();}/* 有闪光灯的设备,在pdc层直接操作pwm*/else{status =  LED_flashLightCreate();}if (OSA_isFail(status)){return OSA_EFAIL;}init = 0;}pLedCfgsNew->gpioCfg1 = pLedCfgs->gpioCfg1;pLedCfgsNew->gpioCfg2 = pLedCfgs->gpioCfg2;goto next;}/* 转换成GPIO号 */pLedCfgsNew->gpioCfg1= PDC_cfgGetGpioId(pLedCfgs->gpioCfg1);/* 设置LED灯GPIO引脚 */param.mode = PDC_cfgGetGpioMode(pLedCfgs->gpioCfg1);if (pLedCfgs->gpioCfg2 != PDC_CFG_GPIO_INVA){/* 转换成GPIO号 */pLedCfgsNew->gpioCfg2= PDC_cfgGetGpioId(pLedCfgs->gpioCfg2);param.mode = PDC_cfgGetGpioMode(pLedCfgs->gpioCfg2);}else{pLedCfgsNew->gpioCfg2 = PDC_CFG_GPIO_INVA;}if(pLedCfgs->needApply){status = PRC_gpioGetPin(pLedCfgsNew->gpioCfg1, &param);if (OSA_isFail(status)){OSA_ERROR("Get gpio failed %u !\n",pLedCfgsNew->gpioCfg1);goto free_pins;}#if (defined(PLAT_AMBACV2) || defined(PLAT_AMBACV22) || defined(PLAT_AMBACV25) || defined(PLAT_AMBACV28))PRC_gpioSetLevel(pLedCfgsNew->gpioCfg1, 0);
#endifif (pLedCfgs->gpioCfg2 != PDC_CFG_GPIO_INVA){status = PRC_gpioGetPin(pLedCfgsNew->gpioCfg2, &param);if (OSA_isFail(status)){PRC_gpioPutPin(pLedCfgsNew->gpioCfg1);OSA_ERROR("Get gpio %u faild !\n",pLedCfgsNew->gpioCfg2);goto free_pins;}}else   /* 对于单引脚LED灯 上电后点亮 */{if (pLedCfgs->level){PRC_gpioSetLevel(pLedCfgsNew->gpioCfg1, 0);}else{PRC_gpioSetLevel(pLedCfgsNew->gpioCfg1, 1);}if(pLedCfgs->powerOnState) /* 上电后灭掉 */{if (pLedCfgs->level){PRC_gpioSetLevel(pLedCfgsNew->gpioCfg1, 1);}else{PRC_gpioSetLevel(pLedCfgsNew->gpioCfg1, 0);}}}}
next:pLedCfgsNew->code = pLedCfgs->code;pLedCfgsNew->level= pLedCfgs->level;pLedCfgsNew->needApply= pLedCfgs->needApply;pLedCfgsNew->ledNum   = pLedCfgs->ledNum;pLedCfgsNew->ledSetWay = pLedCfgs->ledSetWay;pLedCfgsNew->lowThreshold = pLedCfgs->lowThreshold;pLedCfgsNew->highThreshold = pLedCfgs->highThreshold;pLedCfgsNew->smartIrIndex  = pLedCfgs->smartIrIndex;pLedCfgsNew->frequence  = pLedCfgs->frequence;pLedCfgs++;pLedCfgsNew++;}return OSA_SOK;free_pins:while(pLedCfgsNew != pLedObj->pLedCfg){PRC_gpioPutPin(pLedCfgsNew->gpioCfg1);if (pLedCfgs->gpioCfg2 != PDC_CFG_GPIO_INVA){PRC_gpioPutPin(pLedCfgsNew->gpioCfg2);}}OSA_memFree(pLedObj->pLedCfg);return OSA_EFAIL;
}/*******************************************************************************
*  函数名   : LED_putPins
*  描  述   : 释放LED模块所属的GPIO引脚
*  输  入   : pLedObj:  LED灯控制结构体
*  输  出   : 无。
*  返回值   : OSA_EFAIL: 失败
*             OSA_SOK  : 成功
*******************************************************************************/
static Int32 LED_putPins(LED_Obj *pLedObj)
{Uint32          i;Int32           status = OSA_SOK;Int32           SmartirStatus=OSA_SOK;PDC_LedCfg      *pLedCfg;pLedCfg = pLedObj->pLedCfg;PDC_smartIrCfg      *pSmartIrCfg = NULL;/* 获取SmartIR配置 */SmartirStatus = PDC_cfgGet(PDC_MODULE_SMARTIR, (Ptr *)&pSmartIrCfg);for (i = 0; i < pLedObj->ledCfgNum; i++){if( LED_FlashLight == pLedCfg->code ||( (LED_FillInLight == pLedCfg->code) &&(pLedCfg->gpioCfg1 == PDC_CFG_GPIO_INVA) &&(pLedCfg->gpioCfg2 == PDC_CFG_GPIO_INVA))||( (LED_InfraredLight == pLedCfg->code) &&(pLedCfg->gpioCfg1 == PDC_CFG_GPIO_INVA) &&(pLedCfg->gpioCfg2 == PDC_CFG_GPIO_INVA))){if( OSA_isSuccess(SmartirStatus) && (pSmartIrCfg->smartIrType == PDC_SMARTIR_DAC88347) ){LED_DacLightRelease();}else if( OSA_isSuccess(SmartirStatus) && (pSmartIrCfg->smartIrType == PDC_SMARTIR_I2C) ){status = LED_I2cLightRelease();}else{LED_flashLightRelease();}continue;}status |= PRC_gpioPutPin(pLedCfg->gpioCfg1);if (pLedCfg->gpioCfg2 != PDC_CFG_GPIO_INVA){status |= PRC_gpioPutPin(pLedCfg->gpioCfg2);}pLedCfg++;}status |= OSA_memFree(pLedObj->pLedCfg);return status;
}/*******************************************************************************
*  函数名   : PDC_ledInit
*  描  述   : LED模块加载函数
*  输  入   : 无。
*  输  出   : 无。
*  返回值   : OSA_EFAIL: 失败
*             OSA_SOK  : 成功
*******************************************************************************/
Int32 __init PDC_ledInit(void)
{Int32               status;Uint32              count = 0;LED_Obj            *pLedObj = &gLedObj;LED_State          *pLedState;PDC_LedCfg         *pLedCfgs, *pLedCfgsNew;OSA_ThrCreate       ledThread;OSA_ThrHandle      *phThr;MISC_CbParams      *pMiscCbParams = NULL;OSA_INFO("PDC_ledInit\n");PDC_miscGetCbParams(&pMiscCbParams);if (OSA_isNotNull(pMiscCbParams)){pMiscCbParams->OpSetLed = LED_setState;}/* 获取LED配置引脚 */status = PDC_cfgGet(PDC_MODULE_LED,(Ptr *)&pLedCfgs);if (OSA_isFail(status)){OSA_ERROR("Get led cfg failed !\n");return OSA_EFAIL;}pLedCfgsNew = pLedCfgs;/* 创建互斥锁,消除lint用 */status = OSA_mutexCreate(OSA_MUTEX_NORMAL, &pLedObj->hLedMutex);if (OSA_isFail(status)){OSA_ERROR("OSA_mutexCreate failed !\n");return OSA_EFAIL;}/* 统计LED灯个数 */while (pLedCfgsNew->code != LED_INVLIDATE){count++;pLedCfgsNew++;}pLedObj->ledCfgNum = count;status = LED_getPins(pLedObj, pLedCfgs);if (OSA_isFail(status)){OSA_ERROR("Get led pins failed !\n");goto delete_mutex;}/* 申请内存保存配置 */pLedState = OSA_memCalloc(count * sizeof(LED_State));if (OSA_isNull(pLedState)){OSA_ERROR("Mem alloc failed !\n");goto free_pins;}pLedState->turnType = 0;pLedObj->pLedState  = pLedState;/* 启动LED灯亮灯定时器,周期性的设置LED亮状态 */phThr = &pLedObj->hLedCheckThr;OSA_clearSize(&ledThread, sizeof(OSA_ThrCreate));ledThread.OpThrRun =  LED_ledCheckThead;ledThread.stackSize = OSA_THR_STACK_SIZE_DEFAULT;ledThread.thrPol = OSA_SCHED_FIFO;ledThread.thrPri = (Uint16)OSA_THR_PRI_MIN(OSA_SCHED_FIFO);ledThread.pUsrArgs = pLedObj;ledThread.pName    =  "led_Thr";status = OSA_thrCreateEx(&ledThread, phThr);if (OSA_isFail(status)){OSA_ERROR("Fail to create led check thread!\n");goto free_state_mem;}return status;free_state_mem:OSA_memFree(pLedObj->pLedState);free_pins:LED_putPins(pLedObj);delete_mutex:OSA_mutexDelete(pLedObj->hLedMutex);return OSA_EFAIL;
}/*******************************************************************************
*  函数名   : PDC_ledExit
*  描  述   : LED模块卸载函数
*  输  入   : 无。
*  输  出   : 无。
*  返回值   : OSA_EFAIL: 失败
*             OSA_SOK  : 成功
*******************************************************************************/
Int32 __exit PDC_ledExit(void)
{Int32       status = OSA_SOK;LED_Obj    *pLedObj = &gLedObj;status |= OSA_thrDelete(pLedObj->hLedCheckThr);status |= OSA_memFree(pLedObj->pLedState);status |= LED_putPins(pLedObj);/* 销毁互斥锁,消除lint用 */OSA_mutexDelete(pLedObj->hLedMutex);return status;
}
/*******************************************************************************
* pdc_peripheralsCfg_ambacv22.c
*
* Copyright (C) 2011-2013 ZheJiang Dahua Technology CO.,LTD.
*
* Author : wang_zhenyu <wang_zhenyudahuatech.com>
* Version: V1.0.0  2020-10-16 Create
*
* Description: ambacv22配置初始化入口。按照ambacv22管脚资源进行配置,使用3516ev300
*              芯片的设备需要裁减和修改。
*
*       1. 硬件说明。
*
*       2. 程序结构说明。
*
*       3. 使用说明。
*
*       4. 局限性说明。
*
*       5. 其他说明。
*
*
* Modification:
*    Date    :
*    Revision:
*    Author  :
*    Contents:
*******************************************************************************/#include <sys_info.h>
#include "pdc_cfg.h"
#include "pdc_priv.h"//#define FPGA_UPGRADE_SPI_SIMULATE/* 恢复默认配置 */
static PDC_ResetStateCfg gRstStateCfg =
{.gpioCfg = PDC_cfgSetGpio(45, 0),.resetLevel = 0,
};/* 系统重启:reboot */
static PDC_RebootCfg  gRstSysCfg =
{
#if 0.rebootType  = PDC_REBOOT_TYPE_GPIO,.gpioCfg =  43,
#else.rebootType  = PDC_REBOOT_TYPE_WDT,.gpioCfg = PDC_CFG_GPIO_INVA,
#endif.level   = 0,
};/* 看门狗配置 */
static PDC_WdtCfg  gWdtCfg =
{.wdtTypeFlags = PDC_WDT_SOFTWARE,.hardWareWdtCfg ={.gpioCfg = PDC_CFG_GPIO_INVA,.hWdtFeedType = 2,}
};static PDC_ComMapInfo gComPortCfg =
{.comMapItems[0] = {.uartRxGpio = PDC_CFG_GPIO_INVA,.uartRxVal = -1,.uartTxGpio =  PDC_CFG_GPIO_INVA,.uartTxVal = -1,.rs485Gpio = PDC_CFG_GPIO_INVA,.type = COM_IS_CONSOLE,.port = COM_PORT_1,.comStyle = COM_STYLE_UART,.changeGio = PDC_CFG_GPIO_INVA,.reserved ={0,0,0,},},.comMapItems[1] = {.uartRxGpio = PDC_cfgSetGpio(142, 0),.uartRxVal = -1,.uartTxGpio = PDC_cfgSetGpio(143, 0),.uartTxVal = -1,.rs485Gpio = PDC_CFG_GPIO_INVA,.type = COM_STYLE_UART,.port = COM_PORT_2,.comStyle = COM_STYLE_UART,.changeGio = PDC_CFG_GPIO_INVA,.reserved ={0,0,0,},},.comMapItems[2] = {.uartRxGpio = PDC_CFG_GPIO_INVA,.uartRxVal = -1,.uartTxGpio = PDC_CFG_GPIO_INVA,.uartTxVal = -1,.rs485Gpio = PDC_CFG_GPIO_INVA,.type = COM_IS_GENERAL,.port = COM_PORT_MAX_NUM,/* 标识无该串口,配置结束 */.comStyle = COM_STYLE_MAX,.changeGio = PDC_CFG_GPIO_INVA,.reserved ={0,0,0,},},.pullType =  PRC_PINMUX_NOPULL,
};/* RTC配置 */
static PDC_RtcCfg gRtcCfg =
{.rtcId = PDC_RTC_TYPE_SOCRTC,.rtcDevCfg = {0,0},.historicalRtcId = PDC_RTC_TYPE_NR,.rtcHistDevCfg = {0, 0},.reserved = 0,
};static PDC_PlatformCfg gPlatformCfgAll =
{.spiBusInitParams ={{ /* FPGA通信使用 */2, 0, 1, SPI_TRANSMIT_POLLED,{-1,0,PRC_PINMUX_NOPULL,0,0},{-1,0,PRC_PINMUX_NOPULL,0,0},{-1,0,PRC_PINMUX_NOPULL,0,0},},{ /* FPGA加载使用,0-4是控制器 4实际是另外一组复用GPIO的spi1 *///ssi1_sclk(GPIO35) ssi1_txd(GPIO36) ssi1_rxd(GPIO37)/* FPGA升级使用 */4, 0, 1, SPI_TRANSMIT_POLLED,{-1,0,PRC_PINMUX_NOPULL,0,0},{-1,0,PRC_PINMUX_NOPULL,0,0},{-1,0,PRC_PINMUX_NOPULL,0,0},},{SPI_BUS_INVALID ,0,0,0,{0,0,0,0,0},{0,0,0,0,0},{-1,0,0,0,0},},},.I2CinitParams ={{I2C_BUS_INVALID ,0,0,0,{-1,0,0,0,0},{-1,0,0,0,0},I2C_GIO_RESET_INVALID,},},
};static PDC_PlatformCfg gPlatformCfgAll_MULTI =
{.spiBusInitParams ={{ /* 双目FPGA通信和加载复用使用 *//* FPGA 0-4是控制器 4实际是另外一组复用GPIO的spi1 *///ssi1_sclk(GPIO35) ssi1_txd(GPIO36) ssi1_rxd(GPIO37)4, 0, 1, SPI_TRANSMIT_POLLED,{-1,0,PRC_PINMUX_NOPULL,0,0},{-1,0,PRC_PINMUX_NOPULL,0,0},{-1,0,PRC_PINMUX_NOPULL,0,0},},{SPI_BUS_INVALID ,0,0,0,{0,0,0,0,0},{0,0,0,0,0},{-1,0,0,0,0},},},.I2CinitParams ={{I2C_BUS_INVALID ,0,0,0,{-1,0,0,0,0},{-1,0,0,0,0},I2C_GIO_RESET_INVALID,},},
};static PDC_KeyCfg gKeyCfg[]  =
{{.keyType  = PDC_KEY_TYPE_GPIO,.timeOutMs = 500,.cfg.gpioKeyCfg ={.codeMask = PDC_KEY_RESET,.keyGpio  = PDC_cfgSetGpio(45, 0),.keyDownLevel = 0,},},{/* 结束标志 */.keyType  = PDC_KEY_TYPE_NR,.timeOutMs = 0,.cfg.gpioKeyCfg ={.codeMask = KEY_INVALID,.keyGpio  = PDC_CFG_GPIO_INVA,.keyDownLevel = 0,}},
};static  PDC_BeepCfg  gBeepCfg =
{.gpioCfg = PDC_cfgSetGpio(41, 1), /* PWM0/GPIO41 */.outLevel = 1,.ctrlMode = PDC_BEEP_CTRL_BY_PWM,.beepPwmCfg = {.pwmId = 0,.mode = 0,.activeLevel = 1,.frequence = 3100,},
};/* LED使用的是配置数组,需要配套PDC_smartIrCfg */
static  PDC_LedCfg gLedCfgs[] =
{{.code     = LED_OK_STATUS,.ledNum   = 0,.gpioCfg1 = PDC_cfgSetGpio(14, 0),.gpioCfg2 = PDC_CFG_GPIO_INVA,.level    = 0,.needApply = 1,.powerOnState = 1,},{.code     = LED_PHY_LINK,.ledNum   = 1,.gpioCfg1 = PDC_cfgSetGpio(13, 0),.gpioCfg2 = PDC_CFG_GPIO_INVA,.level    = 0,.needApply = 1,.powerOnState = 1,},{.code     = LED_INVLIDATE,  /* 表明结束 */.ledNum   = 2,},
};static  PDC_LedCfg gLedCfgs_Multi[] =
{{.code     = LED_Sys,.ledNum   = 0,.gpioCfg1 = PDC_cfgSetGpio(14, 0),.gpioCfg2 = PDC_CFG_GPIO_INVA,.level    = 0,.needApply = 1,.powerOnState = 1,},{.code     = LED_PHY_LINK,.ledNum   = 1,.gpioCfg1 = PDC_cfgSetGpio(13, 0),.gpioCfg2 = PDC_CFG_GPIO_INVA,.level    = 0,.needApply = 1,.powerOnState = 1,},{.code     = LED_LaserEn,.ledNum   = 2,.gpioCfg1 = PDC_cfgSetGpio(7, 0),.gpioCfg2 = PDC_CFG_GPIO_INVA,.level    = 0,.needApply = 1,.powerOnState = 1,},{.code     = LED_INVLIDATE,  /* 表明结束 */.ledNum   = 3,},
};static PDC_GpioStateCfg gGpioCfg_8k[] =
{{.useType = GPIO_TRIGGER,.gpioCfg = PDC_cfgSetGpio(78, 0),},{.useType = GPIO_FPGA_RESET,.gpioCfg = PDC_cfgSetGpio(83, 0),},{.useType = GPIO_PHASE_MODE_START_STATUS,.gpioCfg = PDC_cfgSetGpio(77, 0),},{.useType = GPIO_PHASE_MODE_END_STATUS,.gpioCfg = PDC_cfgSetGpio(84, 0),},{.useType = GPIO_SEN_RESET,.gpioCfg = PDC_cfgSetGpio(85, 0),},{.useType = GPIO_SEN_SPI_SEL_0,.gpioCfg = PDC_cfgSetGpio(79, 0),},{.useType = GPIO_SEN_SPI_SEL_1,.gpioCfg = PDC_cfgSetGpio(80, 0),},{.useType = GPIO_SEN_SPI_SEL_2,.gpioCfg = PDC_cfgSetGpio(81, 0),},{.useType = GPIO_SEN_SPI_SEL_3,.gpioCfg = PDC_cfgSetGpio(82, 0),},{.useType = GPIO_SEN_SPI_SEL_4,.gpioCfg = PDC_cfgSetGpio(86, 0),},{.useType = GPIO_STATE_NR,.gpioCfg = PDC_CFG_GPIO_INVA,       // 表示结束,不能删},
};static PDC_GpioStateCfg gGpioCfg_7000[] =
{{.useType = GPIO_TRIGGER,.gpioCfg = PDC_cfgSetGpio(6, 0),},{.useType = GPIO_FPGA_RESET,.gpioCfg = PDC_cfgSetGpio(7, 0),},{.useType = GPIO_PHASE_MODE_START_STATUS,.gpioCfg = PDC_cfgSetGpio(4, 0),},{.useType = GPIO_PHASE_MODE_END_STATUS,.gpioCfg = PDC_cfgSetGpio(5, 0),},{.useType = GPIO_STATE_NR,.gpioCfg = PDC_CFG_GPIO_INVA,       // 表示结束,不能删},
};static PDC_GpioStateCfg gGpioCfg_Multi[] =
{{.useType = GPIO_TRIGGER,.gpioCfg = PDC_cfgSetGpio(0, 0),},{.useType = GPIO_TRIGGER_INT,.gpioCfg = PDC_cfgSetGpio(4, 0),},{.useType = GPIO_FPGA_JTAG_DISABLE,.gpioCfg = PDC_cfgSetGpio(5, 0),},{.useType = GPIO_STATE_NR,.gpioCfg = PDC_CFG_GPIO_INVA,       // 表示结束,不能删},
};// xilinx 需在线加载
static PDC_fpgaCfg __initdata gFpgaCfgInit_Xilinx =
{.updateCfg ={.updateMode = FPGA_SSMODE,.ssModeCfg ={.oe = PDC_CFG_GPIO_INVA,           //电平转换芯片开关.init_b = PDC_cfgSetGpio(105, 0),      //fpga 复位状态,从fpga端读.program_b = PDC_cfgSetGpio(106, 0),   //fpga复位信号.done = PDC_cfgSetGpio(107, 0),        //加载完成信号 从fpga端读.independentBus = 1,.bus = FPGA_SPI,.spiCfg ={.busId = 4,.cs = 0,.freq = 12000000,.bitLen = 8,.mode = SPI_MODE_0 | (SPI_RXTX_ALL<<SPI_RXTX_SHIFT),.intGpio = PDC_CFG_GPIO_INVA,.csPinCfg ={/* 真正的片选 假的GPIO*/.pinId = PDC_cfgSetGpio(38, 0),.mode = 0,.pullType = PRC_PINMUX_NOPULL,.isReverse = 0,.debouncTime = 0,},},.fpgaType = FPGA_XILINX,},},.commCfg ={.commMode = FPGA_SPI,.spiCfg ={.busId = 2,.cs = 0,.freq = 1000000,.bitLen = 8,.mode = SPI_MODE_0 | (SPI_RXTX_ALL<<SPI_RXTX_SHIFT),.intGpio = PDC_CFG_GPIO_INVA,.csPinCfg ={/* 真正的片选 */.pinId = PDC_cfgSetGpio(30, 0), //GPIO 3_7.mode = 0,.pullType = PRC_PINMUX_NOPULL,.isReverse = 0,.debouncTime = 0,},},},
};// 紫光 需在线加载,不同于xilinx,升级数据需按特殊格式传输
static PDC_fpgaCfg __initdata gFpgaCfgInit_PGL =
{.updateCfg ={.updateMode = FPGA_SSMODE,.ssModeCfg ={.oe = PDC_CFG_GPIO_INVA,           //电平转换芯片开关.init_b = PDC_cfgSetGpio(158, 0),      //fpga 复位状态,从fpga端读.program_b = PDC_cfgSetGpio(160, 0),   //fpga复位信号.done = PDC_cfgSetGpio(159, 0),    //加载完成信号 从fpga端读.independentBus = 1,.bus = FPGA_SPI,.spiCfg ={.busId = 4,.cs = 0,.freq = 12000000,.bitLen = 8,.mode = SPI_MODE_0 | (SPI_RXTX_ALL<<SPI_RXTX_SHIFT),.intGpio = PDC_CFG_GPIO_INVA,.csPinCfg ={/* 真正的片选 假的GPIO*/.pinId = PDC_cfgSetGpio(38, 0), //GPIO 4_7.mode = 0,.pullType = PRC_PINMUX_NOPULL,.isReverse = 0,.debouncTime = 0,},},.fpgaType = FPGA_PGL,},},.commCfg ={.commMode = FPGA_SPI,.spiCfg ={.busId = 2,.cs = 0,.freq = 1000000,.bitLen = 8,.mode = SPI_MODE_0 | (SPI_RXTX_ALL<<SPI_RXTX_SHIFT),.intGpio = PDC_CFG_GPIO_INVA,.csPinCfg ={/* 真正的片选 */.pinId = PDC_cfgSetGpio(30, 0),.mode = 0,.pullType = PRC_PINMUX_NOPULL,.isReverse = 0,.debouncTime = 0,},},},
};static PDC_fpgaCfg __initdata gFpgaCfgInit_HME =
{.updateCfg ={.updateMode = FPGA_PSMODE,.psModeCfg ={.nstatus = PDC_CFG_GPIO_INVA,       // 状态.confdon = 159,		                // 配置完成.dclk = 35,	        // 时钟.data = PDC_CFG_GPIO_INVA,	        // 数据.ss = 38,                           // HME-HR’s SS pin,控制fpga进入ps模式后兼做片选.nconfig = 160,		                // 配置.resetGpio = PDC_CFG_GPIO_INVA,     // 复位.ctrlGpio   = PDC_CFG_GPIO_INVA,    // 控制.spiMode    = 2,                    // 0 代表用原生SPI通信,1代表用模拟GPIO通信,2代表原生与模拟切换.independentBus = 0,                // 是否独立总线,0、共用data总线,1、独立总线// 若是复用总线,则不进行ss/dclk/data管脚初始化},},.commCfg ={.commMode = FPGA_SPI,.spiCfg ={.busId = 4,  /* 硬件上为GPIO38复用的SPI1,PRC中定义为SPI4 */.cs = 0,.freq = 1000000,.bitLen = 8,.mode = SPI_MODE_0 | (SPI_RXTX_ALL<<SPI_RXTX_SHIFT),.intGpio = PDC_CFG_GPIO_INVA,.csPinCfg ={/* 真正的片选 */.pinId = PDC_cfgSetGpio(38, 0), //GPIO38.mode = 0,.pullType = PRC_PINMUX_NOPULL,.isReverse = 0,.debouncTime = 0,},},},
};static PDC_CfgAllInfo gCfgAllInfo =
{.paCfgArray[PDC_MODULE_RESET_SYS]   = &gRstSysCfg,.aCfgSize[PDC_MODULE_RESET_SYS]     = sizeof(gRstSysCfg),.paCfgArray[PDC_MODULE_WDT]         = &gWdtCfg,.aCfgSize[PDC_MODULE_WDT]           = sizeof(gWdtCfg),.paCfgArray[PDC_MODULE_COMPORT]     = &gComPortCfg,.aCfgSize[PDC_MODULE_COMPORT]       = sizeof(gComPortCfg),};Int32 __init PDC_cfgInit_MV_RH7XXX(SYS_ProductInfo *pPdtInfo)
{Int32       status = OSA_SOK;(void)pPdtInfo;PDC_setHWIDInfo(DSP_CHIP,DSP_CV2S88);gCfgAllInfo.paCfgArray[PDC_MODULE_COMMON]  = &gPlatformCfgAll;gCfgAllInfo.aCfgSize[PDC_MODULE_COMMON]    = sizeof(gPlatformCfgAll);if( OSA_isSuccess(PDC_checkProductType("MV-SL7082MG17C")) ||OSA_isSuccess(PDC_checkProductType("MV-SL7082CG17C"))){gCfgAllInfo.paCfgArray[PDC_MODULE_RESET_STATE] = &gRstStateCfg,gCfgAllInfo.aCfgSize[PDC_MODULE_RESET_STATE]   = sizeof(gRstStateCfg),gCfgAllInfo.paCfgArray[PDC_MODULE_LED]         = gLedCfgs,gCfgAllInfo.aCfgSize[PDC_MODULE_LED]           = sizeof(gLedCfgs),gCfgAllInfo.paCfgArray[PDC_MODULE_KEY]     = gKeyCfg;gCfgAllInfo.aCfgSize[PDC_MODULE_KEY]       = sizeof(gKeyCfg);gCfgAllInfo.paCfgArray[PDC_MODULE_GPIO_STATE]  = gGpioCfg_8k;gCfgAllInfo.aCfgSize[PDC_MODULE_GPIO_STATE]    = sizeof(gGpioCfg_8k);gCfgAllInfo.paCfgArray[PDC_MODULE_FPGA] = &gFpgaCfgInit_Xilinx;gCfgAllInfo.aCfgSize[PDC_MODULE_FPGA]   = sizeof(gFpgaCfgInit_Xilinx);OSA_INFO("FPGA type :  Xilinx\n");gCfgAllInfo.paCfgArray[PDC_MODULE_BEEP]        = &gBeepCfg;gCfgAllInfo.aCfgSize[PDC_MODULE_BEEP]          = sizeof(gBeepCfg);}else if( OSA_isSuccess(PDC_checkProductType("MV-DS5131MG30C")) ||OSA_isSuccess(PDC_checkProductType("MV-DS5131MG30X")) ||OSA_isSuccess(PDC_checkProductType("MV-DS5131CG30C"))){gCfgAllInfo.paCfgArray[PDC_MODULE_LED]         = gLedCfgs_Multi,gCfgAllInfo.aCfgSize[PDC_MODULE_LED]           = sizeof(gLedCfgs_Multi),gCfgAllInfo.paCfgArray[PDC_MODULE_COMMON]  = &gPlatformCfgAll_MULTI;gCfgAllInfo.aCfgSize[PDC_MODULE_COMMON]    = sizeof(gPlatformCfgAll_MULTI);gCfgAllInfo.paCfgArray[PDC_MODULE_GPIO_STATE]  = gGpioCfg_Multi;gCfgAllInfo.aCfgSize[PDC_MODULE_GPIO_STATE]    = sizeof(gGpioCfg_Multi);gCfgAllInfo.paCfgArray[PDC_MODULE_FPGA] = &gFpgaCfgInit_HME;gCfgAllInfo.aCfgSize[PDC_MODULE_FPGA]   = sizeof(gFpgaCfgInit_HME);OSA_INFO("FPGA type :  HME-H1D03\n");}else{gCfgAllInfo.paCfgArray[PDC_MODULE_LED]         = gLedCfgs,gCfgAllInfo.aCfgSize[PDC_MODULE_LED]           = sizeof(gLedCfgs),gCfgAllInfo.paCfgArray[PDC_MODULE_RESET_STATE] = &gRstStateCfg,gCfgAllInfo.aCfgSize[PDC_MODULE_RESET_STATE]   = sizeof(gRstStateCfg),gCfgAllInfo.paCfgArray[PDC_MODULE_KEY]     = gKeyCfg;gCfgAllInfo.aCfgSize[PDC_MODULE_KEY]       = sizeof(gKeyCfg);gCfgAllInfo.paCfgArray[PDC_MODULE_GPIO_STATE]  = gGpioCfg_7000;gCfgAllInfo.aCfgSize[PDC_MODULE_GPIO_STATE]    = sizeof(gGpioCfg_7000);gCfgAllInfo.paCfgArray[PDC_MODULE_FPGA]    = &gFpgaCfgInit_PGL;gCfgAllInfo.aCfgSize[PDC_MODULE_FPGA]      = sizeof(gFpgaCfgInit_PGL);OSA_INFO("FPGA type : PGL22\n");gCfgAllInfo.paCfgArray[PDC_MODULE_BEEP]        = &gBeepCfg;gCfgAllInfo.aCfgSize[PDC_MODULE_BEEP]          = sizeof(gBeepCfg);}status = PDC_cfgRegister(&gCfgAllInfo);return status;
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com