Altera_Forum
Honored Contributor
12 years agoFunctions Inclusion
Hello every body; I have created macros to deal with my hardware component and put them in a separate .c file, how can I include these macros in my main.c file. Thanks.
Good advice from u Mr.tzestan;
This is my base functions that i use in my main function ********************************************************************************************* /* *Description : AES input Output functions *File : "altera_avalon_aes.c" * * Created on: Jan 26, 2014 * Author: a4atmel */ # include "system.h" # include "altera_avalon_aes_regs.h" # include <io.h> alt_u8 c128=0x0; void Write_Array(alt_u8 array[4][4]) { int i,j; for (i=1;i<=4;i++) { for (j=1;j<=4;i++) { IOWR(InText_BASE,4*(i-1)+j,array[j]);}
}
}
void write_key1(alt_u8 array[4][8])
{
int i,j;
for (i=1;i<=4;i++)
{
for (j=1;j<=4;i++)
{
iowr(cipherkey1_base,4*(i-1)+j,array[j]); } } } void Write_key2(alt_u8 array[4][8]) { int i,j; for (i=1;i<=4;i++) { for (j=1;j<=4;i++) { IOWR(Cipherkey2_BASE,4*(i-1)+j,array[4+i][4+j]); } } } void Read_Array(alt_u8 array[4][4]) { int i,j; for (i=1;i<=4;i++) { for (j=1;i<=4;i++) { array[i][j]=IORD(OutText_BASE,4*(i-1)+j); } } } void Cipher128(alt_u8 InText[4][4],alt_u8 Cipherkey[4][8],alt_u8 OutText[4][4]) { Write_key1(Cipherkey); Write_Array(InText); keylen(c128); Cipher; start; Read_Array(OutText); stop; } **************************************************** And this is my main function /* * Description : AES main function * File : main.c" * * Created on: Jan 26, 2014 * Author: a4atmel */ # include "system.h" # include "altera_avalon_aes_regs.c" # include "altera_avalon_aes.h" # include <io.h> int main() { // Declarations and Initializations alt_u8 InText[4][4] = { {0xAE, 0x1E, 0x9E, 0x45}, {0x2D, 0x03, 0xB7, 0xAF}, {0x8A, 0xAC, 0x6F, 0x8E}, {0x57, 0x9C, 0xAC, 0x51} }; alt_u8 Cipherkey[4][8] = { {0x2B, 0x28, 0xAB, 0x09, 0x0, 0x0, 0x0,0x0}, {0x7E, 0xAE, 0xF7, 0xCF, 0x0, 0x0, 0x0,0x0}, {0x15, 0xD2, 0x15, 0x4F, 0x0, 0x0, 0x0,0x0}, {0x16, 0xA6, 0x88, 0x3C, 0x0, 0x0, 0x0,0x0} }; alt_u8 OutText[4][4]; Cipher128(InText,Cipherkey,OutText); return 0; }