Beispiel #1
0
void Udp::read_handler(
      const boost::system::error_code& error,
      size_t bytes_transferred
)
{
   if ( !error ) {                             /* Data received with no error */

      /* Construct a new msg event indicating that a msg has been received */
      MsgData_t msg;
      memset(&msg, 0, sizeof(msg));
      msg.src = _DC3_EthCli;
      msg.dst = _DC3_EthCli;
      msg.dataLen = bytes_transferred;
      memcpy( msg.dataBuf, read_msg_, msg.dataLen );

      /* Put the data into the queue for ClientApi to read */
      if(!this->m_pQueue->push(msg)) {
         ERR_printf( m_pLog, "Unable to push data into queue.");
      }
   } else {
      ERR_printf(this->m_pLog, "Unable to read UDP data");
   }

   read_some();                                           /* Continue reading */
}
Beispiel #2
0
static const DC3Error_t FLASH_writeUint32(
    const uint32_t addr,
    const uint32_t data
)
{
    uint32_t data_read = 0;
    FLASH_Status flash_status = FLASH_COMPLETE;
    DC3Error_t status = ERR_NONE;

    /* These flags have to be cleared before any operation can be done on the
     * flash memory */
    FLASH_ClearFlag(
        FLASH_FLAG_PGSERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGAERR |
        FLASH_FLAG_WRPERR |	FLASH_FLAG_OPERR | FLASH_FLAG_EOP
    );

    flash_status = FLASH_ProgramWord(addr, data);
    if (FLASH_COMPLETE != flash_status) {
        status = FLASH_statusToErrorCode( flash_status );
        ERR_printf("Flash Error %d writing %lx to addr %lx. Error: 0x%08x\n",
                   flash_status, data, addr, status);
        return( status );
    } else {
        data_read = *((uint32_t *)addr);
        if (data_read != data) {
            status = ERR_FLASH_READ_VERIFY_FAILED;
            ERR_printf("Failed to verify write at addr %lx : Wrote %2lx and "
                       "read back %2lx. Error: 0x%08x\n", addr, data, data_read, status);
            return( status );
        }
    }

    return( status );
}
Beispiel #3
0
/*${AOs::FlashMgr::SM::Active::BusyFlash} ..................................*/
static QState FlashMgr_BusyFlash(FlashMgr * const me, QEvt const * const e) {
    QState status_;
    switch (e->sig) {
        /* ${AOs::FlashMgr::SM::Active::BusyFlash} */
        case Q_ENTRY_SIG: {
            /* Arm the timer so if the message can't be processed for some reason, we can get
             * back to idle state.  This timer may be re-armed if some messages require more
             * time to process than others. */
            QTimeEvt_rearm(                         /* Re-arm timer on entry */
                &me->flashTimerEvt,
                SEC_TO_TICKS( HL_MAX_TOUT_SEC_FLASH_FW )
            );

            FLASH_Unlock();/* Always unlock the flash on entry since we'll be doing stuff to it */

            /* Reset all the variables that keep track of FW upgrades on entry so they are
             * guaranteed to be cleared when we start any new operation */
            memset( me->flashSectorsToErase, 0, sizeof(me->flashSectorsToErase) );
            me->flashSectorsToEraseIndex = 0;
            me->flashSectorsToEraseNum = 0;
            me->fwPacketCurr = 0;
            me->fwPacketExp  = 0;
            me->retryCurr    = 0;
            status_ = Q_HANDLED();
            break;
        }
        /* ${AOs::FlashMgr::SM::Active::BusyFlash} */
        case Q_EXIT_SIG: {
            QTimeEvt_disarm(&me->flashTimerEvt); /* Disarm timer on exit */

            FLASH_Lock();     /* Always lock the flash on exit */

            /* Always send a flash status event to the CommMgr AO with the current error code */
            FlashStatusEvt *evt = Q_NEW(FlashStatusEvt, FLASH_OP_DONE_SIG);
            evt->errorCode = me->errorCode;
            QACTIVE_POST(AO_CommMgr, (QEvt *)(evt), AO_FlashMgr);
            status_ = Q_HANDLED();
            break;
        }
        /* ${AOs::FlashMgr::SM::Active::BusyFlash::FLASH_TIMEOUT} */
        case FLASH_TIMEOUT_SIG: {
            ERR_printf("Timeout trying to process flash request, error: 0x%08x\n", me->errorCode);
            status_ = Q_TRAN(&FlashMgr_Idle);
            break;
        }
        /* ${AOs::FlashMgr::SM::Active::BusyFlash::FLASH_ERROR} */
        case FLASH_ERROR_SIG: {
            ERR_printf("Unable to to process flash request. Error: 0x%08x\n", me->errorCode);

            status_ = Q_TRAN(&FlashMgr_Idle);
            break;
        }
        default: {
            status_ = Q_SUPER(&FlashMgr_Active);
            break;
        }
    }
    return status_;
}
Beispiel #4
0
static	int	xmpl_scan_read( POINTER data, int scan, POINTER** line_buff )
{
    int		ct;			/* Channel counter		*/
    long	offset;			/* Offset into file		*/
    int		scan_bytes;		/* Bytes per row in the file	*/
    int		width;			/* Width of a row in the file	*/
    XMPL_FILE	*xmpl_file;		/* Our pertinent info on file	*/


    xmpl_file = (XMPL_FILE *) data;
    scan_bytes = xmpl_file->xf_im_win.right - xmpl_file->xf_im_win.left + 1;
    width = scan_bytes * xmpl_file->xf_size_mult;
    offset = scan * width + sizeof( XMPL_HDR );


    /*
     *  Check for a valid scanline -- position file for read is required.
     */

    if ( scan >= xmpl_file->xf_im_win.bottom
	    && scan <= xmpl_file->xf_im_win.top )
    {
	/*
	 *  Load the address of the vector of pointers to the line buffers
	 *  into line buff.
	 */

	*line_buff = xmpl_file->xf_buff_ptr;
	if ( scan != xmpl_file->xf_cur_scan )
	{
	    (void) fseek( xmpl_file->xf_fp, offset, SEEK_SET );
	}
	for ( ct=0; ct < xmpl_file->xf_num_chans; ct++ )
	{
	    /*
	     *  Read the data for the channel and load into one of the
	     *  line buffers.
	     */

	    if ( fread( (char *) (*line_buff)[ct], scan_bytes, 1,
		    xmpl_file->xf_fp ) != 1 )
	    {
		ERR_printf( ERR__ERROR,
			"xmpl_scan_read, can't read. %s\n",
			strerror( errno ) );
		return( IMF_C_READ_ERR );
	    }
	}

	xmpl_file->xf_cur_scan = scan + 1;

	return( IMF_C_NORMAL );
    }

    ERR_printf( ERR__ERROR, "xmpl_scan_read, bad scan, %d\n", scan );
    return( IMF_C_BAD_SCAN );
}
Beispiel #5
0
const DC3Error_t FLASH_writeBuffer(
    const uint32_t startAddr,
    const uint8_t *buffer,
    const uint16_t size,
    uint16_t *bytesWritten
)
{
    DC3Error_t status = ERR_NONE;
    *bytesWritten = 0;
    uint8_t data_read_back = 0;
    FLASH_Status flash_status;
    uint32_t addr = startAddr;

    /* These flags have to be cleared before any operation can be done on the
     * flash memory */
    FLASH_ClearFlag(
        FLASH_FLAG_PGSERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGAERR |
        FLASH_FLAG_WRPERR |	FLASH_FLAG_OPERR | FLASH_FLAG_EOP
    );

    for ( uint16_t i = 0; i < size; i++, addr++ ) {
        flash_status = FLASH_ProgramByte(addr, buffer[i]);
        if (FLASH_COMPLETE != flash_status) {
            status = FLASH_statusToErrorCode( flash_status );
            ERR_printf("Flash Error %d (error 0x%08x) writing %x to address %lx\n",
                       flash_status, status, buffer[i], addr);
            return( status );
        } else {
            data_read_back = *((uint8_t *)addr);
            if (data_read_back != buffer[i]) {
                status = ERR_FLASH_READ_VERIFY_FAILED;
                ERR_printf("Failed to verify write at address %lx : Wrote %2x and "
                           "read back %2ux.  Error: 0x%08x\n",
                           addr, buffer[i], data_read_back, status);
                return( status );
            }
            *bytesWritten += 1; /* Increment the return value for bytes written */
        }
    }

    if (*bytesWritten != size) {
        status = ERR_FLASH_WRITE_INCOMPLETE;
        ERR_printf("Bytes written (%d) != number of bytes requested to be "
                   "written (%d). Error: 0x%08x\n", bytesWritten, size, status);
    }

    return (status);
}
Beispiel #6
0
const DC3Error_t FLASH_eraseSector( const uint32_t sectorAddr )
{
    DC3Error_t status = ERR_NONE;

    /* These flags have to be cleared before any operation can be done on the
     * flash memory */
    //	DBG_printf("Clearing flash flags. Status before clear: %x\n",FLASH->SR );
    FLASH_ClearFlag(
        FLASH_FLAG_PGSERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGAERR |
        FLASH_FLAG_WRPERR | FLASH_FLAG_OPERR | FLASH_FLAG_EOP
    );
    //	DBG_printf("Status after clear: %x\n",FLASH->SR );
    WRN_printf("*** Erasing Flash sector addr 0x%08x ***\n", sectorAddr);

    /*Look up the STM32 value of the sector given the sector address */
    uint16_t sector = FLASH_sectorAddrToFlashSect( sectorAddr );

    DBG_printf("Erasing sector (0x%04x) with base addr: 0x%08x...\n",
               sector, sectorAddr);
    /* This is a blocking operation but it's only for a single sector so should
     * not take that long */
    FLASH_Status flash_status = FLASH_EraseSector(sector, VoltageRange_3);
    status = FLASH_statusToErrorCode( flash_status );

    if (ERR_NONE != status) {
        ERR_printf("Flash error %d ( error 0x%08x) while erasing sector "
                   "0x%04x (base addr: 0x%08x)\n",
                   flash_status, status, sector, sectorAddr);
        DBG_printf("FLASH SR:%lx\n", FLASH->SR);
    }

    return( status );
}
Beispiel #7
0
static	int	xmpl_scan_write(  POINTER data, int scan,
			POINTER *line_buff )
{
    int		ct;			/* Channel counter		*/
    int		scan_bytes;		/* Number of bytes per scanline	*/
    XMPL_FILE	*xmpl_file;		/* Our pertinent info on file	*/


    xmpl_file = (XMPL_FILE *) data;
    scan_bytes = xmpl_file->xf_im_win.right - xmpl_file->xf_im_win.left + 1;

    if ( scan == xmpl_file->xf_cur_scan
	    && scan <= xmpl_file->xf_im_win.top )
    {
	for ( ct = 0; ct < xmpl_file->xf_num_chans; ct++ )
	{
	    /*
	     *  Loop through the channels and write the data to the image
	     *  file.  The data for the channel is pointed to by
	     *  line_buff[ct].
	     */

	    if ( fwrite( (char *) line_buff[ct], scan_bytes, 1,
		    xmpl_file->xf_fp ) != 1 )
	    {
		ERR_printf( ERR__ERROR,
			"xmpl_scan_write, can't write. %s\n",
			strerror( errno ) );
		return( IMF_C_WRITE_ERR );
	    }
	}


	/*
	 *  Increment the current scan counter.
	 */

	xmpl_file->xf_cur_scan++;

	return( IMF_C_NORMAL );
    }

    ERR_printf( ERR__ERROR, "xmpl_scan_write, bad scan, %d\n", scan );
    return( IMF_C_BAD_SCAN );
}
Beispiel #8
0
void Udp::write_handler(
      const boost::system::error_code& error,
      size_t bytes_transferred
)
{
   write_msg_[bytes_transferred]=0;
   if (error) {
      ERR_printf(
            this->m_pLog,
            "Send error: %s.  %d bytes written: %s",
            error.message().c_str(),
            bytes_transferred,
            write_msg_
      );
   }
}
Beispiel #9
0
const bool DB_isArraysMatch(
      const uint8_t*  dt1,
      const uint8_t*  dt2,
      const uint16_t  len
)
{
   /* iterate arrays backwards and check if they match.  The reason for
    * iterating backwards is because most checks will involve changes in the
    * LSByte so this should be faster for most cases */
   for(int i = len - 1; i >= 0; i-- ) {
      if (dt1[i] != dt2[i]) {
         ERR_printf("dt1[%d]: %02x dt2[%d]: %02x\n", i, dt1[i], i, dt2[i]);
         return false;
      }
   }
   return true;
}
Beispiel #10
0
/*${AOs::FlashMgr::SM::Active::BusyRam} ....................................*/
static QState FlashMgr_BusyRam(FlashMgr * const me, QEvt const * const e) {
    QState status_;
    switch (e->sig) {
        /* ${AOs::FlashMgr::SM::Active::BusyRam} */
        case Q_ENTRY_SIG: {
            /* Arm the timer so if the message can't be processed for some reason, we can get
             * back to idle state.  This timer may be re-armed if some messages require more
             * time to process than others. */
            QTimeEvt_rearm(                         /* Re-arm timer on entry */
                &me->ramTimerEvt,
                SEC_TO_TICKS( HL_MAX_TOUT_SEC_CLI_WAIT_FOR_RAM_TEST )
            );

            status_ = Q_HANDLED();
            break;
        }
        /* ${AOs::FlashMgr::SM::Active::BusyRam} */
        case Q_EXIT_SIG: {
            QTimeEvt_disarm(&me->ramTimerEvt); /* Disarm timer on exit */

            /* Always send a flash status event to the CommMgr AO with the current error code */
            RamStatusEvt *evt = Q_NEW(RamStatusEvt, RAM_TEST_DONE_SIG);
            evt->errorCode = me->errorCode;
            evt->test = me->currRamTest;
            evt->addr = me->currRamAddr;
            QACTIVE_POST(AO_CommMgr, (QEvt *)(evt), AO_FlashMgr);
            status_ = Q_HANDLED();
            break;
        }
        /* ${AOs::FlashMgr::SM::Active::BusyRam::RAM_TIMEOUT} */
        case RAM_TIMEOUT_SIG: {
            ERR_printf(
                "Timeout trying to process RAM test request during RAM test %d, error: 0x%08x\n",
                me->currRamTest, me->errorCode
            );
            status_ = Q_TRAN(&FlashMgr_Idle);
            break;
        }
        default: {
            status_ = Q_SUPER(&FlashMgr_Active);
            break;
        }
    }
    return status_;
}
Beispiel #11
0
/*${AOs::FlashMgr::SM::Active::BusyRam::DeviceTest} ........................*/
static QState FlashMgr_DeviceTest(FlashMgr * const me, QEvt const * const e) {
    QState status_;
    switch (e->sig) {
        /* ${AOs::FlashMgr::SM::Active::BusyRam::DeviceTest} */
        case Q_ENTRY_SIG: {
            me->currRamTest = _DC3_RAM_TEST_DEV_INT;
            me->currRamAddr = 0;
            me->errorCode = ERR_SDRAM_DEVICE_INTEGRITY_TEST_TIMEOUT;

            QEvt *evt = Q_NEW(QEvt, RAM_OP_START_SIG);
            QACTIVE_POST(AO_FlashMgr, (QEvt *)(evt), AO_FlashMgr);

            status_ = Q_HANDLED();
            break;
        }
        /* ${AOs::FlashMgr::SM::Active::BusyRam::DeviceTest::RAM_OP_START} */
        case RAM_OP_START_SIG: {
            me->currRamAddr = SDRAM_testDevice(0, RAM_TEST_BLOCK_SIZE );
            /* ${AOs::FlashMgr::SM::Active::BusyRam::DeviceTest::RAM_OP_START::[Error?]} */
            if (0 != me->currRamAddr) {
                me->errorCode = ERR_SDRAM_DEVICE_INTEGRITY;
                ERR_printf(
                    "RAM device bus test failed at addr: 0x%08x. Error: 0x%08x\n",
                    me->currRamAddr, me->errorCode
                );
                status_ = Q_TRAN(&FlashMgr_Idle);
            }
            /* ${AOs::FlashMgr::SM::Active::BusyRam::DeviceTest::RAM_OP_START::[else]} */
            else {
                me->errorCode = ERR_NONE;
                DBG_printf("No RAM device errors found.\n");
                status_ = Q_TRAN(&FlashMgr_Idle);
            }
            break;
        }
        default: {
            status_ = Q_SUPER(&FlashMgr_BusyRam);
            break;
        }
    }
    return status_;
}
Beispiel #12
0
/*${AOs::FlashMgr::SM::Active::BusyRam::DataBusTest} .......................*/
static QState FlashMgr_DataBusTest(FlashMgr * const me, QEvt const * const e) {
    QState status_;
    switch (e->sig) {
        /* ${AOs::FlashMgr::SM::Active::BusyRam::DataBusTest} */
        case Q_ENTRY_SIG: {
            me->currRamTest = _DC3_RAM_TEST_DATA_BUS;
            me->currRamAddr = 0;
            me->errorCode = ERR_SDRAM_DATA_BUS_TEST_TIMEOUT;

            QEvt *evt = Q_NEW(QEvt, RAM_OP_START_SIG);
            QACTIVE_POST(AO_FlashMgr, (QEvt *)(evt), AO_FlashMgr);

            status_ = Q_HANDLED();
            break;
        }
        /* ${AOs::FlashMgr::SM::Active::BusyRam::DataBusTest::RAM_OP_START} */
        case RAM_OP_START_SIG: {
            me->currRamTest = _DC3_RAM_TEST_DATA_BUS;
            me->currRamAddr = SDRAM_testDataBus( 0 );
            /* ${AOs::FlashMgr::SM::Active::BusyRam::DataBusTest::RAM_OP_START::[Error?]} */
            if (0 != me->currRamAddr) {
                me->errorCode = ERR_SDRAM_DATA_BUS;
                ERR_printf(
                    "RAM data bus test failed at addr: 0x%08x on pattern: 0x%08x. Error: 0x%08x\n",
                    SDRAM_BANK_ADDR + 0, me->currRamAddr, me->errorCode
                );
                status_ = Q_TRAN(&FlashMgr_Idle);
            }
            /* ${AOs::FlashMgr::SM::Active::BusyRam::DataBusTest::RAM_OP_START::[else]} */
            else {
                DBG_printf("No RAM Data bus error found.\n");
                status_ = Q_TRAN(&FlashMgr_AddrBusTest);
            }
            break;
        }
        default: {
            status_ = Q_SUPER(&FlashMgr_BusyRam);
            break;
        }
    }
    return status_;
}
Beispiel #13
0
const DC3Error_t FLASH_validateMetadata(
    const struct DC3FlashMetaPayloadMsg const *fwMetadata
)
{
    DC3Error_t status = ERR_NONE;
    if ( 0 == fwMetadata->_imageCrc || 0xFFFFFFF == fwMetadata->_imageCrc ) {
        status = ERR_FLASH_INVALID_IMAGE_CRC;
    } else if ( fwMetadata->_imageDatetime_len != DC3_DATETIME_LEN ) {
        ERR_printf("Datetime len: %d\n", fwMetadata->_imageDatetime_len);
        status = ERR_FLASH_INVALID_DATETIME_LEN;
    } else if ( fwMetadata->_imageDatetime[0] != '2' &&  fwMetadata->_imageDatetime[0] != '0' ) {
        status = ERR_FLASH_INVALID_DATETIME;
    } else if ( fwMetadata->_imageType == _DC3_Application ) {
        /* Make sure that the image is not bigger than the total available flash */
        if ( 0 == fwMetadata->_imageSize ||
                fwMetadata->_imageSize >= MAX_APPL_FWIMAGE_SIZE ) {
            status = ERR_FLASH_IMAGE_SIZE_INVALID;
        }
    } else {
        status = ERR_FLASH_IMAGE_TYPE_INVALID;
    }

    return status;
}
Beispiel #14
0
const DC3Error_t FLASH_getSectorsToErase(
    uint32_t *sectorArrayLoc,
    uint8_t *nSectors,
    const uint8_t sectorArraySize,
    const DC3BootMode_t flashImageLoc,
    const uint32_t flashImageSize
)
{
    DC3Error_t status = ERR_NONE;

    /* Make sure the buffer is not null */
    if ( NULL == sectorArray ) {
        status = ERR_MEM_NULL_VALUE;
        ERR_printf("Sector array is NULL. Error: 0x%08x\n", status);
        return( status );
    }

    /* Make sure the buffer is long enough to fit enough sectors */
    if( sectorArraySize < ADDR_FLASH_SECTORS ) {
        status = ERR_MEM_BUFFER_LEN;
        ERR_printf("Sector array is not long enough. Error: 0x%08x\n", status);
        return( status );
    }

    uint32_t startAddr = 0;
    uint32_t currAddr = 0;
    /* Check for a valid image type and set the correct starting address */
    if( _DC3_Application == flashImageLoc ) {
        startAddr = FLASH_APPL_START_ADDR;
    } else if( _DC3_Bootloader == flashImageLoc ) {
        startAddr = FLASH_BOOT_START_ADDR;
    } else {
        status = ERR_FLASH_IMAGE_TYPE_INVALID;
        return( status );
    }

    /* Set the current address to the start address so that start address can be
     * used to offset the flash image size. */
    currAddr = startAddr;

    *nSectors = 0; /* Clear the counter pointer so caller knows how many filled */

    while( currAddr <= startAddr + flashImageSize ) {
        /* Get the sector address where the current address resides*/
        currAddr = FLASH_addrToSectorAddr( currAddr );

        if ( 0 == currAddr ) {
            status = ERR_FLASH_SECTOR_ADDR_NOT_FOUND;
            ERR_printf(
                "Sector not found given addr 0x%08x.  Error: 0x%08x\n",
                currAddr, status
            );
        }
        DBG_printf("Addr at %d: 0x%08x\n", *nSectors, currAddr);
        sectorArrayLoc[(*nSectors)++] = currAddr;

        /* Get the address of the next sector */
        currAddr = FLASH_getNextSectorAddr(currAddr);
    }

    /* If we are doing application, make sure to also erase the very last sector
     * since we store information about the application image there. */
    if( _DC3_Application == flashImageLoc ) {
        sectorArrayLoc[(*nSectors)++] = FLASH_END_ADDR_SECTOR;
    }
    return( status );
}
Beispiel #15
0
static FILE	*xmpl_open( IMF_INFO *info, char *access )
{
    char	*filename;		/* Name of file to open		*/
    FILE	*fp;			/* File pointer			*/


    if ( strcmp( access, "r" ) == 0 )
    {
	if ( info->handle_complete )
	{
	    filename = info->handle;
	    if ( ( fp = fopen( filename,
#ifdef _WIN32
		    "rb"
#else  /* _WIN32 */
		   "r"
#endif /* _WIN32 */
		    ) ) == NULL )
	    {
#ifndef _WIN32
		imf__err = IMF_C_CANNOT_OPEN;
#endif	/* _WIN32 */
		goto open_err;
	    }
	}
	else
	{
	    filename = imf__build_handle( NULL, info->handle, info->ext );
	    if ( ( fp = fopen( filename,
#ifdef _WIN32
		    "rb"
#else  /* _WIN32 */
		   "r"
#endif /* _WIN32 */
		    ) ) == NULL )
	    {
		filename = imf__build_handle( getenv( "WF_IMG_DIR" ),
			info->handle, info->ext );
		if ( ( fp = fopen( filename,
#ifdef _WIN32
			"rb"
#else  /* _WIN32 */
		       "r"
#endif /* _WIN32 */
			) ) == NULL )
		{
#ifndef _WIN32
		    imf__err = IMF_C_CANNOT_OPEN;
#endif	/* _WIN32 */
		    goto open_err;
		}
	    }
	}
    }
    else
    {
	filename = info->handle_complete ? info->handle
		: imf__build_handle( getenv( "WF_IMG_DIR" ), info->handle,
		    info->ext );
	if ( ( fp = fopen( filename,
#ifdef _WIN32
		"wb"
#else  /* _WIN32 */
	       "w"
#endif /* _WIN32 */
		) ) == NULL )
	{
#ifndef _WIN32
	    imf__err = IMF_C_CANNOT_OPEN;
#endif	/* _WIN32 */
	    goto open_err;
	}
    }

    return( fp );

open_err:
    ERR_printf( ERR__ERROR, "xmpl_open, can't open file %s. %s\n",
	    filename, strerror( errno ) );

    return( NULL );
}
Beispiel #16
0
int		imageReadOpen( IMF_OBJECT *imf )
{
    FMT_ASPECT_INFO	*fmt_info;	/* Entry in aspect table	*/
    XMPL_HDR		hdr;		/* Header we're writing to file	*/
    IMF_INFO		*info;		/* Sub-struct inside `imf'	*/
#ifndef _WIN32
    static char		*month[] =
	    {
		"Jan", "Feb", "Mar", "Apr", "May", "Jun",
		"Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
	    };
    char		date[256];	/* Resuling date file last chngd*/
    struct  passwd	*passwd_ptr;	/* For extracting file owner id	*/
    struct  stat	stat_buf;	/* For extracting date on file	*/
    struct  tm		*tm;		/* For extracting date on file	*/
#endif /* _WIN32 */
    XMPL_FILE		*xmpl_file;	/* Our pertinent info on file	*/
    XMPL_FILE		**xmpl_file_ptr;/* Our pertinent info on file	*/


    ERR_printf( ERR__INFO, "imageReadOpen, hello from the plug-in!\n" );


    /*
     *  Allocate the local data structure for the file.
     */

    xmpl_file_ptr = NULL;
    xmpl_file = NULL;

    if ( ( xmpl_file_ptr = (XMPL_FILE **) malloc( sizeof( XMPL_FILE * ) ) )
	    == NULL )
    {
#ifndef _WIN32
	imf__err = IMF_C_MEM_ALLOC;
#endif	/* _WIN32 */
	imf->data = NULL;
	goto open_err;
    }
    imf->data = (POINTER *) xmpl_file_ptr;


    /*
     *  Assign pointers into the appropriate points in the buffer.
     */

    if ( ( xmpl_file = (XMPL_FILE *) malloc( sizeof( XMPL_FILE ) ) )
	    == NULL )
    {
#ifndef _WIN32
	imf__err = IMF_C_MEM_ALLOC;
#endif	/* _WIN32 */
	xmpl_file_ptr[0] = NULL;
	goto open_err;
    }
    xmpl_file_ptr[0] = xmpl_file;
    xmpl_file->xf_buff_ptr = NULL;

    imf->info.count = 1;	    /* force count to be one */
    if ( ( imf->info.image = (IMF_IMAGE *) malloc( sizeof( IMF_IMAGE ) ) )
	    == NULL )
    {
#ifndef _WIN32
	imf__err = IMF_C_MEM_ALLOC;
#endif	/* _WIN32 */
	goto open_err;
    }


    /*
     *  Initialize the image array structures.
     */

    (void) imf__init_ifd( imf );


    /*
     *  Complete filling in the imf_data structure - load pointers to
     *  the write scan and the close routines.
     */

    imf->scan = (IMF_scanProc) xmpl_scan_read;
    imf->close = (IMF_closeProc) xmpl_close;
    if ( ( xmpl_file->xf_fp = xmpl_open( &imf->info,"r" ) ) == NULL )
    {
	goto open_err;
    }


    /*
     *  Read the file header and load the header information. Load the
     *  information into the XMPL_FILE structure and into the IMF_INFO
     *  structure of the image object.
     *
     *  NOTE:
     *	    If you copy you image files between machines with different
     *  alignment requirements or type sizes, you will need to read each
     *  element of the structure separately.  Also if the machines have
     *  different byte ordering or float point format, you will need to
     *  correct those element for the differences.
     */

    if ( fread( (char *) &hdr, sizeof( XMPL_HDR ), 1, xmpl_file->xf_fp )
	    != 1 )
    {
#ifndef _WIN32
	imf__err = IMF_C_READ_ERR;
#endif	/* _WIN32 */
	ERR_printf( ERR__ERROR,
		"imageReadOpen, can't read header. %s\n", strerror( errno ) );
	goto open_err;
    }
    else if ( hdr.xh_magic != XMPL_MAGIC )
    {
#ifndef _WIN32
	imf__err = IMF_C_READ_ERR;
#endif	/* _WIN32 */
	ERR_printf( ERR__ERROR,
		"imageReadOpen, not a `%s' image file. Got magic number %d\n",
		imageName, hdr.xh_magic );
	goto open_err;
    }


    /*
     *  Fill in info fields
     */

    info = &imf->info;
    IF_NULL_GOTO_ERROR( info->name = STRDUP( hdr.xh_name ), no_mem );
    IF_NULL_GOTO_ERROR( info->desc = STRDUP( "None" ), no_mem );
    IF_NULL_GOTO_ERROR( info->program = STRDUP( xmpl_unknown ), no_mem );
    IF_NULL_GOTO_ERROR( info->machine = STRDUP( xmpl_unknown ), no_mem );
#ifndef _WIN32
    if ( stat( info->handle, &stat_buf ) == 0 )
    {
	if ( ( passwd_ptr = getpwuid( stat_buf.st_uid ) ) != NULL )
	{
  	    IF_NULL_GOTO_ERROR( info->user = STRDUP( passwd_ptr->pw_name ),
		    no_mem );
	}
	else
	{
	    IF_NULL_GOTO_ERROR( info->user = STRDUP( xmpl_unknown ),
		    no_mem );
	}
	tm = localtime( &stat_buf.st_mtime );
  	(void) sprintf( date, "%s %d %02d:%02d %4d", month[tm->tm_mon],
		tm->tm_mday, tm->tm_hour, tm->tm_min, 1900 + tm->tm_year );
	IF_NULL_GOTO_ERROR( info->date = STRDUP( date ), no_mem );
    }
    else 
#endif /* _WIN32 */
    {
	IF_NULL_GOTO_ERROR( info->user = STRDUP( xmpl_unknown ), no_mem );
	IF_NULL_GOTO_ERROR( info->date = STRDUP( xmpl_unknown ), no_mem );
    }
    IF_NULL_GOTO_ERROR( info->time = STRDUP( xmpl_unknown ), no_mem );
    IF_NULL_GOTO_ERROR( info->filter = STRDUP( xmpl_unknown ), no_mem );
    IF_NULL_GOTO_ERROR( info->compress = STRDUP( "none" ), no_mem );

    info->frame = hdr.xh_frame;
    info->red_pri = hdr.xh_red_pri;
    info->green_pri = hdr.xh_green_pri;
    info->blue_pri = hdr.xh_blue_pri;
    info->white_pt = hdr.xh_white_pt;
    info->image[0].window = hdr.xh_im_win;
    info->image[0].active = hdr.xh_act_win;
    if ( ( fmt_info = FMT_find( hdr.xh_aspect ) ) != NULL )
    {
	info->image[0].aspect = *fmt_info;
	IF_NULL_GOTO_ERROR( info->image[0].aspect.name
		= STRDUP( fmt_info->name ), no_mem );
    }
    else
    {
	IF_NULL_GOTO_ERROR( info->image[0].aspect.name
		= STRDUP( hdr.xh_aspect ), no_mem );
	info->image[0].aspect.width
		= hdr.xh_im_win.right - hdr.xh_im_win.left +1;
	info->image[0].aspect.height
		= hdr.xh_im_win.top - hdr.xh_im_win.bottom +1;
	info->image[0].aspect.ratio
		= info->image[0].aspect.width
		/ (float) info->image[0].aspect.height;
    }
    info->image[0].curve.gamma = hdr.xh_gamma;
    info->image[0].curve.usage = hdr.xh_usage;

    info->image[0].chan_bits = hdr.xh_chan_bits;
    info->image[0].chan_count = hdr.xh_num_im_chan;
    IF_NULL_GOTO_ERROR( info->image[0].chan_format
	    = STRDUP( hdr.xh_chan_format ), no_mem );
    info->image[0].chan_type = hdr.xh_chan_type;


    /*
     *  Assumes matte channel is same bits & type as rgb channels.
     */

    info->image[0].matte_bits = hdr.xh_chan_bits;
    info->image[0].matte_count = hdr.xh_num_matte_chan;
    IF_NULL_GOTO_ERROR( info->image[0].matte_format
	    = STRDUP( xmpl_unknown ), no_mem );
    info->image[0].matte_type = hdr.xh_chan_type;

    info->image[0].aux_bits = hdr.xh_chan_bits;
    info->image[0].aux_count = 0;
    IF_NULL_GOTO_ERROR( info->image[0].aux_format
	    = STRDUP( xmpl_unknown ), no_mem );
    info->image[0].aux_type = hdr.xh_chan_type;

    xmpl_file->xf_size_mult
	    = xmpl_file->xf_num_chans
	    = hdr.xh_num_im_chan + hdr.xh_num_matte_chan;
    xmpl_file->xf_im_win = hdr.xh_im_win;
    xmpl_file->xf_cur_scan = hdr.xh_im_win.bottom;

    if ( ( xmpl_file->xf_buff_ptr = IMF_chan_alloc( info->image,
	    hdr.xh_im_win.right - hdr.xh_im_win.left + 1,
	    info->key, (int *) NULL ) ) != NULL )
    {
	/*
	 *  Successful completion of open for read, print out the
	 *  details of the file we opened, and then return TRUE.
	 */

	ERR_printf( ERR__INFO, "imageReadOpen, returning success!!!" );
	ERR_printf( ERR__INFO, "\txh_magic = 0x%x",hdr.xh_magic );
	ERR_printf( ERR__INFO, "\txh_im_win = (%d,%d,%d,%d)",
		hdr.xh_im_win.left, hdr.xh_im_win.right,
		hdr.xh_im_win.bottom, hdr.xh_im_win.top );
	ERR_printf( ERR__INFO, "\txh_act_win = (%d,%d,%d,%d)",
		hdr.xh_act_win.left, hdr.xh_act_win.right,
		hdr.xh_act_win.bottom, hdr.xh_act_win.top );
	ERR_printf( ERR__INFO, "\txh_frame = %d", hdr.xh_frame );
	ERR_printf( ERR__INFO, "\txh_chan_type = %d", hdr.xh_chan_type );
	ERR_printf( ERR__INFO, "\txh_chan_bits = %d", hdr.xh_chan_bits );
	ERR_printf( ERR__INFO, "\txh_num_im_chan = %d",
		hdr.xh_num_im_chan );
	ERR_printf( ERR__INFO, "\txh_num_matte_chan = %d",
		hdr.xh_num_matte_chan );
	ERR_printf( ERR__INFO, "\txh_gamma = %f", hdr.xh_gamma );
	ERR_printf( ERR__INFO, "\txh_usage = %d", hdr.xh_usage );
	ERR_printf( ERR__INFO, "\txh_red_pri = {%f,%f,%f}",
		hdr.xh_red_pri.x,
		hdr.xh_red_pri.y,
		hdr.xh_red_pri.z );
	ERR_printf( ERR__INFO, "\txh_green_pri = {%f,%f,%f}",
		hdr.xh_green_pri.x,
		hdr.xh_green_pri.y,
		hdr.xh_green_pri.z );
	ERR_printf( ERR__INFO, "\txh_blue_pri = {%f,%f,%f}",
		hdr.xh_blue_pri.x,
		hdr.xh_blue_pri.y,
		hdr.xh_blue_pri.z );
	ERR_printf( ERR__INFO, "\txh_white_pt = {%f,%f,%f}",
		hdr.xh_white_pt.x,
		hdr.xh_white_pt.y,
		hdr.xh_white_pt.z );
	ERR_printf( ERR__INFO, "\txh_name = `%s'", hdr.xh_name );
	ERR_printf( ERR__INFO, "\txh_aspect = `%s'", hdr.xh_aspect );
	ERR_printf( ERR__INFO, "\txh_chan_format = `%s'",
		hdr.xh_chan_format );

	return( TRUE );
    }

#ifndef _WIN32
    imf__err = IMF_C_MEM_ALLOC;
#endif	/* _WIN32 */

no_mem:
#ifndef _WIN32
    imf__err = IMF_C_READ_ERR;
#endif	/* _WIN32 */
    ERR_printf( ERR__ERROR,
	    "imageReadOpen, insufficient memory when reading file. %s\n",
	    strerror( errno ) );
    return( FALSE );

open_err:
    if ( xmpl_file->xf_fp != NULL )
    {
	(void) fclose( xmpl_file->xf_fp );
	xmpl_file->xf_fp = NULL;
    }

    return( FALSE );
}
Beispiel #17
0
int		imageWriteOpen( IMF_OBJECT *imf )
{
    XMPL_HDR	hdr;			/* Header read from file	*/
    XMPL_FILE	*xmpl_file = 0;		/* Our pertinent info on file	*/
    XMPL_FILE	**xmpl_file_ptr = 0;	/* Our pertinent info on file	*/


    /*
     *  Various tests to ensure incoming imf image is reasonable
     */

    if ( imf->info.count != 1 )
    {
	ERR_printf( ERR__WARNING,
		"imageWriteOpen, Writing first image only of '%d' images\n",
		imf->info.count );
	imf->info.count = 1;
    }
    if ( imf->info.image[0].chan_bits != 8 )
    {
	ERR_printf( ERR__ERROR,
		"imageWriteOpen, Xmpl format cannot write %d-bit channels\n",
		imf->info.image[0].chan_bits );
#ifndef _WIN32
	imf__err = IMF_C_NO_SUPPORT;
#endif	/* _WIN32 */
	goto open_err;
    }
    if ( imf->info.image[0].chan_type != IMF_C_INTEGER )
    {
	ERR_printf( ERR__ERROR,
		"imageWriteOpen, Xmpl format cannot write type '%d' channels\n",
		imf->info.image[0].chan_type );
#ifndef _WIN32
	imf__err = IMF_C_NO_SUPPORT;
#endif	/* _WIN32 */
	goto open_err;
    }


    /*
     *  Allocate the local data structure for the file.
     */

    xmpl_file_ptr = NULL;
    xmpl_file = NULL;

    if ( ( imf->data = (POINTER *) malloc(
	    imf->info.count * sizeof( XMPL_FILE * ) ) ) == NULL )
    {
#ifndef _WIN32
	imf__err = IMF_C_MEM_ALLOC;
#endif	/* _WIN32 */
	goto open_err;
    }

    xmpl_file_ptr = (XMPL_FILE **) imf->data;
    if ( ( *xmpl_file_ptr = (XMPL_FILE *) malloc(
	    imf->info.count * sizeof( XMPL_FILE ) ) ) == NULL )
    {
#ifndef _WIN32
	imf__err = IMF_C_MEM_ALLOC;
#endif	/* _WIN32 */
	goto open_err;
    }
    xmpl_file = *xmpl_file_ptr;
    xmpl_file->xf_buff_ptr = NULL;


    /*
     *  Complete filling in the imf_data structure - load pointers to
     *  the write scan and the close routines.
     */

    imf->scan =  (IMF_scanProc) xmpl_scan_write;
    imf->close = (IMF_closeProc) xmpl_close;
    if ( ( xmpl_file->xf_fp = xmpl_open( &imf->info, "w") ) == NULL )
    {
	goto open_err;
    }


    /*
     *  Fill in the XMPL_FILE data structure -- allocate and define local
     *  buffers, resolutions etc. as required for this file type.
     */

    xmpl_file->xf_im_win = imf->info.image[0].window;
    xmpl_file->xf_cur_scan = xmpl_file->xf_im_win.bottom;


    /*
     *  Aux channel is not written.
     */

    xmpl_file->xf_num_chans = imf->info.image[0].chan_count
	    + imf->info.image[0].matte_count;


    /*
     *  Build the header and write the header for the file.
     */

    hdr.xh_magic = XMPL_MAGIC;
    hdr.xh_im_win = imf->info.image[0].window;
    hdr.xh_act_win = imf->info.image[0].active;
    hdr.xh_frame = imf->info.frame;
    hdr.xh_chan_bits = xmpl_file->xf_size_mult
	    = imf->info.image[0].chan_bits;
    hdr.xh_num_im_chan = imf->info.image[0].chan_count;
    hdr.xh_num_matte_chan = imf->info.image[0].matte_count;
    hdr.xh_gamma = imf->info.image[0].curve.gamma;
    hdr.xh_usage = imf->info.image[0].curve.usage;
    hdr.xh_red_pri = imf->info.red_pri;
    hdr.xh_green_pri = imf->info.green_pri;
    hdr.xh_blue_pri = imf->info.blue_pri;
    hdr.xh_white_pt = imf->info.white_pt;
    hdr.xh_chan_type = imf->info.image[0].chan_type;
    (void) strncpy( hdr.xh_name, imf->info.handle, 128 );
    hdr.xh_name[127] = '\0';
    (void) strncpy( hdr.xh_aspect, imf->info.image[0].aspect.name, 32 );
    hdr.xh_aspect[31] = '\0';
    (void) strncpy( hdr.xh_chan_format, imf->info.image[0].chan_format, 32 );
    hdr.xh_chan_format[31] = '\0';

    if ( fwrite( (char *) &hdr, sizeof( XMPL_HDR ), 1, xmpl_file->xf_fp )
	    != 1 )
    {
#ifndef _WIN32
	imf__err = IMF_C_WRITE_ERR;
#endif	/* _WIN32 */
	ERR_printf( ERR__ERROR, "imageWriteOpen, can't write. %s\n",
		strerror( errno ) );
	goto open_err;
    }


    /*
     *  Successful compeltion of open for write, return TRUE.
     */

    return( TRUE );

open_err:
    if ( xmpl_file != NULL && xmpl_file->xf_fp != NULL )
    {
	(void) fclose( xmpl_file->xf_fp );
	xmpl_file->xf_fp = NULL;
    }

    return( FALSE );
}
Beispiel #18
0
int	imageInit( void )
{
    ERR_printf( ERR__INFO, "imageInit, hello from the plug-in!\n" );

    return( TRUE );
}
Beispiel #19
0
BOOLEAN		imageIsFile( char *fn, FILE *fp )
{
    U_SHORT	magic;		/* Magic number read from file		*/
    BOOLEAN	was_open;	/* TRUE if mode where file opened by app*/


    was_open = ( fp != NULL );

    if ( fp )
    {
	/*
	 *  The application is calling us in the mode where the file is
	 *  pre-opened.
	 */

	rewind( fp );
    }
    else
    {
	/*
	 *  The application is calling us in the mode where we must open
	 *  the file ourselves.
	 */

#ifdef _WIN32
	if ( ( fp = fopen( fn, "rb" ) ) == NULL )
#else
	if ( ( fp = fopen( fn, "r" ) ) == NULL )
#endif /* _WIN32 */
	{
	    ERR_printf( ERR__ERROR, "imageIsFile, can't open `%s'. %s\n",
		    fn, strerror( errno ) );
	    return( FALSE );
	}
    }


    /*
     *  Read the first 2 bytes, which is the magic number.
     */

    if ( fread( (U_SHORT *) &magic, sizeof( magic ), 1, fp ) != 1 )
    {
	ERR_printf( ERR__ERROR, "imageIsFile, can't read `%s'. %s\n",
		fn, strerror( errno ) );
	return( FALSE );
    }
    
    if ( !was_open )
    {
	fclose( fp );
    }


    /*
     *  Return TRUE if the magic number matches. You should probably
     *  be a bit more sophisticated here.
     */

    return( magic == XMPL_MAGIC );
}
Beispiel #20
0
/*${AOs::FlashMgr::SM::Active::BusyFlash::PrepFlash} .......................*/
static QState FlashMgr_PrepFlash(FlashMgr * const me, QEvt const * const e) {
    QState status_;
    switch (e->sig) {
        /* ${AOs::FlashMgr::SM::Active::BusyFlash::PrepFlash} */
        case Q_ENTRY_SIG: {
            /* Self post an event to keep going.  The reason this is done is so that we can use
             * common error handling of the parent state to report errors back to CommMgr instead
             * of having to manually port events whenever an error occurs.*/
            QEvt *evt = Q_NEW(QEvt, FLASH_NEXT_STEP_SIG);
            QACTIVE_POST(AO_FlashMgr, (QEvt *)(evt), AO_FlashMgr);

            status_ = Q_HANDLED();
            break;
        }
        /* ${AOs::FlashMgr::SM::Active::BusyFlash::PrepFlash::FLASH_NEXT_STEP} */
        case FLASH_NEXT_STEP_SIG: {
            DBG_printf("FLASH_NEXT_STEP\n");

            LOG_printf("Extracted FW image metadata:\n");
            LOG_printf("CRC: 0x%08x\n", me->fwFlashMetadata._imageCrc);
            LOG_printf("Maj: %02d\n", me->fwFlashMetadata._imageMaj);
            LOG_printf("Min: %02d\n", me->fwFlashMetadata._imageMin);
            LOG_printf("Size: %d\n", me->fwFlashMetadata._imageSize);
            LOG_printf("Type: %d\n", me->fwFlashMetadata._imageType);
            LOG_printf("Datetime: %s\n", me->fwFlashMetadata._imageDatetime);
            LOG_printf("Number of packets: %d\n", me->fwFlashMetadata._imageNumPackets);

            /* Do some sanity checking on the FW image metadata */
            me->errorCode = FLASH_validateMetadata(&(me->fwFlashMetadata));
            /* ${AOs::FlashMgr::SM::Active::BusyFlash::PrepFlash::FLASH_NEXT_STEP::[MetadataValid?]} */
            if (ERR_NONE == me->errorCode) {
                DBG_printf("Finding flash sectors to erase.\n");

                me->errorCode = FLASH_getSectorsToErase(
                    me->flashSectorsToErase,
                    &(me->flashSectorsToEraseNum),
                    ADDR_FLASH_SECTORS,
                    me->fwFlashMetadata._imageType,
                    me->fwFlashMetadata._imageSize
                );

                /* Set the start address which will get used later when the fw packets start coming in*/
                if (me->fwFlashMetadata._imageType == _DC3_Application ) {
                    me->flashAddrCurr = FLASH_APPL_START_ADDR;
                    me->fwPacketExp   = me->fwFlashMetadata._imageNumPackets;
                    DBG_printf("Expecting %d FW data packets\n", me->fwPacketExp);
                } else {
                    me->errorCode = ERR_FLASH_IMAGE_TYPE_INVALID;
                    ERR_printf("FW image type %d currently not supported for FW upgrades, error: 0x%08x\n",
                        me->fwFlashMetadata._imageType, me->errorCode);
                }
                /* ${AOs::FlashMgr::SM::Active::BusyFlash::PrepFlash::FLASH_NEXT_STEP::[MetadataValid?]::[SectorsValid?]} */
                if (ERR_NONE == me->errorCode && me->flashSectorsToEraseNum > 1) {
                    LOG_printf("List of %d sectors (by address) to erase:\n", me->flashSectorsToEraseNum);
                    for( uint8_t i=0; i < me->flashSectorsToEraseNum; i++ ) {
                        LOG_printf("Sector at address at 0x%08x\n", me->flashSectorsToErase[i]);
                    }
                    status_ = Q_TRAN(&FlashMgr_ErasingSector);
                }
                /* ${AOs::FlashMgr::SM::Active::BusyFlash::PrepFlash::FLASH_NEXT_STEP::[MetadataValid?]::[else]} */
                else {
                    ERR_printf("Unable to get a list of sectors to erase. Error: 0x%08x\n", me->errorCode);
                    status_ = Q_TRAN(&FlashMgr_Idle);
                }
            }
            /* ${AOs::FlashMgr::SM::Active::BusyFlash::PrepFlash::FLASH_NEXT_STEP::[else]} */
            else {
                ERR_printf("FW image metadata failed validation with error: 0x%08x\n", me->errorCode);
                status_ = Q_TRAN(&FlashMgr_Idle);
            }
            break;
        }
        /* ${AOs::FlashMgr::SM::Active::BusyFlash::PrepFlash::FLASH_OP_TIMEOUT} */
        case FLASH_OP_TIMEOUT_SIG: {
            /* Override whatever error since the timeout interrupted whatever was happening. */
            me->errorCode = ERR_FLASH_ERASE_TIMEOUT;
            ERR_printf("Timed out while preparing flash for FW update. Error: 0x%08x\n", me->errorCode);
            status_ = Q_TRAN(&FlashMgr_Idle);
            break;
        }
        default: {
            status_ = Q_SUPER(&FlashMgr_BusyFlash);
            break;
        }
    }
    return status_;
}
Beispiel #21
0
void CPLR_Task( void* pvParameters )
{
   (void) pvParameters;
   QEvt const *evt; /* This pointer to an event always lives but should be
                       garbage collected after finishing to process it so the
                       memory in the pool to which it points can be reused. If
                       this thread needs to wait on another event while still
                       processing this (main) one, a different local pointer
                       should be used and garbage collected after. */

   DC3Error_t status = ERR_NONE; /* Keep track of failures of various func
                                     calls and commands.  If this is ever set
                                     to something other than ERR_NONE, it will
                                     be printed out at the end of the for loop*/

   for (;;) {                         /* Beginning of the thread forever loop */
      /* Check if there's data in the queue and process it if there. */

      evt = QEQueue_get(&CPLR_evtQueue);
      if ( evt != (QEvt *)0 ) { /* Check whether an event is present in queue */

         switch( evt->sig ) {        /* Identify the event by its signal enum */
            case CPLR_ETH_SYS_TEST_SIG:
               DBG_printf(
                     "Received CPLR_ETH_SYS_TEST_SIG (%d) signal with event EthEvt of len: %d\n",
                     evt->sig,
                     ((EthEvt const *)evt)->msg_len
               );
#if 0
               /* Going to use this signal to test some stuff in this thread */
               /* Do a read from the EEPROM on the I2C Bus */
               status = I2C_readDevMemEVT(
                     _DC3_EEPROM,                                    // DC3I2CDevice_t iDev,
                     0x00,                                           // uint16_t offset,
                     17,                                             // uint16_t bytesToRead,
                     _DC3_ACCESS_FRT,                                // AccessType_t accType,
                     NULL                                            // QActive* callingAO
               );
               if ( ERR_NONE != status ) {
                  ERR_printf("Error calling I2C_readDevMemEVT()\n");
                  goto CPLR_Task_ERR_HANDLE; /* Stop and jump to error handling */
               }

               /* If we got here, there were no errors during the call to
                * I2C_readDevMemEVT() so we can expect an event from that driver
                */
               uint32_t timeout = 1000;
               QEvt const *evtI2CDone = 0;

               /* We only expect an I2C read done signal and no others */
               do {
                  evtI2CDone = QEQueue_get(&CPLR_evtQueue);
                  if (evtI2CDone != (QEvt *)0 ) {
                     break;
                  } else {
                     vTaskDelay(1);
                  }
               } while ( --timeout != 0 );

               if ( 0 == timeout ) {
                  ERR_printf("Timed out waiting for an event\n");
               } else {
                  switch( evtI2CDone->sig ) {
                     case I2C1_DEV_READ_DONE_SIG:
                        DBG_printf("Got I2C1_DEV_READ_DONE_SIG\n");
                        break;
                     default:
                        WRN_printf("Unknown signal %d\n", evtI2CDone->sig);
                        break;
                  }
                  QF_gc(evt);
               }

#endif
               uint8_t buffer[20];
               uint16_t bytesRead = 0;

               DBG_printf("Issuing I2C_readDevMemFRT()\n");
               status = I2C_readDevMemFRT(
                     _DC3_EEPROM,                     // const DC3I2CDevice_t iDev,
                     0x00,                            // const uint16_t offset,
                     17,                              // const uint16_t nBytesToRead
                     sizeof(buffer),                  // const uint16_t nBufferSize,
                     buffer,                          // uint8_t const *pBuffer,
                     &bytesRead                       // uint16_t *pBytesRead,
               );

               char tmp[120];
               uint16_t tmpLen = 0;
               status = CON_hexToStr(
                     (const uint8_t *)buffer,             // data to convert
                     bytesRead,                           // length of data to convert
                     tmp,                                 // where to write output
                     sizeof(tmp),                         // max size of output buffer
                     &tmpLen,                             // size of the resulting output
                     0,                                   // no columns
                     ' ',                                 // separator
                     true                                 // bPrintX
               );
               DBG_printf("I2C_readDevMemFRT() returned having read %d bytes: %s\n", bytesRead, tmp);
               break;

            default:
               WRN_printf("Received an unknown signal: %d. Ignoring...\n", evt->sig);
               break;

         }
         /* If any data from the event needs to be used after garbage
          * collection, it should be locally stored if. */


CPLR_Task_ERR_HANDLE:             /* Handle any error that may have occurred. */
         /* Print error if exists */
         ERR_COND_OUTPUT(
               status,
               _DC3_ACCESS_FRT,
               "Error 0x%08x occurred in FreeRTOS thread!!!\n",
               status
         );

         QF_gc(evt); /* !!! Don't forget to garbage collect the event after
                        processing the event.  After this, any data to which
                        this pointer points to may not be valid and should not
                        be referenced. */
      }

//      vTaskSuspend(NULL);
      vTaskDelay(1); /* Always task-delay so this thread can go to sleep while
                        other threads/AOs can process their data */
   }                                        /* End of the thread forever loop */
}
Beispiel #22
0
/*${AOs::FlashMgr::SM::Active::BusyFlash::PrepFlash::ErasingSector} ........*/
static QState FlashMgr_ErasingSector(FlashMgr * const me, QEvt const * const e) {
    QState status_;
    switch (e->sig) {
        /* ${AOs::FlashMgr::SM::Active::BusyFlash::PrepFlash::ErasingSector} */
        case Q_ENTRY_SIG: {
            QTimeEvt_rearm(                         /* Re-arm timer on entry */
                &me->flashOpTimerEvt,
                SEC_TO_TICKS( LL_MAX_TOUT_SEC_FLASH_SECTOR_ERASE )
            );

            DBG_printf("Attempting to erase sector addr 0x%08x\n",
                me->flashSectorsToErase[ me->flashSectorsToEraseIndex ]);

            /* Use a separate status variable so if a timeout occurs, the timeout error won't get
             * overwritten */
            me->errorCode = FLASH_eraseSector(
                me->flashSectorsToErase[ me->flashSectorsToEraseIndex ]
            );

            /* Post event to move to the next step only AFTER the blocking call to
             * FLASH_eraseSector() returns */
            QEvt *evt = Q_NEW(QEvt, FLASH_NEXT_STEP_SIG);
            QACTIVE_POST(AO_FlashMgr, (QEvt *)(evt), AO_FlashMgr);
            status_ = Q_HANDLED();
            break;
        }
        /* ${AOs::FlashMgr::SM::Active::BusyFlash::PrepFlash::ErasingSector} */
        case Q_EXIT_SIG: {
            QTimeEvt_disarm(&me->flashOpTimerEvt); /* Disarm timer on exit */
            status_ = Q_HANDLED();
            break;
        }
        /* ${AOs::FlashMgr::SM::Active::BusyFlash::PrepFlash::ErasingSector::FLASH_NEXT_STEP} */
        case FLASH_NEXT_STEP_SIG: {
            /* ${AOs::FlashMgr::SM::Active::BusyFlash::PrepFlash::ErasingSector::FLASH_NEXT_STEP::[EraseOK?]} */
            if (ERR_NONE == me->errorCode) {
                DBG_printf("Successfully erased sector addr 0x%08x\n",
                    me->flashSectorsToErase[ me->flashSectorsToEraseIndex ]);

                me->flashSectorsToEraseIndex += 1; /* increment the index into the erase array */

                /* ${AOs::FlashMgr::SM::Active::BusyFlash::PrepFlash::ErasingSector::FLASH_NEXT_STEP::[EraseOK?]::[MoreToErase?]} */
                if (me->flashSectorsToEraseIndex < me->flashSectorsToEraseNum) {
                    status_ = Q_TRAN(&FlashMgr_ErasingSector);
                }
                /* ${AOs::FlashMgr::SM::Active::BusyFlash::PrepFlash::ErasingSector::FLASH_NEXT_STEP::[EraseOK?]::[else]} */
                else {
                    status_ = Q_TRAN(&FlashMgr_WaitingForFWData);
                }
            }
            /* ${AOs::FlashMgr::SM::Active::BusyFlash::PrepFlash::ErasingSector::FLASH_NEXT_STEP::[else]} */
            else {
                WRN_printf("Failed to erase flash sector 0x%08x\n", me->flashSectorsToErase[ me->flashSectorsToEraseIndex ]);
                /* ${AOs::FlashMgr::SM::Active::BusyFlash::PrepFlash::ErasingSector::FLASH_NEXT_STEP::[else]::[retry?]} */
                if (me->retryCurr < MAX_FLASH_RETRIES) {
                    me->retryCurr += 1; /* Increment retry counter */
                    WRN_printf("Attempting operation again (retry %d out of %d)...\n", me->retryCurr, MAX_FLASH_RETRIES);
                    status_ = Q_TRAN(&FlashMgr_ErasingSector);
                }
                /* ${AOs::FlashMgr::SM::Active::BusyFlash::PrepFlash::ErasingSector::FLASH_NEXT_STEP::[else]::[else]} */
                else {
                    ERR_printf("No more retries, aborting with error: 0x%08x\n", me->errorCode);
                    status_ = Q_TRAN(&FlashMgr_Idle);
                }
            }
            break;
        }
        default: {
            status_ = Q_SUPER(&FlashMgr_PrepFlash);
            break;
        }
    }
    return status_;
}
Beispiel #23
0
/*${AOs::FlashMgr::SM::Active::BusyFlash::WritingFlash} ....................*/
static QState FlashMgr_WritingFlash(FlashMgr * const me, QEvt const * const e) {
    QState status_;
    switch (e->sig) {
        /* ${AOs::FlashMgr::SM::Active::BusyFlash::WritingFlash} */
        case Q_ENTRY_SIG: {
            me->errorCode = ERR_FLASH_WRITE_TIMEOUT; /* Set the timeout error code*/
            if ( (me->fwPacketCurr + 1) % 100 == 0 ) {
                DBG_printf("Writing FW data packet %d of %d total.\n", me->fwPacketCurr + 1, me->fwFlashMetadata._imageNumPackets);
            }

            QTimeEvt_rearm(                         /* Re-arm timer on entry */
                &me->flashOpTimerEvt,
                SEC_TO_TICKS( LL_MAX_TOUT_SEC_FLASH_DATA_WRITE )
            );

            uint16_t bytesWritten = 0;
            DC3Error_t err = FLASH_writeBuffer(
                  me->flashAddrCurr,
                  me->fwDataToFlash,
                  me->fwDataToFlashLen,
                  &bytesWritten
            );

            me->errorCode = err;

            if( ERR_NONE != err || bytesWritten != me->fwDataToFlashLen) { /* Error occurred */
                WRN_printf("Error flashing data: 0x%08x\n", me->errorCode);
                QEvt *evt = Q_NEW(QEvt, FLASH_ERROR_SIG);
                QACTIVE_POST(AO_FlashMgr, (QEvt *)(evt), AO_FlashMgr);
            } else {                                                            /* No errors */
                /* Increment addr and counters */
                me->flashAddrCurr += bytesWritten;
                me->fwPacketCurr += 1;
                QEvt *evt = Q_NEW(QEvt, FLASH_DONE_SIG);
                QACTIVE_POST(AO_FlashMgr, (QEvt *)(evt), AO_FlashMgr);
            }
            status_ = Q_HANDLED();
            break;
        }
        /* ${AOs::FlashMgr::SM::Active::BusyFlash::WritingFlash::FLASH_DONE} */
        case FLASH_DONE_SIG: {
            /* ${AOs::FlashMgr::SM::Active::BusyFlash::WritingFlash::FLASH_DONE::[MorePackets?]} */
            if (me->fwPacketCurr != me->fwPacketExp) {
                status_ = Q_TRAN(&FlashMgr_WaitingForFWData);
            }
            /* ${AOs::FlashMgr::SM::Active::BusyFlash::WritingFlash::FLASH_DONE::[else]} */
            else {
                DBG_printf("No more fw packets expected\n");
                /* Do a check of the FW image and compare all the CRCs and sizes */
                CRC_ResetDR();
                uint32_t crcCheck = CRC32_Calc(
                    (uint8_t *)FLASH_APPL_START_ADDR,
                    me->fwFlashMetadata._imageSize
                );
                /* ${AOs::FlashMgr::SM::Active::BusyFlash::WritingFlash::FLASH_DONE::[else]::[CRCMatch?]} */
                if (me->fwFlashMetadata._imageCrc == crcCheck) {
                    DBG_printf("CRCs of the FW image match, writing metadata...\n");
                    me->errorCode = FLASH_writeApplSize( me->fwFlashMetadata._imageSize );
                    /* ${AOs::FlashMgr::SM::Active::BusyFlash::WritingFlash::FLASH_DONE::[else]::[CRCMatch?]::[NoError?]} */
                    if (ERR_NONE == me->errorCode) {
                        me->errorCode = FLASH_writeApplCRC( me->fwFlashMetadata._imageCrc );
                        /* ${AOs::FlashMgr::SM::Active::BusyFlash::WritingFlash::FLASH_DONE::[else]::[CRCMatch?]::[NoError?]::[NoError?]} */
                        if (ERR_NONE == me->errorCode) {
                            me->errorCode = FLASH_writeApplMajVer( me->fwFlashMetadata._imageMaj );
                            /* ${AOs::FlashMgr::SM::Active::BusyFlash::WritingFlash::FLASH_DONE::[else]::[CRCMatch?]::[NoError?]::[NoError?]::[NoError?]} */
                            if (ERR_NONE == me->errorCode) {
                                me->errorCode = FLASH_writeApplMinVer( me->fwFlashMetadata._imageMin );
                                /* ${AOs::FlashMgr::SM::Active::BusyFlash::WritingFlash::FLASH_DONE::[else]::[CRCMatch?]::[NoError?]::[NoError?]::[NoError?]::[NoError?]} */
                                if (ERR_NONE == me->errorCode) {
                                    me->errorCode = FLASH_writeApplBuildDatetime(
                                        (uint8_t *)me->fwFlashMetadata._imageDatetime,
                                        me->fwFlashMetadata._imageDatetime_len
                                    );
                                    /* ${AOs::FlashMgr::SM::Active::BusyFlash::WritingFlash::FLASH_DONE::[else]::[CRCMatch?]::[NoError?]::[NoError?]::[NoError?]::[NoError?]::[NoError?]} */
                                    if (ERR_NONE == me->errorCode) {
                                        LOG_printf("Successfully finished upgrading FW!\n");
                                        status_ = Q_TRAN(&FlashMgr_Idle);
                                    }
                                    /* ${AOs::FlashMgr::SM::Active::BusyFlash::WritingFlash::FLASH_DONE::[else]::[CRCMatch?]::[NoError?]::[NoError?]::[NoError?]::[NoError?]::[else]} */
                                    else {
                                        ERR_printf("Unable to write image build datetime after flashing. Error: 0x%08x.\n", me->errorCode);
                                        status_ = Q_TRAN(&FlashMgr_Idle);
                                    }
                                }
                                /* ${AOs::FlashMgr::SM::Active::BusyFlash::WritingFlash::FLASH_DONE::[else]::[CRCMatch?]::[NoError?]::[NoError?]::[NoError?]::[else]} */
                                else {
                                    ERR_printf("Unable to write image Minor Version after flashing. Error: 0x%08x.\n", me->errorCode);
                                    status_ = Q_TRAN(&FlashMgr_Idle);
                                }
                            }
                            /* ${AOs::FlashMgr::SM::Active::BusyFlash::WritingFlash::FLASH_DONE::[else]::[CRCMatch?]::[NoError?]::[NoError?]::[else]} */
                            else {
                                ERR_printf("Unable to write image Major Version after flashing. Error: 0x%08x.\n", me->errorCode);
                                status_ = Q_TRAN(&FlashMgr_Idle);
                            }
                        }
                        /* ${AOs::FlashMgr::SM::Active::BusyFlash::WritingFlash::FLASH_DONE::[else]::[CRCMatch?]::[NoError?]::[else]} */
                        else {
                            ERR_printf("Unable to write image CRC after flashing. Error: 0x%08x.\n", me->errorCode);
                            status_ = Q_TRAN(&FlashMgr_Idle);
                        }
                    }
                    /* ${AOs::FlashMgr::SM::Active::BusyFlash::WritingFlash::FLASH_DONE::[else]::[CRCMatch?]::[else]} */
                    else {
                        ERR_printf("Unable to write image size after flashing. Error: 0x%08x.\n", me->errorCode);
                        status_ = Q_TRAN(&FlashMgr_Idle);
                    }
                }
                /* ${AOs::FlashMgr::SM::Active::BusyFlash::WritingFlash::FLASH_DONE::[else]::[else]} */
                else {
                    me->errorCode = ERR_FLASH_INVALID_IMAGE_CRC_AFTER_FLASH;
                    ERR_printf("CRC check failed after flash. Error: 0x%08x.\n", me->errorCode);
                    ERR_printf("Expected  : 0x%08x\n", me->fwFlashMetadata._imageCrc);
                    ERR_printf("Calculated: 0x%08x\n", crcCheck);
                    status_ = Q_TRAN(&FlashMgr_Idle);
                }
            }
            break;
        }
        /* ${AOs::FlashMgr::SM::Active::BusyFlash::WritingFlash::FLASH_ERROR} */
        case FLASH_ERROR_SIG: {
            WRN_printf("FLASH_ERROR\n");
            /* ${AOs::FlashMgr::SM::Active::BusyFlash::WritingFlash::FLASH_ERROR::[RetriesLeft?]} */
            if (me->retryCurr < MAX_FLASH_RETRIES) {
                LOG_printf("Retrying to flash packet, retry %d out of %d max\n", me->retryCurr, MAX_FLASH_RETRIES);
                status_ = Q_TRAN(&FlashMgr_WritingFlash);
            }
            /* ${AOs::FlashMgr::SM::Active::BusyFlash::WritingFlash::FLASH_ERROR::[else]} */
            else {
                ERR_printf("No more retries\n");
                status_ = Q_TRAN(&FlashMgr_Idle);
            }
            break;
        }
        default: {
            status_ = Q_SUPER(&FlashMgr_BusyFlash);
            break;
        }
    }
    return status_;
}
Beispiel #24
0
/*${AOs::FlashMgr::SM::Active::BusyFlash::WaitingForFWData} ................*/
static QState FlashMgr_WaitingForFWData(FlashMgr * const me, QEvt const * const e) {
    QState status_;
    switch (e->sig) {
        /* ${AOs::FlashMgr::SM::Active::BusyFlash::WaitingForFWData} */
        case Q_ENTRY_SIG: {
            /* Ok, we are ready to receive FW data and start flashing. Post an event letting
             * CommMgr know we are ready for a data packet. */
            FlashStatusEvt *evt = Q_NEW(FlashStatusEvt, FLASH_OP_DONE_SIG);
            evt->errorCode = me->errorCode;
            QACTIVE_POST(AO_CommMgr, (QEvt *)(evt), AO_FlashMgr);

            me->errorCode = ERR_FLASH_WAIT_FOR_DATA_TIMEOUT; /* Set the timeout error code*/

            QTimeEvt_rearm(                         /* Re-arm timer on entry */
                &me->flashOpTimerEvt,
                SEC_TO_TICKS( LL_MAX_TOUT_SEC_FLASH_WAIT_FOR_DATA )
            );


            status_ = Q_HANDLED();
            break;
        }
        /* ${AOs::FlashMgr::SM::Active::BusyFlash::WaitingForFWData} */
        case Q_EXIT_SIG: {
            QTimeEvt_disarm(&me->flashOpTimerEvt); /* Disarm timer on exit */
            status_ = Q_HANDLED();
            break;
        }
        /* ${AOs::FlashMgr::SM::Active::BusyFlash::WaitingForFWData::FLASH_DATA} */
        case FLASH_DATA_SIG: {
            /* ${AOs::FlashMgr::SM::Active::BusyFlash::WaitingForFWData::FLASH_DATA::[ValidSeq?]} */
            if (me->fwPacketCurr + 1 == ((FWDataEvt const *)e)->seqCurr) {
                /* Calculate packet data CRC and make sure it matches the one sent over */
                CRC_ResetDR();
                uint32_t CRCValue = CRC32_Calc(((FWDataEvt const *)e)->dataBuf, ((FWDataEvt const *)e)->dataLen);
                /* ${AOs::FlashMgr::SM::Active::BusyFlash::WaitingForFWData::FLASH_DATA::[ValidSeq?]::[ValidCRC?]} */
                if (CRCValue == ((FWDataEvt const *)e)->dataCRC) {
                    me->fwDataToFlashLen = ((FWDataEvt const *)e)->dataLen;
                    MEMCPY(
                        me->fwDataToFlash,
                        ((FWDataEvt const *)e)->dataBuf,
                        me->fwDataToFlashLen
                    );
                    status_ = Q_TRAN(&FlashMgr_WritingFlash);
                }
                /* ${AOs::FlashMgr::SM::Active::BusyFlash::WaitingForFWData::FLASH_DATA::[ValidSeq?]::[else]} */
                else {
                    me->errorCode = ERR_FLASH_INVALID_FW_PACKET_CRC;
                    ERR_printf(
                        "Sent CRC (0x%08x) doesn't match calculated (0x%08x) for fw packet: %d. Error: 0x%08x\n",
                        CRCValue, ((FWDataEvt const *)e)->dataCRC, ((FWDataEvt const *)e)->seqCurr, me->errorCode);

                    status_ = Q_TRAN(&FlashMgr_Idle);
                }
            }
            /* ${AOs::FlashMgr::SM::Active::BusyFlash::WaitingForFWData::FLASH_DATA::[else]} */
            else {
                ERR_printf("Invalid fw packet sequence number. Expecting: %d, got %d\n", me->fwPacketCurr + 1, ((FWDataEvt const *)e)->seqCurr);
                status_ = Q_TRAN(&FlashMgr_Idle);
            }
            break;
        }
        default: {
            status_ = Q_SUPER(&FlashMgr_BusyFlash);
            break;
        }
    }
    return status_;
}