int parity_check(struct lista *p) { if(p==NULL) return 1; else return (!(p->num % 2) && parity_check(p->next)); }
unsigned int build_flit (int flitType, unsigned int payload) { unsigned int flit = 0 | \ (payload << PAYLOAD_OFFSET) | \ (flitType << FLIT_TYPE_OFFSET); unsigned int parity = parity_check(flit); return flit | parity; }
int main(void) { struct lista *testa=NULL; int n,max; testa = crea_lista(testa); n = calcola_elementi(testa); printf("Numero elementi: %d\n",n); stamp_inverso(testa); printf("Max: %d\n",rit_max(testa)); printf("Elementi pari: %d\n",parity_check(testa)); system("pause"); }
/* * Generate a table of matrix products to update a 32-bit PRBS generator. */ void PrbsGenerator::gen_prbs_table() { int i; for (i = 0; i < 4; ++i) { int j; for (j = 0; j < 256; ++j) { uint32_t prbs_accum = ((uint32_t)j << (i * 8)); int k; for (k = 0; k < 8; ++k) { prbs_accum = (prbs_accum << 1) ^ parity_check(prbs_accum & d_polynomial); } d_prbs_table[i][j] = (prbs_accum & 0xff); } } }
/* * Generate a table of matrix products to update a 32-bit PRBS generator. */ void gen_prbs_table(void* args) { prbs_data* data = (prbs_data*)args; int i; for (i = 0; i < 4; ++i) { int j; for (j = 0; j < 256; ++j) { unsigned long prbs_accum = ((unsigned long)j << (i * 8)); int k; for (k = 0; k < 8; ++k) { prbs_accum = (prbs_accum << 1) ^ parity_check(prbs_accum & data->polynomial); } data->prbs_table[i][j] = (prbs_accum & 0xff); } } }
int ImagerDoc::check_copy(void * in ) { int block_status = 0; int section_status = 0; //int sub_status = 0; block_status = (crcCheck(in, BLOCK0_BSZ) == MAGIC_CRC); // 0 is fail if (block_status == 0) { //std::cout << "block id = " << gvar.blockId() << ", count = " << gvar.blockCount(); //std::cout << ": Crc Check failed (in imagerdoc copy subroutine)\n" << std::flush; section_status = parity_check(in); // try to recover // fail ==1, pass=0 //for (int j=0; j<6; j++) { // sub_status += ( (section_status & (2 << j)) == (2 << j)); //} //std::cout << sub_status << " sections of block 0 failed parity check\n"; if ((section_status & 2) == 2) { //std::cout << " section 1 of block 0, count = " << gvar.blockCount() << " failed parity check\n"; // check some key values } else { // for now, if section 1 passes parity assume it's values are ok // most of the code only uses values from section 1 block_status = 1; } } return(block_status); }
bool decoder::parity_check_all(){ return parity_check(21, 28) and parity_check(29, 35) and parity_check(36, 58); }
int16_t magneto_hal_write( uint16_t address, int16_t value ) { uint16_t command; switch( current_mode ) { case MAGNETO_I2C: { uint8_t buffer[ AS5048A_MAX_READ_SIZE ]; buffer[1] = ( uint8_t )value & 0xff; switch( address ) { case AS5048A_CLEAR_ERROR_FLAG: break; case AS5048A_PROGRAMMING_CONTROL: buffer[0] = 0x03; break; case AS5048A_OTP_REGISTER_ZERO_POS_HIGH: buffer[0] = 0x16; break; case AS5048A_OTP_REGISTER_ZERO_POS_LOW: buffer[0] = 0x17; break; } #if defined( __MIKROC_PRO_FOR_ARM__ ) #if defined( STM32F107VC ) || defined( STM32F407VG ) || \ defined( STM32F030C6 ) || defined( STM32F746VG ) i2c_start_p(); i2c_write_p( i2c_address, buffer, 2, END_MODE_STOP ); #elif defined( LM3S1165 ) || defined( TM4C129ENCZAD ) i2c_set_slave_address_p( i2c_address, _I2C_DIR_MASTER_TRANSMIT ); i2c_write_p( buffer[0], _I2C_MASTER_MODE_BURST_SEND_START ); i2c_write_p( buffer[1], _I2C_MASTER_MODE_BURST_SEND_FINISH ); #endif #elif defined(__MIKROC_PRO_FOR_FT90x__) i2c_set_slave_address_p( i2c_address ); //TODO: Send bytes i2c_write_p( buffer[0] ); i2c_write_p( buffer[1] ); #elif defined(__MIKROC_PRO_FOR_AVR__) || \ defined(__MIKROC_PRO_FOR_8051__) || \ defined(__MIKROC_PRO_FOR_DSPIC__) || \ defined(__MIKROC_PRO_FOR_PIC32__) || \ defined(__MIKROC_PRO_FOR_PIC__) i2c_start_p(); i2c_write_p( i2c_address | WRITE ); i2c_write_p( buffer[0] ); i2c_write_p( buffer[1] ); i2c_stop_p(); #elif defined( __GNUC__) printf( "Start\n" ); printf( "Address: 0x%02x\n", address ); printf( "\tData: 0x%02x\n", value ); #endif } break; case MAGNETO_SPI: #if defined ( __GNUC__ ) cs_low(); printf( "%s\n", byte_to_binary( command ) ); // Write command cs_high(); cs_low(); printf( "%s\n", byte_to_binary( value ) ); cs_high(); #else command = 0x00 | ( address & 0x3FFF ); command |= ( ( int16_t )parity_check( command ) << AS5048A_PARITY_BIT ); if( device_count == 1 ) { cs_low(); spi_write_p( ( command >> 8 ) & 0xff ); spi_write_p( command & 0xff ); cs_high(); value = 0x00 | ( value & 0x3FFF ); value |= ( ( int16_t )parity_check( value ) << AS5048A_PARITY_BIT ); cs_low(); spi_write_p( ( value >> 8 ) & 0xff ); spi_write_p( value & 0xff ); cs_high(); cs_low(); command = ( spi_read_p( 0x00 ) << 8 ); command |= spi_read_p( 0x00 ); cs_high(); } else {
int decode_LDPC_MinSum_atn(LDPC *ldpc, int n_iter) { int iter, i, j, k; int s; double f; double tmp; double min; // ノードの初期化 for(i=0;i<ldpc->n_row;i++){ init_darray(ldpc->C_llr[i], 0, ldpc->CV_1p[i]); } for(i=0;i<ldpc->n_col;i++){ init_darray(ldpc->V_llr[i], 0, ldpc->VC_1p[i]); } for(iter=0;iter<n_iter;iter++){ // 行処理 for(i=0;i<ldpc->n_row;i++){ for(j=0;j<ldpc->CV_1p[i];j++){ s = f = 0; min = 99999; for(k=0;k<j;k++){ tmp = ldpc->llr[ldpc->CV_1[i][k]]+ldpc->V_llr[ldpc->CV_1[i][k]][ldpc->CV_1_inv[i][k]]; s += sign(tmp); if(min>fabs(tmp)){ min = fabs(tmp); } } for(k=j+1;k<ldpc->CV_1p[i];k++){ tmp = ldpc->llr[ldpc->CV_1[i][k]]+ldpc->V_llr[ldpc->CV_1[i][k]][ldpc->CV_1_inv[i][k]]; s += sign(tmp); if(min>fabs(tmp)){ min = fabs(tmp); } } ldpc->C_llr[i][j] = (s&1) ? -0.7*min : 0.7*min; } } // 一時推定語 for(i=0;i<ldpc->n_col;i++){ tmp = 0; for(j=0;j<ldpc->VC_1p[i];j++){ tmp += ldpc->C_llr[ldpc->VC_1[i][j]][ldpc->VC_1_inv[i][j]]; } tmp += ldpc->llr[i]; ldpc->variablebits[i] = (tmp>0) ? 0 : 1; } // パリティチェック if(!parity_check(ldpc)){ for(i=0;i<ldpc->n_effinf;i++){ ldpc->infbits_out[i] = ldpc->variablebits[i+ldpc->n_parity]; } return 0; } // 列処理 for(i=0;i<ldpc->n_col;i++){ for(j=0;j<ldpc->VC_1p[i];j++){ f = 0; for(k=0;k<j;k++){ tmp = ldpc->C_llr[ldpc->VC_1[i][k]][ldpc->VC_1_inv[i][k]]; f += tmp; } for(k=j+1;k<ldpc->VC_1p[i];k++){ tmp = ldpc->C_llr[ldpc->VC_1[i][k]][ldpc->VC_1_inv[i][k]]; f += tmp; } ldpc->V_llr[i][j] = f; } } } for(i=0;i<ldpc->n_effinf;i++){ ldpc->infbits_out[i] = ldpc->variablebits[i+ldpc->n_parity]; } return 1; }
int decode_LDPC(LDPC *ldpc, int n_iter) { int iter, i, j, k; int s; int f; int tmp; // ノードの初期化 for(i=0;i<ldpc->n_row;i++){ init_darray(ldpc->C_llr[i], 0, ldpc->CV_1p[i]); } for(i=0;i<ldpc->n_col;i++){ init_darray(ldpc->V_llr[i], 0, ldpc->VC_1p[i]); } int idx1, idx2; for(iter=0;iter<n_iter;iter++){ // 行処理 for(i=0;i<ldpc->n_row;i++){ for(j=0;j<ldpc->CV_1p[i];j++){ f = INT_MAX; for(k=0;k<j;k++){ tmp = ldpc->llr[ldpc->CV_1[i][k]]+ldpc->V_llr[ldpc->CV_1[i][k]][ldpc->CV_1_inv[i][k]]; f = ldpc->BP_table[idx1][idx2]; } for(k=j+1;k<ldpc->CV_1p[i];k++){ tmp = ldpc->llr[ldpc->CV_1[i][k]]+ldpc->V_llr[ldpc->CV_1[i][k]][ldpc->CV_1_inv[i][k]]; idx1 = BP_real2idx(ldpc, f); idx2 = BP_real2idx(ldpc, tmp); f = ldpc->BP_table[idx1][idx2]; } ldpc->C_llr[i][j] = f; } } // 一時推定語 for(i=0;i<ldpc->n_col;i++){ tmp = 0; for(j=0;j<ldpc->VC_1p[i];j++){ tmp += ldpc->C_llr[ldpc->VC_1[i][j]][ldpc->VC_1_inv[i][j]]; } tmp += ldpc->llr[i]; ldpc->variablebits[i] = (tmp>0) ? 0 : 1; } // パリティチェック if(!parity_check(ldpc)){ for(i=0;i<ldpc->n_effinf;i++){ ldpc->infbits_out[i] = ldpc->variablebits[i+ldpc->n_parity]; } return 0; } // 列処理 for(i=0;i<ldpc->n_col;i++){ for(j=0;j<ldpc->VC_1p[i];j++){ f = 0; for(k=0;k<j;k++){ tmp = ldpc->C_llr[ldpc->VC_1[i][k]][ldpc->VC_1_inv[i][k]]; f += tmp; } for(k=j+1;k<ldpc->VC_1p[i];k++){ tmp = ldpc->C_llr[ldpc->VC_1[i][k]][ldpc->VC_1_inv[i][k]]; f += tmp; } ldpc->V_llr[i][j] = f; } } } for(i=0;i<ldpc->n_effinf;i++){ ldpc->infbits_out[i] = ldpc->variablebits[i+ldpc->n_parity]; } return 1; }