Advertisement
steschm0712

clocktask

Nov 13th, 2015
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.87 KB | None | 0 0
  1. #include <stdbool.h>
  2. #include <inc/hw_memmap.h>
  3.  
  4.  
  5.  
  6. #include <xdc/std.h>
  7. #include <xdc/runtime/System.h>
  8. #include <xdc/runtime/Error.h>
  9.  
  10. #include <ti/sysbios/BIOS.h>
  11. #include <ti/sysbios/knl/Clock.h>
  12. #include <ti/sysbios/knl/Task.h>
  13. #include <ti/sysbios/knl/Event.h>
  14. #include <ti/sysbios/knl/Semaphore.h>
  15.  
  16. #include <driverlib/gpio.h>
  17. #include <driverlib/pin_map.h>/*supplies GPIO_PIN_x*/
  18. #include <driverlib/sysctl.h>
  19.  
  20.  
  21. Void clockfnc();
  22. void blinkled();
  23.  
  24. Event_Handle eventtrg;
  25.  
  26.  
  27. /*
  28.  *  ======== main ========
  29.  */
  30. Int main()
  31. {
  32.     Clock_Params clkParams;
  33.     Task_Params tskParams;
  34.  
  35.     SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
  36.     GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_0, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);
  37.  
  38.     GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE,GPIO_PIN_0);
  39.     GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0, 0x00);
  40.  
  41.     Error_Block eb;
  42.  
  43.     Error_init(&eb);
  44.  
  45.     eventtrg = Event_create(NULL, &eb);
  46.     if (eventtrg == NULL) {
  47.         System_abort("Event create failed");
  48.     }
  49.  
  50.  
  51.  
  52.  
  53.     /* Create a periodic Clock Instance with period = 1000 system time units */
  54.     Clock_Params_init(&clkParams);
  55.     clkParams.period = 1000;
  56.     clkParams.startFlag = TRUE;
  57.     Clock_create(clockfnc, 1000, &clkParams, NULL);
  58.  
  59.     /* create a ledblink task */
  60.     Task_Params_init(&tskParams);
  61.     tskParams.priority = 15;
  62.     tskParams.arg0 = NULL;
  63.     Task_create(blinkled, &tskParams, NULL);
  64.  
  65.     BIOS_start();    /* does not return */
  66.     return(0);
  67. }
  68.  
  69. /*
  70.  *  ======== clockfnc =======
  71.  */
  72. Void clockfnc()
  73. {
  74.     /* Explicit posting of Event_Id_00 by calling Event_post() */
  75.     Event_post(eventtrg, Event_Id_00);
  76. }
  77.  
  78. void blinkled()
  79. {
  80.     static uint8_t ui8val = 0;
  81.     UInt res;
  82.  
  83.     for (;;) {
  84.  
  85.         res = Event_pend(eventtrg,Event_Id_00,Event_Id_00,NULL);
  86.         if (res != 0)
  87.             ui8val=ui8val ^ 1;
  88.  
  89.         GPIOPinWrite (GPIO_PORTF_BASE, GPIO_PIN_0, ui8val);
  90.     }
  91.  
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement