⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp

📁 用于DSP下摄像机的图像抓取、图像处理和传输、以及与上位机TCP/IP通信的工程文件。基于Texas Instruments Code Composer Studio实现。
💻 CPP
字号:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "Phocus1820BSP.h"
#include "CommonDef.h"
#include "Config.h"
#include "Sync.h"

typedef struct _tagCfgAreaHeader
{
	unsigned short nStatus; 
	unsigned short nNum;	
	unsigned short nCheckSum;  
}CFG_AREA_HEADER;

ETH_INFO* g_pEthInfo;
MBX_Handle hMbxCfg = NULL;
MBX_Handle hMbxGet = NULL;
MBX_Handle hMbxNetNormal = NULL;
MBX_Handle hMbxNetPrior = NULL;
MBX_Handle hMbxSchedule = NULL;
//SEM_Handle hSemCapture = NULL;
MBX_Handle hMbxStartSerial = NULL;
MBX_Handle hMbxStopSerial = NULL;
MBX_Handle hMbxSoftTriger = NULL;
MBX_Handle hMbxImageSerial = NULL;
//MBX_Handle hMbxGetData = NULL;

#define INIT_SYSTEM 0
#define SET_IP 0
#if INIT_SYSTEM
void InitParams();
#endif

int main()
{
#if SET_IP	
	Uint8 bMacAddr[8]= {0x00,0x50,0xc2,0x5b,0xb0,0x67};  	
#endif
	//Board init
	Phocus1820_init();
 
#if INIT_SYSTEM
    InitParams();
#endif	
	g_pConfigure = new CConfigure();
	
	if(g_pConfigure != NULL)
	{			
		//Read configure info from flash
		g_pEthInfo = (ETH_INFO*)(g_pConfigure->GetEthInfo());

#if SET_IP			
		memcpy(g_pEthInfo->bMacAddr, bMacAddr, sizeof(bMacAddr));	
    	strcpy(g_pEthInfo->strLocalIPAddr,"192.168.10.203");       
		strcpy(g_pEthInfo->strLocalIPMask, "255.0.0.0");    
		strcpy(g_pEthInfo->strGatewayIP,"192.168.10.1");      
		strcpy(g_pEthInfo->strDomainName,"demo.net");
		strcpy(g_pEthInfo->strHostName,"Phocus1820");
#endif	

	}
	
	hMbxCfg = MBX_create(sizeof(MBX_MESSAGE), 1, NULL);
	hMbxNetNormal = MBX_create(sizeof(MBX_MESSAGE), 1, NULL);
	hMbxNetPrior = MBX_create(sizeof(MBX_MESSAGE), 1, NULL);
	hMbxSchedule = MBX_create(sizeof(MBX_MESSAGE), 1, NULL);
	hMbxGet = MBX_create(sizeof(MBX_MESSAGE), 1, NULL);
	hMbxStartSerial = MBX_create(sizeof(MBX_MESSAGE), 1, NULL);
	hMbxStopSerial = MBX_create(sizeof(MBX_MESSAGE), 1, NULL);
	hMbxSoftTriger = MBX_create(sizeof(MBX_MESSAGE), 1, NULL);
	hMbxImageSerial = MBX_create(sizeof(MBX_MESSAGE), 1, NULL);
//	hMbxControlSerial = MBX_create(sizeof(MBX_MESSAGE), 1, NULL);

	Phocus1820_led_on();
    Phocus1820_waitusec(1000000);
    Phocus1820_led_off();
    Phocus1820_waitusec(1000000);
    Phocus1820_led_on();
/*    Phocus1820_waitusec(10000);
    
    Phocus1820_led_off();
    Phocus1820_waitusec(10000);
    Phocus1820_led_on();*/
		
	//Led on
//	Phocus1820_cpld_write(0x18, 0x00);
	return 1;
}

//Use for first write configure into flash
#if INIT_SYSTEM
static unsigned char CheckSum(unsigned char* pData, int nLen)
{
	unsigned short cksum = 0;
	while(nLen > 0)
	{
		cksum += *pData++;
		nLen --;
	}
	cksum = (cksum >> 8) + (cksum & 0xff);
	cksum += (cksum >> 8);
	return (unsigned char)(~cksum);
}

void write_common_configure(UART_PARAM* pUartParam, ETH_INFO* pEthInfo)
{
//	CSST39v flashDev;
	CFG_AREA_HEADER* tmp = NULL;
	unsigned char rc;	
	
	tmp = (CFG_AREA_HEADER*)malloc(0x1000);
	if(tmp == 0)
		return;
	
	memset(tmp, 0xff, 0x1000);
	tmp->nStatus = 0xffff;
	tmp->nNum = 0x0;  
	memcpy((char*)((unsigned int)(tmp + 1) + 0x400), (char*)pEthInfo, sizeof(ETH_INFO));
	memcpy((char*)(unsigned int)(tmp + 1), (char*)pUartParam, sizeof(UART_PARAM));
	tmp->nCheckSum = 0;
	tmp->nCheckSum = CheckSum((unsigned char*)tmp, 0x1000);
		
	Phocus1820_flash_erase(0x90001000, 0x1000);
	rc = Phocus1820_flash_write(0x90001000, (unsigned int)tmp, 0x1000);
	if(rc != 0)
	{
		free(tmp);
		return;
	}	
	free(tmp);	
	return;
}


void InitParams()
{
//	UART_PARAM stUartParam;
	ETH_INFO stEthInfo;
	
	Uint8 bMacAddr[8]= {0x00,0x50,0xc2,0x5b,0xb0,0x67};
	memcpy(stEthInfo.bMacAddr, bMacAddr, sizeof(bMacAddr));	
    strcpy(stEthInfo.strLocalIPAddr,"192.168.10.203");       
	strcpy(stEthInfo.strLocalIPMask, "255.0.0.0");    
	strcpy(stEthInfo.strGatewayIP,"192.168.10.1");      
	strcpy(stEthInfo.strDomainName,"demo.net");
	strcpy(stEthInfo.strHostName,"Phocus1820");
	#ifdef _DEBUG
	printf("mac ok\n");
	#endif
/*	
	stUartParam.nBaudRate = UartA_BAUD9600;
	stUartParam.nFlowCtrl = UartA_FLOWNO;
	stUartParam.nParity = UartA_PARITYDISABLE;
	stUartParam.nStopBit = UartA_STOPBIT1;
	stUartParam.nWordLen = UartA_CHARLEN8;
	*/
		
	write_common_configure(NULL, &stEthInfo);
}

#endif



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -