adcapp

This is a tool to read all the available ADC channels.
A raw value is read from each of the channels.

Updated LICENSE file to cover all source files and
removed file specific licenses at the top of some
of the files.

Signed-off-by: Hongwei Zhang <hongweiz@ami.com>
Change-Id: I3c1b389c0d91bccfc3ee93bccfe04137d7ea9960
Signed-off-by: Kiran Kumar <kirank@ami.com>
diff --git a/hongweiz/adcapp/LICENSE b/hongweiz/adcapp/LICENSE
new file mode 100644
index 0000000..3600ecd
--- /dev/null
+++ b/hongweiz/adcapp/LICENSE
@@ -0,0 +1,12 @@
+Copyright (C) 2019 American Megatrends Internation LLC.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
diff --git a/hongweiz/adcapp/Makefile.am b/hongweiz/adcapp/Makefile.am
new file mode 100644
index 0000000..38bdf12
--- /dev/null
+++ b/hongweiz/adcapp/Makefile.am
@@ -0,0 +1,2 @@
+SUBDIRS = src
+dist_doc_DATA = README
diff --git a/hongweiz/adcapp/README b/hongweiz/adcapp/README
new file mode 100644
index 0000000..f7b288a
--- /dev/null
+++ b/hongweiz/adcapp/README
@@ -0,0 +1,5 @@
+This is a package for a tool that can be used to read ADC channel
+Raw readings from available maximum number channels.
+
+Usage : addapp NumOfMaxChannels <option> 
+	--read-adc-channel: 		Get ADC value for all the ADC channels
diff --git a/hongweiz/adcapp/configure.ac b/hongweiz/adcapp/configure.ac
new file mode 100644
index 0000000..2692ad2
--- /dev/null
+++ b/hongweiz/adcapp/configure.ac
@@ -0,0 +1,9 @@
+AC_INIT([adcapp], [1.0], [bug-bmcapps@ami.com])
+AM_INIT_AUTOMAKE([-Wall -Werror foreign])
+AC_PROG_CC
+AC_CONFIG_HEADERS([config.h])
+AC_CONFIG_FILES([
+ Makefile
+ src/Makefile
+])
+AC_OUTPUT
diff --git a/hongweiz/adcapp/src/EINTR_wrappers.c b/hongweiz/adcapp/src/EINTR_wrappers.c
new file mode 100644
index 0000000..b60622e
--- /dev/null
+++ b/hongweiz/adcapp/src/EINTR_wrappers.c
@@ -0,0 +1,826 @@
+
+/*
+* File: EINTR_wrappers.c
+*
+* This file implements the wrapper functions for some of the System APIs
+*
+* Copyright (C) <2019>  <American Megatrends International LLC>
+*
+*/
+
+#include "EINTR_wrappers.h"
+#if defined(__linux__)
+#include <sys/msg.h>
+#include <sys/file.h>
+#endif
+#include <errno.h>
+#include <unistd.h>
+
+static const int OneSecondasNS = 1000000000;
+
+#ifndef bool
+typedef int bool;
+#endif
+
+#ifndef TRUE
+#define TRUE (1)
+#endif
+
+#ifndef FALSE
+#define FALSE (0)
+#endif
+
+typedef struct
+{
+    bool OnePoll;
+    struct timespec EndTime, Timeout;
+} SIGWRAP_TIMEOUT;
+
+static void sigwrap_InitTimeout(SIGWRAP_TIMEOUT *pDst, const struct timespec *timeout)
+{
+    pDst->Timeout = *timeout;
+
+    if ((timeout->tv_sec == 0) && (timeout->tv_nsec == 0))                  // If both value are zero than only a single poll is requested!
+    {
+        pDst->OnePoll = 1;
+        return;
+    }
+
+    pDst->OnePoll = 0;
+
+    struct timespec Now;
+
+    (void)clock_gettime(CLOCK_MONOTONIC_RAW, &Now);                         // CLOCK_MONOTONIC_RAW is not affected by NTP etc.
+
+    pDst->EndTime.tv_sec = Now.tv_sec + pDst->Timeout.tv_sec;               // Check necessary in 2038 due to signed integer variables
+    pDst->EndTime.tv_nsec = Now.tv_nsec + pDst->Timeout.tv_nsec;
+
+    if (pDst->EndTime.tv_nsec >= OneSecondasNS)
+    {
+        pDst->EndTime.tv_sec += (pDst->EndTime.tv_nsec / OneSecondasNS);
+        pDst->EndTime.tv_nsec = (pDst->EndTime.tv_nsec % OneSecondasNS);
+    }
+}
+
+
+static bool sigwrap_CheckTimeout(SIGWRAP_TIMEOUT *pTo)
+{
+    if (pTo->OnePoll == TRUE) // Make sure, that in the case that a single poll is requested at least one call is not terminated with EINTR
+        return FALSE;
+
+    struct timespec Now;
+
+    (void)clock_gettime(CLOCK_MONOTONIC_RAW, &Now);
+
+    if (Now.tv_sec > pTo->EndTime.tv_sec) // Can become a problem already in 2038 due to signed integer variables
+        return TRUE;
+
+    pTo->Timeout.tv_nsec = pTo->EndTime.tv_nsec - Now.tv_nsec;
+    pTo->Timeout.tv_sec = pTo->EndTime.tv_sec - Now.tv_sec;
+
+    if (pTo->Timeout.tv_sec == 0)
+    {
+        if (pTo->Timeout.tv_nsec <= 0)
+            return TRUE;
+    }
+    else if (pTo->Timeout.tv_nsec < 0)
+    {
+        pTo->Timeout.tv_nsec += OneSecondasNS;
+        pTo->Timeout.tv_sec--;
+    }
+
+    return FALSE;
+}
+
+
+
+int sigwrap_semop(int semid, struct sembuf *sops, size_t nsops)
+{
+    while (1)
+    {
+        if (semop(semid, sops, nsops) == 0)
+            return 0;
+
+        if (errno != EINTR)
+            return -1;
+    }
+}
+
+#if 0
+int sigwrap_semtimedop(int semid, struct sembuf *sops, size_t nsops, const struct timespec *timeout)
+{
+    SIGWRAP_TIMEOUT To;
+
+    if (timeout == NULL)
+        return (sigwrap_semop(semid, sops, nsops));
+
+    sigwrap_InitTimeout(&To, timeout);
+
+    while (1)
+    {
+        if (semtimedop(semid, sops, nsops, &To.Timeout) == 0)
+            return 0;
+
+        if (errno != EINTR)
+            return -1;
+
+        if (sigwrap_CheckTimeout(&To))
+        {
+            errno = EAGAIN;
+            return -1;
+        }
+    }
+}
+#endif
+
+int sigwrap_epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout)
+{
+    SIGWRAP_TIMEOUT To;
+
+    if (timeout != -1)
+    {
+        struct timespec Timeout;
+
+        Timeout.tv_sec = timeout / 1000;
+        Timeout.tv_nsec = (timeout % 1000) * 1000000; // Convert msec to nsec
+
+        sigwrap_InitTimeout(&To, &Timeout);
+    }
+
+    while (1)
+    {
+        int Result = epoll_wait(epfd, events, maxevents, timeout);
+
+        if (Result != -1)
+            return Result;
+
+        if (errno != EINTR)
+            return Result;
+
+        if (timeout == -1)
+            continue;
+
+        if (sigwrap_CheckTimeout(&To))
+            return 0;
+
+        timeout = To.Timeout.tv_sec * 1000 + To.Timeout.tv_nsec / 1000000;
+    }
+}
+
+
+int sigwrap_epoll_pwait(int epfd, struct epoll_event *events, int maxevents, int timeout, const sigset_t *sigmask)
+{
+    SIGWRAP_TIMEOUT To;
+
+    if (timeout != -1)
+    {
+        struct timespec Timeout;
+
+        Timeout.tv_sec = timeout / 1000;
+        Timeout.tv_nsec = (timeout % 1000) * 1000000; // Convert msec to nsec
+
+        sigwrap_InitTimeout(&To, &Timeout);
+    }
+
+    while (1)
+    {
+        int Result = epoll_pwait(epfd, events, maxevents, timeout, sigmask);
+
+        if (Result != -1)
+            return Result;
+
+        if (errno != EINTR)
+            return Result;
+
+        if (timeout == -1)
+            continue;
+
+        if (sigwrap_CheckTimeout(&To))
+            return 0;
+
+        timeout = To.Timeout.tv_sec * 1000 + To.Timeout.tv_nsec / 1000000;
+    }
+}
+
+
+int sigwrap_sigwaitinfo(const sigset_t *set, siginfo_t *info)
+{
+    while (1)
+    {
+        int Result = sigwaitinfo(set, info);
+
+        if (Result != -1)
+            return Result;
+
+        if (errno != EINTR)
+            return Result;
+    }
+}
+
+
+int sigwrap_sigtimedwait(const sigset_t *set, siginfo_t *info, const struct timespec *timeout)
+{
+    SIGWRAP_TIMEOUT To;
+
+    sigwrap_InitTimeout(&To, timeout);
+
+    while (1)
+    {
+        int Result = sigtimedwait(set, info, &To.Timeout);
+
+        if (Result != -1)
+            return Result;
+
+        if (errno != EINTR)
+            return Result;
+
+        if (sigwrap_CheckTimeout(&To))
+            return 0;
+    }
+}
+
+
+int sigwrap_nanosleep(const struct timespec *req, struct timespec *rem)
+{
+    struct timespec Wait, Remain;
+
+    if (!rem)
+        rem = &Remain;
+
+    Wait = *req;
+
+    while (1)
+    {
+        if (nanosleep(&Wait, rem) == 0)
+            return 0;
+
+        if (errno != EINTR)
+            return -1;
+
+        Wait = *rem;
+    }
+}
+
+
+int sigwrap_clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *request, struct timespec *remain)
+{
+    struct timespec Wait, Remain;
+
+    if (!remain)
+        remain = &Remain;
+
+    Wait = *request;
+
+    while (1)
+    {
+        int Result = clock_nanosleep(clock_id, flags, &Wait, remain);
+        
+        if (Result == 0)
+            return Result;
+
+        if (Result != EINTR)
+            return Result;
+
+        if (flags != TIMER_ABSTIME)
+            Wait = *remain;
+    }
+}
+
+
+int sigwrap_usleep(useconds_t usec)
+{
+    SIGWRAP_TIMEOUT To;
+
+    struct timespec Timeout;
+
+    Timeout.tv_sec = usec / 1000000;
+    Timeout.tv_nsec = (usec % 1000000) * 1000;
+
+    sigwrap_InitTimeout(&To, &Timeout);
+
+    while (1)
+    {
+        if (usleep(usec) == 0)
+            return 0;
+
+        if (errno != EINTR)
+            return -1;
+
+        if (sigwrap_CheckTimeout(&To))
+            return 0;
+
+        usec = To.Timeout.tv_sec * 1000000 + To.Timeout.tv_nsec / 1000;
+    }
+}
+
+
+int sigwrap_poll(struct pollfd *fds, nfds_t nfds, int timeout)
+{
+    SIGWRAP_TIMEOUT To;
+
+    if (timeout > 0)
+    {
+        struct timespec Timeout;
+
+        Timeout.tv_sec = timeout / 1000;
+        Timeout.tv_nsec = (timeout % 1000) * 1000000;
+
+        sigwrap_InitTimeout(&To, &Timeout);
+    }
+
+    while (1)
+    {
+        int Result = poll(fds, nfds, timeout);
+
+        if (Result != -1)
+            return Result;
+
+        if (errno != EINTR)
+            return Result;
+
+        if (timeout < 0) // Specifying a negative value in timeout means an infinite/no timeout. 
+            continue;
+        else if (timeout == 0)
+            continue; // We want to make sure that at least one check was not aborted with EINTR
+
+        if (sigwrap_CheckTimeout(&To))
+            return 0;
+
+        timeout = To.Timeout.tv_sec * 1000 + To.Timeout.tv_nsec / 1000000;
+    }
+}
+
+#if 0
+int sigwrap_ppoll(struct pollfd *fds, nfds_t nfds, const struct timespec *tmo_p, const sigset_t *sigmask)
+{
+    SIGWRAP_TIMEOUT To;
+
+    if (tmo_p != NULL)
+    {
+        sigwrap_InitTimeout(&To, tmo_p);
+        tmo_p = &To.Timeout;
+    }
+
+    while (1)
+    {
+        int Result = ppoll(fds, nfds, tmo_p, sigmask);
+
+        if (Result != -1)
+            return Result;
+
+        if (errno != EINTR)
+            return Result;
+
+        if (tmo_p == NULL)
+            continue;
+
+        if (sigwrap_CheckTimeout(&To))
+            return 0;
+    }
+}
+#endif
+
+int sigwrap_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
+{
+    while (1)
+    {
+        int Result = select(nfds, readfds, writefds, exceptfds, timeout);
+
+        if (Result != -1)
+            return Result;
+
+        if (errno != EINTR)
+            return Result;
+    }
+}
+
+
+int sigwrap_pselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, const struct timespec *timeout,
+                    const sigset_t *sigmask)
+{
+    SIGWRAP_TIMEOUT To;
+
+    if (timeout != NULL)
+    {
+        sigwrap_InitTimeout(&To, timeout);
+        timeout = &To.Timeout;
+    }
+
+    while (1)
+    {
+        int Result = pselect(nfds, readfds, writefds, exceptfds, timeout, sigmask);
+
+        if (Result != -1)
+            return Result;
+
+        if (errno != EINTR)
+            return Result;
+
+        if (timeout == NULL)
+            continue;
+
+        if (sigwrap_CheckTimeout(&To))
+            return 0;
+    }
+}
+
+
+int sigwrap_msgsnd(int msqid, const void *msgp, size_t msgsz, int msgflg)
+{
+    while (1)
+    {
+        int Result = msgsnd(msqid, msgp, msgsz, msgflg);
+
+        if (Result != -1)
+            return Result;
+
+        if (errno != EINTR)
+            return Result;
+    }
+}
+
+
+ssize_t sigwrap_msgrcv(int msqid, void *msgp, size_t msgsz, long msgtyp, int msgflg)
+{
+    while (1)
+    {
+        ssize_t Result = msgrcv(msqid, msgp, msgsz, msgtyp, msgflg);
+
+        if (Result != -1)
+            return Result;
+
+        if (errno != EINTR)
+            return Result;
+    }
+}
+
+
+int sigwrap_connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen)
+{
+    while (1)
+    {
+        int Result = connect(sockfd, addr, addrlen);
+
+        if (Result != -1)
+            return Result;
+
+        if (errno != EINTR)
+            return Result;
+    }
+}
+
+
+ssize_t sigwrap_send(int sockfd, const void *buf, size_t len, int flags)
+{
+    while (1)
+    {
+        ssize_t Result = send(sockfd, buf, len, flags);
+
+        if (Result != -1)
+            return Result;
+
+        if (errno != EINTR)
+            return Result;
+    }
+}
+
+
+ssize_t sigwrap_sendto(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr,
+                       socklen_t addrlen)
+{
+    while (1)
+    {
+        ssize_t Result = sendto(sockfd, buf, len, flags, dest_addr, addrlen);
+
+        if (Result != -1)
+            return Result;
+
+        if (errno != EINTR)
+            return Result;
+    }
+}
+
+
+ssize_t sigwrap_sendsendmsg(int sockfd, const struct msghdr *msg, int flags)
+{
+    while (1)
+    {
+        ssize_t Result = sendmsg(sockfd, msg, flags);
+
+        if (Result != -1)
+            return Result;
+
+        if (errno != EINTR)
+            return Result;
+    }
+}
+
+
+int sigwrap_accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
+{
+    while (1)
+    {
+        int Result = accept(sockfd, addr, addrlen);
+
+        if (Result != -1)
+            return Result;
+
+        if (errno != EINTR)
+            return Result;
+    }
+}
+
+#if 0
+int sigwrap_accept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags)
+{
+    while (1)
+    {
+        int Result = accept4(sockfd, addr, addrlen, flags);
+
+        if (Result != -1)
+            return Result;
+
+        if (errno != EINTR)
+            return Result;
+    }
+}
+#endif
+
+// EINTR wrapper for the standard read() function. Can be used for sockets that are the to non-blocking mode.
+// The length of the returned data can be shorter than the requested one!
+
+ssize_t sigwrap_read(int fd, void *buf, size_t count)
+{
+    while (1)
+    {
+        ssize_t Result = read(fd, buf, count);
+
+        if (Result != -1)
+            return (Result);
+
+        if (errno != EINTR)
+            return (Result);
+    }
+}
+
+
+// EINTR wrapper for the standard read() function. Waits until ALL requested data is available. Use the non-blocking version (sigwrap_read)
+// for sockets that are set to non-blocking mode or when partial data is okay
+// Although the description for the read() function describes it differently, it seems possible that the original function may already return
+// even though partial data has already been read. This implementation makes sure that all requested data have been read.
+// See the comment in the signal description https://linux.die.net/man/7/signal
+//* read(2), readv(2), write(2), writev(2), and ioctl(2) calls on "slow" devices. 
+//* A "slow" device is one where the I/O call may block for an indefinite time, for example, a terminal, pipe, or socket. 
+//* (A disk is not a slow device according to this definition.) If an I/O call on a slow device has already transferred
+//* some data by the time it is interrupted by a signal handler, then the call will return a success status (normally, the number of bytes transferred). 
+
+ssize_t sigwrap_blocking_read(int hFile, void *pData, size_t RdLen)
+{
+    ssize_t Transfered;
+    ssize_t Len = RdLen;
+
+    while ((Transfered = read(hFile, pData, Len)) != Len)
+    {
+        if (Transfered == 0) // EOF reached?
+            return 0;
+
+        if (Transfered != -1)
+        {
+            pData += Transfered;
+            Len -= Transfered;
+            continue;
+        }
+
+        if (errno != EINTR)
+            return -1;
+    }
+
+    return RdLen;
+}
+
+
+ssize_t sigwrap_readv(int fd, const struct iovec *iov, int iovcnt)
+{
+    while (1)
+    {
+        ssize_t Result = readv(fd, iov, iovcnt);
+
+        if (Result != -1)
+            return (Result);
+
+        if (errno != EINTR)
+            return (Result);
+    }
+}
+
+
+ssize_t sigwrap_recv(int sockfd, void *buf, size_t len, int flags)
+{
+    while (1)
+    {
+        ssize_t Result = recv(sockfd, buf, len, flags);
+
+        if (Result != -1)
+            return (Result);
+
+        if (errno != EINTR)
+            return (Result);
+    }
+}
+
+
+ssize_t sigwrap_recvfrom(int sockfd, void *buf, size_t len, int flags, struct sockaddr *src_addr, socklen_t *addrlen)
+{
+    while (1)
+    {
+        ssize_t Result = recvfrom(sockfd, buf, len, flags, src_addr, addrlen);
+
+        if (Result != -1)
+            return (Result);
+
+        if (errno != EINTR)
+            return (Result);
+    }
+}
+
+
+ssize_t sigwrap_recvmsg(int sockfd, struct msghdr *msg, int flags)
+{
+    while (1)
+    {
+        ssize_t Result = recvmsg(sockfd, msg, flags);
+
+        if (Result != -1)
+            return (Result);
+
+        if (errno != EINTR)
+            return (Result);
+    }
+}
+
+
+// EINTR wrapper for the standard write() function. Can be used for sockets that are the to non-blocking mode.
+// The length of the effectively written data can be shorter than the length specified at the function call!
+
+ssize_t sigwrap_write(int fd, const void *buf, size_t count)
+{
+    while (1)
+    {
+        ssize_t Result = write(fd, buf, count);
+
+        if (Result != -1)
+            return (Result);
+
+        if (errno != EINTR)
+            return (Result);
+    }
+}
+
+// EINTR wrapper for the standard write() function. Waits until ALL data is written! Use the non-blocking version (sigwrap_write)
+// for sockets that are set to non-blocking mode, or when it is OK to write only partial data.
+// Although the description for the write() function describes it differently, it seems possible that the original function may already return
+// even though partial data has already been written. This implementation makes sure that all requested data have been written.
+// See the comment in the signal description https://linux.die.net/man/7/signal
+//* read(2), readv(2), write(2), writev(2), and ioctl(2) calls on "slow" devices. 
+//* A "slow" device is one where the I/O call may block for an indefinite time, for example, a terminal, pipe, or socket. 
+//* (A disk is not a slow device according to this definition.) If an I/O call on a slow device has already transferred
+//* some data by the time it is interrupted by a signal handler, then the call will return a success status (normally, the number of bytes transferred). 
+        
+ssize_t sigwrap_blocking_write(int hFile, const void *pData, ssize_t WrtLen)
+{
+    ssize_t Written;
+    ssize_t Len = WrtLen;
+
+    while ((Written = write(hFile, pData, Len)) != Len)
+    {
+        if (Written != -1)
+        {
+            pData += Written;
+            Len -= Written;
+            continue;
+        }
+
+        if (errno != EINTR)
+            return -1;
+    }
+
+    return WrtLen;
+}
+
+
+ssize_t sigwrap_writev(int fd, const struct iovec *iov, int iovcnt)
+{
+    while (1)
+    {
+        ssize_t Result = writev(fd, iov, iovcnt);
+
+        if (Result != -1)
+            return (Result);
+
+        if (errno != EINTR)
+            return (Result);
+    }
+}
+
+
+int sigwrap_close(int hFile)
+{
+    while (close(hFile) == -1)
+    {
+        if (errno != EINTR)
+            return -1;
+    }
+
+    return 0;
+}
+
+
+int sigwrap_open_mode(const char *pathname, int flags, mode_t mode)
+{
+    while (1)
+    {
+        int hFile = open(pathname, flags, mode);
+        
+        if(hFile != -1)
+            return hFile;
+        
+        if (errno != EINTR)
+            return hFile;
+    }
+}
+
+int sigwrap_open(const char *pathname, int flags)
+{
+    while (1)
+    {
+        int hFile = open(pathname, flags);
+        
+        if(hFile != -1)
+            return hFile;
+        
+        if (errno != EINTR)
+            return hFile;
+    }
+}
+
+
+pid_t sigwrap_wait(int *status)
+{
+    while(1)
+    {
+        pid_t Result = wait(status);
+        
+        if(Result != -1)
+            return Result;
+        
+        if(errno != EINTR)
+            return Result;
+    }
+}
+
+
+pid_t sigwrap_waitpid(pid_t pid, int *status, int options)
+{
+    while(1)
+    {
+        pid_t Result = waitpid(pid, status, options);
+        
+        if(Result != -1)
+            return Result;
+        
+        if(errno != EINTR)
+            return Result;
+    }
+}
+
+
+int sigwrap_waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options)
+{
+    while(1)
+    {
+        int Result = waitid(idtype, id, infop, options);
+        
+        if(Result != -1)
+            return Result;
+        
+        if(errno != EINTR)
+            return Result;
+    }
+}
+
+
+int sigwrap_flock(int fd, int operation) 
+{
+    while(1)
+    {
+        int Result = flock(fd, operation);
+        
+        if(Result != -1)
+            return Result;
+        
+        if(errno != EINTR)
+            return Result;
+    }
+}
+
+
diff --git a/hongweiz/adcapp/src/EINTR_wrappers.h b/hongweiz/adcapp/src/EINTR_wrappers.h
new file mode 100644
index 0000000..c39fa34
--- /dev/null
+++ b/hongweiz/adcapp/src/EINTR_wrappers.h
@@ -0,0 +1,124 @@
+
+/*File:EINTR_wrappers.h
+*
+* Wrapper functions header file.
+*
+* Copyright (C) <2019>  <American Megatrends International LLC>
+*
+*/
+
+#ifndef EINTR_WRAPPERS_H__
+#define EINTR_WRAPPERS_H__
+
+#if defined(__linux__)
+#ifndef _SYS_TYPES_H
+#include <sys/types.h>
+#endif
+
+#ifndef _SYS_PC_H
+#include <sys/ipc.h>
+#endif
+
+#ifndef _SYS_SEM_H
+#include <sys/sem.h>
+#endif
+
+#ifndef _SYS_EPOLL_H
+#include <sys/epoll.h>
+#endif
+
+#ifndef _SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+
+#ifndef _SIGNAL_H
+#include <signal.h>
+#endif
+
+#ifndef _TIME_H
+#include <time.h>
+#endif
+
+#ifndef _POLL_H
+#include <poll.h>
+#endif
+
+#ifndef _WAIT_H
+#include <wait.h>
+#endif
+
+#ifndef _UNISTD_H
+#include <unistd.h>
+#endif
+
+int  sigwrap_semop(int semid, struct sembuf *sops, size_t nsops);
+int  sigwrap_semtimedop(int semid, struct sembuf *sops, size_t nsops, const struct timespec *timeout);
+int  sigwrap_epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout);
+int  sigwrap_epoll_pwait(int epfd, struct epoll_event *events, int maxevents, int timeout, const sigset_t *sigmask);
+int  sigwrap_sigwaitinfo(const sigset_t *set, siginfo_t *info);
+int  sigwrap_sigtimedwait(const sigset_t *set, siginfo_t *info, const struct timespec *timeout);
+int  sigwrap_nanosleep(const struct timespec *req, struct timespec *rem);
+int  sigwrap_clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *request, struct timespec *remain);
+int  sigwrap_usleep(useconds_t usec);
+int  sigwrap_poll(struct pollfd *fds, nfds_t nfds, int timeout);
+int  sigwrap_ppoll(struct pollfd *fds, nfds_t nfds, const struct timespec *tmo_p, const sigset_t *sigmask);
+int  sigwrap_select(int nfds, fd_set *readfds, fd_set *writefds,fd_set *exceptfds, struct timeval *timeout);
+int  sigwrap_pselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, const struct timespec *timeout, const sigset_t *sigmask);
+int  sigwrap_msgsnd(int msqid, const void *msgp, size_t msgsz, int msgflg);
+int  sigwrap_connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
+int  sigwrap_accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
+int  sigwrap_accept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags);
+int  sigwrap_close(int hFile);
+int sigwrap_open_mode(const char *pathname, int flags, mode_t mode);
+int  sigwrap_open(const char *pathname, int flags);
+
+
+pid_t sigwrap_wait(int *status);
+pid_t sigwrap_waitpid(pid_t pid, int *status, int options);
+int   sigwrap_waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options);
+
+
+ssize_t sigwrap_msgrcv(int msqid, void *msgp, size_t msgsz, long msgtyp, int msgflg);
+ssize_t sigwrap_send(int sockfd, const void *buf, size_t len, int flags);
+ssize_t sigwrap_sendto(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen);
+ssize_t sigwrap_sendsendmsg(int sockfd, const struct msghdr *msg, int flags);
+
+ssize_t sigwrap_read(int fd, void *buf, size_t count);
+// EINTR wrapper for the standard read() function. Waits until ALL requested data is available. Use the non-blocking version (sigwrap_read)
+// for sockets that are set to non-blocking mode or when partial data is okay
+// Although the description for the read() function describes it differently, it seems possible that the original function may already return
+// even though partial data has already been read. This implementation makes sure that all requested data have been read.
+// See the comment in the signal description https://linux.die.net/man/7/signal
+//* read(2), readv(2), write(2), writev(2), and ioctl(2) calls on "slow" devices. 
+//* A "slow" device is one where the I/O call may block for an indefinite time, for example, a terminal, pipe, or socket. 
+//* (A disk is not a slow device according to this definition.) If an I/O call on a slow device has already transferred
+//* some data by the time it is interrupted by a signal handler, then the call will return a success status (normally, the number of bytes transferred). 
+ssize_t sigwrap_blocking_read(int hFile, void *pData, size_t RdLen);
+
+ssize_t sigwrap_readv(int fd, const struct iovec *iov, int iovcnt);
+
+ssize_t sigwrap_write(int fd, const void *buf, size_t count);
+// EINTR wrapper for the standard write() function. Waits until ALL data is written! Use the non-blocking version (sigwrap_write)
+// for sockets that are set to non-blocking mode, or when it is OK to write only partial data.
+// Although the description for the write() function describes it differently, it seems possible that the original function may already return
+// even though partial data has already been written. This implementation makes sure that all requested data have been written.
+// See the comment in the signal description https://linux.die.net/man/7/signal
+//* read(2), readv(2), write(2), writev(2), and ioctl(2) calls on "slow" devices. 
+//* A "slow" device is one where the I/O call may block for an indefinite time, for example, a terminal, pipe, or socket. 
+//* (A disk is not a slow device according to this definition.) If an I/O call on a slow device has already transferred
+//* some data by the time it is interrupted by a signal handler, then the call will return a success status (normally, the number of bytes transferred). 
+ssize_t sigwrap_blocking_write(int hFile, const void *pData, ssize_t WrtLen);
+
+ssize_t sigwrap_writev(int fd, const struct iovec *iov, int iovcnt);
+
+ssize_t sigwrap_recv(int sockfd, void *buf, size_t len, int flags);
+
+ssize_t sigwrap_recvfrom(int sockfd, void *buf, size_t len, int flags, struct sockaddr *src_addr, socklen_t *addrlen);
+
+ssize_t sigwrap_recvmsg(int sockfd, struct msghdr *msg, int flags);
+
+int sigwrap_flock(int fd, int operation);
+
+
+#endif
+#endif
diff --git a/hongweiz/adcapp/src/Makefile.am b/hongweiz/adcapp/src/Makefile.am
new file mode 100644
index 0000000..07896c2
--- /dev/null
+++ b/hongweiz/adcapp/src/Makefile.am
@@ -0,0 +1,2 @@
+bin_PROGRAMS = adcapp
+adcapp_SOURCES = adcapp.c adcifc.c adcifc.h adc.h EINTR_wrappers.c EINTR_wrappers.h
diff --git a/hongweiz/adcapp/src/adc.h b/hongweiz/adcapp/src/adc.h
new file mode 100644
index 0000000..51c967f
--- /dev/null
+++ b/hongweiz/adcapp/src/adc.h
@@ -0,0 +1,56 @@
+/*****************************************************************
+ *
+ * adcapp.c
+ * application specific driver header.
+ *
+ * Author: Rama Rao Bisa <ramab@ami.com>
+ *
+ * Copyright (C) <2019> <American Megatrends International LLC>
+ *
+ *****************************************************************/
+
+#ifndef __ADC_H__
+#define __ADC_H__
+
+#define READ_ADC_CHANNEL            _IOC(_IOC_WRITE,'K',0x100,0x3FFF)
+#define READ_ADC_REF_VOLATGE        _IOC(_IOC_WRITE,'K',0x101,0x3FFF)
+#define READ_ADC_RESOLUTION         _IOC(_IOC_WRITE,'K',0x102,0x3FFF)
+#define ENABLE_EXT_REF_VOLTAGE      _IOC(_IOC_WRITE,'K',0x103,0x3FFF)
+#define DISABLE_EXT_REF_VOLTAGE     _IOC(_IOC_WRITE,'K',0x104,0x3FFF)
+#define ENABLE_ADC_CHANNEL          _IOC(_IOC_WRITE,'K',0x105,0x3FFF)
+#define DISABLE_ADC_CHANNEL         _IOC(_IOC_WRITE,'K',0x106,0x3FFF)
+
+#define PACKED __attribute__ ((packed))
+
+typedef struct
+{
+	uint8_t 	channel_num;
+	uint16_t	channel_value;
+
+} PACKED get_adc_value_t;
+#if 0
+typedef struct
+{
+	int (*adc_read_channel) (uint16_t *adc_value, int channel);
+	int (*adc_get_resolution) (uint16_t *adc_resolution);
+	int (*adc_get_reference_voltage) (uint16_t *adc_ref_volatge);
+	int (*adc_reboot_notifier) (void);
+}adc_hal_operations_t;
+
+typedef struct
+{
+} adc_core_funcs_t;
+
+
+struct adc_hal
+{
+	adc_hal_operations_t *padc_hal_ops;
+};
+
+struct adc_dev
+{
+	struct adc_hal *padc_hal;
+};
+#endif
+
+#endif /* !__ADC_H__ */
diff --git a/hongweiz/adcapp/src/adcapp.c b/hongweiz/adcapp/src/adcapp.c
new file mode 100644
index 0000000..b7b2e44
--- /dev/null
+++ b/hongweiz/adcapp/src/adcapp.c
@@ -0,0 +1,105 @@
+/*****************************************************************
+ *
+ * adcapp.c
+ * application to acess ADC adriver
+ *
+ * Author: Rama Rao Bisa <ramab@ami.com>
+ *
+ * Copyright (C) <2019> <American Megatrends International LLC>
+ *
+ *****************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <string.h>
+#include <fcntl.h>
+#include <ctype.h>
+#include <unistd.h>
+#include <sys/select.h>
+#include <sys/ioctl.h>
+#include <sys/poll.h>
+#include <sys/time.h>
+#include <stdint.h>
+#include "EINTR_wrappers.h"
+#include "adc.h"
+#include "adcifc.h"
+
+typedef enum {
+	GET_ADC_VALUE,
+	END_OF_FUNCLIST
+
+}e_adc_actions;
+
+e_adc_actions action = END_OF_FUNCLIST;
+
+static void ShowUsuage ( void )
+{
+	printf ("ADC Test Tool - Copyright (c) 2009-2015 American Megatrends Inc.\n");
+	printf( "Usage : addapp NumOfMaxChannels <option> \n" );
+	printf( "option: \n" );
+	printf( "\t--read-adc-channel 	\tGet ADC value for all the ADC channels\n" );
+	printf( "\n" );
+}
+
+static int process_arguments( int argc, char **argv )
+{
+	int i=2;
+	if( strcmp( argv[ i ], "--read-adc-channel" ) == 0 )
+	{
+		action = GET_ADC_VALUE;
+	}
+	else
+	{
+		action = END_OF_FUNCLIST;
+	}
+	return 0;
+}
+
+int
+main ( int argc , char* argv [] )
+{
+
+	get_adc_value_t get_adc_value;
+	int max_adc_channels;
+	int i,ret_val;
+	unsigned short reading=0;
+	if ( !(argc >= 3 ) )
+	{
+		ShowUsuage () ;
+		return 0;
+	}
+	max_adc_channels = (unsigned char)strtol( argv[1], NULL, 10);
+	process_arguments( argc , argv);
+	if ( (END_OF_FUNCLIST == action))
+	{
+		ShowUsuage ();
+		return 0;
+	}
+
+	switch ( action )
+	{
+		case GET_ADC_VALUE:
+			for (i = 0; i < max_adc_channels; i++)
+			{	
+				get_adc_value.channel_num  = i;
+				get_adc_value.channel_value = 0;
+
+				ret_val = get_adc_val(get_adc_value.channel_num, &reading);
+
+				if (ret_val == -1)
+				{
+					printf ("Read ADC channel failed\n");
+					return -1;
+				}
+				printf ("ADC Channel Value =%5d for channel %d\n", reading, get_adc_value.channel_num);
+			}
+			break;
+
+		default:
+			printf("Invalid ADC Function Call ");
+			break;
+	}
+
+	return 0;
+}
diff --git a/hongweiz/adcapp/src/adcifc.c b/hongweiz/adcapp/src/adcifc.c
new file mode 100644
index 0000000..9627b28
--- /dev/null
+++ b/hongweiz/adcapp/src/adcifc.c
@@ -0,0 +1,88 @@
+ /*****************************************************************
+ *
+ * adcapp.c
+ * Simple interface to read and write adc.
+ *
+ * Author: Rama Rao Bisa <ramab@ami.com>
+ *
+ * Copyright (C) <2019> <American Megatrends International LLC>
+ *
+ *****************************************************************/
+
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <errno.h>
+#include <string.h>
+#include <stdint.h>
+#include "adc.h"
+#include "adcifc.h"
+#include "EINTR_wrappers.h"
+
+/** \file adcifc.c
+  \brief Source for all adc interface code
+ */
+
+static int adc_directory_check()
+{
+	int retval = 0;
+	struct stat sb;
+	if (!(stat("/sys/bus/iio/devices/iio:device0", &sb) == 0 && S_ISDIR(sb.st_mode)))
+	{
+		printf("\"/sys/bus/iio/devices/iio:device0\" is not exist!\n");
+		retval = -1;
+	}
+	return retval;
+}
+
+static int sys_get_adc_vol( get_adc_value_t *argp )
+{
+	int retval = -1;
+	int fd;
+	int tmp;
+	char stringArray[50];
+	char val[5];
+	if(argp->channel_num > 15)	retval = -1;
+	retval = adc_directory_check();
+	if(retval != 0)
+	{
+		return retval;
+	}
+	snprintf(stringArray, sizeof(stringArray), "%s%s%d%s", "/sys/bus/iio/devices/iio:device0","/in_voltage", argp->channel_num,"_raw");
+	retval = access(stringArray,F_OK);
+	if(retval != 0)
+	{
+		return retval;
+	}
+	fd = sigwrap_open(stringArray, O_RDONLY);
+	if (fd < 0) {
+		return fd;
+	}
+	read(fd, val, 5);
+	tmp = atoi(val);
+	(void)sigwrap_close(fd);
+	argp->channel_value = (uint16_t)(tmp);
+	retval = 0;
+	return( retval );
+}
+
+/**
+ * get_adc_val
+ *
+ **/
+int get_adc_val( int channel , unsigned short *data)
+{
+	get_adc_value_t adc_arg;
+
+	/* Set the adc channel to read */
+	adc_arg.channel_num   = channel;
+	adc_arg.channel_value = 0;
+
+	if ( -1 == sys_get_adc_vol(&adc_arg)) { return -1; }
+	*data = (unsigned short)(adc_arg.channel_value);
+
+	return ( 0 );
+}
diff --git a/hongweiz/adcapp/src/adcifc.h b/hongweiz/adcapp/src/adcifc.h
new file mode 100644
index 0000000..586ea62
--- /dev/null
+++ b/hongweiz/adcapp/src/adcifc.h
@@ -0,0 +1,51 @@
+/****************************************************************
+
+ **                                                            **
+
+ **    (C)Copyright 2006-2009, American Megatrends Inc.        **
+
+ **                                                            **
+
+ **            All Rights Reserved.                            **
+
+ **                                                            **
+
+ **        5555 Oakbrook Pkwy Suite 200, Norcross,             **
+
+ **                                                            **
+
+ **        Georgia - 30093, USA. Phone-(770)-246-8600.         **
+
+ **                                                            **
+
+****************************************************************/
+/*****************************-*- ********-*-********************************/
+/* Filename:    adcifc.h                                                    */
+/* Description: Library interface to adc access                             */
+/*****************************************************************************/
+
+#ifndef ADCIFC_H
+#define ADCIFC_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "adc.h"
+
+	/** \file adcifc.h
+	 *  \brief Public headers for the adc interface library
+	 *  
+	 *  This library contains friendly function call interfaces for getting 
+	 *  adc channel data.  It hides all the details of playing with
+	 *  adc through the adc manager (opening the device file, calling ioctl,
+	 *  etc.)
+	 */
+
+	extern  int get_adc_val( int channel , unsigned short *data);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif //ADCIFC_H