Exemple #1
0
u16 testRES() {
    u8 R1, R2;
    u32 v0, v680, v470K, rt680, rt470K, rr;
    R1 = tList[0][0];
    R2 = tList[0][1];
    R_0(R2, LOW);
    R_680(R1, HIGH);
    Delay_MS(10);

    v0 = ReadADC(R2);
    v680 = ReadADC(R1);

    R_470K(R1, HIGH);
    Delay_MS(10);
    v470K = ReadADC(R1);
    HiZ(R1);
    HiZ(R2);

    //When Rx > sqrt(680*470000) the rt470K is more accurate
    //we calculate if this threshold has been passed below
    if (v680 > 512) rt680 = v680 - 512;
    else rt680 = 512 - v680;

    if (v470K > 512) rt470K = v470K - 512;
    else rt470K = 512 - v470K;

    if (rt470K > rt680){
        //We will use the value calculated with the 680R resistor
        if(v680==v0){ //Shortcircuit?
            rr = 1; //0 is considered error
        }
        else{
            //Use the common formula for a voltage divisor with some correction
            //The output is not 5V and 0V for HIGH and LOW, the difference increasses with
            //lower resistor values, empirically V_low=x, V_high=Vcc-2.80*V_low
            //R = 680*(v680-v0)/(1023-2.8v0-v680)
            rr = (5*R680_IDEAL*(v680-v0)) / (5*1023 - 14*v0 - 5*v680);
        }
    }
    else{
        //We will use the value calculated with the 470K resistor
        //Use the common formula for a voltage divisor
        rr = (R470K_IDEAL*v470K) / (1023 - v470K);
    }

    pins[R1] = 'R';
    pins[R2] = 'R';
    part_unit = 'R';

    if (rr > 0x03E7FC18) { //Values that overflow 16bits when divided by 1000
        rr /= 1000000;
        part_unit = 'M';
    }
    else if(rr > 0xFFFF){ //Values that overflow 16bits
            rr /= 1000;
            part_unit = 'K';
    }
    return (u16) rr;
}
void HD66773R_Driver::Set_Display_On( void )
{
    Reg_Write(DISP_CTRL_REG, 0x0001);
    Delay_MS (100);                             /* 3Frame   */
    Reg_Write(DISP_CTRL_REG, 0x0021);
    Reg_Write(DISP_CTRL_REG, 0x0023);
    Delay_MS (100);                             /* 3Frame   */  
    Reg_Write(DISP_CTRL_REG, 0x0037);      /***normaly white ***/
}
Exemple #3
0
void lcd_init(void) 
{
	deg_Printf("lcd_init spi_ili8961 \n");
	blcd_FrameEnd_Flag = 0;	
	blcd_writeback_Flag = 0;
	
	PIN_CONF()
	SPI_PIN_CONF()	  	

//====open lcd ldo=====
	REG32(SYS_CON) = 0x932B;	//SPEC request value
	REG32(LDO_ACON) |= 0x4;			// 3.0v
	REG32(LDO_ACON) |= (1<<3);		//lcd ldo enable
	deg_Printf("lcd ldo open \n");
	Delay_MS(100);
//====end open lcd ldo=====

	lcd_spirgb_timing_init(spi_ili8961);
    	lcd_spi_init(&table_init[0][0]);	

#if (USER_CONFIG==CONFIG_AX3251_K6000)
	reset_rgb_data_en(0xfe);			// data  7bit en  
#endif

	deg_Printf("Reg1=%x,%x,%x,%x,%x\n",REG32(PF_DIR),REG32(PG_DIR),REG32(PMAP_CFG0),REG32(LCD_CFG),REG32(LCD_CFG_EMI));
	
    spi_to_rgb(); 
	//REG32(LCDCON0)|=BIT(8)|BIT(13);//XJC
	SetIntSrc(LCD_INT);
	REG32(LCDCON0) |= 1<<10;	
}
Exemple #4
0
static void sensorUnplug4( void )
{
	#if ENABLE_UART_PRINTF
	UARTprintf ( "Sensor 4 Unplug Task\n" );
	#endif
			   
	// Wait a few milliseconds to debounce the port interrupt
	Delay_MS( SENSOR_UNPLUG_DELAY );	  

	// If the sensor has been re-connected, abort the unplug routine.													 
	if( 1 == GPIO_Read( SensorPort4.int_port, SensorPort4.int_pin ) )	
	{
		GPIO_EnableInterrupts( SensorPort4.int_port, SensorPort4.int_pin );
	}
	else				
	{
		// Remove this sensor from the sensor task scheduler
		ActiveSensor[3] = -1;
		NumActiveSensors--;
		SensorSampRate[3] = 0;
		SampRateChanged = 1;

#if ENABLE_TRANSCEIVER
		// Remove sensor id 
		Transceiver_UnregisterSensor ( SensorPort4.port_number );
#endif

		// Change the interrupt to detect when a sensor is plugged into this port	  
		GPIO_SetInterruptTask( SensorPort4.int_port, SensorPort4.int_pin, GPIO_RISING_EDGE,
						   2, sensorDetect4 );
   	}

	// Kill this task
	vTaskDelete( NULL );
}
Exemple #5
0
u16 testPNP() {
    u8 i, C[2], B[2], E[2];
    u16 Vc[2], Vb[2];
    u32 hFE[2];
    B[0] = B[1] = tList[0][1];
    C[0] = E[1] = tList[1][0];
    C[1] = E[0] = tList[0][0];
    R_470K(B[0], LOW);
    for (i = 0; i < 2; i++) {
        R_680(C[i], LOW);
        R_0(E[i], HIGH);
        Delay_MS(10);
        Vc[i] = ReadADC(C[i]);
        Vb[i] = ReadADC(B[i]);
        hFE[i] = (u32) Vc[i]*691;
        hFE[i] = hFE[i] / Vb[i];
    }
    HiZ3(B[0], C[0], E[0]);
    if (hFE[0] > hFE[1])i = 0;
    else i = 1;
    pins[C[i]] = 'C';
    pins[B[i]] = 'B';
    pins[E[i]] = 'E';
    return hFE[i];
}
Exemple #6
0
void lcd_init(void) 
{
	deg_Printf("lcd_init mcu 9303 \n");
	blcd_FrameEnd_Flag = 0;	
	blcd_writeback_Flag = 0;
	PIN_CONF()

	lcd_emi_timing_init(emi_9303);

//====open lcd ldo=====
	REG32(SYS_CON) = 0x932B;	//SPEC request value
	REG32(LDO_ACON) |= 0x4;			// 3.0v
	REG32(LDO_ACON) |= (1<<3);		//lcd ldo enable
	deg_Printf("lcd ldo open \n");
	Delay_MS(100);
//====end open lcd ldo=====
	
	lcd_emi_init();

	lcd_clean_screen();

//	lcd_set_backlight(1);
//	while(1);


	LCD_WR_SET;
    	datactrl_mode_sel();

	SetIntSrc(LCD_INT);
	REG32(LCDCON0) |= 1<<10;	

	deg_Printf("pass emi lcd init \n");
 
}
/******** Debug_NetworkTransceiver_Lock ************************************
// PASS - test transceiver lock
// Input: none
// Output: none
// ------------------------------------------------------------------------*/
void Debug_NetworkTransceiver_Lock ( void )
{
    TransceiverPacket pkt;

    pkt.dataSize = 0;

    Delay_MS ( 100 );
    UARTprintf ( "LockerTest thread tries to send transceiver packet\n" );
    Transceiver_SendMessage ( pkt );
    UARTprintf ( "LockerTest PASSED IF packet is sent after locker thread release\n" );

    UARTprintf ("-----------------------------------------\n");

    switch ( testID )
    {
    case '0':
        xTaskCreate( Debug_NetworkTransceiver_Positive, ( signed portCHAR * ) "Debug_NetworkTransceiver_Positive",
                     DEFAULT_STACK_SIZE, NULL, DEFAULT_PRIORITY, NULL );
        break;

    case '7':
        break;

    default:
        xTaskCreate( Debug_NetworkTransceiver, ( signed portCHAR * ) "Debug_NetworkTransceiver",
                     DEFAULT_STACK_SIZE, NULL, DEFAULT_PRIORITY, NULL );
        break;
    }

    vTaskDelete ( NULL );
}
/** Configures the board hardware and chip peripherals for the demo's functionality. */
void SetupHardware(void)
{
	/* Disable watchdog if enabled by bootloader/fuses */
	MCUSR &= ~(1 << WDRF);
	wdt_disable();

	/* Disable clock division */
	clock_prescale_set(clock_div_1);

	/* Hardware Initialization */
	SoftUART_Init();
	LEDs_Init();
	USB_Init();

	/* Disable JTAG debugging */
	MCUCR |= (1 << JTD);
	MCUCR |= (1 << JTD);

	/* Enable pull-up on the JTAG TDI pin so we can use it to select the mode */
	PORTF |= (1 << 7);
	Delay_MS(10);

	/* Select the firmware mode based on the JTD pin's value */
	CurrentFirmwareMode = (PINF & (1 << 7)) ? MODE_USART_BRIDGE : MODE_PDI_PROGRAMMER;

	/* Re-enable JTAG debugging */
	MCUCR &= ~(1 << JTD);
	MCUCR &= ~(1 << JTD);
}
Exemple #9
0
u16 testNMOS() {
    u32 rON;
    u16 vG, vD;
    u8 D, S, G;
    if (tList[2][0] != tList[0][0]) {
        D = tList[2][0];
        S = tList[2][1];
    } else {
        S = tList[2][0];
        D = tList[2][1];
    }
    G = 3 - (S + D);
    R_680(D, HIGH);
    R_0(S, LOW);
    R_680(G, LOW);
    Delay_MS(10);
    vG = ReadADC(G);
    if (vG > 10) {
        HiZ3(S, D, G);
        return 0; //if gate is lower the vdd it meas current is flowing into it which is not MOS
    }
    vD = ReadADC(D);
    if (vD < 1000) {
        HiZ3(S, D, G);
        return 0; //if the VD is higher then 0 when off means its not PMOS
    }
    R_680(G, HIGH);
    Delay_MS(10);
    vG = ReadADC(G);
    if (vG < 1000) {
        HiZ3(S, D, G);
        return 0; //if gate is higher then 0 it meas current is flowing into it which is not MOS
    }
    vD = ReadADC(D);
    if (vD > 123) {
        HiZ3(S, D, G);
        return 0; //if the VD is lower then 0.9*Vdd when ON means its not PMOS
    }
    HiZ3(S, D, G);
    pins[D] = 'D';
    pins[S] = 'S';
    pins[G] = 'G';
    rON = vD * R680_IDEAL;
    rON = rON / (1023 - vD);
    return (u16) rON;
}
void HD66773R_Driver::Set_Display_Off (void)
{
    Reg_Write(DISP_CTRL_REG, 0x0032);      /* GON = 1, DTE = 1, D1-0 = 10 */
    Delay_MS (100);                             /* 3Frame */
    Reg_Write(DISP_CTRL_REG, 0x0022);      /* GON = 1, DTE = 0, D1-0 = 10 */
    Delay_MS (100);                             /* 3Frame */
    Reg_Write(DISP_CTRL_REG, 0x0000);      /* GON = 0, DTE = 0, D1-0 = 00 */

#if 0 // JJ: this was the original code, I added more code to follow the manual */
    Reg_Write (PWR1_CTRL_REG, 0x0000);
#else
    Reg_Write(PWR1_CTRL_REG, 0x0600);      /* BT2-0 = 110 */
    Delay_MS (100);                             /* wait 100ms */    
    Reg_Write(PWR4_CTRL_REG, 0x0000);      /* PON = 0 */
    Reg_Write(PWR5_CTRL_REG, 0x0000);      /* VCOMG = 0 */
    Reg_Write(PWR1_CTRL_REG, 0x0000);      /* BT2-0 = 000, AP2-0 000 */
#endif
}
Exemple #11
0
type getPartSS_CAP_RES() {
    u8 i, j;
    u16 vT1 = 0, vT2, k2;
    for (i = 0; i < 2; i++)
        for (j = i + 1; j < 3; j++) {
            k2 = 400;
            quickADCsetup(i);
            R_0(j, LOW);
            R_470K(i, HIGH);
            while (k2--);

            //Do the ADC acq just after the left over pin is HiZ
            ADCON0 |= 0b10; //GO/!DONE=1
            while (ADCON0 & 0b10);
            vT1 = ADRES;

            //Do the ADC acq after some time and see if the value changes
            Delay_MS(10);
            ADCON0 |= 0b10; //GO/!DONE=1
            while (ADCON0 & 0b10);
            vT2 = ADRES;

            //Discharge?
            R_680(i, LOW);
            Delay_MS(10);
            R_0(i, LOW);
            HiZ(i);
            HiZ(j);

            if (vT1 > CP_HIGH) continue;
            else {
                tList[0][0] = i;
                tList[0][1] = j;
                tList[0][2] = 1023;
                tList[1][0] = j;
                tList[1][1] = i;
                tList[1][2] = 1023;
                nC = 2;
                if (vT2 > (vT1 + CAP_DIFF)) return CAP;
                else return RES;
            }
        }
    return ERROR5;
}
/** Updates the device descriptors so that the correct compatibility mode is used
 *  when the \c RESET_TOGGLES_LIBUSB_COMPAT compile time option is enabled. This
 *  configures the programmer for either Jungo or libUSB driver compatibility. Each
 *  time the AVR is reset via pulling the reset line low the compatibility mode will
 *  be toggled. The current mode is stored in EEPROM and preserved through power
 *  cycles of the AVR.
 */
void UpdateCurrentCompatibilityMode(void)
{
	/* Load the current IN endpoint address stored in EEPROM */
	AVRISP_CurrDataINEndpointAddress = eeprom_read_byte(&AVRISP_CurrDataINEndpointAddress_EEPROM);

	/* Check if we need to switch compatibility modes */
	if (AVRISP_NeedCompatibilitySwitch)
	{
		/* Toggle between compatibility modes */
		AVRISP_CurrDataINEndpointAddress = (AVRISP_CurrDataINEndpointAddress == AVRISP_DATA_IN_EPADDR_LIBUSB) ?
				AVRISP_DATA_IN_EPADDR_JUNGO : AVRISP_DATA_IN_EPADDR_LIBUSB;

		/* Save the new mode into EEPROM */
		eeprom_update_byte(&AVRISP_CurrDataINEndpointAddress_EEPROM, AVRISP_CurrDataINEndpointAddress);
	}

	LEDs_SetAllLEDs(LEDS_NO_LEDS);

	/* Validate IN endpoint address and indicate current mode via LED flashes */
	switch (AVRISP_CurrDataINEndpointAddress)
	{
		default:
			/* Default to Jungo compatibility mode if saved EEPROM is invalid */
			AVRISP_CurrDataINEndpointAddress = AVRISP_DATA_IN_EPADDR_JUNGO;
		case AVRISP_DATA_IN_EPADDR_JUNGO:
			/* Two flashes for Jungo compatibility mode */
			for (uint8_t i = 0; i < 4; i++)
			{
				LEDs_ToggleLEDs(LEDS_ALL_LEDS);
				Delay_MS(100);
			}
			break;
		case AVRISP_DATA_IN_EPADDR_LIBUSB:
			/* Five flashes for libUSB compatibility mode */
			for (uint8_t i = 0; i < 10; i++)
			{
				LEDs_ToggleLEDs(LEDS_ALL_LEDS);
				Delay_MS(100);
			}
			break;
	}

	Delay_MS(500);
}
/** Special startup routine to check if the bootloader was started via a watchdog reset, and if the magic application
 *  start key has been loaded into \ref MagicBootKey. If the bootloader started via the watchdog and the key is valid,
 *  this will force the user application to start via a software jump.
 */
void Application_Jump_Check(void)
{
	bool JumpToApplication = false;

	#if (BOARD == BOARD_LEONARDO)
		/* Enable pull-up on the IO13 pin so we can use it to select the mode */
		PORTC |=  (1 << 7);
		Delay_MS(10);

		/* If IO13 is not jumpered to ground, start the user application instead */
		JumpToApplication |= ((PINC & (1 << 7)) != 0);

		/* Disable pull-up after the check has completed */
		PORTC &= ~(1 << 7);
	#elif ((BOARD == BOARD_XPLAIN) || (BOARD == BOARD_XPLAIN_REV1))
		/* Disable JTAG debugging */
		JTAG_DISABLE();

		/* Enable pull-up on the JTAG TCK pin so we can use it to select the mode */
		PORTF |= (1 << 4);
		Delay_MS(10);

		/* If the TCK pin is not jumpered to ground, start the user application instead */
		JumpToApplication |= ((PINF & (1 << 4)) != 0);

		/* Re-enable JTAG debugging */
		JTAG_ENABLE();
	#endif

	/* If the reset source was the bootloader and the key is correct, clear it and jump to the application */
	if ((MCUSR & (1 << WDRF)) && (MagicBootKey == MAGIC_BOOT_KEY))
	{
		MagicBootKey      = 0;
		JumpToApplication = true;
	}

	if (JumpToApplication)
	{
		// cppcheck-suppress constStatement
		((void (*)(void))0x0000)();
	}
}
BOOL HD66773R_Driver::Uninitialize()
{
    NATIVE_PROFILE_HAL_DRIVERS_DISPLAY();
    Clear();

    Set_Display_Off();

    Delay_MS (1);
    Reg_Write (OSCILLATION_REG, 0x0001);
    Delay_MS (10);
    
    Reg_Write (PWR1_CTRL_REG, 0x0000);
    Reg_Write (PWR2_CTRL_REG, 0x0000);  
    Reg_Write (PWR3_CTRL_REG, 0x0000);
    Reg_Write (PWR4_CTRL_REG, 0x0F00);  /* Pon = 0 */
    Reg_Write (PWR5_CTRL_REG, 0x0E0F);  /* VCOMG=0 */
    Reg_Write (PWR1_CTRL_REG, 0x0003);  /* SLP="1",STB="1" */

    return TRUE;
}
Exemple #15
0
void ILI9328_Driver::Set_Display_On( void )
{
#if 0
    Reg_Write(DISP_CTRL_REG, 0x0001);
    Delay_MS (100);                             /* 3Frame   */
    Reg_Write(DISP_CTRL_REG, 0x0021);
    Reg_Write(DISP_CTRL_REG, 0x0023);
    Delay_MS (100);                             /* 3Frame   */  
    Reg_Write(DISP_CTRL_REG, 0x0037);      /***normaly white ***/
#endif
#if 0
    Reg_Write(ILI9325_POW_CTRL_1, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
    Reg_Write(ILI9325_POW_CTRL_2, 0x0007); /* DC1[2:0], DC0[2:0], VC[2:0]  */
    Reg_Write(LI9325_POW_CTRL_3, 0x0000); /* VREG1OUT voltage  */
    Reg_Write(ILI9325_POW_CTRL_4, 0x0000); /* VDV[4:0] for VCOM amplitude  */
     Delay_MS(200); /* Dis-charge capacitor power voltage */

     Reg_Write(ILI9325_POW_CTRL_1, 0x1690); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
     Reg_Write(ILI9325_POW_CTRL_2, 0x0227); /* R11h=0x0221 at VCI=3.3V, DC1[2:0], DC0[2:0], VC[2:0]  */
     Delay_MS(50);

     Reg_Write(ILI9325_POW_CTRL_3, 0x001D); /* External reference voltage= Vci  */
     Delay_MS(50);

     Reg_Write(ILI9325_POW_CTRL_4, 0x0800); /* R13=1D00 when R12=009D;VDV[4:0] for VCOM amplitude  */
     Reg_Write(ILI9325_POW_CTRL_7, 0x0012); /* R29=0013 when R12=009D;VCM[5:0] for VCOMH  */
     Reg_Write(ILI9325_FRM_RATE_COLOR, 0x000B); /* Frame Rate = 70Hz  */
     Delay_MS(50);
#endif
}
Exemple #16
0
/*******************************************************************************
 Function Name : main
 Description :
*******************************************************************************/
void   main(void){
	u16 i, x, y;
	u16 pict_y;

	Display_Info("main", 0);
	/*--------------initialize the hardware-----------*/
	NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0xC000);
	NVIC_Configuration();
	/*----------display APP version ----------*/
	// (0,0) lower left
	__Display_Str(0, 112, TXT_COLOR, BKGND_COLOR, msg_app_ver);
	__Display_Str(0, 96, TXT_COLOR, BKGND_COLOR, msg_chans);
	__Display_Str(0, 80, RED, BKGND_COLOR, msg_free);
	__Display_Str(0, 64, RED, BKGND_COLOR, msg_warr);
	/*--------initialization --------*/
	Read_Config();
	if(confp->initialized != INIT_FLAG){	// check for first time run
		Reset_Config();
	}
	// initialize based on saved parameters
	Set_Base(0);	// fastest sample speed
	Set_Range(confp->sig_range);
	Set_Orientation(confp->orient);
	Delay_MS(4000);
	Clear_Screen( BKGND_COLOR );
	confp->mode = confp->rtn_mode;
	switch(confp->mode){
		case PHA:
			Init_Spectrum();
			Display_Spectrum ();
			break;
		case RATE:
			Init_Rate();
			Display_Rate();
			break;
		case MENU:
			Display_Menu(confp->menu_index);
			break;
	}
	if (SD_Card_On() == 0){
		if (FAT_Info()){
			if (FAT_Info()){
				__Display_Str(0, 0, RED, BKGND_COLOR, SD_Msgs[SDErr]);
			}
		}
	}
	Beep(BEEP_500Hz, 500);
	/*--------application main loop --------*/
	ctr_key = KEY_SAMPLE;
	ctr_refresh = confp->refresh_time * 1000;	// in mS
	Scan_Samples();	// never returns from this call
}
/**********擦除扇形区*****************************/
void EEPROMSectorErase(UINT16 addr)
{
EEPROMEnable();	
//	EA =0;
ISP_CMD = 0x03;//触发命令,擦除扇区
ISP_ADDRH = (UINT8)( (addr + EEPROM_START_ADDRESS)>>8 );
ISP_ADDRL = (UINT8) addr;
EEPROMStart();
Delay_MS(10);//擦除等待时间,约10毫秒
Delay_US(900);//万一10毫秒延时等待不够,增加900微秒的延时等待时间,确保扇区擦除完成。
EEPROMDisable();
//	EA = 1;
}
Exemple #18
0
void jumpToBootloader(void)
{
    // If USB is used, detach from the bus and reset it
    USB_Disable();
    // Disable all interrupts
    cli();
    // Wait two seconds for the USB detachment to register on the host
    Delay_MS(2000);
    // Set the bootloader key to the magic value and force a reset
    Boot_Key = MAGIC_BOOT_KEY;
    wdt_enable(WDTO_250MS);
    for (;;);
}
Exemple #19
0
static void sensorInit4( void )
{
	unsigned short  eeprom_addr = 0x1800;
	unsigned short  driver_size = 0x700;
	unsigned char  *node_addr   = NULL;

	#if ENABLE_UART_PRINTF
	UARTprintf( "Sensor 4 Init\n" );
	#endif		 

	// Wait a few milliseconds to debounce the port interrupt	
	Delay_MS(SENSOR_INIT_DELAY);

	// If a sensor is no longer plugged in, abort the initialization.														 
	if( 0 == GPIO_Read( SensorPort4.int_port, SensorPort4.int_pin ) )	
	{
		GPIO_EnableInterrupts( SensorPort4.int_port, SensorPort4.int_pin );
	}
	else				
	{
		// Read in the sensor driver from this sensor's EEPROM 
		node_addr = (unsigned char *)SensorDriver4Ptr;			  
    	EEPROM_Open( SensorPort4.rom_cs_port, SensorPort4.rom_cs_pin );
    	EEPROM_ReadBurst( eeprom_addr, node_addr, driver_size );	  		  
    	EEPROM_Close( SensorPort4.rom_cs_port, SensorPort4.rom_cs_pin );

		// Call the sensor_init routine
		SensorInit4( (PORT_T *)&SensorPort4 );
	
		// Call the sensor_config routine
		SensorConfig4( (PORT_T *)&SensorPort4 );

#if ENABLE_TRANSCEIVER
		// Send sensor id to transceiver
		Transceiver_RegisterSensor ( SensorPort4.port_number, SensorPort4.sensor_id );
#endif
		
		taskENTER_CRITICAL();
		SensorSampRate[3] = 1;
		SampRateChanged   = 1;
		ActiveSensor[3]   = 1;
		NumActiveSensors++;	
		taskEXIT_CRITICAL();
										  
		GPIO_SetInterruptTask( SensorPort4.int_port, SensorPort4.int_pin, GPIO_FALLING_EDGE,
							   2, sensorDetectUnplug4 );	
	}

	// Kill this task
	vTaskDelete( NULL );	 
}
Exemple #20
0
u16 checkConduct(u8 A, u8 B, u8 state) {
    u8 i = TEST_DELAY;
    u8 C; //Calculate the leftover pin
    u16 Value;
    C = 3 - (A + B);

    //charges the leftover pin to test State and waits for charge
    R_680(C, state); 
    Delay_MS(10);

    quickADCsetup(B); //sets up the ADC for a later reading

    //conects the A pin to 5V throgh 680R 5V--[680]--[A]
    //brings the leftover pin to HiZ
    R_680(B, LOW);
    R_0(A, HIGH); 
    HiZ(C);
    while (i--);

    //Do the ADC acq just after the left over pin is HiZ
    ADCON0 |= 0b10; //GO/!DONE=1
    while (ADCON0 & 0b10);
    Value = 1023 - ADRES;

    //Discharge?
    R_0(A, LOW);
    Delay_MS(10);
    R_0(B, LOW);
    Delay_MS(10);
    HiZ(A);
    HiZ(B);

    //If the read value is less the 93% of VCC then it is a conductor
    if (Value < CP_HIGH) return Value + 1; 
    return 0; //otherwise its not conducting
}
uint8_t Endpoint_Null_Stream(uint16_t Length,
                             uint16_t* const BytesProcessed)
{
	uint32_t i;

	while ( !Endpoint_IsINReady() ) /*-- Wait until ready --*/
	{
		Delay_MS(2);
	}
	for (i=0; i < Length; i++)
	{
		Endpoint_Write_8(0);	
	}
	return ENDPOINT_RWSTREAM_NoError;
}
//Disable some component
void state_power_saving_init()
{
		
		sensor_board_heater_on(false);
		motor_set(0);
		led_set(0,0,0);	
		//Disable TWI, SPI,Timer2 Timer1 ADC
		PRR0=(1 <<PRTWI) | (1 << PRTIM2) | (1 << PRTIM0) | (1 << PRTIM1) | (1 << PRSPI) | (1 << PRADC) ;
		//Disable Timer3, USART1
		PRR1=(1 << PRTIM3) | (1 << PRUSART1);
		//Disable Analog Comparator Disable
		ACSR|= (1<<ACD);
		//Enter in sleep mode
		SMCR=(1 << SM1) | (1 << SE);
		Delay_MS(200);
		sleep();
}
void Application_Jump_Check(void)
{
	bool JumpToApplication = false;

	#if (BOARD == BOARD_LEONARDO)
		/* Enable pull-up on the IO13 pin so we can use it to select the mode */
		PORTC |=  (1 << 7);
		Delay_MS(10);
		JumpToApplication |= ((PINC & (1 << 7)) != 0);
		PORTC &= ~(1 << 7);
	#endif

	if (JumpToApplication)
	{
		// cppcheck-suppress constStatement
		((void (*)(void))0x0000)();
	}
}
Exemple #24
0
u16 testDIODE() {
    u8 A, C;
    u32 v680_l, v680_h;
    u32 vD;
    A = tList[0][0];
    C = tList[0][1];

    R_680(C, LOW);
    R_680(A, HIGH);
    Delay_MS(10);
    v680_l = ReadADC(C);
    v680_h = ReadADC(A);
    HiZ(A);
    HiZ(C);

    vD = ((v680_h-v680_l) * VCC) / 1023;
    pins[A] = 'A';
    pins[C] = 'C';
    return vD;
}
u16 ReadADC(u8 Pin){
	u16 i;
	//setup ADC
	ADCON2=0b10101110; //R justified result, 12TAD time 101, FOSC/64 110 
	//Analog inputs
	//A0-2 are analog monitors
	ADCON1=0b1000; //internal Vrefs, A0-6 analog
	//set channel
	ADCON0=0;
	ADCON0|=((Pin+4)<<2);//enable the channel
	ADCON0|=0b1;//ADON=1
	//take reading
	Delay_MS(1);
	ADCON0|=0b10; //GO/!DONE=1
	while(ADCON0&0b10);
	//return reading
	//i=ADRESH;
	//i=i<<8;
	//i|=ADRESL;
	return ADRES;
}
Exemple #26
0
void task_play_pause_control(void)
{
	if(!task_ctl.on_playing)
	{
		deg_Printf("play...\n");
		Delay_MS(500);
	
		task_ctl.on_playing = 1;
		t_play.pause_flag = 0;
		timer_Timer2_Start();
		audio_dac_init();
		g_stcJpegInfo.iValidFrameCnt = g_stcJpegInfo.i30FrameCnt;
	}
	else
	{
		deg_Printf("pause\n");
		t_play.pause_flag = 1;
		task_ctl.on_playing=0;
		audio_dac_Stop();
		key_voice_init();
	}
}
Exemple #27
0
/** Special startup routine to check if the bootloader was started via a watchdog reset, and if the magic application
 *  start key has been loaded into \ref MagicBootKey. If the bootloader started via the watchdog and the key is valid,
 *  this will force the user application to start via a software jump.
 */
void Application_Jump_Check(void) // FIXME: update to the 2015 version where (maybe?) is more reliable the checks
{
    bool JumpToApplication = false;

#if ((BOARD == BOARD_XPLAIN) || (BOARD == BOARD_XPLAIN_REV1))
    /* Disable JTAG debugging */
    JTAG_DISABLE();

    /* Enable pull-up on the JTAG TCK pin so we can use it to select the mode */
    PORTF |= (1 << 4);
    Delay_MS(10);

    /* If the TCK pin is not jumpered to ground, start the user application instead */
    JumpToApplication |= ((PINF & (1 << 4)) != 0);

    /* Re-enable JTAG debugging */
    JTAG_ENABLE();
#endif

    /* If the reset source was the bootloader and the key is correct, clear it and jump to the application */
    if ((MCUSR & (1 << WDRF)) && (MagicBootKey == MAGIC_BOOT_KEY))
        JumpToApplication |= true;

    /* If a request has been made to jump to the user application, honor it */
    if (JumpToApplication)
    {
        /* Turn off the watchdog */
        MCUSR &= ~(1<<WDRF);
        wdt_disable();

        /* Clear the boot key and jump to the user application */
        MagicBootKey = 0;

        // cppcheck-suppress constStatement
        ((void (*)(void))0x0000)();
    }
}
Exemple #28
0
/** Configures the board hardware and chip peripherals for the demo's functionality. */
void SetupHardware(void)
{
#if (ARCH == ARCH_AVR8)
	/* Disable watchdog if enabled by bootloader/fuses */
	MCUSR &= ~(1 << WDRF);
	wdt_disable();

	/* Disable clock division */
	clock_prescale_set(clock_div_1);
#endif

	/* Disable JTAG debugging */
	MCUCR |= (1 << JTD);
	MCUCR |= (1 << JTD);

	/* Enable pull-up on the JTAG TDI pin so we can use it to select the mode */
	PORTF |= (1 << 7);
	Delay_MS(10);

	/* Select the firmware mode based on the JTD pin's value */
	CurrentFirmwareMode = (PINF & (1 << 7)) ? MODE_USART_BRIDGE : MODE_PDI_PROGRAMMER;

	/* Re-enable JTAG debugging */
	MCUCR &= ~(1 << JTD);
	MCUCR &= ~(1 << JTD);

	/* Hardware Initialization */
	SoftUART_Init();
	LEDs_Init();
	#if defined(RESET_TOGGLES_LIBUSB_COMPAT)
	UpdateCurrentCompatibilityMode();
	#endif

	/* USB Stack Initialization */
	USB_Init();
}
Exemple #29
0
u16 testZENER() {
    u8 A, C, t;
    u32 v680_l, v680_h;
    u32 vZ;

    if (tList[0][2] > tList[1][2])t = 0;
    else t = 1;

    C = tList[t][0];
    A = tList[t][1];

    R_680(A, LOW);
    R_680(C, HIGH);
    Delay_MS(10);
    v680_l = ReadADC(A);
    v680_h = ReadADC(C);
    HiZ(A);
    HiZ(C);

    vZ = ((v680_h-v680_l) * VCC) / 1023;
    pins[A] = 'A';
    pins[C] = 'C';
    return vZ;
}
/** Special startup routine to check if the bootloader was started via a watchdog reset, and if the magic application
 *  start key has been loaded into \ref MagicBootKey. If the bootloader started via the watchdog and the key is valid,
 *  this will force the user application to start via a software jump.
 */
void Application_Jump_Check(void)
{
	bool JumpToApplication = false;

	#if (BOARD == BOARD_LEONARDO)
		/* Enable pull-up on the IO13 pin so we can use it to select the mode */
		PORTC |= (1 << 7);
		Delay_MS(10);

		/* If IO13 is not jumpered to ground, start the user application instead */
		JumpToApplication = ((PINC & (1 << 7)) != 0);

		/* Disable pull-up after the check has completed */
		PORTC &= ~(1 << 7);
	#elif ((BOARD == BOARD_XPLAIN) || (BOARD == BOARD_XPLAIN_REV1))
		/* Disable JTAG debugging */
		JTAG_DISABLE();

		/* Enable pull-up on the JTAG TCK pin so we can use it to select the mode */
		PORTF |= (1 << 4);
		Delay_MS(10);

		/* If the TCK pin is not jumpered to ground, start the user application instead */
		JumpToApplication = ((PINF & (1 << 4)) != 0);

		/* Re-enable JTAG debugging */
		JTAG_ENABLE();
	#else
		/* Check if the device's BOOTRST fuse is set */
		if (boot_lock_fuse_bits_get(GET_HIGH_FUSE_BITS) & FUSE_BOOTRST)
		{
			/* If the reset source was not an external reset or the key is correct, clear it and jump to the application */
			if (!(MCUSR & (1 << EXTRF)) || (MagicBootKey == MAGIC_BOOT_KEY))
			  JumpToApplication = true;

			/* Clear reset source */
			MCUSR &= ~(1 << EXTRF);
		}
		else
		{
			/* If the reset source was the bootloader and the key is correct, clear it and jump to the application;
			 * this can happen in the HWBE fuse is set, and the HBE pin is low during the watchdog reset */
			if ((MCUSR & (1 << WDRF)) && (MagicBootKey == MAGIC_BOOT_KEY))
				JumpToApplication = true;

			/* Clear reset source */
			MCUSR &= ~(1 << WDRF);
		}
	#endif

	/* Don't run the user application if the reset vector is blank (no app loaded) */
	bool ApplicationValid = (pgm_read_word_near(0) != 0xFFFF);

	/* If a request has been made to jump to the user application, honor it */
	if (JumpToApplication && ApplicationValid)
	{
		/* Turn off the watchdog */
		MCUSR &= ~(1 << WDRF);
		wdt_disable();

		/* Clear the boot key and jump to the user application */
		MagicBootKey = 0;

		// cppcheck-suppress constStatement
		((void (*)(void))0x0000)();
	}
}