SHARE
TWEET

sunxi_axp209_temp.c

a guest Jan 15th, 2016 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <sys/mman.h>
  2. #include <sys/types.h>
  3. #include <sys/stat.h>
  4. #include <errno.h>
  5. #include <fcntl.h>
  6. #include <unistd.h>
  7. #include <string.h>
  8. #include <stdlib.h>
  9. #include <stdio.h>
  10. #include <time.h>
  11. #include <math.h>
  12. #include "mod_mmio.h"
  13.  
  14. int main(int argc, char **argv)
  15. {
  16.  
  17.   int opt ;
  18.   int unit = 0 ;
  19.   int debug = 0 ;
  20.   int adj = 0 ;
  21.   int tempoffset = 0 ;
  22.  
  23.   adj = atoi(argv[1]) ;
  24.   tempoffset = atoi(argv[2]) ;
  25.  
  26.   while ((opt = getopt(argc, argv, "cCfFdDn")) > 0)
  27.   {
  28.     switch (opt)
  29.     {
  30.       case 'f':
  31.         unit = 1 ;
  32.         break ;
  33.       case 'F':
  34.         unit = 1 ;
  35.         break ;
  36.       case 'd':
  37.         debug = 1 ;
  38.         break ;
  39.       case 'D':
  40.         debug = 1 ;
  41.         break ;
  42.       case 'n':
  43.         unit = 2 ;
  44.         break ;
  45.     }
  46.   }
  47.  
  48.   mmio_write(0x01c25000, 0x0027003f) ;
  49.   mmio_write(0x01c25010, 0x00040000) ;
  50.   mmio_write(0x01c25018, 0x00010fff) ;
  51.   mmio_write(0x01c25004, 0x00000090) ;
  52.  
  53.   if ( debug == 1 )
  54.   {
  55.     printf("w 0x01c25000: %08lx\n", mmio_read(0x01c25000)) ;
  56.     printf("w 0x01c25010: %08lx\n", mmio_read(0x01c25010)) ;
  57.     printf("w 0x01c25018: %08lx\n", mmio_read(0x01c25018)) ;
  58.     printf("w 0x01c25004: %08lx\n", mmio_read(0x01c25004)) ;
  59.     printf("r 0x01c25020: %08lx\n", mmio_read(0x01c25020)) ;
  60.   }
  61.  
  62.   switch (unit)
  63.   {
  64.     case 0:
  65.       printf("%0.1f",(float)((mmio_read(0x01c25020)*tempoffset)-adj)/1000) ;
  66.       if ( debug == 1 )
  67.         printf(" Celsius") ;
  68.       break ;
  69.     case 1:
  70.       printf("%0.1f",((float)((mmio_read(0x01c25020)*tempoffset)-adj)/1000*9/5)+32) ;
  71.       if ( debug == 1 )
  72.         printf(" Fahrenheit") ;
  73.       break ;
  74.   }
  75.  
  76.   printf("\n");
  77.  
  78.   return 0;
  79.  
  80. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top