diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d8c3c1d --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +*~ +*.pyc +\#*\# +*.o +*.vlw +.DS_Store diff --git a/hemps8.5/README.txt b/README.txt similarity index 100% rename from hemps8.5/README.txt rename to README.txt diff --git a/hemps8.5/applications/MPEG4/ADSP_0.c b/applications/MPEG4/ADSP_0.c similarity index 100% rename from hemps8.5/applications/MPEG4/ADSP_0.c rename to applications/MPEG4/ADSP_0.c diff --git a/hemps8.5/applications/MPEG4/AU_0.c b/applications/MPEG4/AU_0.c similarity index 100% rename from hemps8.5/applications/MPEG4/AU_0.c rename to applications/MPEG4/AU_0.c diff --git a/hemps8.5/applications/MPEG4/BAB_0.c b/applications/MPEG4/BAB_0.c similarity index 100% rename from hemps8.5/applications/MPEG4/BAB_0.c rename to applications/MPEG4/BAB_0.c diff --git a/hemps8.5/applications/MPEG4/IDCT_0.c b/applications/MPEG4/IDCT_0.c similarity index 100% rename from hemps8.5/applications/MPEG4/IDCT_0.c rename to applications/MPEG4/IDCT_0.c diff --git a/hemps8.5/applications/MPEG4/MCPU_0.c b/applications/MPEG4/MCPU_0.c similarity index 100% rename from hemps8.5/applications/MPEG4/MCPU_0.c rename to applications/MPEG4/MCPU_0.c diff --git a/hemps8.5/applications/MPEG4/MPEG4.cfg b/applications/MPEG4/MPEG4.cfg similarity index 100% rename from hemps8.5/applications/MPEG4/MPEG4.cfg rename to applications/MPEG4/MPEG4.cfg diff --git a/hemps8.5/applications/MPEG4/RAST_0.c b/applications/MPEG4/RAST_0.c similarity index 100% rename from hemps8.5/applications/MPEG4/RAST_0.c rename to applications/MPEG4/RAST_0.c diff --git a/hemps8.5/applications/MPEG4/RISC_0.c b/applications/MPEG4/RISC_0.c similarity index 100% rename from hemps8.5/applications/MPEG4/RISC_0.c rename to applications/MPEG4/RISC_0.c diff --git a/hemps8.5/applications/MPEG4/SDRAM_0.c b/applications/MPEG4/SDRAM_0.c similarity index 100% rename from hemps8.5/applications/MPEG4/SDRAM_0.c rename to applications/MPEG4/SDRAM_0.c diff --git a/hemps8.5/applications/MPEG4/SRAM1_0.c b/applications/MPEG4/SRAM1_0.c similarity index 100% rename from hemps8.5/applications/MPEG4/SRAM1_0.c rename to applications/MPEG4/SRAM1_0.c diff --git a/hemps8.5/applications/MPEG4/SRAM2_0.c b/applications/MPEG4/SRAM2_0.c similarity index 100% rename from hemps8.5/applications/MPEG4/SRAM2_0.c rename to applications/MPEG4/SRAM2_0.c diff --git a/hemps8.5/applications/MPEG4/UPSAMP_0.c b/applications/MPEG4/UPSAMP_0.c similarity index 100% rename from hemps8.5/applications/MPEG4/UPSAMP_0.c rename to applications/MPEG4/UPSAMP_0.c diff --git a/hemps8.5/applications/MPEG4/VU_0.c b/applications/MPEG4/VU_0.c similarity index 100% rename from hemps8.5/applications/MPEG4/VU_0.c rename to applications/MPEG4/VU_0.c diff --git a/hemps8.5/applications/MWD/BLEND.c b/applications/MWD/BLEND.c similarity index 100% rename from hemps8.5/applications/MWD/BLEND.c rename to applications/MWD/BLEND.c diff --git a/hemps8.5/applications/MWD/HS.c b/applications/MWD/HS.c similarity index 100% rename from hemps8.5/applications/MWD/HS.c rename to applications/MWD/HS.c diff --git a/hemps8.5/applications/MWD/HVS.c b/applications/MWD/HVS.c similarity index 100% rename from hemps8.5/applications/MWD/HVS.c rename to applications/MWD/HVS.c diff --git a/hemps8.5/applications/MWD/IN.c b/applications/MWD/IN.c similarity index 100% rename from hemps8.5/applications/MWD/IN.c rename to applications/MWD/IN.c diff --git a/hemps8.5/applications/MWD/JUG1.c b/applications/MWD/JUG1.c similarity index 100% rename from hemps8.5/applications/MWD/JUG1.c rename to applications/MWD/JUG1.c diff --git a/hemps8.5/applications/MWD/JUG2.c b/applications/MWD/JUG2.c similarity index 100% rename from hemps8.5/applications/MWD/JUG2.c rename to applications/MWD/JUG2.c diff --git a/hemps8.5/applications/MWD/MEM1.c b/applications/MWD/MEM1.c similarity index 100% rename from hemps8.5/applications/MWD/MEM1.c rename to applications/MWD/MEM1.c diff --git a/hemps8.5/applications/MWD/MEM2.c b/applications/MWD/MEM2.c similarity index 100% rename from hemps8.5/applications/MWD/MEM2.c rename to applications/MWD/MEM2.c diff --git a/hemps8.5/applications/MWD/MEM3.c b/applications/MWD/MEM3.c similarity index 100% rename from hemps8.5/applications/MWD/MEM3.c rename to applications/MWD/MEM3.c diff --git a/hemps8.5/applications/MWD/MWD.cfg b/applications/MWD/MWD.cfg similarity index 100% rename from hemps8.5/applications/MWD/MWD.cfg rename to applications/MWD/MWD.cfg diff --git a/hemps8.5/applications/MWD/NR.c b/applications/MWD/NR.c similarity index 100% rename from hemps8.5/applications/MWD/NR.c rename to applications/MWD/NR.c diff --git a/hemps8.5/applications/MWD/SE.c b/applications/MWD/SE.c similarity index 100% rename from hemps8.5/applications/MWD/SE.c rename to applications/MWD/SE.c diff --git a/hemps8.5/applications/MWD/VS.c b/applications/MWD/VS.c similarity index 100% rename from hemps8.5/applications/MWD/VS.c rename to applications/MWD/VS.c diff --git a/hemps8.5/applications/VOPD/ACDC_0.c b/applications/VOPD/ACDC_0.c similarity index 100% rename from hemps8.5/applications/VOPD/ACDC_0.c rename to applications/VOPD/ACDC_0.c diff --git a/hemps8.5/applications/VOPD/ARM_0.c b/applications/VOPD/ARM_0.c similarity index 100% rename from hemps8.5/applications/VOPD/ARM_0.c rename to applications/VOPD/ARM_0.c diff --git a/hemps8.5/applications/VOPD/IDCT2_0.c b/applications/VOPD/IDCT2_0.c similarity index 100% rename from hemps8.5/applications/VOPD/IDCT2_0.c rename to applications/VOPD/IDCT2_0.c diff --git a/hemps8.5/applications/VOPD/IQUANT_0.c b/applications/VOPD/IQUANT_0.c similarity index 100% rename from hemps8.5/applications/VOPD/IQUANT_0.c rename to applications/VOPD/IQUANT_0.c diff --git a/hemps8.5/applications/VOPD/ISCAN_0.c b/applications/VOPD/ISCAN_0.c similarity index 100% rename from hemps8.5/applications/VOPD/ISCAN_0.c rename to applications/VOPD/ISCAN_0.c diff --git a/hemps8.5/applications/VOPD/PAD_0.c b/applications/VOPD/PAD_0.c similarity index 100% rename from hemps8.5/applications/VOPD/PAD_0.c rename to applications/VOPD/PAD_0.c diff --git a/hemps8.5/applications/VOPD/RUN_0.c b/applications/VOPD/RUN_0.c similarity index 100% rename from hemps8.5/applications/VOPD/RUN_0.c rename to applications/VOPD/RUN_0.c diff --git a/hemps8.5/applications/VOPD/STRIPEM_0.c b/applications/VOPD/STRIPEM_0.c similarity index 100% rename from hemps8.5/applications/VOPD/STRIPEM_0.c rename to applications/VOPD/STRIPEM_0.c diff --git a/hemps8.5/applications/VOPD/UPSAMP_0.c b/applications/VOPD/UPSAMP_0.c similarity index 100% rename from hemps8.5/applications/VOPD/UPSAMP_0.c rename to applications/VOPD/UPSAMP_0.c diff --git a/hemps8.5/applications/VOPD/VLD_0.c b/applications/VOPD/VLD_0.c similarity index 100% rename from hemps8.5/applications/VOPD/VLD_0.c rename to applications/VOPD/VLD_0.c diff --git a/hemps8.5/applications/VOPD/VOPD.cfg b/applications/VOPD/VOPD.cfg similarity index 100% rename from hemps8.5/applications/VOPD/VOPD.cfg rename to applications/VOPD/VOPD.cfg diff --git a/hemps8.5/applications/VOPD/VOPME_0.c b/applications/VOPD/VOPME_0.c similarity index 100% rename from hemps8.5/applications/VOPD/VOPME_0.c rename to applications/VOPD/VOPME_0.c diff --git a/hemps8.5/applications/VOPD/VOPREC_0.c b/applications/VOPD/VOPREC_0.c similarity index 100% rename from hemps8.5/applications/VOPD/VOPREC_0.c rename to applications/VOPD/VOPREC_0.c diff --git a/hemps8.5/applications/aes/aes.cfg b/applications/aes/aes.cfg similarity index 100% rename from hemps8.5/applications/aes/aes.cfg rename to applications/aes/aes.cfg diff --git a/hemps8.5/applications/aes/aes_generator/aes.h b/applications/aes/aes.h similarity index 95% rename from hemps8.5/applications/aes/aes_generator/aes.h rename to applications/aes/aes.h index c2d078f..fe94e65 100644 --- a/hemps8.5/applications/aes/aes_generator/aes.h +++ b/applications/aes/aes.h @@ -314,19 +314,19 @@ void AddRoundKey(BYTE state[][4], const WORD w[]) subkey[2] = (w[0] >> 8) & 0xFF; subkey[3] = (w[0]) & 0xFF; - //Echo(" "); - //Echo("subkey"); + //puts(" "); + //puts("subkey"); //for(j=0; j<4;j++){ - // Echo(itoh(subkey[j])); + // puts(itoh(subkey[j])); //} - //Echo(" "); + //puts(" "); // - //Echo(" "); - //Echo("state"); + //puts(" "); + //puts("state"); //for(j=0; j<4;j++){ - // Echo(itoh(state[j][0])); + // puts(itoh(state[j][0])); //} - //Echo(" "); + //puts(" "); state[0][0] ^= subkey[0]; state[1][0] ^= subkey[1]; @@ -361,14 +361,14 @@ void AddRoundKey(BYTE state[][4], const WORD w[]) state[3][3] ^= subkey[3]; #ifdef debug_aes_on - Echo(" "); - Echo("AddRoundKey"); + puts(" "); + puts("AddRoundKey"); for(i=0; i<4;i++){ for(j=0; j<4;j++){ - Echo(itoh(state[j][i])); + puts(itoh(state[j][i])); } } - Echo(" "); + puts(" "); #endif } @@ -402,14 +402,14 @@ void SubBytes(BYTE state[][4]) state[3][3] = aes_sbox[state[3][3] >> 4][state[3][3] & 0x0F]; #ifdef debug_aes_on - Echo(" "); - Echo("SubBytes"); + puts(" "); + puts("SubBytes"); for(i=0; i<4;i++){ for(j=0; j<4;j++){ - Echo(itoh(state[j][i])); + puts(itoh(state[j][i])); } } - Echo(" "); + puts(" "); #endif } @@ -437,14 +437,14 @@ void InvSubBytes(BYTE state[][4]) state[3][3] = aes_invsbox[state[3][3] >> 4][state[3][3] & 0x0F]; #ifdef debug_aes_on - Echo(" "); - Echo("InvSubBytes"); + puts(" "); + puts("InvSubBytes"); for(i=0; i<4;i++){ for(j=0; j<4;j++){ - Echo(itoh(state[j][i])); + puts(itoh(state[j][i])); } } - Echo(" "); + puts(" "); #endif } @@ -482,14 +482,14 @@ void ShiftRows(BYTE state[][4]) state[3][1] = t; #ifdef debug_aes_on - Echo(" "); - Echo("ShiftRows"); + puts(" "); + puts("ShiftRows"); for(i=0; i<4;i++){ for(j=0; j<4;j++){ - Echo(itoh(state[j][i])); + puts(itoh(state[j][i])); } } - Echo(" "); + puts(" "); #endif @@ -523,14 +523,14 @@ void InvShiftRows(BYTE state[][4]) state[3][2] = t; #ifdef debug_aes_on - Echo(" "); - Echo("InvShiftRows"); + puts(" "); + puts("InvShiftRows"); for(i=0; i<4;i++){ for(j=0; j<4;j++){ - Echo(itoh(state[j][i])); + puts(itoh(state[j][i])); } } - Echo(" "); + puts(" "); #endif } @@ -635,14 +635,14 @@ void MixColumns(BYTE state[][4]) state[3][3] ^= gf_mul[col[3]][0]; #ifdef debug_aes_on - Echo(" "); - Echo("MixColumns"); + puts(" "); + puts("MixColumns"); for(i=0; i<4;i++){ for(j=0; j<4;j++){ - Echo(itoh(state[j][i])); + puts(itoh(state[j][i])); } } - Echo(" "); + puts(" "); #endif } @@ -738,14 +738,14 @@ void InvMixColumns(BYTE state[][4]) state[3][3] ^= gf_mul[col[2]][2]; state[3][3] ^= gf_mul[col[3]][5]; #ifdef debug_aes_on - Echo(" "); - Echo("InvMixColumns"); + puts(" "); + puts("InvMixColumns"); for(i=0; i<4;i++){ for(j=0; j<4;j++){ - Echo(itoh(state[j][i])); + puts(itoh(state[j][i])); } } - Echo(" "); + puts(" "); #endif } @@ -768,12 +768,12 @@ void aes_encrypt(const BYTE in[], BYTE out[], const WORD key[], int keysize) // column, then row. Accessing an element in C requires row then column. Thus, all state // references in AES must have the column and row indexes reversed for C implementation. - //Echo(" "); - //Echo("in"); + //puts(" "); + //puts("in"); //for(i=0; i 128) { if (keysize > 192) { AddRoundKey(state,&key[56]); - Echo("ROUND 0 finished."); + puts("ROUND 0 finished."); InvShiftRows(state);InvSubBytes(state);AddRoundKey(state,&key[52]);InvMixColumns(state); InvShiftRows(state);InvSubBytes(state);AddRoundKey(state,&key[48]);InvMixColumns(state); } else { AddRoundKey(state,&key[48]); - Echo("ROUND 0 finished."); + puts("ROUND 0 finished."); } InvShiftRows(state);InvSubBytes(state);AddRoundKey(state,&key[44]);InvMixColumns(state); InvShiftRows(state);InvSubBytes(state);AddRoundKey(state,&key[40]);InvMixColumns(state); } else { AddRoundKey(state,&key[40]); - Echo("ROUND 0 finished."); + puts("ROUND 0 finished."); } InvShiftRows(state);InvSubBytes(state);AddRoundKey(state,&key[36]);InvMixColumns(state); InvShiftRows(state);InvSubBytes(state);AddRoundKey(state,&key[32]);InvMixColumns(state); @@ -921,7 +921,7 @@ void aes_decrypt(const BYTE in[], BYTE out[], const WORD key[], int keysize) InvShiftRows(state);InvSubBytes(state);AddRoundKey(state,&key[8]);InvMixColumns(state); InvShiftRows(state);InvSubBytes(state);AddRoundKey(state,&key[4]);InvMixColumns(state); InvShiftRows(state);InvSubBytes(state);AddRoundKey(state,&key[0]); - Echo("ROUND Final finished."); + puts("ROUND Final finished."); // Copy the state to the output array. out[0] = state[0][0]; diff --git a/hemps8.5/applications/aes/aes_generator/Aplicacao_AES_para_HeMPS.pdf b/applications/aes/aes_generator/Aplicacao_AES_para_HeMPS.pdf similarity index 100% rename from hemps8.5/applications/aes/aes_generator/Aplicacao_AES_para_HeMPS.pdf rename to applications/aes/aes_generator/Aplicacao_AES_para_HeMPS.pdf diff --git a/hemps8.5/applications/aes/aes_generator/README.txt b/applications/aes/aes_generator/README.txt similarity index 100% rename from hemps8.5/applications/aes/aes_generator/README.txt rename to applications/aes/aes_generator/README.txt diff --git a/hemps8.5/applications/aes/aes_generator/aes.cfg b/applications/aes/aes_generator/aes.cfg similarity index 100% rename from hemps8.5/applications/aes/aes_generator/aes.cfg rename to applications/aes/aes_generator/aes.cfg diff --git a/hemps8.5/applications/aes/aes.h b/applications/aes/aes_generator/aes.h similarity index 95% rename from hemps8.5/applications/aes/aes.h rename to applications/aes/aes_generator/aes.h index 100a089..fe94e65 100644 --- a/hemps8.5/applications/aes/aes.h +++ b/applications/aes/aes_generator/aes.h @@ -8,7 +8,7 @@ #define FALSE 0 //#define debug_aes_on -#define debug_comunication_on +//#define debug_comunication_on #define KEY_SIZE 256 #define AES_BLOCK_SIZE 16 // AES operates on 16 bytes at a time @@ -314,19 +314,19 @@ void AddRoundKey(BYTE state[][4], const WORD w[]) subkey[2] = (w[0] >> 8) & 0xFF; subkey[3] = (w[0]) & 0xFF; - //Echo(" "); - //Echo("subkey"); + //puts(" "); + //puts("subkey"); //for(j=0; j<4;j++){ - // Echo(itoh(subkey[j])); + // puts(itoh(subkey[j])); //} - //Echo(" "); + //puts(" "); // - //Echo(" "); - //Echo("state"); + //puts(" "); + //puts("state"); //for(j=0; j<4;j++){ - // Echo(itoh(state[j][0])); + // puts(itoh(state[j][0])); //} - //Echo(" "); + //puts(" "); state[0][0] ^= subkey[0]; state[1][0] ^= subkey[1]; @@ -361,14 +361,14 @@ void AddRoundKey(BYTE state[][4], const WORD w[]) state[3][3] ^= subkey[3]; #ifdef debug_aes_on - Echo(" "); - Echo("AddRoundKey"); + puts(" "); + puts("AddRoundKey"); for(i=0; i<4;i++){ for(j=0; j<4;j++){ - Echo(itoh(state[j][i])); + puts(itoh(state[j][i])); } } - Echo(" "); + puts(" "); #endif } @@ -402,14 +402,14 @@ void SubBytes(BYTE state[][4]) state[3][3] = aes_sbox[state[3][3] >> 4][state[3][3] & 0x0F]; #ifdef debug_aes_on - Echo(" "); - Echo("SubBytes"); + puts(" "); + puts("SubBytes"); for(i=0; i<4;i++){ for(j=0; j<4;j++){ - Echo(itoh(state[j][i])); + puts(itoh(state[j][i])); } } - Echo(" "); + puts(" "); #endif } @@ -437,14 +437,14 @@ void InvSubBytes(BYTE state[][4]) state[3][3] = aes_invsbox[state[3][3] >> 4][state[3][3] & 0x0F]; #ifdef debug_aes_on - Echo(" "); - Echo("InvSubBytes"); + puts(" "); + puts("InvSubBytes"); for(i=0; i<4;i++){ for(j=0; j<4;j++){ - Echo(itoh(state[j][i])); + puts(itoh(state[j][i])); } } - Echo(" "); + puts(" "); #endif } @@ -482,14 +482,14 @@ void ShiftRows(BYTE state[][4]) state[3][1] = t; #ifdef debug_aes_on - Echo(" "); - Echo("ShiftRows"); + puts(" "); + puts("ShiftRows"); for(i=0; i<4;i++){ for(j=0; j<4;j++){ - Echo(itoh(state[j][i])); + puts(itoh(state[j][i])); } } - Echo(" "); + puts(" "); #endif @@ -523,14 +523,14 @@ void InvShiftRows(BYTE state[][4]) state[3][2] = t; #ifdef debug_aes_on - Echo(" "); - Echo("InvShiftRows"); + puts(" "); + puts("InvShiftRows"); for(i=0; i<4;i++){ for(j=0; j<4;j++){ - Echo(itoh(state[j][i])); + puts(itoh(state[j][i])); } } - Echo(" "); + puts(" "); #endif } @@ -635,14 +635,14 @@ void MixColumns(BYTE state[][4]) state[3][3] ^= gf_mul[col[3]][0]; #ifdef debug_aes_on - Echo(" "); - Echo("MixColumns"); + puts(" "); + puts("MixColumns"); for(i=0; i<4;i++){ for(j=0; j<4;j++){ - Echo(itoh(state[j][i])); + puts(itoh(state[j][i])); } } - Echo(" "); + puts(" "); #endif } @@ -738,14 +738,14 @@ void InvMixColumns(BYTE state[][4]) state[3][3] ^= gf_mul[col[2]][2]; state[3][3] ^= gf_mul[col[3]][5]; #ifdef debug_aes_on - Echo(" "); - Echo("InvMixColumns"); + puts(" "); + puts("InvMixColumns"); for(i=0; i<4;i++){ for(j=0; j<4;j++){ - Echo(itoh(state[j][i])); + puts(itoh(state[j][i])); } } - Echo(" "); + puts(" "); #endif } @@ -768,12 +768,12 @@ void aes_encrypt(const BYTE in[], BYTE out[], const WORD key[], int keysize) // column, then row. Accessing an element in C requires row then column. Thus, all state // references in AES must have the column and row indexes reversed for C implementation. - //Echo(" "); - //Echo("in"); + //puts(" "); + //puts("in"); //for(i=0; i 128) { if (keysize > 192) { AddRoundKey(state,&key[56]); - Echo("ROUND 0 finished."); + puts("ROUND 0 finished."); InvShiftRows(state);InvSubBytes(state);AddRoundKey(state,&key[52]);InvMixColumns(state); InvShiftRows(state);InvSubBytes(state);AddRoundKey(state,&key[48]);InvMixColumns(state); } else { AddRoundKey(state,&key[48]); - Echo("ROUND 0 finished."); + puts("ROUND 0 finished."); } InvShiftRows(state);InvSubBytes(state);AddRoundKey(state,&key[44]);InvMixColumns(state); InvShiftRows(state);InvSubBytes(state);AddRoundKey(state,&key[40]);InvMixColumns(state); } else { AddRoundKey(state,&key[40]); - Echo("ROUND 0 finished."); + puts("ROUND 0 finished."); } InvShiftRows(state);InvSubBytes(state);AddRoundKey(state,&key[36]);InvMixColumns(state); InvShiftRows(state);InvSubBytes(state);AddRoundKey(state,&key[32]);InvMixColumns(state); @@ -921,7 +921,7 @@ void aes_decrypt(const BYTE in[], BYTE out[], const WORD key[], int keysize) InvShiftRows(state);InvSubBytes(state);AddRoundKey(state,&key[8]);InvMixColumns(state); InvShiftRows(state);InvSubBytes(state);AddRoundKey(state,&key[4]);InvMixColumns(state); InvShiftRows(state);InvSubBytes(state);AddRoundKey(state,&key[0]); - Echo("ROUND Final finished."); + puts("ROUND Final finished."); // Copy the state to the output array. out[0] = state[0][0]; diff --git a/hemps8.5/applications/aes/aes_generator/aes.hmp b/applications/aes/aes_generator/aes.hmp similarity index 100% rename from hemps8.5/applications/aes/aes_generator/aes.hmp rename to applications/aes/aes_generator/aes.hmp diff --git a/hemps8.5/applications/aes/aes_generator/aes_generator.sh b/applications/aes/aes_generator/aes_generator.sh similarity index 100% rename from hemps8.5/applications/aes/aes_generator/aes_generator.sh rename to applications/aes/aes_generator/aes_generator.sh diff --git a/hemps8.5/applications/aes/aes_generator/aes_master.c b/applications/aes/aes_generator/aes_master.c similarity index 76% rename from hemps8.5/applications/aes/aes_generator/aes_master.c rename to applications/aes/aes_generator/aes_master.c index 7d940d0..18d4616 100644 --- a/hemps8.5/applications/aes/aes_generator/aes_master.c +++ b/applications/aes/aes_generator/aes_master.c @@ -7,8 +7,8 @@ *********************************************************************/ /*************************** HEADER FILES ***************************/ -#include -#include +#include +#include "map_pkg.h" #include "aes_master.h" /***************************** DEFINES ******************************/ // total message length @@ -22,7 +22,7 @@ //index of slaves (slave names) int Slave[MAX_SLAVES] = {}; -Message msg; +int *msg; /*************************** MAIN PROGRAM ***************************/ @@ -34,30 +34,29 @@ int main() int msg_length, blocks, qtd_messages[MAX_SLAVES]; int pad_value, aux_msg[3]; int aux1_blocks_PE; - int aux2_blocks_PE; + int aux2_blocks_PE; + int size; + int src; + int msg1[4*AES_BLOCK_SIZE]; // fill each block with values 'A', 'B', ... for(x = 0; x < MSG_LENGHT; x++){ plain_msg[x] = ((x/16)%26)+0x41; } - Echo("task AES started."); - Echo(itoa(GetTick())); - + puts("task AES started.\n"); // calculate number of block and pad value (PCKS5) of last block msg_length = MSG_LENGHT; blocks = (MSG_LENGHT%AES_BLOCK_SIZE)==0 ? (MSG_LENGHT/AES_BLOCK_SIZE) : (MSG_LENGHT/AES_BLOCK_SIZE)+1; pad_value = (AES_BLOCK_SIZE - (msg_length%AES_BLOCK_SIZE))%AES_BLOCK_SIZE; - Echo(" "); - Echo("Blocks:"); - Echo(itoa(blocks)); + puts(" "); + puts("Blocks:\n"); #ifdef debug_comunication_on - Echo(" "); - Echo("plain msg"); + puts(" "); + puts("plain msg\n"); for(x=0; x= NUMBER_OF_SLAVES) // zero messages to Slave not used aux_msg[0] = END_TASK; - memcpy(&msg.msg, &aux_msg, 4*msg.length); - Send(&msg, Slave[x]); - } + memcpy(msg1, &aux_msg, 4*sizeof(aux_msg)); + send_msg(Slave[x], (unsigned int*)msg1, sizeof(msg1)); + } // Send blocks to Cipher and // Receive the correspondent block Encrypted @@ -94,20 +93,21 @@ int main() // send a block to Slave_PE encrypt for(y = 0; y < NUMBER_OF_SLAVES; y++){ if(qtd_messages[(x+y) % NUMBER_OF_SLAVES] != 0){ - msg.length = 4*AES_BLOCK_SIZE; - memcpy(msg.msg, &plain_msg[(x+y)*AES_BLOCK_SIZE], 4*AES_BLOCK_SIZE); - Send(&msg, Slave[(x+y) % NUMBER_OF_SLAVES]); + size = 4*AES_BLOCK_SIZE; + memcpy(msg1, &plain_msg[(x+y)*AES_BLOCK_SIZE], 4*AES_BLOCK_SIZE); + send_msg(Slave[x+y], (unsigned int*)msg1, sizeof(msg1)); } } // Receive Encrypted block from Slave_PE for(y = 0; y < NUMBER_OF_SLAVES; y++){ if(qtd_messages[(x+y) % NUMBER_OF_SLAVES] != 0){ - Receive(&msg, Slave[(x+y) % NUMBER_OF_SLAVES]); + prepare_recv_msg(&src, &size); + msg = wait_receive(); j = 0; for (i=(x+y)*AES_BLOCK_SIZE;i < ((x+y)*AES_BLOCK_SIZE) + AES_BLOCK_SIZE; i++) { - cipher_msg[i] = msg.msg[j]; + cipher_msg[i] = msg[j]; j++; } j = 0; @@ -116,12 +116,11 @@ int main() } } #ifdef debug_comunication_on - Echo(" "); - Echo("cipher msg"); + puts(" "); + puts("cipher msg\n"); for(i=0; i -#include +#include +#include "map_pkg.h" #include "aes.h" /**************************** VARIABLES *****************************/ -Message msg; +int *msg; /*************************** MAIN PROGRAM ***************************/ @@ -20,27 +20,29 @@ int main() { unsigned int key_schedule[60]; int qtd_messages, op_mode, x, flag=1, id = -1, i; + int size; + int src; + int msg1[4*AES_BLOCK_SIZE]; unsigned int enc_buf[128]; unsigned int input_text[16]; unsigned int key[1][32] = { {0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4} }; - Echo(itoa(GetTick())); - Echo("task AES SLAVE started - ID:"); + puts("task AES SLAVE started - ID:\n"); aes_key_setup(&key[0][0], key_schedule, 256); while(flag){ - Receive(&msg, aes_master); - memcpy(input_text, msg.msg, 12); + prepare_recv_msg(&src, &size); + msg = wait_receive(); + memcpy(input_text, msg, 12); #ifdef debug_comunication_on - Echo(" "); - Echo("Slave configuration"); + puts(" "); + puts("Slave configuration\n"); for(i=0; i<3;i++){ - Echo(itoh(input_text[i])); } - Echo(" "); + puts(" "); #endif op_mode = input_text[0]; @@ -49,46 +51,40 @@ int main() if(id == -1){ id = x; - Echo(itoa(id)); } - Echo("Operation:"); - Echo(itoa(op_mode)); - Echo("Blocks:"); - Echo(itoa(qtd_messages)); + puts("Operation:\n"); + puts("Blocks:\n"); if (op_mode == END_TASK){ flag = 0; qtd_messages = 0; } for(x = 0; x < qtd_messages; x++){ - Receive(&msg, aes_master); - memcpy(input_text, msg.msg, 4*AES_BLOCK_SIZE); + prepare_recv_msg(&src, &size); + msg = wait_receive(); + memcpy(input_text, msg, 4*AES_BLOCK_SIZE); #ifdef debug_comunication_on - Echo(" "); - Echo("received msg"); + puts(" "); + puts("received msg"); for(i=0; i<16;i++){ - Echo(itoh(input_text[i])); } - Echo(" "); + puts(" "); #endif if(op_mode == CIPHER_MODE){ - Echo("encript"); + puts("encript"); aes_encrypt(input_text, enc_buf, key_schedule, KEY_SIZE); } else{ - Echo("decript"); + puts("decript"); aes_decrypt(input_text, enc_buf, key_schedule, KEY_SIZE); } - msg.length = 4*AES_BLOCK_SIZE; - memcpy( msg.msg, enc_buf,4*AES_BLOCK_SIZE); - Send(&msg, aes_master); + size = 4*AES_BLOCK_SIZE; + memcpy( msg1, enc_buf,4*AES_BLOCK_SIZE); + send_msg(aes_master, (unsigned int*)msg1, sizeof(msg1)); } } - Echo("task AES SLAVE finished - ID: "); - Echo(itoa(id)); - Echo(itoa(GetTick())); - - exit(); + puts("task AES SLAVE finished - ID: \n"); + exit(); } diff --git a/hemps8.5/applications/aes/aes_master.c b/applications/aes/aes_master.c similarity index 73% rename from hemps8.5/applications/aes/aes_master.c rename to applications/aes/aes_master.c index a778117..18d4616 100644 --- a/hemps8.5/applications/aes/aes_master.c +++ b/applications/aes/aes_master.c @@ -1,29 +1,28 @@ /********************************************************************* * Filename: aes_main.c * Author: Leonardo Rezende Juracy and Luciano L. Caimi -* Copyleft: Original AES implementation: Brad Conte -* (brad AT bradconte.com) +* Copyleft: * Disclaimer: This code is presented "as is" without any guarantees. * Details: *********************************************************************/ /*************************** HEADER FILES ***************************/ -#include -#include +#include +#include "map_pkg.h" #include "aes_master.h" /***************************** DEFINES ******************************/ // total message length -#define MSG_LENGHT 256 +#define MSG_LENGHT // number of efectived used slaves -#define NUMBER_OF_SLAVES 8 +#define NUMBER_OF_SLAVES // number of total slaves allocated -#define MAX_SLAVES 8 +#define MAX_SLAVES /**************************** VARIABLES *****************************/ //index of slaves (slave names) -int Slave[MAX_SLAVES] = {aes_slave1,aes_slave2,aes_slave3,aes_slave4,aes_slave5,aes_slave6,aes_slave7,aes_slave8}; -Message msg; +int Slave[MAX_SLAVES] = {}; +int *msg; /*************************** MAIN PROGRAM ***************************/ @@ -35,30 +34,29 @@ int main() int msg_length, blocks, qtd_messages[MAX_SLAVES]; int pad_value, aux_msg[3]; int aux1_blocks_PE; - int aux2_blocks_PE; + int aux2_blocks_PE; + int size; + int src; + int msg1[4*AES_BLOCK_SIZE]; // fill each block with values 'A', 'B', ... for(x = 0; x < MSG_LENGHT; x++){ plain_msg[x] = ((x/16)%26)+0x41; } - Echo("task AES started."); - Echo(itoa(GetTick())); - + puts("task AES started.\n"); // calculate number of block and pad value (PCKS5) of last block msg_length = MSG_LENGHT; blocks = (MSG_LENGHT%AES_BLOCK_SIZE)==0 ? (MSG_LENGHT/AES_BLOCK_SIZE) : (MSG_LENGHT/AES_BLOCK_SIZE)+1; pad_value = (AES_BLOCK_SIZE - (msg_length%AES_BLOCK_SIZE))%AES_BLOCK_SIZE; - Echo(" "); - Echo("Blocks:"); - Echo(itoa(blocks)); + puts(" "); + puts("Blocks:\n"); #ifdef debug_comunication_on - Echo(" "); - Echo("plain msg"); + puts(" "); + puts("plain msg\n"); for(x=0; x= NUMBER_OF_SLAVES) // zero messages to Slave not used aux_msg[0] = END_TASK; - memcpy(&msg.msg, &aux_msg, 4*msg.length); - Send(&msg, Slave[x]); - } + memcpy(msg1, &aux_msg, 4*sizeof(aux_msg)); + send_msg(Slave[x], (unsigned int*)msg1, sizeof(msg1)); + } // Send blocks to Cipher and // Receive the correspondent block Encrypted @@ -95,20 +93,21 @@ int main() // send a block to Slave_PE encrypt for(y = 0; y < NUMBER_OF_SLAVES; y++){ if(qtd_messages[(x+y) % NUMBER_OF_SLAVES] != 0){ - msg.length = 4*AES_BLOCK_SIZE; - memcpy(msg.msg, &plain_msg[(x+y)*AES_BLOCK_SIZE], 4*AES_BLOCK_SIZE); - Send(&msg, Slave[(x+y) % NUMBER_OF_SLAVES]); + size = 4*AES_BLOCK_SIZE; + memcpy(msg1, &plain_msg[(x+y)*AES_BLOCK_SIZE], 4*AES_BLOCK_SIZE); + send_msg(Slave[x+y], (unsigned int*)msg1, sizeof(msg1)); } } // Receive Encrypted block from Slave_PE for(y = 0; y < NUMBER_OF_SLAVES; y++){ if(qtd_messages[(x+y) % NUMBER_OF_SLAVES] != 0){ - Receive(&msg, Slave[(x+y) % NUMBER_OF_SLAVES]); + prepare_recv_msg(&src, &size); + msg = wait_receive(); j = 0; for (i=(x+y)*AES_BLOCK_SIZE;i < ((x+y)*AES_BLOCK_SIZE) + AES_BLOCK_SIZE; i++) { - cipher_msg[i] = msg.msg[j]; + cipher_msg[i] = msg[j]; j++; } j = 0; @@ -117,12 +116,11 @@ int main() } } #ifdef debug_comunication_on - Echo(" "); - Echo("cipher msg"); + puts(" "); + puts("cipher msg\n"); for(i=0; i -#include +#include +#include "map_pkg.h" #include "aes.h" /**************************** VARIABLES *****************************/ -Message msg; +int *msg; /*************************** MAIN PROGRAM ***************************/ @@ -21,27 +20,29 @@ int main() { unsigned int key_schedule[60]; int qtd_messages, op_mode, x, flag=1, id = -1, i; + int size; + int src; + int msg1[4*AES_BLOCK_SIZE]; unsigned int enc_buf[128]; unsigned int input_text[16]; unsigned int key[1][32] = { {0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4} }; - Echo(itoa(GetTick())); - Echo("task AES SLAVE started - ID:"); + puts("task AES SLAVE started - ID:\n"); aes_key_setup(&key[0][0], key_schedule, 256); while(flag){ - Receive(&msg, aes_master); - memcpy(input_text, msg.msg, 12); + prepare_recv_msg(&src, &size); + msg = wait_receive(); + memcpy(input_text, msg, 12); #ifdef debug_comunication_on - Echo(" "); - Echo("Slave configuration"); + puts(" "); + puts("Slave configuration\n"); for(i=0; i<3;i++){ - Echo(itoh(input_text[i])); } - Echo(" "); + puts(" "); #endif op_mode = input_text[0]; @@ -50,46 +51,40 @@ int main() if(id == -1){ id = x; - Echo(itoa(id)); } - Echo("Operation:"); - Echo(itoa(op_mode)); - Echo("Blocks:"); - Echo(itoa(qtd_messages)); + puts("Operation:\n"); + puts("Blocks:\n"); if (op_mode == END_TASK){ flag = 0; qtd_messages = 0; } for(x = 0; x < qtd_messages; x++){ - Receive(&msg, aes_master); - memcpy(input_text, msg.msg, 4*AES_BLOCK_SIZE); + prepare_recv_msg(&src, &size); + msg = wait_receive(); + memcpy(input_text, msg, 4*AES_BLOCK_SIZE); #ifdef debug_comunication_on - Echo(" "); - Echo("received msg"); + puts(" "); + puts("received msg"); for(i=0; i<16;i++){ - Echo(itoh(input_text[i])); } - Echo(" "); + puts(" "); #endif if(op_mode == CIPHER_MODE){ - Echo("encript"); + puts("encript"); aes_encrypt(input_text, enc_buf, key_schedule, KEY_SIZE); } else{ - Echo("decript"); + puts("decript"); aes_decrypt(input_text, enc_buf, key_schedule, KEY_SIZE); } - msg.length = 4*AES_BLOCK_SIZE; - memcpy( msg.msg, enc_buf,4*AES_BLOCK_SIZE); - Send(&msg, aes_master); + size = 4*AES_BLOCK_SIZE; + memcpy( msg1, enc_buf,4*AES_BLOCK_SIZE); + send_msg(aes_master, (unsigned int*)msg1, sizeof(msg1)); } } - Echo("task AES SLAVE finished - ID: "); - Echo(itoa(id)); - Echo(itoa(GetTick())); - - exit(); + puts("task AES SLAVE finished - ID: \n"); + exit(); } diff --git a/hemps8.5/applications/aes/aes_slave2.c b/applications/aes/aes_slave2.c similarity index 62% rename from hemps8.5/applications/aes/aes_slave2.c rename to applications/aes/aes_slave2.c index df04729..26250e1 100644 --- a/hemps8.5/applications/aes/aes_slave2.c +++ b/applications/aes/aes_slave2.c @@ -1,19 +1,18 @@ /********************************************************************* * Filename: aes_sl(n).c * Author: Leonardo Rezende Juracy and Luciano L. Caimi -* Copyleft: Original AES implementation: Brad Conte -* (brad AT bradconte.com) +* Copyleft: * Disclaimer: This code is presented "as is" without any guarantees. * Details: *********************************************************************/ /*************************** HEADER FILES ***************************/ -#include -#include +#include +#include "map_pkg.h" #include "aes.h" /**************************** VARIABLES *****************************/ -Message msg; +int *msg; /*************************** MAIN PROGRAM ***************************/ @@ -21,27 +20,29 @@ int main() { unsigned int key_schedule[60]; int qtd_messages, op_mode, x, flag=1, id = -1, i; + int size; + int src; + int msg1[4*AES_BLOCK_SIZE]; unsigned int enc_buf[128]; unsigned int input_text[16]; unsigned int key[1][32] = { {0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4} }; - Echo(itoa(GetTick())); - Echo("task AES SLAVE started - ID:"); + puts("task AES SLAVE started - ID:\n"); aes_key_setup(&key[0][0], key_schedule, 256); while(flag){ - Receive(&msg, aes_master); - memcpy(input_text, msg.msg, 12); + prepare_recv_msg(&src, &size); + msg = wait_receive(); + memcpy(input_text, msg, 12); #ifdef debug_comunication_on - Echo(" "); - Echo("Slave configuration"); + puts(" "); + puts("Slave configuration\n"); for(i=0; i<3;i++){ - Echo(itoh(input_text[i])); } - Echo(" "); + puts(" "); #endif op_mode = input_text[0]; @@ -50,46 +51,40 @@ int main() if(id == -1){ id = x; - Echo(itoa(id)); } - Echo("Operation:"); - Echo(itoa(op_mode)); - Echo("Blocks:"); - Echo(itoa(qtd_messages)); + puts("Operation:\n"); + puts("Blocks:\n"); if (op_mode == END_TASK){ flag = 0; qtd_messages = 0; } for(x = 0; x < qtd_messages; x++){ - Receive(&msg, aes_master); - memcpy(input_text, msg.msg, 4*AES_BLOCK_SIZE); + prepare_recv_msg(&src, &size); + msg = wait_receive(); + memcpy(input_text, msg, 4*AES_BLOCK_SIZE); #ifdef debug_comunication_on - Echo(" "); - Echo("received msg"); + puts(" "); + puts("received msg"); for(i=0; i<16;i++){ - Echo(itoh(input_text[i])); } - Echo(" "); + puts(" "); #endif if(op_mode == CIPHER_MODE){ - Echo("encript"); + puts("encript"); aes_encrypt(input_text, enc_buf, key_schedule, KEY_SIZE); } else{ - Echo("decript"); + puts("decript"); aes_decrypt(input_text, enc_buf, key_schedule, KEY_SIZE); } - msg.length = 4*AES_BLOCK_SIZE; - memcpy( msg.msg, enc_buf,4*AES_BLOCK_SIZE); - Send(&msg, aes_master); + size = 4*AES_BLOCK_SIZE; + memcpy( msg1, enc_buf,4*AES_BLOCK_SIZE); + send_msg(aes_master, (unsigned int*)msg1, sizeof(msg1)); } } - Echo("task AES SLAVE finished - ID: "); - Echo(itoa(id)); - Echo(itoa(GetTick())); - - exit(); + puts("task AES SLAVE finished - ID: \n"); + exit(); } diff --git a/hemps8.5/applications/aes/aes_slave3.c b/applications/aes/aes_slave3.c similarity index 62% rename from hemps8.5/applications/aes/aes_slave3.c rename to applications/aes/aes_slave3.c index df04729..26250e1 100644 --- a/hemps8.5/applications/aes/aes_slave3.c +++ b/applications/aes/aes_slave3.c @@ -1,19 +1,18 @@ /********************************************************************* * Filename: aes_sl(n).c * Author: Leonardo Rezende Juracy and Luciano L. Caimi -* Copyleft: Original AES implementation: Brad Conte -* (brad AT bradconte.com) +* Copyleft: * Disclaimer: This code is presented "as is" without any guarantees. * Details: *********************************************************************/ /*************************** HEADER FILES ***************************/ -#include -#include +#include +#include "map_pkg.h" #include "aes.h" /**************************** VARIABLES *****************************/ -Message msg; +int *msg; /*************************** MAIN PROGRAM ***************************/ @@ -21,27 +20,29 @@ int main() { unsigned int key_schedule[60]; int qtd_messages, op_mode, x, flag=1, id = -1, i; + int size; + int src; + int msg1[4*AES_BLOCK_SIZE]; unsigned int enc_buf[128]; unsigned int input_text[16]; unsigned int key[1][32] = { {0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4} }; - Echo(itoa(GetTick())); - Echo("task AES SLAVE started - ID:"); + puts("task AES SLAVE started - ID:\n"); aes_key_setup(&key[0][0], key_schedule, 256); while(flag){ - Receive(&msg, aes_master); - memcpy(input_text, msg.msg, 12); + prepare_recv_msg(&src, &size); + msg = wait_receive(); + memcpy(input_text, msg, 12); #ifdef debug_comunication_on - Echo(" "); - Echo("Slave configuration"); + puts(" "); + puts("Slave configuration\n"); for(i=0; i<3;i++){ - Echo(itoh(input_text[i])); } - Echo(" "); + puts(" "); #endif op_mode = input_text[0]; @@ -50,46 +51,40 @@ int main() if(id == -1){ id = x; - Echo(itoa(id)); } - Echo("Operation:"); - Echo(itoa(op_mode)); - Echo("Blocks:"); - Echo(itoa(qtd_messages)); + puts("Operation:\n"); + puts("Blocks:\n"); if (op_mode == END_TASK){ flag = 0; qtd_messages = 0; } for(x = 0; x < qtd_messages; x++){ - Receive(&msg, aes_master); - memcpy(input_text, msg.msg, 4*AES_BLOCK_SIZE); + prepare_recv_msg(&src, &size); + msg = wait_receive(); + memcpy(input_text, msg, 4*AES_BLOCK_SIZE); #ifdef debug_comunication_on - Echo(" "); - Echo("received msg"); + puts(" "); + puts("received msg"); for(i=0; i<16;i++){ - Echo(itoh(input_text[i])); } - Echo(" "); + puts(" "); #endif if(op_mode == CIPHER_MODE){ - Echo("encript"); + puts("encript"); aes_encrypt(input_text, enc_buf, key_schedule, KEY_SIZE); } else{ - Echo("decript"); + puts("decript"); aes_decrypt(input_text, enc_buf, key_schedule, KEY_SIZE); } - msg.length = 4*AES_BLOCK_SIZE; - memcpy( msg.msg, enc_buf,4*AES_BLOCK_SIZE); - Send(&msg, aes_master); + size = 4*AES_BLOCK_SIZE; + memcpy( msg1, enc_buf,4*AES_BLOCK_SIZE); + send_msg(aes_master, (unsigned int*)msg1, sizeof(msg1)); } } - Echo("task AES SLAVE finished - ID: "); - Echo(itoa(id)); - Echo(itoa(GetTick())); - - exit(); + puts("task AES SLAVE finished - ID: \n"); + exit(); } diff --git a/hemps8.5/applications/audio_video/FIR.c b/applications/audio_video/FIR.c similarity index 100% rename from hemps8.5/applications/audio_video/FIR.c rename to applications/audio_video/FIR.c diff --git a/hemps8.5/applications/audio_video/adpcm_dec.c b/applications/audio_video/adpcm_dec.c similarity index 100% rename from hemps8.5/applications/audio_video/adpcm_dec.c rename to applications/audio_video/adpcm_dec.c diff --git a/hemps8.5/applications/audio_video/audio_video_def.h b/applications/audio_video/audio_video_def.h similarity index 100% rename from hemps8.5/applications/audio_video/audio_video_def.h rename to applications/audio_video/audio_video_def.h diff --git a/hemps8.5/applications/audio_video/idct.c b/applications/audio_video/idct.c similarity index 100% rename from hemps8.5/applications/audio_video/idct.c rename to applications/audio_video/idct.c diff --git a/hemps8.5/applications/audio_video/iquant.c b/applications/audio_video/iquant.c similarity index 100% rename from hemps8.5/applications/audio_video/iquant.c rename to applications/audio_video/iquant.c diff --git a/hemps8.5/applications/audio_video/ivlc.c b/applications/audio_video/ivlc.c similarity index 100% rename from hemps8.5/applications/audio_video/ivlc.c rename to applications/audio_video/ivlc.c diff --git a/hemps8.5/applications/audio_video/join.c b/applications/audio_video/join.c similarity index 100% rename from hemps8.5/applications/audio_video/join.c rename to applications/audio_video/join.c diff --git a/hemps8.5/applications/audio_video/split.c b/applications/audio_video/split.c similarity index 100% rename from hemps8.5/applications/audio_video/split.c rename to applications/audio_video/split.c diff --git a/hemps8.5/applications/audio_video/tcg.yaml b/applications/audio_video/tcg.yaml similarity index 100% rename from hemps8.5/applications/audio_video/tcg.yaml rename to applications/audio_video/tcg.yaml diff --git a/hemps8.5/applications/dijkstra/dijkstra.cfg b/applications/dijkstra/dijkstra.cfg similarity index 100% rename from hemps8.5/applications/dijkstra/dijkstra.cfg rename to applications/dijkstra/dijkstra.cfg diff --git a/hemps8.5/applications/dijkstra/dijkstra_0.c b/applications/dijkstra/dijkstra_0.c similarity index 100% rename from hemps8.5/applications/dijkstra/dijkstra_0.c rename to applications/dijkstra/dijkstra_0.c diff --git a/hemps8.5/applications/dijkstra/dijkstra_1.c b/applications/dijkstra/dijkstra_1.c similarity index 100% rename from hemps8.5/applications/dijkstra/dijkstra_1.c rename to applications/dijkstra/dijkstra_1.c diff --git a/hemps8.5/applications/dijkstra/dijkstra_2.c b/applications/dijkstra/dijkstra_2.c similarity index 100% rename from hemps8.5/applications/dijkstra/dijkstra_2.c rename to applications/dijkstra/dijkstra_2.c diff --git a/hemps8.5/applications/dijkstra/dijkstra_3.c b/applications/dijkstra/dijkstra_3.c similarity index 100% rename from hemps8.5/applications/dijkstra/dijkstra_3.c rename to applications/dijkstra/dijkstra_3.c diff --git a/hemps8.5/applications/dijkstra/dijkstra_4.c b/applications/dijkstra/dijkstra_4.c similarity index 100% rename from hemps8.5/applications/dijkstra/dijkstra_4.c rename to applications/dijkstra/dijkstra_4.c diff --git a/hemps8.5/applications/dijkstra/divider.c b/applications/dijkstra/divider.c similarity index 100% rename from hemps8.5/applications/dijkstra/divider.c rename to applications/dijkstra/divider.c diff --git a/hemps8.5/applications/dijkstra/print.c b/applications/dijkstra/print.c similarity index 100% rename from hemps8.5/applications/dijkstra/print.c rename to applications/dijkstra/print.c diff --git a/hemps8.5/applications/dtw/bank.c b/applications/dtw/bank.c similarity index 100% rename from hemps8.5/applications/dtw/bank.c rename to applications/dtw/bank.c diff --git a/hemps8.5/applications/dtw/dtw.cfg b/applications/dtw/dtw.cfg similarity index 100% rename from hemps8.5/applications/dtw/dtw.cfg rename to applications/dtw/dtw.cfg diff --git a/hemps8.5/applications/dtw/dtw.h b/applications/dtw/dtw.h similarity index 100% rename from hemps8.5/applications/dtw/dtw.h rename to applications/dtw/dtw.h diff --git a/hemps8.5/applications/dtw/p1.c b/applications/dtw/p1.c similarity index 100% rename from hemps8.5/applications/dtw/p1.c rename to applications/dtw/p1.c diff --git a/hemps8.5/applications/dtw/p2.c b/applications/dtw/p2.c similarity index 100% rename from hemps8.5/applications/dtw/p2.c rename to applications/dtw/p2.c diff --git a/hemps8.5/applications/dtw/p3.c b/applications/dtw/p3.c similarity index 100% rename from hemps8.5/applications/dtw/p3.c rename to applications/dtw/p3.c diff --git a/hemps8.5/applications/dtw/p4.c b/applications/dtw/p4.c similarity index 100% rename from hemps8.5/applications/dtw/p4.c rename to applications/dtw/p4.c diff --git a/hemps8.5/applications/dtw/recognizer.c b/applications/dtw/recognizer.c similarity index 100% rename from hemps8.5/applications/dtw/recognizer.c rename to applications/dtw/recognizer.c diff --git a/hemps8.5/applications/fixe_base_test_16/DLAB.c b/applications/fixe_base_test_16/DLAB.c similarity index 100% rename from hemps8.5/applications/fixe_base_test_16/DLAB.c rename to applications/fixe_base_test_16/DLAB.c diff --git a/hemps8.5/applications/fixe_base_test_16/DRGB.c b/applications/fixe_base_test_16/DRGB.c similarity index 100% rename from hemps8.5/applications/fixe_base_test_16/DRGB.c rename to applications/fixe_base_test_16/DRGB.c diff --git a/hemps8.5/applications/fixe_base_test_16/DXYZ.c b/applications/fixe_base_test_16/DXYZ.c similarity index 100% rename from hemps8.5/applications/fixe_base_test_16/DXYZ.c rename to applications/fixe_base_test_16/DXYZ.c diff --git a/hemps8.5/applications/fixe_base_test_16/GFC.c b/applications/fixe_base_test_16/GFC.c similarity index 100% rename from hemps8.5/applications/fixe_base_test_16/GFC.c rename to applications/fixe_base_test_16/GFC.c diff --git a/hemps8.5/applications/fixe_base_test_16/LAB1.c b/applications/fixe_base_test_16/LAB1.c similarity index 100% rename from hemps8.5/applications/fixe_base_test_16/LAB1.c rename to applications/fixe_base_test_16/LAB1.c diff --git a/hemps8.5/applications/fixe_base_test_16/LAB2.c b/applications/fixe_base_test_16/LAB2.c similarity index 100% rename from hemps8.5/applications/fixe_base_test_16/LAB2.c rename to applications/fixe_base_test_16/LAB2.c diff --git a/hemps8.5/applications/fixe_base_test_16/P1.c b/applications/fixe_base_test_16/P1.c similarity index 100% rename from hemps8.5/applications/fixe_base_test_16/P1.c rename to applications/fixe_base_test_16/P1.c diff --git a/hemps8.5/applications/fixe_base_test_16/P2.c b/applications/fixe_base_test_16/P2.c similarity index 100% rename from hemps8.5/applications/fixe_base_test_16/P2.c rename to applications/fixe_base_test_16/P2.c diff --git a/hemps8.5/applications/fixe_base_test_16/RGB1.c b/applications/fixe_base_test_16/RGB1.c similarity index 100% rename from hemps8.5/applications/fixe_base_test_16/RGB1.c rename to applications/fixe_base_test_16/RGB1.c diff --git a/hemps8.5/applications/fixe_base_test_16/RGB2.c b/applications/fixe_base_test_16/RGB2.c similarity index 100% rename from hemps8.5/applications/fixe_base_test_16/RGB2.c rename to applications/fixe_base_test_16/RGB2.c diff --git a/hemps8.5/applications/fixe_base_test_16/RMS.c b/applications/fixe_base_test_16/RMS.c similarity index 100% rename from hemps8.5/applications/fixe_base_test_16/RMS.c rename to applications/fixe_base_test_16/RMS.c diff --git a/hemps8.5/applications/fixe_base_test_16/WRMS.c b/applications/fixe_base_test_16/WRMS.c similarity index 100% rename from hemps8.5/applications/fixe_base_test_16/WRMS.c rename to applications/fixe_base_test_16/WRMS.c diff --git a/hemps8.5/applications/fixe_base_test_16/XYZ1.c b/applications/fixe_base_test_16/XYZ1.c similarity index 100% rename from hemps8.5/applications/fixe_base_test_16/XYZ1.c rename to applications/fixe_base_test_16/XYZ1.c diff --git a/hemps8.5/applications/fixe_base_test_16/XYZ2.c b/applications/fixe_base_test_16/XYZ2.c similarity index 100% rename from hemps8.5/applications/fixe_base_test_16/XYZ2.c rename to applications/fixe_base_test_16/XYZ2.c diff --git a/hemps8.5/applications/fixe_base_test_16/fixe_base_test_16.cfg b/applications/fixe_base_test_16/fixe_base_test_16.cfg similarity index 100% rename from hemps8.5/applications/fixe_base_test_16/fixe_base_test_16.cfg rename to applications/fixe_base_test_16/fixe_base_test_16.cfg diff --git a/hemps8.5/applications/mpeg/idct.c b/applications/mpeg/idct.c similarity index 91% rename from hemps8.5/applications/mpeg/idct.c rename to applications/mpeg/idct.c index 773e826..0ae4a01 100644 --- a/hemps8.5/applications/mpeg/idct.c +++ b/applications/mpeg/idct.c @@ -1,16 +1,3 @@ -/*--------------------------------------------------------------------- -TITLE: Program Scheduler -AUTHOR: Nicolas Saint-jean -EMAIL : saintjea@lirmm.fr -DATE CREATED: 04/04/06 -FILENAME: task3.c -PROJECT: Network Process Unit -COPYRIGHT: Software placed into the public domain by the author. - Software 'as is' without warranty. Author liable for nothing. -DESCRIPTION: This file contains the task3 ----------------------------------------------------------------------*/ - - // ********************************************************************************************************** // * IDCT.C * // * * @@ -38,8 +25,9 @@ DESCRIPTION: This file contains the task3 // * Number of clock cycles (with these inEcho) -> 4150 Cicli * // ********************************************************************************************************** -#include -#include + +#include +#include "map_pkg.h" #include "mpeg_std.h" typedef int type_DATA; //unsigned @@ -58,9 +46,6 @@ typedef int type_DATA; //unsigned int out; -Message msg1; - - /* iclip table */ short int iclp[1024] = { -256,-256,-256,-256,-256,-256,-256,-256,-256,-256,-256,-256,-256,-256,-256,-256,-256,-256,-256,-256,-256,-256,-256,-256,-256,-256,-256,-256,-256,-256,-256,-256, @@ -223,35 +208,31 @@ void idct_func(type_DATA *block,int lx) int main() { - unsigned int time_a, time_b; + printf("MPEG Task D start: iDCT "); int i,j; type_DATA block[64]; - - - Echo("MPEG Task D start: iDCT "); - Echo(itoa(GetTick())); + int msg1[128]; + int size; + int *buff; + int src; for(j=0;j 4214 * // ********************************************************************************************************* - -#include -#include +#include +#include "map_pkg.h" #include "mpeg_std.h" typedef int type_DATA; //unsigned -Message msg1; unsigned char intramatrix[64]={ @@ -86,37 +84,34 @@ void iquant_func(type_DATA *src, int lx, int dc_prec, int mquant) int main() { - unsigned int time_a, time_b; - int i,j; + int msg1[128]; + int size; + int *buff; + int src; + int i,j; type_DATA clk_count; type_DATA block[64]; - - - Echo("MPEG Task C start: iquant "); - Echo(itoa(GetTick())); + puts("MPEG Task C start: iquant \n"); for(j=0;j 57026 * // ********************************************************************************************************* -#include -#include +#include +#include "map_pkg.h" #include "mpeg_std.h" typedef int type_DATA; //unsigned @@ -460,42 +448,37 @@ void ivlc_func(type_DATA *block, short int comp, short int lx, type_DATA *buffer return; } -Message msg1; - int main() { - unsigned int time_a, time_b; + puts("MPEG Task B start: iVLC \n"); + int msg1[128]; + int size; + int *buff; + int src; int i,j; type_DATA vlc_array[128]; type_DATA block[64]; - Echo("MPEG Task B start: iVLC "); - Echo(itoa(GetTick())); - for(j=0;j +#include "map_pkg.h" +#include "mpeg_std.h" + +typedef int type_DATA; //unsigned + + + +int main() +{ + printf("MPEG Task PRINT start:\n"); + int i; + int *buff; + int size; + int src; + + + + for(i=0;i -#include +#include +#include "map_pkg.h" #include "mpeg_std.h" - unsigned int vlc_array[128] = { // array containing the compressed data stream // It must be specified as an input 0xfa,0xb8,0x20,0x05,0x20,0x20,0x02,0x38, @@ -27,38 +14,23 @@ unsigned int vlc_array[128] = { // array containing the compressed data stream 0xa7,0x3c,0x73,0xb6,0x31,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}; -Message msg1; - int main(){ - - unsigned int time_a, time_b; - int i; - - Echo("MPEG Task A start: "); - Echo(itoa(GetTick())); - + puts("MPEG started\n"); + int i; + int size; + int msg1[128]; for(i=0; i<128; i++) - msg1.msg[i] = vlc_array[i]; - - - msg1.length = 128; + msg1[i] = vlc_array[i]; + size = 128; for(i=0;i +#include +Message msg; +int main(){ + int i, j,t; + Echo("task A started."); + Echo(itoa(GetTick())); + for(i=0;i<1;i++) + { + msg.length = 30; + for(j=0;j<30;j++) msg.msg[j]=i; + Send(&msg,taskB); + } + + Echo(itoa(GetTick())); + Echo("task A finished."); + exit(); +} diff --git a/applications/pc1/taskB.c b/applications/pc1/taskB.c new file mode 100644 index 0000000..2349ed7 --- /dev/null +++ b/applications/pc1/taskB.c @@ -0,0 +1,17 @@ +#include +#include +Message msg; +int main() +{ + int i; + Echo("task B started."); + Echo(itoa(GetTick())); + for(i=0;i<1;i++) + { + Receive(&msg,taskA); + } + + Echo(itoa(GetTick())); + Echo("task B finished."); + exit(); +} diff --git a/applications/pc2/taskA.c b/applications/pc2/taskA.c new file mode 100644 index 0000000..2a6fdbc --- /dev/null +++ b/applications/pc2/taskA.c @@ -0,0 +1,18 @@ +#include +#include +Message msg; +int main(){ + int i, j,t; + Echo("task A started."); + Echo(itoa(GetTick())); + for(i=0;i<30;i++) + { + msg.length = 30; + for(j=0;j<30;j++) msg.msg[j]=i; + Send(&msg,taskB); + } + + Echo(itoa(GetTick())); + Echo("task A finished."); + exit(); +} diff --git a/applications/pc2/taskB.c b/applications/pc2/taskB.c new file mode 100644 index 0000000..40d5f16 --- /dev/null +++ b/applications/pc2/taskB.c @@ -0,0 +1,17 @@ +#include +#include +Message msg; +int main() +{ + int i; + Echo("task B started."); + Echo(itoa(GetTick())); + for(i=0;i<30;i++) + { + Receive(&msg,taskA); + } + + Echo(itoa(GetTick())); + Echo("task B finished."); + exit(); +} diff --git a/applications/pc_test/receiver.c b/applications/pc_test/receiver.c new file mode 100644 index 0000000..7b3bfc6 --- /dev/null +++ b/applications/pc_test/receiver.c @@ -0,0 +1,17 @@ +#include + +int main() { + char *msg = NULL; + flit_t src; + size_t size; + + do { + free(msg); + prepare_recv_msg(&src, &size); + printf("Waiting to receive %d bytes from %X\n", size, src); + msg = wait_receive(); + puts(msg); + } while(strcmp(msg, "END\n")); + + return 0; +} diff --git a/applications/pc_test/sender.c b/applications/pc_test/sender.c new file mode 100644 index 0000000..560662f --- /dev/null +++ b/applications/pc_test/sender.c @@ -0,0 +1,13 @@ +#include +#include "map_pkg.h" + +int main() { + const char *hello = "Hello World!\n"; + + send_msg(receiver, hello, strlen(hello)+1); + printf("Message transmited to %X\n", receiver); + send_msg(receiver, "END\n", strlen("END\n")+1); + printf("Termination message sent to %X, terminating\n", receiver); + + return 0; +} diff --git a/applications/pc_test2/receiver.c b/applications/pc_test2/receiver.c new file mode 100644 index 0000000..7b3bfc6 --- /dev/null +++ b/applications/pc_test2/receiver.c @@ -0,0 +1,17 @@ +#include + +int main() { + char *msg = NULL; + flit_t src; + size_t size; + + do { + free(msg); + prepare_recv_msg(&src, &size); + printf("Waiting to receive %d bytes from %X\n", size, src); + msg = wait_receive(); + puts(msg); + } while(strcmp(msg, "END\n")); + + return 0; +} diff --git a/applications/pc_test2/sender.c b/applications/pc_test2/sender.c new file mode 100644 index 0000000..560662f --- /dev/null +++ b/applications/pc_test2/sender.c @@ -0,0 +1,13 @@ +#include +#include "map_pkg.h" + +int main() { + const char *hello = "Hello World!\n"; + + send_msg(receiver, hello, strlen(hello)+1); + printf("Message transmited to %X\n", receiver); + send_msg(receiver, "END\n", strlen("END\n")+1); + printf("Termination message sent to %X, terminating\n", receiver); + + return 0; +} diff --git a/hemps8.5/applications/prod_cons/cons.c b/applications/prod_cons/cons.c similarity index 100% rename from hemps8.5/applications/prod_cons/cons.c rename to applications/prod_cons/cons.c diff --git a/hemps8.5/applications/prod_cons/prod.c b/applications/prod_cons/prod.c similarity index 100% rename from hemps8.5/applications/prod_cons/prod.c rename to applications/prod_cons/prod.c diff --git a/hemps8.5/applications/prod_cons/prod_cons.cfg b/applications/prod_cons/prod_cons.cfg similarity index 100% rename from hemps8.5/applications/prod_cons/prod_cons.cfg rename to applications/prod_cons/prod_cons.cfg diff --git a/hemps8.5/applications/prod_cons/prod_cons_std.h b/applications/prod_cons/prod_cons_std.h similarity index 100% rename from hemps8.5/applications/prod_cons/prod_cons_std.h rename to applications/prod_cons/prod_cons_std.h diff --git a/applications/sort/master.c b/applications/sort/master.c new file mode 100644 index 0000000..837e4f5 --- /dev/null +++ b/applications/sort/master.c @@ -0,0 +1,81 @@ +#include +#include "map_pkg.h" + +#include "sort.h" + +#define TASKS 40 +#define SLAVES 3 + +void init_array(int *array, int size){ + int i; + + for (i = 0; i < size; i++) + array[i] = size - i; +} + +void print_array(int *array, int size){ + int i; + for (i = 0; i < size; i++) { + puts(itoasc(array[i])); + puts(" "); + } + puts("\n"); + +} + +int get_id(int src) { + if (src==slave1) + return 0; + if (src==slave2) + return 1; + if (src==slave3) + return 2; +} + +int main(){ + int i; + int *buff; + int slave_addr[SLAVES] = {slave1, slave2, slave3}; + + int array[TASKS][ARRAY_SIZE]; + int slave_task[SLAVES]; + int task = 0; + int slave_id; + + int msg_kill = KILL_PROC; + flit_t src; + size_t size; + + for (i = 0; i < TASKS; i++) + init_array(array[i], ARRAY_SIZE); + + for (i = 0; i < SLAVES; i++){ + prepare_recv_msg(&src, &size); + printf("Waiting to receive %d bytes from slave %X\n", size, src); + buff = wait_receive(); + puts(itoasc(buff[0])); + puts("\n"); + slave_task[buff[0]] = task; + send_msg(slave_addr[buff[0]], (unsigned int*)array[task], sizeof(array[task])); + free(buff); + task++; + } + + for (i = 0; i < TASKS; i++){ + prepare_recv_msg(&src, &size); + printf("Waiting to receive %d bytes from slave %X\n", size, src); + buff = wait_receive(); + print_array(buff, ARRAY_SIZE); + free(buff); + slave_id = get_id(src); + slave_task[slave_id] = task; + if (task == TASKS){ + send_msg(slave_addr[slave_id], &msg_kill, sizeof(msg_kill)); + printf("Master Sening kill to %X\n", src); + } + else { + send_msg(slave_addr[slave_id], (unsigned int*)array[task], sizeof(array[task])); + task++; + } + } +} diff --git a/applications/sort/slave1.c b/applications/sort/slave1.c new file mode 100644 index 0000000..a51ecd7 --- /dev/null +++ b/applications/sort/slave1.c @@ -0,0 +1,28 @@ +#include +#include "map_pkg.h" + +#include "sort.h" + +#define SLAVE_ID 0 + +int main(){ + int task_request[2]; + int *array; + + flit_t src; + size_t size; + + task_request[0] = SLAVE_ID; + task_request[1] = TASK_REQUEST; + /*Requests initial task*/ + send_msg(master, &task_request, sizeof(task_request)); + + /* Wait for a task, execute and return result to master*/ + for (;;) { + prepare_recv_msg(&src, &size); + array=wait_receive(); + if (array[0] == KILL_PROC) break; + quicksort(array, 0, ARRAY_SIZE-1); + send_msg(master, (unsigned int*)array, ARRAY_SIZE*4); + } +} \ No newline at end of file diff --git a/applications/sort/slave2.c b/applications/sort/slave2.c new file mode 100644 index 0000000..1a56485 --- /dev/null +++ b/applications/sort/slave2.c @@ -0,0 +1,28 @@ +#include +#include "map_pkg.h" + +#include "sort.h" + +#define SLAVE_ID 1 + +int main(){ + int task_request[2]; + int *array; + + flit_t src; + size_t size; + + task_request[0] = SLAVE_ID; + task_request[1] = TASK_REQUEST; + /*Requests initial task*/ + send_msg(master, &task_request, sizeof(task_request)); + + /* Wait for a task, execute and return result to master*/ + for (;;) { + prepare_recv_msg(&src, &size); + array=wait_receive(); + if (array[0] == KILL_PROC) break; + quicksort(array, 0, ARRAY_SIZE-1); + send_msg(master, (unsigned int*)array, ARRAY_SIZE*4); + } +} \ No newline at end of file diff --git a/applications/sort/slave3.c b/applications/sort/slave3.c new file mode 100644 index 0000000..13a0069 --- /dev/null +++ b/applications/sort/slave3.c @@ -0,0 +1,28 @@ +#include +#include "map_pkg.h" + +#include "sort.h" + +#define SLAVE_ID 2 + +int main(){ + int task_request[2]; + int *array; + + flit_t src; + size_t size; + + task_request[0] = SLAVE_ID; + task_request[1] = TASK_REQUEST; + /*Requests initial task*/ + send_msg(master, &task_request, sizeof(task_request)); + + /* Wait for a task, execute and return result to master*/ + for (;;) { + prepare_recv_msg(&src, &size); + array=wait_receive(); + if (array[0] == KILL_PROC) break; + quicksort(array, 0, ARRAY_SIZE-1); + send_msg(master, (unsigned int*)array, ARRAY_SIZE*4); + } +} \ No newline at end of file diff --git a/applications/sort/sort.h b/applications/sort/sort.h new file mode 100644 index 0000000..1c7aa76 --- /dev/null +++ b/applications/sort/sort.h @@ -0,0 +1,80 @@ +#include + +#define ARRAY_SIZE 40 +#define LFSR_POL 0xA3000000 + +#define TASK_REQUEST 0x1000 +#define KILL_PROC 0x2000 +#define MSG_ACK 0x3000 + +char *itoasc(unsigned int num) +{ + static char buf[12]; + static char buf2[12]; + int i,j; + + if (num==0) + { + buf[0] = '0'; + buf[1] = '\0'; + return &buf[0]; + } + + for(i=0;i<11 && num!=0;i++) + { + buf[i]=(char)((num%10)+'0'); + num/=10; + } + buf2[i] = '\0'; + j = 0; + i--; + for(;i>=0;i--){ + buf2[i]=buf[j]; + j++; + } + return &buf2[0]; +} + +unsigned int rand_val = LFSR_POL; + +unsigned int rand(){ + rand_val = (rand_val >> 1) ^ (-(rand_val & 1u) & LFSR_POL); + return rand_val; +} + +void swap(int *array, int a, int b){ + int aux; + + aux = array[a]; + array[a] = array[b]; + array[b] = aux; +} + +int partition(int *array, int lo, int hi){ + int pivo, i, j; + int index; + + i = lo - 1; + index = rand() % (hi - lo) + lo; + swap(array, index, hi); + pivo = array[hi]; + + for (j = lo; j < hi; j++){ + if (array[j] < pivo){ + i++; + swap(array, i, j); + } + } + if (array[hi] < array[i+1]) + swap(array, i+1, hi); + return i+1; +} + +void quicksort(int *array, int lo, int hi) { + int p; + if (lo < hi){ + p = partition(array, lo, hi); + quicksort(array, lo, p - 1); + quicksort(array, p + 1, hi); + } +} diff --git a/hemps8.5/applications/synthetic/syn_std.h b/applications/synthetic/syn_std.h similarity index 100% rename from hemps8.5/applications/synthetic/syn_std.h rename to applications/synthetic/syn_std.h diff --git a/hemps8.5/applications/synthetic/synthetic.cfg b/applications/synthetic/synthetic.cfg similarity index 100% rename from hemps8.5/applications/synthetic/synthetic.cfg rename to applications/synthetic/synthetic.cfg diff --git a/applications/synthetic/taskA.c b/applications/synthetic/taskA.c new file mode 100644 index 0000000..8909b20 --- /dev/null +++ b/applications/synthetic/taskA.c @@ -0,0 +1,25 @@ + +#include +#include "map_pkg.h" +#include "syn_std.h" +int main() +{ + + int i, j,t; + int msg1[30]; + int size; + //msg1 = malloc(sizeof(int)); + + puts("synthetic task A started.\n"); + +for(i=0;i +#include "map_pkg.h" +#include "syn_std.h" +int main() +{ + + int i, j,t; + int msg1[30]; + int size; + + puts("synthetic task B started.\n"); + + for(i=0;i +#include "map_pkg.h" +#include "syn_std.h" +int main() +{ + + int i, j,t; + int msg1[30]; + int size; + int *buff; + int src; + puts("synthetic task C started.\n"); + + //msg1 = malloc(sizeof(int)); + +for(i=0;i +#include "map_pkg.h" +#include "syn_std.h" +int main() +{ + + int i, j,t; + int msg1[30]; + int size; + flit_t src; + int *buff; + //msg1 = malloc(sizeof(int)); + + puts("synthetic task D started.\n"); + +for(i=0;i +#include "map_pkg.h" +#include "syn_std.h" + +int main() +{ + + int i, j,t; + int msg1[30]; + int size; + int *buff; + int src; + //msg1 = malloc(sizeof(int)); + + puts("synthetic task E started.\n"); + +for(i=0;i +#include "map_pkg.h" +#include "syn_std.h" +int main() +{ + + int i,t; + int msg1[30]; + int size; + int src; + int *buff; + + puts("synthetic task F started.\n"); + +for(i=0;i X\"",k); for (i = 0; i < 32; i++) - printf("%2.2X",init[k][i]); + printf("%2.2X", init[k][i]); printf("\""); if (k != 63) @@ -706,6 +706,9 @@ int main(int argc, char* argv[]){ else if(strcmp(argv[3],"kernel_slave.txt") == 0){ vhd_ram_parametrized(code, size, i, "slave"); } + else{ + vhd_ram_parametrized(code, size, i, "simple"); + } } else if(strcmp(argv[2],"-h") == 0){ if (strcmp(argv[3],"kernel_master.txt") == 0){ diff --git a/build_env/bin/ram_simple b/build_env/bin/ram_simple new file mode 100755 index 0000000..30b238e --- /dev/null +++ b/build_env/bin/ram_simple @@ -0,0 +1,2 @@ +00000000 +00000000 diff --git a/build_env/bin/ram_simple.txt b/build_env/bin/ram_simple.txt new file mode 100755 index 0000000..30b238e --- /dev/null +++ b/build_env/bin/ram_simple.txt @@ -0,0 +1,2 @@ +00000000 +00000000 diff --git a/hemps8.5/build_env/deloream_env.py b/build_env/deloream_env.py similarity index 100% rename from hemps8.5/build_env/deloream_env.py rename to build_env/deloream_env.py diff --git a/hemps8.5/build_env/makes/make_all_apps b/build_env/makes/make_all_apps similarity index 100% rename from hemps8.5/build_env/makes/make_all_apps rename to build_env/makes/make_all_apps diff --git a/build_env/makes/make_app b/build_env/makes/make_app new file mode 100644 index 0000000..e9348fc --- /dev/null +++ b/build_env/makes/make_app @@ -0,0 +1,53 @@ +BASEDIR = ../.. +BAREOS_DIR = $(BASEDIR)/software/bareOS +TRIPLET = mips-elf +CC = $(TRIPLET)-gcc +CFLAGS = -I$(BAREOS_DIR)/include -O2 -fno-builtin -Wall -fms-extensions -nostdinc +AS = $(TRIPLET)-as +ASFLAGS = +CPP = $(TRIPLET)-g++ +CCFLAGS = $(CFLAGS) +LD = $(TRIPLET)-ld +LDFLAGS = -nostdlib -T$(BAREOS_DIR)/hemps.ld --defsym=_stack=$(PAGE_SP_INIT) +OBJCOPY = $(TRIPLET)-objcopy +OBJDUMP = $(TRIPLET)-objdump + +PROGNAME = $(basename $(wildcard *.c)) + +DUMP_FILES = $(addsuffix .dump, $(PROGNAME)) +LST_FILES = $(addsuffix .lst, $(PROGNAME)) +TXT_FILES = $(addsuffix .txt, $(PROGNAME)) +BIN_FILES = $(addsuffix .bin, $(PROGNAME)) + +BARE_OS = $(BAREOS_DIR)/crt0.o \ + $(BAREOS_DIR)/hal.o \ + $(BAREOS_DIR)/libos.o \ + $(BAREOS_DIR)/malloc.o \ + $(BAREOS_DIR)/comm.o + + +all : $(DUMP_FILES) $(LST_FILES) $(TXT_FILES) $(BIN_FILES) + +%.dump : %.bin + $(OBJCOPY) -O binary $< $@ + +%.lst : %.bin + $(OBJDUMP) -d $< > $@ + +%.txt : %.dump + hexdump -v -e '1/1 "%02x" 1/1 "%02x" 1/1 "%02x" 1/1 "%02x" "\n"' $< > $@ + +%.o: %.c + $(CC) $(CFLAGS) -o $@ -c $< + +%.o: %.cpp + $(CPP) $(CCFLAGS) -o $@ -c $< + +%.o: %.s + $(AS) $(ASFLAGS) -o $@ $< + +%.bin: $(BARE_OS) %.o + $(LD) -o $@ $+ $(LDFLAGS) + +clean : + rm -f $(BIN_FILES) $(LST_FILES) $(BARE_OS) $(wildcard *~) $(wildcard *.o) diff --git a/hemps8.5/build_env/makes/make_kernel b/build_env/makes/make_kernel similarity index 100% rename from hemps8.5/build_env/makes/make_kernel rename to build_env/makes/make_kernel diff --git a/hemps8.5/build_env/makes/make_systemc b/build_env/makes/make_systemc similarity index 100% rename from hemps8.5/build_env/makes/make_systemc rename to build_env/makes/make_systemc diff --git a/hemps8.5/build_env/makes/make_systemc_mod b/build_env/makes/make_systemc_mod similarity index 100% rename from hemps8.5/build_env/makes/make_systemc_mod rename to build_env/makes/make_systemc_mod diff --git a/hemps8.5/build_env/makes/make_testcase b/build_env/makes/make_testcase similarity index 95% rename from hemps8.5/build_env/makes/make_testcase rename to build_env/makes/make_testcase index ee2de40..d583a9d 100644 --- a/hemps8.5/build_env/makes/make_testcase +++ b/build_env/makes/make_testcase @@ -3,7 +3,7 @@ TC_NAME=$(notdir ${CURDIR}) default: all -all: banner apps kernel hw +all: banner kernel apps hw update: @cd ..; hemps-gen $(TC_NAME).yaml 1; cd $(TC_NAME); make clean; make all; cd ..; diff --git a/hemps8.5/build_env/makes/make_vhdl b/build_env/makes/make_vhdl similarity index 94% rename from hemps8.5/build_env/makes/make_vhdl rename to build_env/makes/make_vhdl index 6b3e7a9..9c85ca9 100644 --- a/hemps8.5/build_env/makes/make_vhdl +++ b/build_env/makes/make_vhdl @@ -8,10 +8,10 @@ COMP =vcom -work $(LIB) #VHDL files HEMPS_PKG =hemps_pkg STAND =standards -TOP =hemps test_bench +TOP =hemps receive_data inject_data test_bench PE =pe DMNI =dmni -MEMORY =ram_master ram_slave +MEMORY =ram_simple ram_master ram_slave PROCESSOR =mlite_pack UartFile alu bus_mux control mem_ctrl mult pc_next pipeline reg_bank shifter mlite_cpu ROUTER =Hermes_buffer Hermes_crossbar Hermes_switchcontrol RouterCC @@ -71,4 +71,4 @@ clean: @rm -f repository* @rm -f ../modelsim.ini @rm -rf ../work - @rm -rf ../transcript \ No newline at end of file + @rm -rf ../transcript diff --git a/hemps8.5/build_env/makes/sim.do b/build_env/makes/sim.do similarity index 56% rename from hemps8.5/build_env/makes/sim.do rename to build_env/makes/sim.do index 1764d56..ce51019 100644 --- a/hemps8.5/build_env/makes/sim.do +++ b/build_env/makes/sim.do @@ -1,4 +1,4 @@ -vsim -novopt -t ps +notimingchecks hardware/work.test_bench +vsim -voptargs=+acc=lprn -t ps +notimingchecks hardware/work.test_bench do wave.do onerror {resume} diff --git a/hemps8.5/build_env/scripts/app_builder.py b/build_env/scripts/app_builder.py similarity index 86% rename from hemps8.5/build_env/scripts/app_builder.py rename to build_env/scripts/app_builder.py index d8ab419..e333c7c 100644 --- a/hemps8.5/build_env/scripts/app_builder.py +++ b/build_env/scripts/app_builder.py @@ -21,6 +21,8 @@ def main(): page_size_bytes = get_page_size_KB(yaml_r) * 1024 generate_apps_id(apps_name_list) + + generate_map_pkg(yaml_r) exit_status = os.system("cd applications/; make sp_init=" + str(page_size_bytes -1) ) @@ -28,10 +30,12 @@ def main(): sys.exit("\nError compiling applications' source code\n"); #Generate the repository.txt and repository_debug.txt files, returning a list of tuple {app_name, repo_address} - apps_repo_addr_list = generate_repository(yaml_r, apps_name_list); + #apps_repo_addr_list = generate_repository(yaml_r, apps_name_list); #Generates the appstart.txt and appstart_debug.txt files - generate_appstart(apps_repo_addr_list, yaml_r) + #generate_appstart(apps_repo_addr_list, yaml_r) + + generate_cfg_file(yaml_r) def generate_apps_id(apps_name_list): @@ -77,9 +81,63 @@ def generate_appstart(apps_repo_addr_list, yaml_r): app_start_obj.repo_address = app_address - + generate_appstart_file(apps_start_obj_list) +def generate_cfg_file(yaml_r): + + apps_file_path = "apps.cfg" + + apps_lines = [] + + app_list = get_apps_list(yaml_r) + + num_apps = len(app_list) + + for i in range(0,num_apps): + app = app_list[i] + name = app["name"] + tasks_list = app["tasks"] + apps_lines.append(name + ".cfg\n") + cfg_lines = [] + for task in tasks_list: + task_name = task["task"] + location = task["location"] + x_address = location[0] + y_address = location[1] + pos = x_address << 8 | y_address + size = get_task_txt_size(name, task_name) + cfg_lines.append("applications/" + name + "/" + task_name+".txt\n") + cfg_lines.append(toX(pos)+"\n") + cfg_lines.append(toX(size)+"\n") + cfg_file_path = name + ".cfg" + writes_file_into_testcase(cfg_file_path, cfg_lines) + + writes_file_into_testcase(apps_file_path, apps_lines) + +def generate_map_pkg(yaml_r): + + app_list = get_apps_list(yaml_r) + + + for app in app_list: + tasks_list = app["tasks"] + app_name = app["name"] + #---------------- C SINTAX ------------------ + file_lines = [] + file_lines.append("#ifndef _MAP_PKG_\n") + file_lines.append("#define _MAP_PKG_\n\n") + for task in tasks_list: + task_name = task["task"] + location = task["location"] + x_address = location[0] + y_address = location[1] + pos = x_address << 8 | y_address + file_lines.append("#define " + task_name + "\t0x" + toX(pos) + "\n") + file_lines.append("\n#endif\n") + writes_file_into_testcase("applications/" + app_name + "/map_pkg.h", file_lines) + + #Function that generates a new repository from the dir: /applications #Please, behold this following peace of art: def generate_repository(yaml_r, apps_name_list): diff --git a/hemps8.5/build_env/scripts/banner.py b/build_env/scripts/banner.py similarity index 100% rename from hemps8.5/build_env/scripts/banner.py rename to build_env/scripts/banner.py diff --git a/hemps8.5/build_env/scripts/build_utils.py b/build_env/scripts/build_utils.py similarity index 100% rename from hemps8.5/build_env/scripts/build_utils.py rename to build_env/scripts/build_utils.py diff --git a/hemps8.5/build_env/scripts/hw_builder.py b/build_env/scripts/hw_builder.py similarity index 69% rename from hemps8.5/build_env/scripts/hw_builder.py rename to build_env/scripts/hw_builder.py index bcd28b9..519f795 100644 --- a/hemps8.5/build_env/scripts/hw_builder.py +++ b/build_env/scripts/hw_builder.py @@ -29,12 +29,12 @@ def generate_hw_pkg( yaml_r ): #Variables from yaml used into this function x_mpsoc_dim = get_mpsoc_x_dim(yaml_r) y_mpsoc_dim = get_mpsoc_y_dim(yaml_r) - x_cluster_dim = get_cluster_x_dim(yaml_r) - y_cluster_dim = get_cluster_y_dim(yaml_r) - master_location = get_master_location(yaml_r) + x_cluster_dim = get_mpsoc_x_dim(yaml_r) + y_cluster_dim = get_mpsoc_y_dim(yaml_r) + #master_location = get_master_location(yaml_r) system_model_desc = get_model_description(yaml_r) - cluster_list = create_cluster_list(x_mpsoc_dim, y_mpsoc_dim, x_cluster_dim, y_cluster_dim, master_location) + cluster_list = [] #create_cluster_list(x_mpsoc_dim, y_mpsoc_dim, x_cluster_dim, y_cluster_dim, master_location) pe_type = [] #----------- Generates PEs types ---------------- @@ -120,11 +120,15 @@ def generate_to_vhdl(is_master_list, yaml_r): #Variables from yaml used into this function page_size_KB = get_page_size_KB(yaml_r) memory_size_KB = get_memory_size_KB(yaml_r) - repo_size_bytes = get_repository_size_BYTES(yaml_r) + #repo_size_bytes = get_repository_size_BYTES(yaml_r) noc_buffer_size = get_noc_buffer_size(yaml_r) x_mpsoc_dim = get_mpsoc_x_dim(yaml_r) y_mpsoc_dim = get_mpsoc_y_dim(yaml_r) app_number = get_apps_number(yaml_r) + simple_soc = get_simple_soc(yaml_r) + open_ports = get_open_ports(yaml_r) + io_number = get_io_number(yaml_r) + apps_list = get_apps_list(yaml_r) #These lines compute the logical memory addresses used by the mlite to index the pages at the local memory @@ -144,6 +148,48 @@ def generate_to_vhdl(is_master_list, yaml_r): #Remove the lost ',' in the string_pe_type_vhdl string_pe_type_vhdl = string_pe_type_vhdl[0:len(string_pe_type_vhdl)-1] + + open_ports_vector = [] + for i in range(0,x_mpsoc_dim*y_mpsoc_dim): + open_ports_vector.append("gnd"); + + for port in open_ports: + index = port[1]*x_mpsoc_dim + port[0] + if port[2] == "N": + open_ports_vector[index] = "nor" + if port[2] == "S": + open_ports_vector[index] = "sou" + if port[2] == "E": + open_ports_vector[index] = "eas" + if port[2] == "W": + open_ports_vector[index] = "wes" + + if open_ports[0][2] == "N": + loader_addr = 0xC0000000 + if open_ports[0][2] == "S": + loader_addr = 0xE0000000 + if open_ports[0][2] == "E": + loader_addr = 0x80000000 + if open_ports[0][2] == "W": + loader_addr = 0xA0000000 + + loader_addr = loader_addr + (open_ports[0][1] << 8) + open_ports[0][1] + + + open_ports_string = "" + for i in range(0,x_mpsoc_dim*y_mpsoc_dim): + open_ports_string = open_ports_string + "\"" + open_ports_vector[i] + "\"," + open_ports_string = open_ports_string[0:len(open_ports_string)-1] + + #Computes the max of tasks into an app + max_task_per_app = 0 #len(taks_list) + for app in apps_list: + tasks_list = app["tasks"] + + task_count = len( tasks_list ) + + if task_count > max_task_per_app: + max_task_per_app = task_count file_lines = [] @@ -156,21 +202,28 @@ def generate_to_vhdl(is_master_list, yaml_r): file_lines.append(" -- paging definitions\n") file_lines.append(" constant PAGE_SIZE_BYTES : integer := "+str(page_size_KB*1024)+";\n") file_lines.append(" constant MEMORY_SIZE_BYTES : integer := "+str(memory_size_KB*1024)+";\n") - file_lines.append(" constant TOTAL_REPO_SIZE_BYTES : integer := "+str(repo_size_bytes)+";\n") + #file_lines.append(" constant TOTAL_REPO_SIZE_BYTES : integer := "+str(repo_size_bytes)+";\n") file_lines.append(" constant APP_NUMBER : integer := "+str(app_number)+";\n") + file_lines.append(" constant MAX_TASKS_APP : integer := "+str(max_task_per_app)+";\n") file_lines.append(" constant PAGE_SIZE_H_INDEX : integer := "+str(page_size_h_index)+";\n") file_lines.append(" constant PAGE_NUMBER_H_INDEX : integer := "+str(page_number_h_index)+";\n") file_lines.append(" -- Hemps top definitions\n") file_lines.append(" constant NUMBER_PROCESSORS_X : integer := "+str(x_mpsoc_dim)+";\n") file_lines.append(" constant NUMBER_PROCESSORS_Y : integer := "+str(y_mpsoc_dim)+";\n") file_lines.append(" constant TAM_BUFFER : integer := "+str(noc_buffer_size)+";\n") - file_lines.append(" constant NUMBER_PROCESSORS : integer := "+str(x_mpsoc_dim*y_mpsoc_dim)+";\n\n") + file_lines.append(" constant NUMBER_PROCESSORS : integer := "+str(x_mpsoc_dim*y_mpsoc_dim)+";\n") + file_lines.append(" constant SIMPLE_SOC : boolean := "+str(simple_soc)+";\n") + file_lines.append(" constant IO_NUMBER : integer := "+str(io_number)+";\n") + file_lines.append(" constant LOADER_NETADDR : std_logic_vector(31 downto 0) := x\"%x\";\n\n" % loader_addr) file_lines.append(" subtype kernel_str is string(1 to 3);\n") - file_lines.append(" type pe_type_t is array(0 to NUMBER_PROCESSORS-1) of kernel_str;\n") - file_lines.append(" constant pe_type : pe_type_t := ("+string_pe_type_vhdl+");\n\n") + #file_lines.append(" type pe_type_t is array(0 to NUMBER_PROCESSORS-1) of kernel_str;\n") + #file_lines.append(" constant pe_type : pe_type_t := ("+string_pe_type_vhdl+");\n\n") + file_lines.append(" subtype manual_io_option is string(1 to 3);\n") + file_lines.append(" type manual_io_type is array(0 to NUMBER_PROCESSORS-1) of manual_io_option;\n") + file_lines.append(" constant OPEN_IO : manual_io_type := ("+open_ports_string+");\n\n") file_lines.append("end hemps_pkg;\n") #Use this function to create any file into testcase, it automatically only updates the old file if necessary writes_file_into_testcase("include/hemps_pkg.vhd", file_lines) -main() \ No newline at end of file +main() diff --git a/hemps8.5/build_env/scripts/kernel_builder.py b/build_env/scripts/kernel_builder.py similarity index 92% rename from hemps8.5/build_env/scripts/kernel_builder.py rename to build_env/scripts/kernel_builder.py index d340cbe..6d5ded5 100644 --- a/hemps8.5/build_env/scripts/kernel_builder.py +++ b/build_env/scripts/kernel_builder.py @@ -40,10 +40,10 @@ def generate_sw_pkg( yaml_r ): max_local_tasks = get_tasks_per_PE(yaml_r) x_mpsoc_dim = get_mpsoc_x_dim(yaml_r) y_mpsoc_dim = get_mpsoc_y_dim(yaml_r) - x_cluster_dim = get_cluster_x_dim(yaml_r) - y_cluster_dim = get_cluster_y_dim(yaml_r) - master_location = get_master_location(yaml_r) - apps_list = get_apps_name_list(yaml_r) + x_cluster_dim = get_mpsoc_x_dim(yaml_r) + y_cluster_dim = get_mpsoc_y_dim(yaml_r) + master_location = "LB" #get_master_location(yaml_r) + apps_list = get_apps_list(yaml_r) static_mapping_list = get_static_mapping_list(yaml_r) @@ -53,14 +53,15 @@ def generate_sw_pkg( yaml_r ): max_slave_processors = (x_mpsoc_dim*y_mpsoc_dim) - master_number max_cluster_slave = (x_cluster_dim * y_cluster_dim) - 1 apps_number = len(apps_list) - static_lenght = str(len(static_mapping_list)) - + static_lenght = str(len(static_mapping_list)) + + #Computes the max of tasks into an app - max_task_per_app = 0 - - for app_name in apps_list: + max_task_per_app = 0 #len(taks_list) + for app in apps_list: + tasks_list = app["tasks"] - task_count = len( get_app_task_name_list(".", app_name) ) + task_count = len( tasks_list ) if task_count > max_task_per_app: max_task_per_app = task_count @@ -161,10 +162,10 @@ def generate_memory( yaml_r ): #Variables from yaml used into this function x_mpsoc_dim = get_mpsoc_x_dim(yaml_r) y_mpsoc_dim = get_mpsoc_y_dim(yaml_r) - x_cluster_dim = get_cluster_x_dim(yaml_r) - y_cluster_dim = get_cluster_y_dim(yaml_r) + x_cluster_dim = get_mpsoc_x_dim(yaml_r) + y_cluster_dim = get_mpsoc_y_dim(yaml_r) model_descr = get_model_description(yaml_r) - master_location = get_master_location(yaml_r) + master_location = "LB" #get_master_location(yaml_r) mem_size_KB = get_memory_size_KB(yaml_r) @@ -190,6 +191,9 @@ def generate_memory( yaml_r ): ext_slave = os.system("cd software; ram_generator " + str(gen_compatible_mem_size) + " -rtl kernel_slave.txt > ../ram_pe/ram_slave.vhd") ext_master = os.system("cd software; ram_generator " + str(gen_compatible_mem_size) + " -rtl kernel_master.txt > ../ram_pe/ram_master.vhd") + + os.system("cd software; echo 00000000 > ram_simple.txt"); + os.system("cd software; ram_generator " + str(gen_compatible_mem_size) + " -rtl ram_simple.txt > ../ram_pe/ram_simple.vhd") if ext_master != 0 or ext_slave != 0 or gen_compatible_mem_size == 0: sys.exit("ERROR: Error in the ram_generation process") diff --git a/hemps8.5/build_env/scripts/yaml_intf.py b/build_env/scripts/yaml_intf.py similarity index 86% rename from hemps8.5/build_env/scripts/yaml_intf.py rename to build_env/scripts/yaml_intf.py index 4c64c52..8f87890 100644 --- a/hemps8.5/build_env/scripts/yaml_intf.py +++ b/build_env/scripts/yaml_intf.py @@ -78,6 +78,22 @@ def get_apps_name_list(yaml_reader): return apps_name_list +def get_apps_list(yaml_reader): + + apps_list = yaml_reader["apps"] + return apps_list + +def get_apps_location_list(yaml_reader): + + apps_list = yaml_reader["apps"] + + apps_location_list = [] + + for app in apps_list: + apps_location_list.append(app["location"]) + + return apps_location_list + def get_apps_number(yaml_reader): number = len(get_apps_name_list(yaml_reader)) return number @@ -88,6 +104,30 @@ def get_task_scheduler(yaml_reader): def get_app_repo_size(yaml_reader): return 1000 +def get_simple_soc(yaml_reader): + if 'simple_soc' in yaml_reader["hw"]: + return yaml_reader["hw"]["simple_soc"] + else: + return False + +def get_open_ports(yaml_reader): + io_list = yaml_reader["hw"]["open_port"] + + open_port_list = [] + + for port in io_list: + open_port_list.append(port["port"]) + + return open_port_list + +def get_io_number(yaml_reader): + number = len(get_open_ports(yaml_reader)) + return number + + +#def get_cfg_params(yaml_reader): +# app_names = [] +# for app_n in yaml_reader["apps"]: #------- Repository Generation Scope ------------------- #ATTENTION: STATIC MAPPING ONLY WORKS IF THE APPS START TIME ARE ORDERED diff --git a/hemps8.5/build_env/testcase_builder.py b/build_env/testcase_builder.py similarity index 99% rename from hemps8.5/build_env/testcase_builder.py rename to build_env/testcase_builder.py index a2ab2f4..9fa068e 100644 --- a/hemps8.5/build_env/testcase_builder.py +++ b/build_env/testcase_builder.py @@ -84,6 +84,8 @@ def main(): copy_hardware( HEMPS_PATH, TESTCASE_NAME, model_description) copy_makefiles( HEMPS_PATH, TESTCASE_NAME, page_size_KB, memory_size_KB, model_description, apps_name_list, simul_time) copy_testcase_file( TESTCASE_NAME, INPUT_TESTCASE_FILE_PATH) + #Calls the hemps-wave_gen script if + generate_wave(INPUT_TESTCASE_FILE_PATH) #Create other importatants dirs create_ifn_exists(TESTCASE_NAME+"/include") @@ -91,9 +93,7 @@ def main(): #Calls the deloream_env.py to generate all necessary debugging dir and files generate_deloream_env(TESTCASE_NAME, yaml_reader) - - #Calls the hemps-wave_gen script if - generate_wave(INPUT_TESTCASE_FILE_PATH) + # ----------------------------------------- FUNCTIONS --------------------------------------------- diff --git a/hemps8.5/docs/hemps_doxy.conf b/docs/hemps_doxy.conf similarity index 100% rename from hemps8.5/docs/hemps_doxy.conf rename to docs/hemps_doxy.conf diff --git a/hemps8.5/hardware/sc/hemps.cpp b/hardware/sc/hemps.cpp similarity index 100% rename from hemps8.5/hardware/sc/hemps.cpp rename to hardware/sc/hemps.cpp diff --git a/hemps8.5/hardware/sc/hemps.h b/hardware/sc/hemps.h similarity index 100% rename from hemps8.5/hardware/sc/hemps.h rename to hardware/sc/hemps.h diff --git a/hemps8.5/hardware/sc/pe/dmni/dmni.cpp b/hardware/sc/pe/dmni/dmni.cpp similarity index 100% rename from hemps8.5/hardware/sc/pe/dmni/dmni.cpp rename to hardware/sc/pe/dmni/dmni.cpp diff --git a/hemps8.5/hardware/sc/pe/dmni/dmni.h b/hardware/sc/pe/dmni/dmni.h similarity index 100% rename from hemps8.5/hardware/sc/pe/dmni/dmni.h rename to hardware/sc/pe/dmni/dmni.h diff --git a/hemps8.5/hardware/sc/pe/memory/ram.cpp b/hardware/sc/pe/memory/ram.cpp similarity index 100% rename from hemps8.5/hardware/sc/pe/memory/ram.cpp rename to hardware/sc/pe/memory/ram.cpp diff --git a/hemps8.5/hardware/sc/pe/memory/ram.h b/hardware/sc/pe/memory/ram.h similarity index 100% rename from hemps8.5/hardware/sc/pe/memory/ram.h rename to hardware/sc/pe/memory/ram.h diff --git a/hemps8.5/hardware/sc/pe/pe.cpp b/hardware/sc/pe/pe.cpp similarity index 100% rename from hemps8.5/hardware/sc/pe/pe.cpp rename to hardware/sc/pe/pe.cpp diff --git a/hemps8.5/hardware/sc/pe/pe.h b/hardware/sc/pe/pe.h similarity index 100% rename from hemps8.5/hardware/sc/pe/pe.h rename to hardware/sc/pe/pe.h diff --git a/hemps8.5/hardware/sc/pe/processor/plasma/mlite_cpu.cpp b/hardware/sc/pe/processor/plasma/mlite_cpu.cpp similarity index 100% rename from hemps8.5/hardware/sc/pe/processor/plasma/mlite_cpu.cpp rename to hardware/sc/pe/processor/plasma/mlite_cpu.cpp diff --git a/hemps8.5/hardware/sc/pe/processor/plasma/mlite_cpu.h b/hardware/sc/pe/processor/plasma/mlite_cpu.h similarity index 100% rename from hemps8.5/hardware/sc/pe/processor/plasma/mlite_cpu.h rename to hardware/sc/pe/processor/plasma/mlite_cpu.h diff --git a/hemps8.5/hardware/sc/pe/router/queue.cpp b/hardware/sc/pe/router/queue.cpp similarity index 100% rename from hemps8.5/hardware/sc/pe/router/queue.cpp rename to hardware/sc/pe/router/queue.cpp diff --git a/hemps8.5/hardware/sc/pe/router/queue.h b/hardware/sc/pe/router/queue.h similarity index 100% rename from hemps8.5/hardware/sc/pe/router/queue.h rename to hardware/sc/pe/router/queue.h diff --git a/hemps8.5/hardware/sc/pe/router/router_cc.cpp b/hardware/sc/pe/router/router_cc.cpp similarity index 100% rename from hemps8.5/hardware/sc/pe/router/router_cc.cpp rename to hardware/sc/pe/router/router_cc.cpp diff --git a/hemps8.5/hardware/sc/pe/router/router_cc.h b/hardware/sc/pe/router/router_cc.h similarity index 100% rename from hemps8.5/hardware/sc/pe/router/router_cc.h rename to hardware/sc/pe/router/router_cc.h diff --git a/hemps8.5/hardware/sc/pe/router/switchcontrol.cpp b/hardware/sc/pe/router/switchcontrol.cpp similarity index 100% rename from hemps8.5/hardware/sc/pe/router/switchcontrol.cpp rename to hardware/sc/pe/router/switchcontrol.cpp diff --git a/hemps8.5/hardware/sc/pe/router/switchcontrol.h b/hardware/sc/pe/router/switchcontrol.h similarity index 100% rename from hemps8.5/hardware/sc/pe/router/switchcontrol.h rename to hardware/sc/pe/router/switchcontrol.h diff --git a/hemps8.5/hardware/sc/standards.h b/hardware/sc/standards.h similarity index 100% rename from hemps8.5/hardware/sc/standards.h rename to hardware/sc/standards.h diff --git a/hemps8.5/hardware/sc/test_bench.cpp b/hardware/sc/test_bench.cpp similarity index 100% rename from hemps8.5/hardware/sc/test_bench.cpp rename to hardware/sc/test_bench.cpp diff --git a/hemps8.5/hardware/sc/test_bench.h b/hardware/sc/test_bench.h similarity index 100% rename from hemps8.5/hardware/sc/test_bench.h rename to hardware/sc/test_bench.h diff --git a/hardware/vhdl/hemps.vhd b/hardware/vhdl/hemps.vhd new file mode 100644 index 0000000..53876f7 --- /dev/null +++ b/hardware/vhdl/hemps.vhd @@ -0,0 +1,269 @@ +------------------------------------------------------------------------------------------------ +-- +-- DISTRIBUTED HEMPS - version 5.0 +-- +-- Research group: GAPH-PUCRS - contact fernando.moraes@pucrs.br +-- +-- Distribution: September 2013 +-- +-- Source name: HeMPS.vhd +-- +-- Brief description: NoC generation +-- +------------------------------------------------------------------------------------------------ + +library IEEE; +use ieee.std_logic_1164.all; +use ieee.std_logic_arith.all; +use ieee.std_logic_unsigned.all; +use work.standards.all; +use work.hemps_pkg.all; + +entity HeMPS is -- Interface com o ambiente exterior + port( + clock : in std_logic; + reset : in std_logic; + + -- Tasks repository interface + repo_address : out std_logic_vector(29 downto 0); + repo_data : in std_logic_vector(31 downto 0); + ack_app : out std_logic; + req_app : in std_logic_vector(31 downto 0); + + --NoC Interface (IO) + tx_io : out std_logic_vector((IO_NUMBER-1) downto 0); + data_out_io : out arrayNio_regflit; + credit_i_io : in std_logic_vector((IO_NUMBER-1) downto 0); + clock_tx_io : out std_logic_vector((IO_NUMBER-1) downto 0); + rx_io : in std_logic_vector((IO_NUMBER-1) downto 0); + data_in_io : in arrayNio_regflit; + credit_o_io : out std_logic_vector((IO_NUMBER-1) downto 0); + clock_rx_io : in std_logic_vector((IO_NUMBER-1) downto 0) + + -- External Debug interface +-- write_enable_debug : out std_logic; +-- data_out_debug : out std_logic_vector(31 downto 0); +-- busy_debug : in std_logic; + + ); +end; + +architecture HeMPS of HeMPS is --Relacao entre as portas + + -- Interconnection signals + type txNport is array (NUMBER_PROCESSORS - 1 downto 0) of std_logic_vector(3 downto 0); + signal tx : txNPORT; + type rxNport is array (NUMBER_PROCESSORS - 1 downto 0) of std_logic_vector(3 downto 0); + signal rx : rxNPORT; + type clock_rxNport is array (NUMBER_PROCESSORS - 1 downto 0) of std_logic_vector(3 downto 0); + signal clock_rx : clock_rxNPORT; + type clock_txNport is array (NUMBER_PROCESSORS - 1 downto 0) of std_logic_vector(3 downto 0); + signal clock_tx : clock_txNPORT; + type credit_iNport is array (NUMBER_PROCESSORS - 1 downto 0) of std_logic_vector(3 downto 0); + signal credit_i : credit_iNPORT; + type credit_oNport is array (NUMBER_PROCESSORS - 1 downto 0) of std_logic_vector(3 downto 0); + signal credit_o : credit_oNPORT; + type data_inNport is array (NUMBER_PROCESSORS - 1 downto 0) of arrayNPORT_1_regflit; + signal data_in : data_inNPORT; + type data_outNport is array (NUMBER_PROCESSORS - 1 downto 0) of arrayNPORT_1_regflit; + signal data_out : data_outNPORT; + signal address_router : std_logic_vector(7 downto 0); + type router_position is array (NUMBER_PROCESSORS - 1 downto 0) of integer range 0 to TR; + signal position : router_position; + + type repo_address_t is array (NUMBER_PROCESSORS - 1 downto 0) of std_logic_vector(29 downto 0); + signal repo_address_sig : repo_address_t; + signal repo_data_sig : arrayNPe_reg32; + signal ack_app_sig : regNPe; + signal req_app_sig : arrayNPe_reg32; + +begin + + core_type_gen : for i in 0 to NUMBER_PROCESSORS-1 generate + position(i) <= RouterPosition(i); + end generate core_type_gen; + + + proc : for i in 0 to NUMBER_PROCESSORS-1 generate --Gera uma matriz de processadores homeogenios + + PE : entity work.pe + generic map ( + router_address => RouterAddress(i), + kernel_type => "sla", + log_file => log_filename(i), + simple_soc => SIMPLE_SOC, + manual_NORTH => ManualNORTHbyPos(i), + manual_SOUTH => ManualSOUTHbyPos(i), + manual_EAST => ManualEASTbyPos(i), + manual_WEST => ManualWESTbyPos(i)) + port map( + clock => clock, + reset => reset, + -- NoC + clock_tx => clock_tx(i), + tx => tx(i), + data_out => data_out(i), + credit_i => credit_i(i), + clock_rx => clock_rx(i), + rx => rx(i), + data_in => data_in(i), + credit_o => credit_o(i), + -- External Memory + repo_address => repo_address_sig(i), + repo_data_read => repo_data_sig(i), + ack_app => ack_app_sig(i), + req_app => req_app_sig(i) + -- External Debug interface +-- write_enable_debug => write_enable_debug_sig(i), +-- data_out_debug => data_out_debug_sig(i), +-- busy_debug => busy_debug_sig(i) + + ); + + ------------------------------------------------------------------------------ + --- REPOSITORY CONNECTIONS ---------------------------------------------------- + ------------------------------------------------------------------------------ + repo_mas : if RouterPosition(i) = BL generate + repo_address <= repo_address_sig(i); + repo_data_sig(i) <= repo_data; + ack_app <= ack_app_sig(i); + req_app_sig(i) <= req_app; + end generate; + + ground_repo : if RouterPosition(i) /= BL generate + repo_address_sig(i) <= (others => '0'); + repo_data_sig(i) <= (others => '0'); + ack_app_sig(i) <= '0'; + req_app_sig(i) <= (others => '0'); + end generate; + + + + + + -- Returns the router position in the mesh + -- BR: Botton Right + -- BL: Botton Left + -- TR: Top Right + -- TL: Top Left + -- CRX: Center Right + -- CL: Center Left + -- CC: Center + -- 4x4 positions exemple + -- TL TC TC TR + -- CL CC CC CRX + -- CL CC CC CRX + -- BL BC BC BR + + + + ------------------------------------------------------------------------------ + --- EAST PORT CONNECTIONS ---------------------------------------------------- + ------------------------------------------------------------------------------ + east_io : if OPEN_IO(i) = "eas" generate + rx(i)(EAST) <= rx_io(io_index(i)); + clock_rx(i)(EAST) <= clock_rx_io(io_index(i)); + credit_i(i)(EAST) <= credit_i_io(io_index(i)); + data_in(i)(EAST) <= data_in_io(io_index(i)); + tx_io(io_index(i)) <= tx(i)(EAST); + clock_tx_io(io_index(i)) <= clock_tx(i)(EAST); + credit_o_io(io_index(i)) <= credit_o(i)(EAST); + data_out_io(io_index(i)) <= data_out(i)(EAST); + end generate; + east_grounding : if OPEN_IO(i) = "gnd" and (RouterPosition(i) = BR or RouterPosition(i) = CRX or RouterPosition(i) = TR) generate + rx(i)(EAST) <= '0'; + clock_rx(i)(EAST) <= '0'; + credit_i(i)(EAST) <= '0'; + data_in(i)(EAST) <= (others => '0'); + end generate; + + east_connection : if RouterPosition(i) = BL or RouterPosition(i) = CL or RouterPosition(i) = TL or RouterPosition(i) = BC or RouterPosition(i) = TC or RouterPosition(i) = CC generate + rx(i)(EAST) <= tx(i+1)(WEST); + clock_rx(i)(EAST) <= clock_tx(i+1)(WEST); + credit_i(i)(EAST) <= credit_o(i+1)(WEST); + data_in(i)(EAST) <= data_out(i+1)(WEST); + end generate; + + ------------------------------------------------------------------------------ + --- WEST PORT CONNECTIONS ---------------------------------------------------- + ------------------------------------------------------------------------------ + west_io : if OPEN_IO(i) = "wes" generate + rx(i)(WEST) <= rx_io(io_index(i)); + clock_rx(i)(WEST) <= clock_rx_io(io_index(i)); + credit_i(i)(WEST) <= credit_i_io(io_index(i)); + data_in(i)(WEST) <= data_in_io(io_index(i)); + tx_io(io_index(i)) <= tx(i)(WEST); + clock_tx_io(io_index(i)) <= clock_tx(i)(WEST); + credit_o_io(io_index(i)) <= credit_o(i)(WEST); + data_out_io(io_index(i)) <= data_out(i)(WEST); + end generate; + west_grounding : if OPEN_IO(i) = "gnd" and (RouterPosition(i) = BL or RouterPosition(i) = CL or RouterPosition(i) = TL) generate + rx(i)(WEST) <= '0'; + clock_rx(i)(WEST) <= '0'; + credit_i(i)(WEST) <= '0'; + data_in(i)(WEST) <= (others => '0'); + end generate; + + west_connection : if (RouterPosition(i) = BR or RouterPosition(i) = CRX or RouterPosition(i) = TR or RouterPosition(i) = BC or RouterPosition(i) = TC or RouterPosition(i) = CC) generate + rx(i)(WEST) <= tx(i-1)(EAST); + clock_rx(i)(WEST) <= clock_tx(i-1)(EAST); + credit_i(i)(WEST) <= credit_o(i-1)(EAST); + data_in(i)(WEST) <= data_out(i-1)(EAST); + end generate; + + ------------------------------------------------------------------------------- + --- NORTH PORT CONNECTIONS ---------------------------------------------------- + ------------------------------------------------------------------------------- + north_io : if OPEN_IO(i) = "nor" generate + rx(i)(NORTH) <= rx_io(io_index(i)); + clock_rx(i)(NORTH) <= clock_rx_io(io_index(i)); + credit_i(i)(NORTH) <= credit_i_io(io_index(i)); + data_in(i)(NORTH) <= data_in_io(io_index(i)); + tx_io(io_index(i)) <= tx(i)(NORTH); + clock_tx_io(io_index(i)) <= clock_tx(i)(NORTH); + credit_o_io(io_index(i)) <= credit_o(i)(NORTH); + data_out_io(io_index(i)) <= data_out(i)(NORTH); + end generate; + north_grounding : if OPEN_IO(i) = "gnd" and (RouterPosition(i) = TL or RouterPosition(i) = TC or RouterPosition(i) = TR) generate + rx(i)(NORTH) <= '0'; + clock_rx(i)(NORTH) <= '0'; + credit_i(i)(NORTH) <= '0'; + data_in(i)(NORTH) <= (others => '0'); + end generate; + + north_connection : if RouterPosition(i) = BL or RouterPosition(i) = BC or RouterPosition(i) = BR or RouterPosition(i) = CL or RouterPosition(i) = CRX or RouterPosition(i) = CC generate + rx(i)(NORTH) <= tx(i+NUMBER_PROCESSORS_X)(SOUTH); + clock_rx(i)(NORTH) <= clock_tx(i+NUMBER_PROCESSORS_X)(SOUTH); + credit_i(i)(NORTH) <= credit_o(i+NUMBER_PROCESSORS_X)(SOUTH); + data_in(i)(NORTH) <= data_out(i+NUMBER_PROCESSORS_X)(SOUTH); + end generate; + + -------------------------------------------------------------------------------- + --- SOUTH PORT CONNECTIONS ----------------------------------------------------- + --------------------------------------------------------------------------- + south_io : if OPEN_IO(i) = "sou" generate + rx(i)(SOUTH) <= rx_io(io_index(i)); + clock_rx(i)(SOUTH) <= clock_rx_io(io_index(i)); + credit_i(i)(SOUTH) <= credit_i_io(io_index(i)); + data_in(i)(SOUTH) <= data_in_io(io_index(i)); + tx_io(io_index(i)) <= tx(i)(SOUTH); + clock_tx_io(io_index(i)) <= clock_tx(i)(SOUTH); + credit_o_io(io_index(i)) <= credit_o(i)(SOUTH); + data_out_io(io_index(i)) <= data_out(i)(SOUTH); + end generate; + south_grounding : if OPEN_IO(i) = "gnd" and (RouterPosition(i) = BL or RouterPosition(i) = BC or RouterPosition(i) = BR) generate + rx(i)(SOUTH) <= '0'; + clock_rx(i)(SOUTH) <= '0'; + credit_i(i)(SOUTH) <= '0'; + data_in(i)(SOUTH) <= (others => '0'); + end generate; + + south_connection : if RouterPosition(i) = TL or RouterPosition(i) = TC or RouterPosition(i) = TR or RouterPosition(i) = CL or RouterPosition(i) = CRX or RouterPosition(i) = CC generate + rx(i)(SOUTH) <= tx(i-NUMBER_PROCESSORS_X)(NORTH); + clock_rx(i)(SOUTH) <= clock_tx(i-NUMBER_PROCESSORS_X)(NORTH); + credit_i(i)(SOUTH) <= credit_o(i-NUMBER_PROCESSORS_X)(NORTH); + data_in(i)(SOUTH) <= data_out(i-NUMBER_PROCESSORS_X)(NORTH); + end generate; + end generate proc; + +end architecture; diff --git a/hardware/vhdl/inject_data.vhd b/hardware/vhdl/inject_data.vhd new file mode 100644 index 0000000..1d94ed8 --- /dev/null +++ b/hardware/vhdl/inject_data.vhd @@ -0,0 +1,156 @@ +library STD; +use STD.TEXTIO.all; +library IEEE; +use IEEE.std_logic_1164.all; +use IEEE.std_logic_unsigned.all; +use IEEE.std_logic_textio.all; +library work; +use work.hemps_pkg.all; +use work.standards.all; + +------------------------------------------------------------------------------- +-- Ports are labelled from the router's perspective +------------------------------------------------------------------------------- +entity inject_data is + generic(router_nb : integer; + port_name : string); + port( + clock : in std_logic; + reset : in std_logic; + + clock_rx : out std_logic; + rx : out std_logic; + data_in : out regflit; + credit_o : in std_logic); +end inject_data; + + +architecture inject_data of inject_data is + + ---arquivos com os pacotes - pacotes de até 256 flits, e max 100 pacotes por arquivo + + type packet is array (0 to 256) of std_logic_vector(31 downto 0); + + type packet_array is array(0 to 100) of packet; + + signal packets : packet_array; --- packet read from a file + + signal packet_number : integer := 0; + --signal dta_out : string(1 to 8); + + +begin + + clock_rx <= clock; -- enable the router to inject data + + --------------------------------------------------------------------------------------------- + -- inject traffic + --------------------------------------------------------------------------------------------- + process + variable i, ix : integer; + variable ARQ_LINE : line; + variable line_arq : string(1 to 2000); + variable count_flit : integer := 0; + variable position : integer := 1; + file file_out : text; + variable fstatus : file_open_status; + variable dta_out : string(1 to 8); + begin + + rx <= '0'; -- if the file is empty, there is no injection + ix := 0; + + wait for 200 ns; -- condition to start injecting the packets (in fact 200 ns is the time required to read the file and restart the injection) + + -- loop to inject all packets described in the input file + if packet_number > 0 then + + loop + i := 0; + while i < CONV_INTEGER(packets(ix)(1) + 2) loop -- header + packet size + + if credit_o = '1' then -- flow control + file_open(fstatus, file_out, "inj" & integer'image(router_nb) & port_name & ".txt", write_mode); + dta_out := CONV_STRING_32BITS(packets(ix)(i)); + write(ARQ_LINE, dta_out & " " & "," & " " & time'image(NOW)); + writeline(file_out, ARQ_LINE); + rx <= '1'; + data_in <= packets(ix)(i); + wait for 10 ns; + rx <= '0'; + wait for 10 ns; + i := i + 1; + else + wait for 10 ns; + rx <= '0'; + end if; + + end loop; + + wait for 10 ns; -- time between packets - MUDEI MORAES - 07/JULHO + + ix := ix + 1; -- next packet + + exit when ix = packet_number; + + end loop; + end if; + end process; + + --------------------------------------------------------------------------------------------- + -- read the file + --------------------------------------------------------------------------------------------- + process + variable ARQ_LINE : line; + variable line_arq : string(1 to 2000); + variable count_flit : integer := 0; + variable position : integer := 1; + file file_in : text; + variable fstatus : file_open_status; + begin + + wait until reset = '1'; -- start reading the file + + file_open(fstatus, file_in, "in" & integer'image(router_nb) & port_name & ".txt", read_mode); + + if fstatus = open_ok then + + assert false report "Reading file in"& integer'image(router_nb) & port_name & ".txt" + severity note; + + while not (endfile(file_in)) loop -- one packet per line ----- + + readline(file_in, ARQ_LINE); + read(ARQ_LINE, line_arq(1 to ARQ_LINE'length)); ---- read the line + + report "The line is " & line_arq; + + position := 1; + count_flit := 0; -- flit number + loop + for w in 0 to 7 loop + packets(packet_number)(count_flit)((31-w*4) downto (32-(w+1)*4)) <= CONV_VECTOR(line_arq(position+w to position+w+1), 1); + end loop; + + position := position + 9; + count_flit := count_flit + 1; + + wait for 2 ps; -- tempo para avançar o processo (tricki!) + + exit when count_flit > 2 and count_flit = (CONV_INTEGER(packets(packet_number)(1)) + 2); -- second flit is the packet size + + end loop; + + packet_number <= packet_number + 1; --- number of lines of the traffic file + + wait for 2 ps; --required, to wait the next line :-) + + end loop; -- end loop da linha + else + assert false report "Could not open in"& integer'image(router_nb) & port_name & ".txt" + severity note; + end if; + + end process; + +end inject_data; diff --git a/hardware/vhdl/pe/dmni/dmni.vhd b/hardware/vhdl/pe/dmni/dmni.vhd new file mode 100644 index 0000000..1b69c99 --- /dev/null +++ b/hardware/vhdl/pe/dmni/dmni.vhd @@ -0,0 +1,527 @@ +------------------------------------------------------------------------------------------------ +-- +-- DISTRIBUTED HEMPS - version 7.0 +-- +-- Research group: GAPH-PUCRS - contact fernando.moraes@pucrs.br +-- +-- Distribution: May 2015 +-- +-- Source name: dmni.vhd +-- +-- Brief description: Implements a DMNI module. +-- +-- OPERATIONS: +-- 0 - Copy from memory +-- 1 - Copy to memory +--------------------------------------------------------------------- + +library ieee; +use ieee.std_logic_1164.all; +use ieee.std_logic_unsigned.all; +use ieee.std_logic_arith.all; +use work.hemps_pkg.all; +use work.standards.all; + +entity dmni is + generic(address_router : regmetadeflit := (others => '0')); + port( + clock : in std_logic; + reset : in std_logic; + -- Configuration interface + set_address : in std_logic; + set_address_2 : in std_logic; + set_size : in std_logic; + set_size_2 : in std_logic; + set_op : in std_logic; + start : in std_logic; + set_buff : in std_logic; + set_reset_cpu : in std_logic; + request_read : in std_logic; + config_data : in std_logic_vector(31 downto 0); + -- Status outputs + intr : out std_logic; + send_active : out std_logic; + receive_active : out std_logic; + reset_cpu : out std_logic; + recv_buff_out : out std_logic_vector(31 downto 0); + last_req : out std_logic_vector(31 downto 0); + -- Memory interface + mem_address : out std_logic_vector(31 downto 0); + mem_data_write : out std_logic_vector(31 downto 0); + mem_data_read : in std_logic_vector(31 downto 0); + mem_byte_we : out std_logic_vector(3 downto 0); + -- Noc Interface (Local port) + tx : out std_logic; + data_out : out regflit; + credit_i : in std_logic; + clock_tx : out std_logic; + rx : in std_logic; + data_in : in regflit; + credit_o : out std_logic; + clock_rx : in std_logic); +end; + +architecture dmni of dmni is + + constant DMNI_TIMER : std_logic_vector(4 downto 0) := "10000"; + constant WORD_SIZE : std_logic_vector(4 downto 0) := "00100"; + + type dmni_state is (WAIT_state, LOAD, COPY_FROM_MEM, COPY_TO_MEM, COPY_TO_MEM_DMA, COPY_TO_FIFO, DISCARD, FINISH); + type operation_type is (LEGACY, DMMA, MSG_REQ, START_CPU); + signal DMNI_Send : dmni_state; + signal DMNI_Receive : dmni_state; + + type noc_state is (HEADER, PAYLOAD, DATA); + signal SR : noc_state; + + type arbiter_state is (ROUND, SEND, RECEIVE); + signal ARB : arbiter_state; + + signal bufferr : buff_dmni := (others => (others => '0')); + subtype buffsizebool is std_logic_vector(0 to (TAM_BUFFER_DMNI-1)); + signal is_header : buffsizebool := (others => '0'); + signal intr_count : std_logic_vector(3 downto 0); + + signal first, last : pointer := (others => '0'); + signal add_buffer : std_logic; + + signal payload_size : regflit; + + signal timer : std_logic_vector(4 downto 0); + signal address : std_logic_vector(31 downto 0); + signal address_2 : std_logic_vector(31 downto 0); + signal size : std_logic_vector(31 downto 0); + signal size_2 : std_logic_vector(31 downto 0); + signal send_address : std_logic_vector(31 downto 0); + signal send_address_2 : std_logic_vector(31 downto 0); + signal send_size : std_logic_vector(31 downto 0); + signal send_size_2 : std_logic_vector(31 downto 0); + signal recv_address : std_logic_vector(31 downto 0); + signal recv_size : std_logic_vector(31 downto 0); + signal recv_buffer : std_logic_vector(31 downto 0); + signal dmma_done : std_logic; + signal prio : std_logic; + signal operation : std_logic; + signal read_av : std_logic; + signal slot_available : std_logic; + signal read_enable : std_logic; + signal write_enable : std_logic; + + signal send_active_2 : std_logic; + signal receive_active_2 : std_logic; + signal intr_counter_temp : std_logic_vector(3 downto 0); + + signal reset_cpu_r : std_logic; + signal payload_fix : regflit; + signal sizedata_fix : regflit; + signal recv_op : operation_type; + + type req_fifo_t is array(0 to 7) of regflit; + signal req_fifo : req_fifo_t; + signal req_rcount : std_logic_vector(3 downto 0); + signal req_wcount : std_logic_vector(3 downto 0); + signal req_we : std_logic; + signal req_slot_avail : std_logic; + signal req_read_avail : std_logic; +begin + + --request messages fifo controller + proc_req_fifo : process(clock, reset) + variable rcount, wcount : std_logic_vector(3 downto 0); + begin + if reset = '1' then + req_rcount <= (others => '0'); + req_wcount <= (others => '0'); + elsif rising_edge(clock) then + if req_we = '1' then + wcount := req_wcount + 1; + else + wcount := req_wcount; + end if; + + if request_read = '1' and req_read_avail = '1' then + rcount := req_rcount + 1; + else + rcount := req_rcount; + end if; + + if rcount = wcount then + rcount := (others => '0'); + wcount := (others => '0'); + end if; + + req_rcount <= rcount; + req_wcount <= wcount; + end if; + end process proc_req_fifo; + + req_slot_avail <= '1' when req_wcount - req_rcount < 8 else '0'; + req_read_avail <= '0' when req_wcount = req_rcount else '1'; + + last_req <= req_fifo(conv_integer(req_rcount(2 downto 0))) when req_read_avail = '1' + else (others => '0'); + + --config + proc_config : process(clock, reset) + begin + if reset = '1' then + recv_buffer <= (others => '0'); + reset_cpu <= '1'; + elsif(clock'event and clock = '1') then + if (set_address = '1') then + address <= config_data; + address_2 <= (others => '0'); + elsif (set_address_2 = '1') then + address_2 <= config_data; + elsif (set_size = '1') then + size <= config_data; + size_2 <= (others => '0'); + elsif (set_size_2 = '1') then + size_2 <= config_data; + elsif (set_op = '1') then + operation <= config_data(0); + elsif set_buff = '1' then + recv_buffer <= config_data; + elsif set_reset_cpu = '1' and config_data = x"DEADBEEF" then + recv_buffer <= (others => '0'); + reset_cpu <= '1'; + end if; + + if reset_cpu_r = '1' then + reset_cpu <= '0'; + end if; + + if dmma_done = '1' then + recv_buffer(0) <= '1'; + end if; + + end if; + end process proc_config; + + mem_address <= send_address when write_enable = '1' else recv_address; + credit_o <= slot_available; + slot_available <= '0' when (first = last and add_buffer = '1') else '1'; + read_av <= '0' when (first = last and add_buffer = '0') else '1'; + clock_tx <= clock; + send_active <= send_active_2; + receive_active <= receive_active_2; + recv_buff_out <= recv_buffer; + + arbiter : process (clock, reset) + begin + if reset = '1' then + read_enable <= '0'; + write_enable <= '0'; + timer <= "00000"; + prio <= '0'; + ARB <= ROUND; + elsif (clock'event and clock = '1') then + case ARB is + when ROUND => + if prio = '0' then + if (DMNI_Receive = COPY_TO_MEM or DMNI_Receive = COPY_TO_MEM_DMA) then + ARB <= RECEIVE; + read_enable <= '1'; + elsif send_active_2 = '1' then + ARB <= SEND; + write_enable <= '1'; + end if; + else + if send_active_2 = '1' then + ARB <= SEND; + write_enable <= '1'; + elsif (DMNI_Receive = COPY_TO_MEM or DMNI_Receive = COPY_TO_MEM_DMA) then + ARB <= RECEIVE; + read_enable <= '1'; + end if; + end if; + + when SEND => + if DMNI_Send = FINISH or (timer = DMNI_TIMER and receive_active_2 = '1') then + timer <= "00000"; + ARB <= ROUND; + write_enable <= '0'; + prio <= not prio; + else + timer <= timer + '1'; + end if; + + when RECEIVE => + if DMNI_Receive = FINISH or (timer = DMNI_TIMER and send_active_2 = '1') then + timer <= "00000"; + ARB <= ROUND; + read_enable <= '0'; + prio <= not prio; + else + timer <= timer + '1'; + end if; + end case; + end if; + end process arbiter; + + proc_receive : process (clock, reset) + begin + if (reset = '1') then + reset_cpu_r <= '0'; + payload_fix <= (others => '0'); + sizedata_fix <= (others => '0'); + recv_op <= LEGACY; + dmma_done <= '0'; + first <= (others => '0'); + last <= (others => '0'); + payload_size <= (others => '0'); + SR <= HEADER; + add_buffer <= '0'; + receive_active_2 <= '0'; + DMNI_Receive <= WAIT_state; + recv_address <= (others => '0'); + recv_size <= (others => '0'); + mem_data_write <= (others => '0'); + is_header <= (others => '0'); + intr_counter_temp <= (others => '0'); + mem_byte_we <= (others => '0'); + req_we <= '0'; + elsif (clock'event and clock = '1') then + if (rx = '1' and slot_available = '1') then + bufferr(CONV_INTEGER(last)) <= data_in; + add_buffer <= '1'; + last <= last + 1; + + --Read from NoC + case SR is + when HEADER => + intr_counter_temp <= intr_counter_temp + 1; + assert address_router = x"0000" + report "Master receiving msg" + severity note; + is_header(CONV_INTEGER(last)) <= '1'; + SR <= PAYLOAD; + when PAYLOAD => + is_header(CONV_INTEGER(last)) <= '0'; + payload_size <= data_in - 1; + payload_fix <= data_in - 1; + sizedata_fix <= data_in - 2; + SR <= DATA; + when DATA => + is_header(CONV_INTEGER(last)) <= '0'; + if(payload_size = 0) then + SR <= HEADER; + recv_op <= LEGACY; + reset_cpu_r <= '0'; + else + payload_size <= payload_size - 1; + + if (payload_size = payload_fix) then + if data_in = START_CPU_OPERATION then --Service 300 start_cpu + reset_cpu_r <= '1'; + recv_op <= START_CPU; + elsif data_in = DMMA_OPERATION then --Service 290 dmni_operation + recv_op <= DMMA; + elsif data_in = REQ_OPERATION then + recv_op <= MSG_REQ; + end if; + end if; + end if; + end case; + end if; --(rx ='1' and slot_available = '1') + + --Write to memory + case DMNI_Receive is + when WAIT_state => + if ((recv_op = LEGACY and start = '1' and operation = '1') or + (recv_op = DMMA and recv_buffer(0) = '0') or + (recv_op = START_CPU) or + (recv_op = MSG_REQ)) then + if(is_header(CONV_INTEGER(first)) = '1' and intr_counter_temp > 0) then + intr_counter_temp <= intr_counter_temp -1; + end if; + receive_active_2 <= '1'; + + case recv_op is + when LEGACY => + DMNI_Receive <= COPY_TO_MEM; + recv_size <= size - 1; + recv_address <= address - WORD_SIZE; + when DMMA => + DMNI_Receive <= COPY_TO_MEM_DMA; + recv_size <= payload_fix + 2; + recv_address <= recv_buffer - WORD_SIZE; + when START_CPU => + DMNI_Receive <= DISCARD; + recv_size <= payload_fix + 2; + recv_address <= (others => '0'); + when MSG_REQ => + DMNI_Receive <= COPY_TO_FIFO; + recv_size <= payload_fix + 2; + recv_address <= (others => '0'); + end case; + end if; + + when COPY_TO_MEM => + if (read_enable = '1' and read_av = '1') then + mem_byte_we <= "1111"; + mem_data_write <= bufferr(CONV_INTEGER(first)); + recv_address <= recv_address + WORD_SIZE; + first <= first + 1; + add_buffer <= '0'; + recv_size <= recv_size -1; + if (recv_size = 0) then + DMNI_Receive <= FINISH; + end if; + else + mem_byte_we <= "0000"; + end if; + + when DISCARD => + if (read_av = '1') then + first <= first + 1; + add_buffer <= '0'; + recv_size <= recv_size -1; + if (recv_size = 0) then + DMNI_Receive <= FINISH; + end if; + end if; + + when COPY_TO_FIFO => + if (read_av = '1') then + if (recv_size = sizedata_fix) then + if req_slot_avail = '1' then + req_fifo(conv_integer(req_wcount(2 downto 0))) <= bufferr(CONV_INTEGER(first)); + + req_we <= '1'; + first <= first + 1; + add_buffer <= '0'; + recv_size <= recv_size -1; + if (recv_size = 0) then + DMNI_Receive <= FINISH; + end if; + end if; + else + req_we <= '0'; + first <= first + 1; + add_buffer <= '0'; + recv_size <= recv_size -1; + if (recv_size = 0) then + DMNI_Receive <= FINISH; + end if; + end if; + end if; + + when COPY_TO_MEM_DMA => + if (recv_size <= sizedata_fix) then + if (read_enable = '1' and read_av = '1') then + mem_byte_we <= "1111"; + mem_data_write <= bufferr(CONV_INTEGER(first)); + recv_address <= recv_address + WORD_SIZE; + first <= first + 1; + add_buffer <= '0'; + recv_size <= recv_size -1; + if (recv_size = 0) then + dmma_done <= '1'; + DMNI_Receive <= FINISH; + end if; + else + mem_byte_we <= "0000"; + end if; + elsif read_av = '1' then + first <= first + 1; + add_buffer <= '0'; + recv_size <= recv_size -1; + if (recv_size = 0) then + dmma_done <= '1'; + DMNI_Receive <= FINISH; + end if; + end if; + + when FINISH => + req_we <= '0'; + receive_active_2 <= '0'; + mem_byte_we <= "0000"; + recv_address <= (others => '0'); + recv_size <= (others => '0'); + dmma_done <= '0'; + DMNI_Receive <= WAIT_state; + when others => + end case; + end if; --rising_edge(clock) + end process proc_receive; + + intr_count <= intr_counter_temp; + intr <= '1' when intr_counter_temp > 0 else '0'; + + proc_send : process (clock, reset) + begin + if(reset = '1') then + DMNI_Send <= WAIT_state; + send_active_2 <= '0'; + tx <= '0'; + send_size <= (others => '0'); + send_size_2 <= (others => '0'); + send_address <= (others => '0'); + send_address_2 <= (others => '0'); + data_out <= (others => '0'); + elsif (clock'event and clock = '1') then + case DMNI_Send is + when WAIT_state => + if (start = '1' and operation = '0') then + send_address <= address; + send_address_2 <= address_2; + send_size <= size; + send_size_2 <= size_2; + send_active_2 <= '1'; + DMNI_Send <= LOAD; + assert address_router = x"0000" + report "Master sending msg" + severity note; + end if; + + when LOAD => + if(credit_i = '1' and write_enable = '1') then + send_address <= send_address + WORD_SIZE; + DMNI_Send <= COPY_FROM_MEM; + end if; + + when COPY_FROM_MEM => + if(credit_i = '1' and write_enable = '1') then + if(send_size > 0) then + tx <= '1'; + data_out <= mem_data_read; + send_address <= send_address + WORD_SIZE; + send_size <= send_size -1; + elsif (send_size_2 > 0) then + send_size <= send_size_2; + send_size_2 <= (others => '0'); + tx <= '0'; + if(send_address_2(30 downto 28) = "000") then + send_address <= send_address_2; + else + send_address <= send_address_2 - WORD_SIZE; + end if; + DMNI_Send <= LOAD; + else + tx <= '0'; + DMNI_Send <= FINISH; + end if; + else + if (credit_i = '0') then + send_size <= send_size + 1; + send_address <= send_address - WORD_SIZE - WORD_SIZE; -- address back 2 positions + else + send_address <= send_address - WORD_SIZE; -- address back 1 position + end if; + tx <= '0'; + DMNI_Send <= LOAD; + end if; + + when FINISH => + send_active_2 <= '0'; + send_address <= (others => '0'); + send_address_2 <= (others => '0'); + send_size <= (others => '0'); + send_size_2 <= (others => '0'); + DMNI_Send <= WAIT_state; + when others => + end case; + end if; --rising_edge(clock) + end process proc_send; +end dmni; diff --git a/hemps8.5/hardware/vhdl/pe/memory/ram.vhd b/hardware/vhdl/pe/memory/ram.vhd similarity index 100% rename from hemps8.5/hardware/vhdl/pe/memory/ram.vhd rename to hardware/vhdl/pe/memory/ram.vhd diff --git a/hardware/vhdl/pe/pe.vhd b/hardware/vhdl/pe/pe.vhd new file mode 100644 index 0000000..9f90873 --- /dev/null +++ b/hardware/vhdl/pe/pe.vhd @@ -0,0 +1,460 @@ +------------------------------------------------------------------------------------------------ +-- HeMPS Processing Element +------------------------------------------------------------------------------------------------ +library ieee; +use work.mlite_pack.all; +use work.standards.all; +use work.hemps_pkg.all; +use ieee.std_logic_1164.all; +use ieee.std_logic_misc.all; +use ieee.std_logic_arith.all; +use ieee.std_logic_textio.all; +use ieee.std_logic_unsigned.all; +use ieee.math_real.all; + +use std.textio.all; +library unisim; +use unisim.vcomponents.all; + +entity pe is + generic + ( + log_file : string := "output.txt"; + router_address : regmetadeflit := (others => '0'); + kernel_type : kernel_str; + simple_soc : boolean; + manual_NORTH : boolean := false; + manual_SOUTH : boolean := false; + manual_EAST : boolean := false; + manual_WEST : boolean := false); + port + ( + clock : in std_logic; + reset : in std_logic; + -- NoC + clock_rx : in std_logic_vector(3 downto 0); + rx : in std_logic_vector(3 downto 0); + data_in : in arrayNPORT_1_regflit; + credit_o : out std_logic_vector(3 downto 0); + clock_tx : out std_logic_vector(3 downto 0); + tx : out std_logic_vector(3 downto 0); + data_out : out arrayNPORT_1_regflit; + credit_i : in std_logic_vector(3 downto 0); + -- External Memory + repo_address : out std_logic_vector(29 downto 0); + repo_data_read : in std_logic_vector(31 downto 0); + ack_app : out std_logic; + req_app : in std_logic_vector(31 downto 0) + -- External Debug interface +-- write_enable_debug : out std_logic; +-- data_out_debug : out std_logic_vector(31 downto 0); +-- busy_debug : in std_logic + ); +end entity pe; + +architecture structural of pe is + + type repo_state is (WAIT_state, COPY_FROM_REP); + signal repo_FSM : repo_state; + + signal cpu_mem_address_reg : std_logic_vector(31 downto 0); + signal cpu_mem_data_write_reg : std_logic_vector(31 downto 0); + signal cpu_mem_write_byte_enable_reg : std_logic_vector(3 downto 0); + signal irq_mask_reg : std_logic_vector(7 downto 0); + signal irq_status : std_logic_vector(7 downto 0); + signal irq : std_logic; + signal time_slice : std_logic_vector(31 downto 0); + signal write_enable : std_logic; + signal tick_counter_local : std_logic_vector(31 downto 0); + signal tick_counter : std_logic_vector(31 downto 0); + signal current_page : std_logic_vector(7 downto 0); + signal cpu_mem_address : std_logic_vector(31 downto 0); + signal cpu_mem_data_write : std_logic_vector(31 downto 0); + signal cpu_mem_data_read : std_logic_vector(31 downto 0); + signal cpu_mem_write_byte_enable : std_logic_vector(3 downto 0); + signal cpu_mem_pause : std_logic; + signal cpu_enable_ram : std_logic; + signal cpu_set_size : std_logic; + signal cpu_set_address : std_logic; + signal cpu_set_size_2 : std_logic; + signal cpu_set_address_2 : std_logic; + signal cpu_set_op : std_logic; + signal cpu_start : std_logic; + signal cpu_set_buff : std_logic; + signal clock_aux : std_logic; + signal clock_hold_s : std_logic; + signal pending_service : std_logic; + + --Router + signal clock_rx_router : regNport; + signal rx_router : regNport; + signal data_in_router : arrayNport_regflit; + signal credit_o_router : regNport; + signal clock_tx_router : regNport; + signal tx_router : regNport; + signal data_out_router : arrayNport_regflit; + signal credit_i_router : regNport; + + signal data_read_ram : std_logic_vector(31 downto 0); + signal mem_data_read : std_logic_vector(31 downto 0); + --signal debug_busy : std_logic; + --signal debug_write_data : std_logic; + --signal debug_write_busy : std_logic; + --signal debug_data_avail : std_logic; + signal ni_intr : std_logic; + signal dmni_mem_address : std_logic_vector(31 downto 0); + signal dmni_mem_write_byte_enable : std_logic_vector(3 downto 0); + signal dmni_mem_data_write : std_logic_vector(31 downto 0); + signal dmni_mem_data_read : std_logic_vector(31 downto 0); + signal dmni_data_read : std_logic_vector(31 downto 0); + signal dmni_enable_internal_ram : std_logic; + signal dmni_send_active_sig : std_logic; + signal dmni_receive_active_sig : std_logic; + signal addr_a : std_logic_vector(31 downto 2); + signal addr_b : std_logic_vector(31 downto 2); + signal cpu_repo_access : std_logic := '0'; + signal data_av : std_logic; + signal end_sim_reg : std_logic_vector(31 downto 0); + signal uart_write_data : std_logic; + signal dmni_recv_buff : std_logic_vector(31 downto 0); + signal cpu_set_reset : std_logic; + + signal slack_update_timer : std_logic_vector(31 downto 0); + + signal reset_dmni : std_logic; + signal last_req : std_logic_vector(31 downto 0); + signal req_read : std_logic; +begin + +----------------------------------------------------------------------------------- +-- PE COMPONENTS INSTANTIATION +----------------------------------------------------------------------------------- + cpu : entity work.mlite_cpu + port map( + clk => clock_hold_s, + reset_in => reset_dmni, + intr_in => irq, + mem_address => cpu_mem_address, + mem_data_w => cpu_mem_data_write, + mem_data_r => cpu_mem_data_read, + mem_byte_we => cpu_mem_write_byte_enable, + mem_pause => cpu_mem_pause, + current_page => current_page + ); + + + master : if kernel_type = "mas" and simple_soc = false generate + mem : entity work.ram_master + port map( + clk => clock, + enable_a => cpu_enable_ram, + wbe_a => cpu_mem_write_byte_enable, + address_a => addr_a, + data_write_a => cpu_mem_data_write, + data_read_a => data_read_ram, + enable_b => dmni_enable_internal_ram, + wbe_b => dmni_mem_write_byte_enable, + address_b => addr_b, + data_write_b => dmni_mem_data_write, + data_read_b => mem_data_read + ); + end generate; + + slave : if kernel_type = "sla" and simple_soc = false generate + mem : entity work.ram_slave + port map( + clk => clock, + enable_a => cpu_enable_ram, + wbe_a => cpu_mem_write_byte_enable, + address_a => addr_a, + data_write_a => cpu_mem_data_write, + data_read_a => data_read_ram, + enable_b => dmni_enable_internal_ram, + wbe_b => dmni_mem_write_byte_enable, + address_b => addr_b, + data_write_b => dmni_mem_data_write, + data_read_b => mem_data_read + ); + end generate; + + simple_soc_ram : if simple_soc = true generate + mem : entity work.ram_simple + port map( + clk => clock, + enable_a => cpu_enable_ram, + wbe_a => cpu_mem_write_byte_enable, + address_a => addr_a, + data_write_a => cpu_mem_data_write, + data_read_a => data_read_ram, + enable_b => dmni_enable_internal_ram, + wbe_b => dmni_mem_write_byte_enable, + address_b => addr_b, + data_write_b => dmni_mem_data_write, + data_read_b => mem_data_read + ); + end generate; + + router : entity work.RouterCC + generic map(address => router_address, + manual_NORTH => manual_NORTH, + manual_SOUTH => manual_SOUTH, + manual_EAST => manual_EAST, + manual_WEST => manual_WEST) + port map( + clock => clock, + reset => reset, + clock_rx => clock_rx_router, + rx => rx_router, + data_in => data_in_router, + credit_o => credit_o_router, + clock_tx => clock_tx_router, + tx => tx_router, + data_out => data_out_router, + credit_i => credit_i_router); + + + dmni : entity work.dmni + generic map( + address_router => router_address) + port map( + clock => clock, + reset => reset, + --Configuration interface + set_address => cpu_set_address, + set_address_2 => cpu_set_address_2, + set_size => cpu_set_size, + set_size_2 => cpu_set_size_2, + set_op => cpu_set_op, + start => cpu_start, + config_data => dmni_data_read, + set_buff => cpu_set_buff, + set_reset_cpu => cpu_set_reset, + request_read => req_read, + -- Status outputs + intr => ni_intr, + send_active => dmni_send_active_sig, + receive_active => dmni_receive_active_sig, + reset_cpu => reset_dmni, + recv_buff_out => dmni_recv_buff, + last_req => last_req, + -- Memory interface + mem_address => dmni_mem_address, + mem_data_write => dmni_mem_data_write, + mem_data_read => dmni_mem_data_read, + mem_byte_we => dmni_mem_write_byte_enable, + + --NoC Interface (Local port) + tx => rx_router(LOCAL), + data_out => data_in_router(LOCAL), + credit_i => credit_o_router(LOCAL), + clock_tx => clock_rx_router(LOCAL), + rx => tx_router(LOCAL), + data_in => data_out_router(LOCAL), + credit_o => credit_i_router(LOCAL), + clock_rx => clock_tx_router(LOCAL) + ); + + uart : entity work.UartFile + generic map( + log_file => log_file + ) + port map( + reset => reset, + data_av => uart_write_data, + data_in => cpu_mem_data_write_reg + ); + +----------------------------------------------------------------------------------- +-- COMBINATIONAL LOGIC AND WIRING +----------------------------------------------------------------------------------- + + --Router external wiring + clock_rx_router (3 downto 0) <= clock_rx; + rx_router (3 downto 0) <= rx; + credit_i_router (3 downto 0) <= credit_i; + data_in_router (EAST) <= data_in(EAST); + data_in_router (WEST) <= data_in(WEST); + data_in_router (NORTH) <= data_in(NORTH); + data_in_router (SOUTH) <= data_in(SOUTH); + + clock_tx <= clock_tx_router (3 downto 0); + tx <= tx_router (3 downto 0); + credit_o <= credit_o_router (3 downto 0); + data_out(EAST) <= data_out_router (EAST); + data_out(WEST) <= data_out_router (WEST); + data_out(NORTH) <= data_out_router (NORTH); + data_out(SOUTH) <= data_out_router (SOUTH); + + -- UART + uart_write_data <= '1' when cpu_mem_address_reg = DEBUG and write_enable = '1' else '0'; + --debug_busy <= '0'; + --debug_write_busy <= '0'; + --debug_data_avail <= '0'; + + -- CPU data read mux + MUX_CPU : cpu_mem_data_read <= repo_data_read when cpu_mem_address_reg(30 downto 28) = "001" else -- External RAM + ZERO(31 downto 8) & irq_mask_reg when cpu_mem_address_reg = IRQ_MASK else + ZERO(31 downto 8) & irq_status when cpu_mem_address_reg = IRQ_STATUS_ADDR else + time_slice when cpu_mem_address_reg = TIME_SLICE_ADDR else + ZERO(31 downto 16) & router_address when cpu_mem_address_reg = NET_ADDRESS else + tick_counter when cpu_mem_address_reg = TICK_COUNTER_ADDR else + req_app when cpu_mem_address_reg = REQ_APP_REG else + ZERO(31 downto 1) & dmni_send_active_sig when cpu_mem_address_reg = DMNI_SEND_ACTIVE else + ZERO(31 downto 1) & dmni_receive_active_sig when cpu_mem_address_reg = DMNI_RECEIVE_ACTIVE else + dmni_recv_buff when cpu_mem_address_reg = DMNI_RECEIVE_BUFFER else + LOADER_NETADDR when cpu_mem_address_reg = LOADER_NETADDR_REG else + last_req when cpu_mem_address_reg = DMNI_REQ_FIFO else + data_read_ram; + + --Comb assignments + addr_a(31 downto 28) <= cpu_mem_address(31 downto 28); + addr_a(27 downto PAGE_SIZE_H_INDEX + 1) <= ZERO(27 downto PAGE_SIZE_H_INDEX + 9) & current_page when current_page /= "00000000" and cpu_mem_address(31 downto PAGE_SIZE_H_INDEX + 1) /= ZERO(31 downto PAGE_SIZE_H_INDEX + 1) + else cpu_mem_address(27 downto PAGE_SIZE_H_INDEX + 1); + addr_a(PAGE_SIZE_H_INDEX downto 2) <= cpu_mem_address(PAGE_SIZE_H_INDEX downto 2); + + addr_b <= dmni_mem_address(31 downto 2); + data_av <= '1' when cpu_mem_address_reg = DEBUG and write_enable = '1' else '0'; + --write_enable_debug <= '1' when cpu_mem_address_reg = DEBUG and write_enable = '1' else '0'; + --data_out_debug <= cpu_mem_data_write_reg; + --debug_write_busy <= busy_debug; + --debug_busy <= '1' when cpu_mem_address_reg = DEBUG and write_enable = '1' and busy_debug = '1' else '0'; + --cpu_mem_pause <= cpu_repo_access or debug_busy; + cpu_mem_pause <= cpu_repo_access; + irq <= '1' when (irq_status /= x"00" and irq_mask_reg /= x"00") else '0'; + dmni_data_read <= cpu_mem_data_write_reg; + dmni_mem_data_read <= mem_data_read when dmni_enable_internal_ram = '1' else repo_data_read; + cpu_enable_ram <= '1' when cpu_mem_address(30 downto 28) = "000" and reset_dmni = '0' else '0'; + dmni_enable_internal_ram <= '1' when dmni_mem_address(30 downto 28) = "000" else '0'; + end_sim_reg <= x"00000000" when cpu_mem_address_reg = END_SIM and write_enable = '1' else x"00000001"; + irq_status(7 downto 4) <= "00" & ni_intr & '0'; + irq_status(3) <= '1' when time_slice = x"00000001" else '0'; + irq_status(2) <= '0'; + irq_status(1) <= '1' when dmni_send_active_sig = '0' and slack_update_timer = SLACK_MONITOR_WINDOW else '0'; + irq_status(0) <= (not dmni_send_active_sig and pending_service); + + cpu_set_size <= '1' when cpu_mem_address_reg = DMNI_SIZE and write_enable = '1' else '0'; + cpu_set_address <= '1' when cpu_mem_address_reg = DMNI_ADDR and write_enable = '1' else '0'; + cpu_set_size_2 <= '1' when cpu_mem_address_reg = DMNI_SIZE_2 and write_enable = '1' else '0'; + cpu_set_address_2 <= '1' when cpu_mem_address_reg = DMNI_ADDR_2 and write_enable = '1' else '0'; + cpu_set_op <= '1' when cpu_mem_address_reg = DMNI_OP and write_enable = '1' else '0'; + cpu_start <= '1' when cpu_mem_address_reg = START_DMNI and write_enable = '1' else '0'; + cpu_set_buff <= '1' when cpu_mem_address_reg = DMNI_RECEIVE_BUFFER and write_enable = '1' else '0'; + cpu_set_reset <= '1' when cpu_mem_address_reg = SET_CPU_KILL and write_enable = '1' else '0'; + req_read <= '1' when cpu_mem_address_reg = DMNI_REQ_FIFO and write_enable = '1' else '0'; + + write_enable <= '1' when cpu_mem_write_byte_enable_reg /= "0000" else '0'; + + +----------------------------------------------------------------------------------- +-- SYNCHRONOUS PROCESSES +----------------------------------------------------------------------------------- + + repo_to_mem_access : process(clock, reset) + begin + if reset = '1' then + repo_FSM <= WAIT_state; + cpu_repo_access <= '0'; + elsif rising_edge(clock) then + case(repo_FSM) is + when WAIT_state => + if(cpu_mem_address(30 downto 28) = "001") then + cpu_repo_access <= '1'; + repo_FSM <= COPY_FROM_REP; + end if; + when COPY_FROM_REP => + repo_FSM <= WAIT_state; + cpu_repo_access <= '0'; + end case; + end if; + end process repo_to_mem_access; + + + process(cpu_repo_access, dmni_mem_address) + begin + if(cpu_repo_access = '1') then + repo_address <= cpu_mem_address(29 downto 0); + elsif dmni_mem_address(30 downto 28) = "001" then + repo_address <= dmni_mem_address(29 downto 0); + end if; + end process; + + sequential_attr : process(clock, reset) + begin + if reset = '1' then + cpu_mem_address_reg <= ZERO; + cpu_mem_data_write_reg <= ZERO; + cpu_mem_write_byte_enable_reg <= ZERO(3 downto 0); + irq_mask_reg <= ZERO(7 downto 0); + time_slice <= ZERO; + tick_counter <= ZERO; + pending_service <= '0'; + ack_app <= '0'; + slack_update_timer <= ZERO; + elsif (clock'event and clock = '1') then + if cpu_mem_pause = '0' then + cpu_mem_address_reg <= cpu_mem_address; + cpu_mem_data_write_reg <= cpu_mem_data_write; + cpu_mem_write_byte_enable_reg <= cpu_mem_write_byte_enable; + + if cpu_mem_address_reg = IRQ_MASK and write_enable = '1' then + irq_mask_reg <= cpu_mem_data_write_reg(7 downto 0); + end if; + -- Decrements the time slice when executing a task (current_page /= x"00") or handling a syscall (syscall = '1') + if time_slice > 1 then + time_slice <= time_slice - 1; + end if; + + if(cpu_mem_address_reg = PENDING_SERVICE_INTR and write_enable = '1') then + if cpu_mem_data_write_reg = ZERO then + pending_service <= '0'; + else + pending_service <= '1'; + end if; + end if; + end if; + + if cpu_mem_address_reg = SLACK_TIME_MONITOR and write_enable = '1' then + slack_update_timer <= cpu_mem_data_write_reg; + elsif slack_update_timer < SLACK_MONITOR_WINDOW then + slack_update_timer <= slack_update_timer + 1; + end if; + + if cpu_mem_address_reg = TIME_SLICE_ADDR and write_enable = '1' then + time_slice <= cpu_mem_data_write_reg; + end if; + + if cpu_mem_address_reg = ACK_APP_REG then + ack_app <= '1'; + elsif req_app(31) = '0' then + ack_app <= '0'; + end if; + + tick_counter <= tick_counter + 1; + end if; + end process sequential_attr; + + clock_stop : process(reset, clock) + begin + if(reset = '1') then + tick_counter_local <= (others => '0'); + clock_aux <= '1'; + else + if cpu_mem_address_reg = CLOCK_HOLD and write_enable = '1' then + clock_aux <= '0'; + --elsif tx_router(LOCAL) = '1' or ni_intr = '1' or time_slice = x"00000001" then + elsif ni_intr = '1' or time_slice = x"00000001" or irq_status(1) = '1' then + clock_aux <= '1'; + end if; + + if(clock_aux = '1' and clock = '1') then + clock_hold_s <= '1'; + tick_counter_local <= tick_counter_local + 1; + else + clock_hold_s <= '0'; + end if; + end if; + end process clock_stop; + +end architecture structural; + + diff --git a/hardware/vhdl/pe/processor/plasma/UartFile.vhd b/hardware/vhdl/pe/processor/plasma/UartFile.vhd new file mode 100644 index 0000000..8ea29bf --- /dev/null +++ b/hardware/vhdl/pe/processor/plasma/UartFile.vhd @@ -0,0 +1,69 @@ +------------------------------------------------------------------------------------------------ +-- +-- DISTRIBUTED HEMPS - version 5.0 +-- +-- Research group: GAPH-PUCRS - contact fernando.moraes@pucrs.br +-- +-- Distribution: September 2013 +-- +-- Source name: UartFile.vhd +-- +-- AUTHOR: Everton Alceu Carara (everton.carara@pucrs.br) +-- +-- DATE CREATED: 2/12/2009 +-- +-- Brief description: Writes strings from Echo() and puts() to the log_file. +-- +------------------------------------------------------------------------------------------------ + +library ieee; +use ieee.std_logic_1164.all; +use ieee.std_logic_misc.all; +use ieee.std_logic_arith.all; +use ieee.std_logic_textio.all; +use ieee.std_logic_unsigned.all; +use std.textio.all; +use work.mlite_pack.all; + +entity UartFile is + generic(log_file : string := "UNUSED"); + port( + reset : in std_logic; + data_av : in std_logic; + data_in : in std_logic_vector(31 downto 0)); +end; + +architecture logic of UartFile is + +begin + + process(data_av, reset) + file store_file : text open write_mode is log_file; + variable file_line : line; + variable line_type : character; + variable line_length : natural := 0; + variable str : string (1 to 4); + variable str_end : boolean; + begin + if reset = '1' then + str_end := false; + elsif rising_edge(data_av) then + str(4) := character'val(conv_integer(data_in(7 downto 0))); + str(3) := character'val(conv_integer(data_in(15 downto 8))); + str(2) := character'val(conv_integer(data_in(23 downto 16))); + str(1) := character'val(conv_integer(data_in(31 downto 24))); + str_end := false; + for i in 1 to 4 loop + -- Writes a string in the line + if str(i) /= nul and str(i) /= lf and not str_end then + write(file_line, str(i)); + -- Detects the string end + elsif str(i) = nul then + str_end := true; + elsif str(i) = lf then + writeline(store_file, file_line); + end if; + end loop; + end if; + end process; +end; diff --git a/hemps8.5/hardware/vhdl/pe/processor/plasma/alu.vhd b/hardware/vhdl/pe/processor/plasma/alu.vhd similarity index 100% rename from hemps8.5/hardware/vhdl/pe/processor/plasma/alu.vhd rename to hardware/vhdl/pe/processor/plasma/alu.vhd diff --git a/hemps8.5/hardware/vhdl/pe/processor/plasma/bus_mux.vhd b/hardware/vhdl/pe/processor/plasma/bus_mux.vhd similarity index 100% rename from hemps8.5/hardware/vhdl/pe/processor/plasma/bus_mux.vhd rename to hardware/vhdl/pe/processor/plasma/bus_mux.vhd diff --git a/hemps8.5/hardware/vhdl/pe/processor/plasma/control.vhd b/hardware/vhdl/pe/processor/plasma/control.vhd similarity index 100% rename from hemps8.5/hardware/vhdl/pe/processor/plasma/control.vhd rename to hardware/vhdl/pe/processor/plasma/control.vhd diff --git a/hemps8.5/hardware/vhdl/pe/processor/plasma/mem_ctrl.vhd b/hardware/vhdl/pe/processor/plasma/mem_ctrl.vhd similarity index 100% rename from hemps8.5/hardware/vhdl/pe/processor/plasma/mem_ctrl.vhd rename to hardware/vhdl/pe/processor/plasma/mem_ctrl.vhd diff --git a/hemps8.5/hardware/vhdl/pe/processor/plasma/mlite_cpu.vhd b/hardware/vhdl/pe/processor/plasma/mlite_cpu.vhd similarity index 100% rename from hemps8.5/hardware/vhdl/pe/processor/plasma/mlite_cpu.vhd rename to hardware/vhdl/pe/processor/plasma/mlite_cpu.vhd diff --git a/hemps8.5/hardware/vhdl/pe/processor/plasma/mlite_pack.vhd b/hardware/vhdl/pe/processor/plasma/mlite_pack.vhd similarity index 100% rename from hemps8.5/hardware/vhdl/pe/processor/plasma/mlite_pack.vhd rename to hardware/vhdl/pe/processor/plasma/mlite_pack.vhd diff --git a/hemps8.5/hardware/vhdl/pe/processor/plasma/mult.vhd b/hardware/vhdl/pe/processor/plasma/mult.vhd similarity index 100% rename from hemps8.5/hardware/vhdl/pe/processor/plasma/mult.vhd rename to hardware/vhdl/pe/processor/plasma/mult.vhd diff --git a/hemps8.5/hardware/vhdl/pe/processor/plasma/pc_next.vhd b/hardware/vhdl/pe/processor/plasma/pc_next.vhd similarity index 100% rename from hemps8.5/hardware/vhdl/pe/processor/plasma/pc_next.vhd rename to hardware/vhdl/pe/processor/plasma/pc_next.vhd diff --git a/hemps8.5/hardware/vhdl/pe/processor/plasma/pipeline.vhd b/hardware/vhdl/pe/processor/plasma/pipeline.vhd similarity index 100% rename from hemps8.5/hardware/vhdl/pe/processor/plasma/pipeline.vhd rename to hardware/vhdl/pe/processor/plasma/pipeline.vhd diff --git a/hemps8.5/hardware/vhdl/pe/processor/plasma/reg_bank.vhd b/hardware/vhdl/pe/processor/plasma/reg_bank.vhd similarity index 100% rename from hemps8.5/hardware/vhdl/pe/processor/plasma/reg_bank.vhd rename to hardware/vhdl/pe/processor/plasma/reg_bank.vhd diff --git a/hemps8.5/hardware/vhdl/pe/processor/plasma/shifter.vhd b/hardware/vhdl/pe/processor/plasma/shifter.vhd similarity index 100% rename from hemps8.5/hardware/vhdl/pe/processor/plasma/shifter.vhd rename to hardware/vhdl/pe/processor/plasma/shifter.vhd diff --git a/hemps8.5/hardware/vhdl/pe/router/Hermes_buffer.vhd b/hardware/vhdl/pe/router/Hermes_buffer.vhd similarity index 100% rename from hemps8.5/hardware/vhdl/pe/router/Hermes_buffer.vhd rename to hardware/vhdl/pe/router/Hermes_buffer.vhd diff --git a/hemps8.5/hardware/vhdl/pe/router/Hermes_crossbar.vhd b/hardware/vhdl/pe/router/Hermes_crossbar.vhd similarity index 54% rename from hemps8.5/hardware/vhdl/pe/router/Hermes_crossbar.vhd rename to hardware/vhdl/pe/router/Hermes_crossbar.vhd index ded33de..a8c5390 100644 --- a/hemps8.5/hardware/vhdl/pe/router/Hermes_crossbar.vhd +++ b/hardware/vhdl/pe/router/Hermes_crossbar.vhd @@ -50,16 +50,16 @@ begin -- PORTA LOCAL ---------------------------------------------------------------------------------- tx(LOCAL) <= data_av(EAST) when tab_out(LOCAL)="000" and free(LOCAL)='0' else - data_av(WEST) when tab_out(LOCAL)="001" and free(LOCAL)='0' else - data_av(NORTH) when tab_out(LOCAL)="010" and free(LOCAL)='0' else - data_av(SOUTH) when tab_out(LOCAL)="011" and free(LOCAL)='0' else - '0'; + data_av(WEST) when tab_out(LOCAL)="001" and free(LOCAL)='0' else + data_av(NORTH) when tab_out(LOCAL)="010" and free(LOCAL)='0' else + data_av(SOUTH) when tab_out(LOCAL)="011" and free(LOCAL)='0' else + '0'; data_out(LOCAL) <= data_in(EAST) when tab_out(LOCAL)="000" and free(LOCAL)='0' else - data_in(WEST) when tab_out(LOCAL)="001" and free(LOCAL)='0' else - data_in(NORTH) when tab_out(LOCAL)="010" and free(LOCAL)='0' else - data_in(SOUTH) when tab_out(LOCAL)="011" and free(LOCAL)='0' else - (others=>'0'); + data_in(WEST) when tab_out(LOCAL)="001" and free(LOCAL)='0' else + data_in(NORTH) when tab_out(LOCAL)="010" and free(LOCAL)='0' else + data_in(SOUTH) when tab_out(LOCAL)="011" and free(LOCAL)='0' else + (others=>'0'); data_ack(LOCAL) <= credit_i(EAST) when tab_in(LOCAL)="000" and data_av(LOCAL)='1' else credit_i(WEST) when tab_in(LOCAL)="001" and data_av(LOCAL)='1' else @@ -70,52 +70,62 @@ begin -- PORTA EAST ---------------------------------------------------------------------------------- tx(EAST) <= data_av(WEST) when tab_out(EAST)="001" and free(EAST)='0' else - data_av(LOCAL) when tab_out(EAST)="100" and free(EAST)='0' else - '0'; + data_av(NORTH) when tab_out(EAST)="010" and free(EAST)='0' else + data_av(SOUTH) when tab_out(EAST)="011" and free(EAST)='0' else + data_av(LOCAL) when tab_out(EAST)="100" and free(EAST)='0' else + '0'; data_out(EAST) <= data_in(WEST) when tab_out(EAST)="001" and free(EAST)='0' else - data_in(LOCAL) when tab_out(EAST)="100" and free(EAST)='0' else - (others=>'0'); + data_in(NORTH) when tab_out(EAST)="010" and free(EAST)='0' else + data_in(SOUTH) when tab_out(EAST)="011" and free(EAST)='0' else + data_in(LOCAL) when tab_out(EAST)="100" and free(EAST)='0' else + (others=>'0'); data_ack(EAST) <= credit_i(WEST) when tab_in(EAST)="001" and data_av(EAST)='1' else - credit_i(NORTH) when tab_in(EAST)="010" and data_av(EAST)='1' else - credit_i(SOUTH) when tab_in(EAST)="011" and data_av(EAST)='1' else - credit_i(LOCAL) when tab_in(EAST)="100" and data_av(EAST)='1' else - '0'; + credit_i(NORTH) when tab_in(EAST)="010" and data_av(EAST)='1' else + credit_i(SOUTH) when tab_in(EAST)="011" and data_av(EAST)='1' else + credit_i(LOCAL) when tab_in(EAST)="100" and data_av(EAST)='1' else + '0'; ---------------------------------------------------------------------------------- -- PORTA WEST ---------------------------------------------------------------------------------- tx(WEST) <= data_av(EAST) when tab_out(WEST)="000" and free(WEST)='0' else - data_av(LOCAL) when tab_out(WEST)="100" and free(WEST)='0' else - '0'; + data_av(NORTH) when tab_out(WEST)="010" and free(WEST)='0' else + data_av(SOUTH) when tab_out(WEST)="011" and free(WEST)='0' else + data_av(LOCAL) when tab_out(WEST)="100" and free(WEST)='0' else + '0'; data_out(WEST) <= data_in(EAST) when tab_out(WEST)="000" and free(WEST)='0' else - data_in(LOCAL) when tab_out(WEST)="100" and free(WEST)='0' else - (others=>'0'); + data_in(NORTH) when tab_out(WEST)="010" and free(WEST)='0' else + data_in(SOUTH) when tab_out(WEST)="011" and free(WEST)='0' else + data_in(LOCAL) when tab_out(WEST)="100" and free(WEST)='0' else + (others=>'0'); data_ack(WEST) <= credit_i(EAST) when tab_in(WEST)="000" and data_av(WEST)='1' else - credit_i(NORTH) when tab_in(WEST)="010" and data_av(WEST)='1' else - credit_i(SOUTH) when tab_in(WEST)="011" and data_av(WEST)='1' else - credit_i(LOCAL) when tab_in(WEST)="100" and data_av(WEST)='1' else - '0'; + credit_i(NORTH) when tab_in(WEST)="010" and data_av(WEST)='1' else + credit_i(SOUTH) when tab_in(WEST)="011" and data_av(WEST)='1' else + credit_i(LOCAL) when tab_in(WEST)="100" and data_av(WEST)='1' else + '0'; ---------------------------------------------------------------------------------- -- PORTA NORTH ---------------------------------------------------------------------------------- tx(NORTH) <= data_av(EAST) when tab_out(NORTH)="000" and free(NORTH)='0' else - data_av(WEST) when tab_out(NORTH)="001" and free(NORTH)='0' else - data_av(SOUTH) when tab_out(NORTH)="011" and free(NORTH)='0' else - data_av(LOCAL) when tab_out(NORTH)="100" and free(NORTH)='0' else - '0'; + data_av(WEST) when tab_out(NORTH)="001" and free(NORTH)='0' else + data_av(SOUTH) when tab_out(NORTH)="011" and free(NORTH)='0' else + data_av(LOCAL) when tab_out(NORTH)="100" and free(NORTH)='0' else + '0'; data_out(NORTH) <= data_in(EAST) when tab_out(NORTH)="000" and free(NORTH)='0' else - data_in(WEST) when tab_out(NORTH)="001" and free(NORTH)='0' else - data_in(SOUTH) when tab_out(NORTH)="011" and free(NORTH)='0' else - data_in(LOCAL) when tab_out(NORTH)="100" and free(NORTH)='0' else - (others=>'0'); - - data_ack(NORTH) <= credit_i(SOUTH) when tab_in(NORTH)="011" and data_av(NORTH)='1' else - credit_i(LOCAL) when tab_in(NORTH)="100" and data_av(NORTH)='1' else - '0'; + data_in(WEST) when tab_out(NORTH)="001" and free(NORTH)='0' else + data_in(SOUTH) when tab_out(NORTH)="011" and free(NORTH)='0' else + data_in(LOCAL) when tab_out(NORTH)="100" and free(NORTH)='0' else + (others=>'0'); + + data_ack(NORTH) <= credit_i(EAST) when tab_in(NORTH)="000" and data_av(NORTH)='1' else + credit_i(WEST) when tab_in(NORTH)="001" and data_av(NORTH)='1' else + credit_i(SOUTH) when tab_in(NORTH)="011" and data_av(NORTH)='1' else + credit_i(LOCAL) when tab_in(NORTH)="100" and data_av(NORTH)='1' else + '0'; ---------------------------------------------------------------------------------- -- PORTA SOUTH ---------------------------------------------------------------------------------- @@ -131,8 +141,10 @@ begin data_in(LOCAL) when tab_out(SOUTH)="100" and free(SOUTH)='0' else (others=>'0'); - data_ack(SOUTH) <= credit_i(NORTH) when tab_in(SOUTH)="010" and data_av(SOUTH)='1' else - credit_i(LOCAL) when tab_in(SOUTH)="100" and data_av(SOUTH)='1' else + data_ack(SOUTH) <= credit_i(EAST) when tab_in(SOUTH)="000" and data_av(SOUTH)='1' else + credit_i(WEST) when tab_in(SOUTH)="001" and data_av(SOUTH)='1' else + credit_i(NORTH) when tab_in(SOUTH)="010" and data_av(SOUTH)='1' else + credit_i(LOCAL) when tab_in(SOUTH)="100" and data_av(SOUTH)='1' else '0'; end Hermes_crossbar; diff --git a/hemps8.5/hardware/vhdl/pe/router/Hermes_switchcontrol.vhd b/hardware/vhdl/pe/router/Hermes_switchcontrol.vhd similarity index 76% rename from hemps8.5/hardware/vhdl/pe/router/Hermes_switchcontrol.vhd rename to hardware/vhdl/pe/router/Hermes_switchcontrol.vhd index 2f8ab2b..fce5d3d 100644 --- a/hemps8.5/hardware/vhdl/pe/router/Hermes_switchcontrol.vhd +++ b/hardware/vhdl/pe/router/Hermes_switchcontrol.vhd @@ -18,6 +18,11 @@ use IEEE.STD_LOGIC_unsigned.all; use work.standards.all; entity SwitchControl is +generic ( + manual_NORTH : boolean := false; + manual_SOUTH : boolean := false; + manual_EAST: boolean := false; + manual_WEST: boolean := false); port( clock : in std_logic; reset : in std_logic; @@ -49,6 +54,10 @@ signal auxfree: regNport := (others=> '0'); signal source: arrayNport_reg3 := (others=> (others=> '0')); signal sender_ant: regNport := (others=> '0'); +signal manual_routing_flag : std_logic; +signal manual_routing_sel : integer range 0 to (NPORT-1); +signal manual_routing_en : boolean; + begin ask <= '1' when h(LOCAL)='1' or h(EAST)='1' or h(WEST)='1' or h(NORTH)='1' or h(SOUTH)='1' else '0'; @@ -98,8 +107,11 @@ begin tx <= header((METADEFLIT - 1) downto QUARTOFLIT); ty <= header((QUARTOFLIT - 1) downto 0); - dirx <= WEST when lx > tx else EAST; - diry <= NORTH when ly < ty else SOUTH; + manual_routing_flag <= header(TAM_FLIT-1); + manual_routing_sel <= conv_integer(header(TAM_FLIT-2 downto TAM_FLIT-3)); + + dirx <= WEST when lx > tx or (manual_routing_en and manual_routing_sel=WEST) else EAST; + diry <= NORTH when ly < ty or (manual_routing_en and manual_routing_sel=NORTH) else SOUTH; process(reset,clock) begin @@ -137,21 +149,62 @@ begin -- S7 -> O estado S7 � necess�rio para que a porta selecionada para roteamento baixe o sinal -- h. -- - process(ES,ask,h,lx,ly,tx,ty,auxfree,dirx,diry) + + process(manual_routing_flag, manual_routing_sel) begin - case ES is - when S0 => PES <= S1; - when S1 => if ask='1' then PES <= S2; else PES <= S1; end if; - when S2 => PES <= S3; - when S3 => if lx = tx and ly = ty and auxfree(LOCAL)='1' then PES<=S4; - elsif lx /= tx and auxfree(dirx)='1' then PES<=S5; - elsif lx = tx and ly /= ty and auxfree(diry)='1' then PES<=S6; - else PES<=S1; end if; - when S4 => PES<=S7; - when S5 => PES<=S7; - when S6 => PES<=S7; - when S7 => PES<=S1; - end case; + if manual_routing_flag = '1' then + case manual_routing_sel is + when WEST => manual_routing_en <= manual_WEST; + when EAST => manual_routing_en <= manual_EAST; + when NORTH => manual_routing_en <= manual_NORTH; + when SOUTH => manual_routing_en <= manual_SOUTH; + when others => manual_routing_en <= false; + end case; + else + manual_routing_en <= false; + end if; + end process; + + process(ES, ask, auxfree, dirx, diry, lx, ly, manual_routing_en, manual_routing_sel, tx, ty) + begin + case ES is + when S0 => PES <= S1; + when S1 => + if ask = '1' then PES <= S2; else PES <= S1; end if; + when S2 => PES <= S3; + when S3 => + if lx = tx and ly = ty then + if (not manual_routing_en) and auxfree(LOCAL) = '1' then PES <= S4; + elsif manual_routing_en then + case manual_routing_sel is + when EAST|WEST => + if auxfree(dirx) = '1' then + PES <= S5; + else + PES <= S1; + end if; + when NORTH|SOUTH => + if auxfree(diry) = '1' then + PES <= S6; + else + PES <= S1; + end if; + when others => + if auxfree(LOCAL) = '1' then + PES <= S4; + else + PES <= S1; + end if; + end case; + end if; + elsif lx /= tx and auxfree(dirx) = '1' then PES <= S5; + elsif lx = tx and ly /= ty and auxfree(diry) = '1' then PES <= S6; + else PES <= S1; end if; + when S4 => PES <= S7; + when S5 => PES <= S7; + when S6 => PES <= S7; + when S7 => PES <= S1; + end case; end process; ------------------------------------------------------------------------------------------------------ diff --git a/hemps8.5/hardware/vhdl/pe/router/RouterCC.vhd b/hardware/vhdl/pe/router/RouterCC.vhd similarity index 89% rename from hemps8.5/hardware/vhdl/pe/router/RouterCC.vhd rename to hardware/vhdl/pe/router/RouterCC.vhd index 9108fd1..367d02b 100644 --- a/hemps8.5/hardware/vhdl/pe/router/RouterCC.vhd +++ b/hardware/vhdl/pe/router/RouterCC.vhd @@ -25,21 +25,21 @@ use std.textio.all; use IEEE.NUMERIC_STD.all; entity traffic_monitor is - generic( ID : integer ); -port( - clock : in std_logic; - reset : in std_logic; - data_in : in regflit; - address : in regmetadeflit; - rx : in std_logic; - credit_o : in std_logic ); + generic(ID : integer); + port( + clock : in std_logic; + reset : in std_logic; + data_in : in regflit; + address : in regmetadeflit; + rx : in std_logic; + credit_o : in std_logic); end traffic_monitor; architecture arq_traffic of traffic_monitor is type type_state is (Hheader, Ppayload, Sservice, task_allocation, task_menssage, cont_payload); signal SM_traffic_monitor : type_state; - signal tick_counter : reg32; + signal tick_counter : reg32; signal target_router : regflit; signal header_time : integer; signal bandwidth_allocation : integer; @@ -269,18 +269,22 @@ use std.textio.all; use IEEE.NUMERIC_STD.all; entity RouterCC is -generic( address: regmetadeflit); -port( - clock: in std_logic; - reset: in std_logic; - clock_rx: in regNport; - rx: in regNport; - data_in: in arrayNport_regflit; - credit_o: out regNport; - clock_tx: out regNport; - tx: out regNport; - data_out: out arrayNport_regflit; - credit_i: in regNport); + generic(address : regmetadeflit; + manual_NORTH : boolean := false; + manual_SOUTH : boolean := false; + manual_EAST : boolean := false; + manual_WEST : boolean := false); + port( + clock : in std_logic; + reset : in std_logic; + clock_rx : in regNport; + rx : in regNport; + data_in : in arrayNport_regflit; + credit_o : out regNport; + clock_tx : out regNport; + tx : out regNport; + data_out : out arrayNport_regflit; + credit_i : in regNport); end RouterCC; architecture RouterCC of RouterCC is @@ -304,10 +308,10 @@ begin -- Remova esse generate caso queira fazer uma synthesis. -- Esse generate é usado para o traffic_monitor das portas de entrada do router. --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - credit_o <= credit_o_sig; + credit_o <= credit_o_sig; traffic_router: for i in 0 to (NPORT-1) generate traffic_monit : entity work.traffic_monitor - generic map( ID => i ) + generic map( ID => i ) port map( clock => clock, reset => reset, @@ -393,18 +397,23 @@ begin data_ack => data_ack(4), credit_o => credit_o_sig(4)); - SwitchControl : Entity work.SwitchControl(XY) - port map( - clock => clock, - reset => reset, - h => h, - ack_h => ack_h, - address => address, - data => data, - sender => sender, - free => free, - mux_in => mux_in, - mux_out => mux_out); + SwitchControl : Entity work.SwitchControl(XY) + generic map( + manual_NORTH => manual_NORTH, + manual_SOUTH => manual_SOUTH, + manual_EAST => manual_EAST, + manual_WEST => manual_WEST) + port map( + clock => clock, + reset => reset, + h => h, + ack_h => ack_h, + address => address, + data => data, + sender => sender, + free => free, + mux_in => mux_in, + mux_out => mux_out); CrossBar : Entity work.Hermes_crossbar port map( diff --git a/hardware/vhdl/receive_data.vhd b/hardware/vhdl/receive_data.vhd new file mode 100644 index 0000000..6081b7b --- /dev/null +++ b/hardware/vhdl/receive_data.vhd @@ -0,0 +1,56 @@ +library STD; +use STD.TEXTIO.all; +library IEEE; +use IEEE.std_logic_1164.all; +use IEEE.std_logic_unsigned.all; +use IEEE.std_logic_textio.all; +library work; +use work.hemps_pkg.all; +use work.standards.all; + +entity receive_data is + generic(router_nb : integer; + port_name : string); + port( + clock : in std_logic; + reset : in std_logic; + + clock_tx : in std_logic; + tx : in std_logic; + data_out : in regflit; + credit_i : out std_logic); +end receive_data; + +architecture receive_data of receive_data is +begin + + +--------------------------------------------------------------------------------------------- +-- receive traffic +--------------------------------------------------------------------------------------------- + + process(clock_tx) + variable ARQ_LINE : line; + variable line_arq : string(1 to 2000); + variable count_flit : integer := 0; + variable position : integer := 1; + file file_out : text; + variable fstatus : file_open_status; + variable dta_out : string(1 to 8); + + begin + credit_i <= '1'; -- can receive data + + if clock_tx'event and clock_tx = '1' and tx = '1' then + file_open(fstatus, file_out, "out" & integer'image(router_nb) & port_name & ".txt", write_mode); + -- report "The output file " & filename & "is open."; + dta_out := CONV_STRING_32BITS(data_out); +-- report "Data Out is:" & dta_out; + write(ARQ_LINE, dta_out & " " & "," & " " & time'image(NOW)); + writeline(file_out, ARQ_LINE); + --write(line_arq, time'image(now)); + --writeline(file_out, line_arq); + end if; + end process; + +end receive_data; diff --git a/hardware/vhdl/standards.vhd b/hardware/vhdl/standards.vhd new file mode 100644 index 0000000..4e280e9 --- /dev/null +++ b/hardware/vhdl/standards.vhd @@ -0,0 +1,431 @@ +------------------------------------------------------------------------------------------------ +-- +-- DISTRIBUTED HEMPS - version 5.0 +-- +-- Research group: GAPH-PUCRS - contact fernando.moraes@pucrs.br +-- +-- Distribution: September 2013 +-- +-- Source name: standards.vhd +-- +-- Brief description: Functions and constants for NoC generation. +-- +------------------------------------------------------------------------------------------------ + +library IEEE; +use IEEE.Std_Logic_1164.all; +use IEEE.std_logic_unsigned.all; +use IEEE.std_logic_arith.all; +use work.hemps_pkg.all; + +package standards is + +-------------------------------------------------------- +-- CONSTANTS +-------------------------------------------------------- +-- Memory map constants. + constant DEBUG : std_logic_vector(31 downto 0) := x"20000000"; + constant IRQ_MASK : std_logic_vector(31 downto 0) := x"20000010"; + constant IRQ_STATUS_ADDR : std_logic_vector(31 downto 0) := x"20000020"; + constant TIME_SLICE_ADDR : std_logic_vector(31 downto 0) := x"20000060"; + constant FIFO_AVAIL : std_logic_vector(31 downto 0) := x"20000040"; + constant END_SIM : std_logic_vector(31 downto 0) := x"20000080"; + constant CLOCK_HOLD : std_logic_vector(31 downto 0) := x"20000090"; + constant NET_ADDRESS : std_logic_vector(31 downto 0) := x"20000140"; + constant LOADER_NETADDR_REG : std_logic_vector(31 downto 0) := x"20000144"; + + -- Network interface mapping. + constant NI_STATUS_READ : std_logic_vector(31 downto 0) := x"20000100"; + constant NI_STATUS_SEND : std_logic_vector(31 downto 0) := x"20000110"; + constant NI_READ : std_logic_vector(31 downto 0) := x"20000120"; + constant NI_WRITE : std_logic_vector(31 downto 0) := x"20000130"; + constant NI_CONFIGURATION : std_logic_vector(31 downto 0) := x"20000140"; + constant NI_ACK : std_logic_vector(31 downto 0) := x"20000150"; + constant NI_NACK : std_logic_vector(31 downto 0) := x"20000160"; + constant NI_END : std_logic_vector(31 downto 0) := x"20000170"; + + -- DMNI mapping. + constant DMNI_SIZE : std_logic_vector(31 downto 0) := x"20000200"; + constant DMNI_ADDR : std_logic_vector(31 downto 0) := x"20000210"; + constant DMNI_SIZE_2 : std_logic_vector(31 downto 0) := x"20000204"; + constant DMNI_ADDR_2 : std_logic_vector(31 downto 0) := x"20000214"; + constant DMNI_OP : std_logic_vector(31 downto 0) := x"20000220"; + constant START_DMNI : std_logic_vector(31 downto 0) := x"20000230"; + constant DMNI_ACK : std_logic_vector(31 downto 0) := x"20000240"; + + constant DMNI_SEND_ACTIVE : std_logic_vector(31 downto 0) := x"20000250"; + constant DMNI_RECEIVE_ACTIVE : std_logic_vector(31 downto 0) := x"20000260"; + constant DMNI_RECEIVE_BUFFER : std_logic_vector(31 downto 0) := x"20000264"; + constant DMNI_REQ_FIFO : std_logic_vector(31 downto 0) := x"20000268"; + + constant SCHEDULING_REPORT : std_logic_vector(31 downto 0) := x"20000270"; + + constant TICK_COUNTER_ADDR : std_logic_vector(31 downto 0) := x"20000300"; + constant SET_CPU_KILL : std_logic_vector(31 downto 0) := x"20000320"; + constant REQ_APP_REG : std_logic_vector(31 downto 0) := x"20000350"; + constant ACK_APP_REG : std_logic_vector(31 downto 0) := x"20000360"; + + constant PENDING_SERVICE_INTR : std_logic_vector(31 downto 0) := x"20000400"; + + + constant SLACK_TIME_MONITOR : std_logic_vector(31 downto 0) := x"20000370"; + constant SLACK_MONITOR_WINDOW : integer := 50000; +-------------------------------------------------------------------------------- +-- Router position constants - FIXED - it is not a function of the NoC size +-------------------------------------------------------------------------------- + constant BL : integer := 0; + constant BC : integer := 1; + constant BR : integer := 2; + constant CL : integer := 3; + constant CC : integer := 4; + constant CRX : integer := 5; + constant TL : integer := 6; + constant TC : integer := 7; + constant TR : integer := 8; + + ----------------------------------------------------------------------------- + -- DMNI Hardware handled operations + ----------------------------------------------------------------------------- + constant DMMA_OPERATION : std_logic_vector(31 downto 0) := x"00000290"; + constant START_CPU_OPERATION : std_logic_vector(31 downto 0) := x"00000300"; + constant REQ_OPERATION : std_logic_vector(31 downto 0) := x"00000480"; + +--------------------------------------------------------- +-- CONSTANTS INDEPENDENTES +--------------------------------------------------------- + constant NPORT : integer := 5; + + constant EAST : integer := 0; + constant WEST : integer := 1; + constant NORTH : integer := 2; + constant SOUTH : integer := 3; + constant LOCAL : integer := 4; + +--------------------------------------------------------- +-- CONSTANT DEPENDENTE DA LARGURA DE BANDA DA REDE - FIXED FOR HEMPS +--------------------------------------------------------- + constant TAM_FLIT : integer range 1 to 64 := 32; -- Flit tem faixa de 1 ate 64 e eh atribuido 32 + constant METADEFLIT : integer range 1 to 32 := (TAM_FLIT/2); + constant QUARTOFLIT : integer range 1 to 16 := (TAM_FLIT/4); + +--------------------------------------------------------- +-- CONSTANTS DEPENDENTES DA PROFUNDIDADE DA FILA +--------------------------------------------------------- + constant TAM_BUFFER : integer := 16; + constant TAM_BUFFER_DMNI : integer := 16; + constant TAM_POINTER : integer range 1 to 32 := 4; + +--------------------------------------------------------- +-- CONSTANTS DEPENDENTES DO NUMERO DE ROTEADORES +--------------------------------------------------------- + constant NROT : integer := NUMBER_PROCESSORS; + + constant MIN_X : integer := 0; + constant MIN_Y : integer := 0; + constant MAX_X : integer := NUMBER_PROCESSORS_X-1; + constant MAX_Y : integer := NUMBER_PROCESSORS_Y-1; + +--------------------------------------------------------- +-- CONSTANT TB +--------------------------------------------------------- + constant TAM_LINHA : integer := 2; --4; + +--------------------------------------------------------- +-- SUBTIPOS, TIPOS E FUNCOES +--------------------------------------------------------- + + subtype reg3 is std_logic_vector(2 downto 0); + subtype reg8 is std_logic_vector(7 downto 0); + subtype reg30 is std_logic_vector(29 downto 0); + subtype reg32 is std_logic_vector(31 downto 0); + subtype regNrot is std_logic_vector((NROT-1) downto 0); + subtype regNport is std_logic_vector((NPORT-1) downto 0); + subtype regflit is std_logic_vector((TAM_FLIT-1) downto 0); + subtype regmetadeflit is std_logic_vector((METADEFLIT-1) downto 0); + subtype regquartoflit is std_logic_vector((QUARTOFLIT-1) downto 0); + subtype pointer is std_logic_vector((TAM_POINTER-1) downto 0); + subtype regNPe is std_logic_vector((NUMBER_PROCESSORS - 1) downto 0); + + type buff is array(0 to TAM_BUFFER-1) of regflit; + type buff_dmni is array(0 to TAM_BUFFER_DMNI-1) of regflit; + + + type arrayNport_reg3 is array((NPORT-1) downto 0) of reg3; + type arrayNport_reg8 is array((NPORT-1) downto 0) of reg8; + type arrayNport_regflit is array((NPORT-1) downto 0) of regflit; + type arrayNrot_reg3 is array((NROT-1) downto 0) of reg3; + type arrayNrot_regflit is array((NROT-1) downto 0) of regflit; + type arrayNrot_regmetadeflit is array((NROT-1) downto 0) of regmetadeflit; + type arrayNPe_reg32 is array((NUMBER_PROCESSORS -1) downto 0) of reg32; + type arrayNPe_reg30 is array((NUMBER_PROCESSORS -1) downto 0) of reg30; + type arrayNio_regflit is array((IO_NUMBER-1) downto 0) of regflit; + + -- number of ports of the processing_element - 4 - north/south/west/east + type arrayNPORT_1_regflit is array(3 downto 0) of regflit; + +--------------------------------------------------------- +-- HERMES FUCTIONS +--------------------------------------------------------- + function CONV_VECTOR(int : integer) return std_logic_vector; + function CONV_VECTOR(letra : string(1 to TAM_LINHA); pos : integer) return std_logic_vector; + function CONV_HEX(int : integer) return string; + function CONV_STRING_4BITS(dado : std_logic_vector(3 downto 0)) return string; + function CONV_STRING_8BITS(dado : std_logic_vector(7 downto 0)) return string; + function CONV_STRING_16BITS(dado : std_logic_vector(15 downto 0)) return string; + function CONV_STRING_32BITS(dado : std_logic_vector(31 downto 0)) return string; + +--------------------------------------------------------- +-- HEMPS FUCTIONS +--------------------------------------------------------- + function RouterPosition(router : integer) return integer; + function RouterAddress(router : integer) return std_logic_vector; + function log_filename(i : integer) return string; + + function ManualNORTHbyPos(router : integer) return boolean; + function ManualSOUTHbyPos(router : integer) return boolean; + function ManualEASTbyPos(router : integer) return boolean; + function ManualWESTbyPos(router : integer) return boolean; + + function io_index(router : integer) return integer; + +end standards; + +package body standards is + -- + -- converte um inteiro em um std_logic_vector(2 downto 0) + -- + function CONV_VECTOR(int : integer) return std_logic_vector is + variable bin : reg3; + begin + case(int) is + when 0 => bin := "000"; + when 1 => bin := "001"; + when 2 => bin := "010"; + when 3 => bin := "011"; + when 4 => bin := "100"; + when 5 => bin := "101"; + when 6 => bin := "110"; + when 7 => bin := "111"; + when others => bin := "000"; + end case; + return bin; +end CONV_VECTOR; +--------------------------------------------------------- +-- FUNCOES TB +--------------------------------------------------------- +-- +-- converte um caracter de uma dada linha em um std_logic_vector +-- +function CONV_VECTOR(letra : string(1 to TAM_LINHA); pos : integer) return std_logic_vector is + variable bin : std_logic_vector(3 downto 0); +begin + case (letra(pos)) is + when '0' => bin := "0000"; + when '1' => bin := "0001"; + when '2' => bin := "0010"; + when '3' => bin := "0011"; + when '4' => bin := "0100"; + when '5' => bin := "0101"; + when '6' => bin := "0110"; + when '7' => bin := "0111"; + when '8' => bin := "1000"; + when '9' => bin := "1001"; + when 'A' => bin := "1010"; + when 'B' => bin := "1011"; + when 'C' => bin := "1100"; + when 'D' => bin := "1101"; + when 'E' => bin := "1110"; + when 'F' => bin := "1111"; + when others => bin := "0000"; + end case; + return bin; +end CONV_VECTOR; + +-- converte um inteiro em um string +function CONV_HEX(int : integer) return string is + variable str : string(1 to 1); +begin + case(int) is + when 0 => str := "0"; + when 1 => str := "1"; + when 2 => str := "2"; + when 3 => str := "3"; + when 4 => str := "4"; + when 5 => str := "5"; + when 6 => str := "6"; + when 7 => str := "7"; + when 8 => str := "8"; + when 9 => str := "9"; + when 10 => str := "A"; + when 11 => str := "B"; + when 12 => str := "C"; + when 13 => str := "D"; + when 14 => str := "E"; + when 15 => str := "F"; + when others => str := "U"; +end case; +return str; +end CONV_HEX; + +function CONV_STRING_4BITS(dado : std_logic_vector(3 downto 0)) return string is + variable str : string(1 to 1); +begin + str := CONV_HEX(CONV_INTEGER(dado)); + return str; +end CONV_STRING_4BITS; + +function CONV_STRING_8BITS(dado : std_logic_vector(7 downto 0)) return string is + variable str1, str2 : string(1 to 1); + variable str : string(1 to 2); +begin + str1 := CONV_STRING_4BITS(dado(7 downto 4)); + str2 := CONV_STRING_4BITS(dado(3 downto 0)); + str := str1 & str2; + return str; +end CONV_STRING_8BITS; + +function CONV_STRING_16BITS(dado : std_logic_vector(15 downto 0)) return string is + variable str1, str2 : string(1 to 2); + variable str : string(1 to 4); +begin + str1 := CONV_STRING_8BITS(dado(15 downto 8)); + str2 := CONV_STRING_8BITS(dado(7 downto 0)); + str := str1 & str2; + return str; +end CONV_STRING_16BITS; + +function CONV_STRING_32BITS(dado : std_logic_vector(31 downto 0)) return string is + variable str1, str2 : string(1 to 4); + variable str : string(1 to 8); +begin + str1 := CONV_STRING_16BITS(dado(31 downto 16)); + str2 := CONV_STRING_16BITS(dado(15 downto 0)); + str := str1 & str2; + return str; +end CONV_STRING_32BITS; + +-- Returns the router position in the mesh +-- BR: Botton Right +-- BL: Botton Left +-- TR: Top Right +-- TL: Top Left +-- CRX: Center Right +-- CL: Center Left +-- CC: Center +-- 4x4 positions exemple +-- TL TC TC TR +-- CL CC CC CRX +-- CL CC CC CRX +-- BL BC BC BR +function RouterPosition(router : integer) return integer is + variable pos : integer range 0 to TR; + variable line, column : integer; +begin + + --line := router/NUMBER_PROCESSORS_Y; + column := router mod NUMBER_PROCESSORS_X; + + if router >= NUMBER_PROCESSORS-NUMBER_PROCESSORS_X then --TOP + if column = NUMBER_PROCESSORS_X-1 then --RIGHT + pos := TR; + elsif column = 0 then --LEFT + pos := TL; + else --CENTER_X + pos := TC; + end if; + elsif router < NUMBER_PROCESSORS_X then --BOTTOM + if column = NUMBER_PROCESSORS_X-1 then --RIGHT + pos := BR; + elsif column = 0 then --LEFT + pos := BL; + else --CENTER_X + pos := BC; + end if; + else --CENTER_Y + if column = NUMBER_PROCESSORS_X-1 then --RIGHT + pos := CRX; + elsif column = 0 then --LEFT + pos := CL; + else --CENTER_X + pos := CC; + end if; + end if; + + return pos; + +end RouterPosition; + +function RouterAddress(router : integer) return std_logic_vector is + variable pos_x, pos_y : regquartoflit; + variable addr : regmetadeflit; + variable aux : integer; +begin + aux := (router/NUMBER_PROCESSORS_X); + pos_x := conv_std_logic_vector((router mod NUMBER_PROCESSORS_X), QUARTOFLIT); + pos_y := conv_std_logic_vector(aux, QUARTOFLIT); + + addr := pos_x & pos_y; + return addr; +end RouterAddress; + +function log_filename(i : integer) return string is + variable filename : string(1 to 14); + variable aux_x : integer; + variable aux_y : integer; +begin + aux_x := (i mod NUMBER_PROCESSORS_X); + aux_y := (i/NUMBER_PROCESSORS_X); + filename := "log/log" & CONV_HEX(aux_x) & "x" & CONV_HEX(aux_y) & ".txt"; + return filename; +end log_filename; + +function ManualNORTHbyPos(router : integer) return boolean is +begin + if (OPEN_IO(router) = "nor") then + return true; + else + return false; + end if; +end ManualNORTHbyPos; + +function ManualSOUTHbyPos(router : integer) return boolean is +begin + if (OPEN_IO(router) = "sou") then + return true; + else + return false; + end if; +end ManualSOUTHbyPos; + +function ManualEASTbyPos(router : integer) return boolean is +begin + if (OPEN_IO(router) = "eas") then + return true; + else + return false; + end if; +end ManualEASTbyPos; + +function ManualWESTbyPos(router : integer) return boolean is +begin + if (OPEN_IO(router) = "wes") then + return true; + else + return false; + end if; +end ManualWESTbyPos; + +function io_index(router : integer) return integer is + variable i : integer; + variable index : integer; +begin + index := 0; + for i in 0 to router loop + if (OPEN_IO(i) = "eas" or OPEN_IO(i) = "wes" or OPEN_IO(i) = "nor" or OPEN_IO(i) = "sou") then + index := index + 1; + end if; + end loop; + return index-1; +end io_index; + +end standards; diff --git a/hardware/vhdl/test_bench.vhd b/hardware/vhdl/test_bench.vhd new file mode 100644 index 0000000..a601ebd --- /dev/null +++ b/hardware/vhdl/test_bench.vhd @@ -0,0 +1,454 @@ +------------------------------------------------------------------------------------------------ +-- +-- DISTRIBUTED HEMPS - version 5.0 +-- +-- Research group: GAPH-PUCRS - contact fernando.moraes@pucrs.br +-- +-- Distribution: September 2013 +-- +-- Source name: test_bench.vhd +-- +-- Brief description: Test bench. +-- +------------------------------------------------------------------------------------------------ + +library IEEE; +use ieee.std_logic_1164.all; +use ieee.std_logic_arith.all; +use ieee.std_logic_unsigned.all; +use ieee.std_logic_textio.all; +use std.textio.all; +use work.hemps_pkg.all; +use work.standards.all; + +entity test_bench is + + type procload is record + position : std_logic_vector(31 downto 0); + status : std_logic; + end record; + + type list_of_procs is array(0 to MAX_TASKS_APP-1) of procload; + + + type config is record + code_name : string(1 to 40); + position : std_logic_vector(31 downto 0); + code_size : std_logic_vector(31 downto 0); + end record; + + type list_of_tasks is array(0 to MAX_TASKS_APP-1) of config; + type list_of_apps is array(0 to APP_NUMBER-1) of string(1 to 40); + + --constant log_file : string := "output_master.txt"; --! port description + constant mlite_description : string := "RTL"; + constant ram_description : string := "RTL"; + constant router_description : string := "RTL"; + + constant REPO_SIZE : integer := (MEMORY_SIZE_BYTES/4); --This math is because each repoline is 32 bits word + constant TAM_PACKSTART : integer := 4; + + type repo_type is array(REPO_SIZE-1 downto 0) of std_logic_vector(31 downto 0); + + impure function load_repo (repo_file : in string) return repo_type is + file file_ptr : text open read_mode is repo_file; + variable inline : line; + variable i : integer := 0; + + variable mem : repo_type := (others => (others => '0')); + + begin + while not endfile(file_ptr) loop + if (i = REPO_SIZE) then + assert false report "ERROR: reposiotory access overflow - i= " & integer'image(i) + severity error; + end if; + + readline(file_ptr, inline); + hread(inline, mem(i)); + i := i + 1; + end loop; + + file_close(file_ptr); + return mem; + end load_repo; + + impure function get_cfg (cfg_file : in string) return list_of_tasks is + + file file_ptr : text open read_mode is cfg_file; + variable inline : line; + variable strline : string(1 to 40); + variable cfg : list_of_tasks; + variable str_len : integer; + variable i : integer := 0; + begin + + while not endfile(file_ptr) loop + readline(file_ptr, inline); + str_len := inline'length; + read(inline, strline(1 to inline'length)); + cfg(i).code_name(1 to str_len) := strline(1 to str_len); + cfg(i).code_name(str_len+1 to 40) := (others => NUL); + readline(file_ptr, inline); + hread(inline, cfg(i).position); + readline(file_ptr, inline); + hread(inline, cfg(i).code_size); + i := i + 1; + end loop; + file_close(file_ptr); + return cfg; + end get_cfg; + + + impure function get_procs (cfg_file : in string) return list_of_procs is + + file file_ptr : text open read_mode is cfg_file; + variable inline : line; + variable strline : string(1 to 40); + variable procs : list_of_procs; + variable cfg : list_of_tasks; + variable str_len : integer; + variable i : integer := 0; + begin + + while not endfile(file_ptr) loop + readline(file_ptr, inline); + str_len := inline'length; + read(inline, strline(1 to inline'length)); + cfg(i).code_name(1 to str_len) := strline(1 to str_len); + cfg(i).code_name(str_len+1 to 40) := (others => NUL); + readline(file_ptr, inline); + hread(inline, cfg(i).position); + procs(i).position := cfg(i).position; + procs(i).status := '1'; + readline(file_ptr, inline); + hread(inline, cfg(i).code_size); + i := i + 1; + end loop; + file_close(file_ptr); + return procs; + end get_procs; + + + + impure function get_num_tasks(cfg_file : in string) return integer is + + file file_ptr : text open read_mode is cfg_file; + variable inline : line; + variable i : integer := 0; + begin + + while not endfile(file_ptr) loop + readline(file_ptr, inline); + readline(file_ptr, inline); + readline(file_ptr, inline); + i := i + 1; + end loop; + file_close(file_ptr); + return i; + end get_num_tasks; + + impure function get_apps_cfg (cfg_file : in string) return list_of_apps is + + file file_ptr : text open read_mode is cfg_file; + variable inline : line; + variable strline : string(1 to 15); + variable apps_cfg : list_of_apps; + variable str_len : integer; + begin + + for i in 0 to APP_NUMBER-1 loop + readline(file_ptr, inline); + str_len := inline'length; + read(inline, strline(1 to inline'length)); + apps_cfg(i)(1 to str_len) := strline(1 to str_len); + apps_cfg(i)(str_len+1 to 15) := (others => NUL); + end loop; + file_close(file_ptr); + return apps_cfg; + end get_apps_cfg; + + + impure function next_wave (taloc : in integer; vapp_counter: in integer; vapps_cfg: list_of_apps; vlisttask_ocupacao: arrayNPe_reg32) return integer is + variable talocret: integer := 0; + variable task_cfg : list_of_tasks; + variable proc_load : list_of_procs; + variable task_num : integer; + begin + if (vapp_counter+1 < APP_NUMBER) then + task_cfg := get_cfg(vapps_cfg(vapp_counter+1)); + proc_load := get_procs(vapps_cfg(vapp_counter+1)); + task_num := get_num_tasks(vapps_cfg(vapp_counter+1)); + for i in 0 to task_num-1 loop + for j in 0 to NUMBER_PROCESSORS-1 loop + if (task_cfg(i).position = RouterAddress(j)) then + if (vlisttask_ocupacao(j) = x"00000001") then + talocret := 1; + end if; + end if; + end loop; + end loop; + end if; + + return talocret; + end next_wave; + +end; + + +architecture test_bench of test_bench is + + signal clock : std_logic := '0'; + signal clock_200 : std_logic := '1'; + signal reset : std_logic; + + constant apps_cfg : list_of_apps := get_apps_cfg("apps.cfg"); + + signal current_time : integer := 0; + signal app_i : integer := 0; + + --NoC Interface (IO) + signal tx_io : std_logic_vector((IO_NUMBER-1) downto 0); + signal data_out_io : arrayNio_regflit; + signal credit_i_io : std_logic_vector((IO_NUMBER-1) downto 0); + signal clock_tx_io : std_logic_vector((IO_NUMBER-1) downto 0); + signal rx_io : std_logic_vector((IO_NUMBER-1) downto 0); + signal data_in_io : arrayNio_regflit; + signal credit_o_io : std_logic_vector((IO_NUMBER-1) downto 0); + signal clock_rx_io : std_logic_vector((IO_NUMBER-1) downto 0); + + --Leitura para IO + + signal task_cfg : list_of_tasks; + signal ntask_cfg : list_of_tasks; + signal proc_load : list_of_procs; + signal task_num : integer; + signal ntask_num : integer; + signal rd_addr : std_logic_vector(23 downto 0); + signal flit_counter : integer; + signal file_counter : integer; + signal app_counter : integer; + signal packstart_counter : integer; + type packstart_type is array(0 to TAM_PACKSTART-1) of regflit; + signal packstart_data : packstart_type; + signal task_code : repo_type; + + --- Variaveis novas testbench + signal listtask_ocupacao_ret : arrayNPe_reg32:= (others=>x"00000010"); + signal listtask_ocupacao_env : arrayNPe_reg32:= (others=>x"00000010"); + signal listtask_ocupacao : arrayNPe_reg32; + + --- Variaveis novas testbench Fim + + type send_state is (WAIT_state, GET_CODE, SEND_TASK, SEND_START); + signal SEND: send_state; + +begin + + packstart_data(0) <= x"00000002"; + packstart_data(1) <= x"00000300"; + packstart_data(2) <= x"00000000"; + + -- + -- HeMPS instantiation + -- + HeMPS : entity work.HeMPS + generic map( + mlite_description => mlite_description, + ram_description => ram_description, + router_description => router_description + ) + port map( + clock => clock, + reset => reset, + --repository + repo_address => open, + repo_data => (others => '0'), + ack_app => open, + req_app => (others => '0'), + + --NoC Interface (IO) + tx_io => tx_io, + data_out_io => data_out_io, + credit_i_io => credit_i_io, + clock_tx_io => clock_tx_io, + rx_io => rx_io, + data_in_io => data_in_io, + credit_o_io => credit_o_io, + clock_rx_io => clock_rx_io + ); + + --data_injector : entity work.inject_data + --generic map ( + -- router_nb => 1, + -- port_name => "IO" + --) + --port map ( + -- clock => clock, + -- reset => reset, + -- clock_rx => clock_rx_io, + -- rx => rx_io, + -- data_in => data_in_io, + -- credit_o => credit_o_io + --); + + data_consumer : entity work.receive_data + generic map ( + router_nb => 1, + port_name => "IO" + ) + port map ( + clock => clock, + reset => reset, + clock_tx => clock_tx_io(0), + tx => tx_io(0), + data_out => data_out_io(0), + credit_i => credit_i_io(0) + ); + + + +--------------------------------------------------------------------------------------------- +-- recebe retornos de encerramento +--------------------------------------------------------------------------------------------- + + process + begin + wait until (clock_tx_io(0)'event and clock_tx_io(0) = '1') or (reset'event and reset = '1'); + if reset = '1' then + for i in 0 to NUMBER_PROCESSORS -1 loop + listtask_ocupacao_ret(i) <= listtask_ocupacao_ret(i) + x"00000000"; + end loop; + else + if (data_out_io(0) = x"E0000000") then + wait until (clock_tx_io(0)'event and clock_tx_io(0) = '1'); + wait until (clock_tx_io(0)'event and clock_tx_io(0) = '1'); + wait until (clock_tx_io(0)'event and clock_tx_io(0) = '1'); + if (data_out_io(0) = x"00000070") then + wait until (clock_tx_io(0)'event and clock_tx_io(0) = '1'); + for i in 0 to NUMBER_PROCESSORS -1 loop + if (RouterAddress(i) = data_out_io(0)) then + listtask_ocupacao_ret(i) <= listtask_ocupacao_ret(i) + x"00000001"; + end if; + end loop; + end if; + end if; + end if; + end process; + + + + reset <= '1', '0' after 100 ns; + -- 100 MHz + clock <= not clock after 5 ns; + -- 200 MHz + clock_200 <= not clock_200 after 1.25 ns; + + --Conecta o testbench inicialmente no IO 0 + clock_rx_io(0) <= clock; + process + variable liberar_envio : integer := 1; + begin + wait until (clock'event and clock = '1') or (reset'event and reset = '1'); + if reset = '1' then + rx_io(0) <= '0'; + rd_addr <= (others => '0'); + flit_counter <= 0; + packstart_counter <= 0; + file_counter <= 0; + app_counter <= 0; + task_num <= 0; + liberar_envio := 1; + SEND <= WAIT_state; + else + for i in 0 to NUMBER_PROCESSORS-1 loop + listtask_ocupacao(i) <= listtask_ocupacao_env(i) - listtask_ocupacao_ret(i); + end loop; + case SEND is + when WAIT_state => + if (liberar_envio = 0) then + liberar_envio := 1; + for i in 0 to ntask_num-1 loop + for j in 0 to NUMBER_PROCESSORS-1 loop + if (ntask_cfg(i).position = RouterAddress(j)) then + if (listtask_ocupacao(j) = x"00000001") then + liberar_envio := 0; + end if; + end if; + end loop; + end loop; + end if; + wait until (clock'event and clock = '1'); + if ((app_counter < APP_NUMBER) and (liberar_envio = 1)) then + liberar_envio := 0; + task_cfg <= get_cfg(apps_cfg(app_counter)); + proc_load <= get_procs(apps_cfg(app_counter)); + task_num <= get_num_tasks(apps_cfg(app_counter)); + if(app_counter+1 < APP_NUMBER) then + ntask_cfg <= get_cfg(apps_cfg(app_counter+1)); + ntask_num <= get_num_tasks(apps_cfg(app_counter+1)); + end if; + wait until (clock'event and clock = '1'); + for i in 0 to NUMBER_PROCESSORS-1 loop + for j in 0 to task_num-1 loop + if (proc_load(j).position = RouterAddress(i)) then + listtask_ocupacao_env(i) <= listtask_ocupacao_env(i) + x"00000001"; + end if; + end loop; + end loop; + SEND <= GET_CODE; + + end if; + + when GET_CODE => + if file_counter < task_num then + flit_counter <= CONV_INTEGER(task_cfg(file_counter).code_size); + task_code <= load_repo(task_cfg(file_counter).code_name); + rd_addr <= (others => '0'); + SEND <= SEND_TASK; + else + app_counter <= app_counter + 1; + file_counter <= 0; + SEND <= WAIT_state; + end if; + + when SEND_TASK => + if credit_o_io(0) = '1' and flit_counter > 0 then + rx_io(0) <= '1'; + rd_addr <= rd_addr + 1; + if rd_addr = 0 then + data_in_io(0) <= task_cfg(file_counter).position; + elsif rd_addr = 1 then + data_in_io(0) <= task_cfg(file_counter).code_size + 1; + elsif rd_addr = 2 then + data_in_io(0) <= x"00000290"; + else + data_in_io(0) <= task_code(CONV_INTEGER(rd_addr-3)); + flit_counter <= flit_counter - 1; + end if; + elsif flit_counter = 0 then + SEND <= SEND_START; + rd_addr <= (others => '0'); + rx_io(0) <= '0'; + end if; + + when SEND_START => + if credit_o_io(0) = '1' and rd_addr < TAM_PACKSTART then + rx_io(0) <= '1'; + rd_addr <= rd_addr + 1; + if rd_addr = 0 then + data_in_io(0) <= task_cfg(file_counter).position; + else + data_in_io(0) <= packstart_data(CONV_INTEGER(rd_addr-1)); + end if; + else + file_counter <= file_counter + 1; + rx_io(0) <= '0'; + SEND <= GET_CODE; + end if; + + end case; + end if; + end process; + +end test_bench; diff --git a/hemps8.5/applications/aes/aes_slave4.c b/hemps8.5/applications/aes/aes_slave4.c deleted file mode 100644 index df04729..0000000 --- a/hemps8.5/applications/aes/aes_slave4.c +++ /dev/null @@ -1,95 +0,0 @@ -/********************************************************************* -* Filename: aes_sl(n).c -* Author: Leonardo Rezende Juracy and Luciano L. Caimi -* Copyleft: Original AES implementation: Brad Conte -* (brad AT bradconte.com) -* Disclaimer: This code is presented "as is" without any guarantees. -* Details: -*********************************************************************/ - -/*************************** HEADER FILES ***************************/ -#include -#include -#include "aes.h" -/**************************** VARIABLES *****************************/ - -Message msg; - -/*************************** MAIN PROGRAM ***************************/ - -int main() -{ - unsigned int key_schedule[60]; - int qtd_messages, op_mode, x, flag=1, id = -1, i; - unsigned int enc_buf[128]; - unsigned int input_text[16]; - unsigned int key[1][32] = { - {0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4} - }; - - Echo(itoa(GetTick())); - Echo("task AES SLAVE started - ID:"); - aes_key_setup(&key[0][0], key_schedule, 256); - - while(flag){ - Receive(&msg, aes_master); - memcpy(input_text, msg.msg, 12); - -#ifdef debug_comunication_on - Echo(" "); - Echo("Slave configuration"); - for(i=0; i<3;i++){ - Echo(itoh(input_text[i])); - } - Echo(" "); -#endif - - op_mode = input_text[0]; - qtd_messages = input_text[1]; - x = input_text[2]; - - if(id == -1){ - id = x; - Echo(itoa(id)); - } - Echo("Operation:"); - Echo(itoa(op_mode)); - Echo("Blocks:"); - Echo(itoa(qtd_messages)); - - if (op_mode == END_TASK){ - flag = 0; - qtd_messages = 0; - } - for(x = 0; x < qtd_messages; x++){ - Receive(&msg, aes_master); - memcpy(input_text, msg.msg, 4*AES_BLOCK_SIZE); - -#ifdef debug_comunication_on - Echo(" "); - Echo("received msg"); - for(i=0; i<16;i++){ - Echo(itoh(input_text[i])); - } - Echo(" "); -#endif - - if(op_mode == CIPHER_MODE){ - Echo("encript"); - aes_encrypt(input_text, enc_buf, key_schedule, KEY_SIZE); - } - else{ - Echo("decript"); - aes_decrypt(input_text, enc_buf, key_schedule, KEY_SIZE); - } - msg.length = 4*AES_BLOCK_SIZE; - memcpy( msg.msg, enc_buf,4*AES_BLOCK_SIZE); - Send(&msg, aes_master); - } - } - Echo("task AES SLAVE finished - ID: "); - Echo(itoa(id)); - Echo(itoa(GetTick())); - - exit(); -} diff --git a/hemps8.5/applications/aes/aes_slave5.c b/hemps8.5/applications/aes/aes_slave5.c deleted file mode 100644 index df04729..0000000 --- a/hemps8.5/applications/aes/aes_slave5.c +++ /dev/null @@ -1,95 +0,0 @@ -/********************************************************************* -* Filename: aes_sl(n).c -* Author: Leonardo Rezende Juracy and Luciano L. Caimi -* Copyleft: Original AES implementation: Brad Conte -* (brad AT bradconte.com) -* Disclaimer: This code is presented "as is" without any guarantees. -* Details: -*********************************************************************/ - -/*************************** HEADER FILES ***************************/ -#include -#include -#include "aes.h" -/**************************** VARIABLES *****************************/ - -Message msg; - -/*************************** MAIN PROGRAM ***************************/ - -int main() -{ - unsigned int key_schedule[60]; - int qtd_messages, op_mode, x, flag=1, id = -1, i; - unsigned int enc_buf[128]; - unsigned int input_text[16]; - unsigned int key[1][32] = { - {0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4} - }; - - Echo(itoa(GetTick())); - Echo("task AES SLAVE started - ID:"); - aes_key_setup(&key[0][0], key_schedule, 256); - - while(flag){ - Receive(&msg, aes_master); - memcpy(input_text, msg.msg, 12); - -#ifdef debug_comunication_on - Echo(" "); - Echo("Slave configuration"); - for(i=0; i<3;i++){ - Echo(itoh(input_text[i])); - } - Echo(" "); -#endif - - op_mode = input_text[0]; - qtd_messages = input_text[1]; - x = input_text[2]; - - if(id == -1){ - id = x; - Echo(itoa(id)); - } - Echo("Operation:"); - Echo(itoa(op_mode)); - Echo("Blocks:"); - Echo(itoa(qtd_messages)); - - if (op_mode == END_TASK){ - flag = 0; - qtd_messages = 0; - } - for(x = 0; x < qtd_messages; x++){ - Receive(&msg, aes_master); - memcpy(input_text, msg.msg, 4*AES_BLOCK_SIZE); - -#ifdef debug_comunication_on - Echo(" "); - Echo("received msg"); - for(i=0; i<16;i++){ - Echo(itoh(input_text[i])); - } - Echo(" "); -#endif - - if(op_mode == CIPHER_MODE){ - Echo("encript"); - aes_encrypt(input_text, enc_buf, key_schedule, KEY_SIZE); - } - else{ - Echo("decript"); - aes_decrypt(input_text, enc_buf, key_schedule, KEY_SIZE); - } - msg.length = 4*AES_BLOCK_SIZE; - memcpy( msg.msg, enc_buf,4*AES_BLOCK_SIZE); - Send(&msg, aes_master); - } - } - Echo("task AES SLAVE finished - ID: "); - Echo(itoa(id)); - Echo(itoa(GetTick())); - - exit(); -} diff --git a/hemps8.5/applications/aes/aes_slave6.c b/hemps8.5/applications/aes/aes_slave6.c deleted file mode 100644 index df04729..0000000 --- a/hemps8.5/applications/aes/aes_slave6.c +++ /dev/null @@ -1,95 +0,0 @@ -/********************************************************************* -* Filename: aes_sl(n).c -* Author: Leonardo Rezende Juracy and Luciano L. Caimi -* Copyleft: Original AES implementation: Brad Conte -* (brad AT bradconte.com) -* Disclaimer: This code is presented "as is" without any guarantees. -* Details: -*********************************************************************/ - -/*************************** HEADER FILES ***************************/ -#include -#include -#include "aes.h" -/**************************** VARIABLES *****************************/ - -Message msg; - -/*************************** MAIN PROGRAM ***************************/ - -int main() -{ - unsigned int key_schedule[60]; - int qtd_messages, op_mode, x, flag=1, id = -1, i; - unsigned int enc_buf[128]; - unsigned int input_text[16]; - unsigned int key[1][32] = { - {0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4} - }; - - Echo(itoa(GetTick())); - Echo("task AES SLAVE started - ID:"); - aes_key_setup(&key[0][0], key_schedule, 256); - - while(flag){ - Receive(&msg, aes_master); - memcpy(input_text, msg.msg, 12); - -#ifdef debug_comunication_on - Echo(" "); - Echo("Slave configuration"); - for(i=0; i<3;i++){ - Echo(itoh(input_text[i])); - } - Echo(" "); -#endif - - op_mode = input_text[0]; - qtd_messages = input_text[1]; - x = input_text[2]; - - if(id == -1){ - id = x; - Echo(itoa(id)); - } - Echo("Operation:"); - Echo(itoa(op_mode)); - Echo("Blocks:"); - Echo(itoa(qtd_messages)); - - if (op_mode == END_TASK){ - flag = 0; - qtd_messages = 0; - } - for(x = 0; x < qtd_messages; x++){ - Receive(&msg, aes_master); - memcpy(input_text, msg.msg, 4*AES_BLOCK_SIZE); - -#ifdef debug_comunication_on - Echo(" "); - Echo("received msg"); - for(i=0; i<16;i++){ - Echo(itoh(input_text[i])); - } - Echo(" "); -#endif - - if(op_mode == CIPHER_MODE){ - Echo("encript"); - aes_encrypt(input_text, enc_buf, key_schedule, KEY_SIZE); - } - else{ - Echo("decript"); - aes_decrypt(input_text, enc_buf, key_schedule, KEY_SIZE); - } - msg.length = 4*AES_BLOCK_SIZE; - memcpy( msg.msg, enc_buf,4*AES_BLOCK_SIZE); - Send(&msg, aes_master); - } - } - Echo("task AES SLAVE finished - ID: "); - Echo(itoa(id)); - Echo(itoa(GetTick())); - - exit(); -} diff --git a/hemps8.5/applications/aes/aes_slave7.c b/hemps8.5/applications/aes/aes_slave7.c deleted file mode 100644 index df04729..0000000 --- a/hemps8.5/applications/aes/aes_slave7.c +++ /dev/null @@ -1,95 +0,0 @@ -/********************************************************************* -* Filename: aes_sl(n).c -* Author: Leonardo Rezende Juracy and Luciano L. Caimi -* Copyleft: Original AES implementation: Brad Conte -* (brad AT bradconte.com) -* Disclaimer: This code is presented "as is" without any guarantees. -* Details: -*********************************************************************/ - -/*************************** HEADER FILES ***************************/ -#include -#include -#include "aes.h" -/**************************** VARIABLES *****************************/ - -Message msg; - -/*************************** MAIN PROGRAM ***************************/ - -int main() -{ - unsigned int key_schedule[60]; - int qtd_messages, op_mode, x, flag=1, id = -1, i; - unsigned int enc_buf[128]; - unsigned int input_text[16]; - unsigned int key[1][32] = { - {0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4} - }; - - Echo(itoa(GetTick())); - Echo("task AES SLAVE started - ID:"); - aes_key_setup(&key[0][0], key_schedule, 256); - - while(flag){ - Receive(&msg, aes_master); - memcpy(input_text, msg.msg, 12); - -#ifdef debug_comunication_on - Echo(" "); - Echo("Slave configuration"); - for(i=0; i<3;i++){ - Echo(itoh(input_text[i])); - } - Echo(" "); -#endif - - op_mode = input_text[0]; - qtd_messages = input_text[1]; - x = input_text[2]; - - if(id == -1){ - id = x; - Echo(itoa(id)); - } - Echo("Operation:"); - Echo(itoa(op_mode)); - Echo("Blocks:"); - Echo(itoa(qtd_messages)); - - if (op_mode == END_TASK){ - flag = 0; - qtd_messages = 0; - } - for(x = 0; x < qtd_messages; x++){ - Receive(&msg, aes_master); - memcpy(input_text, msg.msg, 4*AES_BLOCK_SIZE); - -#ifdef debug_comunication_on - Echo(" "); - Echo("received msg"); - for(i=0; i<16;i++){ - Echo(itoh(input_text[i])); - } - Echo(" "); -#endif - - if(op_mode == CIPHER_MODE){ - Echo("encript"); - aes_encrypt(input_text, enc_buf, key_schedule, KEY_SIZE); - } - else{ - Echo("decript"); - aes_decrypt(input_text, enc_buf, key_schedule, KEY_SIZE); - } - msg.length = 4*AES_BLOCK_SIZE; - memcpy( msg.msg, enc_buf,4*AES_BLOCK_SIZE); - Send(&msg, aes_master); - } - } - Echo("task AES SLAVE finished - ID: "); - Echo(itoa(id)); - Echo(itoa(GetTick())); - - exit(); -} diff --git a/hemps8.5/applications/aes/aes_slave8.c b/hemps8.5/applications/aes/aes_slave8.c deleted file mode 100644 index df04729..0000000 --- a/hemps8.5/applications/aes/aes_slave8.c +++ /dev/null @@ -1,95 +0,0 @@ -/********************************************************************* -* Filename: aes_sl(n).c -* Author: Leonardo Rezende Juracy and Luciano L. Caimi -* Copyleft: Original AES implementation: Brad Conte -* (brad AT bradconte.com) -* Disclaimer: This code is presented "as is" without any guarantees. -* Details: -*********************************************************************/ - -/*************************** HEADER FILES ***************************/ -#include -#include -#include "aes.h" -/**************************** VARIABLES *****************************/ - -Message msg; - -/*************************** MAIN PROGRAM ***************************/ - -int main() -{ - unsigned int key_schedule[60]; - int qtd_messages, op_mode, x, flag=1, id = -1, i; - unsigned int enc_buf[128]; - unsigned int input_text[16]; - unsigned int key[1][32] = { - {0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4} - }; - - Echo(itoa(GetTick())); - Echo("task AES SLAVE started - ID:"); - aes_key_setup(&key[0][0], key_schedule, 256); - - while(flag){ - Receive(&msg, aes_master); - memcpy(input_text, msg.msg, 12); - -#ifdef debug_comunication_on - Echo(" "); - Echo("Slave configuration"); - for(i=0; i<3;i++){ - Echo(itoh(input_text[i])); - } - Echo(" "); -#endif - - op_mode = input_text[0]; - qtd_messages = input_text[1]; - x = input_text[2]; - - if(id == -1){ - id = x; - Echo(itoa(id)); - } - Echo("Operation:"); - Echo(itoa(op_mode)); - Echo("Blocks:"); - Echo(itoa(qtd_messages)); - - if (op_mode == END_TASK){ - flag = 0; - qtd_messages = 0; - } - for(x = 0; x < qtd_messages; x++){ - Receive(&msg, aes_master); - memcpy(input_text, msg.msg, 4*AES_BLOCK_SIZE); - -#ifdef debug_comunication_on - Echo(" "); - Echo("received msg"); - for(i=0; i<16;i++){ - Echo(itoh(input_text[i])); - } - Echo(" "); -#endif - - if(op_mode == CIPHER_MODE){ - Echo("encript"); - aes_encrypt(input_text, enc_buf, key_schedule, KEY_SIZE); - } - else{ - Echo("decript"); - aes_decrypt(input_text, enc_buf, key_schedule, KEY_SIZE); - } - msg.length = 4*AES_BLOCK_SIZE; - memcpy( msg.msg, enc_buf,4*AES_BLOCK_SIZE); - Send(&msg, aes_master); - } - } - Echo("task AES SLAVE finished - ID: "); - Echo(itoa(id)); - Echo(itoa(GetTick())); - - exit(); -} diff --git a/hemps8.5/applications/mpeg/print.c b/hemps8.5/applications/mpeg/print.c deleted file mode 100644 index 1214d46..0000000 --- a/hemps8.5/applications/mpeg/print.c +++ /dev/null @@ -1,37 +0,0 @@ -/*--------------------------------------------------------------------- -TITLE: Program Scheduler -AUTHOR: Nicolas Saint-jean -EMAIL : saintjea@lirmm.fr -DATE CREATED: 04/04/06 -FILENAME: task3.c -PROJECT: Network Process Unit -COPYRIGHT: Software placed into the public domain by the author. - Software 'as is' without warranty. Author liable for nothing. -DESCRIPTION: This file contains the task3 ----------------------------------------------------------------------*/ - -#include -#include -#include "mpeg_std.h" - -typedef int type_DATA; //unsigned - -Message msg1; - -int main() -{ - unsigned int time_a, time_b; - int i; - - Echo("MPEG Task PRINT start:"); - - for(i=0;i -#include -#include "syn_std.h" - -Message msg; - -int main() -{ - - int i, j,t; - - Echo("synthetic task A started."); - Echo(itoa(GetTick())); - -for(i=0;i -#include -#include "syn_std.h" - -Message msg; - -int main() -{ - - int i, j,t; - - Echo("synthetic task B started."); - Echo(itoa(GetTick())); - -for(i=0;i -#include -#include "syn_std.h" - -Message msg; - -int main() -{ - - int i, j,t; - - Echo("synthetic task C started."); - Echo(itoa(GetTick())); - -for(i=0;i -#include -#include "syn_std.h" - -Message msg; - -int main() -{ - - int i, j,t; - - Echo("synthetic task D started."); - Echo(itoa(GetTick())); - -for(i=0;i -#include -#include "syn_std.h" - -Message msg; - -int main() -{ - - int i, j,t; - - Echo("synthetic task E started."); - Echo(itoa(GetTick())); - -for(i=0;i -#include -#include "syn_std.h" - -Message msg; - -int main() -{ - - int i,t; - - Echo("synthetic task F started."); - Echo(itoa(GetTick())); - -for(i=0;i $*.lst - $(COPY_MIPS) $*.bin $*.dump - hexdump -v -e '1/1 "%02x" 1/1 "%02x" 1/1 "%02x" 1/1 "%02x" "\n"' $*.dump > $*.txt - -clean: - @printf "Cleaning up\n" - @rm -rf *.o - @rm -rf *.bin - @rm -rf *.map - @rm -rf *.lst - @rm -rf *.txt - @rm -rf *.dump - diff --git a/hemps8.5/hardware/vhdl/hemps.vhd b/hemps8.5/hardware/vhdl/hemps.vhd deleted file mode 100644 index f1d896d..0000000 --- a/hemps8.5/hardware/vhdl/hemps.vhd +++ /dev/null @@ -1,195 +0,0 @@ ------------------------------------------------------------------------------------------------- --- --- DISTRIBUTED HEMPS - version 5.0 --- --- Research group: GAPH-PUCRS - contact fernando.moraes@pucrs.br --- --- Distribution: September 2013 --- --- Source name: HeMPS.vhd --- --- Brief description: NoC generation --- ------------------------------------------------------------------------------------------------- - -library IEEE; -use ieee.std_logic_1164.all; -use ieee.std_logic_arith.all; -use ieee.std_logic_unsigned.all; -use work.standards.all; -use work.hemps_pkg.all; - -entity HeMPS is - port( - clock : in std_logic; - reset : in std_logic; - - -- Tasks repository interface - repo_address : out std_logic_vector(29 downto 0); - repo_data : in std_logic_vector(31 downto 0); - ack_app : out std_logic; - req_app : in std_logic_vector(31 downto 0) - - -- External Debug interface --- write_enable_debug : out std_logic; --- data_out_debug : out std_logic_vector(31 downto 0); --- busy_debug : in std_logic; - - ); -end; - -architecture HeMPS of HeMPS is - - -- Interconnection signals - type txNport is array (NUMBER_PROCESSORS - 1 downto 0) of std_logic_vector(3 downto 0); - signal tx : txNPORT; - type rxNport is array (NUMBER_PROCESSORS - 1 downto 0) of std_logic_vector(3 downto 0); - signal rx : rxNPORT; - type clock_rxNport is array (NUMBER_PROCESSORS - 1 downto 0) of std_logic_vector(3 downto 0); - signal clock_rx : clock_rxNPORT; - type clock_txNport is array (NUMBER_PROCESSORS - 1 downto 0) of std_logic_vector(3 downto 0); - signal clock_tx : clock_txNPORT; - type credit_iNport is array (NUMBER_PROCESSORS - 1 downto 0) of std_logic_vector(3 downto 0); - signal credit_i : credit_iNPORT; - type credit_oNport is array (NUMBER_PROCESSORS - 1 downto 0) of std_logic_vector(3 downto 0); - signal credit_o : credit_oNPORT; - type data_inNport is array (NUMBER_PROCESSORS - 1 downto 0) of arrayNPORT_1_regflit; - signal data_in : data_inNPORT; - type data_outNport is array (NUMBER_PROCESSORS - 1 downto 0) of arrayNPORT_1_regflit; - signal data_out : data_outNPORT; - signal address_router : std_logic_vector(7 downto 0); - type router_position is array (NUMBER_PROCESSORS - 1 downto 0) of integer range 0 to TR; - signal position : router_position; - - type repo_address_t is array (NUMBER_PROCESSORS - 1 downto 0) of std_logic_vector(29 downto 0); - signal repo_address_sig : repo_address_t; - signal repo_data_sig : arrayNPe_reg32; - signal ack_app_sig : regNPe; - signal req_app_sig : arrayNPe_reg32; - - begin - - core_type_gen: for i in 0 to NUMBER_PROCESSORS-1 generate - position(i) <= RouterPosition(i); - end generate core_type_gen; - - - proc: for i in 0 to NUMBER_PROCESSORS-1 generate - - PE: entity work.pe - generic map ( - router_address => RouterAddress(i), - kernel_type => pe_type(i), - log_file => log_filename(i) - ) - port map( - clock => clock, - reset => reset, - -- NoC - clock_tx => clock_tx(i), - tx => tx(i), - data_out => data_out(i), - credit_i => credit_i(i), - clock_rx => clock_rx(i), - rx => rx(i), - data_in => data_in(i), - credit_o => credit_o(i), - -- External Memory - repo_address => repo_address_sig(i), - repo_data_read => repo_data_sig(i), - ack_app => ack_app_sig(i), - req_app => req_app_sig(i) - -- External Debug interface --- write_enable_debug => write_enable_debug_sig(i), --- data_out_debug => data_out_debug_sig(i), --- busy_debug => busy_debug_sig(i) - - ); - - ------------------------------------------------------------------------------ - --- REPOSITORY CONNECTIONS ---------------------------------------------------- - ------------------------------------------------------------------------------ - repo_mas: if pe_type(i) = "mas" generate - repo_address <= repo_address_sig(i); - repo_data_sig(i) <= repo_data; - ack_app <= ack_app_sig(i); - req_app_sig(i) <= req_app; - end generate; - - ground_repo: if pe_type(i) /= "mas" generate - repo_address_sig(i) <= (others => '0'); - repo_data_sig(i) <= (others => '0'); - ack_app_sig(i) <= '0'; - req_app_sig(i) <= (others => '0'); - end generate; - - ------------------------------------------------------------------------------ - --- EAST PORT CONNECTIONS ---------------------------------------------------- - ------------------------------------------------------------------------------ - east_grounding: if RouterPosition(i) = BR or RouterPosition(i) = CRX or RouterPosition(i) = TR generate - rx(i)(EAST) <= '0'; - clock_rx(i)(EAST) <= '0'; - credit_i(i)(EAST) <= '0'; - data_in(i)(EAST) <= (others => '0'); - end generate; - - east_connection: if RouterPosition(i) = BL or RouterPosition(i) = CL or RouterPosition(i) = TL or RouterPosition(i) = BC or RouterPosition(i) = TC or RouterPosition(i) = CC generate - rx(i)(EAST) <= tx(i+1)(WEST); - clock_rx(i)(EAST) <= clock_tx(i+1)(WEST); - credit_i(i)(EAST) <= credit_o(i+1)(WEST); - data_in(i)(EAST) <= data_out(i+1)(WEST); - end generate; - - ------------------------------------------------------------------------------ - --- WEST PORT CONNECTIONS ---------------------------------------------------- - ------------------------------------------------------------------------------ - west_grounding: if RouterPosition(i) = BL or RouterPosition(i) = CL or RouterPosition(i) = TL generate - rx(i)(WEST) <= '0'; - clock_rx(i)(WEST) <= '0'; - credit_i(i)(WEST) <= '0'; - data_in(i)(WEST) <= (others => '0'); - end generate; - - west_connection: if (RouterPosition(i) = BR or RouterPosition(i) = CRX or RouterPosition(i) = TR or RouterPosition(i) = BC or RouterPosition(i) = TC or RouterPosition(i) = CC) generate - rx(i)(WEST) <= tx(i-1)(EAST); - clock_rx(i)(WEST) <= clock_tx(i-1)(EAST); - credit_i(i)(WEST) <= credit_o(i-1)(EAST); - data_in(i)(WEST) <= data_out(i-1)(EAST); - end generate; - - ------------------------------------------------------------------------------- - --- NORTH PORT CONNECTIONS ---------------------------------------------------- - ------------------------------------------------------------------------------- - north_grounding: if RouterPosition(i) = TL or RouterPosition(i) = TC or RouterPosition(i) = TR generate - rx(i)(NORTH) <= '0'; - clock_rx(i)(NORTH) <= '0'; - credit_i(i)(NORTH) <= '0'; - data_in(i)(NORTH) <= (others => '0'); - end generate; - - north_connection: if RouterPosition(i) = BL or RouterPosition(i) = BC or RouterPosition(i) = BR or RouterPosition(i) = CL or RouterPosition(i) = CRX or RouterPosition(i) = CC generate - rx(i)(NORTH) <= tx(i+NUMBER_PROCESSORS_X)(SOUTH); - clock_rx(i)(NORTH) <= clock_tx(i+NUMBER_PROCESSORS_X)(SOUTH); - credit_i(i)(NORTH) <= credit_o(i+NUMBER_PROCESSORS_X)(SOUTH); - data_in(i)(NORTH) <= data_out(i+NUMBER_PROCESSORS_X)(SOUTH); - end generate; - - -------------------------------------------------------------------------------- - --- SOUTH PORT CONNECTIONS ----------------------------------------------------- - --------------------------------------------------------------------------- - south_grounding: if RouterPosition(i) = BL or RouterPosition(i) = BC or RouterPosition(i) = BR generate - rx(i)(SOUTH) <= '0'; - clock_rx(i)(SOUTH) <= '0'; - credit_i(i)(SOUTH) <= '0'; - data_in(i)(SOUTH) <= (others => '0'); - end generate; - - south_connection: if RouterPosition(i) = TL or RouterPosition(i) = TC or RouterPosition(i) = TR or RouterPosition(i) = CL or RouterPosition(i) = CRX or RouterPosition(i) = CC generate - rx(i)(SOUTH) <= tx(i-NUMBER_PROCESSORS_X)(NORTH); - clock_rx(i)(SOUTH) <= clock_tx(i-NUMBER_PROCESSORS_X)(NORTH); - credit_i(i)(SOUTH) <= credit_o(i-NUMBER_PROCESSORS_X)(NORTH); - data_in(i)(SOUTH) <= data_out(i-NUMBER_PROCESSORS_X)(NORTH); - end generate; - end generate proc; - -end architecture; \ No newline at end of file diff --git a/hemps8.5/hardware/vhdl/pe/dmni/dmni.vhd b/hemps8.5/hardware/vhdl/pe/dmni/dmni.vhd deleted file mode 100644 index 473a5c1..0000000 --- a/hemps8.5/hardware/vhdl/pe/dmni/dmni.vhd +++ /dev/null @@ -1,349 +0,0 @@ ------------------------------------------------------------------------------------------------- --- --- DISTRIBUTED HEMPS - version 7.0 --- --- Research group: GAPH-PUCRS - contact fernando.moraes@pucrs.br --- --- Distribution: May 2015 --- --- Source name: dmni.vhd --- --- Brief description: Implements a DMNI module. --- --- OPERATIONS: --- 0 - Copy from memory --- 1 - Copy to memory ---------------------------------------------------------------------- - -library ieee; -use ieee.std_logic_1164.all; -use ieee.std_logic_unsigned.all; -use ieee.std_logic_arith.all; -use work.hemps_pkg.all; -use work.standards.all; - -entity dmni is - generic(address_router: regmetadeflit := (others=>'0')); - port - ( - clock : in std_logic; - reset : in std_logic; - -- Configuration interface - set_address : in std_logic; - set_address_2 : in std_logic; - set_size : in std_logic; - set_size_2 : in std_logic; - set_op : in std_logic; - start : in std_logic; - config_data : in std_logic_vector(31 downto 0); - -- Status outputs - intr : out std_logic; - send_active : out std_logic; - receive_active : out std_logic; - -- Memory interface - mem_address : out std_logic_vector(31 downto 0); - mem_data_write : out std_logic_vector(31 downto 0); - mem_data_read : in std_logic_vector(31 downto 0); - mem_byte_we : out std_logic_vector(3 downto 0); - -- Noc Interface (Local port) - tx : out std_logic; - data_out : out regflit; - credit_i : in std_logic; - clock_tx : out std_logic; - rx : in std_logic; - data_in : in regflit; - credit_o : out std_logic; - clock_rx : in std_logic - ); -end; - -architecture dmni of dmni is - - constant DMNI_TIMER: std_logic_vector(4 downto 0):="10000"; - constant WORD_SIZE: std_logic_vector(4 downto 0):="00100"; - - type dmni_state is (WAIT_state, LOAD, COPY_FROM_MEM, COPY_TO_MEM, FINISH); - signal DMNI_Send: dmni_state; - signal DMNI_Receive: dmni_state; - - type noc_state is (HEADER, PAYLOAD, DATA); - signal SR: noc_state; - - type arbiter_state is (ROUND, SEND, RECEIVE); - signal ARB: arbiter_state; - - signal bufferr: buff_dmni := (others=>(others=>'0')); - subtype buffsizebool is std_logic_vector(0 to (TAM_BUFFER_DMNI-1)); - signal is_header: buffsizebool := (others=> '0'); - signal intr_count : std_logic_vector(3 downto 0); - - signal first,last: pointer := (others=>'0'); - signal add_buffer : std_logic; - - signal payload_size : regflit; - - signal timer : std_logic_vector(4 downto 0); - signal address : std_logic_vector(31 downto 0); - signal address_2 : std_logic_vector(31 downto 0); - signal size : std_logic_vector(31 downto 0); - signal size_2 : std_logic_vector(31 downto 0); - signal send_address : std_logic_vector(31 downto 0); - signal send_address_2 : std_logic_vector(31 downto 0); - signal send_size : std_logic_vector(31 downto 0); - signal send_size_2 : std_logic_vector(31 downto 0); - signal recv_address : std_logic_vector(31 downto 0); - signal recv_size : std_logic_vector(31 downto 0); - signal prio : std_logic; - signal operation : std_logic; - signal read_av : std_logic; - signal slot_available : std_logic; - signal read_enable : std_logic; - signal write_enable : std_logic; - - signal send_active_2 : std_logic; - signal receive_active_2 : std_logic; - signal intr_counter_temp : std_logic_vector(3 downto 0); -begin - --config - proc_config: process(clock) - begin - if(clock'event and clock = '1') then - if (set_address = '1') then - address <= config_data; - address_2 <= (others => '0'); - elsif (set_address_2 = '1') then - address_2 <= config_data; - elsif (set_size = '1') then - size <= config_data; - size_2 <= (others => '0'); - elsif (set_size_2 = '1') then - size_2 <= config_data; - elsif (set_op = '1') then - operation <= config_data(0); - end if; - end if; - end process proc_config; - - mem_address <= send_address when write_enable = '1' else recv_address; - credit_o <= slot_available; - slot_available <= '0' when (first = last and add_buffer = '1') else '1'; - read_av <= '0' when (first = last and add_buffer = '0') else '1'; - clock_tx <= clock; - send_active <= send_active_2; - receive_active <= receive_active_2; - - arbiter: process (clock,reset) - begin - if reset = '1' then - read_enable <= '0'; - write_enable <= '0'; - timer <= "00000"; - prio <= '0'; - ARB <= ROUND; - elsif (clock'event and clock = '1') then - case ARB is - when ROUND => - if prio = '0' then - if DMNI_Receive = COPY_TO_MEM then - ARB <= RECEIVE; - read_enable <= '1'; - elsif send_active_2 = '1' then - ARB <= SEND; - write_enable <= '1'; - end if; - else - if send_active_2 = '1' then - ARB <= SEND; - write_enable <= '1'; - elsif DMNI_Receive = COPY_TO_MEM then - ARB <= RECEIVE; - read_enable <= '1'; - end if; - end if; - - when SEND => - if DMNI_Send = FINISH or (timer = DMNI_TIMER and receive_active_2 = '1') then - timer <= "00000"; - ARB <= ROUND; - write_enable <= '0'; - prio <= not prio; - else - timer <= timer + '1'; - end if; - - when RECEIVE => - if DMNI_Receive = FINISH or (timer = DMNI_TIMER and send_active_2 = '1') then - timer <= "00000"; - ARB <= ROUND; - read_enable <= '0'; - prio <= not prio; - else - timer <= timer + '1'; - end if; - end case; - end if; - end process arbiter; - - proc_receive : process (clock, reset) - begin - if (reset = '1') then - first <= (others=> '0'); - last <= (others=> '0'); - payload_size <= (others=> '0'); - SR <= HEADER; - add_buffer <= '0'; - receive_active_2 <= '0'; - DMNI_Receive <= WAIT_state; - recv_address <= (others=> '0'); - recv_size <= (others=> '0'); - mem_data_write <= (others=> '0'); - is_header <= (others=> '0'); - intr_counter_temp <= (others=> '0'); - mem_byte_we <= (others=> '0'); - elsif (clock'event and clock = '1') then - if (rx ='1' and slot_available = '1') then - bufferr(CONV_INTEGER(last)) <= data_in; - add_buffer <= '1'; - last <= last + 1; - - --Read from NoC - case( SR ) is - when HEADER => - intr_counter_temp <= intr_counter_temp + 1; - assert address_router = x"0000" - report "Master receiving msg" - severity note; - is_header(CONV_INTEGER(last)) <= '1'; - SR <= PAYLOAD; - when PAYLOAD => - is_header(CONV_INTEGER(last)) <= '0'; - payload_size <= data_in - 1; - SR <= DATA; - when DATA => - is_header(CONV_INTEGER(last)) <= '0'; - if(payload_size = 0) then - SR <= HEADER; - else - payload_size <= payload_size - 1; - end if; - end case ; - end if; --(rx ='1' and slot_available = '1') - - --Write to memory - case( DMNI_Receive ) is - when WAIT_state => - if (start = '1' and operation = '1') then - recv_address <= address - WORD_SIZE; - recv_size <= size - 1; - if(is_header(CONV_INTEGER(first)) = '1' and intr_counter_temp > 0) then - intr_counter_temp <= intr_counter_temp -1; - end if; - receive_active_2 <= '1'; - DMNI_Receive <= COPY_TO_MEM; - end if; - - when COPY_TO_MEM => - if (read_enable = '1' and read_av = '1') then - mem_byte_we <= "1111"; - mem_data_write <= bufferr(CONV_INTEGER(first)); - first <= first + 1; - add_buffer <= '0'; - recv_address <= recv_address + WORD_SIZE; - recv_size <= recv_size -1; - if (recv_size = 0) then - DMNI_Receive <= FINISH; - end if ; - else - mem_byte_we <= "0000"; - end if; - - when FINISH => - receive_active_2 <= '0'; - mem_byte_we <= "0000"; - recv_address <= (others=> '0'); - recv_size <= (others=> '0'); - DMNI_Receive <= WAIT_state; - when OTHERS => - end case; - end if; --rising_edge(clock) - end process proc_receive; - - intr_count <= intr_counter_temp; - intr <= '1' when intr_counter_temp > 0 else '0'; - - proc_send : process (clock, reset) - begin - if(reset = '1') then - DMNI_Send <= WAIT_state; - send_active_2 <= '0'; - tx <= '0'; - send_size <= (others=> '0'); - send_size_2 <= (others=> '0'); - send_address <= (others=> '0'); - send_address_2 <= (others=> '0'); - data_out <= (others=> '0'); - elsif (clock'event and clock = '1') then - case( DMNI_Send ) is - when WAIT_state => - if (start = '1' and operation = '0') then - send_address <= address; - send_address_2 <= address_2; - send_size <= size; - send_size_2 <= size_2; - send_active_2 <= '1'; - DMNI_Send <= LOAD; - assert address_router = x"0000" - report "Master sending msg" - severity note; - end if ; - - when LOAD => - if(credit_i = '1' and write_enable = '1') then - send_address <= send_address + WORD_SIZE; - DMNI_Send <= COPY_FROM_MEM; - end if; - - when COPY_FROM_MEM => - if(credit_i = '1' and write_enable = '1') then - if(send_size > 0) then - tx <= '1'; - data_out <= mem_data_read; - send_address <= send_address + WORD_SIZE; - send_size <= send_size -1; - elsif (send_size_2 > 0) then - send_size <= send_size_2; - send_size_2 <= (others=> '0'); - tx <= '0'; - if(send_address_2(30 downto 28) = "000") then - send_address <= send_address_2; - else - send_address <= send_address_2 - WORD_SIZE; - end if; - DMNI_Send <= LOAD; - else - tx <= '0'; - DMNI_Send <= FINISH; - end if; - else - if (credit_i = '0') then - send_size <= send_size + 1; - send_address <= send_address - WORD_SIZE - WORD_SIZE; -- address back 2 positions - else - send_address <= send_address - WORD_SIZE; -- address back 1 position - end if; - tx <= '0'; - DMNI_Send <= LOAD; - end if; - - when FINISH => - send_active_2 <= '0'; - send_address <= (others=> '0'); - send_address_2 <= (others=> '0'); - send_size <= (others=> '0'); - send_size_2 <= (others=> '0'); - DMNI_Send <= WAIT_state; - when OTHERS => - end case ; - end if; --rising_edge(clock) - end process proc_send; -end dmni; diff --git a/hemps8.5/hardware/vhdl/pe/pe.vhd b/hemps8.5/hardware/vhdl/pe/pe.vhd deleted file mode 100644 index 5818de4..0000000 --- a/hemps8.5/hardware/vhdl/pe/pe.vhd +++ /dev/null @@ -1,421 +0,0 @@ ------------------------------------------------------------------------------------------------- --- HeMPS Processing Element ------------------------------------------------------------------------------------------------- -library ieee; -use work.mlite_pack.all; -use work.standards.all; -use work.hemps_pkg.all; -use ieee.std_logic_1164.all; -use ieee.std_logic_misc.all; -use ieee.std_logic_arith.all; -use ieee.std_logic_textio.all; -use ieee.std_logic_unsigned.all; -use ieee.math_real.all; - -use std.textio.all; -library unisim; -use unisim.vcomponents.all; - -entity pe is - generic - ( - log_file : string := "output.txt"; - router_address : regmetadeflit:= (others=>'0'); - kernel_type : kernel_str - ); - port - ( - clock : in std_logic; - reset : in std_logic; - -- NoC - clock_rx : in std_logic_vector(3 downto 0); - rx : in std_logic_vector(3 downto 0); - data_in : in arrayNPORT_1_regflit; - credit_o : out std_logic_vector(3 downto 0); - clock_tx : out std_logic_vector(3 downto 0); - tx : out std_logic_vector(3 downto 0); - data_out : out arrayNPORT_1_regflit; - credit_i : in std_logic_vector(3 downto 0); - -- External Memory - repo_address : out std_logic_vector(29 downto 0); - repo_data_read : in std_logic_vector(31 downto 0); - ack_app : out std_logic; - req_app : in std_logic_vector(31 downto 0) - -- External Debug interface --- write_enable_debug : out std_logic; --- data_out_debug : out std_logic_vector(31 downto 0); --- busy_debug : in std_logic - ); -end entity pe; - -architecture structural of pe is - - type repo_state is (WAIT_state, COPY_FROM_REP); - signal repo_FSM : repo_state; - - signal cpu_mem_address_reg : std_logic_vector(31 downto 0); - signal cpu_mem_data_write_reg : std_logic_vector(31 downto 0); - signal cpu_mem_write_byte_enable_reg : std_logic_vector(3 downto 0); - signal irq_mask_reg : std_logic_vector(7 downto 0); - signal irq_status : std_logic_vector(7 downto 0); - signal irq : std_logic; - signal time_slice : std_logic_vector(31 downto 0); - signal write_enable : std_logic; - signal tick_counter_local : std_logic_vector(31 downto 0); - signal tick_counter : std_logic_vector(31 downto 0); - signal current_page : std_logic_vector(7 downto 0); - signal cpu_mem_address : std_logic_vector(31 downto 0); - signal cpu_mem_data_write : std_logic_vector(31 downto 0); - signal cpu_mem_data_read : std_logic_vector(31 downto 0); - signal cpu_mem_write_byte_enable : std_logic_vector(3 downto 0); - signal cpu_mem_pause : std_logic; - signal cpu_enable_ram : std_logic; - signal cpu_set_size : std_logic; - signal cpu_set_address : std_logic; - signal cpu_set_size_2 : std_logic; - signal cpu_set_address_2 : std_logic; - signal cpu_set_op : std_logic; - signal cpu_start : std_logic; - signal clock_aux : std_logic; - signal clock_hold_s : std_logic; - signal pending_service : std_logic; - - --Router - signal clock_rx_router : regNport; - signal rx_router : regNport; - signal data_in_router : arrayNport_regflit; - signal credit_o_router : regNport; - signal clock_tx_router : regNport; - signal tx_router : regNport; - signal data_out_router : arrayNport_regflit; - signal credit_i_router : regNport; - - signal data_read_ram : std_logic_vector(31 downto 0); - signal mem_data_read : std_logic_vector(31 downto 0); - --signal debug_busy : std_logic; - --signal debug_write_data : std_logic; - --signal debug_write_busy : std_logic; - --signal debug_data_avail : std_logic; - signal ni_intr : std_logic; - signal dmni_mem_address : std_logic_vector(31 downto 0); - signal dmni_mem_write_byte_enable : std_logic_vector(3 downto 0); - signal dmni_mem_data_write : std_logic_vector(31 downto 0); - signal dmni_mem_data_read : std_logic_vector(31 downto 0); - signal dmni_data_read : std_logic_vector(31 downto 0); - signal dmni_enable_internal_ram : std_logic; - signal dmni_send_active_sig : std_logic; - signal dmni_receive_active_sig : std_logic; - signal addr_a : std_logic_vector(31 downto 2); - signal addr_b : std_logic_vector(31 downto 2); - signal cpu_repo_access : std_logic := '0'; - signal data_av : std_logic; - signal end_sim_reg : std_logic_vector(31 downto 0); - signal uart_write_data : std_logic; - - signal slack_update_timer : std_logic_vector(31 downto 0); - -begin - ------------------------------------------------------------------------------------ --- PE COMPONENTS INSTANTIATION ------------------------------------------------------------------------------------ - cpu : entity work.mlite_cpu - port map( - clk => clock_hold_s, - reset_in => reset, - intr_in => irq, - mem_address => cpu_mem_address, - mem_data_w => cpu_mem_data_write, - mem_data_r => cpu_mem_data_read, - mem_byte_we => cpu_mem_write_byte_enable, - mem_pause => cpu_mem_pause, - current_page => current_page - ); - - -master: if kernel_type = "mas" generate - mem : entity work.ram_master - port map( - clk => clock, - enable_a => cpu_enable_ram, - wbe_a => cpu_mem_write_byte_enable, - address_a => addr_a, - data_write_a => cpu_mem_data_write, - data_read_a => data_read_ram, - enable_b => dmni_enable_internal_ram, - wbe_b => dmni_mem_write_byte_enable, - address_b => addr_b, - data_write_b => dmni_mem_data_write, - data_read_b => mem_data_read - ); -end generate; - -slave: if kernel_type = "sla" generate - mem : entity work.ram_slave - port map( - clk => clock, - enable_a => cpu_enable_ram, - wbe_a => cpu_mem_write_byte_enable, - address_a => addr_a, - data_write_a => cpu_mem_data_write, - data_read_a => data_read_ram, - enable_b => dmni_enable_internal_ram, - wbe_b => dmni_mem_write_byte_enable, - address_b => addr_b, - data_write_b => dmni_mem_data_write, - data_read_b => mem_data_read - ); -end generate; - - router : Entity work.RouterCC - generic map(address => router_address) - port map( - clock => clock, - reset => reset, - clock_rx => clock_rx_router, - rx => rx_router, - data_in => data_in_router, - credit_o => credit_o_router, - clock_tx => clock_tx_router, - tx => tx_router, - data_out => data_out_router, - credit_i => credit_i_router - ); - - - dmni : entity work.dmni - generic map( - address_router => router_address - ) - port map( - clock => clock, - reset => reset, - --Configuration interface - set_address => cpu_set_address, - set_address_2 => cpu_set_address_2, - set_size => cpu_set_size, - set_size_2 => cpu_set_size_2, - set_op => cpu_set_op, - start => cpu_start, - config_data => dmni_data_read, - - -- Status outputs - intr => ni_intr, - send_active => dmni_send_active_sig, - receive_active => dmni_receive_active_sig, - - -- Memory interface - mem_address => dmni_mem_address, - mem_data_write => dmni_mem_data_write, - mem_data_read => dmni_mem_data_read, - mem_byte_we => dmni_mem_write_byte_enable, - - --NoC Interface (Local port) - tx => rx_router(LOCAL), - data_out => data_in_router(LOCAL), - credit_i => credit_o_router(LOCAL), - clock_tx => clock_rx_router(LOCAL), - rx => tx_router(LOCAL), - data_in => data_out_router(LOCAL), - credit_o => credit_i_router(LOCAL), - clock_rx => clock_tx_router(LOCAL) - ); - - uart : entity work.UartFile - generic map( - log_file => log_file - ) - port map( - reset => reset, - data_av => uart_write_data, - data_in => cpu_mem_data_write_reg - ); - ------------------------------------------------------------------------------------ --- COMBINATIONAL LOGIC AND WIRING ------------------------------------------------------------------------------------ - - --Router external wiring - clock_rx_router (3 downto 0) <= clock_rx; - rx_router (3 downto 0) <= rx; - credit_i_router (3 downto 0) <= credit_i; - data_in_router (EAST) <= data_in(EAST); - data_in_router (WEST) <= data_in(WEST); - data_in_router (NORTH) <= data_in(NORTH); - data_in_router (SOUTH) <= data_in(SOUTH); - - clock_tx <= clock_tx_router (3 downto 0); - tx <= tx_router (3 downto 0); - credit_o <= credit_o_router (3 downto 0); - data_out(EAST) <= data_out_router (EAST); - data_out(WEST) <= data_out_router (WEST); - data_out(NORTH) <= data_out_router (NORTH); - data_out(SOUTH) <= data_out_router (SOUTH); - - -- UART - uart_write_data <= '1' when cpu_mem_address_reg = DEBUG and write_enable = '1' else '0'; - --debug_busy <= '0'; - --debug_write_busy <= '0'; - --debug_data_avail <= '0'; - - -- CPU data read mux - MUX_CPU : cpu_mem_data_read <= repo_data_read when cpu_mem_address_reg(30 downto 28) = "001" else -- External RAM - ZERO(31 downto 8) & irq_mask_reg when cpu_mem_address_reg = IRQ_MASK else - ZERO(31 downto 8) & irq_status when cpu_mem_address_reg = IRQ_STATUS_ADDR else - time_slice when cpu_mem_address_reg = TIME_SLICE_ADDR else - ZERO(31 downto 16) & router_address when cpu_mem_address_reg = NET_ADDRESS else - tick_counter when cpu_mem_address_reg = TICK_COUNTER_ADDR else - req_app when cpu_mem_address_reg = REQ_APP_REG else - ZERO(31 downto 1) & dmni_send_active_sig when cpu_mem_address_reg = DMNI_SEND_ACTIVE else - ZERO(31 downto 1) & dmni_receive_active_sig when cpu_mem_address_reg = DMNI_RECEIVE_ACTIVE else - data_read_ram; - - --Comb assignments - addr_a(31 downto 28) <= cpu_mem_address(31 downto 28); - addr_a(27 downto PAGE_SIZE_H_INDEX + 1) <= ZERO(27 downto PAGE_SIZE_H_INDEX + 9) & current_page when current_page /= "00000000" and cpu_mem_address(31 downto PAGE_SIZE_H_INDEX + 1) /= ZERO(31 downto PAGE_SIZE_H_INDEX + 1) - else cpu_mem_address(27 downto PAGE_SIZE_H_INDEX + 1); - addr_a(PAGE_SIZE_H_INDEX downto 2) <= cpu_mem_address(PAGE_SIZE_H_INDEX downto 2); - - addr_b <= dmni_mem_address(31 downto 2); - data_av <= '1' when cpu_mem_address_reg = DEBUG and write_enable = '1' else '0'; - --write_enable_debug <= '1' when cpu_mem_address_reg = DEBUG and write_enable = '1' else '0'; - --data_out_debug <= cpu_mem_data_write_reg; - --debug_write_busy <= busy_debug; - --debug_busy <= '1' when cpu_mem_address_reg = DEBUG and write_enable = '1' and busy_debug = '1' else '0'; - --cpu_mem_pause <= cpu_repo_access or debug_busy; - cpu_mem_pause <= cpu_repo_access; - irq <= '1' when (irq_status /= x"00" and irq_mask_reg /= x"00") else '0'; - dmni_data_read <= cpu_mem_data_write_reg; - dmni_mem_data_read <= mem_data_read when dmni_enable_internal_ram = '1' else repo_data_read; - cpu_enable_ram <= '1' when cpu_mem_address(30 downto 28) = "000" else '0'; - dmni_enable_internal_ram <= '1' when dmni_mem_address(30 downto 28) = "000" else '0'; - end_sim_reg <= x"00000000" when cpu_mem_address_reg = END_SIM and write_enable = '1' else x"00000001"; - irq_status(7 downto 4) <= "00" & ni_intr & '0'; - irq_status(3) <= '1' when time_slice = x"00000001" else '0'; - irq_status(2) <= '0'; - irq_status(1) <= '1' when dmni_send_active_sig = '0' and slack_update_timer = SLACK_MONITOR_WINDOW else '0'; - irq_status(0) <= (not dmni_send_active_sig and pending_service); - - cpu_set_size <= '1' when cpu_mem_address_reg = DMNI_SIZE and write_enable = '1' else '0'; - cpu_set_address <= '1' when cpu_mem_address_reg = DMNI_ADDR and write_enable = '1' else '0'; - cpu_set_size_2 <= '1' when cpu_mem_address_reg = DMNI_SIZE_2 and write_enable = '1' else '0'; - cpu_set_address_2 <= '1' when cpu_mem_address_reg = DMNI_ADDR_2 and write_enable = '1' else '0'; - cpu_set_op <= '1' when (cpu_mem_address_reg = DMNI_OP and write_enable = '1') else '0'; - cpu_start <= '1' when (cpu_mem_address_reg = START_DMNI and write_enable = '1') else '0'; - - write_enable <= '1' when cpu_mem_write_byte_enable_reg /= "0000" else '0'; - - ------------------------------------------------------------------------------------ --- SYNCHRONOUS PROCESSES ------------------------------------------------------------------------------------ - - repo_to_mem_access: process(clock,reset) - begin - if reset = '1' then - repo_FSM <= WAIT_state; - cpu_repo_access <= '0'; - elsif rising_edge(clock) then - case( repo_FSM ) is - when WAIT_state => - if(cpu_mem_address(30 downto 28) = "001") then - cpu_repo_access <= '1'; - repo_FSM <= COPY_FROM_REP; - end if; - when COPY_FROM_REP => - repo_FSM <= WAIT_state; - cpu_repo_access <= '0'; - end case ; - end if; - end process repo_to_mem_access; - - - process(cpu_repo_access, dmni_mem_address) - begin - if(cpu_repo_access = '1') then - repo_address <= cpu_mem_address(29 downto 0) ; - elsif dmni_mem_address(30 downto 28) = "001" then - repo_address <= dmni_mem_address(29 downto 0); - end if; - end process; - - sequential_attr: process(clock, reset) - begin - if reset = '1' then - cpu_mem_address_reg <= ZERO; - cpu_mem_data_write_reg <= ZERO; - cpu_mem_write_byte_enable_reg <= ZERO(3 downto 0); - irq_mask_reg <= ZERO(7 downto 0); - time_slice <= ZERO; - tick_counter <= ZERO; - pending_service <= '0'; - ack_app <= '0'; - slack_update_timer <= ZERO; - elsif (clock'event and clock = '1') then - if cpu_mem_pause = '0' then - cpu_mem_address_reg <= cpu_mem_address; - cpu_mem_data_write_reg <= cpu_mem_data_write; - cpu_mem_write_byte_enable_reg <= cpu_mem_write_byte_enable; - - if cpu_mem_address_reg = IRQ_MASK and write_enable = '1' then - irq_mask_reg <= cpu_mem_data_write_reg(7 downto 0); - end if; - -- Decrements the time slice when executing a task (current_page /= x"00") or handling a syscall (syscall = '1') - if time_slice > 1 then - time_slice <= time_slice - 1; - end if; - - if(cpu_mem_address_reg = PENDING_SERVICE_INTR and write_enable = '1') then - if cpu_mem_data_write_reg = ZERO then - pending_service <= '0'; - else - pending_service <= '1'; - end if; - end if; - end if; - - if cpu_mem_address_reg = SLACK_TIME_MONITOR and write_enable = '1' then - slack_update_timer <= cpu_mem_data_write_reg; - elsif slack_update_timer < SLACK_MONITOR_WINDOW then - slack_update_timer <= slack_update_timer + 1; - end if; - - if cpu_mem_address_reg = TIME_SLICE_ADDR and write_enable = '1' then - time_slice <= cpu_mem_data_write_reg; - end if; - - if cpu_mem_address_reg = ACK_APP_REG then - ack_app <= '1'; - elsif req_app(31) = '0' then - ack_app <= '0'; - end if; - - tick_counter <= tick_counter + 1; - end if; - end process sequential_attr; - - clock_stop: process(reset,clock) - begin - if(reset = '1') then - tick_counter_local <= (others=> '0'); - clock_aux <= '1'; - else - if cpu_mem_address_reg = CLOCK_HOLD and write_enable = '1' then - clock_aux <= '0'; - --elsif tx_router(LOCAL) = '1' or ni_intr = '1' or time_slice = x"00000001" then - elsif ni_intr = '1' or time_slice = x"00000001" or irq_status(1) = '1' then - clock_aux <= '1'; - end if; - - if(clock_aux ='1' and clock ='1') then - clock_hold_s <= '1'; - tick_counter_local <= tick_counter_local + 1; - else - clock_hold_s <= '0'; - end if; - end if; - end process clock_stop; - -end architecture structural; - - \ No newline at end of file diff --git a/hemps8.5/hardware/vhdl/pe/processor/plasma/UartFile.vhd b/hemps8.5/hardware/vhdl/pe/processor/plasma/UartFile.vhd deleted file mode 100644 index 6410842..0000000 --- a/hemps8.5/hardware/vhdl/pe/processor/plasma/UartFile.vhd +++ /dev/null @@ -1,110 +0,0 @@ ------------------------------------------------------------------------------------------------- --- --- DISTRIBUTED HEMPS - version 5.0 --- --- Research group: GAPH-PUCRS - contact fernando.moraes@pucrs.br --- --- Distribution: September 2013 --- --- Source name: UartFile.vhd --- --- AUTHOR: Everton Alceu Carara (everton.carara@pucrs.br) --- --- DATE CREATED: 2/12/2009 --- --- Brief description: Writes strings from Echo() and puts() to the log_file. --- ------------------------------------------------------------------------------------------------- - -library ieee; -use ieee.std_logic_1164.all; -use ieee.std_logic_misc.all; -use ieee.std_logic_arith.all; -use ieee.std_logic_textio.all; -use ieee.std_logic_unsigned.all; -use std.textio.all; -use work.mlite_pack.all; - -entity UartFile is - generic(log_file : string := "UNUSED"); - port( - reset : in std_logic; - data_av : in std_logic; - data_in : in std_logic_vector(31 downto 0)); - end; - -architecture logic of UartFile is - -type state is (S0, S1); -signal CS: state; - -begin - - - process(data_av,reset) - file store_file : text open write_mode is log_file; - variable file_line : line; - variable line_type: character; - variable line_length : natural := 0; - variable str: string (1 to 4); - variable str_end: boolean; - begin - if reset = '1' then - str_end := false; - CS <= S0; - - elsif rising_edge(data_av) then - case CS is - when S0 => - -- Reads the incoming string - line_type := character'val(conv_integer(data_in(7 downto 0))); - - -- Verifies if the string is from Echo() - if line_type = '$' then - write(file_line, line_type); - line_length := line_length + 1; - CS <= S1; - - -- Writes the string to the file - else - str(4) := character'val(conv_integer(data_in(7 downto 0))); - str(3) := character'val(conv_integer(data_in(15 downto 8))); - str(2) := character'val(conv_integer(data_in(23 downto 16))); - str(1) := character'val(conv_integer(data_in(31 downto 24))); - - str_end := false; - - for i in 1 to 4 loop - -- Writes a string in the line - if str(i) /= lf and str(i) /= nul and not str_end then - write(file_line, str(i)); - line_length := line_length + 1; - - -- Detects the string end - elsif str(i) = nul then - str_end := true; - - -- Line feed detected. Writes the line in the file - elsif str(i) = lf then - writeline(store_file, file_line); - line_length := 0; - end if; - end loop; - end if; - - -- Receives from plasma the source processor, source task and writes them to the file - when S1 => - write(file_line, ','); - write(file_line, conv_integer(data_in(7 downto 0))); - line_length := line_length + 1; - - if line_length = 3 then - write(file_line, ','); - CS <= S0; - else - CS <= S1; - end if; - end case; - end if; - end process; -end; diff --git a/hemps8.5/hardware/vhdl/standards.vhd b/hemps8.5/hardware/vhdl/standards.vhd deleted file mode 100644 index 8f0b1b7..0000000 --- a/hemps8.5/hardware/vhdl/standards.vhd +++ /dev/null @@ -1,363 +0,0 @@ ------------------------------------------------------------------------------------------------- --- --- DISTRIBUTED HEMPS - version 5.0 --- --- Research group: GAPH-PUCRS - contact fernando.moraes@pucrs.br --- --- Distribution: September 2013 --- --- Source name: standards.vhd --- --- Brief description: Functions and constants for NoC generation. --- ------------------------------------------------------------------------------------------------- - -library IEEE; -use IEEE.Std_Logic_1164.all; -use IEEE.std_logic_unsigned.all; -use IEEE.std_logic_arith.all; -use work.hemps_pkg.all; - -package standards is - --------------------------------------------------------- --- CONSTANTS --------------------------------------------------------- --- Memory map constants. - constant DEBUG : std_logic_vector(31 downto 0) := x"20000000"; - constant IRQ_MASK : std_logic_vector(31 downto 0) := x"20000010"; - constant IRQ_STATUS_ADDR : std_logic_vector(31 downto 0) := x"20000020"; - constant TIME_SLICE_ADDR : std_logic_vector(31 downto 0) := x"20000060"; - constant FIFO_AVAIL : std_logic_vector(31 downto 0) := x"20000040"; - constant END_SIM : std_logic_vector(31 downto 0) := x"20000080"; - constant CLOCK_HOLD : std_logic_vector(31 downto 0) := x"20000090"; - constant NET_ADDRESS : std_logic_vector(31 downto 0) := x"20000140"; - - -- Network interface mapping. - constant NI_STATUS_READ : std_logic_vector(31 downto 0) := x"20000100"; - constant NI_STATUS_SEND : std_logic_vector(31 downto 0) := x"20000110"; - constant NI_READ : std_logic_vector(31 downto 0) := x"20000120"; - constant NI_WRITE : std_logic_vector(31 downto 0) := x"20000130"; - constant NI_CONFIGURATION : std_logic_vector(31 downto 0) := x"20000140"; - constant NI_ACK : std_logic_vector(31 downto 0) := x"20000150"; - constant NI_NACK : std_logic_vector(31 downto 0) := x"20000160"; - constant NI_END : std_logic_vector(31 downto 0) := x"20000170"; - - -- DMNI mapping. - constant DMNI_SIZE : std_logic_vector(31 downto 0) := x"20000200"; - constant DMNI_ADDR : std_logic_vector(31 downto 0) := x"20000210"; - constant DMNI_SIZE_2 : std_logic_vector(31 downto 0) := x"20000204"; - constant DMNI_ADDR_2 : std_logic_vector(31 downto 0) := x"20000214"; - constant DMNI_OP : std_logic_vector(31 downto 0) := x"20000220"; - constant START_DMNI : std_logic_vector(31 downto 0) := x"20000230"; - constant DMNI_ACK : std_logic_vector(31 downto 0) := x"20000240"; - - constant DMNI_SEND_ACTIVE : std_logic_vector(31 downto 0) := x"20000250"; - constant DMNI_RECEIVE_ACTIVE : std_logic_vector(31 downto 0) := x"20000260"; - - constant SCHEDULING_REPORT : std_logic_vector(31 downto 0) := x"20000270"; - - constant TICK_COUNTER_ADDR : std_logic_vector(31 downto 0) := x"20000300"; - constant REQ_APP_REG : std_logic_vector(31 downto 0) := x"20000350"; - constant ACK_APP_REG : std_logic_vector(31 downto 0) := x"20000360"; - - constant PENDING_SERVICE_INTR : std_logic_vector(31 downto 0) := x"20000400"; - - - constant SLACK_TIME_MONITOR : std_logic_vector(31 downto 0) := x"20000370"; - constant SLACK_MONITOR_WINDOW : integer := 50000; --------------------------------------------------------------------------------- --- Router position constants - FIXED - it is not a function of the NoC size --------------------------------------------------------------------------------- - constant BL: integer := 0; - constant BC: integer := 1; - constant BR: integer := 2; - constant CL: integer := 3; - constant CC: integer := 4; - constant CRX: integer := 5; - constant TL: integer := 6; - constant TC: integer := 7; - constant TR: integer := 8; - ---------------------------------------------------------- --- CONSTANTS INDEPENDENTES ---------------------------------------------------------- - constant NPORT: integer := 5; - - constant EAST: integer := 0; - constant WEST: integer := 1; - constant NORTH : integer := 2; - constant SOUTH : integer := 3; - constant LOCAL : integer := 4; - ---------------------------------------------------------- --- CONSTANT DEPENDENTE DA LARGURA DE BANDA DA REDE - FIXED FOR HEMPS ---------------------------------------------------------- - constant TAM_FLIT : integer range 1 to 64 := 32; - constant METADEFLIT : integer range 1 to 32 := (TAM_FLIT/2); - constant QUARTOFLIT : integer range 1 to 16 := (TAM_FLIT/4); - ---------------------------------------------------------- --- CONSTANTS DEPENDENTES DA PROFUNDIDADE DA FILA ---------------------------------------------------------- - constant TAM_BUFFER: integer := 16; - constant TAM_BUFFER_DMNI: integer := 16; - constant TAM_POINTER : integer range 1 to 32 := 4; - ---------------------------------------------------------- --- CONSTANTS DEPENDENTES DO NUMERO DE ROTEADORES ---------------------------------------------------------- - constant NROT: integer := NUMBER_PROCESSORS; - - constant MIN_X : integer := 0; - constant MIN_Y : integer := 0; - constant MAX_X : integer := NUMBER_PROCESSORS_X-1; - constant MAX_Y : integer := NUMBER_PROCESSORS_Y-1; - ---------------------------------------------------------- --- CONSTANT TB ---------------------------------------------------------- - constant TAM_LINHA : integer := 2; --4; - ---------------------------------------------------------- --- SUBTIPOS, TIPOS E FUNCOES ---------------------------------------------------------- - - subtype reg3 is std_logic_vector(2 downto 0); - subtype reg8 is std_logic_vector(7 downto 0); - subtype reg30 is std_logic_vector(29 downto 0); - subtype reg32 is std_logic_vector(31 downto 0); - subtype regNrot is std_logic_vector((NROT-1) downto 0); - subtype regNport is std_logic_vector((NPORT-1) downto 0); - subtype regflit is std_logic_vector((TAM_FLIT-1) downto 0); - subtype regmetadeflit is std_logic_vector((METADEFLIT-1) downto 0); - subtype regquartoflit is std_logic_vector((QUARTOFLIT-1) downto 0); - subtype pointer is std_logic_vector((TAM_POINTER-1) downto 0); - subtype regNPe is std_logic_vector((NUMBER_PROCESSORS - 1) downto 0); - - type buff is array(0 to TAM_BUFFER-1) of regflit; - type buff_dmni is array(0 to TAM_BUFFER_DMNI-1) of regflit; - - - type arrayNport_reg3 is array((NPORT-1) downto 0) of reg3; - type arrayNport_reg8 is array((NPORT-1) downto 0) of reg8; - type arrayNport_regflit is array((NPORT-1) downto 0) of regflit; - type arrayNrot_reg3 is array((NROT-1) downto 0) of reg3; - type arrayNrot_regflit is array((NROT-1) downto 0) of regflit; - type arrayNrot_regmetadeflit is array((NROT-1) downto 0) of regmetadeflit; - type arrayNPe_reg32 is array((NUMBER_PROCESSORS -1) downto 0) of reg32; - type arrayNPe_reg30 is array((NUMBER_PROCESSORS -1) downto 0) of reg30; - - -- number of ports of the processing_element - 4 - north/south/west/east - type arrayNPORT_1_regflit is array(3 downto 0) of regflit; - ---------------------------------------------------------- --- HERMES FUCTIONS ---------------------------------------------------------- - Function CONV_VECTOR( int: integer ) return std_logic_vector; - function CONV_VECTOR( letra : string(1 to TAM_LINHA); pos: integer ) return std_logic_vector; - function CONV_HEX( int : integer ) return string; - function CONV_STRING_4BITS( dado : std_logic_vector(3 downto 0)) return string; - function CONV_STRING_8BITS( dado : std_logic_vector(7 downto 0)) return string; - function CONV_STRING_16BITS( dado : std_logic_vector(15 downto 0)) return string; - function CONV_STRING_32BITS( dado : std_logic_vector(31 downto 0)) return string; - ---------------------------------------------------------- --- HEMPS FUCTIONS ---------------------------------------------------------- - function RouterPosition(router: integer) return integer; - function RouterAddress(router: integer) return std_logic_vector; - function log_filename(i: integer) return string; - -end standards; - -package body standards is - -- - -- converte um inteiro em um std_logic_vector(2 downto 0) - -- - function CONV_VECTOR( int: integer ) return std_logic_vector is - variable bin: reg3; - begin - case(int) is - when 0 => bin := "000"; - when 1 => bin := "001"; - when 2 => bin := "010"; - when 3 => bin := "011"; - when 4 => bin := "100"; - when 5 => bin := "101"; - when 6 => bin := "110"; - when 7 => bin := "111"; - when others => bin := "000"; - end case; - return bin; - end CONV_VECTOR; - --------------------------------------------------------- - -- FUNCOES TB - --------------------------------------------------------- - -- - -- converte um caracter de uma dada linha em um std_logic_vector - -- - function CONV_VECTOR( letra:string(1 to TAM_LINHA);pos: integer ) return std_logic_vector is - variable bin: std_logic_vector(3 downto 0); - begin - case (letra(pos)) is - when '0' => bin := "0000"; - when '1' => bin := "0001"; - when '2' => bin := "0010"; - when '3' => bin := "0011"; - when '4' => bin := "0100"; - when '5' => bin := "0101"; - when '6' => bin := "0110"; - when '7' => bin := "0111"; - when '8' => bin := "1000"; - when '9' => bin := "1001"; - when 'A' => bin := "1010"; - when 'B' => bin := "1011"; - when 'C' => bin := "1100"; - when 'D' => bin := "1101"; - when 'E' => bin := "1110"; - when 'F' => bin := "1111"; - when others =>bin := "0000"; - end case; - return bin; - end CONV_VECTOR; - --- converte um inteiro em um string - function CONV_HEX( int: integer ) return string is - variable str: string(1 to 1); - begin - case(int) is - when 0 => str := "0"; - when 1 => str := "1"; - when 2 => str := "2"; - when 3 => str := "3"; - when 4 => str := "4"; - when 5 => str := "5"; - when 6 => str := "6"; - when 7 => str := "7"; - when 8 => str := "8"; - when 9 => str := "9"; - when 10 => str := "A"; - when 11 => str := "B"; - when 12 => str := "C"; - when 13 => str := "D"; - when 14 => str := "E"; - when 15 => str := "F"; - when others =>str := "U"; - end case; - return str; - end CONV_HEX; - - function CONV_STRING_4BITS(dado : std_logic_vector(3 downto 0)) return string is - variable str: string(1 to 1); - begin - str := CONV_HEX(CONV_INTEGER(dado)); - return str; - end CONV_STRING_4BITS; - - function CONV_STRING_8BITS(dado : std_logic_vector(7 downto 0)) return string is - variable str1,str2: string(1 to 1); - variable str: string(1 to 2); - begin - str1 := CONV_STRING_4BITS(dado(7 downto 4)); - str2 := CONV_STRING_4BITS(dado(3 downto 0)); - str := str1 & str2; - return str; - end CONV_STRING_8BITS; - - function CONV_STRING_16BITS(dado : std_logic_vector(15 downto 0)) return string is - variable str1,str2: string(1 to 2); - variable str: string(1 to 4); - begin - str1 := CONV_STRING_8BITS(dado(15 downto 8)); - str2 := CONV_STRING_8BITS(dado(7 downto 0)); - str := str1 & str2; - return str; - end CONV_STRING_16BITS; - - function CONV_STRING_32BITS(dado : std_logic_vector(31 downto 0)) return string is - variable str1,str2: string(1 to 4); - variable str: string(1 to 8); - begin - str1 := CONV_STRING_16BITS(dado(31 downto 16)); - str2 := CONV_STRING_16BITS(dado(15 downto 0)); - str := str1 & str2; - return str; - end CONV_STRING_32BITS; - - -- Returns the router position in the mesh - -- BR: Botton Right - -- BL: Botton Left - -- TR: Top Right - -- TL: Top Left - -- CRX: Center Right - -- CL: Center Left - -- CC: Center - -- 4x4 positions exemple - -- TL TC TC TR - -- CL CC CC CRX - -- CL CC CC CRX - -- BL BC BC BR - function RouterPosition(router: integer) return integer is - variable pos: integer range 0 to TR; - variable line, column: integer; - begin - - --line := router/NUMBER_PROCESSORS_Y; - column := router mod NUMBER_PROCESSORS_X; - - if router >= NUMBER_PROCESSORS-NUMBER_PROCESSORS_X then --TOP - if column = NUMBER_PROCESSORS_X-1 then --RIGHT - pos := TR; - elsif column = 0 then--LEFT - pos := TL; - else--CENTER_X - pos := TC; - end if; - elsif router < NUMBER_PROCESSORS_X then --BOTTOM - if column = NUMBER_PROCESSORS_X-1 then --RIGHT - pos := BR; - elsif column = 0 then--LEFT - pos := BL; - else--CENTER_X - pos := BC; - end if; - else --CENTER_Y - if column = NUMBER_PROCESSORS_X-1 then --RIGHT - pos := CRX; - elsif column = 0 then--LEFT - pos := CL; - else--CENTER_X - pos := CC; - end if; - end if; - - return pos; - - end RouterPosition; - - function RouterAddress(router: integer) return std_logic_vector is - variable pos_x, pos_y : regquartoflit; - variable addr : regmetadeflit; - variable aux : integer; - begin - aux := (router/NUMBER_PROCESSORS_X); - pos_x := conv_std_logic_vector((router mod NUMBER_PROCESSORS_X),QUARTOFLIT); - pos_y := conv_std_logic_vector(aux,QUARTOFLIT); - - addr := pos_x & pos_y; - return addr; - end RouterAddress; - - function log_filename(i: integer) return string is - variable filename : string(1 to 14); - variable aux_x : integer; - variable aux_y : integer; - begin - aux_x := (i mod NUMBER_PROCESSORS_X); - aux_y := (i/NUMBER_PROCESSORS_X); - filename := "log/log" & CONV_HEX(aux_x) & "x" & CONV_HEX(aux_y) & ".txt"; - return filename; - end log_filename; - -end standards; diff --git a/hemps8.5/hardware/vhdl/test_bench.vhd b/hemps8.5/hardware/vhdl/test_bench.vhd deleted file mode 100644 index bc4dfae..0000000 --- a/hemps8.5/hardware/vhdl/test_bench.vhd +++ /dev/null @@ -1,284 +0,0 @@ ------------------------------------------------------------------------------------------------- --- --- DISTRIBUTED HEMPS - version 5.0 --- --- Research group: GAPH-PUCRS - contact fernando.moraes@pucrs.br --- --- Distribution: September 2013 --- --- Source name: test_bench.vhd --- --- Brief description: Test bench. --- ------------------------------------------------------------------------------------------------- - -library IEEE; -use ieee.std_logic_1164.all; -use ieee.std_logic_arith.all; -use ieee.std_logic_unsigned.all; -use ieee.std_logic_textio.all; -use std.textio.all; -use work.hemps_pkg.all; -use work.standards.all; - ---! @file ---! @ingroup vhdl_group ---! @{ ---! @} - ---! @brief entity brief description - ---! @detailed detailed description -entity test_bench is - - --constant log_file : string := "output_master.txt"; --! port description - constant mlite_description : string := "RTL"; - constant ram_description : string := "RTL"; - constant router_description : string := "RTL"; - - constant REPO_SIZE: integer := (TOTAL_REPO_SIZE_BYTES/4); --This math is because each repoline is 32 bits word - constant APPSTART_SIZE: integer := (APP_NUMBER*2)+1; --THis math is because the appstart file have two values per app plus one end of file mark - type repo_type is array(REPO_SIZE-1 downto 0) of std_logic_vector(31 downto 0); - type appstart_type is array(APPSTART_SIZE-1 downto 0) of std_logic_vector(31 downto 0); - - - impure function load_repo (repo_file : in string) return repo_type is - - file file_ptr : text open read_mode is repo_file; - variable inline : line; - variable i : integer := 0; - - variable mem : repo_type := (others => (others => '0')); - - begin - - while not endfile(file_ptr) loop - - if (i = REPO_SIZE) then - assert false report "ERROR: reposiotory access overflow - i= " & integer'image(i) - severity error; - end if; - - readline(file_ptr, inline); - hread(inline, mem(i)); - i := i + 1; - - end loop; - - file_close(file_ptr); - - return mem; - - end load_repo; - - - impure function load_appstart (appstart_file : in string) return appstart_type is - - file file_ptr2 : text open read_mode is appstart_file; - variable inline : line; - variable i : integer := 0; - - variable mem : appstart_type := (others => (others => '0')); - - begin - - while not endfile(file_ptr2) loop - - if (i = REPO_SIZE) then - assert false report "ERROR: appstart access overflow - i= " & integer'image(i) - severity error; - end if; - - readline(file_ptr2, inline); - hread(inline, mem(i)); - i := i + 1; - - end loop; - - file_close(file_ptr2); - - return mem; - - end load_appstart; - - -end; - -architecture test_bench of test_bench is - - - signal clock : std_logic := '0'; - signal clock_200 : std_logic := '1'; - signal reset : std_logic; --- signal control_write_enable_debug : std_logic; --- signal control_data_out_debug : std_logic_vector(31 downto 0); --- signal control_busy_debug : std_logic; - signal control_hemps_addr : std_logic_vector(29 downto 0); - signal control_hemps_data : std_logic_vector(31 downto 0); - - type state is (LER, WAIT_DDR, WR_HEMPS, START); - signal EA : state; - type state2 is (S0, S1); - - signal CS : state2; - signal counter : integer := 0; - signal ack_app : std_logic; - signal req_app : std_logic_vector(31 downto 0); - - constant repository : repo_type := load_repo("repository.txt"); - constant appstart : appstart_type := load_appstart("appstart.txt"); - - - signal current_time : integer := 0; - signal app_i : integer := 0; - -begin - - -- - -- HeMPS instantiation - -- - HeMPS : entity work.HeMPS - generic map( - mlite_description => mlite_description, - ram_description => ram_description, - router_description => router_description - ) - port map( - clock => clock, - reset => reset, - --repository - repo_address => control_hemps_addr, - repo_data => control_hemps_data, - ack_app => ack_app, - req_app => req_app - --debug - -- write_enable_debug => control_write_enable_debug, - -- data_out_debug => control_data_out_debug, - -- busy_debug => control_busy_debug, - - ); - - - - reset <= '1', '0' after 100 ns; - -- 100 MHz - clock <= not clock after 5 ns; - -- 200 MHz - clock_200 <= not clock_200 after 1.25 ns; - - --Repository data assignment - control_hemps_data <= repository(CONV_INTEGER(control_hemps_addr(23 downto 0)) / 4); - --- App request control - - process (clock, reset) - variable app_repo_address : integer := 0; - variable app_start_time_ms : integer := 0; - begin - - if reset = '1' then - - req_app <= (others => '0'); - app_i <= 0; - current_time <= 0; - - elsif rising_edge(clock) then - - current_time <= current_time + 1; - - if req_app = x"00000000" then - - if appstart(app_i) /= x"deadc0de" then - - app_repo_address := conv_integer(appstart(app_i)); - app_start_time_ms := conv_integer(appstart(app_i+1)); - - if (app_start_time_ms * 100000) <= current_time then - - req_app <= CONV_STD_LOGIC_VECTOR(app_repo_address, 32) or x"80000000"; - - assert false report "Repository requesting app "& integer'image(app_i/2) - severity note; - - app_i <= app_i+2; - - end if; - end if; - elsif ack_app = '1' then - req_app <= (others => '0'); - end if; - - end if; - - end process; - - -- - -- creates the output file. This code was not removed because it can be useful in a protipation. In fact, all debug traces all only commented in testbench, hemps, pe - -- --- process(control_write_enable_debug,reset) --- file store_file : text open write_mode is log_file; --- variable file_line : line; --- variable line_type: character; --- variable line_length : natural := 0; --- variable str: string (1 to 4); --- variable str_end: boolean; --- begin --- if reset = '1' then --- str_end := false; --- CS <= S0; --- elsif rising_edge(control_write_enable_debug) then --- case CS is --- when S0 => --- -- Reads the incoming string --- line_type := character'val(conv_integer(control_data_out_debug(7 downto 0))); --- --- -- Verifies if the string is from Echo() --- if line_type = '$' then --- write(file_line, line_type); --- line_length := line_length + 1; --- CS <= S1; --- --- -- Writes the string to the file --- else --- str(4) := character'val(conv_integer(control_data_out_debug(7 downto 0))); --- str(3) := character'val(conv_integer(control_data_out_debug(15 downto 8))); --- str(2) := character'val(conv_integer(control_data_out_debug(23 downto 16))); --- str(1) := character'val(conv_integer(control_data_out_debug(31 downto 24))); --- --- str_end := false; --- --- for i in 1 to 4 loop --- -- Writes a string in the line --- if str(i) /= lf and str(i) /= nul and not str_end then --- write(file_line, str(i)); --- line_length := line_length + 1; --- --- -- Detects the string end --- elsif str(i) = nul then --- str_end := true; --- --- -- Line feed detected. Writes the line in the file --- elsif str(i) = lf then --- writeline(store_file, file_line); --- line_length := 0; --- end if; --- end loop; --- end if; --- --- -- Receives from plasma the source processor, source task and writes them to the file --- when S1 => --- write(file_line, ','); --- write(file_line, conv_integer(control_data_out_debug(7 downto 0))); --- line_length := line_length + 1; --- --- if line_length = 3 then --- write(file_line, ','); --- CS <= S0; --- else --- CS <= S1; --- end if; --- end case; --- end if; --- end process; - -end test_bench; \ No newline at end of file diff --git a/hemps8.5/software/boot_task/boot_task.asm b/hemps8.5/software/boot_task/boot_task.asm deleted file mode 100644 index 5550bee..0000000 --- a/hemps8.5/software/boot_task/boot_task.asm +++ /dev/null @@ -1,50 +0,0 @@ -## HEMPS VERSION - 8.0 - support for RT applications -## -## Distribution: June 2016 -## -## Created by: Marcelo Ruaro - contact: marcelo.ruaro@acad.pucrs.br -## -## Research group: GAPH-PUCRS - contact: fernando.moraes@pucrs.br -## -## Brief description: Initializes the stack pointer and jumps to main(). Handles the syscall. - - - - .text - .align 2 - .globl entry - .ent entry -entry: - .set noreorder - - li $sp,sp_addr # new initialization - - jal main - nop - - move $4,$0 - syscall - nop - -$L1: - j $L1 - nop - - .end entry - -################################################### - - .globl SystemCall - .ent SystemCall -SystemCall: - .set noreorder - - syscall - nop - jr $31 - nop - - .set reorder - .end SystemCall - - diff --git a/load_env b/load_env new file mode 100644 index 0000000..d59263a --- /dev/null +++ b/load_env @@ -0,0 +1,4 @@ +module load systemc mips-elf/4.1.1-hemps questa + +export HEMPS_PATH=$(pwd) +export PATH=${PATH}:${HEMPS_PATH}/build_env/bin diff --git a/software/bareOS/comm.c b/software/bareOS/comm.c new file mode 100644 index 0000000..dc0eada --- /dev/null +++ b/software/bareOS/comm.c @@ -0,0 +1,113 @@ +#include "include/libos.h" + +static void *send_buff = NULL; + +void transmit(flit_t target, flit_t service, + void *msg, size_t msg_len) { + static const flit_t zero = 0; + static mac_header_t p; + size_t flit_len, len; + + // Waiting untill last transmission has finished + while (MemoryRead32(DMNI_SEND_ACTIVE)); + + len = align_type(msg_len, flit_t); + flit_len = len/sizeof(flit_t); + + p.target = target; + p.service = service; + p.length = (flit_len ? flit_len : 1); + p.length += mem_offset(p, p.length)/sizeof(flit_t); + + // Configure DMNI for package header transmission + MemoryWrite32(DMNI_SIZE, MAC_HEADER_LEN); + MemoryWrite32(DMNI_ADDRESS, (size_t)(&p)); + + // Configure DMNI for package payload transmission + if(flit_len) { + free(send_buff); + + if(!(send_buff = malloc(len))) + panic("Cannot allocate memory for transmit buffer.\n"); + + memcpy(send_buff, msg, msg_len); + if(len - msg_len) + memset(send_buff+msg_len, 0, len-msg_len); + + MemoryWrite32(DMNI_SIZE_2, flit_len); + MemoryWrite32(DMNI_ADDRESS_2, (size_t)send_buff); + } else { + MemoryWrite32(DMNI_SIZE_2, 1); + MemoryWrite32(DMNI_ADDRESS_2, (size_t)(&zero)); + } + + MemoryWrite32(DMNI_OP, READ); + MemoryWrite32(DMNI_START, 1); +} + +void *prepare_receive(void *buff) { + buff = (void*)align((size_t)buff, 2); + MemoryWrite32(DMNI_RECEIVE_BUFFER, (size_t)buff); + return buff; +} + +void *wait_receive(){ + size_t ret; + while(!((ret = MemoryRead32(DMNI_RECEIVE_BUFFER)) & 1)); + return (void*)(ret & -4); +} + +void send_msg(flit_t target, void *msg, size_t len) { + msg_req_t msg_req, ack_reply; + void *old_buff; + size_t received_len; + + msg_req.addr = MemoryRead32(NET_ADDRESS); + msg_req.size = align_type(len, flit_t)/sizeof(flit_t); + + /* waits previous operation to finish + * this avoids overwriting previous buffer pointer */ + old_buff = wait_receive(); + + transmit(target, REQ_OPERATION, &msg_req, sizeof(msg_req_t)); + prepare_receive(&ack_reply); + wait_receive(); + + // restauring previous buffer + MemoryWrite32(DMNI_RECEIVE_BUFFER, (size_t)old_buff | 1); + + if((ack_reply.addr != msg_req.addr)) + panic("Received ACK diverges from expected\n"); + + received_len = ack_reply.size*sizeof(flit_t); + len = min(received_len, len); + transmit(target, DMA_OPERATION, msg, len); +} + +typedef union { + uint32_t i32; + msg_req_t s; +} msg_req_u; + +void *prepare_recv_msg(flit_t *src, size_t *size) { + static msg_req_u req; + void *buff; + + while(!(req.i32 = MemoryRead32(DMNI_REQ_FIFO))); + MemoryWrite32(DMNI_REQ_FIFO, 0); + + if(!(buff = malloc(req.s.size << 2))) + return NULL; + + if(src) *src = req.s.addr; + if(size) *size = req.s.size << 2; + + transmit(req.s.addr, DMA_OPERATION, &req, sizeof(msg_req_t)); + + return prepare_receive(buff); +} + +void *receive_msg(flit_t *src, size_t *size) { + prepare_recv_msg(src, size); + return wait_receive(); +} diff --git a/software/bareOS/crt0.s b/software/bareOS/crt0.s new file mode 100644 index 0000000..26088d4 --- /dev/null +++ b/software/bareOS/crt0.s @@ -0,0 +1,24 @@ + .section .text.init + .global _entry + .ent _entry + .set noreorder +_entry: + la $sp, _stack + addiu $sp, $sp, 3 + li $2, -4 + and $sp, $sp, $2 + la $gp, _gp + la $4, _bss_start + la $5, _bss_end +.clr_bss: + beq $4, $5, .clr_bss_done + addiu $4, $4, 4 + beq $0, $0, .clr_bss + sw $0, -4($4) +.clr_bss_done: + jal main + nop + j exit + or $4, $2, $0 + .set reorder + .end _entry diff --git a/software/bareOS/hal.c b/software/bareOS/hal.c new file mode 100644 index 0000000..775f048 --- /dev/null +++ b/software/bareOS/hal.c @@ -0,0 +1,31 @@ +#include "include/libos.h" + +typedef struct { + flit_t source; + flit_t retcode; +} exit_msg_t; + +void exit(int code) { + exit_msg_t msg; + + msg.source = MemoryRead32(NET_ADDRESS); + msg.retcode = code; + + transmit(MemoryRead32(LOADER_NETADDR), EXIT_OPERATION, &msg, sizeof(exit_msg_t)); + + for(;;) MemoryWrite32(CPU_KILL, CPU_KILL_MAGIC); +} + +void putchar(char c) { + MemoryWrite32(UART_WRITE, (uint32_t)c<<24); +} + +void puts(const char *string) { + int *str_part; + //This is the most crazy and complicated FOR declaration that I ever seen. For obviously purposes, I divided the FOR section in lines + //PS: This indicates a hardware developer putting its hands on software development + //PS2: The original author need to review demorgans law for boolean simplification + for(str_part = (int*)string, MemoryWrite32(UART_WRITE, *str_part); + ((char*)str_part)[0] && ((char*)str_part)[1] && ((char*)str_part)[2] && ((char*)str_part)[3]; + MemoryWrite32(UART_WRITE, *(++str_part))); +} diff --git a/software/bareOS/hemps.ld b/software/bareOS/hemps.ld new file mode 100644 index 0000000..88eeb13 --- /dev/null +++ b/software/bareOS/hemps.ld @@ -0,0 +1,38 @@ +ENTRY(_entry) + +SECTIONS { + . = 0; + + .text : { + _text = .; + *(.text.init) + *(.text) + *(.text.*) + _etext = .; + } + + .data : { + _rodata = .; + *(.rdata) + *(.rodata) + *(.rodata.*) + _erodata = .; + _data = .; + *(.data) + *(.data.*) + _gp = . + 0x800; + *(.sdata) + *(.sdata.*) + . = ALIGN(16); + _edata = .; + _bss_start = .; + *(.sbss) + *(.sbss.*) + *(.bss) + *(.bss.*) + . = ALIGN(4); + _bss_end = . ; + } + _end = .; +} + diff --git a/software/bareOS/include/comm.h b/software/bareOS/include/comm.h new file mode 100644 index 0000000..3f32201 --- /dev/null +++ b/software/bareOS/include/comm.h @@ -0,0 +1,45 @@ +#ifndef _COMM_H +#define _COMM_H + +#include "prototypes.h" +//#include + +/* Manual Routing destination ports */ +#define MANUAL_EAST 0x80000000 +#define MANUAL_WEST 0xA0000000 +#define MANUAL_NORTH 0xC0000000 +#define MANUAL_SOUTH 0xE0000000 + +#define ROUTER_ADDR(x, y) (((x<<8)|y)&0xFFFF) +#define MAC_HEADER_LEN (sizeof(mac_header_t)/sizeof(flit_t)) + +#define EXIT_OPERATION 0x70 +#define DMA_OPERATION 0x290 +#define REQ_OPERATION 0x480 + +typedef uint32_t flit_t; + +typedef struct { + flit_t target; + flit_t length; + flit_t service; + flit_t payload[]; +} mac_header_t; + +typedef struct { + uint16_t addr; + uint16_t size; +} msg_req_t; + +void transmit(flit_t target, flit_t service, + void *msg, size_t len); + +void *prepare_receive(void *buff); +void *wait_receive(); + +void send_msg(flit_t target, void *msg, size_t len); +void *prepare_recv_msg(flit_t *src, size_t *size); + +void *receive_msg(flit_t *src, size_t *size); + +#endif /* !_COMM_H */ diff --git a/software/bareOS/include/hal.h b/software/bareOS/include/hal.h new file mode 100644 index 0000000..7b322ee --- /dev/null +++ b/software/bareOS/include/hal.h @@ -0,0 +1,111 @@ +#ifndef _HAL_H +#define _HAL_H + +#include "prototypes.h" + +/* Paramenters used by malloc */ +//pointer to the end of static program memory +extern uint8_t _end; +//assumes _stack points to the end of the memory +extern uint8_t _stack; +#define MALLOC_ALIGNMENT 4 + +#define HEAP_START ((void*)&_end) +#define HEAP_END ((void*)((&_stack)-1024)) // stack - 1kB +#define HEAP_ALLOCATION_GRAIN 10 //1kB + +/*********** Hardware addresses ***********/ +#define UART_WRITE 0x20000000 +#define UART_READ 0x20000000 +#define IRQ_MASK 0x20000010 +#define IRQ_STATUS 0x20000020 +#define TIME_SLICE 0x20000060 +#define SYS_CALL 0x20000070 +#define END_SIM 0x20000080 +#define CLOCK_HOLD 0x20000090 + +/* Network Interface*/ +#define NI_STATUS_RECV 0x20000100 +#define NI_STATUS_SEND 0x20000110 +#define NI_RECV 0x20000120 +#define NI_SEND 0x20000130 +#define NI_CONFIG 0x20000140 +#define NI_ACK 0x20000150 +#define NI_NACK 0x20000160 +#define NI_END 0x20000170 +#define CURRENT_PAGE 0x20000180 +#define NEXT_PAGE 0x20000190 + +/* Network information */ +#define NET_ADDRESS 0x20000140 +#define LOADER_NETADDR 0x20000144 + +/* Task termination */ +#define CPU_KILL 0x20000320 +#define CPU_KILL_MAGIC 0xDEADBEEF + +/* DMNI */ +#define DMNI_SIZE_2 0x20000204 +#define DMNI_ADDRESS_2 0x20000214 +#define DMNI_SIZE 0x20000200 +#define DMNI_ADDRESS 0x20000210 +#define DMNI_OP 0x20000220 +#define DMNI_START 0x20000230 +#define DMNI_ACK 0x20000240 +#define DMNI_SEND_ACTIVE 0x20000250 +#define DMNI_RECEIVE_ACTIVE 0x20000260 +#define DMNI_RECEIVE_BUFFER 0x20000264 +#define DMNI_REQ_FIFO 0x20000268 + +//Scheduling report +#define SCHEDULING_REPORT 0x20000270 +#define INTERRUPTION 0x10000 +//#define SYSCALL 0x20000 +#define SCHEDULER 0x40000 +#define IDLE 0x80000 + +//Communication graphical debbug +#define ADD_PIPE_DEBUG 0x20000280 +#define REM_PIPE_DEBUG 0x20000285 +#define ADD_REQUEST_DEBUG 0x20000290 +#define REM_REQUEST_DEBUG 0x20000295 + +/* DMNI operations */ +#define READ 0 +#define WRITE 1 + +#define TICK_COUNTER 0x20000300 +#define CURRENT_TASK 0x20000400 + +#define REQ_APP 0x20000350 +#define ACK_APP 0x20000360 + +#define SLACK_TIME_MONITOR 0x20000370 + +//Kernel pending service FIFO +#define PENDING_SERVICE_INTR 0x20000400 + +#define SLACK_TIME_WINDOW 50000 // half milisecond + +/*********** Interrupt bits **************/ +#define IRQ_PENDING_SERVICE 0x01 //bit 0 +#define IRQ_SLACK_TIME 0x02 //bit 1 +#define IRQ_SCHEDULER 0x08 //bit 3 +#define IRQ_NOC 0x20 //bit 5 + +/*Memory Access*/ +#define MemoryRead32(A) (*(volatile uint32_t*)(A)) +#define MemoryWrite32(A,V) *(volatile uint32_t*)(A)=(V) +#define MemoryRead16(A) (*(volatile uint16_t*)(A)) +#define MemoryWrite16(A,V) *(volatile uint16_t*)(A)=(V) +#define MemoryRead8(A) (*(volatile uint8_t*)(A)) +#define MemoryWrite8(A,V) *(volatile uint8_t*)(A)=(V) + +// Stubs, need implementation if running on sharedmemory platforms +static inline int __attribute__((unused)) enter_critical () { return 0; } + +static inline void __attribute__((unused)) +leave_critical(int __attribute__((unused)) i) {} + + +#endif diff --git a/software/bareOS/include/libos.h b/software/bareOS/include/libos.h new file mode 100644 index 0000000..4487523 --- /dev/null +++ b/software/bareOS/include/libos.h @@ -0,0 +1,57 @@ +#ifndef _LIBOS_H +#define _LIBOS_H + +#include "hal.h" +#include "comm.h" + +#define isprint(c) (' '<=(c)&&(c)<='~') +#define isspace(c) ((c)==' '||(c)=='\t'||(c)=='\n'||(c)=='\r') +#define isdigit(c) ('0'<=(c)&&(c)<='9') +#define islower(c) ('a'<=(c)&&(c)<='z') +#define isupper(c) ('A'<=(c)&&(c)<='Z') +#define isalpha(c) (islower(c)||isupper(c)) +#define isalnum(c) (isalpha(c)||isdigit(c)) +#define min(a,b) ((a)<(b)?(a):(b)) +#define max(a,b) ((a)>(b)?(a):(b)) +#define ntohs(A) (((A)>>8) | (((A)&0xff)<<8)) +#define ntohl(A) (((A)>>24) | (((A)&0xff0000)>>8) | (((A)&0xff00)<<8) | ((A)<<24)) + +#define va_start(ap, argN) __builtin_va_start(ap, argN) +#define va_arg(ap, type) __builtin_va_arg(ap, type) +#define va_end(ap) __builtin_va_end(ap) +#define va_copy(dst, src) __builtin_va_copy(dst, src) + +#define new(type) calloc(1, sizeof(type)) +#define align_type(x, type) (((x)+sizeof(type)-1) & -sizeof(type)) +#define align(x, bits) (((x)+(1<>= 1); + + if(b == 1) { + b = (1 << shift)-1; + do { + *q++ = '0' + (i & b); + } while(i >>= shift); + } else + do { + *q++ = '0' + (i % base); + } while (i /= base); + + for (*q = 0; p <= --q; p++){ + (*p > '9')?(c = *p + 39):(c = *p); + (*q > '9')?(*p = *q + 39):(*p = *q); + *q = c; + } + + return s; +} + +char *itoa(int i, char *s, int base){ + char c; + char *p = s; + char *q = s; + + if (i >= 0) + return utoa(i, s, base); + + *q++ = '-'; + p++; + do{ + *q++ = '0' - (i % base); + } while (i /= base); + + for (*q = 0; p <= --q; p++){ + (*p > '9')?(c = *p + 39):(c = *p); + (*q > '9')?(*p = *q + 39):(*p = *q); + *q = c; + } + + return s; +} + +union ptr { + const void *v; + uint8_t *uint8; + uint16_t *uint16; + uint32_t *uint32; +}; + + +void *memset(void *dst, int ic, size_t bytes) { + uint8_t c; + uint32_t f; + + union ptr d = {.v = dst}; + + /* Probably the most assemblish code ever written in C! + * This is what you get when you put a processor designer + * to write software */ + + c = ic; + + switch(bytes & 3) { + case 3: + *(d.uint8++) = c; + bytes--; + case 2: + *(d.uint8++) = c; + bytes--; + case 1: + *(d.uint8++) = c; + bytes--; + case 0: + f = (c << 24) | (c << 16) | (c << 8) | c; + while(bytes){ + *(d.uint32++) = f; + bytes -= 4; + } + } + + return dst; +} + +void *memcpy(void *dst, const void *src, size_t bytes) { + + union ptr d = {.v = dst} , s = {.v = src}; + + while(bytes) { + switch(((size_t)d.v | (size_t)s.v | bytes) & 3) { + case 0: + *(d.uint32++) = *(s.uint32++); + bytes-=4; + break; + case 2: + *(d.uint16++) = *(s.uint16++); + bytes-=2; + break; + case 1: + case 3: + *(d.uint8++) = *(s.uint8++); + bytes--; + break; + } + } + + return dst; +} + +int strcmp(const char *a, const char *b) { + while(*a && *b && *a == *b) a++, b++; + + return *a - *b; +} + +size_t strlen(const char *a) { + size_t ret; + + for(ret = 0 ; *a ; a++, ret++); + + return ret; +} + +void panic(const char *fmt, ...) { + va_list ap; + int ret; + + puts("PANIC: "); + + va_start(ap, fmt); + ret = vprintf(fmt, ap); + va_end(ap); + + putchar('\n'); + + exit(-1); +} + +int printf(const char *fmt, ...) { + va_list ap; + int ret; + + va_start(ap, fmt); + ret = vprintf(fmt, ap); + va_end(ap); + + return ret; +} + +int vprintf(const char *fmt, va_list ap){ + char *s; + int i,j; + char buf[32]; + + while (*fmt){ + if (*fmt != '%') + putchar(*fmt++); + else{ + j = 0; + switch (*++fmt){ + case 'i': + case 'd': + i = va_arg(ap, int); + itoa(i,buf,10); + puts(buf); + break; + case 'u': + i = va_arg(ap, int); + utoa(i, buf, 10); + puts(buf); + break; + case 'o': + i = va_arg(ap, int); + utoa(i,buf,8); + puts(buf); + break; + case 'p': + puts("0x"); + case 'X': + i = va_arg(ap, int); + utoa(i,buf,16); + j=0; + while (buf[j]) + buf[j] = islower(buf[j]) ? buf[j++] - 0x20 : buf[j++]; + puts(buf); + break; + case 'x': + i = va_arg(ap, int); + itoa(i,buf,16); + puts(buf); + break; + case 'c': + putchar(va_arg(ap, int)); + break; + case 's': + s = va_arg(ap, char*); + if (!s) s = "(null)"; + puts(s); + break; + case '%' : + putchar('%'); + break; + } + fmt++; + } + } + + return 0; +} diff --git a/software/bareOS/malloc.c b/software/bareOS/malloc.c new file mode 100644 index 0000000..664192f --- /dev/null +++ b/software/bareOS/malloc.c @@ -0,0 +1,107 @@ +#include "include/libos.h" + +/* Shamelessly stolen from K&R C Programing Language Book */ + +typedef struct header { + struct header *ptr; + size_t size; +} header_t __attribute__ ((aligned(MALLOC_ALIGNMENT))); + +static header_t base = {.ptr = &base, .size = 0 }; +static header_t *freep = &base; + +static header_t *morecore(size_t nunits) { + static header_t *lastp = HEAP_START; + header_t *p; + size_t size; + + size = align_type(min(align(nunits*sizeof(header_t), HEAP_ALLOCATION_GRAIN), + ((size_t)lastp)-((size_t)HEAP_END)), header_t); + size /= sizeof(header_t); + + if(((void*)lastp >= HEAP_END) || size < nunits) + return NULL; + + p = lastp; + lastp += size; + + p->size = size; + free(p+1); + + return p; +} + +void *malloc(size_t nbytes) { + header_t *p, *prevp; + unsigned nunits; + int critical; + nunits = (nbytes+sizeof(header_t)-1)/sizeof(header_t) + 1; + + critical = enter_critical(); + + prevp = freep; + for (p = prevp->ptr; ; prevp = p, p = p->ptr) { + if (p->size >= nunits) { + if (p->size == nunits) + prevp->ptr = p->ptr; + else { + p->size -= nunits; + p += p->size; + p->size = nunits; + } + freep = prevp; + leave_critical(critical); + return (void *)(p+1); + } + if (p == freep) { + if((p = morecore(nunits)) == NULL) { + leave_critical(critical); + return NULL; + } + } + } +} + +void free(void *ap) { + header_t *bp, *p; + int critical; + + if(!ap) return; + + bp = (header_t *)ap - 1; + + critical = enter_critical(); + + for (p = freep; !(bp > p && bp < p->ptr); p = p->ptr) + if (p >= p->ptr && (bp > p || bp < p->ptr)) + break; /* freed block at start or end of arena */ + + if (bp + bp->size == p->ptr) { + /* join to upper nbr */ + bp->size += p->ptr->size; + bp->ptr = p->ptr->ptr; + } else + bp->ptr = p->ptr; + if (p + p->size == bp) { + /* join to lower nbr */ + p->size += bp->size; + p->ptr = bp->ptr; + } else + p->ptr = bp; + freep = p; + + leave_critical(critical); +} + +void *calloc(size_t qty, size_t type_size){ + size_t *buf, *end, *a; + size_t size; + + size = qty == 1 ? align_type(type_size, size_t) : align_type(qty*type_size, size_t); + + if((buf = malloc(size))) + for(end = (size_t*)((size_t)buf + size), a = buf ; a < end ; a++) + *a = 0; + + return (void *)buf; +} diff --git a/software/bareOS/softmul.c b/software/bareOS/softmul.c new file mode 100644 index 0000000..a7d748d --- /dev/null +++ b/software/bareOS/softmul.c @@ -0,0 +1,285 @@ +/* + * software implementation of multiply/divide and 64-bit routines + * copied from Hellfire-OS by Sergio Johann Filho + * https://github.com/sjohann81/hellfireos + */ + +#include "include/prototypes.h" + +typedef union{ + int64_t all; + struct{ +#if LITTLE_ENDIAN + uint32_t low; + int32_t high; +#else + int32_t high; + uint32_t low; +#endif + } s; +} dwords; + +int32_t __mulsi3(uint32_t a, uint32_t b){ + uint32_t answer = 0; + + while(b){ + if(b & 1) + answer += a; + a <<= 1; + b >>= 1; + } + return answer; +} + +int64_t __muldsi3(uint32_t a, uint32_t b){ + dwords r; + + const int32_t bits_in_word_2 = (int32_t)(sizeof(int32_t) * 8) / 2; + const uint32_t lower_mask = (uint32_t)~0 >> bits_in_word_2; + r.s.low = (a & lower_mask) * (b & lower_mask); + uint32_t t = r.s.low >> bits_in_word_2; + r.s.low &= lower_mask; + t += (a >> bits_in_word_2) * (b & lower_mask); + r.s.low += (t & lower_mask) << bits_in_word_2; + r.s.high = t >> bits_in_word_2; + t = r.s.low >> bits_in_word_2; + r.s.low &= lower_mask; + t += (b >> bits_in_word_2) * (a & lower_mask); + r.s.low += (t & lower_mask) << bits_in_word_2; + r.s.high += t >> bits_in_word_2; + r.s.high += (a >> bits_in_word_2) * (b >> bits_in_word_2); + + return r.all; +} + +int64_t __muldi3(int64_t a, int64_t b){ + dwords x; + x.all = a; + dwords y; + y.all = b; + dwords r; + r.all = __muldsi3(x.s.low, y.s.low); + /* r.s.high += x.s.high * y.s.low + x.s.low * y.s.high; */ + r.s.high += __mulsi3(x.s.high, y.s.low) + __mulsi3(x.s.low, y.s.high); + + return r.all; +} + +uint32_t __udivmodsi4(uint32_t num, uint32_t den, int32_t modwanted){ + uint32_t bit = 1; + uint32_t res = 0; + + while (den < num && bit && !(den & (1L << 31))) { + den <<= 1; + bit <<= 1; + } + while (bit){ + if (num >= den){ + num -= den; + res |= bit; + } + bit >>= 1; + den >>= 1; + } + if (modwanted) + return num; + return res; +} + +int32_t __divsi3(int32_t a, int32_t b){ + int32_t neg = 0; + int32_t res; + + if (a < 0){ + a = -a; + neg = !neg; + } + + if (b < 0){ + b = -b; + neg = !neg; + } + + res = __udivmodsi4(a, b, 0); + + if (neg) + res = -res; + + return res; +} + +int32_t __modsi3(int32_t a, int32_t b){ + int32_t neg = 0; + int32_t res; + + if (a < 0){ + a = -a; + neg = 1; + } + + if (b < 0) + b = -b; + + res = __udivmodsi4(a, b, 1); + + if (neg) + res = -res; + + return res; +} + +uint32_t __udivsi3 (uint32_t a, uint32_t b){ + return __udivmodsi4(a, b, 0); +} + +uint32_t __umodsi3 (uint32_t a, uint32_t b){ + return __udivmodsi4(a, b, 1); +} + +int64_t __ashldi3(int64_t u, uint32_t b){ + dwords uu, w; + uint32_t bm; + + if (b == 0) + return u; + + uu.all = u; + bm = 32 - b; + + if (bm <= 0){ + w.s.low = 0; + w.s.high = (uint32_t) uu.s.low << -bm; + }else{ + const uint32_t carries = (uint32_t) uu.s.low >> bm; + + w.s.low = (uint32_t) uu.s.low << b; + w.s.high = ((uint32_t) uu.s.high << b) | carries; + } + + return w.all; +} + +int64_t __ashrdi3(int64_t u, uint32_t b){ + dwords uu, w; + uint32_t bm; + + if (b == 0) + return u; + + uu.all = u; + bm = 32 - b; + + if (bm <= 0){ + /* w.s.high = 1..1 or 0..0 */ + w.s.high = uu.s.high >> 31; + w.s.low = uu.s.low >> -bm; + }else{ + const uint32_t carries = (uint32_t) uu.s.high << bm; + + w.s.high = uu.s.high >> b; + w.s.low = ((uint32_t) uu.s.low >> b) | carries; + } + + return w.all; +} + +int64_t __lshrdi3(int64_t u, uint32_t b){ + dwords uu, w; + uint32_t bm; + + if (b == 0) + return u; + + uu.all = u; + bm = 32 - b; + + if (bm <= 0){ + w.s.high = 0; + w.s.low = (uint32_t) uu.s.high >> -bm; + }else{ + const uint32_t carries = (uint32_t) uu.s.high << bm; + + w.s.high = (uint32_t) uu.s.high >> b; + w.s.low = ((uint32_t) uu.s.low >> b) | carries; + } + + return w.all; +} + +uint64_t __udivmoddi4(uint64_t num, uint64_t den, uint64_t *rem_p){ + uint64_t quot = 0, qbit = 1; + + if (den == 0){ + return 1 / ((uint32_t)den); + } + + while ((int64_t)den >= 0){ + den <<= 1; + qbit <<= 1; + } + + while (qbit){ + if (den <= num){ + num -= den; + quot += qbit; + } + den >>= 1; + qbit >>= 1; + } + + if (rem_p) + *rem_p = num; + + return quot; +} + +uint64_t __umoddi3(uint64_t num, uint64_t den){ + uint64_t v; + + (void) __udivmoddi4(num, den, &v); + return v; +} + +uint64_t __udivdi3(uint64_t num, uint64_t den){ + return __udivmoddi4(num, den, NULL); +} + +int64_t __moddi3(int64_t num, int64_t den){ + int minus = 0; + int64_t v; + + if (num < 0){ + num = -num; + minus = 1; + } + if (den < 0){ + den = -den; + minus ^= 1; + } + + (void) __udivmoddi4(num, den, (uint64_t *)&v); + if (minus) + v = -v; + + return v; +} + +int64_t __divdi3(int64_t num, int64_t den){ + int minus = 0; + int64_t v; + + if (num < 0){ + num = -num; + minus = 1; + } + if (den < 0){ + den = -den; + minus ^= 1; + } + + v = __udivmoddi4(num, den, NULL); + if (minus) + v = -v; + + return v; +} diff --git a/software/boot_task/boot_task.s b/software/boot_task/boot_task.s new file mode 100644 index 0000000..a11b112 --- /dev/null +++ b/software/boot_task/boot_task.s @@ -0,0 +1,82 @@ +# HEMPS VERSION - 8.0 - support for RT applications +# +# Distribution: June 2016 +# +# Created by: Marcelo Ruaro - contact: marcelo.ruaro@acad.pucrs.br +# +# Research group: GAPH-PUCRS - contact: fernando.moraes@pucrs.br +# +# Brief description: Initializes the stack pointer and jumps to main(). Handles the syscall. + + + + .text + .align 2 + .globl entry + .ent entry +entry: + .set noreorder + + la $sp,sp_addr # new initialization + + jal main + nop + + beq $0, $0, exit + or $4, $2, $0 + .end entry + + .globl exit + .ent exit + .set noreorder + +exit: + lui $16, 0x2000 # $16 = *HARDWARE_REGISTERS + la $17, .RET_MSG # $17 = *RET_MSG + + # assemble the package + lw $8, 320($16) # $8 = NET_ADDRESS + lw $9, 324($16) # $9 = LOADER_NETADDR + sw $8, 12($17) # RET_MSG.SOURCE = $8 + sw $9, 0($17) # RET_MSG.TARGET = $9 + ori $8, $0, 5 # $8 = 5 (DMNI_SIZE) + sw $4, 16($17) # RET_MSG.RETURN_CODE = $4 + + # send it + sw $8, 512($16) # *DMNI_SIZE = $8 + sw $17, 528($16) # *DMNI_ADDR = $17 + ori $8, $0, 1 # $8 = 1 + sw $0, 544($16) # READ -> DMNI_OP + sw $8, 560($16) # 1 -> DMNI_START + + # commit suicide + li $8, 0xDEADBEEF # MAGIC WORD TO KILL CPU +.L1: + beq $0, $0, .L1 + sw $8, 800($16) # SET_CPU_KILL + .end exit + +# memory region reserved to assemble termination pkg +.RET_MSG: + .word 0 # TARGET + .word 3 # SIZE + .word 0x70 # SERVICE + .word 0 # SOURCE + .word 0 # RETURN_CODE + + + .globl SystemCall + .ent SystemCall + +SystemCall: + .set noreorder + + syscall + nop + jr $31 + nop + + .set reorder + .end SystemCall + + diff --git a/hemps8.5/software/include/api.h b/software/include/api.h similarity index 70% rename from hemps8.5/software/include/api.h rename to software/include/api.h index 7965084..1acb2eb 100644 --- a/hemps8.5/software/include/api.h +++ b/software/include/api.h @@ -21,12 +21,21 @@ #define READPIPE 2 #define GETTICK 3 #define ECHO 4 -#define REALTIME 5 - +#define REALTIME 5 +#define TRANSMIT 6 + #define MemoryWrite(A,V) *(volatile unsigned int*)(A)=(V) #define TRUE 1 #define FALSE 0 +/* Manual Routing destination ports */ +#define MANUAL_EAST 0x80000000 +#define MANUAL_WEST 0xA0000000 +#define MANUAL_NORTH 0xC0000000 +#define MANUAL_SOUTH 0xE0000000 + +#define ROUTER_ADDR(x, y) (((x<<8)|x)&0xFFFF) + extern int SystemCall(); #define Send(msg, target) while(!SystemCall(WRITEPIPE, (unsigned int*)msg, target,0)) @@ -35,6 +44,10 @@ extern int SystemCall(); #define Echo(str) SystemCall(ECHO, (char*)str,0,0) #define exit() while(!SystemCall(EXIT, 0, 0, 0)) +// Bruno's modification 14/09 - The change reflects the need of a transit message to send packets outside the NoC. +// The call is Target (ROUTER_ADDR(x,y)|MANUAL_PORT) , message (payload), payload len in flits) +#define Transmit(target, msg, len) while (!SystemCall(TRANSMIT, target, (unsigned int*)msg, len)) + //Real-Time API - time represented in microseconds #define RealTime(period, deadline, execution_time) while(!SystemCall(REALTIME, period, deadline, execution_time)) diff --git a/hemps8.5/software/include/plasma.h b/software/include/plasma.h similarity index 100% rename from hemps8.5/software/include/plasma.h rename to software/include/plasma.h diff --git a/hemps8.5/software/include/services.h b/software/include/services.h similarity index 92% rename from hemps8.5/software/include/services.h rename to software/include/services.h index 1f25376..0bfc8ce 100644 --- a/hemps8.5/software/include/services.h +++ b/software/include/services.h @@ -1,48 +1,51 @@ -/*!\file services.h - * HEMPS VERSION - 8.0 - support for RT applications - * - * Distribution: June 2016 - * - * Edited by: Marcelo Ruaro - contact: marcelo.ruaro@acad.pucrs.br - * - * Research group: GAPH-PUCRS - contact: fernando.moraes@pucrs.br - * - * \brief Kernel services definitions. This services are used to - * identifies a packet. - */ - -#ifndef __SERVICES_H__ -#define __SERVICES_H__ - -#define MESSAGE_REQUEST 0x00000010 -#define MESSAGE_DELIVERY 0x00000020 -#define TASK_ALLOCATION 0x00000040 -#define TASK_ALLOCATED 0x00000050 -#define TASK_REQUEST 0x00000060 -#define TASK_TERMINATED 0x00000070 -#define LOAN_PROCESSOR_RELEASE 0x00000090 -#define DEBUG_MESSAGE 0x00000100 -#define NEW_TASK 0x00000130 -#define APP_TERMINATED 0x00000140 -#define NEW_APP 0x00000150 -#define INITIALIZE_CLUSTER 0x00000160 -#define INITIALIZE_SLAVE 0x00000170 -#define TASK_TERMINATED_OTHER_CLUSTER 0x00000180 -#define LOAN_PROCESSOR_REQUEST 0x00000190 -#define LOAN_PROCESSOR_DELIVERY 0x00000200 -#define TASK_MIGRATION 0x00000210 -#define MIGRATION_CODE 0x00000220 -#define MIGRATION_TCB 0x00000221 -#define MIGRATION_TASK_LOCATION 0x00000222 -#define MIGRATION_MSG_REQUEST 0x00000223 -#define MIGRATION_STACK 0x00000224 -#define MIGRATION_DATA_BSS 0x00000225 -#define UPDATE_TASK_LOCATION 0x00000230 -#define TASK_MIGRATED 0x00000235 -#define APP_ALLOCATION_REQUEST 0x00000240 -#define TASK_RELEASE 0x00000250 -#define SLACK_TIME_REPORT 0x00000260 -#define DEADLINE_MISS_REPORT 0x00000270 -#define REAL_TIME_CHANGE 0x00000280 - -#endif +/*!\file services.h + * HEMPS VERSION - 8.0 - support for RT applications + * + * Distribution: June 2016 + * + * Edited by: Marcelo Ruaro - contact: marcelo.ruaro@acad.pucrs.br + * + * Research group: GAPH-PUCRS - contact: fernando.moraes@pucrs.br + * + * \brief Kernel services definitions. This services are used to + * identifies a packet. + */ + +#ifndef __SERVICES_H__ +#define __SERVICES_H__ + +#define MESSAGE_REQUEST 0x00000010 +#define MESSAGE_DELIVERY 0x00000020 +#define TASK_ALLOCATION 0x00000040 +#define TASK_ALLOCATED 0x00000050 +#define TASK_REQUEST 0x00000060 +#define TASK_TERMINATED 0x00000070 +#define LOAN_PROCESSOR_RELEASE 0x00000090 +#define DEBUG_MESSAGE 0x00000100 +#define NEW_TASK 0x00000130 +#define APP_TERMINATED 0x00000140 +#define NEW_APP 0x00000150 +#define INITIALIZE_CLUSTER 0x00000160 +#define INITIALIZE_SLAVE 0x00000170 +#define TASK_TERMINATED_OTHER_CLUSTER 0x00000180 +#define LOAN_PROCESSOR_REQUEST 0x00000190 +#define LOAN_PROCESSOR_DELIVERY 0x00000200 +#define TASK_MIGRATION 0x00000210 +#define MIGRATION_CODE 0x00000220 +#define MIGRATION_TCB 0x00000221 +#define MIGRATION_TASK_LOCATION 0x00000222 +#define MIGRATION_MSG_REQUEST 0x00000223 +#define MIGRATION_STACK 0x00000224 +#define MIGRATION_DATA_BSS 0x00000225 +#define UPDATE_TASK_LOCATION 0x00000230 +#define TASK_MIGRATED 0x00000235 +#define APP_ALLOCATION_REQUEST 0x00000240 +#define TASK_RELEASE 0x00000250 +#define SLACK_TIME_REPORT 0x00000260 +#define DEADLINE_MISS_REPORT 0x00000270 +#define REAL_TIME_CHANGE 0x00000280 +#define BORDER_ROUTE 0x00000310 +#define DMA_OPERATION 0x00000290 +#define START_CPU 0x00000300 + +#endif diff --git a/hemps8.5/software/include/stdlib.h b/software/include/stdlib.h similarity index 100% rename from hemps8.5/software/include/stdlib.h rename to software/include/stdlib.h diff --git a/hemps8.5/software/kernel/master/boot.S b/software/kernel/master/boot.S similarity index 100% rename from hemps8.5/software/kernel/master/boot.S rename to software/kernel/master/boot.S diff --git a/hemps8.5/software/kernel/master/kernel_master.c b/software/kernel/master/kernel_master.c similarity index 100% rename from hemps8.5/software/kernel/master/kernel_master.c rename to software/kernel/master/kernel_master.c diff --git a/hemps8.5/software/kernel/master/kernel_master.h b/software/kernel/master/kernel_master.h similarity index 100% rename from hemps8.5/software/kernel/master/kernel_master.h rename to software/kernel/master/kernel_master.h diff --git a/hemps8.5/software/kernel/slave/boot.S b/software/kernel/slave/boot.S similarity index 100% rename from hemps8.5/software/kernel/slave/boot.S rename to software/kernel/slave/boot.S diff --git a/software/kernel/slave/kernel_slave.c b/software/kernel/slave/kernel_slave.c new file mode 100644 index 0000000..f432b12 --- /dev/null +++ b/software/kernel/slave/kernel_slave.c @@ -0,0 +1,873 @@ +/*!\file kernel_slave.c + * HEMPS VERSION - 8.0 - support for RT applications + * + * Distribution: June 2016 + * + * Edited by: Marcelo Ruaro - contact: marcelo.ruaro@acad.pucrs.br + * + * Research group: GAPH-PUCRS - contact: fernando.moraes@pucrs.br + * + * \brief + * Kernel slave is the system slave used to execute user's tasks. + * + * \detailed + * kernel_slave is the core of the OS running into the slave processors. + * Its job is to runs the user's task. It communicates whit the kernel_master to receive new tasks + * and also notifying its finish. + * The kernel_slave file uses several modules that implement specific functions + */ + +#include "kernel_slave.h" + +#include "../../../include/kernel_pkg.h" +#include "../../include/api.h" +#include "../../include/plasma.h" +#include "../../include/services.h" +#include "../../modules/task_location.h" +#include "../../modules/packet.h" +#include "../../modules/communication.h" +#include "../../modules/pending_service.h" +#include "../../modules/task_scheduler.h" +#include "../../modules/utils.h" +#if MIGRATION_ENABLED +#include "../../modules/task_migration.h" +#endif + +//Globals +unsigned int net_address; //!< Store the current XY address +unsigned int schedule_after_syscall; //!< Signals the syscall function (assembly implemented) to call the scheduler after the syscall +unsigned int cluster_master_address; //!< Store the cluster master XY address +unsigned int last_idle_time; //!< Store the last idle time duration +unsigned int total_slack_time; //!< Store the total of the processor idle time +TCB idle_tcb; //!< TCB pointer used to run idle task +TCB * current; //!< TCB pointer used to store the current task executing into processor +Message msg_write_pipe; //!< Message variable which is used to copy a message and send it by the NoC + + +/** Assembles and sends a TASK_TERMINATED packet to the master kernel + * \param terminated_task Terminated task TCB pointer + */ +void send_task_terminated(TCB * terminated_task){ + + ServiceHeader *p = get_service_header_slot(); + + p->header = terminated_task->master_address; + + p->service = TASK_TERMINATED; + + p->task_ID = terminated_task->id; + + p->master_ID = cluster_master_address; + + send_packet(p, 0, 0); + + if (terminated_task->master_address != cluster_master_address){ + + p = get_service_header_slot(); + + p->header = cluster_master_address; + + p->service = TASK_TERMINATED_OTHER_CLUSTER; + + p->task_ID = terminated_task->id; + + p->master_ID = terminated_task->master_address; + + send_packet(p, 0, 0); + } + +} + +/** Assembles and sends a TASK_ALLOCATED packet to the master kernel + * \param allocated_task Allocated task TCB pointer + */ +void send_task_allocated(TCB * allocated_task){ + + ServiceHeader *p = get_service_header_slot(); + + p->header = allocated_task->master_address; + + p->service = TASK_ALLOCATED; + + p->task_ID = allocated_task->id; + + p->master_ID = cluster_master_address; + + send_packet(p, 0, 0); +} + +/** Assembles and sends a MESSAGE_DELIVERY packet to a consumer task located into a slave processor + * \param producer_task ID of the task that produce the message (Send()) + * \param consumer_task ID of the task that consume the message (Receive()) + * \param msg_ptr Message pointer + */ +void send_message_delivery(int producer_task, int consumer_task, int consumer_PE, Message * msg_ptr){ + + ServiceHeader *p = get_service_header_slot(); + + p->header = consumer_PE; + + p->service = MESSAGE_DELIVERY; + + p->producer_task = producer_task; + + p->consumer_task = consumer_task; + + p->msg_lenght = msg_ptr->length; + + send_packet(p, (unsigned int)msg_ptr->msg, msg_ptr->length); + +} + +/** Assembles and sends a REAL_TIME_CHANGE packet to the master kernel + * \param tcb_ptr TCB pointer of the task that change its real-time parameters + */ +void send_task_real_time_change(TCB * tcb_ptr){ + + ServiceHeader * p = get_service_header_slot(); + + p = get_service_header_slot(); + + p->header = cluster_master_address; + + p->service = REAL_TIME_CHANGE; + + p->task_ID = tcb_ptr->id; + + p->utilization = tcb_ptr->scheduling_ptr->utilization; + + putsv("Send real time change, utilization: ", p->utilization); + + send_packet(p, 0, 0); +} + +/** Assembles and sends a SLACK_TIME_REPORT packet to the master kernel + */ +void send_slack_time_report(){ + + ServiceHeader * p = get_service_header_slot(); + + p->header = cluster_master_address; + + p->service = SLACK_TIME_REPORT; + + p->cpu_slack_time = ( (total_slack_time*100) / SLACK_TIME_WINDOW); + + send_packet(p, 0, 0); +} + +/** Assembles and sends a UPDATE_TASK_LOCATION packet to a slave processor. Useful because task migration + * \param target_proc Target slave processor which the packet will be sent + * \param task_id Task ID that have its location updated + * \param new_task_location New location (slave processor address) of the task + */ +void send_update_task_location(unsigned int target_proc, unsigned int task_id, unsigned int new_task_location){ + + ServiceHeader *p = get_service_header_slot(); + + if (target_proc != net_address){ + + p->header = target_proc; + + p->service = UPDATE_TASK_LOCATION; + + p->task_ID = task_id; + + p->allocated_processor = new_task_location; + + send_packet(p, 0, 0); + } + + if (target_proc != new_task_location){ + + p = get_service_header_slot(); + + p->header = new_task_location; + + p->service = UPDATE_TASK_LOCATION; + + p->task_ID = task_id; + + p->allocated_processor = new_task_location; + + send_packet(p, 0, 0); + } +} + +/** Assembles and sends a MESSAGE_REQUEST packet to producer task into a slave processor + * \param producer_task Producer task ID (Send()) + * \param consumer_task Consumer task ID (Receive()) + * \param targetPE Processor address of the producer task + * \param requestingPE Processor address of the consumer task + * \param insert_pipe_flag Tells to the producer PE that the message not need to be by passed again + */ +void send_message_request(int producer_task, int consumer_task, unsigned int targetPE, unsigned int requestingPE, int insert_pipe_flag){ + + + ServiceHeader *p = get_service_header_slot(); + + p->header = targetPE; + + p->service = MESSAGE_REQUEST; + + p->requesting_processor = requestingPE; + + p->producer_task = producer_task; + + p->consumer_task = consumer_task; + + p->insert_request = insert_pipe_flag; + + send_packet(p, 0, 0); +} + +/** Useful function to writes a message into the task page space + * \param task_tcb_ptr TCB pointer of the task + * \param msg_lenght Lenght of the message to be copied + * \param msg_data Message data + */ +void write_local_msg_to_task(TCB * task_tcb_ptr, int msg_lenght, int * msg_data){ + + Message * msg_ptr; + + msg_ptr = (Message*)((task_tcb_ptr->offset) | ((unsigned int)task_tcb_ptr->reg[3])); //reg[3] = address message + + msg_ptr->length = msg_lenght; + + for (int i=0; ilength; i++) + msg_ptr->msg[i] = msg_data[i]; + + //Unlock the blocked task + task_tcb_ptr->reg[0] = TRUE; + + //Release task to execute + task_tcb_ptr->scheduling_ptr->waiting_msg = 0; +} + +/** Syscall handler. It is called when a task calls a function defined into the api.h file + * \param service Service of the syscall + * \param arg0 Generic argument + * \param arg1 Generic argument + * \param arg2 Generic argument + */ +int Syscall(unsigned int service, unsigned int arg0, unsigned int arg1, unsigned int arg2) { + + ServiceHeader *p; + Message *msg_read; + Message *msg_write; + PipeSlot *pipe_ptr; + MessageRequest * msg_req_ptr; + int consumer_task; + int producer_task; + int producer_PE; + int consumer_PE; + int appID; + int ret; + + schedule_after_syscall = 0; + + switch (service) { + + case EXIT: + + schedule_after_syscall = 1; + + //Deadlock avoidance: avoids to send a packet when the DMNI is busy in send process + //Also, due task migration sincronization messages, the producer task cannot finish it execution while have messages in PIPE + if (MemoryRead(DMNI_SEND_ACTIVE) || search_PIPE_producer(current->id)){ + return 0; + } + + puts("Task id: "); puts(itoa(current->id)); putsv(" terminated at ", MemoryRead(TICK_COUNTER)); + + send_task_terminated(current); + + clear_scheduling(current->scheduling_ptr); + + appID = current->id >> 8; + + if ( !is_another_task_running(appID) ){ + + clear_app_tasks_locations(appID); + } + + return 1; + + case WRITEPIPE: + + producer_task = current->id; + consumer_task = (int) arg1; + + appID = producer_task >> 8; + consumer_task = (appID << 8) | consumer_task; + + //puts("WRITEPIPE - prod: "); puts(itoa(producer_task)); putsv(" consumer ", consumer_task); + + consumer_PE = get_task_location(consumer_task); + + //Test if the consumer task is not allocated + if (consumer_PE == -1){ + //Task is blocked until its a TASK_RELEASE packet + current->scheduling_ptr->status = BLOCKED; + return 0; + } + + /*Points the message in the task page. Address composition: offset + msg address*/ + msg_read = (Message *)((current->offset) | arg0); + + //Searches if there is a message request to the produced message + msg_req_ptr = remove_message_request(producer_task, consumer_task); + + if (msg_req_ptr){ + + if (msg_req_ptr->requester_proc == net_address){ //Test if the consumer is local or remote + + //Writes to the consumer page address (local consumer) + TCB * requesterTCB = searchTCB(consumer_task); + + write_local_msg_to_task(requesterTCB, msg_read->length, msg_read->msg); + +#if MIGRATION_ENABLED + if (requesterTCB->proc_to_migrate != -1){ + + migrate_dynamic_memory(requesterTCB); + + schedule_after_syscall = 1; + } +#endif + + } else { //Send a mesage delivery (remote consumer) + + //Deadlock avoidance: voids to send a packet when the DMNI is busy in send process + if ( MemoryRead(DMNI_SEND_ACTIVE) ){ + //Restore the message request + msg_req_ptr->requested = producer_task; + msg_req_ptr->requester = consumer_task; + return 0; + } + + msg_write_pipe.length = msg_read->length; + + //Avoids message overwriting by the producer task + for (int i=0; i < msg_read->length; i++) + msg_write_pipe.msg[i] = msg_read->msg[i]; + + send_message_delivery(producer_task, consumer_task, msg_req_ptr->requester_proc, &msg_write_pipe); + + } + } else { //message not requested yet, stores into PIPE + + //########################### ADD PIPE ################################# + ret = add_PIPE(producer_task, consumer_task, msg_read); + //########################### ADD PIPE ################################# + + if (ret == 0){ + schedule_after_syscall = 1; + return 0; + } + } + + return 1; + + case READPIPE: + + consumer_task = current->id; + producer_task = (int) arg1; + + appID = consumer_task >> 8; + producer_task = (appID << 8) | producer_task; + + //puts("READPIPE - prod: "); puts(itoa(producer_task)); putsv(" consumer ", consumer_task); + + producer_PE = get_task_location(producer_task); + + //Test if the producer task is not allocated + if (producer_PE == -1){ + //Task is blocked until its a TASK_RELEASE packet + current->scheduling_ptr->status = BLOCKED; + return 0; + } + + if (producer_PE == net_address){ //Local producer + + //Searches if the message is in PIPE (local producer) + pipe_ptr = remove_PIPE(producer_task, consumer_task); + + if (pipe_ptr == 0){ + + //Stores the request into the message request table (local producer) + insert_message_request(producer_task, consumer_task, net_address); + + } else { + + //Message was found in pipe, writes to the consumer page address (local producer) + + msg_write = (Message*) arg0; + + msg_write = (Message*)((current->offset) | ((unsigned int)msg_write)); + + msg_write->length = pipe_ptr->message.length; + + for (int i = 0; ilength; i++) { + msg_write->msg[i] = pipe_ptr->message.msg[i]; + } + + return 1; + } + + } else { //Remote producer : Sends the message request (remote producer) + + //Deadlock avoidance: avoids to send a packet when the DMNI is busy in send process + if ( MemoryRead(DMNI_SEND_ACTIVE) ) + return 0; + + send_message_request(producer_task, consumer_task, producer_PE, net_address, 0); + + } + + //Sets task as waiting blocking its execution, it will execute again when the message is produced by a WRITEPIPE or incoming MSG_DELIVERY + current->scheduling_ptr->waiting_msg = 1; + + schedule_after_syscall = 1; + + return 0; + + case GETTICK: + + return MemoryRead(TICK_COUNTER); + + break; + + case ECHO: + + puts("$$$_"); + puts(itoa(net_address>>8));puts("x");puts(itoa(net_address&0xFF)); puts("_"); + puts(itoa(current->id >> 8)); puts("_"); + puts(itoa(current->id & 0xFF)); puts("_"); + puts((char *)((current->offset) | (unsigned int) arg0)); + puts("\n"); + + break; + + case REALTIME: + + //Deadlock avoidance: avoids to send a packet when the DMNI is busy in send process + if (MemoryRead(DMNI_SEND_ACTIVE)){ + return 0; + } + + //putsv("\nReal-time to task: ", current->id); + + real_time_task(current->scheduling_ptr, arg0, arg1, arg2); + + //send_task_real_time_change(current); + + schedule_after_syscall = 1; + + return 1; + break; + + case TRANSMIT: + p = get_service_header_slot(); + p->header = arg0; + p->service = BORDER_ROUTE; + p->task_ID = current->id; + + send_packet(p, arg1, arg2); + + return 1; + break; + } + + return 0; +} +/** Handles a new packet from NoC + */ +int handle_packet(volatile ServiceHeader * p) { + + int need_scheduling, code_lenght, app_ID, task_loc; + unsigned int app_tasks_location[MAX_TASKS_APP]; + PipeSlot * slot_ptr; + Message * msg_ptr; + TCB * tcb_ptr = 0; + + need_scheduling = 0; + + switch (p->service) { + + case MESSAGE_REQUEST: //This case is the most complicated of the HeMPS if you understand it, so you understand all task communication protocol + //This case sincronizes the communication messages also in case of task migration, the migration allows several scenarios, that are handled inside this case + + //Gets the location of the producer task + task_loc = get_task_location(p->producer_task); + + //Test if the task was migrated to this processor but have message produced in the old processor + //In this case is necessary to forward the message request to the old processor + if (searchTCB(p->producer_task) && task_loc != net_address){ + if (p->insert_request) + insert_message_request(p->producer_task, p->consumer_task, p->requesting_processor); + else + //MESSAGE_REQUEST by pass + send_message_request(p->producer_task, p->consumer_task, task_loc, p->requesting_processor, 0); + + break; + } + + //Remove msg from PIPE, if there is no message, them slot_ptr will be 0 + //Note that this line, is below to the by pass above, becase we need to avoid that the a message be removed if still there are other messages in pipe of the old proc + slot_ptr = remove_PIPE(p->producer_task, p->consumer_task); + + //Test if there is no message in PIPE + if (slot_ptr == 0){ + + //Test if the producer task is running at this processor, this conditions work togheter to the first by pass condition (above). + if (task_loc == net_address){ + + insert_message_request(p->producer_task, p->consumer_task, p->requesting_processor); + + } else { //If not, the task was migrated and the requester message_request need to be forwarded to the correct producer proc + + //If there is no more messages in the pipe of the producer, update the location of the migrated task at the remote proc + if ( search_PIPE_producer(p->producer_task) == 0) + send_update_task_location(p->requesting_processor, p->producer_task, task_loc); + + //MESSAGE_REQUEST by pass with flag insert in pipe enabled (there is no more message for the requesting task in this processor) + send_message_request(p->producer_task, p->consumer_task, task_loc, p->requesting_processor, 1); + } + + //message found, send it!! + } else if (p->requesting_processor != net_address){ + + send_message_delivery(p->producer_task, p->consumer_task, p->requesting_processor, &slot_ptr->message); + + //This else is executed when this slave received a own MESSAGE_REQUEST due a task migration by pass + } else { + + tcb_ptr = searchTCB(p->consumer_task); + + write_local_msg_to_task(tcb_ptr, slot_ptr->message.length, slot_ptr->message.msg); + } + + break; + + case MESSAGE_DELIVERY: + + tcb_ptr = searchTCB(p->consumer_task); + + msg_ptr = (Message *)(tcb_ptr->offset | tcb_ptr->reg[3]); + + msg_ptr->length = p->msg_lenght; + + DMNI_read_data((unsigned int)msg_ptr->msg, msg_ptr->length); + + tcb_ptr->reg[0] = 1; + + //Release task to execute + tcb_ptr->scheduling_ptr->waiting_msg = 0; + +#if MIGRATION_ENABLED + if (tcb_ptr->proc_to_migrate != -1){ + + migrate_dynamic_memory(tcb_ptr); + + need_scheduling = 1; + + } else +#endif + + if (current == &idle_tcb){ + need_scheduling = 1; + } + + break; + + case TASK_ALLOCATION: + + tcb_ptr = search_free_TCB(); + + tcb_ptr->pc = 0; + + tcb_ptr->id = p->task_ID; + + puts("Task id: "); puts(itoa(tcb_ptr->id)); putsv(" allocated at ", MemoryRead(TICK_COUNTER)); + + code_lenght = p->code_size; + + tcb_ptr->text_lenght = code_lenght; + + tcb_ptr->master_address = p->master_ID; + + tcb_ptr->proc_to_migrate = -1; + + tcb_ptr->scheduling_ptr->remaining_exec_time = MAX_TIME_SLICE; + + DMNI_read_data(tcb_ptr->offset, code_lenght); + + tcb_ptr->scheduling_ptr->status = BLOCKED; + + send_task_allocated(tcb_ptr); + + if (current == &idle_tcb){ + need_scheduling = 1; + } + + break; + + case TASK_RELEASE: + + tcb_ptr = searchTCB(p->task_ID); + + app_ID = p->task_ID >> 8; + + //putsv("-> TASK RELEASE received to task ", p->task_ID); + + tcb_ptr->data_lenght = p->data_size; + + tcb_ptr->bss_lenght = p->bss_size; + + tcb_ptr->text_lenght = tcb_ptr->text_lenght - tcb_ptr->data_lenght; + + if (tcb_ptr->scheduling_ptr->status == BLOCKED) + tcb_ptr->scheduling_ptr->status = READY; + + DMNI_read_data( (unsigned int) app_tasks_location, p->app_task_number); + + if (get_task_location(tcb_ptr->id) == -1){ + for (int i = 0; i < p->app_task_number; i++){ + add_task_location(app_ID << 8 | i, app_tasks_location[i]); + } + } + + if (current == &idle_tcb){ + need_scheduling = 1; + } + + break; + + case UPDATE_TASK_LOCATION: + + if (is_another_task_running(p->task_ID >> 8) ){ + + remove_task_location(p->task_ID); + + add_task_location(p->task_ID, p->allocated_processor); + + } + + break; + + case INITIALIZE_SLAVE: + + cluster_master_address = p->source_PE; + + putsv("Slave initialized by cluster address: ", cluster_master_address); + + break; + +#if MIGRATION_ENABLED + case TASK_MIGRATION: + case MIGRATION_CODE: + case MIGRATION_TCB: + case MIGRATION_TASK_LOCATION: + case MIGRATION_MSG_REQUEST: + case MIGRATION_STACK: + case MIGRATION_DATA_BSS: + + need_scheduling = handle_migration(p, cluster_master_address); + + break; +#endif + + default: + putsv("ERROR: service unknown: ", MemoryRead(TICK_COUNTER)); + break; + } + + return need_scheduling; +} + +/** Generic task scheduler call + */ +void Scheduler() { + + Scheduling * scheduled; + unsigned int scheduler_call_time; + + scheduler_call_time = MemoryRead(TICK_COUNTER); + + MemoryWrite(SCHEDULING_REPORT, SCHEDULER); + + #if MIGRATION_ENABLED + if (current->proc_to_migrate != -1 && current->scheduling_ptr->status == RUNNING && current->scheduling_ptr->waiting_msg == 0) + migrate_dynamic_memory(current); + #endif + + scheduled = LST(scheduler_call_time); + + if (scheduled){ + + //This cast is an approach to reduce the scheduler call overhead + current = (TCB *) scheduled->tcb_ptr; + + MemoryWrite(SCHEDULING_REPORT, current->id); + + } else { + + current = &idle_tcb; // schedules the idle task + + last_idle_time = MemoryRead(TICK_COUNTER); + + MemoryWrite(SCHEDULING_REPORT, IDLE); + } + + MemoryWrite(TIME_SLICE, get_time_slice() ); + + OS_InterruptMaskSet(IRQ_SCHEDULER); + +} + +/** Function called by assembly (into interruption handler). Implements the routine to handle interruption in HeMPS + * This function must implement a important rule: it cannot send a packet when the DMNI is already send a packet. + * The interruption triggers according to the DMNI status, and the if-else statements inside this function ensure this + * behavior. + * \param status Status of the interruption. Signal the interruption type + */ +void OS_InterruptServiceRoutine(unsigned int status) { + + MemoryWrite(SCHEDULING_REPORT, INTERRUPTION); + + volatile ServiceHeader p; + ServiceHeader * next_service; + unsigned call_scheduler; + + + if (current == &idle_tcb){ + total_slack_time += MemoryRead(TICK_COUNTER) - last_idle_time; + } + + call_scheduler = 0; + + //***** Check if interruption comes from NoC + if ( status & IRQ_NOC ){ + + read_packet((ServiceHeader *)&p); + + if (MemoryRead(DMNI_SEND_ACTIVE) && (p.service == MESSAGE_REQUEST || p.service == TASK_MIGRATION) ){ + + add_pending_service((ServiceHeader *)&p); + + } else { + + call_scheduler = handle_packet(&p); + } + + //**** Handles remaining packets + } else if (status & IRQ_PENDING_SERVICE) { + + next_service = get_next_pending_service(); + if (next_service){ + call_scheduler = handle_packet(next_service); + } + //***** Send the monitoring packet + } else if (status & IRQ_SLACK_TIME){ + send_slack_time_report(); + total_slack_time = 0; + MemoryWrite(SLACK_TIME_MONITOR, 0); + } + + + if ( status & IRQ_SCHEDULER ){ + + call_scheduler = 1; + } + + + if (call_scheduler){ + + Scheduler(); + + } else if (current == &idle_tcb){ + + last_idle_time = MemoryRead(TICK_COUNTER); + + MemoryWrite(SCHEDULING_REPORT, IDLE); + + } else { + MemoryWrite(SCHEDULING_REPORT, current->id); + } + + /*runs the scheduled task*/ + ASM_RunScheduledTask(current); +} + +/** Clear a interruption mask + * \param Mask Interruption mask clear + */ +unsigned int OS_InterruptMaskClear(unsigned int Mask) { + + unsigned int mask; + + mask = MemoryRead(IRQ_MASK) & ~Mask; + MemoryWrite(IRQ_MASK, mask); + + return mask; +} + +/** Set a interruption mask + * \param Mask Interruption mask set + */ +unsigned int OS_InterruptMaskSet(unsigned int Mask) { + + unsigned int mask; + + mask = MemoryRead(IRQ_MASK) | Mask; + MemoryWrite(IRQ_MASK, mask); + + return mask; +} + +/** Idle function + */ +void OS_Idle() { + for (;;){ + MemoryWrite(CLOCK_HOLD, 1); + } +} + +int main(){ + + ASM_SetInterruptEnable(FALSE); + + idle_tcb.pc = (unsigned int) &OS_Idle; + idle_tcb.id = 0; + idle_tcb.offset = 0; + + total_slack_time = 0; + + last_idle_time = MemoryRead(TICK_COUNTER); + + current = &idle_tcb; + + net_address = MemoryRead(NI_CONFIG); + + puts("Initializing PE: "); puts(itoh(net_address)); puts("\n"); + + init_communication(); + + init_service_header_slots(); + + init_task_location(); + + init_TCBs(); + + /*disable interrupts*/ + OS_InterruptMaskClear(0xffffffff); + + /*enables timeslice counter and wrapper interrupts*/ + OS_InterruptMaskSet(IRQ_SCHEDULER | IRQ_NOC | IRQ_PENDING_SERVICE | IRQ_SLACK_TIME); + + /*runs the scheduled task*/ + ASM_RunScheduledTask(current); + + return 0; +} diff --git a/hemps8.5/software/kernel/slave/kernel_slave.h b/software/kernel/slave/kernel_slave.h similarity index 100% rename from hemps8.5/software/kernel/slave/kernel_slave.h rename to software/kernel/slave/kernel_slave.h diff --git a/hemps8.5/software/kernel/slave/kernel_slave.c b/software/kernel/slave/kernel_slave_old.c similarity index 100% rename from hemps8.5/software/kernel/slave/kernel_slave.c rename to software/kernel/slave/kernel_slave_old.c diff --git a/hemps8.5/software/modules/applications.c b/software/modules/applications.c similarity index 100% rename from hemps8.5/software/modules/applications.c rename to software/modules/applications.c diff --git a/hemps8.5/software/modules/applications.h b/software/modules/applications.h similarity index 100% rename from hemps8.5/software/modules/applications.h rename to software/modules/applications.h diff --git a/software/modules/boarder_route.c b/software/modules/boarder_route.c new file mode 100644 index 0000000..51a240d --- /dev/null +++ b/software/modules/boarder_route.c @@ -0,0 +1,41 @@ +/*!\file task_location.h + * HEMPS VERSION - 8.0 - support for RT applications + * + * Distribution: June 2016 + * + * Created by: Bruno Oliveira - contact: bruno.scherer@acad.pucrs.br + * + * Research group: GAPH-PUCRS - contact: fernando.moraes@pucrs.br + * + * \brief + * This module defines function relative to border routing. + * \detailed + * + */ + +#include "border_route.h" +#include "../../include/kernel_pkg.h" +#include "utils.h" + +/** + * \brief This structure stores the location (slave process address) of the other task + */ + +int border_route(unsigned int f1, unsigned int f2, unsigned int f3){ + if (f1 == 1){ + if (f2 == 1 && f3 == 1){ + return 57344; + } + else if (f2 == 1 && f3 == 0) { + return 49152; + } + else if (f2 == 0 && f3 == 1){ + return 40960; + } + else if (f2 == 0 && f3 == 0){ + return 32768; + } + } +} + +#endif /* BORDER_ROUTE_H_ */ diff --git a/software/modules/boarder_route.h b/software/modules/boarder_route.h new file mode 100644 index 0000000..1cb492f --- /dev/null +++ b/software/modules/boarder_route.h @@ -0,0 +1,32 @@ +/*!\file task_location.h + * HEMPS VERSION - 8.0 - support for RT applications + * + * Distribution: June 2016 + * + * Created by: Bruno Oliveira - contact: bruno.scherer@acad.pucrs.br + * + * Research group: GAPH-PUCRS - contact: fernando.moraes@pucrs.br + * + * \brief + * This module defines function relative to border routing. + * \detailed + * + */ + +#ifndef BORDER_ROUTE +#define BORDER_ROUTE_H_ + +#include "../../include/kernel_pkg.h" +#include "border_route.h" +/** + * \brief This structure stores the location (slave process address) of the other task + */ +struct packed_struct { + unsigned int f1:1; + unsigned int f2:1; + unsigned int f3:1; +} + +int border_route(unsigned int f1, unsigned int f2, unsigned int f3); + +#endif /* BORDER_ROUTE_H_ */ diff --git a/hemps8.5/software/modules/communication.c b/software/modules/communication.c similarity index 100% rename from hemps8.5/software/modules/communication.c rename to software/modules/communication.c diff --git a/hemps8.5/software/modules/communication.h b/software/modules/communication.h similarity index 100% rename from hemps8.5/software/modules/communication.h rename to software/modules/communication.h diff --git a/hemps8.5/software/modules/new_task.c b/software/modules/new_task.c similarity index 100% rename from hemps8.5/software/modules/new_task.c rename to software/modules/new_task.c diff --git a/hemps8.5/software/modules/new_task.h b/software/modules/new_task.h similarity index 100% rename from hemps8.5/software/modules/new_task.h rename to software/modules/new_task.h diff --git a/hemps8.5/software/modules/packet.c b/software/modules/packet.c similarity index 99% rename from hemps8.5/software/modules/packet.c rename to software/modules/packet.c index 7cc4fcf..c559524 100644 --- a/hemps8.5/software/modules/packet.c +++ b/software/modules/packet.c @@ -99,14 +99,12 @@ void send_packet(ServiceHeader *p, unsigned int initial_address, unsigned int dm MemoryWrite(DMNI_ADDRESS, (unsigned int) p); if (dmni_msg_size > 0){ - MemoryWrite(DMNI_SIZE_2, dmni_msg_size); MemoryWrite(DMNI_ADDRESS_2, initial_address); } MemoryWrite(DMNI_OP, READ); MemoryWrite(DMNI_START, 1); - } /**Function that abstracts the process to read a generic packet from NoC by programming the DMNI diff --git a/hemps8.5/software/modules/packet.h b/software/modules/packet.h similarity index 96% rename from hemps8.5/software/modules/packet.h rename to software/modules/packet.h index d24e616..466b52e 100644 --- a/hemps8.5/software/modules/packet.h +++ b/software/modules/packet.h @@ -17,7 +17,7 @@ #include "../../include/kernel_pkg.h" -#define CONSTANT_PKT_SIZE 13 //! task_scheduler + 1.a - Improvements on LST task scheduler to a better deadline miss monitoring + 2. Renaming cluster_scheduler -> resource_manager + + +make[1]: Entering directory '/home/anderson/Documents/hemps/hemps8.5/testcases/teste_2x2_vhdl_ativ2/applications' +make[2]: Entering directory '/home/anderson/Documents/hemps/hemps8.5/testcases/teste_2x2_vhdl_ativ2/applications/pc1' +make[2]: Nothing to be done for 'default'. +make[2]: Leaving directory '/home/anderson/Documents/hemps/hemps8.5/testcases/teste_2x2_vhdl_ativ2/applications/pc1' +make[2]: Entering directory '/home/anderson/Documents/hemps/hemps8.5/testcases/teste_2x2_vhdl_ativ2/applications/pc2' +make[2]: Nothing to be done for 'default'. +make[2]: Leaving directory '/home/anderson/Documents/hemps/hemps8.5/testcases/teste_2x2_vhdl_ativ2/applications/pc2' +make[1]: Leaving directory '/home/anderson/Documents/hemps/hemps8.5/testcases/teste_2x2_vhdl_ativ2/applications' + +***************** task page size report *********************** +Memory size (32KB) OK for file with size (3.0KB) +Memory size (32KB) OK for file with size (3.0KB) +Memory size (32KB) OK for file with size (3.0KB) +Memory size (32KB) OK for file with size (3.0KB) +***************** end task page size report ********************* + + +***************** repository size report *********************** +Repository size (7.0KB) OK for size informed within yaml file (1024KB) +***************** end repository size report *********************** + +make[1]: Entering directory '/home/anderson/Documents/hemps/hemps8.5/testcases/teste_2x2_vhdl_ativ2/software' +Compiling Kernel modules/utils.c ... +mips-elf-gcc -O2 -Wall -fms-extensions -c -s -std=c99 -G 0 -o modules/utils.o modules/utils.c +Compiling Kernel modules/packet.c ... +mips-elf-gcc -O2 -Wall -fms-extensions -c -s -std=c99 -G 0 -o modules/packet.o modules/packet.c +Compiling Kernel modules/applications.c ... +mips-elf-gcc -O2 -Wall -fms-extensions -c -s -std=c99 -G 0 -o modules/applications.o modules/applications.c +Compiling Kernel modules/pending_service.c ... +mips-elf-gcc -O2 -Wall -fms-extensions -c -s -std=c99 -G 0 -o modules/pending_service.o modules/pending_service.c +Compiling Kernel modules/reclustering.c ... +mips-elf-gcc -O2 -Wall -fms-extensions -c -s -std=c99 -G 0 -o modules/reclustering.o modules/reclustering.c +Compiling Kernel modules/new_task.c ... +mips-elf-gcc -O2 -Wall -fms-extensions -c -s -std=c99 -G 0 -o modules/new_task.o modules/new_task.c +Compiling Kernel modules/communication.c ... +mips-elf-gcc -O2 -Wall -fms-extensions -c -s -std=c99 -G 0 -o modules/communication.o modules/communication.c +Compiling Kernel modules/processors.c ... +mips-elf-gcc -O2 -Wall -fms-extensions -c -s -std=c99 -G 0 -o modules/processors.o modules/processors.c +Compiling Kernel modules/task_control.c ... +mips-elf-gcc -O2 -Wall -fms-extensions -c -s -std=c99 -G 0 -o modules/task_control.o modules/task_control.c +Compiling Kernel modules/task_location.c ... +mips-elf-gcc -O2 -Wall -fms-extensions -c -s -std=c99 -G 0 -o modules/task_location.o modules/task_location.c +Compiling Kernel modules/task_migration.c ... +mips-elf-gcc -O2 -Wall -fms-extensions -c -s -std=c99 -G 0 -o modules/task_migration.o modules/task_migration.c +Compiling Kernel modules/task_scheduler.c ... +mips-elf-gcc -O2 -Wall -fms-extensions -c -s -std=c99 -G 0 -o modules/task_scheduler.o modules/task_scheduler.c +Compiling Kernel modules/resource_manager.c ... +mips-elf-gcc -O2 -Wall -fms-extensions -c -s -std=c99 -G 0 -o modules/resource_manager.o modules/resource_manager.c +Compiling Kernel Master: kernel_master.c ... +mips-elf-as --defsym sp_addr=65535 -o boot_master.o kernel/master/boot.S +mips-elf-gcc -O2 -Wall -fms-extensions -c -s -std=c99 -G 0 -DHOP_NUMBER=1 -Dload -o kernel_master.o kernel/master/kernel_master.c -D IS_MASTER +mips-elf-ld -Ttext 0 -eentry -Map kernel_master.map -s -N -o kernel_master.bin boot_master.o kernel_master.o modules/utils.o modules/packet.o modules/applications.o modules/reclustering.o modules/new_task.o modules/communication.o modules/processors.o modules/resource_manager.o ../include/kernel_pkg.o +makefile:51: recipe for target 'kernel_master.txt' failed +make[1]: Leaving directory '/home/anderson/Documents/hemps/hemps8.5/testcases/teste_2x2_vhdl_ativ2/software' +makefile:18: recipe for target 'kernel' failed +make: Leaving directory '/home/anderson/Documents/hemps/hemps8.5/testcases/teste_2x2_vhdl_ativ2' diff --git a/testcases/teste.yaml b/testcases/teste.yaml new file mode 100644 index 0000000..48bee38 --- /dev/null +++ b/testcases/teste.yaml @@ -0,0 +1,16 @@ +hw: + page_size_KB: 32 + tasks_per_PE: 1 + repository_size_MB: 1 + model_description: sc # sc (gcc) | scmod (questa) | vhdl + noc_buffer_size: 8 # must be power of 2 + mpsoc_dimension: [4,4] # for while, must be a square shape + cluster_dimension: [2,2] # for while, must be a square shape + master_location: LB # LB + + +apps: + - name: pc1 + start_time_ms: 0 #any unsigned integer number + - name: pc2 + start_time_ms: 1ms #any unsigned integer number diff --git a/testcases/teste_2x2_vhdl.yaml b/testcases/teste_2x2_vhdl.yaml new file mode 100644 index 0000000..2266430 --- /dev/null +++ b/testcases/teste_2x2_vhdl.yaml @@ -0,0 +1,16 @@ +hw: + page_size_KB: 32 + tasks_per_PE: 1 + repository_size_MB: 1 + model_description: vhdl # sc (gcc) | scmod (questa) | vhdl + noc_buffer_size: 8 # must be power of 2 + mpsoc_dimension: [2,2] # for while, must be a square shape + cluster_dimension: [2,2] # for while, must be a square shape + master_location: LB # LB + + +apps: + - name: pc1 + start_time_ms: 0 #any unsigned integer number + - name: pc2 + start_time_ms: 1ms #any unsigned integer number diff --git a/testcases/teste_2x2_vhdl_ativ2.yaml b/testcases/teste_2x2_vhdl_ativ2.yaml new file mode 100644 index 0000000..87eb331 --- /dev/null +++ b/testcases/teste_2x2_vhdl_ativ2.yaml @@ -0,0 +1,15 @@ +hw: + page_size_KB: 32 + tasks_per_PE: 1 + repository_size_MB: 1 + model_description: vhdl # sc (gcc) | scmod (questa) | vhdl + noc_buffer_size: 8 # must be power of 2 + mpsoc_dimension: [2,2] # for while, must be a square shape + cluster_dimension: [2,2] # for while, must be a square shape + master_location: LB # LB + + +apps: + - name: pc1 + start_time_ms: 0 #any unsigned integer number + diff --git a/testcases/teste_2x2_vhdl_ativ4.yaml b/testcases/teste_2x2_vhdl_ativ4.yaml new file mode 100644 index 0000000..25e569e --- /dev/null +++ b/testcases/teste_2x2_vhdl_ativ4.yaml @@ -0,0 +1,15 @@ +hw: + page_size_KB: 32 + tasks_per_PE: 1 + repository_size_MB: 1 + model_description: vhdl # sc (gcc) | scmod (questa) | vhdl + noc_buffer_size: 8 # must be power of 2 + mpsoc_dimension: [2,2] # for while, must be a square shape + cluster_dimension: [2,2] # for while, must be a square shape + master_location: LB # LB + +apps: + - name: transmit + start_time_ms: 0 #any unsigned integer number + + diff --git a/testcases/teste_vhdl.yaml b/testcases/teste_vhdl.yaml new file mode 100644 index 0000000..dd9ef33 --- /dev/null +++ b/testcases/teste_vhdl.yaml @@ -0,0 +1,16 @@ +hw: + page_size_KB: 32 + tasks_per_PE: 1 + repository_size_MB: 1 + model_description: vhdl # sc (gcc) | scmod (questa) | vhdl + noc_buffer_size: 8 # must be power of 2 + mpsoc_dimension: [4,4] # for while, must be a square shape + cluster_dimension: [2,2] # for while, must be a square shape + master_location: LB # LB + + +apps: + - name: pc1 + start_time_ms: 0 #any unsigned integer number + - name: pc2 + start_time_ms: 1ms #any unsigned integer number