Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * File: RTOS.h
- * Author: abdullah
- *
- * Created on 21 Haziran 2012 Perşembe, 10:51
- */
- #ifndef RTOS_H
- #define RTOS_H
- #define OS_yield(); {\
- asm("movlw _OS_tasks ; Store the address of tasks, which is the start address of our task 'array'."); \
- asm("addwf _OS_currentTask, w ; Add current task's index to the start address."); \
- asm("movwf fsr ; We have the index of current task in W. Copy it to FSR"); \
- asm("movf pclath, w ; Copy PCLATH register's contents to W register."); \
- asm("movwf indf ; Copy W to current task's first item. We now store PCLATH of the current state of the task."); \
- asm("incf fsr, f ; Increment index, so that we will point to the next item of current task."); \
- asm("movlw low($+3) ; Copy PCL+3 to W register. This will let us save the PCL of the current state of the task."); \
- asm("movwf indf ; Copy W to task's next item. With that, we will initialize the current task."); \
- asm("goto _OS_taskswitcher ; Yield the CPU to the awaiting task by going to task switcher."); \
- }
- #define OS_initializeTask(); {\
- asm("movlw _OS_tasks ; Store the address of tasks, which is the start address of our task 'array'."); \
- asm("addwf _OS_currentTask, w ; Add current task's index to the start address."); \
- asm("movwf fsr ; We have the index of current task in W. Copy it to FSR"); \
- asm("movf pclath, w ; Copy PCLATH register's contents to W register."); \
- asm("movwf indf ; Copy W to current task's first item. We now store PCLATH."); \
- asm("incf fsr,f ; Increment index, so that we will point to the next item of current task."); \
- asm("movlw low($+3) ; Copy PCL+3 to W register. This will let us save the PCL of the start of the task."); \
- asm("movwf indf ; Copy W to task's next item. With that, we will initialize the current task."); \
- asm("return ; We have gathered our initialazation information. Return back to main."); \
- }
- #define OS_runTasks(numberOfTasks); {\
- asm("_OS_taskswitcher"); \
- asm("movlw 0x02 ; W = 2"); \
- asm("addwf _OS_currentTask, f ; Add 2 to currentTask, store it in currentTask."); \
- asm("movlw "#numberOfTasks" ; W = numOfTasks"); \
- asm("subwf _OS_currentTask, w ; w= f - w"); \
- asm("btfsc status, 0 ; If currentTask >= numOfTasks"); \
- asm("clrf _OS_currentTask ; Clear currentTask"); \
- asm("movlw _OS_tasks ; Store the address of tasks, which is the start address of our task 'array'."); \
- asm("addwf _OS_currentTask, w ; Add current task's index to the start address."); \
- asm("movwf fsr ; We have the index of current task in W. Copy it to FSR"); \
- asm("movf indf, w ; Copy the contents of current task's first item to W"); \
- asm("movwf pclath ; Copy W to PCLATH. As a result, current task's PCLATH will be in PCLATH register."); \
- asm("incf fsr, f ; Increment index, so that we will point to the next item of current task."); \
- asm("movf indf, w ; Copy the contents of current task's second item to W."); \
- asm("movwf pcl ; Copy W to PCL. Finally, current task's PCL will be in PCL register."); \
- }
- #endif /* RTOS_H */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement