⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kernel.asm

📁 不错的程序
💻 ASM
📖 第 1 页 / 共 2 页
字号:
;/**********************************************************************/
;/*                                                                    */
;/* File name: kernel.asm                                              */
;/*                                                                    */
;/* Since:     2004/09/20                                              */
;/*                                                                    */
;/* Version:   PICos18 v2.00                                           */
;/*            Copyright (C) 2003, 2004 Pragmatec.                     */
;/*                                                                    */
;/* Author:    Designed by Pragmatec S.A.R.L.        www.pragmatec.net */
;/*            MONTAGNE Xavier [XM]      xavier.montagne@pragmatec.net */
;/*                                                                    */
;/* Purpose:   Kernel core.                                            */
;/*                                                                    */
;/* Distribution: This file is part of PICos18.                        */
;/*            PICos18 is free software; you can redistribute it       */
;/*            and/or modify it under the terms of the GNU General     */
;/*            Public License as published by the Free Software        */
;/*            Foundation; either version 2, or (at your option)       */
;/*            any later version.                                      */
;/*                                                                    */
;/*            PICos18 is distributed in the hope that it will be      */
;/*            useful, but WITHOUT ANY WARRANTY; without even the      */
;/*            implied warranty of MERCHANTABILITY or FITNESS FOR A    */
;/*            PARTICULAR PURPOSE.  See the GNU General Public         */
;/*            License for more details.                               */
;/*                                                                    */
;/*            You should have received a copy of the GNU General      */
;/*            Public License along with gpsim; see the file           */
;/*            COPYING.txt. If not, write to the Free Software         */
;/*            Foundation, 59 Temple Place - Suite 330,                */
;/*            Boston, MA 02111-1307, USA.                             */
;/*                                                                    */
;/*          > A special exception to the GPL can be applied should    */
;/*            you wish to distribute a combined work that includes    */
;/*            PICos18, without being obliged to provide the source    */
;/*            code for any proprietary components.                    */
;/*                                                                    */
;/* History:                                                           */
;/* 2004/09/20 [XM]  Create this file.                                 */
;/*                                                                    */
;/**********************************************************************/


;	#include "device.inc"
#include <p18cxxx.inc>

;/* Should be equal to .tempdata + MATH_DATA size (from map file)      */
#define TEMP_SIZE         0x20

;/**********************************************************************
; * Kernel RAM area.
; **********************************************************************/
KERNEL_RAM    UDATA
id_tsk_run    RES     1                       ; ID of the current task
temp          RES     1
id            RES     1
temp2         RES     1
permut        RES     1
kernelState   RES     1
kernelPanic   RES     1

start_addr_L  RES     1
start_addr_H  RES     1


;/**********************************************************************
; * Share global variables with other sections.
; **********************************************************************/
	GLOBAL  id_tsk_run	
    GLOBAL  kernelState
    GLOBAL  kernelPanic

;/**********************************************************************
; * Shared variables defined in other section.
; **********************************************************************/
	extern tsk_1_state_ID
	extern tsk_16_state_ID

	extern tsk_1_activ_prio
	extern tsk_16_activ_prio
	
    extern  FSR1H_MAIN
    extern  FSR1L_MAIN
 
    extern  taskdesc_addr

;/**********************************************************************
; * Hook routines activated by the -D compiler option.
; **********************************************************************/
#IFDEF STARTUPHOOK
        extern StartupHook
#ENDIF

#IFDEF PRETASKHOOK
	extern PreTaskHook
#ENDIF

#IFDEF POSTTASKHOOK
	extern PostTaskHook
#ENDIF

        extern stack_low
        extern stack_high

;/**********************************************************************
; * ------------------------- KERNEL INIT ------------------------------
; *
; * Here is the init phase of the kernel, it means the main access to 
; * the kernel after StartOS call.
; *
; **********************************************************************/
KERNEL_ROM	CODE
_kernel
        GLOBAL  _kernel                         ; Beginning of kernel code
 
        clrf    FSR0H
        clrf    FSR0L
        clrf    FSR1L
        clrf    FSR1H
        clrf    TBLPTRU
        clrf    PCLATH
		
        movlw   0xFF                            ; Clear the first RAM bank

_k_init_RAM	                                          
        clrf    POSTINC0
        cpfseq  FSR0L
        bra     _k_init_RAM

        clrf    FSR0H
        clrf    FSR0L
        clrf    STKPTR

        movlw   0x1E                            ; Clear the hardware stack

_k_init_STK                                           
        incf    STKPTR
        clrf    TOSU
        clrf    TOSH
        clrf    TOSL
        cpfseq  STKPTR
        bra     _k_init_STK
        clrf    STKPTR
        incf    STKPTR

        movlw   0x88                            ; No prescaler
        movwf   T0CON
        clrf    INTCON2
        clrf    PIE1
        clrf    PIE2
        clrf    RCON
		clrf	IPR1
		clrf	IPR2
		clrf	INTCON2
		bsf		RCON, 7							; IPEN enabled
        movlw   0xA0                            ; PEIE
        movwf   INTCON                          ; GIE disabled (TMRO enabled)
        bsf     INTCON, 2                       ; force the TMR0 to be updated by IT

_parser
        movlb   0                               ; Init
        movlw   0x01
        movwf   STKPTR				
        clrf    temp				
        movwf   permut				
        clrf    id_tsk_run
        clrf    FSR0H				
        movlw   tsk_1_activ_prio   	
        movwf   FSR0L                             
                                                ; The Task Descriptor is
        clrf    TBLPTRU
        movff   taskdesc_addr+0, TBLPTRL       	; Load the taskdesc address
        movff   taskdesc_addr+1, TBLPTRH       	; Load the taskdesc address
									

; /* --------- TASKDESC.C CONTENT PARSING ---------- */
_parser_init
        TBLRD   *+                  
        movf    TABLAT, w           
        btfsc	STATUS, Z                       ;	
        bra     _parser_update                  ;
        movff   TABLAT, INDF0       
        TBLRD   *+                  
        movf    TABLAT, w					
        movwf   FSR1L
        TBLRD   *+
        movf    TABLAT, w
        movwf   FSR1H       		

        tstfsz  FSR1L
        incf    FSR1H
        decf    FSR1H
        decf    FSR1L
        movlw   0xad
        movwf   INDF1
        tstfsz  FSR1L
        incf    FSR1H
        decf    FSR1H
        decf    FSR1L
        movlw   0xde
        movwf   INDF1
        incf    FSR1L
        incf    FSR1L
        tstfsz  FSR1L
        decf    FSR1H
        incf    FSR1H

        TBLRD   *+                              ; 
;        movf    TABLAT, w
;        incf    FSR1L				
        TBLRD   *+                              ;
;        movf    TABLAT, w
        bcf     FSR0L, 4
									
        TBLRD   *+                              ; Store the initial state
        movf    TABLAT, w
        addwf   INDF0, 1                        ; State stored
        TBLRD   *+                              ; Store the task ID
        movf    TABLAT, w
        addwf   INDF0, 1
		
        TBLRD   *+                              ; sizeof(stack)
        movf    TABLAT, w					
        decf    WREG
        decf    WREG
        addwf   FSR1L, 1
        clrf    WREG
        addwfc  FSR1H, 1
        TBLRD   *+ 
;        movf    TABLAT, w					
;        addwf   FSR1H, 1
        movlw   0xde
        movwf   INDF1
        incf    FSR1L, 1
        clrf    WREG
        addwfc  FSR1H, 1
        movlw   0xad
        movwf   INDF1
		
        incf    FSR0L
        bsf     FSR0L, 4						
        bra     _parser_init                    ; while another task exists
		
_parser_organize
        GLOBAL  _parser_organize
        clrf    permut
        incf    permut		

; /* ----- REARRANGE TASK ORDER FCT TO PRIORITY ---- */
_parser_update
        movlw   tsk_1_activ_prio
        movwf   FSR0L
        clrf    FSR0H								
        movf    permut,w 
        btfsc   STATUS, Z			
        bra     _isHook
        clrf    permut

_parser_update_loop	
        movlw   0x0F                             
        andwf   INDF0, w	
        movwf   temp                             ; store the priority of a task			
        btfsc   STATUS, Z                        ; is swap finished ?
        bra     _parser_update
        movff   INDF0, temp2                     ; store prio + ID of the task
        movlw   0x0F
        andwf   PREINC0, w                       ; compare with the next task
        cpfseq  temp
        bra     _parser_update_diff              ; task swapping if necessary
        bra     _parser_update_loop

_parser_update_diff
        cpfsgt  temp				
        bra     _parser_update_swap 
        bra     _parser_update_loop

_parser_update_swap
         movf    INDF0, w
        decf    FSR0L               
        movwf   INDF0
        incf    FSR0L
        movff   temp2, INDF0        

        bcf     FSR0L, 4            
        movff   INDF0, temp2        
        decf    FSR0L
        movf    INDF0, w
        movff   temp2, INDF0
        incf    FSR0L
        movwf   INDF0

        bcf     FSR0L, 5
        bsf     FSR0L, 4
        movff   INDF0, temp2        
        decf    FSR0L
        movf    INDF0, w
        movff   temp2, INDF0
        incf    FSR0L
        movwf   INDF0
        
        bcf     FSR0L, 5
        bcf     FSR0L, 4
        movff   INDF0, temp2        
        decf    FSR0L
        movf    INDF0, w
        movff   temp2, INDF0
        incf    FSR0L
        movwf   INDF0
        
        bsf     FSR0L, 4
        bsf     FSR0L, 5
        incf    permut
        bra     _parser_update_loop	
		
_isHook                                               ; Hook kernel service routine
	#IFDEF	STARTUPHOOK
        call    StartupHook
	#ENDIF

;/**********************************************************************
; * --------------------- KERNEL TASK SCHEDULER ------------------------
; *
; * The scheduler manage the task switching during application running.
; *
; **********************************************************************/
_sched
		GLOBAL  _sched
        #IFDEF POSTTASKHOOK
        call    PostTaskHook
        #ENDIF

        movlb   0
        bcf     kernelState, 0                   ; KERNEL mode
        movf 	id_tsk_run , w
        btfsc   STATUS, Z
        bra     _sched_exec_tsk_init
		
        clrf    FSR0H
        movlw   tsk_1_state_ID-1
        movwf   FSR0L
	
_sched_clr_run
        incf    FSR0L                        
        movlw	0x1F
        andwf   INDF0, w
        cpfseq	id_tsk_run
        bra     _sched_clr_run
        bcf     INDF0, 6                          ; task is no more running		 
        clrf    id_tsk_run
        
        bsf     FSR0L, 4		
        movlw	0x1F
        andwf   INDF0, w
        movwf	temp		

_test
        movlw	0x1F
        andwf   PREINC0, w      
        cpfseq  temp			
        bra     _sched_exec_tsk_init
        bra     _RR_routine

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -