Esempio n. 1
0
void TclClass::sendFrame(byte flag, byte red, byte green, byte blue) {
#ifdef TCL_SPI
  SPI.transfer(flag);
  SPI.transfer(blue);
  SPI.transfer(green);
  SPI.transfer(red);
#endif
#ifdef TCL_DIO
  dioWrite(flag);
  dioWrite(blue);
  dioWrite(green);
  dioWrite(red);
#endif
}
Esempio n. 2
0
/*
 * NAME: dasd_write
 *
 * FUNCTION: Write to direct access file descriptor
 *
 * PARAMETERS:
 *	offset	- Starting byte offset for write request
 *	pdata	- Starting address of user data buffer
 *	plen	- On entry, number of bytes to be write
 *		  On exit, number of bytes actually write
 *	vfsp	- pointer to vfs structure
 *
 * RETURNS: 0 for success; Other indicates failure
 */
int32
dasd_write(
int64		offset,
caddr_t		pdata,
int64		*plen,
struct vfs	*vfsp)
{
	int64	blocknum;
	cbuf_t	*bp;
	dio_t	*dp;
	inode_t	*dummy_inode;
	int64	erroff;
	int64	fbytes;
	int64	lbytes;
	int64	mbytes;
	int64	nbytes = *plen;
	int32	rc;

	dummy_inode = getDummyInode(vfsp);

	/* If offset does not start on sector boundary, calculate number of
	 * bytes in first partial sector.
	 */
	if (offset & (vfsp->vfs_bsize - 1))
	{
		fbytes = MIN(nbytes, CM_BSIZE - (offset & CM_OFFSET));
		nbytes -= fbytes;
	}
	else
		fbytes = 0;

	/* If write does not end on sector boundary, calculate number of
	 * bytes in last sector
	 */
	if (nbytes & vfsp->vfs_bsize - 1)
		lbytes = nbytes & CM_OFFSET;
	else
		lbytes = 0;

	mbytes = nbytes - lbytes;

	nbytes = 0;	/* Now counting bytes actually written */

	/* First (partial) block */
	if (fbytes)
	{
		if (rc = rawRead(dummy_inode, offset, &bp))
			goto out1;
		if (rc = copyin(pdata, bp->cm_cdata+(offset & CM_OFFSET),
				fbytes))
		{
			rawRelease(bp);
			goto out1;
		}
		if (rc = rawWrite(dummy_inode, bp, 1))
			goto out1;
		nbytes = fbytes;
		offset += fbytes;
		pdata += fbytes;
	}
	/* Write full sectors
	 */
	if (mbytes)
	{
		blocknum = offset >> dummy_inode->i_l2pbsize;
		if (rc = dioStart(dummy_inode, &dp))
			goto out1;
		(void) dioWrite(dp, blocknum, mbytes, offset, pdata, 0);
		if (rc = dioEnd(dp, &erroff))
		{
			nbytes += (erroff - offset);
			goto out1;
		}
		nbytes += mbytes;
		offset += mbytes;
		pdata += mbytes;
	}
	/* Write last (partial) block
	 */
	if (lbytes)
	{
		if (rc = rawRead(dummy_inode, offset, &bp))
			goto out1;
		if (rc = copyin(pdata, bp->cm_cdata, lbytes))
		{
			rawRelease(bp);
			goto out1;
		}
		if (rc = rawWrite(dummy_inode, bp, 1))
			goto out1;
		nbytes = +lbytes;
	}
out1:
	releDummyInode(dummy_inode);
	*plen = nbytes;
	return (rc);
}