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

📄 system.h

📁 一个简单实用的嵌入式操作系统,实现了嵌入式操作系统的基本模块:内存管理、系统调度 、系统调用等。
💻 H
字号:
/*
 *  include/asm-cc/ads/system.h
 *
 *  Copyright (C) 2007/12/10 Wang Qiang
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * histroy:
 *  2008/04/23, wang qiang, rurality@gmail.com 
 *      1) add the en_cpsr_irq, dis_cpsr_irq
 *
 */

#ifndef _SYSTEM_H_
#define _SYSTEM_H_

// flush the I-Cache
#define     icache_clear \
    __asm { mcr p15, 0, 0, c7, c5, 0 }
// flush the D-Cache
#define     dcache_clear \
    __asm { mcr p15, 0, 0, c7, c6, 0 }
// flush the I-Cache & D-Cache
#define     cache_clear \
    __asm { mcr p15, 0, 0, c7, c7, 0 }

__inline int iskernel(void) 
{
    int __res; 
    __asm { 
        mrs __res,  CPSR ; 
        ands __res, __res, 0xF ; 
        eorne __res, __res, 0xF ; 
    }
   return __res;
}

__inline int isirq(void)
{
    int __res;
    __asm {
        mrs __res,CPSR;
        and __res,__res,#0xF;
        cmp  __res, #0x2;
        movne __res, #0;
    }
   return __res;
}

#define en_spsr_irq()       \
    __asm {                 \
        mrs r0, SPSR ;      \
        bic r0, r0, 0x80 ;  \
        msr SPSR_c, r0 ;    \
        } 

#define dis_spsr_irq()      \
    __asm {                 \
        mrs r0, SPSR ;      \
        orr r0,r0, 0x80 ;   \
        msr SPSR_c, r0 ;    \
        }

#define en_cpsr_irq()       \
    __asm {                 \
        mrs r0, CPSR ;      \
        bic r0, r0, 0x80 ;  \
        msr CPSR_c, r0 ;    \
        } 

#define dis_cpsr_irq()      \
    __asm {                 \
        mrs r0, CPSR ;      \
        orr r0,r0, 0x80 ;   \
        msr CPSR_c, r0 ;    \
        }

//unsigned int do_div(unsigned int *n,unsigned int base)
//{
//    unsigned int __res;
//    switch(base) {
//        case 8,16:
//            power of 2 dividor is special
//            *n = *n % 2^n        remaider
//            __res = *n/2^n        dividend
//            break;
//        case 10:
//            use the magic number 0xCCCCCCCD,to convert
//            div into mul
//            break;
//        default:
//            other return 35(Z)
//            break;
//    }
//    return __res;
//}

__inline unsigned int do_div(unsigned int *n, int base) 
{
    unsigned int __res;
    __asm {
        cmp     base, #16
        beq     hex
        cmp     base, #10
        beq     dec 
        cmp     base, #8 
        beq     oct 
        b       def 
        oct:
        and     __res, *n, #7 
        mov     *n, *n, asr #3
        b       end
        dec:
        mov     r5, 0xCCCCCCCD 
        umull   __res, r6, r5, *n
        mov     r5, r6, lsr #3 
        add     r6, r5, r5, lsl #2
        sub     __res, *n, r6, lsl #1
        mov     *n, r5
        b       end
        hex:
        and     __res, *n, #15
        mov     *n, *n, lsr #4
        b       end
        def:
        mov     __res, #35
        mov     *n, #0
        end:
    }
    return __res;
}

#endif // _SYSTEM_H_

⌨️ 快捷键说明

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