149 lines
3.3 KiB
C
149 lines
3.3 KiB
C
|
/*
|
|||
|
* Copyright (c) 2006-2018, RT-Thread Development Team
|
|||
|
*
|
|||
|
* SPDX-License-Identifier: Apache-2.0
|
|||
|
*
|
|||
|
* Change Logs:
|
|||
|
* Date Author Notes
|
|||
|
* 2017-07-24 Tanek the first version
|
|||
|
* 2018-11-12 Ernest Chen modify copyright
|
|||
|
*/
|
|||
|
//#include "bsp_led.h"
|
|||
|
//#include "device.h"
|
|||
|
//#include "device_drv_config.h"
|
|||
|
#include "main.h"
|
|||
|
#include <rthw.h>
|
|||
|
#include <rtthread.h>
|
|||
|
void SystemClock_Config(void);
|
|||
|
#if 1
|
|||
|
#define _SCB_BASE (0xE000E010UL)
|
|||
|
#define _SYSTICK_CTRL (*(rt_uint32_t *)(_SCB_BASE + 0x0))
|
|||
|
#define _SYSTICK_LOAD (*(rt_uint32_t *)(_SCB_BASE + 0x4))
|
|||
|
#define _SYSTICK_VAL (*(rt_uint32_t *)(_SCB_BASE + 0x8))
|
|||
|
#define _SYSTICK_CALIB (*(rt_uint32_t *)(_SCB_BASE + 0xC))
|
|||
|
#define _SYSTICK_PRI (*(rt_uint8_t *)(0xE000ED23UL))
|
|||
|
|
|||
|
// Updates the variable SystemCoreClock and must be called
|
|||
|
// whenever the core clock is changed during program execution.
|
|||
|
extern void SystemCoreClockUpdate(void);
|
|||
|
|
|||
|
// Holds the system core clock, which is the system clock
|
|||
|
// frequency supplied to the SysTick timer and the processor
|
|||
|
// core clock.
|
|||
|
extern uint32_t SystemCoreClock;
|
|||
|
|
|||
|
static uint32_t _SysTick_Config(rt_uint32_t ticks)
|
|||
|
{
|
|||
|
if ((ticks - 1) > 0xFFFFFF)
|
|||
|
{
|
|||
|
return 1;
|
|||
|
}
|
|||
|
|
|||
|
_SYSTICK_LOAD = ticks - 1;
|
|||
|
_SYSTICK_PRI = 0xFF;
|
|||
|
_SYSTICK_VAL = 0;
|
|||
|
_SYSTICK_CTRL = 0x07;
|
|||
|
|
|||
|
return 0;
|
|||
|
}
|
|||
|
|
|||
|
// us<75><73><EFBFBD><EFBFBD>ʱ
|
|||
|
void rt_hw_us_delay(rt_uint32_t us)
|
|||
|
{
|
|||
|
u32 ticks;
|
|||
|
u32 told,tnow,tcnt=0;
|
|||
|
u32 reload=SysTick->LOAD; //LOAD<41><44>ֵ
|
|||
|
ticks=us; //<2F><>Ҫ<EFBFBD>Ľ<EFBFBD><C4BD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
rt_enter_critical(); //<2F><>ֹOS<4F><53><EFBFBD>ȣ<EFBFBD><C8A3><EFBFBD>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD>us<75><73>ʱ
|
|||
|
told=SysTick->VAL; //<2F>ս<EFBFBD><D5BD><EFBFBD>ʱ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>ֵ
|
|||
|
while(1)
|
|||
|
{
|
|||
|
tnow=SysTick->VAL;
|
|||
|
if(tnow!=told)
|
|||
|
{
|
|||
|
if(tnow<told)tcnt+=told-tnow; //<2F><><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>һ<EFBFBD><D2BB>SYSTICK<43><4B>һ<EFBFBD><D2BB><EFBFBD>ݼ<EFBFBD><DDBC>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϳ<EFBFBD><CDBF><EFBFBD><EFBFBD><EFBFBD>.
|
|||
|
else tcnt+=reload-tnow+told;
|
|||
|
told=tnow;
|
|||
|
if(tcnt>=ticks)break; //ʱ<>䳬<EFBFBD><E4B3AC>/<2F><><EFBFBD><EFBFBD>Ҫ<EFBFBD>ӳٵ<D3B3>ʱ<EFBFBD><CAB1>,<2C><><EFBFBD>˳<EFBFBD>.
|
|||
|
}
|
|||
|
};
|
|||
|
rt_exit_critical(); //<2F>ָ<EFBFBD>OS<4F><53><EFBFBD><EFBFBD>
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
#endif
|
|||
|
|
|||
|
#if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP)
|
|||
|
#define RT_HEAP_SIZE 5*1024//1536
|
|||
|
//static uint32_t rt_heap[RT_HEAP_SIZE]; // heap default size: 6K(1536 * 4)
|
|||
|
RT_WEAK void *rt_heap_begin_get(void)
|
|||
|
{
|
|||
|
// return rt_heap;
|
|||
|
return (void *)0x10000000;
|
|||
|
}
|
|||
|
|
|||
|
RT_WEAK void *rt_heap_end_get(void)
|
|||
|
{
|
|||
|
// return rt_heap + RT_HEAP_SIZE;
|
|||
|
return (void *)(0x10000000+64*1024/4);
|
|||
|
}
|
|||
|
#endif
|
|||
|
|
|||
|
|
|||
|
|
|||
|
void mpu_init(void)
|
|||
|
{
|
|||
|
//ѡ<><D1A1>0<EFBFBD><30>region
|
|||
|
MPU->RNR=0;
|
|||
|
//ѡ<><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
|
|||
|
MPU->RBAR=0x00000000;
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
MPU->RASR=((0x3)<<MPU_RASR_AP_Pos)|((31)<<MPU_RASR_SIZE_Pos)|(0x5<<16)|1;
|
|||
|
//<2F><><EFBFBD><EFBFBD>MPU
|
|||
|
MPU->CTRL=1;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* This function will initial your board.
|
|||
|
*/
|
|||
|
void rt_hw_board_init()
|
|||
|
{
|
|||
|
NVIC_SetVectorTable(NVIC_VectTab_FLASH,(u32)128*1024);
|
|||
|
_SysTick_Config (SystemCoreClock/1000);
|
|||
|
// LED_Init(); // LED初始<E5889D><E5A78B>?
|
|||
|
// Usart_Config(); // 串口初始<E5889D><E5A78B>?
|
|||
|
// SDRAM_Init(); // sdram要先于emwin之前初始<E5889D><E5A78B>?
|
|||
|
// sFLASH_Init();
|
|||
|
//SPI_Flash_Init();
|
|||
|
mymem_init();
|
|||
|
rt_system_heap_init(rt_heap_begin_get(),rt_heap_end_get());
|
|||
|
irq_vector_init();
|
|||
|
mpu_init();
|
|||
|
Touch_Init(); // 触摸屏初始化
|
|||
|
USART3_Init();
|
|||
|
RANDOM_Init();
|
|||
|
USBD_InitAsVcp ( );
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
void OS_CPU_SysTickHandler(void)
|
|||
|
{
|
|||
|
/* enter interrupt */
|
|||
|
rt_interrupt_enter();
|
|||
|
|
|||
|
rt_tick_increase();
|
|||
|
|
|||
|
/* leave interrupt */
|
|||
|
rt_interrupt_leave();
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* @brief System Clock Configuration
|
|||
|
* @retval None
|
|||
|
*/
|
|||
|
__weak void SystemClock_Config(void)
|
|||
|
{
|
|||
|
}
|