Advertisement
Guest User

Untitled

a guest
Dec 13th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1. #include <linux/module.h>
  2. #include <linux/init.h>
  3. #include <linux/kernel.h>
  4. #include <linux/proc_fs.h>
  5. #include <rtai.h>
  6. #include <rtai_sched.h>
  7. #include <rtai_fifos.h>
  8. #include <rtai_proc_fs.h>
  9. #include <comedilib.h>
  10.  
  11. MODULE_LICENSE("GPL");
  12. MODULE_DESCRIPTION("Squelette de programme RTAI et carte ni-6221");
  13. MODULE_AUTHOR("NOM BINOME");
  14.  
  15.  
  16. /*
  17. * command line parameters
  18. */
  19.  
  20.  
  21. #define ms 1000000
  22.  
  23. #define microsec 1000
  24.  
  25. #define CAN 0
  26. #define CNA 1
  27. #define DIO 2
  28. #define CHAN_0 0
  29. #define CHAN_1 1
  30. #define CAN_RANGE 1 // [-5, +5]
  31.  
  32.  
  33. float ech[50]={0.000000 , 0.125270 , 0.248566 , 0.367947 , 0.481530 , 0.587527 , 0.684268 , 0.770229 , 0.844055 , 0.904583 , 0.950859 , 0.982156 , 0.997978 , 0.998078 , 0.982454 , 0.951351 , 0.905261 , 0.844908 , 0.771244 , 0.685429 , 0.588815 , 0.482925 , 0.369427 , 0.250108 , 0.126849 , 0.001592 , -0.123690 , -0.247024 , -0.366465 , -0.480134 , -0.586238 , -0.683106 , -0.769212 , -0.843199 , -0.903902 , -0.950365 , -0.981855 , -0.997876 , -0.998176 , -0.982750 , -0.951841 , -0.905937 , -0.845759 , -0.772258 , -0.686589 , -0.590104 , -0.484321 , -0.370909 , -0.251653 , -0.128432};
  34.  
  35. int bit_n = 0;
  36. int bit_a = 0;
  37. int bit_f = 0;
  38. int bit_p = 1;
  39. long Tp = 20000000;
  40.  
  41.  
  42. static RT_TASK Tache1_Ptr; // Pointeur pour la tache 1
  43. static RT_TASK Handler_Ptr; // Pointeur pour la tache de reprise de main
  44.  
  45. comedi_t *carte;
  46.  
  47. void Tache1 (long int x)
  48.  
  49. {int i=0;
  50. long e;
  51.  
  52. while (1)
  53. {
  54. e = (65535/20)*(ech[i]) + 32767;
  55.  
  56.  
  57. comedi_dio_read(carte,DIO,0,&bit_n);
  58. comedi_dio_read(carte,DIO,1,&bit_a);
  59. comedi_dio_read(carte,DIO,2,&bit_f);
  60. comedi_dio_read(carte,DIO,3,&bit_p);
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68. comedi_data_write(carte ,CNA,0,0,AREF_GROUND,e);
  69. rt_task_wait_period();
  70. i++;
  71. if (i==50) i=0;
  72. //comedi_perror("e=%d",e) ;
  73. }
  74. }
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82. int init_module(void)
  83. { RTIME now;
  84. // Création des tâches
  85.  
  86. // Initialisation de la carte d'E/S
  87. carte = comedi_open("/dev/comedi0");
  88. if(carte == NULL)
  89. {
  90. comedi_perror("Comedi fails to open");
  91. return -1;
  92. }
  93.  
  94. // Configurer le device DIGITAL_INPUT pour recevoir les donnees/signaux
  95. // et DIGITAL_OUTPUT pour envoyer les donnees/signaux
  96. rt_set_oneshot_mode();
  97. rt_assign_irq_to_cpu(TIMER_8254_IRQ, 0);
  98.  
  99.  
  100. // Lancement du timer
  101. start_rt_timer(0);
  102. now=rt_get_time();
  103. // Lancement des taches
  104. rt_task_init(&Tache1_Ptr,Tache1,0,2000,5,0,0);
  105. //timer_period = start_rt_timer(nano2count(100*microsec));
  106. rt_task_make_periodic(&Tache1_Ptr,now,nano2count(Tp));
  107. return 0;
  108. }
  109.  
  110.  
  111. void cleanup_module(void)
  112. {
  113. stop_rt_timer();
  114. // Destruction des objets de l'application
  115. rt_reset_irq_to_sym_mode(TIMER_8254_IRQ);
  116. rt_task_delete(&Tache1_Ptr);
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement