blob: b7b2e443bc934a6d4df08808d8b46a0655a220c3 [file] [log] [blame]
Hongwei Zhangcb66a9e2019-06-05 16:37:19 -04001/*****************************************************************
2 *
3 * adcapp.c
4 * application to acess ADC adriver
5 *
6 * Author: Rama Rao Bisa <ramab@ami.com>
7 *
8 * Copyright (C) <2019> <American Megatrends International LLC>
9 *
10 *****************************************************************/
11
12#include <stdio.h>
13#include <stdlib.h>
14#include <errno.h>
15#include <string.h>
16#include <fcntl.h>
17#include <ctype.h>
18#include <unistd.h>
19#include <sys/select.h>
20#include <sys/ioctl.h>
21#include <sys/poll.h>
22#include <sys/time.h>
23#include <stdint.h>
24#include "EINTR_wrappers.h"
25#include "adc.h"
26#include "adcifc.h"
27
28typedef enum {
29 GET_ADC_VALUE,
30 END_OF_FUNCLIST
31
32}e_adc_actions;
33
34e_adc_actions action = END_OF_FUNCLIST;
35
36static void ShowUsuage ( void )
37{
38 printf ("ADC Test Tool - Copyright (c) 2009-2015 American Megatrends Inc.\n");
39 printf( "Usage : addapp NumOfMaxChannels <option> \n" );
40 printf( "option: \n" );
41 printf( "\t--read-adc-channel \tGet ADC value for all the ADC channels\n" );
42 printf( "\n" );
43}
44
45static int process_arguments( int argc, char **argv )
46{
47 int i=2;
48 if( strcmp( argv[ i ], "--read-adc-channel" ) == 0 )
49 {
50 action = GET_ADC_VALUE;
51 }
52 else
53 {
54 action = END_OF_FUNCLIST;
55 }
56 return 0;
57}
58
59int
60main ( int argc , char* argv [] )
61{
62
63 get_adc_value_t get_adc_value;
64 int max_adc_channels;
65 int i,ret_val;
66 unsigned short reading=0;
67 if ( !(argc >= 3 ) )
68 {
69 ShowUsuage () ;
70 return 0;
71 }
72 max_adc_channels = (unsigned char)strtol( argv[1], NULL, 10);
73 process_arguments( argc , argv);
74 if ( (END_OF_FUNCLIST == action))
75 {
76 ShowUsuage ();
77 return 0;
78 }
79
80 switch ( action )
81 {
82 case GET_ADC_VALUE:
83 for (i = 0; i < max_adc_channels; i++)
84 {
85 get_adc_value.channel_num = i;
86 get_adc_value.channel_value = 0;
87
88 ret_val = get_adc_val(get_adc_value.channel_num, &reading);
89
90 if (ret_val == -1)
91 {
92 printf ("Read ADC channel failed\n");
93 return -1;
94 }
95 printf ("ADC Channel Value =%5d for channel %d\n", reading, get_adc_value.channel_num);
96 }
97 break;
98
99 default:
100 printf("Invalid ADC Function Call ");
101 break;
102 }
103
104 return 0;
105}