daily pastebin goal
82%
SHARE
TWEET

Untitled

a guest Jun 30th, 2011 42 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. component pcl720 """Driver for the Advantech PCL 720 card. Only creates the
  2. digital inputs and outputs, not the counters/timers.""";
  3. pin in bit pin-##-out[32] "output pins";
  4. pin out bit pin-##-in[32] "input pins";
  5. pin out unsigned R0-in;
  6. pin out unsigned R1-in;
  7. pin out unsigned R2-in;
  8. pin out unsigned R3-in;
  9. pin out unsigned R0-out;
  10. pin out unsigned R1-out;
  11. pin out unsigned R2-out;
  12. pin out unsigned R3-out;
  13.  
  14. function read nofp;
  15. function write nofp;
  16.  
  17. variable unsigned base_addr;
  18.  
  19. option count_function yes;
  20. option extra_setup yes;
  21.  
  22.  
  23. modparam dummy ioaddr """Base address of card. Separate each card base address
  24. with a comma but no space to load more than one card. eg
  25. loadrt pcl720 ioaddr=0x200,0x200. use 0xNNN to define addresses in Hex""";
  26.  
  27. license "GPL";
  28. author "Andy Pugh";
  29. ;;
  30.  
  31. #include <asm/io.h>
  32. #define MAX_CHAN 8
  33.  
  34. static int ioaddr[MAX_CHAN] = {-1, -1, -1, -1, -1, -1, -1, -1};
  35. RTAPI_MP_ARRAY_INT(ioaddr, MAX_CHAN, "Base addresses")
  36.  
  37. FUNCTION(read){
  38.     unsigned char R0, R1, R2, R3;
  39.     int i;
  40.     R0 = inb(base_addr);
  41.     R1 = inb(base_addr + 1);
  42.     R2 = inb(base_addr + 2);
  43.     R3 = inb(base_addr + 3);
  44.     R0_in = R0;
  45.     R1_in = R1;
  46.     R2_in = R2;
  47.     R3_in = R3;
  48.     for (i = 0;i <= 7;i++){
  49.         pin_in(i) = R0 & (1 << i);
  50.         pin_in(i+8) = R1 & (1 << i);
  51.         pin_in(i+16) = R2 & (1 << i);
  52.         pin_in(i+24) = R3 & (1 << i);
  53.     }
  54. }
  55.  
  56. FUNCTION(write){
  57.     unsigned char R0, R1, R2, R3;
  58.     int i;
  59.     R0 = 0;
  60.     R1 = 0;
  61.     R2 = 0;
  62.     R3 = 0;
  63.     for (i = 0;i <= 7;i++){
  64.         R0 |= pin_out(i) << i;
  65.         R1 |= pin_out(i+8) << i;
  66.         R2 |= pin_out(i+16) << i;
  67.         R3 |= pin_out(i+24) << i;
  68.     }
  69.     outb(base_addr, R0);
  70.     outb(base_addr + 1, R1);
  71.     outb(base_addr + 2, R2);
  72.     outb(base_addr + 3, R3);
  73.     R0_out = R0;
  74.     R1_out = R1;
  75.     R2_out = R2;
  76.     R3_out = R3;
  77. }
  78.  
  79. EXTRA_SETUP(){
  80.     if (ioaddr[extra_arg] > 0) {
  81.         base_addr = ioaddr[extra_arg];
  82.         rtapi_print("Loading Advantech pcl720 driver at base addr %X\n", base_addr);
  83.         return 0;
  84.     }
  85.     return -EINVAL;
  86. }
  87.    
  88.    
  89. int get_count(void){
  90.     int i;
  91.     for (i=0; ioaddr[i] > 0 && i < MAX_CHAN; i++){}
  92.     return i;
  93. }
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