Ejemplo n.º 1
0
void Gpio_example2(void)
{ 
   // Example 2:
   // Toggle I/Os using SET/CLEAR registers
   for(;;)
   {    
   
       GpioDataRegs.GPASET.all    =0xAAAAAAAA;
       GpioDataRegs.GPACLEAR.all  =0x55555555;
       
       GpioDataRegs.GPBSET.all    =0x0000000A;   			  
       GpioDataRegs.GPBCLEAR.all  =0x00000005;   			  
              
       delay_loop();

       GpioDataRegs.GPACLEAR.all    =0xAAAAAAAA;
       GpioDataRegs.GPASET.all      =0x55555555;
       
       GpioDataRegs.GPBCLEAR.all    =0x0000000A;   			  
       GpioDataRegs.GPBSET.all      =0x00000005;   			  
    
       delay_loop();	
   
    }
}
Ejemplo n.º 2
0
void bb_stop( void )
{
    SDA_LOW;
    delay_loop();
    SCL_HIGH;
    delay_loop();
    SDA_HIGH;    
}
Ejemplo n.º 3
0
Archivo: main.c Proyecto: spa-pal/fat42
/* -------------------------------------------------------------------------- */
void main(void) {
	u8 i;
	u16 tout;
	
	GPIOH->ODR&=~ALL_LEDs; 						// LEDs - as push-pull outputs, all off
	GPIOH->DDR|= ALL_LEDs;
	GPIOH->CR1|= ALL_LEDs;
	
	init_CAN();
	CAN->DGR|= CAN_DGR_LBKM;					// set CAN in loop back mode
	
	leds= 0;											// utility variables
	id_offset= -1;
	
	while (1) {
		
		CAN->PSR= 0;								// send my message
		memcpy(&CAN->Page.TxMailbox.MDLCR, &MY_MESS[0], MY_MESS_DLC + 5);
		id_offset= ++id_offset & 0x0F;
		CAN->Page.TxMailbox.MIDR2+= (id_offset<<2);
		CAN->Page.TxMailbox.MCSR|= CAN_MCSR_TXRQ;		// transmit request
		tout= 50000;
		while((CAN->TSR & CAN_TSR_TXOK0) == 0  &&  --tout > 0);	// wait for transmition OK
		if(tout) {
			set_Tx_LEDs();
			CAN->TSR|= CAN_TSR_RQCP0;
		}
		else
			if(CAN->Page.TxMailbox.MCSR & CAN_MCSR_TERR)
				CAN->Page.TxMailbox.MCSR|= CAN_MCSR_ABRQ;

		tout= 50000;
		while((CAN->RFR & CAN_RFR_FMP01) == 0 &&  --tout > 0);		// wait for any CAN receive message
		
		if(tout) {
			CAN->PSR= 7;									// page 7 - read messsage
			while (CAN->RFR & CAN_RFR_FMP01) {				// make up all received messages
				memcpy(&mess[0], &CAN->Page.RxFIFO.MFMI, 14); // compare the message content
				for(i=5; i<MY_MESS_DLC+5; ++i)
					if(mess[i+1]!=MY_MESS[i]) { tout= 0; break;	};
				if(tout)
					set_Rx_LEDs();
				CAN->RFR|= CAN_RFR_RFOM;				// release received message
				while(CAN->RFR & CAN_RFR_RFOM);		// wait until the current message is released
			};
		};		
			
		
		delay_loop((u32)( 5000));
		switch_LEDs_off();
		delay_loop((u32)(15000));
	};
}
Ejemplo n.º 4
0
static bool attempt(unsigned long loops, int ticks)
{
	L4_Clock_t start = L4_SystemClock();
	do {
		delay_loop(100);
	} while(L4_SystemClock().raw < start.raw + clock_step - 1);

	delay_loop(loops);
	L4_Clock_t end = L4_SystemClock();

	/* this biases the result upward. that's OK; nsleep() and usleep() are
	 * only defined not to wake before the time is up.
	 */
	return start.raw + ticks * clock_step < end.raw;
}
Ejemplo n.º 5
0
void bb_start( void )
{
    // Idle bus == both lines high
    SDA_LOW;
    delay_loop();
    SCL_LOW;    
}
Ejemplo n.º 6
0
/*---------------------------------------------------------------------------------------------------------*/
int main (void)
{

    /* Init System, IP clock and multi-function I/O */
    SYS_Init(); //In the end of SYS_Init() will issue SYS_LockReg() to lock protected register. If user want to write protected register, please issue SYS_UnlockReg() to unlock protected register.

    /* Init UART for printf */
    UART_Init();

    printf("\n\nCPU @ %dHz\n", SystemCoreClock);

    printf("+-------------------------------------+ \n");
    printf("|    MINI51 GPIO Toggle Sample Code   | \n");
    printf("+-------------------------------------+ \n");

    /*set P3.6 to output mode */
    P3->PMD = (P3->PMD & ~0x3000) | (GPIO_PMD_OUTPUT << 12);
    P36 = 1;

    while(1)
    {
        P36 ^= 1;
        delay_loop();
    }
}
void InitMcbspb(void)
{

// McBSP-B register settings

    McbspbRegs.SPCR2.all=0x0000;		// Reset FS generator, sample rate generator & transmitter
	McbspbRegs.SPCR1.all=0x0000;		// Reset Receiver, Right justify word
	McbspbRegs.SPCR1.bit.DLB = 1;       // Enable loopback mode for test. Comment out for normal McBSP transfer mode.

	McbspbRegs.MFFINT.all=0x0;			// Disable all interrupts

    McbspbRegs.RCR2.all=0x0;			// Single-phase frame, 1 word/frame, No companding	(Receive)
    McbspbRegs.RCR1.all=0x0;

    McbspbRegs.XCR2.all=0x0;			// Single-phase frame, 1 word/frame, No companding	(Transmit)
    McbspbRegs.XCR1.all=0x0;

    McbspbRegs.SRGR2.bit.CLKSM = 1;		// CLKSM=1 (If SCLKME=0, i/p clock to SRG is LSPCLK)
	McbspbRegs.SRGR2.bit.FPER = 31;		// FPER = 32 CLKG periods

    McbspbRegs.SRGR1.bit.FWID = 0;              // Frame Width = 1 CLKG period
    McbspbRegs.SRGR1.bit.CLKGDV = CLKGDV_VAL;	// CLKG frequency = LSPCLK/(CLKGDV+1)

   	McbspbRegs.PCR.bit.FSXM = 1;		// FSX generated internally, FSR derived from an external source
	McbspbRegs.PCR.bit.CLKXM = 1;		// CLKX generated internally, CLKR derived from an external source
    delay_loop();                // Wait at least 2 SRG clock cycles
    McbspbRegs.SPCR2.bit.GRST=1; // Enable the sample rate generator
	clkg_delay_loop();           // Wait at least 2 CLKG cycles
	McbspbRegs.SPCR2.bit.XRST=1; // Release TX from Reset
	McbspbRegs.SPCR1.bit.RRST=1; // Release RX from Reset
    McbspbRegs.SPCR2.bit.FRST=1; // Frame Sync Generator reset

}
Ejemplo n.º 8
0
void calibrate_delay(void)
{
	int sample = 0;
	int count = 0;
	DWORD tick_count1 = 0L;
	DWORD tick_count2 = 0L;

	one_ms_delay = 0;

	for (sample = 0; sample < DELAY_SAMPLES; ++sample)
	{
		count = 0;
		tick_count1 = get_tick_count();

		while ((tick_count2 = get_tick_count()) == tick_count1)
		{};
		
		do 
		{ 
			delay_loop(DELAY_CHECK_LOOPS);
			count++;
		} while	((tick_count1 = get_tick_count()) == tick_count2);

		one_ms_delay += (int)((DELAY_CHECK_LOOPS * (DWORD)count) / (tick_count1 - tick_count2));
	}

	one_ms_delay /= DELAY_SAMPLES;
}
//
// init_mcbsp_spi - Configure McBSP settings
//
void init_mcbsp_spi()
{
    //
    // McBSP-A register settings
    //
    McbspaRegs.SPCR2.all = 0x0000;       // Reset FS generator, sample rate
                                         // generator & transmitter
    McbspaRegs.SPCR1.all = 0x0000;       // Reset Receiver, Right justify word,
                                         // Digital loopback dis.
    McbspaRegs.PCR.all = 0x0F08;         //(CLKXM=CLKRM=FSXM=FSRM= 1, FSXP = 1)
    McbspaRegs.SPCR1.bit.DLB = 1;
    McbspaRegs.SPCR1.bit.CLKSTP = 2;     // Together with CLKXP/CLKRP
                                         // determines clocking scheme
    McbspaRegs.PCR.bit.CLKXP = 0;        // CPOL = 0, CPHA = 0 rising edge
                                         // no delay
    McbspaRegs.PCR.bit.CLKRP = 0;
    McbspaRegs.RCR2.bit.RDATDLY = 01;    // FSX setup time 1 in master mode.
                                         // 0 for slave mode (Receive)
    McbspaRegs.XCR2.bit.XDATDLY = 01;    // FSX setup time 1 in master mode.
                                         // 0 for slave mode (Transmit)

    McbspaRegs.RCR1.bit.RWDLEN1 = 5;     // 32-bit word
    McbspaRegs.XCR1.bit.XWDLEN1 = 5;     // 32-bit word

    McbspaRegs.SRGR2.all = 0x2000;       // CLKSM=1, FPER = 1 CLKG periods
    McbspaRegs.SRGR1.all = 0x000F;       // Frame Width = 1 CLKG period,
                                         // CLKGDV=16

    McbspaRegs.SPCR2.bit.GRST = 1;       // Enable the sample rate generator
    delay_loop();                        // Wait at least 2 SRG clock cycles
    McbspaRegs.SPCR2.bit.XRST = 1;       // Release TX from Reset
    McbspaRegs.SPCR1.bit.RRST = 1;       // Release RX from Reset
    McbspaRegs.SPCR2.bit.FRST = 1;       // Frame Sync Generator reset
}
Ejemplo n.º 10
0
void
LoopDelay (uint16_t ms)
{
  if (!ms) return;

  delay_loop (ms * CONST_LOOPS);
}
Ejemplo n.º 11
0
static void
wait ()
{
	volatile unsigned int i;
	for (i = 0; i < 30000; i++)
		delay_loop ();
}
Ejemplo n.º 12
0
void Gpio_example3(void)
{ 
   // Example 2:
   // Toggle I/Os using TOGGLE registers

   // Set pins to a known state
   
      GpioDataRegs.GPASET.all    =0xAAAAAAAA;
      GpioDataRegs.GPACLEAR.all  =0x55555555;
       
      GpioDataRegs.GPBSET.all    =0x0000000A;   			  
      GpioDataRegs.GPBCLEAR.all  =0x00000005;   			     

   // Use TOGGLE registers to flip the state of
   // the pins. 
   // Any bit set to a 1 will flip state (toggle)
   // Any bit set to a 0 will not toggle.   

   for(;;)
   {    
      GpioDataRegs.GPATOGGLE.all =0xFFFFFFFF;
      GpioDataRegs.GPBTOGGLE.all =0x0000000F;   			  
      delay_loop();
    }
}
Ejemplo n.º 13
0
void pwm_stop(void)
// Stop all PWM signals to the motor.
{
    // Disable interrupts.
    cli();

    // Are we moving in the A or B direction?
    if (pwm_a || pwm_b)
    {
        // Disable OC1A and OC1B outputs.
        TCCR1A &= ~((1<<COM1A1) | (1<<COM1A0));
        TCCR1A &= ~((1<<COM1B1) | (1<<COM1B0));

        // Clear PB1 and PB2.
        PORTB &= ~((1<<PB1) | (1<<PB2));

        delay_loop(DELAYLOOP);

        // Reset the A and B direction flags.
        pwm_a = 0;
        pwm_b = 0;
    }

    // Set the PWM duty cycle to zero.
    OCR1A = 0;
    OCR1B = 0;

    // Restore interrupts.
    sei();

    // Save the pwm A and B duty values.
    registers_write_byte(REG_PWM_DIRA, pwm_a);
    registers_write_byte(REG_PWM_DIRB, pwm_b);
}
Ejemplo n.º 14
0
void nsleep(unsigned long nanoseconds)
{
	int nano_per_hz = 1000000000 / hz,
		ticks = nanoseconds / nano_per_hz;
	if(ticks > 2 && false) {
		/* FIXME: this doesn't work, does it... */
		L4_Clock_t start = L4_SystemClock();
		do {
			delay_loop(iters_per_tick / hz);
		} while(start.raw + ticks < L4_SystemClock().raw);
	} else {
		uint64_t t = nanoseconds;
		t *= iters_per_tick;
		t /= nano_per_hz;
		delay_loop(t);
	}
}
Ejemplo n.º 15
0
void Gpio_example1(void)
{ 
   // Example 1:
   // Toggle I/Os using DATA registers

   for(;;)
   {   
       GpioDataRegs.GPADAT.all    =0xAAAAAAAA;
       GpioDataRegs.GPBDAT.all    =0x0000000A;   			  
       
       delay_loop();

       GpioDataRegs.GPADAT.all    =0x55555555; 
       GpioDataRegs.GPBDAT.all    =0x00000005; 
    
       delay_loop();	
    }
}
Ejemplo n.º 16
0
void send_nak( void )
{
    SDA_HIGH;
    NOP; NOP; NOP;
    SCL_HIGH;
    delay_loop();
    SCL_LOW;
    NOP; NOP; NOP;
}
Ejemplo n.º 17
0
void
vmusic2_init(void)
{
    vmusic2_serial_init();
    delay_loop(4000);
vmusic2_play("0", 1);
    vmusic2_cmd(VMUSIC2_PING_CMD, 1);
    vmusic2_cmd(VMUSIC2_STOP_CMD, 1);
}
Ejemplo n.º 18
0
/**
* @brief   write cyc buffer is data to file
*
* @author hankejia
* @date 2012-07-05
* @param[in] pthis			the pointer point to the CCycBuffer.
* @param[in] fd			file is descriptor.the cyc buffer is data will write to this file
* @param[in] iSize			how many data in bytes from cyc buffer you want to write to the file
* @param[in] pWriteBuffer	the space alloc by caller,fuction will use this space to load the data,and write to file system,
*						if this param is NULL, function will alloc space by himself
* @return T_S32
* @retval return  >=0 the size of bytes write to file, < 0  failed
*/
static T_S32 WriteToFs( T_pVOID pthis, T_S32 fd, T_S32 iSize )
{
    CCycBuffer *this = ( CCycBuffer * )pthis;
    CycBuffer_handle * handle = (CycBuffer_handle *)this->handle;
    T_CHR * pBuffer = NULL;
    T_S32 iLineSize = 0, iLeavings = 0;

    Condition_Lock( handle->mWriteDataCon );

    //need to flash all data
    if ( -1 == iSize ) {
        iSize = handle->mUseSize;
    }

    pBuffer = PopSingle( pthis, iSize );

    if ( pBuffer == NULL ) {
        ResumeForceQuitState( pthis );
        Condition_Unlock( handle->mWriteDataCon );
        delay_loop( 0, 10000 ); // 10ms
        return 0;
    }

    iLeavings = iSize;

    while( iLeavings > 0 ) {
        iLineSize = ( handle->mCycBuffer + handle->mBufferSize ) - pBuffer;
        if ( iLineSize == 0 ) {
            pBuffer = handle->mCycBuffer;
            continue;
        } else if ( iLineSize > iLeavings ) {
            iLineSize = iLeavings;
        }

        if ( WriteComplete( fd, pBuffer, iLineSize ) < 0 ) {
            Condition_Unlock( handle->mWriteDataCon );
            loge( "WriteToFs::WriteComplete error!\n" );
            return -1;
        }

        pBuffer += iLineSize;
        iLeavings -= iLineSize;
    }

    Condition_Lock( handle->mDataCon );
    handle->mRead = pBuffer;
    handle->mUseSize -= iSize;
    handle->mPopComplete = AK_TRUE;
    Condition_Unlock( handle->mDataCon );
    Condition_Unlock( handle->mWriteDataCon );

    //logi( "pop signal send!\n" );
    Condition_Signal( &(handle->mDataCon) );

    return iSize;
}
Ejemplo n.º 19
0
void send_ack( void )
{
    SDA_LOW;
    NOP; NOP; NOP;
    SCL_HIGH;
    delay_loop();
    SCL_LOW;
    NOP; NOP; NOP;
    SDA_HIGH;
}
Ejemplo n.º 20
0
/**
* @brief   file lock set
*
* @author hankejia
* @date 2012-07-05
* @param[in] fd 			file fd
* @param[in] type 			type, file r/w lock or r/w unlock
* @param[in] whence 		lock file is position, SEEK_SET, SEEK_CUR, SEEK_END
* @param[in] nlen 			lock len, lock data from whence to whence + nlen.
* @param[in] time_ms 		time out ms
* @return T_S32
* @retval if return 0 success, otherwise failed
*/
T_S32 flock_set( T_S32 fd, T_U32 type, T_U32 whence, T_U32 nlen, T_U32 time_ms )
{
	struct flock lock;
	T_U32 delay_ms_once = 10 * 1000UL, delay_ms = 0;
	lock.l_type = type;
	lock.l_whence = whence;
	lock.l_start = 0;
	lock.l_len = nlen;

	if ( time_ms > 0 ) //timeout wait
	{
		//Since there is no timeout API for fcntl(), So use while loop
		//to implement time out waiting.
		while( fcntl( fd, F_SETLK, &lock ) < 0 )
		{
			delay_loop( 0, delay_ms ); // delay 10 ms
			delay_ms += delay_ms_once;
			if ( delay_ms >= time_ms ) {
				return 1; // return 1, time out
			}
		}
	}
	else if ( time_ms == 0 )
	{
		if ( fcntl( fd, F_SETLK, &lock ) < 0 )
		{
			if ( fcntl( fd, F_GETLK, &lock ) < 0 ) {
				loge( "fcntl set %d unknown error! %s\n", type, strerror(errno) );
				return -1;
			}

			if ( lock.l_type == F_RDLCK ) {
				logi( "read lock already set by %d\n", lock.l_pid );
				return 2; //return 2 the operation already set by another program
			}

			if ( lock.l_type == F_WRLCK ) {
				logi( "write lock already set by %d\n", lock.l_pid );
				return 2;//return 2 the operation already set by another program
			}

			loge( "fcntl set %d unknown error! %s\n", type, strerror(errno) );
			return -1;
		}
	}
	else //block wait
	{
		if ( fcntl( fd, F_SETLKW, &lock ) < 0 ) {
			loge( "fcntl set %d block error! %s\n", type, strerror(errno) );
			return -1;
		}
	}

	return 0;
}
Ejemplo n.º 21
0
/**
* @brief   flush cyc buffer is data to file
*
* @author hankejia
* @date 2012-07-05
* @param[in] pthis			the pointer point to the CCycBuffer.
* @param[in] fd			file is descriptor.the cyc buffer is data will write to this file
* @return T_S32
* @retval return  >=0 the size of bytes write to file, < 0  failed
*/
static T_S32 flush( T_pVOID pthis, T_S32 fd )
{
    CCycBuffer *this = ( CCycBuffer * )pthis;
    CycBuffer_handle * handle = (CycBuffer_handle *)this->handle;

    while ( !(handle->mPopComplete) ) {
        ForceQuit( pthis );
        delay_loop( 0, 1000 ); // 1ms
    }

    return WriteToFs( pthis, fd, -1 );
}
Ejemplo n.º 22
0
void calibrate_delay_loop(void)
{
	L4_KernelInterfacePage_t *kip = L4_GetKernelInterface();
	L4_Time_t readp = { .raw = kip->ClockInfo.X.ReadPrecision };
	clock_step = time_in_us(readp);
	if(clock_step > 1000000) {
		printf("kernel reports scheduleprecision of %u µs (too high!)\n",
			clock_step);
		abort();
	}
	hz = 1000000 / clock_step;

	printf("calibrating delay loop... (hz %u, clock_step %u)\n",
		hz, clock_step);
	iters_per_tick = measure(15);
	assert(iters_per_tick > 0);
	printf("  %lu.%02lu BogoMIPS (%lu iters / tick)\n",
		iters_per_tick / (500000 / hz),
		(iters_per_tick / (5000 / hz)) % 100,
		iters_per_tick);

#if 0
	/* testing. */
	for(int i=1; i<=25; i++) {
		L4_Clock_t start = L4_SystemClock();
		do {
			delay_loop(200);
		} while(L4_SystemClock().raw < start.raw + 1);

		int ticks = i * 2;
		delay_loop(iters_per_tick * ticks);
		L4_Clock_t end = L4_SystemClock();
		if(start.raw + ticks != end.raw) {
			printf("wanted to wait for %d ticks, waited for %d\n",
				ticks, (int)(end.raw - start.raw));
		}
	}
#endif
}
Ejemplo n.º 23
0
void pwm_stop(void)
// Stop all PWM signals to the motor.
{
    // Disable interrupts.
    cli();

    // Are we moving in the A or B direction?
    if (pwm_a || pwm_b)
    {
        // Make sure that SMPLn_B (PD4) and SMPLn_A (PD7) are held high.
        PORTD |= ((1<<PD4) | (1<<PD7));

        // Disable PWM_A (PB1/OC1A) and PWM_B (PB2/OC1B) output.
        TCCR1A = 0;

        // Make sure that PWM_A (PB1/OC1A) and PWM_B (PB2/OC1B) are held low.
        PORTB &= ~((1<<PB1) | (1<<PB2));

        // Do we want to enable braking?
        if (1)
        {
           // Before enabling braking (which turns on the "two lower MOSFETS"), introduce
           // sufficient delay to give the H-bridge time to respond to the change of state 
           // that has just been made.
           delay_loop(DELAYLOOP);

            // Hold EN_A (PD2) and EN_B (PD3) high.
            PORTD |= ((1<<PD2) | (1<<PD3));
        }
        else
        {
            // Hold EN_A (PD2) and EN_B (PD3) low.
            PORTD &= ~((1<<PD2) | (1<<PD3));
        }

        // Reset the A and B direction flags.
        pwm_a = 0;
        pwm_b = 0;
    }

    // Set the PWM duty cycle to zero.
    OCR1A = 0;
    OCR1B = 0;

    // Restore interrupts.
    sei();

    // Save the pwm A and B duty values.
    registers_write_byte(REG_PWM_DIRA, pwm_a);
    registers_write_byte(REG_PWM_DIRB, pwm_b);
}
Ejemplo n.º 24
0
int main(void)
{
    /* Init System, IP clock and multi-function I/O */
    SYS_Init(); //In the end of SYS_Init() will issue SYS_LockReg() to lock protected register. If user want to write protected register, please issue SYS_UnlockReg() to unlock protected register.

    /* Configure UART and set UART Baudrate */
    UART_Open(UART, 115200);

    printf("+---------------------------------+\n");
    printf("|    Mini58 Toggle LED Sample     |\n");
    printf("+---------------------------------+\n");

    /*set P1.5 to output mode */
    GPIO_SetMode(P1, BIT5, GPIO_MODE_OUTPUT);

    while(1)
    {
        P15 = 0;
        delay_loop();
        P15 = 1;
        delay_loop();
    }
}
Ejemplo n.º 25
0
static void pwm_dir_a(uint8_t pwm_duty)
// Send PWM signal for rotation with the indicated pwm ratio (0 - 255).
// This function is meant to be called only by pwm_update.
{
    // Determine the duty cycle value for the timer.
    uint16_t duty_cycle = PWM_OCRN_VALUE(pwm_div, pwm_duty);

    // Disable interrupts.
    cli();

    // Do we need to reconfigure PWM output?
    if (!pwm_a || pwm_b)
    {

        // Disable PWM_A (PB1/OC1A) and PWM_B (PB2/OC1B) output.
        // NOTE: Actually PWM_A should already be disabled...
        TCCR1A &= ~((1<<COM1A1) | (1<<COM1B1));

        OCR1A = duty_cycle;

        // Yes. Make sure PB1 and PB2 are zero.
        PORTB &= ~((1<<PB1) | (1<<PB2));

        //
        // Give the H-bridge time to respond to the above changes
        //
        delay_loop(DELAYLOOP);

        // Enable PWM_A (PB1/OC1A)  output.
        TCCR1A |= (1<<COM1A1);

        // Reset the B direction flag.
        pwm_b = 0;
    }

    // Set the A direction flag.
    pwm_a = pwm_duty;

    // Update the PWM duty cycle.
    OCR1A = duty_cycle;
    OCR1B = 0;

    // Restore interrupts.
    sei();

    // Save the pwm A and B duty values.
    registers_write_byte(REG_PWM_DIRA, pwm_a);
    registers_write_byte(REG_PWM_DIRB, pwm_b);
}
Ejemplo n.º 26
0
Archivo: conio.c Proyecto: rtemss/rtems
/**
 *  @brief gba_getch function read char from game pad keys
 *
 *  Character input is done with GBA buttons, up-down-left-right/A/B/R/L/Select/Start
 *  - Select-key accept selected character
 *  - Start-key read CR (Enter)
 *  - A-key select 'A' character
 *  - B-key select 'Z' character
 *  - R-key select '1' character
 *  - L-key select '9' character
 *  - up-key increment character ('A'->'B')
 *  - down-key decrement character ('B'-'A')
 *  - left-key change set of character ('!'->'A'->'a')
 *  - right-key change set of character ('a'->'A'->'!')
 *
 *  @param  None
 *  @return Selected char code
 */
int gba_getch(void)
{
  int  keyx, key  = 0;

  while(1) {
      key = GBA_KEY();
      while ( (keyx=GBA_KEY())==key );
      switch (key)
      {
        case GBA_KEY_SELECT:
            gba_put(inputch);
            return inputch;
            break;
        case GBA_KEY_START:
            gba_put(' ');
            inputch = ASCII_CR;
            return inputch;
            break;
        case GBA_KEY_A:
            inputch = 'A';
            break;
        case GBA_KEY_B:
            inputch = 'Z';
            break;
        case GBA_KEY_UP:
            if ((inputch-1) >= 0x20) inputch--;
            break;
        case GBA_KEY_DOWN:
            if ((inputch+1) <=  0x7E) inputch++;
            break;
        case GBA_KEY_LEFT:
            if ((inputch - 0x20) >= 0x20) inputch -= 0x20;
            break;
        case GBA_KEY_RIGHT:
            if ((inputch + 0x20) <= 0x7E) inputch += 0x20;
            break;
        case GBA_KEY_R:
            inputch = '1';
            break;
        case GBA_KEY_L:
            inputch = '9';
            break;
        default:
            break;
      }
      gba_put(inputch);
      delay_loop(1000);
  }
}
Ejemplo n.º 27
0
//
// mcbsp_init_dlb - Initialize MCBSP with digital loopback setup
//
void mcbsp_init_dlb()
{
//
// RESET MCBSP
//
   McbspaRegs.SPCR2.bit.FRST = 0; // Frame Sync generator reset
   McbspaRegs.SPCR2.bit.GRST = 0; // Sample Rate generator Reset
   McbspaRegs.SPCR2.bit.XRST = 0; // Transmitter reset
   McbspaRegs.SPCR1.bit.RRST = 0; // Receiver reset

//
// Initialize McBSP Registers
// McBSP register settings for Digital loop back
//
   McbspaRegs.SPCR2.all = 0x0000; // XRST =0
   McbspaRegs.SPCR1.all = 0x8000; // RRST =0, DLB enabled
   McbspaRegs.RCR2.all = 0x0001;  // RDATDLY = 1
   McbspaRegs.RCR1.all = 0x0;
   McbspaRegs.XCR2.all = 0x0001;  // XDATDLY = 1
   McbspaRegs.XCR1.all = 0x0;

   McbspaRegs.SRGR2.all = 0x3140;
   McbspaRegs.SRGR1.all = 0x010f;
   McbspaRegs.MCR2.all = 0x0;
   McbspaRegs.MCR1.all = 0x0;
   McbspaRegs.PCR.all = 0x0A00;

   McbspaRegs.MFFINT.bit.XINT = 1; // Enable Transmit Interrupts
   McbspaRegs.MFFINT.bit.RINT = 1; // Enable Receive Interrupts

//
// Enable Sample rate generator
//
   McbspaRegs.SPCR2.bit.GRST = 1;
   delay_loop();                   // Wait at least 2 SRG clock cycles

//
// Enable TX/RX unit
//
   McbspaRegs.SPCR2.bit.XRST = 1;
   McbspaRegs.SPCR1.bit.RRST = 1;

//
// Frame Sync generator reset
//
   McbspaRegs.SPCR2.bit.FRST = 1;
}
Ejemplo n.º 28
0
/*
 * This function is called only when the reporter thread
 * This function is the loop that the reporter thread processes
 */
void reporter_spawn( thread_Settings *thread ) {
    do {
        // This section allows for safe exiting with Ctrl-C
        Condition_Lock ( ReportCond );
        if ( ReportRoot == NULL ) {
            // Allow main thread to exit if Ctrl-C is received
            thread_setignore();
            Condition_Wait ( &ReportCond );
            // Stop main thread from exiting until done with all reports
            thread_unsetignore();
        }
        Condition_Unlock ( ReportCond );

again:
        if ( ReportRoot != NULL ) {
            ReportHeader *temp = ReportRoot;
            //Condition_Unlock ( ReportCond );
            if ( reporter_process_report ( temp ) ) {
                // This section allows for more reports to be added while
                // the reporter is processing reports without needing to
                // stop the reporter or immediately notify it
                Condition_Lock ( ReportCond );
                if ( temp == ReportRoot ) {
                    // no new reports
                    ReportRoot = temp->next;
                } else {
                    // new reports added
                    ReportHeader *itr = ReportRoot;
                    while ( itr->next != temp ) {
                        itr = itr->next;
                    }
                    itr->next = temp->next;
                }
                // finished with report so free it
                free( temp );
                Condition_Unlock ( ReportCond );
                Condition_Signal( &ReportDoneCond );
                if (ReportRoot)
                    goto again;
            }
            Condition_Signal( &ReportDoneCond );
            delay_loop(10000); //usleep ?
        } else {
            //Condition_Unlock ( ReportCond );
        }
    } while ( 1 );
}
Ejemplo n.º 29
0
void Gpio_PortF(void)
{

// GPIO Test #5: 
// Configure Upper bits [14:8] of Port F as outputs and bits [7:0] as inputs    
// Loop back bits [14:8] to bits [6:0], also loopback bit #8, to bit #7
 
    var1= 0x0000;        // sets GPIO Muxs as I/Os
    var2= 0xFF00;        // sets GPIO 14-8 DIR as outputs, 7-0 as inputs.
        
    Gpio_select();
    
    Test_status[Test_var] = 0x0007;
    Test_var++;
    
    Test_status[Test_var] = 0xD0BE;      // Set the default value of status 
                                         // to "PASSED"
    test_count = 0;
                                        
    while (test_count < 4)                  // repeat the tests 4 times
    {
       GpioDataRegs.GPFSET.all = 0xFF00;
       delay_loop();

       GpioDataRegs.GPFCLEAR.all = 0xFF00;  // Test Clear    
       asm (" RPT #6 || NOP");             
       Test_flag = GpioDataRegs.GPFDAT.all;
       if ( Test_flag != 0x0000 ) error(1);
                            
       GpioDataRegs.GPFSET.all = 0x5500;    // Test Set
       asm(" RPT #6 || NOP");                         
       Test_flag = GpioDataRegs.GPFDAT.all;
       if ( Test_flag != 0x55D5 ) error(1);
    
       GpioDataRegs.GPFTOGGLE.all = 0xFF00; // Test Toggle 
       asm(" RPT #6 || NOP");
       Test_flag = GpioDataRegs.GPFDAT.all;
       if ( Test_flag != 0x2A2A ) error(1); 
     
       test_count++; 
    
    }
    
    Test_var++;
    
} // End of Test #5
Ejemplo n.º 30
0
static void pwm_dir_a(uint16_t pwm_duty)
// Send PWM signal for rotation with the indicated pwm ratio (0 - 255).
// This function is meant to be called only by pwm_update.
{
    // Determine the duty cycle value for the timer.
    uint16_t duty_cycle = pwm_duty;

    // Disable interrupts.
    //nvic_globalirq_disable();

    // Do we need to reconfigure PWM output?
    if (!pwm_a || pwm_b)
    {

        // Disable PWM_A (PB1/OC1A) and PWM_B (PB2/OC1B) output.
        // NOTE: Actually PWM_A should already be disabled...
        pinMode(6, OUTPUT); //PA8
        pinMode(7, OUTPUT); //PA9
    
        // Yes. Make sure PB1 and PB2 are zero.
        digitalWrite(6, LOW);
        digitalWrite(7, LOW);
        
        //
        // Give the H-bridge time to respond to the above changes
        //
        delay_loop(DELAYLOOP);

        // Reset the B direction flag.
        pwm_b = 0;
    }

    // Set the A direction flag.
    pwm_a = pwm_duty;
    SerialUSB.println(pwm_a);
    // Update the PWM duty cycle.
    pinMode(6, PWM); //PA8
    pwmWrite(6, pwm_a);
    
    // Restore interrupts.
   // nvic_globalirq_enable();

    // Save the pwm A and B duty values.
    registers_write_byte(REG_PWM_DIRA, pwm_a);
    registers_write_byte(REG_PWM_DIRB, pwm_b);
}