Пример #1
0
static unsigned MY_TYPE_T CONCAT(libbf_compute_expr_,MY_TYPE_T_STR) (Expression* expr, unsigned MY_TYPE_T* data_ptr)
{
  switch(expr->e_type)
  {
    case EXPR_CONSTANT:
      return expr->e_constant;
      break;
      
    case EXPR_DATA:
      return data_ptr[expr->e_offset];
      break;
      
    case EXPR_ADD:
      return CONCAT(libbf_compute_expr_,MY_TYPE_T_STR)(expr->e_expr1, data_ptr) +
             CONCAT(libbf_compute_expr_,MY_TYPE_T_STR)(expr->e_expr2, data_ptr);
      break;
      
    case EXPR_MUL:
      return CONCAT(libbf_compute_expr_,MY_TYPE_T_STR)(expr->e_expr1, data_ptr) *
             CONCAT(libbf_compute_expr_,MY_TYPE_T_STR)(expr->e_expr2, data_ptr);
      break;

    default:
      SHOULDNT_HAPPEN();
      return 0;
      break;
  }
}
Пример #2
0
/*============================================================================
Name    :   BitBangSPI_Send_Byte
------------------------------------------------------------------------------
Purpose :   Send and Read one byte using BitBangSPI Interface
Input   :   Data to send to slave
Output  :   Data read from slave
Notes   :	Called from BitBangSPI_Send_Message in this file
============================================================================*/
uint8_t BitBangSPI_Send_Byte(uint8_t c)
{
    unsigned bit;
    for (bit = 0; bit < 8; bit++) {
        /* write MOSI on trailing edge of previous clock */
        if (c & 0x80)
            CONCAT( PORT, SPI_BB_MOSI, _OUTSET) =  ( 1 << MOSI_BB );
        else
            CONCAT( PORT, SPI_BB_MOSI, _OUTCLR) =  ( 1 << MOSI_BB );

        c <<= 1;

        /* half a clock cycle before leading/rising edge */
        DELAYUS(1);

        CONCAT( PORT, SPI_BB_SCK, _OUTSET) = (1 << SCK_BB );

        /* half a clock cycle before trailing/falling edge */
        DELAYUS(1);

        /* read MISO on trailing edge */
        c |= ((CONCAT( PORT, SPI_BB_MISO, _IN) >> MISO_BB) & 0x01);
        CONCAT( PORT, SPI_BB_SCK, _OUTCLR) = (1 << SCK_BB );
    }

    CONCAT( PORT, SPI_BB_MOSI, _OUTCLR) =  ( 1 << MOSI_BB );

    DELAYUS(50);

    return c;
}
Пример #3
0
void CONCAT(LIBBF_INTERPRETER_OPTIMIZER_RADIX, MY_TYPE_T_STR) (const char* source_code)
{
  libbf_interpreter_optimizer_general_internal(
    source_code,
    (void*)CONCAT(CONCAT(LIBBF_INTERPRETER_OPTIMIZER_RADIX, internal_), MY_TYPE_T_STR),
#ifdef PROFILE
    TRUE
#else
    FALSE
#endif
  );
}
Пример #4
0
static int concat_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
{
	struct mtd_concat *concat = CONCAT(mtd);
	int i, err = 0;

	for (i = 0; i < concat->num_subdev; i++) {
		struct mtd_info *subdev = concat->subdev[i];
		uint64_t size;

		if (ofs >= subdev->size) {
			size = 0;
			ofs -= subdev->size;
			continue;
		}
		if (ofs + len > subdev->size)
			size = subdev->size - ofs;
		else
			size = len;

		err = mtd_unlock(subdev, ofs, size);
		if (err)
			break;

		len -= size;
		if (len == 0)
			break;

		err = -EINVAL;
		ofs = 0;
	}

	return err;
}
Пример #5
0
static int concat_block_isbad(struct mtd_info *mtd, loff_t ofs)
{
    struct mtd_concat *concat = CONCAT(mtd);
    int i, res = 0;

    if (!concat->subdev[0]->block_isbad)
        return res;

    if (ofs > mtd->size)
        return -EINVAL;

    for (i = 0; i < concat->num_subdev; i++) {
        struct mtd_info *subdev = concat->subdev[i];

        if (ofs >= subdev->size) {
            ofs -= subdev->size;
            continue;
        }

        res = subdev->block_isbad(subdev, ofs);
        break;
    }

    return res;
}
Пример #6
0
void COBB::GetSideData(const CVector<3, Num> &vCenter, const CVector<3, Num> (&vExtent)[3], int iSide,
                       CVector<3, Num> &vOrigin, CVector<3, Num> &vX, CVector<3, Num> &vY, CVector<4, Num> &vPlane)
{
  int iDim, iDimX, iDimY;
  CVector<3, Num> vNorm;

  ASSERT(iSide >= 0 && iSide < 6);

  iDim = iSide >> 1;
  iDimX = (iDim + 1) % 3;
  iDimY = (iDim + 2) % 3;

  if (iSide & 1) {
    vOrigin = vCenter + vExtent[iDim];
    vOrigin -= vExtent[iDimX];
    vOrigin -= vExtent[iDimY];
    vX = vExtent[iDimX] * 2;
    vY = vExtent[iDimY] * 2;
    vNorm = vExtent[iDim];
  } else {
    vOrigin = vCenter - vExtent[iDim];
    vOrigin += vExtent[iDimX];
    vOrigin -= vExtent[iDimY];
    vX = vExtent[iDimX] * -2;
    vY = vExtent[iDimY] * 2;
    vNorm = -vExtent[iDim];
  }
  vNorm.Normalize();
  vPlane.Set(vNorm);
  vPlane.w() = -(vOrigin % vNorm);
  ASSERT(ID(CONCAT(CVector<4, Num>::Get(vCenter.x(), vCenter.y(), vCenter.z(), 1) % vPlane < 0)));
}
Пример #7
0
static int concat_block_markbad(struct mtd_info *mtd, loff_t ofs)
{
    struct mtd_concat *concat = CONCAT(mtd);
    int i, err = -EINVAL;

    if (!concat->subdev[0]->block_markbad)
        return 0;

    if (ofs > mtd->size)
        return -EINVAL;

    for (i = 0; i < concat->num_subdev; i++) {
        struct mtd_info *subdev = concat->subdev[i];

        if (ofs >= subdev->size) {
            ofs -= subdev->size;
            continue;
        }

        err = subdev->block_markbad(subdev, ofs);
        if (!err)
            mtd->ecc_stats.badblocks++;
        break;
    }

    return err;
}
Пример #8
0
void mtd_concat_destroy(struct mtd_info *mtd)
{
    struct mtd_concat *concat = CONCAT(mtd);
    if (concat->mtd.numeraseregions)
        kfree(concat->mtd.eraseregions);
    kfree(concat);
}
Пример #9
0
/*
 * try to support NOMMU mmaps on concatenated devices
 * - we don't support subdev spanning as we can't guarantee it'll work
 */
static unsigned long concat_get_unmapped_area(struct mtd_info *mtd,
					      unsigned long len,
					      unsigned long offset,
					      unsigned long flags)
{
	struct mtd_concat *concat = CONCAT(mtd);
	int i;

	for (i = 0; i < concat->num_subdev; i++) {
		struct mtd_info *subdev = concat->subdev[i];

		if (offset >= subdev->size) {
			offset -= subdev->size;
			continue;
		}

		/* we've found the subdev over which the mapping will reside */
		if (offset + len > subdev->size)
			return (unsigned long) -EINVAL;

		if (subdev->get_unmapped_area)
			return subdev->get_unmapped_area(subdev, len, offset,
							 flags);

		break;
	}

	return (unsigned long) -ENOSYS;
}
Пример #10
0
/* Writes to ut_os_version_index a zero-based index identifying the OS version and HW model.
 * Also sets up the syscalls table.
 * Should be called only once.
 * May be used for OS-specific arrays of constants (marked with "// OS-specific"). */
void ut_read_os_version_index(void) {
	#if defined STAGE1
			sc_addrs_ptr = CONCAT(CONCAT(CONCAT(syscalls_light_, MODEL), _), OS_VERSION);
	switch (*(unsigned*)(OS_BASE_ADDRESS + 0x20)) {
		// OS-specific
		case 0x102F0FA0:  // 3.1.0 non-CAS
			ut_os_version_index = 0;
			break;
		case 0x102F16D0:  // 3.1.0 CAS
			ut_os_version_index = 1;
			break;
		case 0x102F0A10:  // 3.1.0 non-CAS CX
			ut_os_version_index = 2;
			break;
		case 0x102F11A0:  // 3.1.0 CAS CX
			ut_os_version_index = 3;
			break;
	}
	#else
	/* The heuristic is based on the address of INT_Initialize - Thanks Goplat.
	 * The address is read from the RAM copy and not the real vector which is
	 * destroyed at installation time */
	switch (*(unsigned*)(OS_BASE_ADDRESS + 0x20)) {
		// OS-specific
		case 0x102F0FA0:  // 3.1.0 non-CAS
			ut_os_version_index = 0;
			sc_addrs_ptr = syscalls_ncas_3_1_0;
			break;
		case 0x102F16D0:  // 3.1.0 CAS
			ut_os_version_index = 1;
			sc_addrs_ptr = syscalls_cas_3_1_0;
			break;
		case 0x102F0A10:  // 3.1.0 non-CAS CX
			ut_os_version_index = 2;
			sc_addrs_ptr = syscalls_ncascx_3_1_0;
			break;
		case 0x102F11A0:  // 3.1.0 CAS CX
			ut_os_version_index = 3;
			sc_addrs_ptr = syscalls_cascx_3_1_0;
			break;
		default:
			ut_panic("v?");
	}
	#endif
}
Пример #11
0
/*============================================================================
Name    :   SPI_Master_Init
------------------------------------------------------------------------------
Purpose :   Initialize SPI Interface
Input   :   n/a
Output  :   n/a
Notes   :	Called from QDebug_Init in QDebug.c
============================================================================*/
void SPI_Master_Init (void)
{
    // MOSI, SCK and SS are outputs. Pullup on MISO
    //SPI_DDR |= (1<<SS) | (1<<MOSI) | (1<<SCK) ;
    CONCAT( PORT, SPI_SS, _DIR) =  (1<<SS) | (1<<MOSI) | (1<<SCK) ;

    //SPI_DDR &=~(1<<MISO);
    CONCAT( PORT, SPI_SS, _DIR) &=~(1<<MISO);

   //SPI_PORT &=~ ((1<<SS) | (1<<SCK) | (1<<MOSI)) ;
    CONCAT( PORT, SPI_SS, _OUT)  &=~ ((1<<SS) | (1<<SCK) | (1<<MOSI)) ;

	//SPI_PORT |= (1<<MISO);
    CONCAT( PORT, SPI_SS, _OUT) |= (1<<MISO);

  	SPIC_CTRL = (1<<SPI_ENABLE_bp) | (1<<SPI_MASTER_bp) |
		(0<<SPI_PRESCALER1_bp)|(1<<SPI_PRESCALER0_bp);
}
Пример #12
0
static int
concat_read_ecc(struct mtd_info *mtd, loff_t from, size_t len,
                size_t * retlen, u_char * buf, u_char * eccbuf,
                struct nand_oobinfo *oobsel)
{
    struct mtd_concat *concat = CONCAT(mtd);
    int err = -EINVAL;
    int i;

    *retlen = 0;

    for (i = 0; i < concat->num_subdev; i++) {
        struct mtd_info *subdev = concat->subdev[i];
        size_t size, retsize;

        if (from >= subdev->size) {
            /* Not destined for this subdev */
            size = 0;
            from -= subdev->size;
            continue;
        }

        if (from + len > subdev->size)
            /* First part goes into this subdev */
            size = subdev->size - from;
        else
            /* Entire transaction goes into this subdev */
            size = len;

        if (subdev->read_ecc)
            err = subdev->read_ecc(subdev, from, size,
                                   &retsize, buf, eccbuf, oobsel);
        else
            err = -EINVAL;

        if (err)
            break;

        *retlen += retsize;
        len -= size;
        if (len == 0)
            break;

        err = -EINVAL;
        buf += size;
        if (eccbuf) {
            eccbuf += subdev->oobsize;
            /* in nand.c at least, eccbufs are
               tagged with 2 (int)eccstatus'; we
               must account for these */
            eccbuf += 2 * (sizeof (int));
        }
        from = 0;
    }
    return err;
}
Пример #13
0
static int
concat_read_oob(struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops)
{
    struct mtd_concat *concat = CONCAT(mtd);
    struct mtd_oob_ops devops = *ops;
    int i, err, ret = 0;

    ops->retlen = ops->oobretlen = 0;

    for (i = 0; i < concat->num_subdev; i++) {
        struct mtd_info *subdev = concat->subdev[i];

        if (from >= subdev->size) {
            from -= subdev->size;
            continue;
        }

        /* partial read ? */
        if (from + devops.len > subdev->size)
            devops.len = subdev->size - from;

        err = subdev->read_oob(subdev, from, &devops);
        ops->retlen += devops.retlen;
        ops->oobretlen += devops.oobretlen;

        /* Save information about bitflips! */
        if (unlikely(err)) {
            if (err == -EBADMSG) {
                mtd->ecc_stats.failed++;
                ret = err;
            } else if (err == -EUCLEAN) {
                mtd->ecc_stats.corrected++;
                /* Do not overwrite -EBADMSG !! */
                if (!ret)
                    ret = err;
            } else
                return err;
        }

        if (devops.datbuf) {
            devops.len = ops->len - ops->retlen;
            if (!devops.len)
                return ret;
            devops.datbuf += devops.retlen;
        }
        if (devops.oobbuf) {
            devops.ooblen = ops->ooblen - ops->oobretlen;
            if (!devops.ooblen)
                return ret;
            devops.oobbuf += ops->oobretlen;
        }

        from = 0;
    }
    return -EINVAL;
}
Пример #14
0
static void concat_resume(struct mtd_info *mtd)
{
    struct mtd_concat *concat = CONCAT(mtd);
    int i;

    for (i = 0; i < concat->num_subdev; i++) {
        struct mtd_info *subdev = concat->subdev[i];
        subdev->resume(subdev);
    }
}
Пример #15
0
static int
concat_read(struct mtd_info *mtd, loff_t from, size_t len,
	    size_t * retlen, u_char * buf)
{
	struct mtd_concat *concat = CONCAT(mtd);
	int ret = 0, err;
	int i;

#ifdef __UBOOT__
	*retlen = 0;
#endif

	for (i = 0; i < concat->num_subdev; i++) {
		struct mtd_info *subdev = concat->subdev[i];
		size_t size, retsize;

		if (from >= subdev->size) {
			/* Not destined for this subdev */
			size = 0;
			from -= subdev->size;
			continue;
		}
		if (from + len > subdev->size)
			/* First part goes into this subdev */
			size = subdev->size - from;
		else
			/* Entire transaction goes into this subdev */
			size = len;

		err = mtd_read(subdev, from, size, &retsize, buf);

		/* Save information about bitflips! */
		if (unlikely(err)) {
			if (mtd_is_eccerr(err)) {
				mtd->ecc_stats.failed++;
				ret = err;
			} else if (mtd_is_bitflip(err)) {
				mtd->ecc_stats.corrected++;
				/* Do not overwrite -EBADMSG !! */
				if (!ret)
					ret = err;
			} else
				return err;
		}

		*retlen += retsize;
		len -= size;
		if (len == 0)
			return ret;

		buf += size;
		from = 0;
	}
	return -EINVAL;
}
Пример #16
0
/*============================================================================
Name    :   BitBangSPI_Master_Init
------------------------------------------------------------------------------
Purpose :   Initialize BitBangSPI Interface
Input   :   n/a
Output  :   n/a
Notes   :	Called from QDebug_Init in QDebug.c
============================================================================*/
void BitBangSPI_Master_Init (void)
{
    CONCAT( PORT, SPI_BB_SS, _DIRSET) =  ((1<<SS_BB));
    CONCAT( PORT, SPI_BB_MOSI, _DIRSET) =  (( 1 << MOSI_BB ));
    CONCAT( PORT, SPI_BB_SCK, _DIRSET) =  (( 1 << SCK_BB ));

    CONCAT( PORT, SPI_BB_MISO, _DIRCLR) =  ( 1 << MISO_BB );

    CONCAT( PORT, SPI_BB_SS, _OUTCLR) =  ((1<<SS_BB));
    CONCAT( PORT, SPI_BB_MOSI, _OUTCLR) =  (( 1 << MOSI_BB ));
    CONCAT( PORT, SPI_BB_SCK, _OUTCLR) =  (( 1 << SCK_BB ));
    CONCAT( PORT, SPI_BB_MISO, _OUTSET) =  ( 1 << MISO_BB );
}
Пример #17
0
static int concat_suspend(struct mtd_info *mtd)
{
    struct mtd_concat *concat = CONCAT(mtd);
    int i, rc = 0;

    for (i = 0; i < concat->num_subdev; i++) {
        struct mtd_info *subdev = concat->subdev[i];
        if ((rc = subdev->suspend(subdev)) < 0)
            return rc;
    }
    return rc;
}
Пример #18
0
static int
concat_write_ecc(struct mtd_info *mtd, loff_t to, size_t len,
                 size_t * retlen, const u_char * buf, u_char * eccbuf,
                 struct nand_oobinfo *oobsel)
{
    struct mtd_concat *concat = CONCAT(mtd);
    int err = -EINVAL;
    int i;

    if (!(mtd->flags & MTD_WRITEABLE))
        return -EROFS;

    *retlen = 0;

    for (i = 0; i < concat->num_subdev; i++) {
        struct mtd_info *subdev = concat->subdev[i];
        size_t size, retsize;

        if (to >= subdev->size) {
            size = 0;
            to -= subdev->size;
            continue;
        }
        if (to + len > subdev->size)
            size = subdev->size - to;
        else
            size = len;

        if (!(subdev->flags & MTD_WRITEABLE))
            err = -EROFS;
        else if (subdev->write_ecc)
            err = subdev->write_ecc(subdev, to, size,
                                    &retsize, buf, eccbuf, oobsel);
        else
            err = -EINVAL;

        if (err)
            break;

        *retlen += retsize;
        len -= size;
        if (len == 0)
            break;

        err = -EINVAL;
        buf += size;
        if (eccbuf)
            eccbuf += subdev->oobsize;
        to = 0;
    }
    return err;
}
Пример #19
0
static BOOL add_hooks()
{
    wchar_t curFile[512];
    GetModuleFileNameW(NULL, curFile, 512);

    wstring f = strlower(wstring(curFile));

    // bail immediately if we're in a system process. We don't want to hook, log, anything -
    // this instance is being used for a shell extension.
    if(f.find(L"dllhost.exe") != wstring::npos || f.find(L"explorer.exe") != wstring::npos)
    {
#ifndef _RELEASE
        OutputDebugStringA("Hosting " STRINGIZE(RDOC_DLL_FILE) ".dll in shell process\n");
#endif
        return TRUE;
    }

    if(f.find(CONCAT(L, STRINGIZE(RDOC_DLL_FILE)) L"cmd.exe") != wstring::npos ||
            f.find(CONCAT(L, STRINGIZE(RDOC_DLL_FILE)) L"ui.vshost.exe") != wstring::npos ||
            f.find(L"q" CONCAT(L, STRINGIZE(RDOC_DLL_FILE)) L".exe") != wstring::npos ||
            f.find(CONCAT(L, STRINGIZE(RDOC_DLL_FILE)) L"ui.exe") != wstring::npos)
    {
        RDCDEBUG("Not creating hooks - in replay app");

        RenderDoc::Inst().SetReplayApp(true);

        RenderDoc::Inst().Initialise();

        return true;
    }

    RenderDoc::Inst().Initialise();

    RDCLOG("Loading into %ls", curFile);

    LibraryHooks::GetInstance().CreateHooks();

    return TRUE;
}
Пример #20
0
/**
 * \brief Initialize BitBangSPI Interface.
 */
void BitBangSPI_Master_Init(void)
{
#if SAM3N
	CONCAT(PORT, SPI_BB, _OER) =
			((1 << MOSI_BB) | (1 << SCK_BB) | (1 << PIO_SS));
	CONCAT(PORT, SPI_BB, _ODR) = (1 << MISO_BB);
	CONCAT(PORT, SPI_BB, _CODR) =
			((1 << MOSI_BB) | (1 << SCK_BB) | (1 << PIO_SS));
	CONCAT(PORT, SPI_BB, _SODR) = (1 << MISO_BB);
#else
	CONCAT(PORT, SPI_BB, _OER) = ((1 << MOSI_BB) | (1 << SCK_BB));
	CONCAT(PORT, SPI_BB, _ODR) = (1 << MISO_BB);
	CONCAT(PORT, SPI_BB, _CODR) = ((1 << MOSI_BB) | (1 << SCK_BB));
	CONCAT(PORT, SPI_BB, _SODR) = (1 << MISO_BB);
#endif
}
Пример #21
0
/**
 * \brief  Send and Read one byte using BitBangSPI Interface.
 *
 * \param c  Data to send to slave.
 *
 * \return Data read from slave.
 */
static uint8_t BitBangSPI_Send_Byte(uint8_t c)
{
	uint32_t bit;
	volatile uint32_t i;

	for (bit = 0; bit < 8; bit++) {
		/* Write MOSI on trailing edge of previous clock */
		if (c & 0x80) {
			CONCAT(PORT, SPI_BB, _SODR) = (1 << MOSI_BB);
		} else {
			CONCAT(PORT, SPI_BB, _CODR) = (1 << MOSI_BB);
		}

		c <<= 1;

		/* Half a clock cycle before leading/rising edge */
		DELAY1US();

		CONCAT(PORT, SPI_BB, _SODR) = (1 << SCK_BB);

		/* Half a clock cycle before trailing/falling edge */
		DELAY1US();

		/* Read MISO on trailing edge */
		c |= ((CONCAT(PORT, SPI_BB, _PDSR) >> MISO_BB) & 0x01);
		CONCAT(PORT, SPI_BB, _CODR) = (1 << SCK_BB);
	}

	CONCAT(PORT, SPI_BB, _CODR) = (1 << MOSI_BB);

	for (i = 0; i < 50; i++) {
		DELAY50US();
	}

	return c;
}
Пример #22
0
static int
concat_read_oob(struct mtd_info *mtd, loff_t from, size_t len,
                size_t * retlen, u_char * buf)
{
    struct mtd_concat *concat = CONCAT(mtd);
    int err = -EINVAL;
    int i;

    *retlen = 0;

    for (i = 0; i < concat->num_subdev; i++) {
        struct mtd_info *subdev = concat->subdev[i];
        size_t size, retsize;

        if (from >= subdev->size) {
            /* Not destined for this subdev */
            size = 0;
            from -= subdev->size;
            continue;
        }
        if (from + len > subdev->size)
            /* First part goes into this subdev */
            size = subdev->size - from;
        else
            /* Entire transaction goes into this subdev */
            size = len;

        if (subdev->read_oob)
            err = subdev->read_oob(subdev, from, size,
                                   &retsize, buf);
        else
            err = -EINVAL;

        if (err)
            break;

        *retlen += retsize;
        len -= size;
        if (len == 0)
            break;

        err = -EINVAL;
        buf += size;
        from = 0;
    }
    return err;
}
Пример #23
0
static int
concat_write_oob(struct mtd_info *mtd, loff_t to, struct mtd_oob_ops *ops)
{
    struct mtd_concat *concat = CONCAT(mtd);
    struct mtd_oob_ops devops = *ops;
    int i, err;

    if (!(mtd->flags & MTD_WRITEABLE))
        return -EROFS;

    ops->retlen = 0;

    for (i = 0; i < concat->num_subdev; i++) {
        struct mtd_info *subdev = concat->subdev[i];

        if (to >= subdev->size) {
            to -= subdev->size;
            continue;
        }

        /* partial write ? */
        if (to + devops.len > subdev->size)
            devops.len = subdev->size - to;

        err = subdev->write_oob(subdev, to, &devops);
        ops->retlen += devops.retlen;
        if (err)
            return err;

        if (devops.datbuf) {
            devops.len = ops->len - ops->retlen;
            if (!devops.len)
                return 0;
            devops.datbuf += devops.retlen;
        }
        if (devops.oobbuf) {
            devops.ooblen = ops->ooblen - ops->oobretlen;
            if (!devops.ooblen)
                return 0;
            devops.oobbuf += devops.oobretlen;
        }
        to = 0;
    }
    return -EINVAL;
}
Пример #24
0
static int concat_read (struct mtd_info *mtd, loff_t from, size_t len, 
			size_t *retlen, u_char *buf)
{
	struct mtd_concat *concat = CONCAT(mtd);
	int err = -EINVAL;
	int i;

	*retlen = 0;

	for(i = 0; i < concat->num_subdev; i++)
	{
		struct mtd_info *subdev = concat->subdev[i];
		size_t size, retsize;

		if (from >= subdev->size)
		{
			size  = 0;
			from -= subdev->size;
		}
		else
		{
			if (from + len > subdev->size)
				size = subdev->size - from;
			else
				size = len;

			err = subdev->read(subdev, from, size, &retsize, buf);

			if(err)
				break;

			*retlen += retsize;
			len -= size;
			if(len == 0)
				break;

			err = -EINVAL;
			buf += size;
			from = 0;
		}
	}
	return err;
}
Пример #25
0
static int
concat_write(struct mtd_info *mtd, loff_t to, size_t len,
	     size_t * retlen, const u_char * buf)
{
	struct mtd_concat *concat = CONCAT(mtd);
	int err = -EINVAL;
	int i;

#ifdef __UBOOT__
	*retlen = 0;
#endif

	for (i = 0; i < concat->num_subdev; i++) {
		struct mtd_info *subdev = concat->subdev[i];
		size_t size, retsize;

		if (to >= subdev->size) {
			size = 0;
			to -= subdev->size;
			continue;
		}
		if (to + len > subdev->size)
			size = subdev->size - to;
		else
			size = len;

		err = mtd_write(subdev, to, size, &retsize, buf);
		if (err)
			break;

		*retlen += retsize;
		len -= size;
		if (len == 0)
			break;

		err = -EINVAL;
		buf += size;
		to = 0;
	}
	return err;
}
Пример #26
0
/*
 * try to support NOMMU mmaps on concatenated devices
 * - we don't support subdev spanning as we can't guarantee it'll work
 */
static unsigned long concat_get_unmapped_area(struct mtd_info *mtd,
					      unsigned long len,
					      unsigned long offset,
					      unsigned long flags)
{
	struct mtd_concat *concat = CONCAT(mtd);
	int i;

	for (i = 0; i < concat->num_subdev; i++) {
		struct mtd_info *subdev = concat->subdev[i];

		if (offset >= subdev->size) {
			offset -= subdev->size;
			continue;
		}

		return mtd_get_unmapped_area(subdev, len, offset, flags);
	}

	return (unsigned long) -ENOSYS;
}
Пример #27
0
static int concat_lock (struct mtd_info *mtd, loff_t ofs, size_t len)
{
	struct mtd_concat *concat = CONCAT(mtd);
	int i, err = -EINVAL;

	if ((len + ofs) > mtd->size) 
		return -EINVAL;

	for(i = 0; i < concat->num_subdev; i++)
	{
		struct mtd_info *subdev = concat->subdev[i];
		size_t size;

		if (ofs >= subdev->size)
		{
			size  = 0;
			ofs -= subdev->size;
		}
		else
		{
			if (ofs + len > subdev->size)
				size = subdev->size - ofs;
			else
				size = len;

			err = subdev->lock(subdev, ofs, size);

			if(err)
				break;

			len -= size;
			if(len == 0)
				break;

			err = -EINVAL;
			ofs = 0;
		}
	}
	return err;
}
Пример #28
0
static int concat_block_isbad(struct mtd_info *mtd, loff_t ofs)
{
	struct mtd_concat *concat = CONCAT(mtd);
	int i, res = 0;

	if (!mtd_can_have_bb(concat->subdev[0]))
		return res;

	for (i = 0; i < concat->num_subdev; i++) {
		struct mtd_info *subdev = concat->subdev[i];

		if (ofs >= subdev->size) {
			ofs -= subdev->size;
			continue;
		}

		res = mtd_block_isbad(subdev, ofs);
		break;
	}

	return res;
}
/*============================================================================
*  Name    :   BitBangSPI_Master_Init
*  ------------------------------------------------------------------------------
*  Purpose :   Initialize BitBangSPI Interface
*  Input   :   n/a
*  Output  :   n/a
*  Notes   :	Called from QDebug_Init in QDebug.c
*  ============================================================================*/
void BitBangSPI_Master_Init(void)
{
	struct port_config config_port_pin;

	port_get_config_defaults(&config_port_pin);

	config_port_pin.direction  = PORT_PIN_DIR_OUTPUT;

	port_pin_set_config(CONCAT(PIN_P, SPI_BB_SS, SS_BB), &config_port_pin);
	port_pin_set_config(CONCAT(PIN_P, SPI_BB_MOSI,MOSI_BB), &config_port_pin);
	port_pin_set_config(CONCAT(PIN_P, SPI_BB_SCK,SCK_BB), &config_port_pin);

	config_port_pin.direction  = PORT_PIN_DIR_INPUT;
	config_port_pin.input_pull = PORT_PIN_PULL_UP;
	port_pin_set_config(CONCAT(PIN_P, SPI_BB_MISO,MISO_BB), &config_port_pin);

	port_pin_set_output_level(CONCAT(PIN_P, SPI_BB_SS, SS_BB), 0u);
	port_pin_set_output_level(CONCAT(PIN_P, SPI_BB_MISO, MISO_BB), 1u);
	port_pin_set_output_level(CONCAT(PIN_P, SPI_BB_MOSI, MOSI_BB), 0u);
	port_pin_set_output_level(CONCAT(PIN_P, SPI_BB_SCK, SCK_BB), 0u);



}
/*============================================================================
*  Name    :   BitBangSPI_Send_Byte
*  ------------------------------------------------------------------------------
*  Purpose :   Send and Read one byte using BitBangSPI Interface
*  Input   :   Data to send to slave
*  Output  :   Data read from slave
*  Notes   :	Called from BitBangSPI_Send_Message in this file
*  ============================================================================*/
uint8_t BitBangSPI_Send_Byte(uint8_t c)
{
	uint32_t bit;
	bool i;
	for (bit = 0u; bit < 8u; bit++) {
		/* write MOSI on trailing edge of previous clock */
		if (c & 0x80u) {
			port_pin_set_output_level(CONCAT(PIN_P, SPI_BB_MOSI,
					MOSI_BB), 1u);
		} else {
			port_pin_set_output_level(CONCAT(PIN_P, SPI_BB_MOSI,
					MOSI_BB), 0u);
		}

		c <<= 1u;

		/* half a clock cycle before leading/rising edge */
		cpu_delay_us(1u); /* SHOULD BE ~3uS. */
		port_pin_set_output_level(CONCAT(PIN_P, SPI_BB_SCK, SCK_BB), 1u);

		/* half a clock cycle before trailing/falling edge */
		cpu_delay_us(1u); /* SHOULD BE ~3uS. */

		/* read MISO on trailing edge */
		i = (port_pin_get_input_level(CONCAT(PIN_P, SPI_BB_MISO, MISO_BB)));
		if (i == true) {
			c |= (0x01u);
		} else {
		}

		port_pin_set_output_level(CONCAT(PIN_P, SPI_BB_SCK, SCK_BB), 0u);
	}

	port_pin_set_output_level(CONCAT(PIN_P, SPI_BB_MOSI, MOSI_BB), 0u);

	cpu_delay_us(50u); /* SHOULD BE ~18uS. */

	return c;
}