initial commit

This commit is contained in:
2026-04-12 22:20:18 +08:00
commit 190c2edbb2
155 changed files with 36314 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
#include "common_func.h"
void RegWrite(unsigned int addr,unsigned int var)
{
*((volatile unsigned int *)(addr)) = var;
}
unsigned int RegRead(unsigned int addr)
{
return (*((volatile unsigned int *)(addr)));
}
//memcpy 32bit
void SaveMemory(unsigned int *DestAddr, unsigned int *SrcAddr, unsigned int Size)
{
unsigned int i;
for (i = 0; i < Size; i += 1)
*(U32*)(DestAddr + i) = SrcAddr[i];
}

View File

@@ -0,0 +1,63 @@
#include "confreg_time.h"
#include "time.h"
unsigned long __attribute__((weak)) CONFREG_TIMER_BASE = 0xbf20f100;
unsigned long __attribute__((weak)) CONFREG_CLOCKS_PER_SEC = 50000000L;
unsigned long __attribute__((weak)) CORE_CLOCKS_PER_SEC = 33000000L;
unsigned long get_confreg_clock_count()
{
unsigned long contval;
asm volatile(
"la.local $r25, CONFREG_TIMER_BASE\n\t"
"ld.w $r25, $r25, 0\n\t"
"ld.w %0,$r25,0\n\t"
:"=r"(contval)
:
:"$r25"
);
return contval;
}
unsigned long get_cpu_clock_count()
{
unsigned long contval;
asm volatile(
"rdcntvl.w %0\n\t"
:"=r"(contval)
);
return contval;
}
unsigned long get_clock_count()
{
#ifdef USE_CPU_CLOCK_COUNT
return get_cpu_clock_count();
#else
return get_confreg_clock_count();
#endif
}
unsigned long get_ns(void)
{
unsigned long n=0;
n = get_clock_count();
#ifdef USE_CPU_CLOCK_COUNT
n=n*(NSEC_PER_USEC/(CORE_CLOCKS_PER_SEC/USEC_PER_SEC));
#else
n=n*(NSEC_PER_USEC/(CONFREG_CLOCKS_PER_SEC/USEC_PER_SEC));
#endif
return n;
}
unsigned long get_us(void)
{
unsigned long n=0;
n = get_clock_count();
#ifdef USE_CPU_CLOCK_COUNT
n=n/(CORE_CLOCKS_PER_SEC/USEC_PER_SEC);
#else
n=n/(CONFREG_CLOCKS_PER_SEC/USEC_PER_SEC);
#endif
return n;
}

View File

@@ -0,0 +1,30 @@
#include "core_time.h"
#include "confreg_time.h"
// default : 33 mhz
void delay_ms(uint32_t ms)
{
unsigned char overflow;
unsigned long time,target_time,time_r,target_time_r;
time = get_cpu_clock_count();
time_r = time;
target_time = time + (CORE_CLOCKS_PER_SEC/1000)*ms;
target_time_r = target_time;
if( target_time < time){
overflow = 1;
target_time = 0xffffffff;
}
while(time < target_time){
time = get_cpu_clock_count();
if (time_r > time) break;
time_r = time;
}
if (overflow) {
while( time < target_time_r){
time = get_cpu_clock_count();
}
overflow = 0;
}
}

View File

@@ -0,0 +1,27 @@
#include "dvi.h"
// 设置坐标和颜色的绘图函数
void DVI_Draw_Rect(uint32_t x, uint32_t y, uint32_t l, uint32_t w)
{
// 创建坐标值x 和 y 分别占用 12 位; width 和 height 用于定义范围
uint32_t coordinates = ((x & 0xFFFF)<<16) | (y & 0xFFFF);
uint32_t size = ((l & 0xFFFF)<<16) | (w & 0xFFFF);
// 写入坐标和颜色寄存器
RegWrite(DVI_RECT_DIR, coordinates);
RegWrite(DVI_RECT_L_W, size);
}
// 在指定位置绘制一个点的函数
void DVI_Draw_SQU(uint32_t x, uint32_t y, uint32_t r)
{
// 创建坐标值x 和 y 分别占用 12 位; width 和 height 用于定义范围
uint32_t coordinates = ((x & 0xFFFF)<<16) | (y & 0xFFFF);
uint32_t size = ((r & 0xFFFF)<<16) | (r & 0xFFFF);
// 写入坐标和颜色寄存器
RegWrite(DVI_SQU_DIR, coordinates);
RegWrite(DVI_SQU_R, size);
}

View File

@@ -0,0 +1,28 @@
#include "led.h"
// set leds pin
void setLedPin(uint32_t data)
{
RegWrite(LEDS_GPIO_DATA,data);
}
// toggle one led pin
void toggleLedPin(uint32_t data)
{
uint32_t led_data;
uint32_t process_bit;
led_data = RegRead(LEDS_GPIO_DATA);
process_bit = 0x1 << data;
if(led_data & process_bit)
{
led_data = led_data & (~process_bit);
}
else
{
led_data = led_data | process_bit;
}
RegWrite(LEDS_GPIO_DATA,led_data);
}

View File

@@ -0,0 +1,17 @@
// seg7.c
#include "seg7.h"
void setSegNum(uint32_t seg1,uint32_t num1,uint32_t seg2,uint32_t num2)
{
// select seg
uint32_t select_seg = ((seg1<<2) + seg2);
RegWrite(SEG7_SELECT,select_seg);
// set num
uint32_t num_seg = ((num1<<4) + num2);
RegWrite(SEG7_NUM,num_seg);
}