Пример #1
0
/**
 * Close the CAN port.
 *
 * Parameters:
 *   local Pointer to the local data returned by CopleyCanOpen
 *
 * Returns:
 *    An error code or zero on success.
 */
int CopleyCanClose( void *local )
{
   uint32_t cmd[64];

   assert( local != NULL );

   // Close the CAN port
   cmd[0] = (CANCARD_CMD_CLOSEPORT<<16);
   ccSendCMD( local, cmd );

   // Close the handle to the driver
   return ccCloseFile( local );
}
Пример #2
0
/**
 * Open a CAN port on a Copley CAN card.
 *
 * Parameters:
 *   port  The port number to open.  Ports are numbered starting at zero.
 *         There are two ports for each card, so if the system contains
 *         N CAN cards, then legal port numbers range from 0 to 2*N-1.
 *
 *   baud  The baud rate to set the port to.  This should be one of the 
 *         values defined in the CopleyCAN.h header file.
 *
 *   error If an error occurs opening the card, an appropriate error code
 *         will be returned here.  This parameter may be passed as NULL
 *         if no error information is desired.
 *
 * Returns:
 *    A pointer to a local structure that should be passed to other functions.
 *    NULL will be returned on failure.
 */
void *CopleyCanOpen( int port, int baud, int *error )
{
   int err = 0;
   void *lcl;
   uint32_t cmd[64];

   // Allocate a structure to hold local data
   lcl = ccAllocLocals();
   if( lcl == NULL )
   {
      err = COPLEYCAN_ERR_ALLOC;
      goto done;
   }

   // Open a handle to the device driver
   err = ccOpenFile( port, lcl );
   if( err )
      goto freeLocals;

   // Set the port's baud rate
   cmd[0] = (CANCARD_CMD_SETBPS<<16) | 1;
   cmd[1] = baud;
   err = ccSendCMD( lcl, cmd );
   if( err ) goto closeHandle;

   // Open the CAN port
   cmd[0] = (CANCARD_CMD_OPENPORT<<16);
   err = ccSendCMD( lcl, cmd );
   if( err ) goto closeHandle;

   return lcl;

closeHandle:
   ccCloseFile( lcl );

freeLocals:
   ccFreeLocals( lcl );

done:
   if( *error ) *error = err;
   return NULL;
}
Пример #3
0
int main(int argc, char *argv[])
{
    char buffer[256];
    char *p;
    BOOLEAN multipleFiles = FALSE;
    int rv;
    char realOutFile[260];
    char oldOutFile[260];
    srand(time(0));

        /*   signal(SIGSEGV,internalError) ;*/
        /*   signal(SIGFPE, internalError) ;*/

    /* initialize back end */
    if (!init_backend(&argc,argv))
        fatal("Could not initialize back end");

    if (chosenAssembler->Args)
    {
        CMDLIST *newArgs = calloc(sizeof(Args) + sizeof(Args[0]) * chosenAssembler->ArgCount, 1);
        if (newArgs)
        {
            memcpy(&newArgs[0], chosenAssembler->Args, 
                   chosenAssembler->ArgCount *sizeof(Args[0]));
            memcpy(&newArgs[chosenAssembler->ArgCount], &Args[0], sizeof(Args));
            ArgList = newArgs;
        }
    }		
    /* parse environment variables, command lines, and config files  */
    ccinit(argc, argv);
    
    /* loop through and preprocess all the files on the file list */
    if (clist && clist->next)
        multipleFiles = TRUE;
#ifdef PARSER_ONLY
    strcpy(buffer, clist->data);
    strcpy(realOutFile, outfile);
    outputfile(realOutFile, buffer, ".ods");
    if (!ccDBOpen(realOutFile))
        fatal("Cannot open database file %s", realOutFile);
#else
    BitInit();
    regInit();
#endif
    while (clist)
    {
        cparams.prm_cplusplus = FALSE;
        strcpy(buffer, clist->data);
#ifndef PARSER_ONLY
        strcpy(realOutFile, outfile);
        if (cparams.prm_asmfile)
            outputfile(realOutFile, buffer, chosenAssembler->asmext);
        else
            outputfile(realOutFile, buffer, chosenAssembler->objext);
        strcpy(oldOutFile, realOutFile);
        StripExt(oldOutFile);
        AddExt(oldOutFile, ".tmp");
#else
        ccNewFile(buffer, TRUE);
#endif
        AddExt(buffer, ".C");
        p = strrchr(buffer, '.');
        if (*(p - 1) != '.')
        {
            if (p[1] == 'h' || p[1] == 'H') // compile H files as C++ for the IDE
                cparams.prm_cplusplus = TRUE;
            if (p[1] == 'c' || p[1] == 'C')
            if (p[2] == 'p' || p[2] == 'P')
            {
                if (p[3] == 'p' || p[3] == 'P')
                    cparams.prm_cplusplus = TRUE;
            }
            else
            {
                if (p[2] == 'x' || p[2] == 'X')
                {
                    if (p[3] == 'x' || p[3] == 'X')
                        cparams.prm_cplusplus = TRUE;
                }
            }
            else if ((p[2] == 'c' ||p[2] == 'C' ) && !p[3])
            {
                        cparams.prm_cplusplus = TRUE;
            }
            else
            {
                if (p[2] == '+')
                {
                    if (p[3] == '+')
                        cparams.prm_cplusplus = TRUE;
                }
            }
        }
        inputFile = SrchPth2(buffer, "", "r");
        if (!inputFile)
            fatal("Cannot open input file %s", buffer);
        strcpy(infile, buffer);
        if (cparams.prm_makestubs)
        {
            MakeStubs();
        }
        else
        {
#ifndef PARSER_ONLY
            unlink(oldOutFile);
            rename(realOutFile, oldOutFile);
            outputFile = fopen(realOutFile, cparams.prm_asmfile ? "w" : "wb");
            if (!outputFile)
            {
                fclose(inputFile);
                fatal("Cannot open output file %s", realOutFile);
            }
            setvbuf(outputFile,0,_IOFBF,32768);
#endif
             if (cparams.prm_cppfile)
            {
                StripExt(buffer);
                AddExt(buffer, ".i");
                strcpy(cppfile, buffer);
                cppFile = fopen(buffer, "w");
                if (!cppFile)
                {
                    fclose(inputFile);
                    fclose(outputFile);
                    fatal("Cannot open preprocessor output file %s", buffer);
                }
            }
            if (cparams.prm_listfile)
            {
                StripExt(buffer);
                AddExt(buffer, ".lst");
                listFile = fopen(buffer, "w");
                if (!listFile)
                {
                    fclose(inputFile);
                    fclose(cppFile);
                    fclose(outputFile);
                    fatal("Cannot open list file %s", buffer);
                }
            }
            if (cparams.prm_errfile)
            {
                StripExt(buffer);
                AddExt(buffer, ".err");
                errFile = fopen(buffer, "w");
                if (!errFile)
                {
                    fclose(inputFile);
                    fclose(cppFile);
                    fclose(listFile);
                    fclose(outputFile);
                    fatal("Cannot open error file %s", buffer);
                }
            }
            if (cparams.prm_browse)
            {
                char name[260];
                strcpy(name, outfile);
                StripExt(name);
                AddExt(name, ".cbr");
                browseFile = fopen(name, "wb");
                if (!browseFile)
                {   
                    fclose(errFile);
                    fclose(inputFile);
                    fclose(cppFile);
                    fclose(listFile);
                    fclose(outputFile);
                    fatal("Cannot open browse file %s", buffer);
                }
                setvbuf(browseFile,0,_IOFBF,32768);
            }
            if (cparams.prm_icdfile)
            {
                StripExt(buffer);
                AddExt(buffer, ".icd");
                icdFile = fopen(buffer, "w");
                if (!icdFile)
                {   
                    fclose(browseFile);
                    fclose(errFile);
                    fclose(inputFile);
                    fclose(cppFile);
                    fclose(listFile);
                    fclose(outputFile);
                    fatal("Cannot open error file %s", buffer);
                }
                setvbuf(icdFile,0,_IOFBF,32768);
            }
    
            if (multipleFiles && !cparams.prm_quiet)
                printf("%s\n", clist->data);
    
    
            compile();
        }
#ifdef PARSER_ONLY
        localFree();
#endif
        globalFree();
        if (cparams.prm_diag)
        {
            mem_summary();
            printf("Intermediate stats:\n");
               printf("  Block peak:          %d\n", maxBlocks);
               printf("  Temp peak:           %d\n", maxTemps);
               printf("  Allocation Spills:   %d\n", maxAllocationSpills);		
               printf("  Allocation Passes:   %d\n", maxAllocationPasses);		
               printf("  Allocation Accesses: %d\n", maxAllocationAccesses);
        }
        maxBlocks = maxTemps = maxAllocationSpills = maxAllocationPasses = maxAllocationAccesses = 0;
#ifdef PARSER_ONLY
        ccCloseFile(inputFile);
#else
        fclose(inputFile);
#endif
        if (outputFile)
            fclose(outputFile);
        if (cppFile)
            fclose(cppFile);
        if (listFile)
            fclose(listFile);
        if (errFile)
            fclose(errFile);
        if (browseFile)
            fclose(browseFile);
        if (icdFile)
            fclose(icdFile);
        
        if (total_errors)
        {
            unlink(realOutFile);
            rename(oldOutFile, realOutFile);
        }
        else
        {
            unlink (oldOutFile);
        }

        /* Flag to stop if there are any errors */
        stoponerr |= total_errors;

        clist = clist->next;
    }
    rv = !!stoponerr ;
    if (!cparams.prm_makestubs)
    {
        if (!cparams.prm_compileonly && !stoponerr) {
            rv = 0 ;
            if (chosenAssembler->compiler_postprocess)
            {
                char buf[260];
#ifdef MICROSOFT
                GetModuleFileNameA(NULL, buffer, sizeof(buffer));    
#else
                strcpy(buffer, argv[0]);
#endif
                rv = chosenAssembler->compiler_postprocess(buffer);
            }
        }
        if (chosenAssembler->rundown)
            chosenAssembler->rundown();
    }
    return rv;
}