Ejemplo n.º 1
0
Archivo: main.c Proyecto: atiselsts/osw
void prepareExtFlash(void)
{
    extFlashWake();

    // check if old records exist
    DataPacket_t packet;
    bool oneInvalid = false;

    extFlashAddress = EXT_FLASH_RESERVED;
    while (extFlashAddress < EXT_FLASH_SIZE) {
        extFlashRead(extFlashAddress, &packet, sizeof(packet));
        // PRINT("read packet:\n");
        // printPacket(&packet);
        bool valid = true;
        if (packet.crc != crc16((uint8_t *)&packet, sizeof(packet) - sizeof(uint16_t))) {
            valid = false;
        } else {
            if (packet.dataSeqnum == 0) valid = false;
        }

        if (valid) {
            oneInvalid = false;
        } else {
            // XXX: this is supposed to find first non-packet, but it will find first two invalid packets!!
            if (!oneInvalid) {
                oneInvalid = true;
            } else {
                extFlashAddress -= sizeof(packet);
                break;
            }
        }
        extFlashAddress += sizeof(packet);
    }
    PRINTF("flash packet offset=%lu\n", extFlashAddress - EXT_FLASH_RESERVED);
}
Ejemplo n.º 2
0
//-------------------------------------------
//      Entry point for the application
//-------------------------------------------
void appMain(void)
{
    PRINTF("\n\nAccelerometer data gathering app\n");

    extFlashWake();

    // start with clean and new...
    cleanFlash();

    accelOn();

    userButtonEnable(onUserButton);

    mdelay(START_DELAY);

    uint16_t lastSecond;
    uint16_t samplesPerSecond;

    for (;;) {
        while (!isActiveMode);

        redLedOn();

        lastSecond = getTimeSec();
        samplesPerSecond = 0;

        uint16_t i;
        for (i = 0; isActiveMode; i++) {
            if (i % 10 == 0) redLedToggle();

            uint32_t now = getTimeMs();
            uint32_t endTime = now + MAIN_LOOP_LENGTH;

            Packet_t p;
            p.timestamp = now;

            p.acc_x = accelReadX();
            p.acc_y = accelReadY();
            p.acc_z = accelReadZ();

            printPacket(&p);

            samplesPerSecond++;

            uint16_t currentSecond = getTimeSec();
            if (currentSecond != lastSecond) {
                PRINTF("samples per second = %u\n", samplesPerSecond);
                lastSecond = currentSecond;
                samplesPerSecond = 0;
            } 

            while (timeAfter32(endTime, getTimeMs()));
        }

        redLedOff();
    }
}
Ejemplo n.º 3
0
Archivo: main.c Proyecto: atiselsts/osw
bool prepareExtFlash(void)
{
     extFlashWake();
     extFlashAddress = EXT_FLASH_RESERVED;

//     // check if old records exist
//     Record_t old;
//     extFlashRead(EXT_FLASH_RESERVED, &old, sizeof(old));
//     if (old.magicNumber == MAGIC_NUMBER
//             && old.crc == crc16((uint8_t *)&old, sizeof(Record_t) - sizeof(uint16_t))) {
//         return true;
//     }
//     return false;

     return true;
}
Ejemplo n.º 4
0
int main(void)
{
    // Make sure all interrupts are disabled.
    // This must be the first step, because in some cases interupt vectors are totally wrong
    // (e.g. when we get here after a soft reboot from another application)
    msp430ClearAllInterruptsNosave();

    msp430WatchdogStop();

    ledsInit();

    flashLeds(LEDS_BOOTLOADER_START);

    BootParams_t bootParams;
    intFlashRead(BOOT_PARAMS_ADDRESS, &bootParams, sizeof(bootParams));

    ++bootParams.bootRetryCount;
    if (bootParams.bootRetryCount > MAX_RETRY_COUNT) {
        bootParams.bootRetryCount = 0;
        bootParams.extFlashAddress = GOLDEN_IMAGE_ADDRESS;
        bootParams.doReprogramming = 1;
    }

    // make sure internal flash address is sane
    if (bootParams.intFlashAddress == 0xffff || bootParams.intFlashAddress < BOOTLOADER_END) {
        bootParams.intFlashAddress = SYSTEM_CODE_START;
    }

    // read voltage, and quit if not enough for writing in flash
    if (readVoltage() < THRESHOLD_VOLTAGE) {
        flashLeds(LEDS_LOW_BATTERY);
        goto exec;
    }

    // write the updated info back in flash
    intFlashErase(BOOT_PARAMS_ADDRESS, sizeof(bootParams));
    intFlashWrite(BOOT_PARAMS_ADDRESS, &bootParams, sizeof(bootParams));

    if (bootParams.doReprogramming) {
        redLedOn();

        // will be using external flash
        extFlashInit();
        extFlashWake();

        uint32_t extAddress = bootParams.extFlashAddress;

        // read number of blocks
        uint16_t imageBlockCount;
        extFlashRead(extAddress, &imageBlockCount, sizeof(uint16_t));
        extAddress += 2;

        while (imageBlockCount) {
            // read a block from external flash
            ExternalFlashBlock_t block;
            extFlashRead(extAddress, &block, sizeof(block));

            if (block.crc != crc16((uint8_t *)&block, sizeof(block) - 2)) {
                // the best we can do is to reboot now;
                // after a few tries the golden image will be loaded
                flashLeds(LEDS_CRC_ERROR);
                // no need to disable all of the interrupts (they already are),
                // just write in watchdog timer wihout password, it will generate reset.
                watchdogRebootSimple();
            }

            bool firstBlockInChunk = block.address & 0x1;
            block.address &= ~0x1;
            if (firstBlockInChunk) {
                // prepare internal flash to be written
                intFlashErase(block.address, INT_FLASH_SEGMENT_SIZE);
            }

            // program internal flash
            COMPILE_TIME_ASSERT(sizeof(block.data) == INT_FLASH_BLOCK_SIZE, ifs);
            intFlashWriteBlock(block.address, block.data, INT_FLASH_BLOCK_SIZE);

            --imageBlockCount;
            extAddress += sizeof(ExternalFlashBlock_t);
        }

        extFlashSleep();
        redLedOff();
    }

#if ENABLE_BOOT_DELAY
    // delay for a second or so to allow the user to interrupt booting (by pressing the reset button)
    flashLeds(LEDS_BOOTLOADER_END);
#endif

    // execute the program
  exec:
    ((ApplicationStartExec)bootParams.intFlashAddress)();
}
Ejemplo n.º 5
0
bool prepareExtFlash(void)
{
     extFlashWake();
     extFlashAddress = EXT_FLASH_RESERVED;
     return true;
}