code/WPILib/DigitalModule.cpp
/**
 * Create a new instance of an digital module.
 * Create an instance of the digital module object. Initialize all the parameters
 * to reasonable values on start.
 * Setting a global value on an digital module can be done only once unless subsequent
 * values are set the previously set value.
 * Digital modules are a singleton, so the constructor is never called outside of this class.
 */
Create a new instance of an digital module.
Create an instance of the digital module object. Initialize all the parameters
to reasonable values on start.
Setting a global value on an digital module can be done only once unless subsequent
values are set the previously set value.
Digital modules are a singleton, so the constructor is never called outside of this class.
Create a new instance of an digital module . Create an instance of the digital module object . Initialize all the parameters to reasonable values on start . Setting a global value on an digital module can be done only once unless subsequent values are set the previously set value . Digital modules are a singleton so the constructor is never called outside of this class .
DigitalModule::DigitalModule(UINT32 slot)
	: Module(slot)
	, m_fpgaDIO (NULL)
{
	Resource::CreateResourceObject(&DIOChannels, tDIO::kNumSystems * kDigitalChannels);
	Resource::CreateResourceObject(&DO_PWMGenerators[SlotToIndex(m_slot)], tDIO::kNumDO_PWMDutyCycleElements);
	m_fpgaDIO = new tDIO(SlotToIndex(m_slot), &status);
	while(m_fpgaDIO->readLoopTiming(&status) == 0) taskDelay(1);
	if (m_fpgaDIO->readLoopTiming(&status) != kExpectedLoopTiming)
	{
		wpi_fatal(LoopTimingError);
		printf("DIO LoopTiming: %d, expecting: %d\n", m_fpgaDIO->readLoopTiming(&status), kExpectedLoopTiming);
	}
	m_fpgaDIO->writePWMConfig_Period(PWM::kDefaultPwmPeriod, &status);
	m_fpgaDIO->writePWMConfig_MinHigh(PWM::kDefaultMinPwmHigh, &status);
	for (UINT32 pwm_index = 1; pwm_index <= kPwmChannels; pwm_index++)
	{
		SetPWM(pwm_index, PWM::kPwmDisabled);
		SetPWMPeriodScale(pwm_index, 3); 
	}
	m_fpgaDIO->writeSlowValue_RelayFwd(0, &status);
	m_fpgaDIO->writeSlowValue_RelayRev(0, &status);
	m_relaySemaphore = semMCreate(SEM_Q_PRIORITY | SEM_DELETE_SAFE | SEM_INVERSION_SAFE);
	AddToSingletonList();
}
DigitalModule :: DigitalModule ( UINT32 slot ) : Module ( slot ) , m_fpgaDIO ( NULL ) { Resource :: CreateResourceObject ( & DIOChannels , tDIO :: kNumSystems * kDigitalChannels ) ; Resource :: CreateResourceObject ( & DO_PWMGenerators [ SlotToIndex ( m_slot ) ] , tDIO :: kNumDO_PWMDutyCycleElements ) ; m_fpgaDIO = new tDIO ( SlotToIndex ( m_slot ) , & status ) ; while ( m_fpgaDIO -> readLoopTiming ( & status ) == 0 ) taskDelay ( 1 ) ; if ( m_fpgaDIO -> readLoopTiming ( & status ) != kExpectedLoopTiming ) { wpi_fatal ( LoopTimingError ) ; printf ( " \n " , m_fpgaDIO -> readLoopTiming ( & status ) , kExpectedLoopTiming ) ; } m_fpgaDIO -> writePWMConfig_Period ( PWM :: kDefaultPwmPeriod , & status ) ; m_fpgaDIO -> writePWMConfig_MinHigh ( PWM :: kDefaultMinPwmHigh , & status ) ; for ( UINT32 pwm_index = 1 ; pwm_index <= kPwmChannels ; pwm_index ++ ) { SetPWM ( pwm_index , PWM :: kPwmDisabled ) ; SetPWMPeriodScale ( pwm_index , 3 ) ; } m_fpgaDIO -> writeSlowValue_RelayFwd ( 0 , & status ) ; m_fpgaDIO -> writeSlowValue_RelayRev ( 0 , & status ) ; m_relaySemaphore = semMCreate ( SEM_Q_PRIORITY | SEM_DELETE_SAFE | SEM_INVERSION_SAFE ) ; AddToSingletonList ( ) ; }
Create a new instance of an digital module.
Create a new instance of an digital module .
// Make sure that the 9403 IONode has had a chance to initialize before continuing. // Ensure that PWM output values are set to OFF // Set all to 4x by default. // Turn off all relay outputs. // Create a semaphore to protect changes to the relay values