/* * Make the table local in * linux-2.6.27.y/drivers/mtd/nand/nand_ecc.c */ void mkECCtbl(void) { unsigned char i; unsigned cp0, cp1, cp2, cp3, cp4, cp5; unsigned rp; cp0 = 0, cp1 = 0, cp2 = 0, cp3 = 0, cp4 = 0, cp5 = 0; rp = 0; /* * cp0 = bit6 ^ bit4 ^ bit2 ^ bit0; * cp1 = bit7 ^ bit5 ^ bit3 ^ bit1; * cp2 = bit5 ^ bit4 ^ bit1 ^ bit0; * cp3 = bit7 ^ bit6 ^ bit3 ^ bit2; * cp4 = bit3 ^ bit2 ^ bit1 ^ bit0; * cp5 = bit7 ^ bit6 ^ bit5 ^ bit4; * * rp = xor all bits; */ for (i = 0; i < 0xff; i++) { unsigned char xdata = 0; cp0 = BIT0(i) ^ BIT2(i) ^ BIT4(i) ^ BIT6(i); if (cp0) xdata |= 0x1; cp1 = BIT1(i) ^ BIT3(i) ^ BIT5(i) ^ BIT7(i); if (cp1) xdata |= 0x2; cp2 = BIT0(i) ^ BIT1(i) ^ BIT4(i) ^ BIT5(i); if (cp2) xdata |= 0x4; cp3 = BIT2(i) ^ BIT3(i) ^ BIT6(i) ^ BIT7(i); if (cp3) xdata |= 0x8; cp4 = BIT0(i) ^ BIT1(i) ^ BIT2(i) ^ BIT3(i); if (cp4) xdata |= 0x10; cp5 = BIT4(i) ^ BIT5(i) ^ BIT6(i) ^ BIT7(i); if (cp5) xdata |= 0x20; rp = BIT0(i) ^ BIT1(i) ^ BIT2(i) ^ BIT3(i) ^ BIT4(i) ^ BIT5(i) ^ BIT6(i) ^ BIT7(i); if (rp) xdata |= 0x40; ecc_tbl[i] = xdata; } }
static void calculate_ecc(const uint8_t *buf, uint8_t *ecc) { uint8_t p8, byte; int i; memset(ecc, 0, 3); for (i = 0; i < 256; i++) { byte = buf[i]; ecc[0] ^= (BIT0(byte) ^ BIT2(byte) ^ BIT4(byte) ^ BIT6(byte)) << 2; ecc[0] ^= (BIT1(byte) ^ BIT3(byte) ^ BIT5(byte) ^ BIT7(byte)) << 3; ecc[0] ^= (BIT0(byte) ^ BIT1(byte) ^ BIT4(byte) ^ BIT5(byte)) << 4; ecc[0] ^= (BIT2(byte) ^ BIT3(byte) ^ BIT6(byte) ^ BIT7(byte)) << 5; ecc[0] ^= (BIT0(byte) ^ BIT1(byte) ^ BIT2(byte) ^ BIT3(byte)) << 6; ecc[0] ^= (BIT4(byte) ^ BIT5(byte) ^ BIT6(byte) ^ BIT7(byte)) << 7; p8 = BIT0(byte) ^ BIT1(byte) ^ BIT2(byte) ^ BIT3(byte) ^ BIT4(byte) ^ BIT5(byte) ^ BIT6(byte) ^ BIT7(byte); if (p8) { ecc[2] ^= (0x1 << BIT0(i)); ecc[2] ^= (0x4 << BIT1(i)); ecc[2] ^= (0x10 << BIT2(i)); ecc[2] ^= (0x40 << BIT3(i)); ecc[1] ^= (0x1 << BIT4(i)); ecc[1] ^= (0x4 << BIT5(i)); ecc[1] ^= (0x10 << BIT6(i)); ecc[1] ^= (0x40 << BIT7(i)); } } ecc[0] = ~ecc[0]; ecc[1] = ~ecc[1]; ecc[2] = ~ecc[2]; ecc[0] |= 3; }
BYTE Pad::Update(BYTE valueP1) { BYTE newValue = 0; if(!BIT5(valueP1)) { BYTE start = (m_buttonsState[START] ? 0 : 1) << 3; BYTE select = (m_buttonsState[SELECT] ? 0 : 1) << 2; BYTE b = (m_buttonsState[B] ? 0 : 1) << 1; BYTE a = (m_buttonsState[A] ? 0 : 1); newValue = start | select | b | a; } else if(!BIT4(valueP1)) { BYTE down = (m_buttonsState[DOWN] ? 0 : 1) << 3; BYTE up = (m_buttonsState[UP] ? 0 : 1) << 2; BYTE left = (m_buttonsState[LEFT] ? 0 : 1) << 1; BYTE right = (m_buttonsState[RIGHT] ? 0 : 1); newValue = down | up | left | right; } else { //Desactivar los botones newValue = 0x0F; } return ((valueP1 & 0xF0) | newValue); }