Exemple #1
0
/*------------------------------------------------------------------
 * Func : mcp_init
 *
 * Desc : mcp module init function
 *
 * Parm : N/A
 *         
 * Retn : N/A
 *------------------------------------------------------------------*/
static int __init mcp_module_init(void)
{   
    if (mcp_init()<0)    
        return -ENODEV;    
                    
    cdev_init(&mcp_dev, &mcp_ops);            
                
    if (alloc_chrdev_region(&devno, 0, 1, MCP_DEV_FILE_NAME)!=0)    
    {
        cdev_del(&mcp_dev);
        return -EFAULT;
    }                                 
    
    if (cdev_add(&mcp_dev, devno, 1)<0)
        return -EFAULT;                          
                      
    devfs_mk_cdev(devno, S_IFCHR|S_IRUSR|S_IWUSR, MCP_DEV_FILE_NAME);         
    
    mcp_device = platform_device_register_simple("MCP", 0, NULL, 0);                           
    //MCP_AES_128_ECB_DataEncrypt();   
    //MCP_AES_H_DataHashTest();
    //MCP_SHA1_DataHashTest();
        
    return 0;        
}
Exemple #2
0
int main(void)
{
	int reg_spi;
	reg_spi = open("/root/spi_if",O_RDWR | O_FSYNC); // Open SPI Interface
	printf("reg_spi = %d\n", reg_spi);
	if (reg_spi > 0){
	printf("spi_if open succeeded\n");
	} else {
		printf ("Open failed.\n");
		switch (errno) {
			case EACCES:  printf ("Permission denied.\n"); break;
			case EMFILE:  printf ("No file handle available.\n"); break;
			case ENOENT:  printf ("File or path not found.\n"); break;
			default:      printf ("Unknown error.\n"); break;
		}
		printf("Numero de error %d\n",errno);
	}

	CanMessage can;
	can.id=1;
	can.dlc=2;
	can.data[0]=0x10;
	can.data[1]=0xAA;
	mcp_init(reg_spi);
	can_send(reg_spi, &can);

	close(reg_spi);
	return 0;
}
Exemple #3
0
void main()
{

  int test;
  unsigned char del;
  stCanFrame sample;
  unsigned char mpptDevice = 0x01;
  unsigned char deviceMC = 0x02;
  unsigned char mpptCanConfig[4];
  unsigned char mcCanConfig[4];

  unsigned short filterID = mcBaseAddress | motorTempMes  ;



  OpenUSART( USART_TX_INT_OFF &
  USART_RX_INT_OFF &
  USART_ASYNCH_MODE &
  USART_EIGHT_BIT &
  USART_CONT_RX &
  USART_BRGH_HIGH, 71);
  
   printf("\n\r Serial Open \n");

  OpenSPI( SPI_FOSC_16,   //Master clock 16mhz
  		MODE_00,                 
  		SMPEND);                  //Output data a end of buff

  



    selectNoDevice();

    setmppt(mpptCanConfig);

    test = mcp_init(mpptDevice, mpptCanConfig);		
	while ( test != 0)
	{
		printf("\rMPPT. Failer to init MCP 2515, reseting \n");
		test = mcp_init(mpptDevice, mpptCanConfig);
	}
	mcp2515_normal(mpptDevice);
	printf("\rMPPT. Pass init MCP 2515\n");

    delay();
       
    setmc(mcCanConfig);
    test = mcp_init(deviceMC,mcCanConfig);
    while(test !=0)
    {
		printf("\r MOTOR CONTROLLER.  Failer to init MCP 2515, reseting \n");
	    test = mcp_init(deviceMC,mcCanConfig);
    }
	mcp2515_normal(deviceMC);
	printf("\rMOTOR CONTROLLER. Pass init MCP 2515\n");
    delay();

	if (bit_is_set(0b10111111,6))
		printf("\r Error -simple bit shift fails \n");
	else	
		printf("\r simple bit operations work right \n");
		




		
    //Ending set up

    //starting main loop
	//------------------
    getMessagesThatLookLike(&(filterID), deviceMC);
	while(1)
	{	
    	mpptData myMpptData[4];
		mcData myMCData;
		stCanFrame sample;
		stCanFrame result;
		unsigned char counter = 0, temp;
		int pollCount = 10;
            
		
		//MPPT
        //---------------------
		//build the message prompts the MPPT data
		//The mppt address we want are. 
		// 0x711 , 0x713, 0x715, 0x717
		sample.id =   MPPTRequestID;
		sample.length = 0;
		sample.rtr =0;
		while(counter < 4)
		{
			sample.id =   MPPTRequestID + 1 + (counter * 2);
			if(g_debug) printf("\r the id is %x\n",MPPTRequestID + 1 + (counter * 2));
			mcp2515_send_message(&sample, 0x02,mpptDevice);		
			Delay10TCYx(0x30);
			result.id = 0;
			mcp2515_get_message(&result ,mpptDevice);			
	
			while(!(result.id == MPPTAnswerID + 1 + (counter * 2)) && pollCount ) //while we do not have the matching id, and the time has not expired keep waiting for the message
			{
		 		mcp2515_get_message(&result, mpptDevice);
		    	Delay10TCYx(0x30);
		 		pollCount--;
	
		 	}
			if(pollCount) 
			{
				parsMppt((result.data),myMpptData[counter]);
			    if(g_messageDebug) 
			    {
				    printf("\rMessage from the MPPT \n");
				    printCanMessage(result);
		 	    }

			}
			else
			{
				if(g_debug) printf("\r mppt TimeOUT \n");
			}
	
			

			counter++;
		}
		

		pollCount = 10;
        //MOTOR Controller
        //-------------------------------
        

   		Delay10TCYx(0x30);
		result.id = 0;
	   	mcp2515_get_message(&result ,deviceMC);
		while( !(result.id == 0x040b) && pollCount)
	   	{
			mcp2515_get_message(&result ,deviceMC)	;
		}
		if (result.id = 0x040b)
	 	{
		    int cool = convertToInt(result.data + 4 , 100 );
		    printf("\rThe temp is %i\n",cool);
		    printCanMessage(result);
			parsMC((result.data), result.id, myMCData);
		}
		else
		{
			printf("\r MC TimeOUT \n");
		}
				
		
	}
} 
Exemple #4
0
  int main(void)
  {
		uint16_t adcValue = 0;						//default 0
		int numb[10];
		uint8_t temp = 0;							//default 0
		int instelling = 0;  						//ingestelde waarde temperatuur default 0
		int bool = 0;								//welke weergave op scherm

		//PORT instellingen
		DISPLAYDDR = 0xFF; //Alle D als output.
		DDRB = 0xFF; //alle B as output
		LED_PORT_NR = 0xFF;

		//Waardes hexa 1 -15
	  numb[0] = 0b00111111;  	//0
	  numb[1] = 0b00000110;   	//1
	  numb[2] = 0b01011011;   	//2
	  numb[3] = 0b01001111;	  	//3
	  numb[4] = 0b01100110;	  	//4
	  numb[5] = 0b01101101;	  	//5
	  numb[6] = 0b01111101;	  	//6
	  numb[7] = 0b00000111;		//7
	  numb[8] = 0b01111111;		//8
	  numb[9] = 0b01101111;		//9



	  DISPLAYDDR = 0xFF; //Alle D als output.
	  DDRB = 0xFF; //alle B as output
	  LED_PORT_NR = 0xFF;



	  //adc aan
	  initADC0();

	  //thermometer instellingen
	  mcp_init();
	  mcp_set_power_mode(MCP_POWER_UP);



  while(1) //loop
  {

      temp = mcp_read_temp_float();


		ADCSRA |= (1<< ADSC) ;  //start ad conversion
		loop_until_bit_is_clear(ADCSRA,ADSC);  //wacht to die klaar is
		adcValue = ADC;

			//check of pb0 hoog is, is die hoog. verander led getal naar instelling of temp.
			if((PIN_INPUT_DRUK & (1<<PIN_INPUT)) == 1)
			  	  	  {
				  			  if(bool == 1)
				  			  {
				  				  bool = 0;
				  			  }
				  			  else
				  			  {
				  				  	 bool = 1;
				  			  }
				  			_delay_ms(200);
				  		  //vertraging anders telt hij door

				  	  }

			PIN_INPUT_DRUK &= ~(1<<PIN_INPUT);  //pin weer 0 nadat hij hoog is, anders doet die niks meer
	if((bool == 1) && (instelling == temp))
	{
	  	LED_PORT_NR = (1<<LINKSLED)|(1<<PWM_BLAUW);  	//eerste getal + rood en groen aan
		LED_PORT =~ numb[temp%10];
		_delay_ms(10);
		LED_PORT_NR = (1<<RECHTSLED)|(1<<PWM_BLAUW) ; //tweede getal + rood en groen aan
		LED_PORT =~ numb[temp/10];
		_delay_ms(10);
	}
	if((bool == 1) && (instelling > temp))
	{
	  	LED_PORT_NR = (1<<LINKSLED)|(1<<PWM_BLAUW)| (1<<PWM_GROEN);  //eerste getal + rood aan
		LED_PORT =~ numb[temp%10];
		_delay_ms(10);
		LED_PORT_NR = (1<<RECHTSLED)|(1<<PWM_BLAUW)| (1<<PWM_GROEN);  //tweede getal + rood aan
		LED_PORT =~ numb[temp/10];
		_delay_ms(10);
	}
	if((bool == 1) && (instelling < temp))
	{
	  	LED_PORT_NR = (1<<LINKSLED)|(1<<PWM_BLAUW)| (1<<PWM_ROOD); 	//eerste getal + groen aan
		LED_PORT =~ numb[temp%10];
		_delay_ms(10);
		LED_PORT_NR = (1<<RECHTSLED)|(1<<PWM_BLAUW)| (1<<PWM_ROOD); 	//tweede getal + groen
		LED_PORT =~ numb[temp/10];
		_delay_ms(10);
	}
if(bool == 0)
	{
	instelling = adcValue/30;  //max instelbare waarde is 34 hierdoor
	LED_PORT_NR = (1<<LINKSLED)|(1<<PWM_GROEN)| (1<<PWM_ROOD); //eerste getal + blauw aan
		LED_PORT =~ numb[instelling%10];
		_delay_ms(10);
		LED_PORT_NR = (1<<RECHTSLED)|(1<<PWM_GROEN)| (1<<PWM_ROOD); //led 1+ blauw aan
		LED_PORT =~ numb[instelling/10];
		_delay_ms(10);
	}



 }