Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "includes.h"
- // Stack sizes
- #define TASK1_STK_SIZE 128
- #define TASK1_PRIO 5 #define TASK2_PRIO 6 #define TASK3_PRIO 7
- // Stacks
- OS_STK Task1Stk[TASK1_STK_SIZE]; OS_STK Task2Stk[TASK1_STK_SIZE]; OS_STK Task3Stk[TASK1_STK_SIZE];
- void Task1(void *data); void Task2(void *data); void Task3(void *data);
- INT16U volatile adc_value; OS_EVENT *sem;
- int main (void) {
- ADC_init(ADC_OPTO, ADC_SINGLE);
- LCD_init();
- stdout = &LCD_stdout;
- /* Initializing inner OS variables, creating idle task, ... */
- OSInit();
- /* Create LCD backlight controlling task */
- OSTaskCreate(Task1, NULL, &Task1Stk[TASK1_STK_SIZE - 1], TASK1_PRIO); /* Create semaphore for event signaling */
- sem = OSSemCreate(1);
- /* Start multitasking. ( OSStart() never returns! ) */ OSStart();
- return 0; }
- void Task1(void *data) { OS_ENTER_CRITICAL();
- TCCR0=0x07; /* Set TIMER0 prescaler to CLK/1024 */
- TIMSK=_BV(TOIE0); /* Enable TIMER0 overflow interrupt */ TCNT0=256-(CPU_CLOCK_HZ/OS_TICKS_PER_SEC/1024); /* Set the counter initial value */
- OS_EXIT_CRITICAL();
- /* Create other tasks */
- 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) */
- OSTaskDel(OS_PRIO_SELF); //taszk tˆrlÈse }
- void Task2(void *data) {
- DDRC = 255; PORTC = 1; while(1){
- if(PORTC == 128)
- PORTC = 1; else
- PORTC <<= 1;
- OSTimeDlyHMSM(0,0,1,0); }
- }
- void Task3(void *data) {
- while(1){ ADC_start();
- OSSemPend(sem, 0, NULL);
- LCD_light((unsigned char)(adc_value>>2)); }
- }
- UCOSISR(ADC_vect) { PushRS();
- OSIntEnter();
- if (OSIntNesting == 1)
- OSTCBCur->OSTCBStkPtr = (OS_STK *)SP; /* Begin of application specific code */
- adc_value = ADC_read(); OSSemPost(sem);
- OSIntExit();
- PopRS(); }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement