PageRenderTime 21ms CodeModel.GetById 12ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/elekIO/testAT96.c

http://github.com/Yniold/liftsrc
C | 113 lines | 84 code | 19 blank | 10 comment | 2 complexity | be6633baab42f4b2eb7d660701c412fa MD5 | raw file
  1#include <stdio.h>
  2#include <stdlib.h>
  3#include <unistd.h>
  4#include <sys/io.h>
  5#include <stdint.h>
  6
  7#include <ctype.h>
  8#include <string.h>
  9#include <errno.h>
 10#include <sys/types.h>
 11#include <sys/time.h>
 12
 13#include <fcntl.h>
 14#include <unistd.h>
 15
 16#include "../include/elekIO.h"
 17
 18#define DEBUGLEVEL 10
 19// PC Version
 20//
 21int elkInit (void)
 22{
 23
 24   int ret;
 25
 26   ret=ioperm(ELK_BASE, 50, 1);
 27   return (ret);
 28}
 29//=====================================================================================================
 30int elkExit (void)
 31{
 32
 33   int ret;
 34
 35   ret=ioperm(ELK_BASE, 50, 0);                // we don't need it anymore
 36   return (ret);
 37}
 38//=====================================================================================================
 39
 40int elkWriteData(uint16_t Adress, uint16_t Data)
 41{
 42#if (DEBUGLEVEL > 0)
 43   printf("Write Data 0x%04x to port 0x%04x\n",Data,Adress);
 44#endif
 45
 46   outw(Data, Adress);
 47}
 48// end elkWriteData(uint16_t Adress, uint16_t Data)
 49//
 50//=====================================================================================================
 51
 52int elkReadData(uint16_t Adress)
 53{
 54   int ret;
 55   uint16_t ElkReadData;
 56
 57   ElkReadData   = inw(Adress);   
 58   return(ElkReadData);
 59}
 60//======================================================================================================
 61
 62int main(int argc, char *argv[])
 63{
 64
 65   int ret;
 66   int i;
 67   int ArgCount;
 68   int Addr;
 69   int Value;
 70   if(argc < 2)
 71     {
 72	printf("AT96 Test. Usage 'test (w/r) adress data\n'");
 73	exit(-1);
 74     };
 75   printf("Test program for AT96 backplane\n");
 76
 77   printf(" init Linux rights..");
 78   ret=elkInit();
 79   printf(" returns : 0x%04x \n",ret);
 80   ArgCount=1; // next argument
 81
 82   switch(argv[ArgCount++][0])
 83     {
 84      case 'r':
 85	Addr=strtol(argv[ArgCount],NULL,0);
 86	ArgCount++;
 87	Value=elkReadData((uint16_t) Addr);
 88	printf("Read %04x(%05d) : %04x(%05d)\n",Addr,Addr, Value, Value);
 89	printf("%d\n",Value);
 90	break;
 91
 92      case 'w':
 93	if(argc>3) // better check here before messing around with argv[], hartwig :)
 94	  {
 95	     Addr=strtol(argv[ArgCount],NULL,0);
 96	     ArgCount++;
 97	     Value=strtol(argv[ArgCount],NULL,0);
 98	     ArgCount++;
 99	     ret=elkWriteData((uint16_t) Addr,(uint16_t)Value);
100//	     printf("Wrote %4x=%4x(%5d) : %4x(%5d)\n",ret,Addr,Addr,Value,Value);
101	     break;
102	  }
103
104      default:
105	printf("Unknown Command\n");
106	printf(" exit ..");
107	ret=elkExit();
108	printf(" returns : 0x%x \n",ret);
109     }
110   exit(0);
111};
112   /* main */
113