Browse Source

add delay module to dspkit

Signed-off-by: surenyi <surenyi82@163.com>
master
surenyi 6 years ago
parent
commit
09dcd2c1d1
  1. 2
      packages/vsky/dspkit/driver/board.c
  2. 27
      packages/vsky/dspkit/driver/delay.c
  3. 1
      packages/vsky/dspkit/driver/driver_private.h
  4. 12
      packages/vsky/dspkit/driver/tsc.asm
  5. 49
      packages/vsky/dspkit/include/delay.h
  6. 2
      packages/vsky/dspkit/package.bld

2
packages/vsky/dspkit/driver/board.c

@ -76,6 +76,8 @@ static void active_devices(struct device *dev)
int board_init(unsigned int dtb)
{
delay_init();
if (unflatten_device_tree((void *)dtb)) {
printf("unflatten device tree failed\n");
return -1;

27
packages/vsky/dspkit/driver/delay.c

@ -0,0 +1,27 @@
#include "delay.h"
#include "driver_private.h"
extern unsigned int get_core_frequency(void);
unsigned long system_frequency()
{
return get_core_frequency();
}
void udelay(unsigned long long us)
{
unsigned long long cyc = us * (system_frequency() / 1000000); /* in HZ */
delay_ticks(cyc);
}
void delay_ticks(unsigned long long tick)
{
unsigned long long c, e;
c = system_ticks();
e = c + tick;
while (c < e) {
c = system_ticks();
}
}

1
packages/vsky/dspkit/driver/driver_private.h

@ -1,6 +1,7 @@
#ifndef __DRIVER_PRIVATE_H__
#define __DRIVER_PRIVATE_H__
void delay_init();
extern struct driver __cpu;
#endif

12
packages/vsky/dspkit/driver/tsc.asm

@ -0,0 +1,12 @@
.global delay_init
delay_init:
BNOP B3, 4
MVC A4, TSCL
.global system_ticks
system_ticks:
BNOP B3, 2
MVC TSCL, B0
MVC TSCH, B1
|| MV B0, A4
MV B1, A5

49
packages/vsky/dspkit/include/delay.h

@ -0,0 +1,49 @@
#ifndef __DELAY_H__
#define __DELAY_H__
#ifdef __cplusplus
extern "C" {
#endif
/*
* get system cycles from start.
*/
unsigned long long system_ticks(void);
/*
* get the current system frequncy.
*/
unsigned long system_frequency();
/*
* delay cycles.
*/
void delay_ticks(unsigned long long tick);
/*
* delay microsencods.
*/
void udelay(unsigned long long us);
/*
* delay millseconds.
*/
static void msleep(unsigned long long ms)
{
udelay(ms * 1000);
}
/*
* system cycles from start.
*/
static unsigned long long ticks_offset(unsigned long start)
{
unsigned long long c = system_ticks();
return (c - start) + 1;
}
#ifdef __cplusplus
}
#endif
#endif

2
packages/vsky/dspkit/package.bld

@ -15,6 +15,8 @@ var drvFiles = [
"driver/xstring.c",
"driver/cpu.c",
"driver/board.c",
"driver/tsc.asm",
"driver/delay.c",
];
var elfFiles = [

Loading…
Cancel
Save