SAR 控制

1. SAR 控制概述

The SAR driver provides ioctl interface for users to initialize SAR and get SAR_ADC values.

2.SAR 设备节点

“/dev/sar”

3.包含文件

mdrv_sar_io.h

4.SAR IOCTL 命令

IOCTL command Parameter Description
IOCTL_SAR_INIT NULL initialize
IOCTL_SAR_SET_CHANNEL_READ_VALUE typedef struct { int channel_value; //[IN]int adc_value; //[OUT] } SAR_ADC_CONFIG_READ; channel_value: sar channel number(possible value: 0 or 1) adc_value: sar adc value Get sar adc value

5.例子

#include <stdio.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<errno.h>
#include <sys/ioctl.h>
#include "mdrv_sar_io.h"
int main(void)
{
  int i;
  SAR_ADC_CONFIG_READ adcCfg;
  adcCfg.channel_value = 0; //注意:PAD_SAR_GPIO0 = 0 PAD_SAR_GPIO1 = 1 PAD_SAR_GPIO2 = 2
  int fd = open("/dev/sar", O_WRONLY);
  if(fd == -1) {
   int err = errno;
   rintf("\n!!! FAILED to open /dev/sar, errno: %d %s\n", err, strerror(err));
   return -1;
  }
  if (ioctl(fd, IOCTL_SAR_INIT, NULL) < 0) { 
   int err = errno;
   printf("\n!!! IOCTL_SAR_INIT FAILED, errno: %d, %s\n", err, strerror(err));
  }
  for (i=0; i < 100; i++)
  {
   if (ioctl(fd, IOCTL_SAR_SET_CHANNEL_READ_VALUE, &adcCfg) < 0) {
   int err = errno;
   printf("\n!!! IOCTL_SAR_SET_CHANNEL_READ_VALUE FAILED, errno: %d, %s\n", err, 
   strerror(err));
  }
  else {
   printf("SAR: get value %d", adcCfg.adc_value);
  }
  usleep(100000);
  }
 }
文档更新时间: 2021-03-18 11:36   作者:Aeeditor