Main Page   Data Structures   File List   Data Fields   Globals   Related Pages  

remote.cpp File Reference

#include <conio.h>
#include <stdio.h>
#include <string.h>
#include <dos.h>
#include <stdlib.h>
#include <stdarg.h>
#include <assert.h>
#include "amd186.h"
#include "remote.h"
#include "clib/rtos.h"
#include "clib/hwapi.h"

Go to the source code of this file.

Defines

#define RC_DMA_LEN   1024

Functions

unsigned long DecodeRC5 (unsigned const *samples)
 RC5 decoding state machine.

unsigned long DecodeNEC (unsigned const *samples)
 Decode NEC Timing.

unsigned long DecodeSAMSUNG (unsigned const *samples)
 Decode SAMSUNG timing.

void DecodeSamples (unsigned *samples, unsigned length)
 Try to decode raw timing samples.

void interrupt timerHandler (...)
 Timer interrupt handler.

int RC_KeyAvail ()
 Check for currently available keycodes.

unsigned long RC_GetKey ()
 Get a keycode from the queue.

void RC_Init ()
 This function must be called to initialize the remote control subsystem.

void RC_Done ()
 Shutdown the remote control subsystem, and free all used resources.


Variables

volatile unsigned dmabuf [RC_DMA_LEN]
 DMA buffer for timing samples.

void interrupt(* oldTimerHandler )(...)
 pointer to the old interrupt handler

unsigned long queue [RC_QUEUE_SIZE]
 queue for received keycodes

volatile int qHead
volatile int qCount


Define Documentation

#define RC_DMA_LEN   1024
 

Definition at line 36 of file remote.cpp.

Referenced by RC_Init(), and timerHandler().


Function Documentation

unsigned long DecodeNEC unsigned const *    samples [static]
 

Decode NEC Timing.

Todo:
implement Sanyo code with 13 vendor bits
Parameters:
samples  pointer to cooked timer values.
Returns:
valid keycode, or 0.

Definition at line 163 of file remote.cpp.

References NEC_MARGIN, NEC_PAUSE0, NEC_PAUSE1, NEC_PULSE, NEC_REPEAT, NEC_START1, NEC_START2, RCKEY_CODE, RCKEY_NEC, and RCKEY_REPEAT.

Referenced by DecodeSamples().

unsigned long DecodeRC5 unsigned const *    samples [static]
 

RC5 decoding state machine.

Based on Guy Carpenter's article "An Efficient Algorithm for Decoding RC5 Remote Control Signals", http://deep.clearwater.com.au/pcm-9574/rc5/rc5.html

The RC5 Protocol is widely used by various Vendors, among them Loewe, Philips, Grundig and Marantz

RC5 protocol:
SSTAAA AACCCCCC
Bits 13-12: Startbits (11 or 10)
Bits 11: Toggle bit (toggles between keypresses)
Bits 10-6: System address
Bits 5-0: Command code
Parameters:
samples  pointer to cooked timer samples.
Returns:
valid keycode, or 0 if either a timing or biphase error occured.

Definition at line 111 of file remote.cpp.

References RC5_LONG, RC5_MARGIN, RC5_SHORT, RCKEY_RC5, and RCKEY_REPEAT.

Referenced by DecodeSamples().

void DecodeSamples unsigned *    samples,
unsigned    length
[static]
 

Try to decode raw timing samples.

Because of the DMA logic, there may be more than one sample per signal edge - we have to clean up the timing buffer before we try to recognize any keycode. After cleanup, different decoder functions are run on the array. If a keycode was recognized, it gets added to the key queue

Parameters:
samples  array of raw timer samples
length  number of timer samples
Bug:
error on uneven cooked count! [and find out, why that happens, anyway..]

Definition at line 273 of file remote.cpp.

References DecodeNEC(), DecodeRC5(), DecodeSAMSUNG(), qCount, qHead, queue, RC_QUEUE_SIZE, RC_TRESHOLD, and TICKS_PER_uS.

Referenced by timerHandler().

unsigned long DecodeSAMSUNG unsigned const *    samples [static]
 

Decode SAMSUNG timing.

Parameters:
samples  pointer to cooked timer values.
Returns:
valid keycode, or 0.

Definition at line 213 of file remote.cpp.

References RCKEY_REPEAT, RCKEY_SAMSUNG, RTX_Get_System_Ticks(), SAM_MARGIN, SAM_PAUSE0, SAM_PAUSE1, SAM_PULSE, SAM_REPEATMS, SAM_START1, and SAM_START2.

Referenced by DecodeSamples().

void RC_Done  
 

Shutdown the remote control subsystem, and free all used resources.

Definition at line 416 of file remote.cpp.

References AMD_StopDma(), oldTimerHandler, PCB_T1CON, RC_DMACHANNEL, and TCON_STOP.

Referenced by main().

unsigned long RC_GetKey  
 

Get a keycode from the queue.

This function will block until a keycode is received. Use the RC_KeyAvail() function to check if there are codes in the queue.

See also:
RC_KeyAvail()
Returns:
valid keycode != 0

Definition at line 361 of file remote.cpp.

References qCount, qHead, queue, RC_KeyAvail(), RC_QUEUE_SIZE, and RTX_Sleep_Time().

Referenced by gfxTest().

void RC_Init  
 

This function must be called to initialize the remote control subsystem.

Definition at line 380 of file remote.cpp.

References AMD_EnableDrq(), AMD_StartDma(), DmaInfo::control, DCON_BW, DCON_DINC, DCON_DMIO, DCON_P, DCON_SSYNC, DCON_TC, dmabuf, DmaInfo::dstMem, DmaInfo::length, oldTimerHandler, PCB_T1CMPA, PCB_T1CNT, PCB_T1CON, pfe_enable_bus(), pfe_enable_pcs(), RC_DMA_LEN, RC_DMACHANNEL, DmaInfo::srcPort, TCON_CONT, TCON_INT, TCON_START, TCON_STOP, and timerHandler().

Referenced by main().

int RC_KeyAvail  
 

Check for currently available keycodes.

Any available keycodes can be retrieved with RC_GetKey()

See also:
RC_GetKey()
Returns:
number of available keycodes.

Definition at line 344 of file remote.cpp.

References qCount.

Referenced by RC_GetKey().

void interrupt timerHandler ...    [static]
 

Timer interrupt handler.

This interrupt is called whenever Timer 0 generates an overflow. If there are bytes in the dmabuf buffer, and the DMA position hasn't changed between two of the interrupts, we received a new datagram.

Definition at line 309 of file remote.cpp.

References AMD_GetDmaInfo(), AMD_StartDma(), DecodeSamples(), dmabuf, DmaInfo::dstMem, DmaInfo::length, oldTimerHandler, RC_DMA_LEN, and RC_DMACHANNEL.

Referenced by RC_Init().


Variable Documentation

volatile unsigned dmabuf[RC_DMA_LEN] [static]
 

DMA buffer for timing samples.

Definition at line 40 of file remote.cpp.

Referenced by RC_Init(), and timerHandler().

void interrupt(* oldTimerHandler)(...) [static]
 

pointer to the old interrupt handler

Definition at line 43 of file remote.cpp.

Referenced by RC_Done(), RC_Init(), and timerHandler().

volatile int qCount [static]
 

Definition at line 47 of file remote.cpp.

Referenced by DecodeSamples(), RC_GetKey(), and RC_KeyAvail().

volatile int qHead [static]
 

Definition at line 47 of file remote.cpp.

Referenced by DecodeSamples(), and RC_GetKey().

unsigned long queue[RC_QUEUE_SIZE] [static]
 

queue for received keycodes

Definition at line 46 of file remote.cpp.

Referenced by DecodeSamples(), and RC_GetKey().


Generated on Sun Aug 4 21:47:40 2002 for k/os mp3v2 by doxygen1.2.16