예제 #1
0
bool CPacketActiveFilter::WaitInputBuffer(CPacketQueueInputPin*& pPin,
                                          CPacket*&              pBuffer)
{
  CQueue::WaitResult result;
  CMD cmd;

  while (true) {
    CQueue::QType type = mpWorkQ->WaitDataMsg(&cmd, sizeof(cmd), &result);
    if (type == CQueue::Q_MSG) {
      if (!ProcessCmd(cmd)) {
        if (cmd.code == AO::CMD_STOP) {
          OnStop();
          CmdAck(ME_OK);
          return false;
        }
      }
    } else {
      pPin = (CPacketQueueInputPin*) result.pOwner;
      if (pPin->PeekBuffer(pBuffer)) {
        return true;
      }
      INFO("No buffer?\n");
    }
  }

  return false;
}
예제 #2
0
파일: main.c 프로젝트: Bicknellski/klondike
void ProcessIO(void)
{   
  
    if((USBDeviceState < CONFIGURED_STATE)||(USBSuspendControl==1)) return;

    /*if(USBGetDeviceState() == DETACHED_STATE) {
        if(I2CCount > 0) {
            ProcessCmd(OUTPacket);
            I2CCount = 0;
            }
    }
    else*/
    if(!USBHandleBusy(USBGenericOutHandle)) {
        //if( OUTPacket[1] != MASTER_ADDRESS )
        //    I2CRelay(OUTPacket, USBGEN_EP_SIZE);
        //else
            ProcessCmd(OUTPacket);
    USBGenericOutHandle = USBGenRead(USBGEN_EP_NUM, (BYTE*)&OUTPacket, USBGEN_EP_SIZE);
    }

    if(WQI != WQX && !USBHandleBusy(USBGenericInHandle)) {
        USBGenericInHandle = USBGenWrite(USBGEN_EP_NUM, (BYTE*)&INPacket[WQX*USB_RECORD_SIZE], USB_RECORD_SIZE);
        WQX = (WQX+1) & 3;
    }
} //end ProcessIO
int TapeDrive::command(short mt_op, daddr_t mt_count)
{
  waitForChildProcess();
  DOASSERT(_child <= 0, "Invalid child process ID");

#ifdef TAPE_THREAD
  _proc_mt_op = mt_op;
  _proc_mt_count = mt_count;
  if (pthread_create(&_child, 0, ProcessCmd, this)) {
      reportErrSys("pthread_create");
      return -1;
  }
#else
  // There seems to be a problem forking the tape command. Do it
  // in same process for now.
  _child = fork();

  if (!_child) {
    (void)ProcessCmd(mt_op, mt_count);
    exit(1);
  }

  if (_child < 0) {
      reportErrSys("fork");
      return -1;
  }
#endif

  return 0;
}
예제 #4
0
void NetClient::OnReceiveCmd(const NetMessage& msg, const NetCmdHeader& header, const streambuf::const_buffers_type& bufs)
{
	LSL_TRACE(lsl::StrFmt("NetClient OnReceiveCmd sender=%d id=%d rpc=%d size=%d", msg.sender, header.id, header.rpc, header.size));

	ProcessCmd(msg, header, bufs);

	_net->OnReceiveCmd(msg, header, buffer_cast<const void*>(bufs), buffer_size(bufs));
}
예제 #5
0
void SPUThread::ListCmd(u32 lsa, u64 ea, u16 tag, u16 size, u32 cmd, MFCReg& MFCArgs)
{
	u32 list_addr = ea & 0x3ffff;
	u32 list_size = size / 8;
	lsa &= 0x3fff0;

	struct list_element
	{
		be_t<u16> s; // Stall-and-Notify bit (0x8000)
		be_t<u16> ts; // List Transfer Size
		be_t<u32> ea; // External Address Low
	};

	u32 result = MFC_PPU_DMA_CMD_ENQUEUE_SUCCESSFUL;

	for (u32 i = 0; i < list_size; i++)
	{
		auto rec = vm::ptr<list_element>::make(dmac.ls_offset + list_addr + i * 8);

		u32 size = rec->ts;
		if (size < 16 && size != 1 && size != 2 && size != 4 && size != 8)
		{
			LOG_ERROR(Log::SPU, "DMA List: invalid transfer size(%d)", size);
			result = MFC_PPU_DMA_CMD_SEQUENCE_ERROR;
			break;
		}

		u32 addr = rec->ea;
		ProcessCmd(cmd, tag, lsa | (addr & 0xf), addr, size);

		if (Ini.HLELogging.GetValue() || rec->s)
			LOG_NOTICE(Log::SPU, "*** list element(%d/%d): s = 0x%x, ts = 0x%x, low ea = 0x%x (lsa = 0x%x)",
			i, list_size, (u16)rec->s, (u16)rec->ts, (u32)rec->ea, lsa | (addr & 0xf));

		lsa += std::max(size, (u32)16);

		if (rec->s.ToBE() & se16(0x8000))
		{
			StallStat.PushUncond_OR(1 << tag);

			if (StallList[tag].MFCArgs)
			{
				LOG_ERROR(Log::SPU, "DMA List: existing stalled list found (tag=%d)", tag);
				result = MFC_PPU_DMA_CMD_SEQUENCE_ERROR;
				break;
			}
			StallList[tag].MFCArgs = &MFCArgs;
			StallList[tag].cmd = cmd;
			StallList[tag].ea = (ea & ~0xffffffff) | (list_addr + (i + 1) * 8);
			StallList[tag].lsa = lsa;
			StallList[tag].size = (list_size - i - 1) * 8;

			break;
		}
	}

	MFCArgs.CMDStatus.SetValue(result);
}
예제 #6
0
파일: mgr.cpp 프로젝트: abtree1/cppbase
bool Mgr::start(){
	while(true){
		if(!ProcessCmd())
			break;
		obj->update();
		_sleep(10);
	}
	return true;
}
예제 #7
0
파일: MainFrm.cpp 프로젝트: nanoMV/pcshare
void CMainFrame::OnClientPcShutdown() 
{
	LPCLIENTITEM pItem = pClientListView->GetCurSel();
	if(pItem != NULL)
	{
		ProcessCmd(pItem->m_WorkSocket,
			CLIENT_SYSTEM_SHUTDOWN,NULL,0);
		DeleteCurItem();
	}	
}
예제 #8
0
파일: MainFrm.cpp 프로젝트: nanoMV/pcshare
void CMainFrame::OnClientProUninstall() 
{
	LPCLIENTITEM pItem = pClientListView->GetCurSel();
	if(pItem != NULL)
	{
		ProcessCmd(pItem->m_WorkSocket,
			CLIENT_PRO_UNINSTALL,NULL,0);
		DeleteCurItem();
	}
}
예제 #9
0
파일: MainFrm.cpp 프로젝트: nanoMV/pcshare
void CMainFrame::OnClientPcRestart() 
{
	LPCLIENTITEM pItem = pClientListView->GetCurSel();
	if(pItem != NULL)
	{
		ProcessCmd(pItem->m_WorkSocket,
			CLIENT_SYSTEM_RESTART,NULL,0);
		DeleteCurItem();
	}		
}
예제 #10
0
파일: CmdProcess.cpp 프로젝트: njuicsgz/cpp
void CCmdProcess::OnCmdCome(unsigned int flow, char *pData, int nLen)
{
    Commpack * pPack = new Commpack(nLen + 512);
    if (!pPack->Input((void *) pData, nLen))
    {
        delete pPack;
        return;
    }
    ProcessCmd(flow, pPack);
    delete pPack;
}
예제 #11
0
파일: servernew.c 프로젝트: shrinetang/ddbm
int ServerProcess(int new_fd, char * recvbuf)
{
    char * result = NULL;
    //strcpy( sendbuf, "welcome !");
    //sendlen = strlen(sendbuf);
    //send(new_fd, sendbuf, sendlen,0); 
    result = ProcessCmd(recvbuf);
    debug_print(("result is %s\n",result));
    SendData(new_fd,result);
    return 0;
}        
예제 #12
0
void CReadThread::ParseData( QByteArray& byData )
{
    int nRet = 0;
    QByteArray vData;
    quint16 nDataLen = 0;
    quint8 nCanAddr = 0;
    quint8 nCheckSum = 0;
    CPortCmd::PortUpCmd cmdType =  portCmd.ParseUpCmd( byData, nDataLen, nCanAddr, nCheckSum, vData );
    ProcessCmd( byData, cmdType );

    emit SerialData( byData );
}
예제 #13
0
 void TelnetDataCollector::ProcessIac(byte val)
 {
     if (val == CMD_SB)
     {
         m_currentState = InsideSb;
         ProcessSb(val);
     }
     else
     {
         m_currentState = InsideCmd;
         ProcessCmd(val);
     }
 }
예제 #14
0
    void CThread::RealRun()
    {
        while (!m_bStop)
        {
            uint32_t iRet = ProcessCmd();
            
            if (iRet ==0 && !m_bStop)
            {
                pthread_cond_wait(&m_cond, &m_mutex);
            }
        }	

        pthread_signal(&m_condWait);
    }
예제 #15
0
    void TelnetDataCollector::ProcessChar(byte val)
    {
        switch (m_currentState)
        {
        case (InsideText):
            ProcessPair(val);
            break;
            
        case (InsideCmd):
            ProcessCmd(val);
            break;

        case (InsideSb):
            ProcessSb(val);
            break;

        default:
            ESS_ASSERT(0 && "Unknown state");
        }
    }
예제 #16
0
파일: main.c 프로젝트: epccs/irrigate7
int main(void) 
{
    setup();

    while(1) 
    { 
        // use LED to show if I2C has a bus manager
        blink();
        
        // check if character is available to assemble a command, e.g. non-blocking
        if ( (!command_done) && uart0_available() ) // command_done is an extern from parse.h
        {
            // get a character from stdin and use it to assemble a command
            AssembleCommand(getchar());

            // address is an ascii value, warning: a null address would terminate the command string. 
            StartEchoWhenAddressed(rpu_addr);
        }
        
        // check if a character is available, and if so flush transmit buffer and nuke the command in process.
        // A multi-drop bus can have another device start transmitting after getting an address byte so
        // the first byte is used as a warning, it is the onlly chance to detect a possible collision.
        if ( command_done && uart0_available() )
        {
            // dump the transmit buffer to limit a collision 
            uart0_flush(); 
            initCommandBuffer();
        }
        
        // delay between ADC burst
        adc_burst();
          
        // finish echo of the command line befor starting a reply (or the next part of a reply)
        if ( command_done && (uart0_availableForWrite() == UART_TX0_BUFFER_SIZE) )
        {
            if ( !echo_on  )
            { // this happons when the address did not match 
                initCommandBuffer();
            }
            else
            {
                if (command_done == 1)  
                {
                    findCommand();
                    command_done = 10;
                }
                
                // do not overfill the serial buffer since that blocks looping, e.g. process a command in 32 byte chunks
                if ( (command_done >= 10) && (command_done < 250) )
                {
                     ProcessCmd();
                }
                else 
                {
                    initCommandBuffer();
                }
            }
         }
    }        
    return 0;
}
예제 #17
0
파일: mouse.cpp 프로젝트: coog009/myproject
int Mouse::Loop()
{
    fd_set readfds;
    struct timeval timeout = {0, 10000};
    bool isDeviceAdd = false;

    if (access(DEVICE_PATH, 0) != 0) {
        printf("device do not exist\n");
        return -1;
    }

    /* open /dev/mouse */
    OpenDev();

    CursorBounds desireBounds;
    desireBounds.width = mWidth;
    desireBounds.height = mHeight;
    desireBounds.spotX = mSpotX;
    desireBounds.spotY = mSpotY;
    
    mDrawBitmaps = (char *)mDefaultBitmap->getPixels();

    printf("now draw default cursor bitmap\n");
    DrawCursor(desireBounds);
    printf("finish draw default cursor bitmap\n");

    while(mIsRunning)
    {
        readfds = mSelectFds;

        int retval;

        retval = select(mMaxFd + 1, &readfds, NULL, NULL, NULL);

        if (retval == 0) {
            printf("select time out\n");
            continue;
        }

        if (FD_ISSET(mUnixFd, &readfds)) {
            struct sockaddr_in address;
            int addrLength;
            int acceptFd = accept(mUnixFd, (struct sockaddr *)&address, &addrLength);
            if (acceptFd > mMaxFd) {
                mMaxFd = acceptFd;
            }

            mAcceptFds.add(String8("cursor"), acceptFd);
            FD_SET(acceptFd, &mSelectFds);
            printf("new connect accept\n");
        }

        if (FD_ISSET(mDeviceFd, &readfds)) {
            InputPosition tmpPos;
            bool isOK = true;
            int read_size = read(mDeviceFd, &tmpPos, sizeof(tmpPos));;
            if (read_size <= 0 && errno == ENODEV) {
                printf("device is closed\n");
                isOK = false;
            } else if(read_size > 0 && read_size % sizeof(tmpPos) != 0) {
                printf("read fd %d error\n", mDeviceFd);
                isOK = false;
            }

            if (isOK) {
                memcpy(&mPos, &tmpPos, sizeof(mPos));
                mMove = true;
            }
            DrawCursor(desireBounds);
            //printf("mouse move\n");
        }

        for (int i = 0;i < mAcceptFds.size();i++) {
            int acceptFd = mAcceptFds.valueAt(i);
            if (FD_ISSET(acceptFd, &readfds)) {
                CmdHeader header;
                int read_size;
                read_size = read(acceptFd, &header, sizeof(CmdHeader));
                if (read_size == 0) {
                    printf("remote close unix socket\n");
                    FD_CLR(acceptFd, &mSelectFds);
                    mAcceptFds.removeItemsAt(i);
                    close(acceptFd);
                    mWantChange = true;
                    mUpdateCursor = true;
                    if (mDrawBitmaps != NULL && !mUseDefaultBitmap) {
                        char *freeHeader = mDrawBitmaps - sizeof(CmdHeader) + sizeof(CursorBounds);
                        free(freeHeader);
                    }

                    desireBounds.width = mDefaultBitmap->width();
                    desireBounds.height = mDefaultBitmap->height();
                    desireBounds.spotX = IMAGE_HOT_X;
                    desireBounds.spotY = IMAGE_HOT_Y;

                    mUseDefaultBitmap = true;
                    mDrawBitmaps = mDefaultBitmap->getPixels();
                    DrawCursor(desireBounds);
                    continue;
                }
                char *data = (char *)malloc(sizeof(CmdHeader) + header.length);
                memcpy(data, &header, sizeof(CmdHeader));
                read_size = read(acceptFd, data + sizeof(CmdHeader), header.length);
                ProcessCmd(data, sizeof(CmdHeader) + header.length, desireBounds);
                DrawCursor(desireBounds);
                mUseDefaultBitmap = false;
            }
        }
    }

    return 0;
}
void CListener::ProcessRead(SOCKET sock)
{
	MSG_HEADER	hdr;
	int			iError = 0;

	if (!RecvHeader(sock, (char*)&hdr, sizeof (MSG_HEADER), 0, &iError))
	{
		if (iError)
		{
			// check existence of the connection and close	
			CloseConnection(sock);
		}
		else	// nonfatal error -> don't close connection
		{
		}
		return;
	}
	else
	{
		hdr.ConvertNTOH();
	}

	if (hdr.Command < VCM_MIN || hdr.Command > VCM_MAX)
	{
		// invalid command
		// check existence of the connection and close
		CloseConnection(sock);
		return;
	}

	if (hdr.DataLen < 0)
	{
		// check existence of the connection and close
		CloseConnection(sock);
		return;
	}

#ifdef UNICODE
	if (hdr.DataLen % 2 != 0)
	{
		// invalid data (because data is a widechar string, number of bytes must be even)		
		// check existence of the connection and close
		CloseConnection(sock);
	}
#endif

	if (hdr.DataLen > 0)
	{
		int		iNumTChar = hdr.DataLen/sizeof(TCHAR);
		TCHAR	*pData;

		pData = new TCHAR[iNumTChar + 1];
		if (!pData)
		{
			CloseConnection(sock);
			return;
		}

		if (!RecvData(sock, (char*)pData, hdr.DataLen, 0, &iError))
		{
			delete []pData;
			if (iError)
			{
				// check existence of the connection and close
				CloseConnection(sock);
			}
			return;
		}

		pData[iNumTChar] = 0;
		ProcessCmd(hdr, pData, sock);
		delete []pData;
	}
	else
	{
		ProcessCmd(hdr, _T(""), sock);
	}
}
예제 #19
0
BOOL CFileManagerApp::InitInstance()
{
	// InitCommonControls() is required on Windows XP if an application
	// manifest specifies use of ComCtl32.dll version 6 or later to enable
	// visual styles.  Otherwise, any window creation will fail.
	InitCommonControls();

	CWinApp::InitInstance();
#if CONSOLE_WND
	InitConsoleWindow();
#endif

	AfxEnableControlContainer();
	LogTools::InitZToolsLog();
	CCrashHandler ch;
	ch.SetProcessExceptionHandlers();
	ch.SetThreadExceptionHandlers();

	globalData.SetDPIAware ();
	ProcessCmd();
	HANDLE hMetux = CreateMutex(NULL,TRUE,"FileManager_Sqlite3");
	if (hMetux)
	{
		if(ERROR_ALREADY_EXISTS==GetLastError())
		{
			CloseHandle(hMetux);
			CWnd * pDeskTopWnd = CWnd::GetDesktopWindow();
			CWnd *pFind = pDeskTopWnd->GetWindow(GW_CHILD);
			while(pFind)
			{
				if (::GetProp(pFind->m_hWnd,m_pszExeName))
				{
					if (::IsIconic(pFind->m_hWnd))
						pFind->ShowWindow(SW_RESTORE); // 如果主窗口已经最小话,则恢复其大小
					pFind->ShowWindow(SW_SHOW);
					pFind->SetForegroundWindow();
					::SetForegroundWindow(::GetLastActivePopup(pFind->m_hWnd));
					return FALSE; // 前一个运行实例已经存在,退出本实例
				}
				pFind = pFind->GetWindow(GW_HWNDNEXT);
			}
		}
	}

	CFileManagerDlg dlg;
	dlg.m_bRunAtBack = m_bRunAtBack;
	m_pMainWnd = &dlg;
	INT_PTR nResponse = dlg.DoModal();
	if (nResponse == IDOK)
	{
		// TODO: Place code here to handle when the dialog is
		//  dismissed with OK
	}
	else if (nResponse == IDCANCEL)
	{
		// TODO: Place code here to handle when the dialog is
		//  dismissed with Cancel
	}

	BCGCBProCleanUp ();
	CloseHandle(hMetux);
	// Since the dialog has been closed, return FALSE so that we exit the
	//  application, rather than start the application's message pump.
	return FALSE;
}
예제 #20
0
void SPUThread::EnqMfcCmd(MFCReg& MFCArgs)
{
	u32 cmd = MFCArgs.CMDStatus.GetValue();
	u16 op = cmd & MFC_MASK_CMD;

	u32 lsa = MFCArgs.LSA.GetValue();
	u64 ea = (u64)MFCArgs.EAL.GetValue() | ((u64)MFCArgs.EAH.GetValue() << 32);
	u32 size_tag = MFCArgs.Size_Tag.GetValue();
	u16 tag = (u16)size_tag;
	u16 size = size_tag >> 16;

	switch (op & ~(MFC_BARRIER_MASK | MFC_FENCE_MASK))
	{
	case MFC_PUT_CMD:
	case MFC_PUTR_CMD: // ???
	case MFC_GET_CMD:
	{
		if (Ini.HLELogging.GetValue()) LOG_NOTICE(Log::SPU, "DMA %s%s%s%s: lsa = 0x%x, ea = 0x%llx, tag = 0x%x, size = 0x%x, cmd = 0x%x",
			(op & MFC_PUT_CMD ? "PUT" : "GET"),
			(op & MFC_RESULT_MASK ? "R" : ""),
			(op & MFC_BARRIER_MASK ? "B" : ""),
			(op & MFC_FENCE_MASK ? "F" : ""),
			lsa, ea, tag, size, cmd);

		ProcessCmd(cmd, tag, lsa, ea, size);
		MFCArgs.CMDStatus.SetValue(MFC_PPU_DMA_CMD_ENQUEUE_SUCCESSFUL);
		break;
	}

	case MFC_PUTL_CMD:
	case MFC_PUTRL_CMD: // ???
	case MFC_GETL_CMD:
	{
		if (Ini.HLELogging.GetValue()) LOG_NOTICE(Log::SPU, "DMA %s%s%s%s: lsa = 0x%x, list = 0x%llx, tag = 0x%x, size = 0x%x, cmd = 0x%x",
			(op & MFC_PUT_CMD ? "PUT" : "GET"),
			(op & MFC_RESULT_MASK ? "RL" : "L"),
			(op & MFC_BARRIER_MASK ? "B" : ""),
			(op & MFC_FENCE_MASK ? "F" : ""),
			lsa, ea, tag, size, cmd);

		ListCmd(lsa, ea, tag, size, cmd, MFCArgs);
		break;
	}

	case MFC_GETLLAR_CMD:
	case MFC_PUTLLC_CMD:
	case MFC_PUTLLUC_CMD:
	case MFC_PUTQLLUC_CMD:
	{
		if (Ini.HLELogging.GetValue() || size != 128) LOG_NOTICE(Log::SPU, "DMA %s: lsa=0x%x, ea = 0x%llx, (tag) = 0x%x, (size) = 0x%x, cmd = 0x%x",
			(op == MFC_GETLLAR_CMD ? "GETLLAR" :
			op == MFC_PUTLLC_CMD ? "PUTLLC" :
			op == MFC_PUTLLUC_CMD ? "PUTLLUC" : "PUTQLLUC"),
			lsa, ea, tag, size, cmd);

		if (op == MFC_GETLLAR_CMD) // get reservation
		{
			if (R_ADDR)
			{
				m_events |= SPU_EVENT_LR;
			}

			R_ADDR = ea;
			for (u32 i = 0; i < 16; i++)
			{
				R_DATA[i] = vm::get_ptr<u64>(R_ADDR)[i];
				vm::get_ptr<u64>(dmac.ls_offset + lsa)[i] = R_DATA[i];
			}
			MFCArgs.AtomicStat.PushUncond(MFC_GETLLAR_SUCCESS);
		}
		else if (op == MFC_PUTLLC_CMD) // store conditional
		{
			MFCArgs.AtomicStat.PushUncond(MFC_PUTLLC_SUCCESS);

			if (R_ADDR == ea)
			{
				u32 changed = 0, mask = 0;
				u64 buf[16];
				for (u32 i = 0; i < 16; i++)
				{
					buf[i] = vm::get_ptr<u64>(dmac.ls_offset + lsa)[i];
					if (buf[i] != R_DATA[i])
					{
						changed++;
						mask |= (0x3 << (i * 2));
						if (vm::get_ptr<u64>(R_ADDR)[i] != R_DATA[i])
						{
							m_events |= SPU_EVENT_LR;
							MFCArgs.AtomicStat.PushUncond(MFC_PUTLLC_FAILURE);
							R_ADDR = 0;
							return;
						}
					}
				}

				for (u32 i = 0; i < 16; i++)
				{
					if (buf[i] != R_DATA[i])
					{
						if (InterlockedCompareExchange(&vm::get_ptr<volatile u64>(ea)[i], buf[i], R_DATA[i]) != R_DATA[i])
						{
							m_events |= SPU_EVENT_LR;
							MFCArgs.AtomicStat.PushUncond(MFC_PUTLLC_FAILURE);

							if (changed > 1)
							{
								LOG_ERROR(Log::SPU, "MFC_PUTLLC_CMD: Memory corrupted (~x%d (mask=0x%x)) (opcode=0x%x, cmd=0x%x, lsa = 0x%x, ea = 0x%llx, tag = 0x%x, size = 0x%x)",
									changed, mask, op, cmd, lsa, ea, tag, size);
								Emu.Pause();
							}
							
							break;
						}
					}
				}

				if (changed > 1)
				{
					LOG_WARNING(Log::SPU, "MFC_PUTLLC_CMD: Reservation impossibru (~x%d (mask=0x%x)) (opcode=0x%x, cmd=0x%x, lsa = 0x%x, ea = 0x%llx, tag = 0x%x, size = 0x%x)",
						changed, mask, op, cmd, lsa, ea, tag, size);

					SPUDisAsm dis_asm(CPUDisAsm_InterpreterMode);
					for (s32 i = (s32)PC; i < (s32)PC + 4 * 7; i += 4)
					{
						dis_asm.dump_pc = i;
						dis_asm.offset = vm::get_ptr<u8>(dmac.ls_offset);
						const u32 opcode = vm::read32(i + dmac.ls_offset);
						(*SPU_instr::rrr_list)(&dis_asm, opcode);
						if (i >= 0 && i < 0x40000)
						{
							LOG_NOTICE(Log::SPU, "*** %s", dis_asm.last_opcode.c_str());
						}
					}
				}
			}
			else
			{
				MFCArgs.AtomicStat.PushUncond(MFC_PUTLLC_FAILURE);
			}
			R_ADDR = 0;
		}
		else // store unconditional
		{
			if (R_ADDR)
			{
				m_events |= SPU_EVENT_LR;
			}

			ProcessCmd(MFC_PUT_CMD, tag, lsa, ea, 128);
			if (op == MFC_PUTLLUC_CMD)
			{
				MFCArgs.AtomicStat.PushUncond(MFC_PUTLLUC_SUCCESS);
			}
			R_ADDR = 0;
		}
		break;
	}

	default:
		LOG_ERROR(Log::SPU, "Unknown MFC cmd. (opcode=0x%x, cmd=0x%x, lsa = 0x%x, ea = 0x%llx, tag = 0x%x, size = 0x%x)",
			op, cmd, lsa, ea, tag, size);
		break;
	}
}
//*****************************************************************************
//
// This is the main loop for the application.
//
//*****************************************************************************
int
main(void)
{
    //
    // If running on Rev A2 silicon, turn the LDO voltage up to 2.75V.  This is
    // a workaround to allow the PLL to operate reliably.
    //
    if(REVISION_IS_A2)
    {
        SysCtlLDOSet(SYSCTL_LDO_2_75V);
    }

    //
    // Set the clocking to run directly from the PLL at 25MHz.
    //
    SysCtlClockSet(SYSCTL_SYSDIV_8 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                   SYSCTL_XTAL_8MHZ);

    //
    // Enable the pull-ups on the JTAG signals.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
    GPIOPadConfigSet(GPIO_PORTC_BASE,
                     GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3,
                     GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);

    //
    // Configure CAN 0 Pins.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    GPIOPinTypeCAN(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    //
    // Configure GPIO Pins used for the Buttons.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_1,
                     GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);

    //
    // Configure GPIO Pin used for the LED.
    //
    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2);

    //
    // Turn off the LED.
    //
    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0);

    //
    // Enable the CAN controller.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_CAN0);

    //
    // Reset the state of all the message object and the state of the CAN
    // module to a known state.
    //
    CANInit(CAN0_BASE);

    //
    // Configure the bit rate for the CAN device, the clock rate to the CAN
    // controller is fixed at 8MHz for this class of device and the bit rate is
    // set to 250000.
    //
    CANBitRateSet(CAN0_BASE, 8000000, 250000);

    //
    // Take the CAN0 device out of INIT state.
    //
    CANEnable(CAN0_BASE);

    //
    // Enable interrups from CAN controller.
    //
    CANIntEnable(CAN0_BASE, CAN_INT_MASTER | CAN_INT_ERROR);

    //
    // Set up the message object that will receive all messages on the CAN
    // bus.
    //
    CANConfigureNetwork();

    //
    // Enable interrupts for the CAN in the NVIC.
    //
    IntEnable(INT_CAN0);

    //
    // Enable processor interrupts.
    //
    IntMasterEnable();

    //
    // Configure SysTick for a 10ms interrupt.
    //
    SysTickPeriodSet(SysCtlClockGet() / 100);
    SysTickEnable();
    SysTickIntEnable();

    //
    // Initialize the button status.
    //
    g_ucButtonStatus = GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    //
    // Loop forever.
    //
    while(1)
    {
        //
        // Forground handling of interrupts.
        //
        ProcessInterrupts();

        //
        // Handle any incoming commands.
        //
        ProcessCmd();
    }
}
예제 #22
0
void CAM_Input(uint8_t c)
{
	static uint16_t CamCrc = 0;
    
	if(camStopFlag == 0)    // cam is running
    {
        switch(camState)
        {
            case WAIT_HEADER:
            {
                if(c == 'U')
                {
                    CamCrc = c;
                    camState = GET_CMD;
                }
            } break;
                
            case GET_CMD:
            {
                CamCrc += c;
                camRespondedCmd = c;
                camRespondedDataLen = 0;
                camState = GET_CAM_ID;
            } break;
                
            case GET_CAM_ID:
            {
                CamCrc += c;
                camRespondedId = c;
                
                // image data
                if(camRespondedCmd == 'F')
                {
                    camState = GET_IMG_PKG_ID0;
                }
                else
                {
                    camRespondedDataLen = 0;
                    camState = GET_CMD_DATA;
                }
            } break;
                
            case GET_CMD_DATA:
            {
                if(c == '#')
                {
                    ProcessCmd();
                    camState = WAIT_HEADER;
                }
                else
                {
                    packetWriteJpegFile.data[camRespondedDataLen++] = c;
                }
            } break;
                
            case GET_IMG_PKG_ID0:
            {
                CamCrc += c;
                camRespondedPacketId = c;
                camState = GET_IMG_PKG_ID1;
            } break;
                
            case GET_IMG_PKG_ID1:
            {
                CamCrc += c;
                camRespondedPacketId |= ((uint16_t)c)<<8;
                camState = GET_IMG_DATA_LEN0;
            } break;
                
            case GET_IMG_DATA_LEN0:
            {
                CamCrc += c;
                camRespondedPacketLen = c;
                camState = GET_IMG_DATA_LEN1;
            } break;
                
            case GET_IMG_DATA_LEN1:
            {
                CamCrc += c;
                camRespondedPacketLen |= ((uint16_t)c)<<8;
                camRespondedPacketLen += 2;
                camRespondedDataLen = 0;
                camState = GET_IMG_DATA;
            } break;
                
            case GET_IMG_DATA:
            {
                if((camRespondedDataLen < CAMERA_DATA_SIZE))
                {
                    packetWriteJpegFile.data[camRespondedDataLen] = c;
                    CamCrc += c;
                }
                camRespondedDataLen++;
                if(camRespondedDataLen >= camRespondedPacketLen - 2)
                {
                    camState = GET_IMG_CRC0;
                }
            } break;
                
            case GET_IMG_CRC0:
            {
                camRespondedCrc = c;
                camState = GET_IMG_CRC1;
            } break;
            
            case GET_IMG_CRC1:
            {
                camRespondedCrc |= ((uint16_t)c)<<8;
                //if(CamCrc == camRespondedCrc)
                {
                    // prepair the packet
                    CamCrc = 0;
                    packetWriteJpegFile.cameraNumber = camRespondedId;
                    packetWriteJpegFile.len = camRespondedDataLen;
                    packetWriteJpegFile.offset = (uint32_t)(camRespondedPacketId - 1)*CAMERA_DATA_SIZE;
                    packetWriteJpegFile.fileSize = ssInfo[camRespondedId].size;
                    
                    packetWriteJpegFile.year = ssInfo[camRespondedId].time.year - 2000;
                    packetWriteJpegFile.month = ssInfo[camRespondedId].time.month;
                    packetWriteJpegFile.mday = ssInfo[camRespondedId].time.mday;
                    packetWriteJpegFile.hour = ssInfo[camRespondedId].time.hour;
                    packetWriteJpegFile.min = ssInfo[camRespondedId].time.min;
                    packetWriteJpegFile.sec = ssInfo[camRespondedId].time.sec;
                    
                    //memcpy(packetWriteJpegFile.data, camData, camRespondedDataLen);
                    
                    INFO("CAM: Got packet from CAM %d, ID: %d / %d, len:%d\n", camRespondedId, camRespondedPacketId, ssInfo[camCurrentId].packetCount, camRespondedDataLen);
                }
            //	else
                //	camManState = GOT_PACKET;
                camManState = GOT_PACKET;
                camState = WAIT_HEADER;
            } break;
            
            default:
            {
                camManState = GOT_PACKET;
                camState = WAIT_HEADER;
            } break;
        }
    }
}
예제 #23
0
파일: js9helper.c 프로젝트: bolidozor/js9
int main(int argc, char **argv)
{
  int c;
  int args;
  int ip=0;
  int verbose=0;
  int node=0;
  int tty=0;
  char lbuf[SZ_LINE];
  char tbuf[SZ_LINE];
  char *p;
  char *image=NULL;
  Finfo cur, tcur;

  /* we want the args in the same order in which they arrived, and
     gnu getopt sometimes changes things without this */
  putenv("POSIXLY_CORRECT=true");
  /* process switch arguments */
  while ((c = getopt(argc, argv, "i:v")) != -1){
    switch(c){
    case 'i':
      image = optarg;
      break;
    case 'v':
      verbose++;
      break;
    }
  }
  /* process remaining args */
  args = argc - optind;
  /* if image was specified, this is a batch job */
  if( image ){
    switch(args){
    case 0:
      /* get image info and exit */
      if( ProcessCmd("image", &image, 1, 0, 0) == 0 ){
	FinfoFree(image);
	return 0;
      } else {
	return 1;
      }
      break;
    case 1:
      /* set image (no info returned) */
      if( ProcessCmd("image_", &image, 1, 0, 0) != 0 ){
	return 1;
      }
      /* process command without args */
      if( ProcessCmd(argv[optind+0], NULL, 0, 0, 0) == 0 ){
	FinfoFree(image);
	return 0;
      } else {
	return 1;
      }
      break;
    default:
      /* set image (no info returned) */
      if( ProcessCmd("image_", &image, 1, 0, 0) != 0 ){
	return 1;
      }
      /* process command with args */
      if( ProcessCmd(argv[optind+0], &(argv[optind+1]), args-1, 0, 0) == 0 ){
	FinfoFree(image);
	return 0;
      } else {
	return 1;
      }
      break;
    }
  }
  /* stdout is connected to terminal => not connected to the node helper */
  if( isatty(1) ){
    node = 0;
    tty = 1;
  } else {
    node = 1;
    tty = 0;
  }
  /* initial prompt */
  if( !node ){
    fprintf(stdout, "js9helper> ");
    fflush(stdout);
  }
  /* command loop */
  while( fgets(lbuf, SZ_LINE-1, stdin) ){
    /* first arg: command */
    ip = 0;
    if( !word(lbuf, tbuf, &ip) ) continue;
    /* look for quit */
    if( !node ){
      if( !strcasecmp(tbuf, "quit") ){
	break;
      }
    }
    /* process this command */
    p = &lbuf[ip];
    ProcessCmd(tbuf, &p, 1, node, tty);
    /* re-prompt, if necessary */
    if( !node ){
      fprintf(stdout, "js9helper> ");
      fflush(stdout);
    }
  }
  /* clean up */
  for(cur=finfohead; cur!=NULL; ){
    tcur = cur->next;
    _FinfoFree(cur);
    cur = tcur;
  }
  /* all done */
  return 0;
}
예제 #24
0
파일: main.c 프로젝트: epccs/RPUno
int main(void) 
{
    // Initialize Timers, ADC, and clear bootloader, Arduino does these with init() in wiring.c 
    initTimers(); //Timer0 Fast PWM mode, Timer1 & Timer2 Phase Correct PWM mode.
    init_ADC_single_conversion(EXTERNAL_AVCC); // warning AREF should only have a bypass cap
    init_uart0_after_bootloader(); // bootloader may have the UART setup
    
    // setup()

    // Set digital pins to control load
    init_load();

    // Set digital pins to control solar
    init_pv();

    // put ADC in free running Auto Trigger mode
    enable_ADC_auto_conversion(FREE_RUNNING);
    
    
    /* Initialize UART, it returns a pointer to FILE so redirect of stdin and stdout works*/
    stdout = stdin = uartstream0_init(BAUD);
    
    /* Clear and setup the command buffer, (probably not needed at this point) */
    initCommandBuffer();

    sei(); // Enable global interrupts starts TIMER0, UART0, ADC and any other ISR's
    
    // this start up command should run cctest, e.g. after a reset.
    if (uart0_available() == 0)
    {
        strcpy_P(command_buf, PSTR("/0/cctest?"));
        command_done = 1;
        echo_on = 1;
        printf_P(PSTR("%s\r\n"), command_buf);
    }
    
    // loop() 
    while(1) /* I am tyring to use non-blocking code */
    { 
        // check if character is available to assemble a command, e.g. non-blocking
        if ( (!command_done) && uart0_available() ) // command_done is an extern from parse.h
        {
            // get a character from stdin and use it to assemble a command
            AssembleCommand(getchar());

            // address is the ascii value for '0' note: a null address will terminate the command string. 
            StartEchoWhenAddressed('0');
        }
        
        // check if a character is available, and if so flush transmit buffer and nuke the command in process.
        // A multi-drop bus can have another device start transmitting after getting an address byte so
        // the first byte is used as a warning, it is the onlly chance to detect a possible collision.
        if ( command_done && uart0_available() )
        {
            // dump the transmit buffer to limit a collision 
            uart0_flush(); 
            initCommandBuffer();
            
            //Enable the LT3652, which may have been turned off
            digitalWrite(SHUTDOWN, LOW);
            
            // trun off the load
            load_step(0);
        }
        
        // finish echo of the command line befor starting a reply (or the next part of a reply)
        if ( command_done && (uart0_availableForWrite() == UART_TX0_BUFFER_SIZE) )
        {
            if ( !echo_on  )
            { // this happons when the address did not match 
                initCommandBuffer();
            }
            else
            {
                if (command_done == 1)  
                {
                    findCommand();
                    command_done = 10;
                }
                
                // do not overfill the serial buffer since that blocks looping, e.g. process a command in 32 byte chunks
                if ( (command_done >= 10) && (command_done < 250) )
                {
                     ProcessCmd();
                }
                else 
                {
                    initCommandBuffer();
                }
            }
         }
    }        
    return 0;
}
예제 #25
0
파일: main.c 프로젝트: epccs/RPUno
int main(void) {    

    /* Initialize UART, it returns a pointer to FILE so redirect of stdin and stdout works*/
    stdout = stdin = uartstream0_init(BAUD);
    
    /* Initialize I2C, with the internal pull-up*/
    twi_init(1);

    /* Clear and setup the command buffer, (probably not needed at this point) */
    initCommandBuffer();
       
    sei(); // Enable global interrupts

    char rpu_addr = get_Rpu_address();
    
    // set a default address if RPU manager not found
    if (rpu_addr == 0)
    {
        rpu_addr = '0';
    }
    
    while(1) 
    {
        // check if character is available to assemble a command, e.g. non-blocking
        if ( (!command_done) && uart0_available() ) // command_done is an extern from parse.h
        {
            // get a character from stdin and use it to assemble a command
            AssembleCommand(getchar());

            // address is a char e.g. the ascii value for '0' warning: a null will terminate the command string. 
            StartEchoWhenAddressed(rpu_addr);
        }
        
        // check if the character is available, and if so stop transmit and the command in process.
        // a multi-drop bus can have another device start transmitting after the second received byte so
        // there is little time to detect a possible collision
        if ( command_done && uart0_available() )
        {
            // dump the transmit buffer to limit a collision 
            uart0_flush(); 
            initCommandBuffer();
        }
        
        // finish echo of the command line befor starting a reply (or the next part of reply)
        if ( command_done && (uart0_availableForWrite() == UART_TX0_BUFFER_SIZE) )
        {
            if ( !echo_on  )
            { // this happons when the address did not match
                initCommandBuffer();
            }
            else
            {
                // command is a pointer to string and arg[] is an array of pointers to strings
                // use findCommand to make them point to the correct places in the command line
                // this can only be done once, since spaces and delimeters are replaced with null termination
                if (command_done == 1)  
                {
                    findCommand();
                    command_done = 10;
                }
                
                if ( (command_done >= 10) && (command_done < 250) )
                {
                     ProcessCmd();
                }
                else 
                {
                    initCommandBuffer();
                }
            }
         }
    }        
    return 0;
}