Example #1
0
void my_main_function(co_stream s_in, co_stream s_out) {
    int i;
    int hi = 10000000;
    int32 err;
    co_stream_open(s_in, 0, co_type_create(co_int_sort, 32));
    co_stream_open(s_out, 1, co_type_create(co_int_sort, 32));
    co_stream_write(s_out, &(hi), sizeof (hi));
    (err = (co_stream_read(s_in, &(hi), sizeof (hi)) != co_err_none));
    printf("Rez = %d\n", hi);
    printf("SERIALSTOP");
    co_stream_close(s_in);
    co_stream_close(s_out);
}
Example #2
0
void producer_func(co_stream output_stream) {

  co_stream_open(output_stream, O_WRONLY, CHAR_TYPE);
//  char *p = "0253aau0396l4374r3343t2337j03b3m435ap332bo03adk2315f43d5i3391g23c7e03dah0318b034ed13e2c0366a0";

  char *p = "a0253aau036bl23c7q3347o132br13dbt1394k4324p33c3s3311h0376i03den239dm1317e034cg036ef332ed0389a0";
  
  while((*p)!=0){
  	co_stream_write(output_stream, p, sizeof(char));
  	p++;
  }
  while(1);
}
Example #3
0
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);
}
Example #4
0
void my_function(co_stream s_in, co_stream s_out) {
    co_int32 i, a, b, c, n;
    co_stream_open(s_in, 0, co_type_create(co_int_sort, 32));
    co_stream_open(s_out, 1, co_type_create(co_int_sort, 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);
}
Example #5
0
void function_eight(co_stream s_in1, co_stream s_in2, co_stream s_out) {
    co_int32 i, a, b, c, n1, n2;
    co_stream_open(s_in1, 0, co_type_create(co_int_sort, 32));
    co_stream_open(s_in2, 0, co_type_create(co_int_sort, 32));
    co_stream_open(s_out, 1, co_type_create(co_int_sort, 32));
    co_stream_read(s_in1, &n1, sizeof(co_int32));
    co_stream_read(s_in2, &n2, sizeof(co_int32));
    a = 0;
    b = 1;
    for (i = 1; i <= n1; i++) {
        c = a + b;
        a = b;
        b = c;
    }
    b = ((b + n2) < 0 ? -(b + n2) : (b + n2)) % n1;
    co_stream_write(s_out, &b, sizeof(co_int32));
    co_stream_close(s_out);
    co_stream_close(s_in1);
    co_stream_close(s_in2);
}
Example #6
0
void Producer(co_stream output_stream)
{
	int iterations=1;
	int32 i;
	static char HelloWorldString[] = "Hello World!";
	char *p;

	xil_printf("producer, 123\n");
	co_stream_open(output_stream, O_WRONLY, CHAR_TYPE);

	for(i=0; i<iterations; i++) {
		p = HelloWorldString;

		while (*p) {
			co_stream_write(output_stream, p, sizeof(char));
			p++;
		}
	}
	co_stream_close(output_stream);
  
}
Example #7
0
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);
}
Example #8
0
//
// 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);
}
Example #9
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);
}