1 /*
2  * Copyright (c) 2006-2021, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date                Author         Notes
8  * 2010-07-09     Bernard        first version
9  * 2010-09-11     Bernard        add CPU reset implementation
10  * 2015-07-06     chinesebear  modified for loongson 1c
11  */
12 
13 #include <rtthread.h>
14 #include "gs232.h"
15 
16 /**
17  * @addtogroup Loongson GS232
18  */
19 
20 /*@{*/
21 
22 /**
23  * this function will reset CPU
24  *
25  */
rt_hw_cpu_reset(void)26 void rt_hw_cpu_reset(void)
27 {
28     /* open the watch-dog */
29     WDT_EN = 0x01;      /* watch dog enable */
30     WDT_TIMER = 0x01;   /* watch dog will be timeout after 1 tick */
31     WDT_SET = 0x01;     /* watch dog start */
32 
33     rt_kprintf("reboot system...\n");
34     while (1);
35 }
36 
37 #define Hit_Invalidate_I    0x10
38 #define Hit_Invalidate_D    0x11
39 #define CONFIG_SYS_CACHELINE_SIZE   32
40 #define Hit_Writeback_Inv_D 0x15
41 
42 
flush_cache(unsigned long start_addr,unsigned long size)43 void flush_cache(unsigned long start_addr, unsigned long size)
44 {
45     unsigned long lsize = CONFIG_SYS_CACHELINE_SIZE;
46     unsigned long addr = start_addr & ~(lsize - 1);
47     unsigned long aend = (start_addr + size - 1) & ~(lsize - 1);
48 
49     while (1) {
50         cache_op(Hit_Writeback_Inv_D, addr);
51         cache_op(Hit_Invalidate_I, addr);
52         if (addr == aend)
53             break;
54         addr += lsize;
55     }
56 }
57 
58 
59 /*@}*/
60 
61