//*****************************************************************************
//
// This function is called to stop an acquisition running.  It disables the
// ADC sequencers and the RTC match interrupt.
//
//*****************************************************************************
void
AcquireStop(void)
{
    //
    // Disable RTC interrupts
    //
    MAP_IntDisable(INT_HIBERNATE);

    //
    // Disable ADC interrupts
    //
    MAP_IntDisable(INT_ADC0SS0);
    MAP_IntDisable(INT_ADC1SS0);

    //
    // Disable ADC sequencers
    //
    MAP_ADCSequenceDisable(ADC0_BASE, 0);
    MAP_ADCSequenceDisable(ADC1_BASE, 0);

    //
    // If USB stick is being used, then close the file so it will flush
    // the buffers to the USB stick.
    //
    if(g_psConfigState->ui8Storage == CONFIG_STORAGE_USB)
    {
        USBStickCloseFile();
    }

    //
    // Disable the configuration pointer, which acts as a flag to indicate
    // if we are properly configured for data acquisition.
    //
    g_psConfigState = 0;
}
Beispiel #2
0
//*****************************************************************************
//
// Saves data records that are stored in the flash to an externally connected
// USB memory storage device (USB stick).
// The flash memory is scanned for the presence of store data records.  When
// records are found they are written in CSV format to the USB stick.  This
// function assumes a non-corrupted storage area, and that any records, once
// found, are contiguous with all stored records.  It will find the oldest
// record and start with that when storing.
//
//*****************************************************************************
int
FlashStoreSave(void)
{
    unsigned long ulAddr;
    unsigned long ulOldestRecord = FLASH_STORE_START_ADDR;
    unsigned long ulOldestSeconds = 0xFFFFFFFF;
    tLogRecord *pRecord;

    //
    // Show a message to the user.
    //
    SetStatusText("SAVE", "SCANNING", "FLASH", 0);

    //
    // Start at beginning of flash storage area
    //
    ulAddr = FLASH_STORE_START_ADDR;

    //
    // Search all of flash area checking every stored record.
    //
    while(ulAddr < FLASH_STORE_END_ADDR)
    {
        //
        // If a record signature is found, check for oldest record, then
        // increment to the next record
        //
        if((HWREG(ulAddr) & 0xFFFFFF00) == 0x53554100)
        {
            //
            // Get a pointer to the data record (account for flash header word)
            //
            pRecord = (tLogRecord *)(ulAddr + 4);

            //
            // If the seconds in this record are older than any found so far
            // then save the seconds value, and the address of this record
            //
            if(pRecord->ulSeconds < ulOldestSeconds)
            {
                ulOldestSeconds = pRecord->ulSeconds;
                ulOldestRecord = ulAddr;
            }

            //
            // Advance the address to the next record.
            //
            ulAddr += HWREG(ulAddr) & 0xFF;
        }

        //
        // Otherwise a record was not found so just advance to the next
        // location in flash
        //
        else
        {
            ulAddr += 4;
        }
    }

    //
    // If no "oldest" seconds was found, then there is no valid data stored
    //
    if(ulOldestSeconds == 0xFFFFFFFF)
    {
        SetStatusText("SAVE", "NO RECORDS", "FOUND", "PRESS <");
        return(1);
    }

    //
    // Open the output file on the USB stick.  It will return NULL if there
    // was any problem.
    //
    if(!USBStickOpenLogFile(0))
    {
        SetStatusText("SAVE", 0, "USB ERROR", "PRESS <");
        return(1);
    }

    //
    // Notify user we are saving data to USB
    //
    SetStatusText("SAVE", "SAVING", "TO USB", 0);

    //
    // Start reading records from flash, start at the address of the oldest
    // record, as found above.  We scan through records, assuming the flash
    // store is not corrupted.  Continue scanning until a blank space is
    // found which should indicate the end of recorded data, or until we
    // have read all the records.
    //
    ulAddr = ulOldestRecord;
    while(HWREG(ulAddr) != 0xFFFFFFFF)
    {
        unsigned long ulCount;
        unsigned long ulPartialCount;

        //
        // If a record signature is found (which it should be), extract the
        // record data and send it to USB stick.
        //
        if((HWREG(ulAddr) & 0xFFFFFF00) == 0x53554100)
        {
            //
            // Get byte count for this record
            //
            ulCount = HWREG(ulAddr) & 0xFF;

            //
            // Adjust the count and the address to remove the flash header
            //
            ulCount -= 4;
            ulAddr += 4;

            //
            // Adjust for memory wrap
            //
            if(ulAddr >= FLASH_STORE_END_ADDR)
            {
                ulAddr = FLASH_STORE_START_ADDR;
            }

            //
            // If the contents of this record go past the end of the memory
            // storage area, then perform a partial copy first.
            //
            ulPartialCount = 0;
            if((ulAddr + ulCount) >= FLASH_STORE_END_ADDR)
            {
                //
                // Find how many bytes are left on this page
                //
                ulPartialCount = FLASH_STORE_END_ADDR - ulAddr;

                //
                // Copy the portion until the end of memory store, adjust
                // remaining count and address
                //
                memcpy(g_ulRecordBuf, (void *)ulAddr, ulPartialCount);
                ulCount -= ulPartialCount;
                ulAddr = FLASH_STORE_START_ADDR;
            }

            //
            // Copy entire record (or remaining part of record if memory wrap)
            // into record buffer
            //
            memcpy(&g_ulRecordBuf[ulPartialCount / 4], (void *)ulAddr,
                   ulCount);

            //
            // Update address pointer to next record
            //
            ulAddr += ulCount;

            //
            // Now we have an entire data logger record copied from flash
            // storage into a local (contiguous) memory buffer.  Pass it
            // to the USB file writing function to write the record to the
            // USB stick.
            //
            USBStickWriteRecord((tLogRecord *)g_ulRecordBuf);
        }

        //
        // This should not happen, but it means we ended up in a non-blank
        // location that is not the start of a record.  In this case just
        // advance through memory until either a blank location or another
        // record is found.
        //
        else
        {
            //
            // Increment to next word in flash, adjust for memory wrap.
            //
            ulAddr += 4;
            if(ulAddr >= FLASH_STORE_END_ADDR)
            {
                ulAddr = FLASH_STORE_START_ADDR;
            }
        }
    }

    //
    // Close the USB stick file so that any buffers will be flushed.
    //
    USBStickCloseFile();

    //
    // Inform user that save is complete.
    //
    SetStatusText("SAVE", "USB SAVE", "COMPLETE", "PRESS <");

    //
    // Return success
    //
    return(0);
}