Advertisement
Guest User

3.4

a guest
Dec 5th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. #include "includes.h"
  2. // Stack sizes
  3. #define TASK1_STK_SIZE 128
  4. #define TASK1_PRIO 5 #define TASK2_PRIO 6 #define TASK3_PRIO 7
  5. // Stacks
  6. OS_STK Task1Stk[TASK1_STK_SIZE]; OS_STK Task2Stk[TASK1_STK_SIZE]; OS_STK Task3Stk[TASK1_STK_SIZE];
  7. void Task1(void *data); void Task2(void *data); void Task3(void *data);
  8. INT16U volatile adc_value; OS_EVENT *sem;
  9. int main (void) {
  10. ADC_init(ADC_OPTO, ADC_SINGLE);
  11. LCD_init();
  12. stdout = &LCD_stdout;
  13. /* Initializing inner OS variables, creating idle task, ... */
  14. OSInit();
  15. /* Create LCD backlight controlling task */
  16. OSTaskCreate(Task1, NULL, &Task1Stk[TASK1_STK_SIZE - 1], TASK1_PRIO); /* Create semaphore for event signaling */
  17. sem = OSSemCreate(1);
  18. /* Start multitasking. ( OSStart() never returns! ) */ OSStart();
  19. return 0; }
  20. void Task1(void *data) { OS_ENTER_CRITICAL();
  21. TCCR0=0x07; /* Set TIMER0 prescaler to CLK/1024 */
  22. TIMSK=_BV(TOIE0); /* Enable TIMER0 overflow interrupt */ TCNT0=256-(CPU_CLOCK_HZ/OS_TICKS_PER_SEC/1024); /* Set the counter initial value */
  23. OS_EXIT_CRITICAL();
  24. /* Create other tasks */
  25. OSTaskCreate(Task2, NULL, &Task2Stk[TASK1_STK_SIZE - 1], TASK2_PRIO); //Task2 lÈtrehoz·sa OSTaskCreate(Task3, NULL, &Task3Stk[TASK1_STK_SIZE - 1], TASK3_PRIO); //Task3 lÈtrehoz·sa /* Delete current task (single-shot task architecture) */
  26. OSTaskDel(OS_PRIO_SELF); //taszk tˆrlÈse }
  27. void Task2(void *data) {
  28. DDRC = 255; PORTC = 1; while(1){
  29. if(PORTC == 128)
  30. PORTC = 1; else
  31. PORTC <<= 1;
  32. OSTimeDlyHMSM(0,0,1,0); }
  33. }
  34. void Task3(void *data) {
  35. while(1){ ADC_start();
  36. OSSemPend(sem, 0, NULL);
  37. LCD_light((unsigned char)(adc_value>>2)); }
  38. }
  39. UCOSISR(ADC_vect) { PushRS();
  40. OSIntEnter();
  41. if (OSIntNesting == 1)
  42. OSTCBCur->OSTCBStkPtr = (OS_STK *)SP; /* Begin of application specific code */
  43. adc_value = ADC_read(); OSSemPost(sem);
  44. OSIntExit();
  45. PopRS(); }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement