【TI毫米波雷达笔记】ADCBuf外设初始化配置及驱动(以IWR6843AOP为例)
ADCBuf是为mmwave服务的 在配置之前需要配置好mmwave
#include < ti/drivers/ADCBuf.h>
对应mmwave studio:
ADCBuf模块上电
调用:
ADCBuf_init();
ADCBuf初始化ADCBuf_open
1. 打开ADCBufADCBuf_open
ADCBuf_Params adcBufParams;
ADCBuf_Params_init(&adcBufParams);
adcBufParams.source = ADCBUF_SOURCE_DFE;
adcBufParams.continousMode = continousMode; //连续模式
adcBufParams.chirpThresholdPing = chirpThresholdVal;
adcBufParams.chirpThresholdPong = chirpThresholdVal;
adcBufParams.custom = &adcBufParams;
adcBufParams.socHandle = MMWave_Global_Params.handle.socHandle;
MMWave_Global_Params.handle.adcbuf_handle = ADCBuf_open(0,&adcBufParams);
if (MMWave_Global_Params.handle.adcbuf_handle == NULL )
{
System_printf ("Error: ADCBuf Initialization failed\n");
}
这里设置了ADCBuf的工作模式
其中 乒乓球(ping、pong)阈值表示接收到多少个ADC信号后才开始工作 我这里是一接收就工作
2. 控制(配置)ADCBufADCBuf_control
通过ADCBuf_control
可以配置很多东西
第二个参数就是命令参数 结构体:ADCBufMMWave_CMD
通过传入不同的命令 控制要配置的东西 然后再把值传进去
ADCBuf_RxChanConf rxChanConf;
memset((void *)&rxChanConf, 0, sizeof(ADCBuf_RxChanConf));
rxChanConf.channel = 0;
rxChanConf.offset = 0;
for (channel = 0; channel < SYS_COMMON_NUM_RX_CHANNEL; channel++)
{
rxChanConf.channel = channel;
retVal = ADCBuf_control(MMWave_Global_Params.handle.adcbuf_handle, ADCBufMMWave_CMD_CHANNEL_ENABLE, (void *)&rxChanConf);
if (retVal < 0)
{
System_printf ("Error: ADCBuf Channel Enable failed\n");
}
rxChanConf.offset += 128 * 4 * chirpThresholdVal; //chanDataSize * chirpThresholdVal;
// 128*4的原因是16位复数采样 就是16*2 换算过来就是4byte 然后ADC只采96个 但要按2^N也就是128对齐 所以每个RX通道第96个byte后面的都是0
}
这里配置了ADCBuf的大小 我的ADC采样数为96个 16位复数采样
但是要进行2^N对齐 所以最低采样就是128个(后面的去掉或者补0)
16位复数采样就是4B 再乘以128个就是128*4=512B 那么一个ADC数据就是0.5KB 再加上四个通道就是2KB 那么一帧96个chirps就是192KB
retVal = ADCBuf_control(MMWave_Global_Params.handle.adcbuf_handle, ADCBufMMWave_CMD_SET_PING_CHIRP_THRESHHOLD,(void *)&chirpThresholdVal);
if(retVal < 0)
{
System_printf ("Error: ADCBuf Ping Chirp THRESHHOLD failed\n");
}
retVal = ADCBuf_control(MMWave_Global_Params.handle.adcbuf_handle, ADCBufMMWave_CMD_SET_PONG_CHIRP_THRESHHOLD,(void *)&chirpThresholdVal);
if(retVal < 0)
{
System_printf ("Error: ADCBuf Pong Chirp THRESHHOLD failed\n");
}
retVal = ADCBuf_control(MMWave_Global_Params.handle.adcbuf_handle, ADCBufMMWave_CMD_SET_CONTINUOUS_MODE,(void *)&continousMode);
if(retVal < 0)
{
System_printf ("Error: ADCBuf Set Continuous Mode failed\n");
}
retVal = ADCBuf_control(MMWave_Global_Params.handle.adcbuf_handle, ADCBufMMWave_CMD_START_CONTINUOUS_MODE ,(void *)&continousMode);
if(retVal < 0)
{
System_printf ("Error: ADCBuf Start Continuous Mode failed\n");
}
这里设置了乒乓阈值和连续模式
其实上面已经设置过了 再设置一遍以防万一
获取数据
有两种方式
- 官方推荐的ADC转换
调用ADCBuf_Conversion
:
ADCBuf_Conversion blockingConversion;
blockingConversion.arg = NULL;
blockingConversion.adcChannel = Board_ADCCHANNEL_A1;
blockingConversion.sampleBuffer = sampleBufferOnePtr;
blockingConversion.sampleBufferTwo = NULL;
blockingConversion.samplesRequestedCount = ADCBUFFERSIZE;
if (!ADCBuf_convert(adcBuf, &continuousConversion, 1)) {
// handle error
}
这种方式是一个阻塞 但是不太好控制存储的位置(我认为)
- 比较好实现的转换:
调用ADCBuf_getChanBufAddr
函数然后移过去
我设置了SOC监听 然后把L3_RAM利用起来:
/*! L3 RAM buffer for object detection DPC */
uint8_t L3_RAM_Buf[SOC_L3RAM_SIZE]={0};
#pragma DATA_SECTION(L3_RAM_Buf, ".l3ram");
int32_t errCode;
SOC_SysIntListenerCfg listenerCfg;
/* Register Chirp Available Listener */
memset ((void*)&listenerCfg, 0, sizeof(SOC_SysIntListenerCfg));
listenerCfg.systemInterrupt = SOC_XWR68XX_MSS_CHIRP_AVAIL_IRQ;
listenerCfg.listenerFxn = MMWave_chirpIntCallback;
listenerCfg.arg = 0;
MMWave_Global_Params.handle.chirpIntHandle = SOC_registerSysIntListener (MMWave_Global_Params.handle.socHandle, &listenerCfg, &errCode);
if (MMWave_Global_Params.handle.chirpIntHandle == NULL)
{
System_printf ("Error: Unable to register the Chirp Available Listener [Error code %d]\n", errCode);
}
每次chirp接收完成以后 触发chirp有效中断 然后把四个RX通道的值移到L3_RAM里面 我一帧是96个Chirps 所以chirp_updata_flag
计数96次
在回调函数里面移动数据:
static uint8_t chirp_updata_flag=0;
void MMWave_chirpIntCallback(uintptr_t arg)
{
int32_t errCode;
uint8_t channel=0;
uint32_t add=0;
for(channel=0;channel<4;channel++)
{
add = ADCBuf_getChanBufAddr(MMWave_Global_Params.handle.adcbuf_handle,channel,&errCode);
memset(&L3_RAM_Buf[chirp_updata_flag*2048+channel*512],0,512);
memcpy(&L3_RAM_Buf[chirp_updata_flag*2048+channel*512],(void *)add,512);
}
chirp_updata_flag++;
if(chirp_updata_flag==96)
{
chirp_updata_flag=0;
}
}
最后效果: