/*** * Hardware_Tools.c * module "boite à outils" pour les modules du simulation du matériel. * * voir hardware.ps pour le detail du matériel simulé par cette bibliothèque. * */ #include #include #include #include #include #include #include #include #include #include #include #include "Hardware.h" #include "Hardware_Tools.h" /** * table des handlers de ticks élémentaires de simulation */ struct sTickHandler { int used; int rate; int next; funcHandler callback; } ; #define MAXTICKHANDLERS 16 static struct sTickHandler tickHandler[MAXTICKHANDLERS]; int Debug = 0 ; char *BaseOfSharedMem = NULL ; char *TopOfSharedMem = NULL ; int *pSigKey = NULL ; int main_pid = 0 ; /** * Fonction de trace de debuggage */ void trace(int type, const char *msg, ...) { static int isANewLine = 1; int i; char buffer[2048]; va_list args; buffer[0] = '\0'; if( (Debug & type) != type) return ; if(isANewLine) { isANewLine=0; fprintf(stderr,"<"); if( (Debug & DEBUG_WARNING) ) { if( (type & DEBUG_WARNING) ) fprintf(stderr,"W"); else fprintf(stderr,"-"); } if( (Debug & DEBUG_SETUP) ) { if( (type & DEBUG_SETUP) ) fprintf(stderr,"S"); else fprintf(stderr,"-"); } if( (Debug & DEBUG_HWREG) ) { if( (type & DEBUG_HWREG) ) fprintf(stderr,"R"); else fprintf(stderr,"-"); } if( (Debug & DEBUG_IT) ) { if( (type & DEBUG_IT) ) fprintf(stderr,"I"); else fprintf(stderr,"-"); } fprintf(stderr,">"); } va_start(args,msg); vsprintf(buffer+strlen(buffer),msg,args); va_end(args); for(i=0;i<2048 && buffer[i]!='\0'; i++) { if(buffer[i]=='\n') { isANewLine = 1; break; } } fprintf(stderr,buffer); fflush(stderr); } /** * IRQ Managment... */ static volatile int currentIRQMask = 16; static volatile int lastIRQCalled = 0; int isIRQHiden(int IRQLevel) { if(IRQLevel < currentIRQMask) return 1; lastIRQCalled = IRQLevel; return 0; } void setIRQMask(int IRQLevel) { currentIRQMask = IRQLevel; } void waitIRQ(int IRQLevel) { int t = currentIRQMask; currentIRQMask = 0; lastIRQCalled = 0; while(lastIRQCalled < IRQLevel) { pause(); } currentIRQMask = t; } /** * ajouter une fonction à appeler toutes les "rate" SYSTICKS */ int addTickHandler(int next, int rate, funcHandler callback) { int i; for(i=0;i