📄 ir.c
字号:
/********************** SGS-THOMSON MICROELECTRONICS ************************
FILENAME : IR.C
VERSION : V0.1
DATE : JAN 2000
AUTHOR(s) : Vick Zhong
PROCESSOR : ST92195
DESCRIPTION : This file contains the functions and definitions for decoding
remote IR transmissions, and for presenting them to the
command processor.
MODIFICATIONS:
-
*****************************************************************************/
#include "st92196.h"
#include "macro.h"
#include "tv_glob.h"
#include "register.h"
#include "ir.h"
#include "timer.h"
/*****************************************************************************
INPUTS : none
OUTPUTS : ir_command - Set to no previous command
IR_TIMER - Allow to read IR processor as soon as possible to
prevent false key on start-up
DESCRIPTION: This function initializes IR decoder variables.
*****************************************************************************/
void init_IR(void)
{
/* MCU initialize */
spp(IR_PG);
IRSCR &= ~IRSCR_IRDIS; /* IR interrupt forwarded to the core */
IRSCR &= ~IRSCR_FLSEL; /* spike filter on pulses narrower than 2us */
IRSCR |= IRSCR_POSED; /* IR edge selection for measurement on positive transition */
IRSCR &= ~IRSCR_NEGED; /* IR edge selection for measurement not on negative transition */
IRPR = 0x00; /* clear internal error flag */
/* software initialize */
/* Set to no previous command */
ir_command = NO_IR_COMMAND;
/* Set the IR timer to zero to prevent false key on start-up */
fast_timers[IR_TIMER] = 0;
}
/*****************************************************************************
INPUTS : IR_TIMER - As long as this timer is running, return the current
IR command
IR_PENDING - Set if an IR command is available
OUTPUTS : Current command
bit_counter - Cleared if no IR reception on going
IR_PENDING - Reset
DESCRIPTION: Process IR commands if the pending bit is set. If the pending bit
is not set, process the last IR command as long as the IR timer
is running. The purpose of this timer is to wait for the command
being received without sending the no IR command flag. If the IR
timer is equal to zero, it means no IR command are being received
(re-loaded by IR interrupts).
*****************************************************************************/
unsigned char get_IR(void)
{
/* Is there any pending IR command ? */
if (command_flags & IR_PENDING)
{
/* Yes, return this command */
command_flags = command_flags & ~IR_PENDING;
return ir_command;
}
else
{
/* Otherwise, flag no command */
return NO_IR_COMMAND;
}
}
/*****************************************************************************
INPUTS : ST9 Slice Timer registers
bit_counter - Contain number of bits already received
ir_buffer - Command being received
OUTPUTS :
bit_counter - +1, otherwise cleared
ir_command - New IR command
ir_buffer - Command being received (+1 bit)
IR_PENDING - Set if an IR command is available
IR_TIMER - Re-start IR timer if cleared
DESCRIPTION: This function processes the edge interrupt generated. It
measures parts of the signal generated by the IR receiver to
determime the incoming data. The data is classified as a zero
bit, one bit, or an error.
--------------------------------------------
| Parameter | Typical | Counter |
--------------------------------------------
| 1 | 7.6ms | 95 |
| 0 | 5.0ms | 62 |
| Toggle bit (1/0) | 7.6ms/5.0ms | 95/62 |
| Reference time | 7.6ms | 95 |
| Word distance | 121.6ms | |
--------------------------------------------
Word distance
<------------------------------------------------------------------->
_ _ _ _ _ _ _ _ _ _
_| |____| |____| |____| |____| |____| |____| |_ _| |____| |__ __| |____
Ref Toggle S2 S1 S0 b5 <---------> b0 Ref
*****************************************************************************/
#pragma interrupt(IR_IT)
void IR_IT(void)
{
unsigned int i; /* Temporary storage */
unsigned char tmp;
SAVE_PPR;
EI;
spp(IR_PG);
tmp = IRPR;
IRPR = 0x00; /* enable next interrupt */
if ( tmp == (unsigned char)0xFF)
it_counter = INVALID_COUNTER;
// fast_timers[IR_IMER] = IR_TX_LENGTH; /* set the 11bit receiving max-time */
/* Check bit range */
else
{
if( it_counter == INVALID_COUNTER )
it_counter = 0;
else
{
if ( ( tmp <= IR_1_MAX && tmp >= IR_1_MIN ) || (tmp <= IR_0_MAX && tmp >= IR_0_MIN) )
{
/* Identify receiving bit 0 or 1 */
if (tmp >= IR_1_MIN)
asm ("scf");
else
asm ("rcf");
/* save new IR bit */
asm ("rlcw %0" : "=R"(ir_buffer) : );
/* update counter */
it_counter++;
if (it_counter == 11)
{
/* Make sure we are allowed to process this command */
i = ir_buffer & IR_PREAMBLE;
if (i == IR_PREAMBLE) /* system code match;*/
{
/* FC: save toggle bit */
asm ("tm %H1,#0x02
jxz noset1
or %0,#1
jx q1
noset1:
and %0,#~1
q1:" : "=R"(toggle_flag) : "R"(ir_buffer));
/* Save new command */
asm ("ld %0,%L1" : "=R"(ir_command) : "R"(ir_buffer));
ir_command = ir_command & 0x3F;
command_flags = command_flags | IR_PENDING;
/* Start valid IR timer */
// fast_timers[IR_TIMER] = IR_TIMEOUT;
}
it_counter = INVALID_COUNTER;
}
}
else
/* If anything goes wrong, then re-start IR processing */
it_counter = INVALID_COUNTER;
}
}
/* Restore current page */
RESTORE_PPR;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -