G2A Many GEOs
SHARE
TWEET

Intégration Xenomai pour BBB

a guest Jan 28th, 2014 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. #include <string.h>
  3. #include <fcntl.h>
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <unistd.h>
  8. #include <sys/mman.h>
  9.  
  10. #include <native/task.h>
  11. #include <native/timer.h>
  12. #include <rtdk.h>
  13. #include "gpio-utils.h"
  14.  
  15. int toggle = 0          ;
  16. int onOffTime           ;       // Time in micro sec to keep the signal on/off
  17. int gpio = 60;
  18.  
  19. void fonction_periodique (void * arg)
  20. {
  21.         int err;
  22.         unsigned long depassements;
  23.  
  24.         rt_task_set_periodic(rt_task_self(), TM_NOW,  1000000000);
  25.         rt_printf("[%lld] Timer programmé...\n", rt_timer_read());
  26.         while ((err = rt_task_wait_period(& depassements)) == 0)
  27.         {
  28.          toggle = !toggle;
  29.          gpio_set_value(gpio, toggle);
  30.                 // printf("...value set to %d...\n", toggle);
  31.  
  32.                 //     Pause for a while
  33.                 // usleep(onOffTime);
  34.          rt_printf("[%lld]", rt_timer_read());
  35.          if (depassements != 0)
  36.                 rt_printf(" Depassements : %lu", depassements);
  37.          rt_printf("\n");
  38.         }
  39.         fprintf(stderr, "rt_task_wait_period(): %s\n",strerror(-err));
  40.         exit(EXIT_FAILURE);
  41. }
  42.  
  43.  
  44.  
  45. int main(int argc, char** argv)
  46. {
  47.  
  48. //create a variable to store whether we are sending a '1' or a '0'
  49.  char set_value[5];
  50. //Integer to keep track of whether we want on or off
  51.  int gpio_fd;
  52.  
  53.  if (argc < 2)
  54.  {
  55.                 printf("Usage: %s <on/off time in us>\n\n", argv[0]);
  56.                 printf("Toggle gpio 60 at the period given\n");
  57.                 exit(-1);
  58. } onOffTime = atoi(argv[1]);
  59.  
  60.  printf("**********************************\n"
  61.         "*  Welcome to PIN Blink program  *\n"
  62.         "*  ....blinking gpio 60          *\n"
  63.         "*  ....period of %d us.........*\n"
  64.         "**********************************\n", 2*onOffTime);
  65.  
  66.         //Using sysfs we need to write the gpio number to /sys/class/gpio/export
  67.         //This will create the folder /sys/class/gpio/gpio60
  68.         gpio_export(gpio);
  69.  
  70.         printf("...export file accessed, new pin now accessible\n");
  71.  
  72.         //SET DIRECTION
  73.         gpio_set_dir(gpio, "out");
  74.         printf("...direction set to output\n");
  75.  
  76.         gpio_fd = gpio_fd_open(gpio, O_RDONLY);
  77.  
  78.         RT_TASK task;
  79.  
  80.         mlockall(MCL_CURRENT|MCL_FUTURE);
  81.         rt_print_auto_init(1);
  82.  
  83.         if (rt_task_spawn(& task, NULL, 0, 99,
  84.                 T_JOINABLE, fonction_periodique, NULL) != 0) {
  85.                 fprintf(stderr, "Impossible de creer la tache\n");
  86.                 exit(EXIT_FAILURE);
  87.         }
  88.         rt_task_join(& task);
  89.         gpio_fd_close(gpio_fd);
  90.         return 0;
RAW Paste Data
Ledger Nano X - The secure hardware wallet
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