Example #1
0
/** Return TRUE if the given switch is an opto.  Optos
are defined in the opto mask array, which is auto generated from
the machine description. */
bool switch_is_opto (const switchnum_t sw)
{
	return bitarray_test (mach_opto_mask, sw);
}
Example #2
0
File: lamp.c Project: Dmilo/freewpc
bool bit_test (const_bitset matrix, U8 bit)
{
	return bitarray_test (matrix, bit);
}
Example #3
0
/** Return TRUE if the given switch is CLOSED.
 * This scans the logical values calculated at periodic service time. */
bool switch_poll (const switchnum_t sw)
{
	return bitarray_test (sw_logical, sw);
}
Example #4
0
static size_t lpc2_flash_writeDirect(struct KBlock *blk, block_idx_t idx, const void *_buf, size_t offset, size_t size)
{
	ASSERT(offset == 0);
	ASSERT(FLASH_PAGE_SIZE_BYTES == size);

	Flash *fls = FLASH_CAST(blk);
	if (!(fls->blk.priv.flags & KB_WRITE_ONCE))
		ASSERT(sector_size(idx) <= FLASH_PAGE_SIZE_BYTES);

	const uint8_t *buf = (const uint8_t *)_buf;
	cpu_flags_t flags;

	//Compute page address of current page.
	uint32_t addr = idx * blk->blk_size;
	uint32_t sector = addr_to_sector(addr);
	// Compute the first page index in the sector to manage the status
	int idx_sector = sector_addr(sector) /  blk->blk_size;

	LOG_INFO("Writing page[%ld]sector[%ld]idx[%d]\n", idx, sector, idx_sector);
	IRQ_SAVE_DISABLE(flags);

	IapCmd cmd;
	IapRes res;
	cmd.cmd = PREPARE_SECTOR_FOR_WRITE;
	cmd.param[0] = cmd.param[1] = sector;
	iap(&cmd, &res);

	if (res.status != CMD_SUCCESS)
		goto flash_error;

	if ((fls->blk.priv.flags & KB_WRITE_ONCE) &&
			bitarray_isRangeFull(&lpc2_bitx, idx_sector, erase_group[sector]))
	{
		kputs("blocchi pieni\n");
		ASSERT(0);
		goto flash_error;
	}

	bool erase = false;
	if ((fls->blk.priv.flags & KB_WRITE_ONCE) &&
			bitarray_isRangeEmpty(&lpc2_bitx, idx_sector, erase_group[sector]))
		erase = true;

	if (!(fls->blk.priv.flags & KB_WRITE_ONCE))
		erase = true;

	if (erase)
	{
		cmd.cmd = ERASE_SECTOR;
		cmd.param[0] = cmd.param[1] = sector;
		cmd.param[2] = CPU_FREQ / 1000;
		iap(&cmd, &res);

		if (res.status != CMD_SUCCESS)
			goto flash_error;
	}

	LOG_INFO("Writing page [%ld], addr [%ld] in sector[%ld]\n", idx, addr, sector);
	cmd.cmd = PREPARE_SECTOR_FOR_WRITE;
	cmd.param[0] = cmd.param[1] = sector;
	iap(&cmd, &res);

	if (res.status != CMD_SUCCESS)
		goto flash_error;

	if (fls->blk.priv.flags & KB_WRITE_ONCE)
	{
		if (bitarray_test(&lpc2_bitx, idx))
		{
			ASSERT(0);
			goto flash_error;
		}
		else
			bitarray_set(&lpc2_bitx, idx);
	}

	cmd.cmd = COPY_RAM_TO_FLASH;
	cmd.param[0] = addr;
	cmd.param[1] = (uint32_t)buf;
	cmd.param[2] = FLASH_PAGE_SIZE_BYTES;
	cmd.param[3] = CPU_FREQ / 1000;
	iap(&cmd, &res);

	if (res.status != CMD_SUCCESS)
		goto flash_error;

	IRQ_RESTORE(flags);
	LOG_INFO("Done\n");

	return blk->blk_size;

flash_error:
	LOG_ERR("%ld\n", res.status);
	fls->hw->status |= FLASH_WR_ERR;
	return 0;
}