资源简介
AD5592芯片驱动,8路ADC,8路DAC,8个GPIO,功能需要配置,模块化程序设计。
代码片段和文件信息
/*
* adt7516.c
*
* Created on: 2017年3月8日
* Author: zjc
*/
#include “ad5592.h“
#include “altera_avalon_spi_regs.h“
#include “altera_avalon_pio_regs.h“
#include
#include
#include
#include
#include
#include
#include “../core/laser_arc.h“
static int rd_wr_frame(struct ad5592_device *device short wr_datashort *rd_data)
{
short write=wr_data;
unsigned char *prd = (unsigned char*)rd_data;
int rd_len = (prd==NULL)?0:2;
if(device==NULL )
return -1;
if(device->magic != MAGIC_ACTIVE )
return -1;
if(device->spi->magic != MAGIC_ACTIVE )
return -1;
to_short_big(&write);
device->spi->rdwr_device(device->spi&write2prdrd_len);
if(rd_len)
to_short_big((short*)prd);
return 0;
}
static int read_all_adc(struct ad5592_device*device)
{
short word_data=0tmp[8]={0}ch_mak=0x7000;
if(device==NULL )
return -1;
if(device->magic != MAGIC_ACTIVE )
return -1;
if(device->spi->magic != MAGIC_ACTIVE )
return -1;
pthread_mutex_lock(device->spi->mutex);
word_data = AD5592_ADC_CH_CONFIG|AD5592_ADC_CH1_MAK|AD5592_ADC_CH2_MAK|AD5592_ADC_CH3_MAK
|AD5592_ADC_CH4_MAK | AD5592_ADC_CH5_MAK|AD5592_ADC_CH6_MAK|AD5592_ADC_CH7_MAK|AD5592_ADC_CH8_MAK;
//监测DAC输出
rd_wr_frame(device word_dataNULL);
word_data = 0;
rd_wr_frame(deviceword_data &tmp[0]);
rd_wr_frame(deviceword_data &tmp[1]);
rd_wr_frame(deviceword_data &tmp[2]);
rd_wr_frame(deviceword_data &tmp[3]);
rd_wr_frame(deviceword_data &tmp[4]);
rd_wr_frame(deviceword_data &tmp[5]);
rd_wr_frame(deviceword_data &tmp[6]);
rd_wr_frame(deviceword_data &tmp[7]);
pthread_mutex_unlock(device->spi->mutex);
device->cach.timestamp = get_timestamp();
int i=0;
for(i=0;i<8;i++)
{
switch(tmp[i]&ch_mak)
{
case 0:
device->cach.data[0]=tmp[i]&0xfff;
break;
case 0x1000:
device->cach.data[1]=tmp[i]&0xfff;
break;
case 0x2000:
device->cach.data[2]=tmp[i]&0xfff;
break;
case 0x3000:
device->cach.data[3]=tmp[i]&0xfff;
break;
case 0x4000:
device->cach.data[4]=tmp[i]&0xfff;
break;
case 0x5000:
device->cach.data[5]=tmp[i]&0xfff;
break;
case 0x6000:
device->cach.data[6]=tmp[i]&0xfff;
break;
case 0x7000:
device->cach.data[7]=tmp[i]&0xfff;
break;
default:
break;
}
}
return 0;
}
static int open_device(struct ad5592_device *device struct spi_device *spishort adc_pinshort dac_pin)
{
short word_data=0rcv[8]={0}snd[8]={0};
int i=0num=3;
if(device==NULL || spi ==NULL )
{
#if DEBUG
printf(“open_device ad5592_device error\n\r“);
#endif
return -1;
}
device->spi=spi;
device->spi->user_num++;
device->magic = MAGIC_ACTIVE;
#if DEBUG
printf(“ad5592_device start oepn\n\r“);
#endif
pthread_mutex_lock(device->spi->mutex);
do{
//set adc pin config
word_data = AD5592_ADC_PIN_CONFIG|(adc_pin&0xff);
// word_data = AD5592_ADC_PIN_CONFIG|AD5592_ADC_CH1_MAK|AD5592_ADC_CH2_MAK|AD5592_ADC_CH3_MAK
// |AD5592_ADC_CH4_MA
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1057955 2018-09-18 23:01 AD5592R_cn.pdf
文件 2811 2018-09-25 10:12 ad5592.h
文件 6300 2018-09-25 15:26 ad5592.c
- 上一篇:Matlab图像嵌入VC++界面的实现
- 下一篇:c++对战游戏
评论
共有 条评论