📄 runtables.c
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright 2005 OSR, Open Systems Resources, Inc. All rights Reserved.
//
// Module Name:
//
// runtables.c
//
// Abstract:
//
// We have precalculate so-called "run tables" that we use to
// encode the data from the device into RLC. Those tables
// are here in binary form.
//
// Author:
//
// Revision History:
//
#include "smscir.h"
#ifdef WPP_TRACING
#include "runtables.tmh"
#endif
//
//
// We're going to program the device to work like this:
//
// While the user is pressing a button on a remote,
// the CIRCC samples the IR stream once every 50usecs.
// When we pull a byte out of the FIFO, each bit in the
// byte will represent a sample, MSB first, with a "1"
// meaning an OFF and a "0" meaning an ON.. So if we
// receive a 0x3 from the FIFO, it represents a sample
// of "OFF for 100usecs, ON for 300":
//
// <0000 0011>
//
// Obviously, the next byte received is a continuation
// of the previous byte. So, 0x3 followed by 0x4 means
// "OFF for 100 usecs, ON for 400, OFF for 50, ON for 250"
//
// <0000 0011> <0000 0100>
//
// IOW, we read each set of bits in the byte from right to left
// and if the MSB of the previous byte is the same as the LSB
// of the next byte we continue counting.
//
// Pseudo code for how you calculate a give sample follows:
//
//
// FOR ALL BYTES IN THE SAMPLE {
//
// FOR ALL BITS 0-7 IN THE CURRENT BYTE {
//
// IF PREVBIT == CURBIT
//
// SUM += 50usec
//
// ELSE
//
// STORE SUM AS SAMPLE WITH APPROP. SIGN
// SUM = 50usec;
//
// }
// }
//
// This approach works, but causes a bit of a problem. We pull
// the bytes out of the FIFO in our ISR and complete class
// requests in our DpcForIsr. Neither one of these places
// are really appropriate for a tight loop that in the
// best case will spin 256 times (32byte FIFO * 8 bits). Usually
// we're doing at least 64bytes at a time in order to keep
// well ahead of the FIFO, so we're talking about a 512 iteration
// loop running at DISPATCH_LEVEL or above.
//
// Profiling has proven that calculating the ON/OFF samples using
// the above method causes the driver to spend in the range of
// 35% of its running time in the calculation routine, so obviously
// another approach would be much appreciated.
//
// What we've chosen to exploit in our implementation is the fact that
// the number of possible run combinations per byte is extremely
// finite, in the best case the byte can be described by one sample
// (i.e. ALL ON or ALL OFF) and the worst case being 8 samples
// (i.e. ON, OFF, ON, OFF, ON, OFF, ON, OFF). Also, the possible
// number of values returned by the device is finite at 0xFF.
//
// What this means is that every possible sample by an
// 8 bit value is expressible with a 256x8 matrix, indexed by the
// FIFO byte returned by the device. Once we have the appropriate
// row in the matrx we can walk across it to get the precalculated
// "runs" that make up this value.
//
// For example, the index at 0x3 would contain two entries:
//
// ENTRY 1: SUM == -100, BITS_IN_RUN == 2, ON? FALSE
//
// ENTRY 2: SUM == 300, BITS_IN_RUN == 6, ON? TRUE
//
// This allows the driver to easily walk a byte sample and transform
// it into what the class driver wants (50usec ON/OFF samples).
// The only thing that the driver now has to deal with is the overflow
// of one sample into another, which is trivially achieved with a
// "previous sample" pointer:.
//
// IF PREVSAMPLE->ON == CURSAMPLE->ON
//
// SUM += PREVSAMPLE->SUM
//
// (See SmscirEncodeAndEnqueueRLC for actual implementation).
//
// Once this new "precalulated table" method is implemented, even though
// the degenerate case still requires the same number of loops the amount
// of bit banging is decreased significantly. The fact that this
// approach is a huge win can be backed up by looking at before and
// after profiling analyses - once the table lookup is enabled
// the calculation routine drops to around 15% total time in the driver
//
// Because these tables are static they are here in binary form. Actual code
// for how the table is generated is located after the table data
//
SAMPLE_RUN SmscIrSampleTable[256][8] =
{
/* 000 */
0x00000190,0x00000008,0x01, // On for 8
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
/* 001 */
0xffffffce,0x00000001,0x00, // Off for 1
0x0000015e,0x00000007,0x01, // On for 7
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
/* 002 */
0x00000032,0x00000001,0x01, // On for 1
0xffffffce,0x00000001,0x00, // Off for 1
0x0000012c,0x00000006,0x01, // On for 6
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
/* 003 */
0xffffff9c,0x00000002,0x00, // Etc...
0x0000012c,0x00000006,0x01,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
/* 004 */
0x00000064,0x00000002,0x01,
0xffffffce,0x00000001,0x00,
0x000000fa,0x00000005,0x01,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
/* 005 */
0xffffffce,0x00000001,0x00,
0x00000032,0x00000001,0x01,
0xffffffce,0x00000001,0x00,
0x000000fa,0x00000005,0x01,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
/* 006 */
0x00000032,0x00000001,0x01,
0xffffff9c,0x00000002,0x00,
0x000000fa,0x00000005,0x01,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
/* 007 */
0xffffff6a,0x00000003,0x00,
0x000000fa,0x00000005,0x01,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
/* 008 */
0x00000096,0x00000003,0x01,
0xffffffce,0x00000001,0x00,
0x000000c8,0x00000004,0x01,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
/* 009 */
0xffffffce,0x00000001,0x00,
0x00000064,0x00000002,0x01,
0xffffffce,0x00000001,0x00,
0x000000c8,0x00000004,0x01,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
/* 010 */
0x00000032,0x00000001,0x01,
0xffffffce,0x00000001,0x00,
0x00000032,0x00000001,0x01,
0xffffffce,0x00000001,0x00,
0x000000c8,0x00000004,0x01,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
/* 011 */
0xffffff9c,0x00000002,0x00,
0x00000032,0x00000001,0x01,
0xffffffce,0x00000001,0x00,
0x000000c8,0x00000004,0x01,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
/* 012 */
0x00000064,0x00000002,0x01,
0xffffff9c,0x00000002,0x00,
0x000000c8,0x00000004,0x01,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
/* 013 */
0xffffffce,0x00000001,0x00,
0x00000032,0x00000001,0x01,
0xffffff9c,0x00000002,0x00,
0x000000c8,0x00000004,0x01,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
/* 014 */
0x00000032,0x00000001,0x01,
0xffffff6a,0x00000003,0x00,
0x000000c8,0x00000004,0x01,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
/* 015 */
0xffffff38,0x00000004,0x00,
0x000000c8,0x00000004,0x01,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
/* 016 */
0x000000c8,0x00000004,0x01,
0xffffffce,0x00000001,0x00,
0x00000096,0x00000003,0x01,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
/* 017 */
0xffffffce,0x00000001,0x00,
0x00000096,0x00000003,0x01,
0xffffffce,0x00000001,0x00,
0x00000096,0x00000003,0x01,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
/* 018 */
0x00000032,0x00000001,0x01,
0xffffffce,0x00000001,0x00,
0x00000064,0x00000002,0x01,
0xffffffce,0x00000001,0x00,
0x00000096,0x00000003,0x01,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
/* 019 */
0xffffff9c,0x00000002,0x00,
0x00000064,0x00000002,0x01,
0xffffffce,0x00000001,0x00,
0x00000096,0x00000003,0x01,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
/* 020 */
0x00000064,0x00000002,0x01,
0xffffffce,0x00000001,0x00,
0x00000032,0x00000001,0x01,
0xffffffce,0x00000001,0x00,
0x00000096,0x00000003,0x01,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
/* 021 */
0xffffffce,0x00000001,0x00,
0x00000032,0x00000001,0x01,
0xffffffce,0x00000001,0x00,
0x00000032,0x00000001,0x01,
0xffffffce,0x00000001,0x00,
0x00000096,0x00000003,0x01,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
/* 022 */
0x00000032,0x00000001,0x01,
0xffffff9c,0x00000002,0x00,
0x00000032,0x00000001,0x01,
0xffffffce,0x00000001,0x00,
0x00000096,0x00000003,0x01,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
/* 023 */
0xffffff6a,0x00000003,0x00,
0x00000032,0x00000001,0x01,
0xffffffce,0x00000001,0x00,
0x00000096,0x00000003,0x01,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
/* 024 */
0x00000096,0x00000003,0x01,
0xffffff9c,0x00000002,0x00,
0x00000096,0x00000003,0x01,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
/* 025 */
0xffffffce,0x00000001,0x00,
0x00000064,0x00000002,0x01,
0xffffff9c,0x00000002,0x00,
0x00000096,0x00000003,0x01,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
/* 026 */
0x00000032,0x00000001,0x01,
0xffffffce,0x00000001,0x00,
0x00000032,0x00000001,0x01,
0xffffff9c,0x00000002,0x00,
0x00000096,0x00000003,0x01,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
/* 027 */
0xffffff9c,0x00000002,0x00,
0x00000032,0x00000001,0x01,
0xffffff9c,0x00000002,0x00,
0x00000096,0x00000003,0x01,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
/* 028 */
0x00000064,0x00000002,0x01,
0xffffff6a,0x00000003,0x00,
0x00000096,0x00000003,0x01,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
/* 029 */
0xffffffce,0x00000001,0x00,
0x00000032,0x00000001,0x01,
0xffffff6a,0x00000003,0x00,
0x00000096,0x00000003,0x01,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
/* 030 */
0x00000032,0x00000001,0x01,
0xffffff38,0x00000004,0x00,
0x00000096,0x00000003,0x01,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
/* 031 */
0xffffff06,0x00000005,0x00,
0x00000096,0x00000003,0x01,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
/* 032 */
0x000000fa,0x00000005,0x01,
0xffffffce,0x00000001,0x00,
0x00000064,0x00000002,0x01,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
0x00000000,0x00000000,0x00,
/* 033 */
0xffffffce,0x00000001,0x00,
0x000000c8,0x00000004,0x01,
0xffffffce,0x00000001,0x00,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -