int test_synram_rw() { int rv = TEST_PASS; int i, j; int seed = 1234; unsigned row = 0; for(i=0; i<REPETITIONS; i++) { fxv_array_t wdata; fxv_array_t rdata; for(j=0; j<NUM_BYTES_PER_ARRAY; j++) { wdata.bytes[j] = random_lcg(&seed) & 0x3f; } sync(); fxv_load_array(1, &wdata); syn_store_weights(1, row); syn_load_weights(2, row); fxv_store_array(&rdata, 2); sync(); for(j=0; j<NUM_WORDS_PER_ARRAY; j++) { if( rdata.words[j] != wdata.words[j] ) { rv = TEST_FAIL; mailbox_write(8*4, (uint8_t*)&rdata, sizeof(rdata)); mailbox_write(8*4 + sizeof(rdata), (uint8_t*)&wdata, sizeof(wdata)); return rv; } } row = random_lcg(&seed) % NUM_SYN_LOCATIONS; } return rv; }
int test_cadc_test_load() { int i, j; int rv = TEST_PASS; int seed = 1234; uint8_t a, c; fxv_array_t causal_data; fxv_array_t acausal_data; for(j=0; j<REPETITIONS; j++) { a = random_lcg(&seed); c = random_lcg(&seed); cadc_test_set(0, c, a); cadc_test_load_causal(1, 0); cadc_test_load_acausal(2, 0); fxv_store_array(&causal_data, 1); fxv_store_array(&acausal_data, 2); sync(); for(i=0; i<NUM_BYTES_PER_ARRAY; i++) { if( ((uint8_t)(causal_data.bytes[i]) != c) || ((uint8_t)(acausal_data.bytes[i]) != a) ) { rv = TEST_FAIL; mailbox_write(8*4, (uint8_t*)&causal_data, sizeof(causal_data)); mailbox_write(8*4 + sizeof(causal_data), (uint8_t*)&c, sizeof(c)); mailbox_write(8*4 + 2*sizeof(causal_data), (uint8_t*)&acausal_data, sizeof(acausal_data)); mailbox_write(8*4 + 3*sizeof(causal_data), (uint8_t*)&a, sizeof(a)); return rv; } } } return rv; }
int test_synram_block_rw() { static int const block_size = 10; int rv = TEST_PASS; int i; unsigned j; int k; unsigned loc_start; unsigned loc_stop; fxv_array_t wdata[block_size]; int seed = 1234; for(i=0; i<REPETITIONS; i++) { // generate random data for(j=0; j<block_size; ++j) for(k=0; k<NUM_BYTES_PER_ARRAY; ++k) wdata[j].bytes[k] = 0x3f & random_lcg(&seed); loc_start = random_lcg(&seed) % NUM_SYN_LOCATIONS; loc_stop = loc_start + 10; if( loc_stop >= NUM_SYN_LOCATIONS ) loc_stop = NUM_SYN_LOCATIONS - 1; sync(); // make sure random data is in memory // write random data to synapse locations for(j=loc_start; j < loc_stop; ++j) { fxv_load_array(1, &(wdata[j - loc_start])); syn_store_weights(1, j); } // readback and compare synapse data for(j=loc_start; j<loc_stop; ++j) { fxv_array_t rdata; syn_load_weights(2, j); fxv_store_array(&rdata, 2); sync(); for(k=0; k<NUM_WORDS_PER_ARRAY; ++k) { if( rdata.words[k] != wdata[j - loc_start].words[k] ) { rv = TEST_FAIL; mailbox_write(8*4, (uint8_t*)&rdata, sizeof(rdata)); mailbox_write(8*4 + sizeof(rdata), (uint8_t*)&(wdata[j - loc_start]), sizeof(wdata[j - loc_start])); return rv; } } } } return rv; }
void calculate_salt(void) { uint32_t random_value = 0; calculate_hash(pass_code, 8, var_Hkey.index); // Calculates sha256 of the keys pressed in var_W*10 msec interval and stores it in var_Hkey random_value = random_lcg(); calculate_hash(&random_value, 1, var_R.index); xor_func(var_R.index, var_Hkey.index, 8); calculate_hash(var_R.index, 8, var_T.index); xor_func(var_Salt.index, var_T.index, 8); if (enter_button_status == THIRD_TIME_PRESSED) { save_salt_to_mcu(); } else { Start_W_timer(); } }
void Start_W_timer(void) { var_W = random_lcg() % 500 + 50; var_W_ticks = 0; }
int test_decoder_block_rw() { static int const block_size = 10; int rv = TEST_PASS; int i; unsigned j; int k; unsigned loc_start; unsigned loc_stop; fxv_array_t wdata[block_size]; fxv_array_t ddata[block_size]; int seed = 1234; for(i=0; i<REPETITIONS; i++) { // generate random data for(j=0; j<block_size; ++j) for(k=0; k<NUM_BYTES_PER_ARRAY; ++k) { wdata[j].bytes[k] = 0x3f & random_lcg(&seed); ddata[j].bytes[k] = 0x3f & random_lcg(&seed); } loc_start = random_lcg(&seed) % NUM_SYN_LOCATIONS; loc_stop = loc_start + 10; if( loc_stop >= NUM_SYN_LOCATIONS ) loc_stop = NUM_SYN_LOCATIONS - 1; sync(); // make sure random data is in memory // write random data to synapse locations for(j=loc_start; j < loc_stop; ++j) { fxv_load_array(1, &(wdata[j - loc_start])); fxv_load_array(2, &(ddata[j - loc_start])); syn_store_weights(1, j); syn_store_decoders(2, j); } // readback and compare synapse data for(j=loc_start; j<loc_stop; ++j) { fxv_array_t rdata_w; fxv_array_t rdata_d; syn_load_weights(3, j); syn_load_decoders(4, j); fxv_store_array(&rdata_w, 3); fxv_store_array(&rdata_d, 4); sync(); for(k=0; k<NUM_WORDS_PER_ARRAY; ++k) { if( rdata_w.words[k] != wdata[j - loc_start].words[k] ) { /*rv = TEST_FAIL;*/ /*mailbox_write(8*4, (uint8_t*)&rdata_w, sizeof(rdata_w));*/ /*mailbox_write(8*4 + sizeof(rdata_w), (uint8_t*)&(wdata[j - loc_start]), sizeof(wdata[j - loc_start]));*/ return rv; //TODO it works if this is commented out. wtf } if( rdata_d.words[k] != ddata[j - loc_start].words[k] ) { rv = TEST_FAIL; mailbox_write(8*4, (uint8_t*)&rdata_d, sizeof(rdata_d)); mailbox_write(8*4 + sizeof(rdata_d), (uint8_t*)&(ddata[j - loc_start]), sizeof(ddata[j - loc_start])); return rv; } } } } return rv; }