Esempio n. 1
0
CanDriverReturnType can_driver_write(CanDriverChannelType channel, CanDriverMboxType mbox, CanDriverMessageBufferType buffer)
{
	CanDriverUint16 reg16;
	CanDriverUint8 i;
	CanDriverReturnType error;
	
	if (channel != CAN_DRIVER_CHANNEL) {
		return CAN_DRIVER_E_INVALID;
	}

	reg16 = CanDriver_RegRead16((CanDriverUint16*)MPU_CAN_ADDR_CnMCTRLm(channel, mbox));
	if ((reg16 & MPU_CAN_CnMCTRLm_TRQ_READ_BIT) == MPU_CAN_CnMCTRLm_TRQ_READ_BIT) {
		return CAN_DRIVER_E_BUSY;
	}
	error = EnableBuffer(channel, mbox, 1U);
	if (error != CAN_DRIVER_E_OK) {
		return error;
	}

	/*
	 * 送信データをレジスタに設定
	 */
	for (i = 0; i < CAN_DRIVER_DLC; i++) {
		CanDriver_RegWrite8((CanDriverUint8 *)MPU_CAN_ADDR_CnMDATAxm(channel, mbox, i), buffer[i]);
	}

	
	DisableBuffer(channel, mbox);

	reg16 = MPU_CAN_CnMCTRLm_TRQ_WRITE_SET_BIT;
	CanDriver_RegWrite16((CanDriverUint16*)MPU_CAN_ADDR_CnMCTRLm(channel, mbox), reg16);


	return CAN_DRIVER_E_OK;
}
Esempio n. 2
0
void can_driver_init(void)
{
	//TODO チャネルの初期化
	/*
	 * デモ用なので省略する.
	 */
	/*
	 * CANモジュールの受信割り込みの許可を設定する.
	 *
	 * 設定対象レジスタ:
	 * CANモジュール割込み許可レジスタ CIE1ビットの設定
	 * bit: SetCIE1	  : 9
	 * 		ClearCIE1 : 0
	 * SetCIE1ビット: 1 ClearCIE1ビット: 0 : 受信割り込みを許可ビットをセットする.
	 */
	CanDriver_RegWrite16((CanDriverUint16 *)MPU_CAN_ADDR_CnIE(CAN_DRIVER_CHANNEL), MPU_CAN_CnIE_CIE1_WRITE_SET_BIT);
	
	
	
	//MBOXの初期化
	/*
	 * 0: TX1, 0x100
	 */
	(void)EnableBuffer(CAN_DRIVER_CHANNEL, CAN_DRIVER_TX1_MBOX, 1U);
	InitMboxTx(CAN_DRIVER_CHANNEL, CAN_DRIVER_TX1_MBOX, CAN_DRIVER_TX1_CANID);
	DisableBuffer(CAN_DRIVER_CHANNEL, CAN_DRIVER_TX1_MBOX);
	
		/*
	 * 1: TX2, 0x101
	 */
	(void)EnableBuffer(CAN_DRIVER_CHANNEL, CAN_DRIVER_TX2_MBOX, 1U);
	InitMboxTx(CAN_DRIVER_CHANNEL, CAN_DRIVER_TX2_MBOX, CAN_DRIVER_TX2_CANID);
	DisableBuffer(CAN_DRIVER_CHANNEL, CAN_DRIVER_TX2_MBOX);

	/*
	 * 2: RX, 0x200
	 */
	(void)EnableBuffer(CAN_DRIVER_CHANNEL, CAN_DRIVER_RX_MBOX, 1U);
	InitMboxRx(CAN_DRIVER_CHANNEL, CAN_DRIVER_RX_MBOX, CAN_DRIVER_RX_CANID);
	DisableBuffer(CAN_DRIVER_CHANNEL, CAN_DRIVER_RX_MBOX);
	
	InitMboxUnused(CAN_DRIVER_CHANNEL, CAN_DRIVER_XX_MBOX);
	return;
}
Esempio n. 3
0
int CCamera::Render (void)
{
gameStates.render.cameras.bActive = 1;
if (gameStates.render.cockpit.nType != CM_FULL_SCREEN)
	cockpit->Activate (CM_FULL_SCREEN);
gameData.objs.viewerP = m_info.objP;
gameOpts->render.nMaxFPS = 1;
#if RENDER2TEXTURE
if (ReleaseBuffer () && EnableBuffer ()) {
	RenderFrame (0, 0);
	m_info.bValid = 1;
	DisableBuffer ();
	}
else 
#	if CAMERA_READPIXELS
if (m_info.buffer.Buffer ()) 
#	endif
#endif
 {
	RenderFrame (0, 0);
	m_info.bValid = 1;
	m_info.buffer.ReleaseTexture ();
#if CAMERA_READPIXELS
	memset (m_info.buffer.Buffer (), 0, m_info.buffer.Width () * m_info.buffer.Height () * 4);
	glDisable (GL_TEXTURE_2D);
#endif
	glReadBuffer (GL_BACK);
	if (gameOpts->render.cameras.bFitToWall || m_info.bTeleport) {
#if CAMERA_READPIXELS == 0
		m_info.buffer.SetTranspType (-1);
		m_info.buffer.PrepareTexture (0, 0, NULL);
		glCopyTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, 
			(CCanvas::Current ()->Width () - m_info.buffer.Width ()) / 2, 
			(CCanvas::Current ()->Height () - m_info.buffer.Height ()) / 2, 
			m_info.buffer.Width (), m_info.buffer.Height (), 0);
#else
		glReadPixels (
			(CCanvas::Current ()->Width () - m_info.buffer.Width ()) / 2, 
			(CCanvas::Current ()->Height () - m_info.buffer.Height ()) / 2, 
			m_info.buffer.Width (), m_info.buffer.Height (), 
			GL_RGBA, GL_UNSIGNED_BYTE, m_info.buffer.Buffer ());
		PrepareTexture (&m_info.buffer, 0, -1, NULL);
#endif
		}
	else {
#if CAMERA_READPIXELS == 0
			m_info.buffer.SetTranspType (-1);
			m_info.buffer.PrepareTexture (0, 0, NULL);
			glCopyTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, 
				-(m_info.buffer.Width () - CCanvas::Current ()->Width ()) / 2,
				-(m_info.buffer.Height () - CCanvas::Current ()->Height ()) / 2, 
				m_info.buffer.Width (), m_info.buffer.Height (), 0);
#else
		char	*pSrc, *pDest;
		int	dxBuf = (m_info.buffer.Width () - CCanvas::Current ()->Width ()) / 2;
		int	dyBuf = (m_info.buffer.Height () - CCanvas::Current ()->Height ()) / 2;
		int	wSrc = CCanvas::Current ()->Width () * 4;
		int	wDest = m_info.buffer.Width () * 4;

		if (CCanvas::Current ()->Width () == m_info.buffer.Width ()) {
			glReadPixels (
				0, 0, CCanvas::Current ()->Width (), CCanvas::Current ()->Height (),
				GL_RGBA, GL_UNSIGNED_BYTE, m_info.buffer.Buffer () + dyBuf * m_info.buffer.Width () * 4);
			}
		else {
			glReadPixels (
				0, 0, CCanvas::Current ()->Width (), CCanvas::Current ()->Height (),
				GL_RGBA, GL_UNSIGNED_BYTE, m_info.screenBuf);
			pSrc = m_info.screenBuf;
			pDest = m_info.buffer.Buffer () + (dyBuf - 1) * wDest + dxBuf * 4;
#	ifndef _WIN32
			for (dyBuf = CCanvas::Current ()->Height (); dyBuf; dyBuf--, pSrc += wSrc, pDest += wDest)
				memcpy (pDest, pSrc, wSrc);
#	else
			dxBuf = m_info.buffer.Width () - CCanvas::Current ()->Width ();
			dyBuf = CCanvas::Current ()->Height ();
			wSrc /= 4;
			__asm {
				push	edi
				push	esi
				push	ecx
				mov	edx,dyBuf
				mov	esi,pSrc
				mov	edi,pDest
				mov	eax,dxBuf
				shl	eax,2
				cld
		copy:
				mov	ecx,wSrc
				rep	movsd
				dec	edx
				jz		done
				add	edi,eax
				jmp	copy
		done:
				pop	ecx
				pop	esi
				pop	edi
				}
#	endif
			PrepareTexture (&m_info.buffer, 0, -1);
			}
#endif
		}
	}