Esempio n. 1
0
/*
 * Analog Init
 * - aio: gpio device pointer
 * - pin: pin name
 */
void suli_analog_init(ANALOG_T * aio, PIN_T pin)
{
    if(pin == A3 || pin == A4 || pin == A1 || pin == A2 || pin == TEMP || pin == VOL)
    {
        switch(pin)
        {
        case A3:
            *aio = E_AHI_ADC_SRC_ADC_3;
            break;
        case A4:
            *aio = E_AHI_ADC_SRC_ADC_4;
            break;
        case A1:
            *aio = E_AHI_ADC_SRC_ADC_1;
            break;
        case A2:
            *aio = E_AHI_ADC_SRC_ADC_2;
            break;
        case TEMP:
            *aio = E_AHI_ADC_SRC_TEMP;
            break;
        case VOL:
            *aio = E_AHI_ADC_SRC_VOLT;
            break;
        default:
            *aio = E_AHI_ADC_SRC_TEMP;
        }
        vAHI_ApConfigure(E_AHI_AP_REGULATOR_ENABLE,
    					 E_AHI_AP_INT_DISABLE,
    		    		 E_AHI_AP_SAMPLE_8,
    		    		 E_AHI_AP_CLOCKDIV_500KHZ,
    		    		 E_AHI_AP_INTREF);

    	// Wait until the regulator becomes stable.
    	while(!bAHI_APRegulatorEnabled());
    } else
    {
        DBG_vPrintf(TRACE_SULI, "PIN %d can not be used as analog input.\r\n", pin);
    }
}
/****************************************************************************
 *
 * NAME: vInitSensors
 *
 * DESCRIPTION:
 * Initialise the temperature/humidity sensor and set the ADC to measure the
 * supply voltage.
 *
 ****************************************************************************/
PRIVATE void vInitSensors(void)
{
    /* Initialise temp/humidity sensor interface */
    vHTSreset();
    sTempHumiditySensor.eState = E_STATE_READ_TEMP_HUMID_IDLE;

    /* Initialise ADC for internal battery voltage measurement */

	vAHI_ApConfigure(E_AHI_AP_REGULATOR_ENABLE,
	                 E_AHI_AP_INT_DISABLE,
	                 E_AHI_AP_SAMPLE_2,
	                 E_AHI_AP_CLOCKDIV_2MHZ,
	                 E_AHI_AP_INTREF);

    /* Wait until the analogue peripheral regulator has come up before setting
       the ADC. */
    while(!bAHI_APRegulatorEnabled());

    vAHI_AdcEnable(E_AHI_ADC_CONVERT_DISABLE,
                   E_AHI_AP_INPUT_RANGE_2,
                   E_AHI_ADC_SRC_VOLT);
}
/****************************************************************************
 *
 * NAME:       		LAMP_vInit
 *
 * DESCRIPTION:		Initialises the lamp drive system
 *
 * PARAMETERS:      Name     RW  Usage
 *
 *
 * RETURNS:
 * void
 *
 ****************************************************************************/
PUBLIC void DriverBulb_vInit(void)
{
	bool_t bLampTimerInt = FALSE;

	static bool_t bInit = FALSE;

	if (bInit == FALSE)
	{

		/* Configure DIO pins */
		vAHI_DioSetDirection(0, (LAMP_ON_OFF_MASK | (1 <<LAMP_BLEEDER_PIN)));

		/* Turn CFL lamp off */
		vAHI_DioSetOutput(0, LAMP_ON_OFF_MASK);

		/* Mimic PWM to led ? */
		#if (LAMP_LED_PIN < 21)
		{
			/* Configure as output */
			vAHI_DioSetDirection(0, (1 << LAMP_LED_PIN));
			/* Turn CFL lamp off */
			vAHI_DioSetOutput(0, (1 << LAMP_LED_PIN)/*, 0*/);
			/* Register interrupt callback */
			vAHI_Timer0RegisterCallback(vCbTimer0);
			/* Note we want to generate interrupts */
			bLampTimerInt = TRUE;
		}
		#endif

		/* Configure timer 0 to generate a PWM output on its output pin */
		vAHI_TimerEnable(LAMP_TIMER, LAMP_TIMER_PRESCALE, bLampTimerInt, bLampTimerInt, TRUE);
		vAHI_TimerConfigureOutputs(LAMP_TIMER, FALSE, TRUE);
		vAHI_TimerClockSelect(LAMP_TIMER, FALSE, TRUE);

		/* turn on lamp - this is the default state */

		vAHI_DioSetOutput((1 << LAMP_BLEEDER_PIN),0);
		vAHI_DioSetOutput(LAMP_ON_OFF_MASK,0);


		vAHI_ApConfigure(E_AHI_AP_REGULATOR_ENABLE,
							 E_AHI_AP_INT_DISABLE,
							 E_AHI_AP_SAMPLE_8,
							 E_AHI_AP_CLOCKDIV_500KHZ,
							 E_AHI_AP_INTREF);

		while (!bAHI_APRegulatorEnabled());   /* spin on reg not enabled */

		vAHI_AdcEnable(E_AHI_ADC_SINGLE_SHOT, E_AHI_AP_INPUT_RANGE_2, ADC_USED);

		do
		{
			vAHI_AdcStartSample();
			while(bAHI_AdcPoll());
			gu32BusVoltage = ((uint32)u16AHI_AdcRead()*VBUS_MAXIMUM) >> ADC_BITS;
		} while (gu32BusVoltage< VBUS_TRIP_LO);

		vAHI_AdcDisable();

		vAHI_ApConfigure(E_AHI_AP_REGULATOR_DISABLE,
						 E_AHI_AP_INT_DISABLE,
					     E_AHI_AP_SAMPLE_8,
						 E_AHI_AP_CLOCKDIV_500KHZ,
						 E_AHI_AP_INTREF);

		vAHI_TimerStartRepeat(LAMP_TIMER, PWM_COUNT, PWM_COUNT );

		bInit = TRUE;
		bIsOn = TRUE;

	}
Esempio n. 4
0
/****************************************************************************
 *
 * NAME: AppColdStart
 *
 * DESCRIPTION:
 * Entry point for application from boot loader. Initialises system and runs
 * main loop.
 *
 * RETURNS:
 * Never returns.
 *
 ****************************************************************************/
PUBLIC void AppColdStart(void)
{
#if (defined JN5148 || defined JN5168 )
	// TODO - use watch dog and probably disable brownout reset
	vAHI_WatchdogStop();
#endif
#ifdef JN5139
	vAppApiSetBoostMode(TRUE);
#endif

	// Initialise the hopping mode status
	// TODO - move to settings?
	setHopMode(hoppingRxStartup);

	connectObjects();
	RX.ro.version=2;

	// Initialise the system
	vInitSystem();

	// set up the exception handlers
	setExceptionHandlers();


	if(!radioDebug)debugRoute=&pcViaComPort;
	else debugRoute=&pcViaTx;

	if (debugRoute->routeNodes[0] == CONPC)
	{
		// Don't use uart pins for servo op
		initPcComs(&pccoms, CONPC, 0, rxHandleRoutedMessage);
		rxHardware.uart0InUse=TRUE;
	}


	// Initialise the clock
	// TODO - fix this
	/* the jn5148 defaults to 16MHz for the processor,
	   it can be switched to 32Mhz however the servo driving
	   code would need tweaking
	   */
	//bAHI_SetClockRate(3);


	resetType rt=getResetReason();
	if(rt!=NOEXCEPTION)
	{
		dbgPrintf("EXCEPTION %d \r\n",rt);
	}


	// Set handler for incoming data
	setRadioDataCallback(rxHandleRoutedMessage, CONTX);

	// Retrieve the MAC address and log it to the PC
	module_MAC_ExtAddr_s* macptr = (module_MAC_ExtAddr_s*)pvAppApiGetMacAddrLocation();


	// Send init string to PC log rx mac and bound tx mac to pc
	dbgPrintf("rx24 2.10 rx %x %x tx %x %x",macptr->u32H, macptr->u32L,txMACh ,txMACl );


	// Use dio 16 for test sync pulse
	vAHI_DioSetDirection(0, 1 << 16);


	// Set demands to impossible values
	// TODO - fix magic numbers grrr
	int i;
	for (i = 0; i < 20; i++)
	{
		RX.rxDemands[i] = 4096;
		RX.rxMixedDemands[i] = 4096;
	}
	rxHardware.i2cInUse=imu.enabled;
	startIMU(&imu);


	// Set up digital inputs and outputs
	initInputs(&rxHardware);
	initOutputs(&rxHardware);



	if(rxHardware.oneWireEnabled==TRUE)
	{
		// enable onewire sensor bus
		initOneWireBus(&sensorBus1,CONONEWIRE,rxHardware.oneWirePort,rxHandleRoutedMessage);

	}
	if(rxHardware.gpsEnabled==TRUE)
	{
		initNmeaGps(rxHardware.gpsPort, E_AHI_UART_RATE_38400);
	}

	// Setup DIO  for the LED
	vAHI_DioSetDirection(0, rxHardware.ledBit);

	// Initialise Analogue peripherals
	vAHI_ApConfigure(E_AHI_AP_REGULATOR_ENABLE, E_AHI_AP_INT_DISABLE,
			E_AHI_AP_SAMPLE_8, E_AHI_AP_CLOCKDIV_500KHZ, E_AHI_AP_INTREF);

	while (bAHI_APRegulatorEnabled() == 0)
		;


	// Start the servo pwm generator
	setFrameCallback(frameStartEvent);
	setMixCallback(mixEvent);



	startServoPwm(RX.servoUpdateRate);


	// Enter the never ending main handler
	while (1)
	{
		// Process any events
		vProcessEventQueues();
	}
}