Exemplo n.º 1
0
static vsf_err_t nuc100swj_iap_poll_finish(struct nuc100_fl_t *fl)
{
	uint32_t iap_cnt, iap_fail;
	
	// read fail
	if (adi_memap_read_reg32(NUC100_IAP_FAIL_ADDR, &iap_fail, 1))
	{
		LOG_ERROR(ERRMSG_FAILURE_OPERATION, "read iap fail");
		return ERRCODE_FAILURE_OPERATION;
	}
	if (iap_fail)
	{
		LOG_ERROR(ERRMSG_FAILURE_OPERATION, "run iap");
		cm_dump(NUC100_IAP_BASE, sizeof(iap_code));
		return VSFERR_FAIL;
	}
	
	// read busy
	if (adi_memap_read_reg32(NUC100_IAP_CNT_ADDR, &iap_cnt, 1))
	{
		LOG_ERROR(ERRMSG_FAILURE_OPERATION, "read iap sync");
		return ERRCODE_FAILURE_OPERATION;
	}
	iap_cnt = LE_TO_SYS_U32(iap_cnt);
	if (iap_cnt > fl->iap_cnt)
	{
		cm_dump(NUC100_IAP_BASE, sizeof(iap_code));
		return VSFERR_FAIL;
	}
	return (iap_cnt == fl->iap_cnt) ? VSFERR_NONE : VSFERR_NOT_READY;
}
Exemplo n.º 2
0
static vsf_err_t at91sam3swj_iap_call(struct at91sam3swj_iap_command_t *cmd,
							struct at91sam3swj_iap_reply_t *reply)
{
	uint32_t reg;
	uint32_t start, end;
	uint32_t i;
	
	reg = cmd->iap_command | AT91SAM3_EEFC_FKEY;
	if (adi_memap_write_reg32(cmd->eefc_base + AT91SAM3_EEFC_FCR_OFFSET,
								&reg, 1))
	{
		LOG_ERROR(ERRMSG_FAILURE_OPERATION, "write fcr");
		return ERRCODE_FAILURE_OPERATION;
	}
	
	start = (uint32_t)(clock() / (CLOCKS_PER_SEC / 1000));
	do
	{
		reg = 0;
		if (adi_memap_read_reg32(cmd->eefc_base + AT91SAM3_EEFC_FSR_OFFSET,
									&reg, 1))
		{
			LOG_ERROR(ERRMSG_FAILURE_OPERATION, "read fsr");
			return ERRCODE_FAILURE_OPERATION;
		}
		reg = LE_TO_SYS_U32(reg);
		end = (uint32_t)(clock() / (CLOCKS_PER_SEC / 1000));
	} while (!(reg & 1) && ((end - start) < 500));
	if (!(reg & 1) || (reg & 0x60))
	{
		return VSFERR_FAIL;
	}
	
	if ((reply != NULL) && (reply->data != NULL) && (reply->data_num > 0))
	{
		for (i = 0; i < reply->data_num; i++)
		{
			if (adi_memap_read_reg32(cmd->eefc_base + AT91SAM3_EEFC_FRR_OFFSET,
										&reply->data[i], 1))
			{
				LOG_ERROR(ERRMSG_FAILURE_OPERATION, "read frr");
				return ERRCODE_FAILURE_OPERATION;
			}
			reply->data[i] = LE_TO_SYS_U32(reply->data[i]);
		}
	}
	
	return VSFERR_NONE;
}
Exemplo n.º 3
0
static vsf_err_t nuc400swj_iap_poll_param_taken(struct nuc400_fl_t *fl)
{
	uint32_t sync;
	
	REFERENCE_PARAMETER(fl);
	
	// read sync
	if (adi_memap_read_reg32(NUC400_IAP_SYNC_ADDR, &sync, 1))
	{
		LOG_ERROR(ERRMSG_FAILURE_OPERATION, "read iap sync");
		return ERRCODE_FAILURE_OPERATION;
	}
	sync = LE_TO_SYS_U32(sync);
	return (0 == sync) ? VSFERR_NONE : VSFERR_NOT_READY;
}
Exemplo n.º 4
0
static vsf_err_t nuc400swj_isp_run(uint8_t cmd, uint32_t addr, uint32_t *data,
									uint32_t num, bool read)
{
	vsf_err_t err = VSFERR_NONE;
	uint32_t reg, i;
	
	for (i = 0; i < num; i++)
	{
		if (!read && (data != NULL))
		{
			if (adi_memap_write_reg32(NUC400_REG_ISPADR, &data[i], 0))
			{
				err = ERRCODE_FAILURE_OPERATION;
				break;
			}
		}
		reg = addr;
		addr += 4;
		if (adi_memap_write_reg32(NUC400_REG_ISPADR, &reg, 0))
		{
			err = ERRCODE_FAILURE_OPERATION;
			break;
		}
		reg = cmd;
		if (adi_memap_write_reg32(NUC400_REG_ISPCMD, &reg, 0))
		{
			err = ERRCODE_FAILURE_OPERATION;
			break;
		}
		reg = NUC400_REG_ISPTRG_ISPGO;
		if (adi_memap_write_reg32(NUC400_REG_ISPTRG, &reg, 0))
		{
			err = ERRCODE_FAILURE_OPERATION;
			break;
		}
		while (1)
		{
			if (adi_memap_read_reg32(NUC400_REG_ISPTRG, &reg, 1))
			{
				err = ERRCODE_FAILURE_OPERATION;
				break;
			}
			if (!(reg & NUC400_REG_ISPTRG_ISPGO))
			{
				break;
			}
		}
		if (adi_memap_read_reg32(NUC400_REG_ISPCON, &reg, 1) ||
			(reg & NUC400_REG_ISPCON_ISPFF))
		{
			err = ERRCODE_FAILURE_OPERATION;
			break;
		}
		if (read && (data != NULL) &&
			adi_memap_read_reg32(NUC400_REG_ISPDAT, &data[i], 1))
		{
			err = ERRCODE_FAILURE_OPERATION;
			break;
		}
	}
	return err;
}