Ejemplo n.º 1
0
/*
 * @brief: adds a servo to the active servos list
 * @param   servoNumber:   ID of the servo, from 0 to 8
 * @return: True if servo was successfully attached, False if not.
 */
static bool_t servoAttach( uint8_t servoNumber)
{
   bool_t success = FALSE;
   uint8_t position = 0;

   /* Pin must b config as Output */
   digitalConfig( servoNumber, OUTPUT );

   position = servoIsAttached(servoNumber);
   if(position==0)
   {
      position = servoIsAttached(EMPTY_POSITION); /* Searches for the first empty position */
      if(position) /* if position==0 => there is no room in the list for another servo */
      {
         AttachedServoList[position-1].servo = servoNumber;
         /* Enables the compare match interrupt */
         Timer_EnableCompareMatch( AttachedServoList[position-1].associatedTimer,
                                    AttachedServoList[position-1].associatedCompareMatch,
                                    Timer_microsecondsToTicks(valueToMicroseconds(AttachedServoList[position-1].value)),
                                    AttachedServoList[position-1].associatedFunction
                                 );
         success = TRUE;
      }
   }

   return success;
}
Ejemplo n.º 2
0
Archivo: main.c Proyecto: cpantel/ciaa
int main(void)
{
   boardConfig();

   tickConfig( 1, 0 );

   digitalConfig( 0, ENABLE_DIGITAL_IO );


   uint8_t dutyCycle = 0; /* 0 a 255 */

   analogConfig( ENABLE_ANALOG_INPUTS );

   pwmConfig( 0,     PWM_TIMERS_ENABLE );

   pwmConfig( PWM0,  PWM_OUTPUT_ENABLE );
   pwmConfig( PWM7,  PWM_OUTPUT_ENABLE );

   pwmWrite( PWM7, 0 );
   pwmWrite( PWM0, 0 );

   while(1) {
      dutyCycle = analogRead(AI1) / 4 ;
      pwmWrite( PWM7, dutyCycle );
      pwmWrite( PWM0, dutyCycle );
   }
   return 0 ;
}
Ejemplo n.º 3
0
Archivo: main.c Proyecto: elsuizo/sAPI
/* FUNCION PRINCIPAL, PUNTO DE ENTRADA AL PROGRAMA LUEGO DE RESET. */
int main(void){

   /* ------------- INICIALIZACIONES ------------- */

   /* Inicializar la placa */
   boardConfig();

   /* Inicializar el conteo de Ticks con resolución de 1ms, sin tickHook */
   tickConfig( 1, 0 );

   /* Inicializar DigitalIO */
   digitalConfig( 0, ENABLE_DIGITAL_IO );

   /* Configuración de pines de entrada para Teclas de la CIAA-NXP */
   digitalConfig( TEC1, INPUT );
   digitalConfig( TEC2, INPUT );
   digitalConfig( TEC3, INPUT );
   digitalConfig( TEC4, INPUT );

   /* Configuración de pines de salida para Leds de la CIAA-NXP */
   digitalConfig( LEDR, OUTPUT );
   digitalConfig( LEDG, OUTPUT );
   digitalConfig( LEDB, OUTPUT );
   digitalConfig( LED1, OUTPUT );
   digitalConfig( LED2, OUTPUT );
   digitalConfig( LED3, OUTPUT );

   /* Inicializar UART_USB a 115200 baudios */
   uartConfig( UART_USB, 115200 );
   
   uint8_t dato  = 0;
   uint8_t dato1 = 1;
   uint8_t dato2 = 78;
   int32_t dato3 = 1234;

   /* Buffer */
   static uint8_t uartBuff[10];
   
   uartWriteByte( UART_USB, 'h' - 32 );   /* Envía 'H' */
   uartWriteByte( UART_USB, 'A' + 32 );   /* Envía 'a' */

   /* Enviar un Enter */
   uartWriteByte( UART_USB, '\r' ); /* Envía '\r', retorno de carro */
   uartWriteByte( UART_USB, '\n' ); /* Envía '\n', nueva línea      */

   uartWriteByte( UART_USB, dato1 + 48 ); /* Envía '1' */
   uartWriteByte( UART_USB, ' ' );        /* Envía ' ' */
   uartWriteByte( UART_USB, '1' );        /* Envía '1' */
   uartWriteByte( UART_USB, 32 );         /* Envía ' ' */

   /* Convertir un número entero de 2 dígitos ASCII y enviar */
   uartWriteByte( UART_USB, (dato2/10) + 48 ); /* Envía '7' */
   uartWriteByte( UART_USB, (dato2%10) + 48 ); /* Envía '8' */

   uartWriteString( UART_USB, "\r\n" ); /* Enviar un Enter */

   uartWriteByte( UART_USB, 'H' );  /* Envía 'H' */
   uartWriteByte( UART_USB, 'o' );  /* Envía 'o' */
   uartWriteByte( UART_USB, 'l' );  /* Envía 'l' */
   uartWriteByte( UART_USB, 'a' );  /* Envía 'a' */
   uartWriteByte( UART_USB, '\r' ); /* Envía '\r', retorno de carro */
   uartWriteByte( UART_USB, '\n' ); /* Envía '\n', nueva línea      */
   
   uartWriteString( UART_USB, "Chau\r\n" ); /* Envía "Chau\r\n" */
   
   uint8_t miTexto[] = "Hola de nuevo\r\n";

   uartWriteString( UART_USB, miTexto ); /* Envía "Hola de nuevo\r\n" */
   
   miTexto[0] = 'h';
   uartWriteString( UART_USB, miTexto ); /* Envía "hola de nuevo\r\n" */

   /* Conversión de muestra entera a ascii con base decimal usando itoa() */
   itoa( dato3, uartBuff, 10 ); /* base 10 significa decimal */
   uartWriteString( UART_USB, uartBuff );

   uartWriteString( UART_USB, "\r\n" ); /* Enviar un Enter */

   /* ------------- REPETIR POR SIEMPRE ------------- */
   while(1) {

      /* Recibir byte de la UART_USB y guardarlo en la variable dato */
      dato = uartReadByte( UART_USB );
      
      /* Si el byte recibido es distinto de 0 (caracter NULL) se reenvía 
         a la UART_USB realizando un eco de lo que llega */
      if( dato ){
         uartWriteByte( UART_USB, dato );
      }

   }

   /* NO DEBE LLEGAR NUNCA AQUI, debido a que a este programa no es llamado
      por ningun S.O. */
   return 0 ;
}
Ejemplo n.º 4
0
Archivo: main.c Proyecto: elsuizo/sAPI
/* FUNCION PRINCIPAL, PUNTO DE ENTRADA AL PROGRAMA LUEGO DE RESET. */
int main(void){

   /* ------------- INICIALIZACIONES ------------- */

   /* Inicializar la placa */
   boardConfig();

   /* Inicializar el conteo de Ticks con resolución de 1ms, sin tickHook */
   tickConfig( 1, 0 );

   /* Inicializar DigitalIO */
   digitalConfig( 0, ENABLE_DIGITAL_IO );

   /* Configuración de pines de entrada para Teclas de la CIAA-NXP */
   digitalConfig( TEC1, INPUT );
   digitalConfig( TEC2, INPUT );
   digitalConfig( TEC3, INPUT );
   digitalConfig( TEC4, INPUT );

   /* Configuración de pines de salida para Leds de la CIAA-NXP */
   digitalConfig( LEDR, OUTPUT );
   digitalConfig( LEDG, OUTPUT );
   digitalConfig( LEDB, OUTPUT );
   digitalConfig( LED1, OUTPUT );
   digitalConfig( LED2, OUTPUT );
   digitalConfig( LED3, OUTPUT );

   /* Inicializar UART_USB a 115200 baudios */
   uartConfig( UART_USB, 115200 );

   /* Inicializar AnalogIO */
   /* Posibles configuraciones:
    *    ENABLE_ANALOG_INPUTS,  DISABLE_ANALOG_INPUTS,
    *    ENABLE_ANALOG_OUTPUTS, DISABLE_ANALOG_OUTPUTS
    */
   analogConfig( ENABLE_ANALOG_INPUTS );  /* ADC */
   analogConfig( ENABLE_ANALOG_OUTPUTS ); /* DAC */

   /* Configuración de estado inicial del Led */
   bool_t ledState1 = OFF;

   /* Contador */
   uint32_t i = 0;

   /* Buffer */
   static uint8_t uartBuff[10];

   /* Variable para almacenar el valor leido del ADC CH1 */
   uint16_t muestra = 0;

   /* Variables de delays no bloqueantes */
   delay_t delay1;
   delay_t delay2;

   /* Inicializar Retardo no bloqueante con tiempo en ms */
   delayConfig( &delay1, 500 );
   delayConfig( &delay2, 200 );

   /* ------------- REPETIR POR SIEMPRE ------------- */
   while(1) {

      /* delayRead retorna TRUE cuando se cumple el tiempo de retardo */
      if ( delayRead( &delay1 ) ){

         /* Leo la Entrada Analogica AI0 - ADC0 CH1 */
         muestra = analogRead( AI0 );

         /* Envío la primer parte del mnesaje a la Uart */
         uartWriteString( UART_USB, (uint8_t*)"AI0 value: " );

         /* Conversión de muestra entera a ascii con base decimal */
         itoa( muestra, uartBuff, 10 ); /* 10 significa decimal */

         /* Enviar muestra y Enter */
         uartWriteString( UART_USB, uartBuff );
         uartWriteString( UART_USB, (uint8_t*)";\r\n" );

         /* Escribo la muestra en la Salida AnalogicaAO - DAC */
         analogWrite( AO, muestra );
      }

      /* delayRead retorna TRUE cuando se cumple el tiempo de retardo */
      if ( delayRead( &delay2 ) ){
         if( ledState1 )
            ledState1 = OFF;
         else
            ledState1 = ON;
         digitalWrite( LED1, ledState1 );

         /* Si pasaron 20 delays le aumento el tiempo */
         i++;
         if( i == 20 )
            delayWrite( &delay2, 1000 );
      }

   }

   /* NO DEBE LLEGAR NUNCA AQUI, debido a que a este programa no es llamado
      por ningun S.O. */
   return 0 ;
}
Ejemplo n.º 5
0
/**
 * @brief	main routine for USBD keyboard example
 * @return	Function should not exit.
 */
int main(void)
{
	USBD_API_INIT_PARAM_T usb_param;
	USB_CORE_DESCS_T desc;
	ErrorCode_t ret = LPC_OK;
	USB_CORE_CTRL_T *pCtrl;

	/* Initialize board and chip */
	SystemCoreClockUpdate();
	Board_Init();

	/* enable clocks and pinmux */
	USB_init_pin_clk();

	/* Init EDU-CIAA GPIOs */
	ciaaIOInit();

	/* Init USB API structure */
	g_pUsbApi = (const USBD_API_T *) LPC_ROM_API->usbdApiBase;

	/* initialize call back structures */
	memset((void *) &usb_param, 0, sizeof(USBD_API_INIT_PARAM_T));
	usb_param.usb_reg_base = LPC_USB_BASE;
	usb_param.mem_base = USB_STACK_MEM_BASE;
	usb_param.mem_size = USB_STACK_MEM_SIZE;
	usb_param.max_num_ep = 2;

	/* Set the USB descriptors */
	desc.device_desc = (uint8_t *) USB_DeviceDescriptor;
	desc.string_desc = (uint8_t *) USB_StringDescriptor;

#ifdef USE_USB0
	desc.high_speed_desc = USB_HsConfigDescriptor;
	desc.full_speed_desc = USB_FsConfigDescriptor;
	desc.device_qualifier = (uint8_t *) USB_DeviceQualifier;
#else
	/* Note, to pass USBCV test full-speed only devices should have both
	 * descriptor arrays point to same location and device_qualifier set
	 * to 0.
	 */
	desc.high_speed_desc = USB_FsConfigDescriptor;
	desc.full_speed_desc = USB_FsConfigDescriptor;
	desc.device_qualifier = 0;
#endif

	/* USB Initialization */
	ret = USBD_API->hw->Init(&g_hUsb, &desc, &usb_param);
	if (ret == LPC_OK) {

		/*	WORKAROUND for artf45032 ROM driver BUG:
		    Due to a race condition there is the chance that a second NAK event will
		    occur before the default endpoint0 handler has completed its preparation
		    of the DMA engine for the first NAK event. This can cause certain fields
		    in the DMA descriptors to be in an invalid state when the USB controller
		    reads them, thereby causing a hang.
		 */
		pCtrl = (USB_CORE_CTRL_T *) g_hUsb;	/* convert the handle to control structure */
		g_Ep0BaseHdlr = pCtrl->ep_event_hdlr[0];/* retrieve the default EP0_OUT handler */
		pCtrl->ep_event_hdlr[0] = EP0_patch;/* set our patch routine as EP0_OUT handler */

		ret = Mouse_Init(g_hUsb,
							(USB_INTERFACE_DESCRIPTOR *) &USB_FsConfigDescriptor[sizeof(USB_CONFIGURATION_DESCRIPTOR)],
							&usb_param.mem_base, &usb_param.mem_size);
		if (ret == LPC_OK) {
			/*  enable USB interrrupts */
			NVIC_EnableIRQ(LPC_USB_IRQ);
			/* now connect */
			USBD_API->hw->Connect(g_hUsb, 1);
		}
	}

	
	/*
    * vvvvvvvvvvvvv ENCODER vvvvvvvvvvvvvvvv
    * 
    */

   STATES state;
   STATES nextState;

   int leftCount  = 0;
   int rightCount = 0;
   int skipCount  = 0;
   int errorCount = 0;

   digitalConfig( 0, ENABLE_DIGITAL_IO );

   digitalConfig( DIO3, INPUT );
   digitalConfig( DIO4, INPUT );

   state = ZERO_ZERO;

	while (1) {
      
      uint8_t dt = digitalRead(DIO3);
      uint8_t clk  = digitalRead(DIO4);

      if (clk && dt ) {
          nextState = ONE_ONE;
      } else if ( clk && ! dt ) {
          nextState = ZERO_ONE;
      } else if ( ! clk && dt ) {
          nextState = ONE_ZERO;
      } else if ( !clk && ! dt ) {
          nextState = ZERO_ZERO;
      }

      if (nextState == state) continue;

      switch (state) {
         case ZERO_ZERO:
            switch (nextState) {
               case ZERO_ONE: leftCount++; break;
               case ONE_ZERO: rightCount++; break;
               case ONE_ONE: skipCount++; break;
               default: errorCount++; break;
            }
         break;
         case ZERO_ONE:
            switch (nextState) {
               case ZERO_ZERO: rightCount++; break;
               case ONE_ZERO: skipCount++; break;
               case ONE_ONE: leftCount++; break;
               default: errorCount++; break;
            }
         break;

         case ONE_ZERO:
            switch (nextState) {
               case ZERO_ZERO: leftCount++; break;
               case ZERO_ONE: skipCount++; break;
               case ONE_ONE: rightCount++; break;
               default: errorCount++; break;
            }
         break;

         case ONE_ONE:
            switch (nextState) {
               case ZERO_ZERO: skipCount++; break;
               case ZERO_ONE: rightCount++; break;
               case ONE_ZERO: leftCount++; break;
               default: errorCount++; break;
            }
         break;
         default: errorCount++; break;
      }

      state = nextState;      
  
		/* Do Keyboard tasks */ 
		Mouse_Tasks(leftCount * 6, rightCount * 6);
      leftCount = 0;
      rightCount = 0;
		/* Sleep until next IRQ happens */
		__WFI();
      
      
      
	}
}
Ejemplo n.º 6
0
int main(void)
{
	   uint8_t estado = estado_R;


	   delay_t delay;


   /* ------------- INICIALIZACIONES ------------- */

   /* Inicializar la placa */
   boardConfig();

   /* Inicializar DigitalIO */
   digitalConfig( 0, INITIALIZE );

   tickConfig(1);

   /* Configuración de pines de entrada para
	   Teclas de la CIAA-NXP */
   digitalConfig( TEC1, INPUT );
   digitalConfig( TEC2, INPUT );
   digitalConfig( TEC3, INPUT );
   digitalConfig( TEC4, INPUT );

   /* Configuración de pines de salida para
	   Leds de la CIAA-NXP */
   digitalConfig( LEDR, OUTPUT );
   digitalConfig( LEDG, OUTPUT );
   digitalConfig( LEDB, OUTPUT );
   digitalConfig( LED1, OUTPUT );
   digitalConfig( LED2, OUTPUT );
   digitalConfig( LED3, OUTPUT );


   delayConfig(&delay,1);

   uartConfig( UART_USB, uint32_t baudRate );



   /* ------------- REPETIR POR SIEMPRE ------------- */
	while(1) {


		if( delayRead( &delay ) ){


			switch(estado){

					case estado_R:
								digitalWrite( LED1, 1 );
								digitalWrite( LED2, 0 );
								digitalWrite( LED3, 0 );
								delayWrite( &delay, 2000 );
								estado = estado_RA;
								break;

					case estado_RA:
								digitalWrite( LED1, 1 );
								digitalWrite( LED2, 1 );
								digitalWrite( LED3, 0 );
								delayWrite( &delay, 1000 );
								estado = estado_V;
								break;

					case estado_V:
								digitalWrite( LED1, 0 );
								digitalWrite( LED2, 0 );
								digitalWrite( LED3, 1 );
								delayWrite( &delay, 3000 );
								estado = estado_A;
								break;

					case estado_A:
								digitalWrite( LED1, 0 );
								digitalWrite( LED2, 1 );
								digitalWrite( LED3, 0 );
								delayWrite( &delay, 1000 );
								estado = estado_R;
								break;
			}

		}
	}

	/* NO DEBE LLEGAR NUNCA AQUI, debido a que a este
	   programa no es llamado por ningun S.O. */
	return 0 ;
}
Ejemplo n.º 7
0
Archivo: main.c Proyecto: elsuizo/sAPI
/* FUNCION que inicializa la placa, teclas y leds. */
static void boardAndIOConfig(void){

   /* Inicializar la placa */
   boardConfig();
   
   /* Inicializar DigitalIO */
   digitalConfig( 0, ENABLE_DIGITAL_IO );

   /* Configuración de pines de entrada para Teclas de la CIAA-NXP */
   digitalConfig( TEC1, INPUT );
   digitalConfig( TEC2, INPUT );
   digitalConfig( TEC3, INPUT );
   digitalConfig( TEC4, INPUT );

   /* Configuración de pines de salida para Leds de la CIAA-NXP */
   digitalConfig( LEDR, OUTPUT );
   digitalConfig( LEDG, OUTPUT );
   digitalConfig( LEDB, OUTPUT );
   digitalConfig( LED1, OUTPUT );
   digitalConfig( LED2, OUTPUT );
   digitalConfig( LED3, OUTPUT );

}
Ejemplo n.º 8
0
Archivo: main.c Proyecto: elsuizo/sAPI
/* FUNCION PRINCIPAL, PUNTO DE ENTRADA AL PROGRAMA LUEGO DE RESET. */
int main(void){

   /* ------------- INICIALIZACIONES ------------- */

   /* Inicializar la placa */
   boardConfig();

   /* Inicializar el conteo de Ticks con resolución de 1ms, sin tickHook */
   tickConfig( 1, 0 );

   /* Inicializar DigitalIO */
   digitalConfig( 0, ENABLE_DIGITAL_IO );

   /* Configuración de pines de entrada para Teclas de la CIAA-NXP */
   digitalConfig( TEC1, INPUT );
   digitalConfig( TEC2, INPUT );
   digitalConfig( TEC3, INPUT );
   digitalConfig( TEC4, INPUT );

   /* Configuración de pines de salida para Leds de la CIAA-NXP */
   digitalConfig( LEDR, OUTPUT );
   digitalConfig( LEDG, OUTPUT );
   digitalConfig( LEDB, OUTPUT );
   digitalConfig( LED1, OUTPUT );
   digitalConfig( LED2, OUTPUT );
   digitalConfig( LED3, OUTPUT );

   /* Inicializar UART_USB a 115200 baudios */
   uartConfig( UART_USB, 115200 );
   
   /* Estructura RTC */
   RTC_t rtc;
   
   rtc.year = 2016;
   rtc.month = 7;
   rtc.mday = 3;
   rtc.wday = 1;
   rtc.hour = 13;
   rtc.min = 17;
   rtc.sec= 0;

   bool_t val = 0;
   uint8_t i = 0;

   /* Inicializar RTC */
   val = rtcConfig( &rtc );

   delay_t delay1s;
   delayConfig( &delay1s, 1000 );
   
   delay(2000);
   
   for( i=0; i<10; i++ ){
      /* Leer fecha y hora */
      val = rtcRead( &rtc );
      /* Mostrar fecha y hora en formato "DD/MM/YYYY, HH:MM:SS" */
      showDateAndTime( &rtc );
      delay(1000);
   }
   
   rtc.year = 2016;
   rtc.month = 7;
   rtc.mday = 3;
   rtc.wday = 1;
   rtc.hour = 14;
   rtc.min = 30;
   rtc.sec= 0;
   
   /* Establecer fecha y hora */
   val = rtcWrite( &rtc );

   /* ------------- REPETIR POR SIEMPRE ------------- */
   while(1) {

      if( delayRead( &delay1s ) ){
         /* Leer fecha y hora */
         val = rtcRead( &rtc );
         /* Mostrar fecha y hora en formato "DD/MM/YYYY, HH:MM:SS" */
         showDateAndTime( &rtc );
      }

   }

   /* NO DEBE LLEGAR NUNCA AQUI, debido a que a este programa no es llamado
      por ningun S.O. */
   return 0 ;
}