cpu.c 2.9 KB
Newer Older
B
Bernard Xiong 已提交
1
/*
mysterywolf's avatar
mysterywolf 已提交
2
 * Copyright (c) 2006-2021, RT-Thread Development Team
B
Bernard Xiong 已提交
3
 *
4
 * SPDX-License-Identifier: Apache-2.0
B
Bernard Xiong 已提交
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 * Change Logs:
 * Date           Author       Notes
 * 2006-03-13     Bernard      first version
 */

#include <rtthread.h>
#include <sep4020.h>

extern rt_uint32_t rt_hw_interrupt_disable(void);

//TODO
#warning I DON'T KNOW IF THE MMU OPERATION WORKS ON SEP4020

/**
 * @addtogroup S3C24X0
 */
/*@{*/

mysterywolf's avatar
mysterywolf 已提交
24 25
#define ICACHE_MASK (rt_uint32_t)(1 << 12)
#define DCACHE_MASK (rt_uint32_t)(1 << 2)
B
Bernard Xiong 已提交
26 27 28 29

#ifdef __GNUC__
rt_inline rt_uint32_t cp15_rd(void)
{
mysterywolf's avatar
mysterywolf 已提交
30
    rt_uint32_t i;
B
Bernard Xiong 已提交
31

mysterywolf's avatar
mysterywolf 已提交
32 33
    asm ("mrc p15, 0, %0, c1, c0, 0":"=r" (i));
    return i;
B
Bernard Xiong 已提交
34 35 36 37
}

rt_inline void cache_enable(rt_uint32_t bit)
{
mysterywolf's avatar
mysterywolf 已提交
38 39 40 41 42 43 44
    __asm__ __volatile__(           \
        "mrc  p15,0,r0,c1,c0,0\n\t" \
        "orr  r0,r0,%0\n\t"         \
        "mcr  p15,0,r0,c1,c0,0"     \
        :                           \
        :"r" (bit)                  \
        :"memory");
B
Bernard Xiong 已提交
45 46 47 48
}

rt_inline void cache_disable(rt_uint32_t bit)
{
mysterywolf's avatar
mysterywolf 已提交
49 50 51 52 53 54 55
    __asm__ __volatile__(           \
        "mrc  p15,0,r0,c1,c0,0\n\t" \
        "bic  r0,r0,%0\n\t"         \
        "mcr  p15,0,r0,c1,c0,0"     \
        :                           \
        :"r" (bit)                  \
        :"memory");
B
Bernard Xiong 已提交
56 57 58 59 60 61
}
#endif

#ifdef __CC_ARM
rt_inline rt_uint32_t cp15_rd(void)
{
mysterywolf's avatar
mysterywolf 已提交
62
    rt_uint32_t i;
B
Bernard Xiong 已提交
63

mysterywolf's avatar
mysterywolf 已提交
64 65 66 67
    __asm
    {
        mrc p15, 0, i, c1, c0, 0
    }
B
Bernard Xiong 已提交
68

mysterywolf's avatar
mysterywolf 已提交
69
    return i;
B
Bernard Xiong 已提交
70 71 72 73
}

rt_inline void cache_enable(rt_uint32_t bit)
{
mysterywolf's avatar
mysterywolf 已提交
74 75 76 77 78 79 80 81
    rt_uint32_t value;

    __asm
    {
        mrc p15, 0, value, c1, c0, 0
        orr value, value, bit
        mcr p15, 0, value, c1, c0, 0
    }
B
Bernard Xiong 已提交
82 83 84 85
}

rt_inline void cache_disable(rt_uint32_t bit)
{
mysterywolf's avatar
mysterywolf 已提交
86 87 88 89 90 91 92 93
    rt_uint32_t value;

    __asm
    {
        mrc p15, 0, value, c1, c0, 0
        bic value, value, bit
        mcr p15, 0, value, c1, c0, 0
    }
B
Bernard Xiong 已提交
94 95 96 97 98 99 100 101 102
}
#endif

/**
 * enable I-Cache
 *
 */
void rt_hw_cpu_icache_enable()
{
mysterywolf's avatar
mysterywolf 已提交
103
    cache_enable(ICACHE_MASK);
B
Bernard Xiong 已提交
104 105 106 107 108 109 110 111
}

/**
 * disable I-Cache
 *
 */
void rt_hw_cpu_icache_disable()
{
mysterywolf's avatar
mysterywolf 已提交
112
    cache_disable(ICACHE_MASK);
B
Bernard Xiong 已提交
113 114 115 116 117 118 119 120
}

/**
 * return the status of I-Cache
 *
 */
rt_base_t rt_hw_cpu_icache_status()
{
mysterywolf's avatar
mysterywolf 已提交
121
    return (cp15_rd() & ICACHE_MASK);
B
Bernard Xiong 已提交
122 123 124 125 126 127 128 129
}

/**
 * enable D-Cache
 *
 */
void rt_hw_cpu_dcache_enable()
{
mysterywolf's avatar
mysterywolf 已提交
130
    cache_enable(DCACHE_MASK);
B
Bernard Xiong 已提交
131 132 133 134 135 136 137 138
}

/**
 * disable D-Cache
 *
 */
void rt_hw_cpu_dcache_disable()
{
mysterywolf's avatar
mysterywolf 已提交
139
    cache_disable(DCACHE_MASK);
B
Bernard Xiong 已提交
140 141 142 143 144 145 146 147
}

/**
 * return the status of D-Cache
 *
 */
rt_base_t rt_hw_cpu_dcache_status()
{
mysterywolf's avatar
mysterywolf 已提交
148
    return (cp15_rd() & DCACHE_MASK);
B
Bernard Xiong 已提交
149 150 151 152 153 154
}

/**
 * reset cpu by dog's time-out
 *
 */
155
RT_WEAK void rt_hw_cpu_reset()
B
Bernard Xiong 已提交
156 157
{

mysterywolf's avatar
mysterywolf 已提交
158 159
    /* enable watchdog */
    *(RP)(RTC_CTR) = 0x02;
B
Bernard Xiong 已提交
160

mysterywolf's avatar
mysterywolf 已提交
161 162
    /*Enable watchdog reset*/
    *(RP)(RTC_INT_EN) = 0x20;
B
Bernard Xiong 已提交
163

mysterywolf's avatar
mysterywolf 已提交
164 165
    /* Initialize watchdog timer count register */
    *(RP)(RTC_WD_CNT) = 0x0001;
B
Bernard Xiong 已提交
166

mysterywolf's avatar
mysterywolf 已提交
167
    while(1);   /* loop forever and wait for reset to happen */
B
Bernard Xiong 已提交
168

mysterywolf's avatar
mysterywolf 已提交
169
    /* NEVER REACHED */
B
Bernard Xiong 已提交
170 171 172 173 174 175
}

/**
 *  shutdown CPU
 *
 */
176
RT_WEAK void rt_hw_cpu_shutdown()
B
Bernard Xiong 已提交
177
{
mysterywolf's avatar
mysterywolf 已提交
178 179
    rt_uint32_t UNUSED level;
    rt_kprintf("shutdown...\n");
B
Bernard Xiong 已提交
180

mysterywolf's avatar
mysterywolf 已提交
181
    level = rt_hw_interrupt_disable();
B
Bernard Xiong 已提交
182

mysterywolf's avatar
mysterywolf 已提交
183
    RT_ASSERT(RT_NULL);
B
Bernard Xiong 已提交
184 185 186
}

/*@}*/