📄 utility.c
字号:
/********************** SGS-THOMSON MICROELECTRONICS ************************
FILENAME : UTILITY.C
VERSION : V1.0
DATE : JAN 1999
AUTHOR(s) : ASHISH RUDOLA / DEEPAK DOSHI
PROCESSOR : ST92195
DESCRIPTION : This file contains the source code for the user utilities.
MODIFICATIONS:
-
*****************************************************************************/
#include "macro.h"
#include "utility.h"
#include "tv_glob.h"
#include "register.h"
/*****************************************************************************
INPUTS : Number of microseconds to wait for
OUTPUTS : none
DESCRIPTION: This function generates a "n" microseconds delay.
Keep this function in assembler to control processing time.
Internal clock frequency = 24Mhz ( 1 INT = 1/24MHZ )
call: 12 INT clock cycles => 0.5us
sub: 6 INT clock cycles => 0.25us
jrnz: 6 INT clock cycles => 0.25us
nop: 2 INT clock cycles =>
ret: 8 INT clock cycles (internal stack) =>
dec: 4 INT clock cycles =>
Equation is
===========
Xus = (microsecond_counter+1) us
2 < Xus < 256
where us_count is the count generated by the macro
to obtain the delay of Xus
e.g: if for a Xus=10us delay us_count (microsecond counter) must be 9
*****************************************************************************/
void us_delay(void)
{
asm volatile ("
MD0: dec %0
nop
nop
nop
nop
nop
nop
nop
jpnz MD0
nop
nop" : "=R"(microsecond_counter) :);
}
/*****************************************************************************
INPUTS : Number of milliseconds to wait for
OUTPUTS : none
DESCRIPTION: This function generates a "n" milliseconds delay.
Keep this function in assembler to control processing time.
*****************************************************************************/
void ms_delay(void)
{
microsecond_delay(250);
microsecond_delay(250);
microsecond_delay(250);
microsecond_delay(240);
asm volatile ("sub %0,#1
jpnz ms_delay" : "=R"(millisecond_counter) :);
}
/*****************************************************************************
INPUTS : value - Parameter to process
mask - Value (within parameter) to keep and to shift
OUTPUTS : result
DESCRIPTION: This function outputs the requested value shifted to the right.
*****************************************************************************/
unsigned int get_value(unsigned int value, unsigned int mask)
{
value = value & mask;
while (!(mask & 0x01))
{
mask = mask >> 1;
value = value >> 1;
}
return value;
}
/*****************************************************************************
INPUTS : value - Parameter to process
mask - Value (within parameter) to keep and to shift
OUTPUTS : result
DESCRIPTION: This function outputs the requested value shifted to the left.
*****************************************************************************/
unsigned int set_value(unsigned int value, unsigned int mask)
{
unsigned int i; /* Temporary storage */
i =0;
while (!(mask & 0x01))
{
mask = mask >> 1;
i++;;
}
value = value << i;
return value;
}
/*****************************************************************************
INPUTS :
OUTPUTS :
DESCRIPTION:
*****************************************************************************/
unsigned int roll_inc(unsigned int value,unsigned int maximum_value)
{
value++;
if (value>maximum_value)
value = 0;
return value;
}
/*****************************************************************************/
unsigned int roll_source(unsigned int value,unsigned int maximum_value)
{
value++;
#ifndef OPTION_AV2
if(value == 2)
value++;
#endif
#ifndef OPTION_SVHS
if(value == 3)
value++;
#endif
#ifndef OPTION_RGB
if(value == 4)
value++;
#endif
if (value>maximum_value)
value = 0;
return value;
}
/*****************************************************************************
INPUTS :
OUTPUTS :
DESCRIPTION:
*****************************************************************************/
unsigned int roll_dec(unsigned int value,unsigned int maximum_value)
{
value--;
if (value ==0xffff)
value = maximum_value;
return value;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -