void config_function(void * arg) { co_process test_function_three_proc, function_three_proc, stub_function_three_proc; co_stream stream_test_function = co_stream_create("stream_test_function", INT_TYPE(32), 8); co_stream stream_stub_test = co_stream_create("stream_stub_test", INT_TYPE(32), 8); co_stream stream_function_stub = co_stream_create("stream_function_stub", INT_TYPE(32), 8); test_function_three_proc = co_process_create("test_function_three", (co_function)test_function_three, 2, stream_stub_test, stream_test_function); function_three_proc = co_process_create("function_three", (co_function)function_three, 2, stream_test_function, stream_function_stub); stub_function_three_proc = co_process_create("stub_function_three", (co_function)stub_function_three, 2, stream_function_stub, stream_stub_test); co_process_config(function_three_proc, co_loc, "PE0"); co_process_config(stub_function_three_proc, co_loc, "PE0"); }
// // Impulse C configuration function // void config_BubbleSort(void *arg) { co_stream input; co_stream output; co_process Sorter_process; co_process producer_process; co_process consumer_process; input = co_stream_create("input", INT_TYPE(STREAMWIDTH), STREAMDEPTH); output = co_stream_create("output", INT_TYPE(STREAMWIDTH), STREAMDEPTH); producer_process = co_process_create("Producer", (co_function)Producer, 1, input); Sorter_process = co_process_create("Sorter", (co_function)Sorter, 2, input, output); consumer_process = co_process_create("Consumer",(co_function)Consumer, 1, output); co_process_config(Sorter_process, co_loc, "pe0"); }
void stub_function_two(co_stream s_in, co_stream s_out) { co_int32 n; co_stream_open(s_in, O_RDONLY, INT_TYPE(32)); co_stream_open(s_out, O_WRONLY, INT_TYPE(32)); co_stream_read(s_in, &n, sizeof(co_int32)); co_stream_write(s_out, &n, sizeof(co_int32)); co_stream_close(s_out); co_stream_close(s_in); }
void test_function_four(co_stream s_in, co_stream s_out) { int i; int hi = 10000000; int32 err; co_stream_open(s_in, O_RDONLY, INT_TYPE(32)); co_stream_open(s_out, O_WRONLY, INT_TYPE(32)); #if defined(XPAR_MICROBLAZE_ID) printf ("\r\n===================Running on MicroBlaze================\r\n"); INIT_TIMER(); StartIF_TS = XTmrCtr_GetValue (&TimerInst, 0); #endif HW_STREAM_WRITE(test_function_four, s_out, hi); #if defined(XPAR_MICROBLAZE_ID) FinishIF_TS = XTmrCtr_GetValue (&TimerInst, 0); Time_Com = (FinishIF_TS - StartIF_TS)/TIMER_FREQ_MILLI; #endif #if defined(XPAR_MICROBLAZE_ID) StartIF_TS = XTmrCtr_GetValue (&TimerInst, 0); #endif HW_STREAM_READ(test_function_four, s_in, hi, err); printf("Rez = %d\n", hi); #if defined(XPAR_MICROBLAZE_ID) FinishIF_TS = XTmrCtr_GetValue (&TimerInst, 0); /* Print timpul de comunicatie */ printf("%d\n", Time_Com); /* Print timpul de executie */ TimeSA = (FinishIF_TS - StartIF_TS)/TIMER_FREQ_MILLI; printf("%d\n", TimeSA); printf("SERIALSTOP"); #endif HW_STREAM_CLOSE(test_function_four, s_in); HW_STREAM_CLOSE(test_function_four, s_out); }
void config_hello(void * arg) { co_process my_function_proc, my_test_function_proc; co_stream stream_in = co_stream_create("stream_in", INT_TYPE(32), 8); co_stream stream_out = co_stream_create("stream_out", INT_TYPE(32), 8); my_function_proc = co_process_create("my_function", (co_function)my_function, 2, stream_in, stream_out); my_test_function_proc = co_process_create("my_test_function", (co_function)my_test_function, 2, stream_out, stream_in); co_process_config(my_function_proc, co_loc, "PE0"); }
// // This is the Consumer process that reads ciphertext from // the hardware process to display. // void Consumer(co_stream AESoutputStream) { co_uint8 streamValue; co_stream_open(AESoutputStream, O_RDONLY, INT_TYPE(STREAMWIDTH)); printf("Consumer reading data.\n"); while ( co_stream_read(AESoutputStream, &streamValue, sizeof(co_int8)) == co_err_none ) { printf(" -> 0x%x\n", streamValue); } co_stream_close(AESoutputStream); }
co_architecture co_initialize(void *arg) { co_stream input; co_stream output; input=co_stream_create("input",INT_TYPE(32),1024); output=co_stream_create("output",INT_TYPE(32),1024); co_process_create("Producer",(co_function)Producer, 1, input); co_process_create("Consumer",(co_function)Consumer, 1, output); /* Architecture Initialization */ co_stream_attach(input,XPAR_PLB_BUBBLESORT_ARCH_0_BASEADDR+0,HW_INPUT); co_stream_attach(output,XPAR_PLB_BUBBLESORT_ARCH_0_BASEADDR+16,HW_OUTPUT); return(NULL); }
TEMP_PAR INT_TYPE NUM_SYS::minorProduct(const int to) const { if( to < _border + 1) return INT_TYPE(); INT_TYPE ret = matrix_traits_int::getElement(_border + 1, _border + 1, _G); for(int i = _border + 2; i < to; ++i) { ret *= matrix_traits_int::getElement(i, i, _G); } return ret; }
void my_function(co_stream s_in, co_stream s_out) { co_int32 i, a, b, c, n; co_stream_open(s_in, O_RDONLY, INT_TYPE(32)); co_stream_open(s_out, O_WRONLY, INT_TYPE(32)); co_stream_read(s_in, &n, sizeof(co_int32)); a = 0; b = 1; for (i = 1; i<= n; i++) { c = a + b; a = b; b = c; } co_stream_write(s_out, &b, sizeof(co_int32)); co_stream_close(s_out); co_stream_close(s_in); }
void config_function(void * arg) { co_process test_function_five_proc, function_five_proc, stub_function_five_proc; co_stream stream_test_function1 = co_stream_create("stream_test_function1", INT_TYPE(32), 8); co_stream stream_test_function2 = co_stream_create("stream_test_function2", INT_TYPE(32), 8); co_stream stream_test_function3 = co_stream_create("stream_test_function3", INT_TYPE(32), 8); co_stream stream_stub_test = co_stream_create("stream_stub_test", INT_TYPE(32), 8); co_stream stream_function_stub1 = co_stream_create("stream_function_stub1", INT_TYPE(32), 8); co_stream stream_function_stub2 = co_stream_create("stream_function_stub2", INT_TYPE(32), 8); test_function_five_proc = co_process_create("test_function_five", (co_function)test_function_five, 4, stream_stub_test, stream_test_function1, stream_test_function2, stream_test_function3); function_five_proc = co_process_create("function_five", (co_function)function_five, 5, stream_test_function1, stream_test_function2, stream_test_function3, stream_function_stub1, stream_function_stub2); stub_function_five_proc = co_process_create("stub_function_five", (co_function)stub_function_five, 3, stream_function_stub1, stream_function_stub2, stream_stub_test); co_process_config(function_five_proc, co_loc, "PE0"); co_process_config(stub_function_five_proc, co_loc, "PE0"); }
// // This is the software data producer for the hardware AES process. // It will signal the hardware process when it has initialized all // of the data the encryption engine needs to operate. // void Producer(co_signal AESinputSignal, co_stream AESdataStream) { co_uint32 i, j, k; co_uint8 tempKey[4][4]; co_uint8 tempKeyCol[4]; co_uint8 expandedKey[11][4][4]; // Create the key and plaintext for use by the AES engine. uint8 key[4][4] = { { 0x2b, 0x28, 0xab, 0x09 }, { 0x7e, 0xae, 0xf7, 0xcf }, { 0x15, 0xd2, 0x15, 0x4f }, { 0x16, 0xa6, 0x88, 0x3c } }; uint8 plainText[4][4] = { {0x32, 0x88, 0x31, 0xe0}, {0x43, 0x5a, 0x31, 0x37}, {0xf6, 0x30, 0x98, 0x07}, {0xa8, 0x8d, 0xa2, 0x34} }; // Expand the key into the key schedule using an inline version of ExpandKey. memset(tempKey, 0, 4 * 4 * sizeof(uint8)); memset(tempKeyCol, 0, 4 * sizeof(uint8)); memset(expandedKey, 0, 11 * 4 * 4 * sizeof(uint8)); // Copy the encryption key to ExpandedKey[0]. memcpy(expandedKey[0], key, 4 * 4 * sizeof(uint8)); // TODO: start timer // Create the expanded key. for (i = 1; i < 11; i++) { // Rotate the column. tempKeyCol[0] = expandedKey[i - 1][1][3]; tempKeyCol[1] = expandedKey[i - 1][2][3]; tempKeyCol[2] = expandedKey[i - 1][3][3]; tempKeyCol[3] = expandedKey[i - 1][0][3]; // Replace the bytes with vlaues from the s-box. tempKeyCol[0] = SubBox[tempKeyCol[0]]; tempKeyCol[1] = SubBox[tempKeyCol[1]]; tempKeyCol[2] = SubBox[tempKeyCol[2]]; tempKeyCol[3] = SubBox[tempKeyCol[3]]; // Apply the rcon. tempKeyCol[0] ^= RCon[i - 1]; // XOR operation. for (j = 0; j < 4; j++) { tempKeyCol[0] = tempKeyCol[0] ^ expandedKey[i - 1][0][j]; tempKeyCol[1] = tempKeyCol[1] ^ expandedKey[i - 1][1][j]; tempKeyCol[2] = tempKeyCol[2] ^ expandedKey[i - 1][2][j]; tempKeyCol[3] = tempKeyCol[3] ^ expandedKey[i - 1][3][j]; // Set the new column data in the expanded key. expandedKey[i][0][j] = tempKeyCol[0]; expandedKey[i][1][j] = tempKeyCol[1]; expandedKey[i][2][j] = tempKeyCol[2]; expandedKey[i][3][j] = tempKeyCol[3]; } } // Display the contents of the expanded key printf("ExpandKey routine complete.\n"); printf("\nDisplaying expandedKey contents:\n"); for (i = 0; i < 11; i++) { printf("Block %d\n", i); for (j = 0; j < 4; j++) { printf("[%x, %x, %x, %x]\n", expandedKey[i][j][0], expandedKey[i][j][1], expandedKey[i][j][2], expandedKey[i][j][3]); } printf("\n"); } // Send the plaintext to the output stream so it can be used by the hardware process. co_stream_open(AESdataStream, O_WRONLY, INT_TYPE(STREAMWIDTH)); printf("Sending plaintext to AES data stream.\n"); for (i = 0; i < 4; i++) { for (j = 0; j < 4; j++) { printf(" -> 0x%x\n", plainText[i][j]); co_stream_write(AESdataStream, &plainText[i][j], sizeof(co_uint8)); } } co_stream_close(AESdataStream); co_signal_post(AESinputSignal, 0); printf("Plaintext copy complete.\n\n"); // Send the expanded key to the HW process using a stream. co_stream_open(AESdataStream, O_WRONLY, INT_TYPE(STREAMWIDTH)); printf("Sending expanded key to AES input stream.\n"); for (i = 0; i < 11; i++) { for (j = 0; j < 4; j++) { for (k = 0; k < 4; k++) { printf(" -> 0x%x\n", expandedKey[i][j][k]); co_stream_write(AESdataStream, &expandedKey[i][j][k], sizeof(co_uint8)); } } } co_stream_close(AESdataStream); co_signal_post(AESinputSignal, 0); printf("Expanded key copy complete.\n\n"); // Signal that expand key is complete and allow the AES engine to start processing the data. printf("Signaling hardware process to begin.\n\n"); co_signal_post(AESinputSignal, 0); }
// // This is the hardware process. // void Sorter(co_stream input, co_stream output) { co_int32 nSample = 0; co_int32 samples[STREAMDEPTH]; co_int32 index; co_int32 innerIndex; co_uint32 NUM_LOOPS = 10000; co_int32 counter = 0; // Zero out the sample buffer for (index = 0; index < STREAMDEPTH; index++) { samples[index] = 0; } do // Hardware processes run forever { // Read values from the stream and store them in a buffer index = 0; co_stream_open(input, O_RDONLY, INT_TYPE(STREAMWIDTH)); { while (co_stream_read(input, &nSample, sizeof(co_int32)) == co_err_none) { samples[index++] = nSample; } } co_stream_close(input); // Sort the data using the bubblesort algorithm for (counter = 0; counter < NUM_LOOPS; counter++) { for (index = 0; index < STREAMDEPTH; index++) { for (innerIndex = 0; innerIndex < STREAMDEPTH - 1; innerIndex++) { if (counter % 2 == 0) { if (samples[innerIndex] > samples[innerIndex + 1]) { nSample = samples[innerIndex + 1]; samples[innerIndex + 1] = samples[innerIndex]; samples[innerIndex] = nSample; } } else { if (samples[innerIndex] < samples[innerIndex + 1]) { nSample = samples[innerIndex + 1]; samples[innerIndex + 1] = samples[innerIndex]; samples[innerIndex] = nSample; } } } } } // Write out the sorted values co_stream_open(output, O_WRONLY, INT_TYPE(STREAMWIDTH)); for (index = 0; index < STREAMDEPTH; index++) { co_stream_write(output, &samples[index], sizeof(co_int32)); } co_stream_close(output); } while(1); }