surenyi
6 years ago
6 changed files with 93 additions and 0 deletions
@ -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(); |
|||
} |
|||
} |
|||
|
@ -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 |
@ -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 |
|||
|
Loading…
Reference in new issue