Esempio n. 1
0
/**
 * @fn void WriteMyFlashedRSCP(unsigned char radio, unsigned char setting, unsigned char channel, unsigned char power)
 *
 * @brief This function writes the node's indices for current radio, config, 
 *        channel and power, into flash
 *
 * @param radio an unsigned char
 * @param setting an unsigned char
 * @param channel an unsigned char
 * @param power an unsigned char
 */
void WriteMyFlashedRSCP(unsigned char radio, unsigned char setting, unsigned char channel, unsigned char power) 
{
  unsigned long rscp = 0;
  rscp = power;
  rscp = (rscp << 8) | channel;
  rscp = (rscp << 8) | setting;
  rscp = (rscp << 8) | radio;
  FlashWriteBuffer(&MyFlashStorage.myRSCP.radio, (unsigned char*)&rscp, sizeof(rscp)); // Write my owm RSCP settings to flash.                              
}
Esempio n. 2
0
/**
 * @fn uint8_t SetApplicationState(__ApplicationState state) 
 *
 * @brief This function sets the application state of the node. If flash storage
 *        is included, it writes the state to flash.
 *
 * @param state an __ApplicationState enumeration
 *
 * @return an unsigned int
 */
uint8_t SetApplicationState(__ApplicationState state) 
{
  #ifdef INCLUDE_FLASH_STORAGE
    FlashWriteBuffer((unsigned char *)&MyFlashStorage.myAppState, (unsigned char *)&state, sizeof(state)); // Write the new application state to flash.
  #endif
  ApplicationState = state;                                                     // Change application state.
  #ifdef __COMMAND_INTERFACE
    ApplicationChanged();                                                       // Report to GUI that the application state has been changed.
  #endif
  return 1;
}
Esempio n. 3
0
void main(void)
{
	static char code[6];

	CPU_Init();
	Flash_Init();
	GPRS_Init();
	LCD_Init();
	Clr_LCDRam();
	LCD_LIGHT_ON;
	Dis_Logo();

	//#define FLASH_DEBUG
#ifdef FLASH_DEBUG
	while (1) {
		char checknum[32];
		INT16U cnt, offset;
		RECORD_HEAD_T head;
		RECORD_ITEM_T item;

		Format_AllHistoryRecord();

		for (cnt = 0; cnt < MAX_ALARM_NUM; cnt++) {
			FlashMemoryToBufferTransfer(cnt, FLASHBUFFER1);
			memset(&head, 0, sizeof(RECORD_HEAD_T));
			offset = OFFSET_OF(RECORD_T, info);
			FlashReadBuffer(offset, &head, sizeof(RECORD_HEAD_T), FLASHBUFFER1);
		}

		memset(&head, 0, sizeof(RECORD_HEAD_T));
		sprintf(head.mn, "98765432101234");
		Format_HistoryRecord(0, &head);

		FlashMemoryToBufferTransfer(0, FLASHBUFFER1);
		memset(&head, 0, sizeof(RECORD_HEAD_T));
		offset = OFFSET_OF(RECORD_T, info);
		FlashReadBuffer(offset, &head, sizeof(RECORD_HEAD_T), FLASHBUFFER1);

		memset(&item, 0, sizeof(RECORD_ITEM_T));
		sprintf(item.datetime, "12345678901234");
		item.inuse = 1;
		item.status = 'O';
		Add_HisRecordItem(&item, 0);

		FlashMemoryToBufferTransfer(0, FLASHBUFFER1);
		memset(&head, 0, sizeof(RECORD_HEAD_T));
		offset = OFFSET_OF(RECORD_T, info);
		FlashReadBuffer(offset, &head, sizeof(RECORD_HEAD_T), FLASHBUFFER1);

		Fetch_HisRecord(0);
		memset(&item, 0, sizeof(RECORD_ITEM_T));
		Get_HisRecordItemsBackward(&item, 1);

		FlashWriteBuffer(0, "asdfghjklqwertyuiop", 32, FLASHBUFFER1);
		memset(checknum, 0, sizeof(checknum));
		FlashReadBuffer(0, checknum, 32, FLASHBUFFER1);

		FlashBufferToMemoryWithErase(0, FLASHBUFFER1);
		memset(checknum, 0, sizeof(checknum));
		FlashReadBuffer(0, checknum, 32, FLASHBUFFER1);

		FlashMemoryToBufferTransfer(0, FLASHBUFFER1);
		memset(checknum, 0, sizeof(checknum));
		FlashReadBuffer(0, checknum, 32, FLASHBUFFER1);

		FlashReadMemoryContinus(0, 0, checknum, 32);
		memset(checknum, 0, sizeof(checknum));
		FlashReadBuffer(0, checknum, 32, FLASHBUFFER1);

		//FlashMemoryErasePage(0, 1);
		FlashClearMemory(0, 0, 32);
		memset(checknum, 0, sizeof(checknum));
		FlashReadBuffer(0, checknum, 8, FLASHBUFFER1);

		FlashWriteMemoryThroughBuffer(0, 0, "ABCDEFGHIJKLMNOP", 8, FLASHBUFFER1);
		memset(checknum, 0, sizeof(checknum));
		FlashReadBuffer(0, checknum, 8, FLASHBUFFER1);
	}
#endif

	Read_VersionCode(code);
	if (memcmp(code, VersionCode, 6) == 0) {
		Read_SysParam(&Sys_Param);
		Read_ADParam(Ad_Param);
		Read_ComParam(&Com_Param);
		Read_AlarmParam(Alarm_Param);
	} else {
		Default_SysParam(&Sys_Param);
		Default_ADParam(Ad_Param);
		Default_ComParam(&Com_Param);
		Default_AlarmParam(Alarm_Param);
		Save_SysParam(&Sys_Param);
		Save_ADParam(Ad_Param);
		Save_ComParam(&Com_Param);
		Save_AlarmParam(Alarm_Param);
		Save_VersionCode((char *) VersionCode);
		Format_AllHistoryRecord();
	}
	Read_ADCalibParam(&Ad_CalibParam);
	Fix_ADCalibParam(&Ad_CalibParam);
	ADParam_Calculate();

	v_Get1302(System_TimeStr, &Current_Tm);
	strcpy((char *) System_StartTimeStr, (char *) System_TimeStr);
	Dis_Welcome(1);

	IS752_Init(9600, COM2);
	IS752_Init(9600, COM3);
	IS752_Init(9600, COM4);
	IS752_Init(9600, COM5);
	Modbus_Init();
	ModbusIO_Init();
	InitHjt212();
	ENABLEINT();

	while (1) {
		SoftWDT_Flag = 0;
		ProcRunLED();
		ProcAlarm();
		ProcRTC();
		ProcDIO();
		//ProcADC();
		ProcessModbusSlave();
		//ProcessModbus();
		//ProcessModbusIO();
		//ProcData();
		ProcDisplay();
		ProcessHjt212();
	}
}
Esempio n. 4
0
/**
 * @fn void WriteMyFlashedPairedID(unsigned char index, unsigned long ID) 
 *
 * @brief This function writes the ID of the paired node into flash.
 *
 * @param index an unsigned char
 * @param ID an unsigned long
 */
void WriteMyFlashedPairedID(unsigned char index, unsigned long ID) 
{
  FlashWriteBuffer((unsigned char *)&MyFlashStorage.myNodeIDs.myPairedNodeID[index-1], (unsigned char *)&ID, sizeof(ID)); // Write the ID of the paired node to Flash
}
Esempio n. 5
0
/**
 * @fn void WriteMyFlashedID(unsigned long ID) 
 *
 * @brief This function writes the node's own ID into flash
 *
 * @param ID an unsigned long
 */
void WriteMyFlashedID(unsigned long ID) 
{
  FlashWriteBuffer((unsigned char *)&MyFlashStorage.myNodeIDs.myNodeID, (unsigned char *)&ID, sizeof(ID)); //Write my node ID to flash.
}
Esempio n. 6
0
static void ProcessUpdateCommand( WORD unused )
{
    WORD writeAddr;

    switch( Cmd.command ) {
        case UC_WRITE_BOOT:
            V2( EventLogAdd( EVENTLOG_UPDATER_WRITE_BOOT ) );
            writeAddr = PMU430_BOOT_UPDATE_START + UpdateBytesWritten;
            // make sure we arn't going to write past the end of flash
            // CmdIndex is the number of bytes received in this transaction to be written
            if( (DWORD)(writeAddr + CmdIndex) > PMU430_BOOTAPP_END ) {
                UpdateResponse = UR_TOO_LARGE;
                break;
            }
            FlashWriteBuffer( writeAddr, Cmd.payload, CmdIndex );

            UpdateBytesWritten += CmdIndex;

            break;
        case UC_WRITE_APP:
            V2( EventLogAdd( EVENTLOG_UPDATER_WRITE_APP ) );
            writeAddr = (WORD)RocketMetrics.AppImage + UpdateBytesWritten;
            // make sure we arn't going to write past the end of flash
            // CmdIndex is the number of bytes received in this transaction to be written
            if( (DWORD)(writeAddr + CmdIndex) > PMU430_BOOTAPP_END ) {
                UpdateResponse = UR_TOO_LARGE;
                break;
            }
            FlashWriteBuffer( writeAddr, Cmd.payload, CmdIndex );

            UpdateBytesWritten += CmdIndex;

            break;

        case UC_PREP_BOOT:
            {
                V1( EventLogAdd( EVENTLOG_UPDATER_PREP_BOOT ) );
                UpdateBytesWritten = 0;

                // don't allow app calls anymore since we are wiping the APP section
                if( AppCallsAllowed ) {
                    AppExitpoint();
                    // Exitpoint doesn't disable the UTC, so do it now
                    UtcDisable();
                    AppCallsAllowed = FALSE;
                }

                UpdateSize = (Cmd.payload[0]<<8) + Cmd.payload[1];
                if( UpdateSize > PMU430_MAX_BOOT_SIZE ) {
                    UpdateResponse = UR_TOO_LARGE;
                    break;
                }

                // Erase enough space for the code update to be written to
                writeAddr = PMU430_BOOT_UPDATE_START;
                while( writeAddr < UpdateSize+PMU430_BOOT_UPDATE_START ) {
                    EventLogAddN( EVENTLOG_UPDATER_ERASE_SEG, writeAddr );
                    FlashEraseSegment( writeAddr );
                    writeAddr += PMU430_FLASH_SEGMENT_SIZE;
                }
            }
            break;
        case UC_VERIFY_BOOT:
            {

                // verify image is valid as well as the 2 CRC's at the
                // start of the image
                WORD crcHost = (Cmd.payload[0]<<8) + Cmd.payload[1];
                WORD pairCrcHost = (Cmd.payload[2]<<8) + Cmd.payload[3];

                V1( EventLogAdd( EVENTLOG_UPDATER_VERIFY_BOOT ) );

                if( !IsImageValid( (ImageInfo*)PMU430_BOOT_UPDATE_START, crcHost, pairCrcHost ) ) {
                    UpdateResponse = UR_BADCRC;
                } else {
                    // now that we have a valid image ready to be loaded,
                    // flag it
                    WriteBootloaderMsg( FLASHMSG_APPLY_BOOT_UPDATE, crcHost );

                    // Trigger a full reset sequence that also resets the PMU430 core
                    // - Don't trust the host processor to do this for us (for now?)
                    #if !defined( PLATFORM_RIMEVALBOARD )
                    HostCtrlInitiateReset( RESET_COOKIE_INITIATED_UPDATER, RESET_PMU430_CORE | RESET_LCD_IO );
                    #endif
                }
            }
            break;
        case UC_CHECK_UPDATE:
            {
                WORD crcBootHost = (Cmd.payload[0]<<8) + Cmd.payload[1];
                WORD crcAppHost = (Cmd.payload[2]<<8) + Cmd.payload[3];

                V1( EventLogAdd( EVENTLOG_UPDATER_CHECK_UPDATE ) );

                if( crcBootHost != RocketMetrics.BootImage->crc ||
                    crcAppHost != RocketMetrics.BootImage->pairCrc ) {

                    UpdateResponse = UR_BOOT_REQ_UPDATE;

                } else if( !AppCallsAllowed ||
                           crcBootHost != RocketMetrics.AppImage->pairCrc ||
                           crcAppHost != RocketMetrics.AppImage->crc ) {

                    UpdateResponse = UR_APP_REQ_UPDATE;
                } else {
                    UpdateResponse = UR_SUCCESS;
                }
                break;
            }
        case UC_PREP_APP:
            {
                V1( EventLogAdd( EVENTLOG_UPDATER_PREP_APP ) );
                UpdateBytesWritten = 0;

                // don't allow app calls anymore since we are wiping the APP section
                if( AppCallsAllowed ) {
                    AppExitpoint();
                    AppCallsAllowed = FALSE;
                }

                UpdateSize = (Cmd.payload[0]<<8) + Cmd.payload[1];
                if( UpdateSize > (PMU430_BOOTAPP_END - (WORD)RocketMetrics.AppImage) ) {
                    UpdateResponse = UR_TOO_LARGE;
                    break;
                }

                // erase the APP image section so it can accept the update
                writeAddr = (WORD)RocketMetrics.AppImage;
                while( writeAddr < UpdateSize+(WORD)RocketMetrics.AppImage ) {
                        EventLogAddN( EVENTLOG_UPDATER_ERASE_SEG, writeAddr );
                        FlashEraseSegment( writeAddr );
                        writeAddr += PMU430_FLASH_SEGMENT_SIZE;
                }

            }
            break;

        case UC_VERIFY_APP:
            {
                V1( EventLogAdd( EVENTLOG_UPDATER_VERIFY_APP ) );
                if( !IsImageValid( (ImageInfo *)RocketMetrics.AppImage, RocketMetrics.BootImage->pairCrc, RocketMetrics.BootImage->crc ) ) {
                    UpdateResponse = UR_BADCRC;
                } else {
                    AppCallsAllowed = TRUE;
                    EventLogAdd( EVENTLOG_RTC_INIT );
                    UtcInit();
                    // Run the AppInit code now that we have it up and running
                    RocketMetrics.AppImage->entrypoint();
                }
            }
            break;
        case UC_BLOW_JTAG_FUSE:
            {
                if( Cmd.payload[0] == 0xDE && Cmd.payload[1] == 0xAD ) {
#if defined( JTAG_FUSE_BLOW_ENABLED )
                    V1( EventLogAdd( EVENTLOG_UPDATER_BLOW_JTAG_FUSE ) );
                    // kill the fuse :(
                    BlowJtagAccessFuse();
#else
                    // if the build doesn't allow this, be a bit more descriptive then FAILURE
                    UpdateResponse = UR_UNKNOWN_COMMAND;
#endif
                } else {
                    UpdateResponse = UR_FAILURE;
                }
            }
            break;
        case UC_IS_JTAG_ENABLED:
            {
                if( !IsJtagEnabled() ) {
                    // FAILURE in this case, means JTAG isn't available
                    UpdateResponse = UR_FAILURE;
                }
            }
            break;
        default:
            UpdateResponse = UR_UNKNOWN_COMMAND;
            break;
    }

    if( UpdateResponse == UR_BUSY ) {
        UpdateResponse = UR_SUCCESS;
    }
}