Exemplo n.º 1
0
void UserInit(void){
	StartCritical();

	//println_W(startmessage);// All printfDEBUG functions do not need to be removed from code if debug is disabled
//#if defined(DEBUG)
//	ConfigureUART(115200);
//	if(GetChannelMode(16)!=IS_UART_TX)
//		setMode(16,IS_UART_TX);
//#endif
	setPrintLevelInfoPrint();
	println_I(/*PSTR*/("\e[1;1H\e[2J ***Starting User initialization***"));
	InitFlagPins();
	InitBankLEDs();
	SetPowerState0(0,0);
	SetPowerState1(0,0);


	//_delay_ms(1);

#if defined(WPIRBE)
	SPISlaveInit();
#endif


	//_delay_ms(100);
	println_I(/*PSTR*/("Starting Pin Functions"));
	InitPinFunction();
	println_I(/*PSTR*/("Starting Pin Modes"));
	InitPinModes();
	int i=0;
	//println_I(/*PSTR*/("Starting hardware modes"));
	for(i=0;i<GetNumberOfIOChannels();i++){
		initPinState(i);
		configAdvancedAsyncNotEqual(i,10);
		setAsyncLocal(i,true) ;
	}
	//println_I(/*PSTR*/("DONE pin initialization"));

	//println_I(/*PSTR*/("Adding IO Initialization"));
	addNamespaceToList((NAMESPACE_LIST *)get_bcsIoNamespace());
	//println_I(/*PSTR*/("Adding IO.SETMODE Initialization"));
	addNamespaceToList((NAMESPACE_LIST *)get_bcsIoSetmodeNamespace());
	//println_I(/*PSTR*/("Adding Internal Initialization"));
	addNamespaceToList((NAMESPACE_LIST *)get_internalNamespace());
	setNoAsyncMode(true);
	setIgnoreAddressing(true);
	//SetPinTris(0,OUTPUT);
	//SetDIO(0,OFF);

#if defined(USE_AS_LIBRARY)
	InitializeUserCode();
#endif
	EndCritical();
	println_I(/*PSTR*/("Starting Core"));
//	setMode(22,IS_DO);
//	setMode(23,IS_DI);
//	println_I(/*PSTR*/("Pin done"));
}
void InitPins(void){
	//println_I(/*PSTR*/("Starting Pin Functions"));
	InitPinFunction();
	//println_I(/*PSTR*/("Starting Pin Modes"));
	InitPinModes();
	int i=0;
	//println_I(/*PSTR*/("Starting hardware modes"));
	for(i=0;i<GetNumberOfIOChannels();i++){
		initPinState(i);
		configAdvancedAsyncNotEqual(i,10);
		setAsyncLocal(i,TRUE);
	}
	//println_I(/*PSTR*/("DONE pin initialization"));
}
boolean configAdvancedAsync(BowlerPacket * Packet){
	INT32_UNION val;
	INT32_UNION time;
	uint8_t pin = Packet->use.data[0];
	uint8_t type = Packet->use.data[1];
	time.byte.FB= Packet->use.data[2];
	time.byte.TB= Packet->use.data[3];
	time.byte.SB= Packet->use.data[4];
	time.byte.LB= Packet->use.data[5];
	// this sets default async mode and clears and setting of async mode
	setAsyncLocal(Packet->use.data[0],true) ;

	//printPacket(Packet,ERROR_PRINT);
	switch(type){
	case AUTOSAMP:
		configAdvancedAsyncAutoSample(pin,time.Val);
		break;
	case NOTEQUAL:
		configAdvancedAsyncNotEqual(pin,time.Val);
		break;
	case DEADBAND:
		val.byte.FB= Packet->use.data[6];
		val.byte.TB= Packet->use.data[7];
		val.byte.SB= Packet->use.data[8];
		val.byte.LB= Packet->use.data[9];
		configAdvancedAsyncDeadBand(pin,time.Val,val.Val);
		break;
	case THRESHHOLD:
		val.byte.FB= Packet->use.data[6];
		val.byte.TB= Packet->use.data[7];
		val.byte.SB= Packet->use.data[8];
		val.byte.LB= Packet->use.data[9];
		configAdvancedAsyncTreshhold(pin,time.Val,val.Val,Packet->use.data[10]);
		break;
	default:
		ERR(Packet,45,0);
		break;
	}
	getBcsIoDataTable(pin)->PIN.asyncDataPreviousVal=0xffffffff;// invalid previous, forces a value update
	READY(Packet,45,0);
	return true; 
}
void setAsync(uint8_t pin,boolean async){
	setAsyncLocal(pin,async);
	startAdvancedAsyncDefault(pin);
}