Пример #1
0
int main(void)
{
	int i;

	system_init();
	p_init();
	led_init();
	cdcacm_init();
	cdcacm_register_receive_callback(cdcacm_input_callback);
	usart_init();

	led1_on();
	led2_on();
	led3_on();
	led4_on();
	led5_on();

	for (i = 0; i < 0x800000; i++)
		__asm__("nop");

	led1_off();
	led2_off();
	led3_off();
	led4_off();
	led5_off();

	while (1) {
		cdcacm_run();
		led_process();
	}
}
Пример #2
0
void led2_toggle()
{
    if (led2_is_off())
        led2_on();
    else
        led2_off();
}
Пример #3
0
Файл: main.c Проект: huig-/SED
/*--- codigo de la funcion ---*/
int Main(void){

	char *pt_str = str;
	leds_off();
	sys_init(); // inicializacion de la placa, interrupciones, puertos
	Eint4567_init();
	keyboard_init();
	Uart_Init(115200); // inicializacion de la Uart
	Uart_Config(); // configuración de interrupciones y buffers

	while(1){
		*pt_str = Uart_Getch1(); // leer caracter
		if(pt_str[0] == 'L'){
			led1_on();
			led2_off();
		} else if (pt_str[0] == 'R'){
			led2_on();
			led1_off();
		}

		else  {
			D8Led_symbol(pt_str[0]-'0');
		}
	}
}
Пример #4
0
int
main(int argc, char *argv[])
{
    /* Initialize board-specific hardware */
    BSP_Init();
    led1_off();
    led2_off();

#if 1
    /* Initialize TimerA and oscillator */
    BCSCTL3 |= LFXT1S_2;                      // LFXT1 = VLO
    TACCTL0 = CCIE;                           // TACCR0 interrupt enabled
    TACCR0 = 12000;                           // ~1 second
    TACTL = TASSEL_1 + MC_1;                  // ACLK, upmode
#endif

    while (1)
    {
        main_init();

        while (1)
        {
            main_task();
        }
    }

    return 0;
}
Пример #5
0
int led_task(void)
{
	DCC_LOG1(LOG_TRACE, "[%d] started.", thinkos_thread_self());

	while (1) {
		DCC_LOG(LOG_MSG, "thinkos_flag_wait()...");
		thinkos_flag_wait(led_flag);
		if (led1_flash_tail != led1_flash_head) {
			led1_flash_tail++;
			if (!led_locked)
				led1_on();
		}
		if (led2_flash_tail != led2_flash_head) {
			led2_flash_tail++;
			if (!led_locked)
				led2_on();
		}

		if ((led1_flash_tail == led1_flash_head) &&
			(led2_flash_tail == led2_flash_head)) 
			thinkos_flag_clr(led_flag);

		thinkos_sleep(100);
		if (!led_locked) {
			led1_off();
			led2_off();
		}
		thinkos_sleep(100);
	}
}
void led_off_id(unsigned char id)
{
	switch (id)
	{
		case 1: led1_off();break;
		case 2: led2_off();break;
		case 3: led3_off();break;
		case 4: led4_off();break;
		default: led_all_off();break;
	}
}
Пример #7
0
void switchLed2() {
/*TAREA 4b*/
/*El alumno/a debe completar esta funcion para que cambie el estado del led 2, 
si estaba encendido debera apagarlo
y si esta apagado encenderlo */
	if ((led_state == 2) || (led_state == 3))
		led2_off();
	else
		led2_on();
/*fin TAREA 4b*/
}
Пример #8
0
Файл: timer.c Проект: huig-/SED
void timer2_ISR(void)
{
	if (row) {
	    led1_on();
	    DelayMs(30);
	    led1_off();
	}
	else {
	    led2_on();
	    DelayMs(30);
	    led2_off();
	}
	rI_ISPC = BIT_TIMER2;
}
Пример #9
0
/*********************************************************************************************
* name:		Led_Test
* func:		leds test funciton
* para:		none
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void Led_Test()
{
	/* 1 on -> 2 on -> all on -> 2 off -> 1 off */
	leds_off();
	Delay(1000);
	led1_on();
	Delay(1000);
	led1_off();
	led2_on();
	Delay(1000);
	leds_on();
	Delay(1000);
	led2_off();
	Delay(1000);
	led1_off();
}
Пример #10
0
static int led_ioctl(struct inode *i, struct file *f, unsigned int cmd, unsigned long arg)
{
    printk("FUN %s is calling\n", __func__);

    if (cmd == LED1) {
        if (arg == ON) {
            led1_on();
        } else if(arg == OFF) {
            led1_off();   
        }
    }

    if (cmd == LED2) {
        if (arg == ON) {
            led2_on();
        } else if(arg == OFF) {
            led2_off();   
        }
    }

    if (cmd == LED3) {
        if (arg == ON) {
            led3_on();
        } else if(arg == OFF) {
            led3_off();   
        }
    }

    if (cmd == LED4) {
        if (arg == ON) {
            led4_on();
        } else if(arg == OFF) {
            led4_off();   
        }
    }

    return 0;
}
Пример #11
0
PROCESS_THREAD(rest_server_example, ev, data)
{
  static struct etimer ds_periodic_timer;
  static int ext4=0;
  static int ext5=0;
  static int ext6=0;
//  ext4 = is_button_ext4();
//  ext5 = is_button_ext5();
//  ext6 = is_button_ext6();
  
	  
  PROCESS_BEGIN();
  PRINTF("Starting Erbium Example Server\n");

#ifdef RF_CHANNEL
  PRINTF("RF channel: %u\n", RF_CHANNEL);
#endif
#ifdef IEEE802154_PANID
  PRINTF("PAN ID: 0x%04X\n", IEEE802154_PANID);
#endif

  PRINTF("uIP buffer: %u\n", UIP_BUFSIZE);
  PRINTF("LL header: %u\n", UIP_LLH_LEN);
  PRINTF("IP+UDP header: %u\n", UIP_IPUDPH_LEN);
  PRINTF("REST max chunk: %u\n", REST_MAX_CHUNK_SIZE);

/* if static routes are used rather than RPL */
#if !UIP_CONF_IPV6_RPL && !defined (CONTIKI_TARGET_MINIMAL_NET) && !defined (CONTIKI_TARGET_NATIVE)
  set_global_address();
  configure_routing();
#endif

  /* Initialize the OSD Hardware. */
  hw_init();
  /* Initialize the REST engine. */
  rest_init_engine();

  /* Activate the application-specific resources. */
  rest_activate_resource(&resource_led1);
  rest_activate_resource(&resource_extbutton);
#if REST_RES_INFO
  rest_activate_resource(&resource_info);
#endif
  /* Activate the application-specific resources. */
#if REST_RES_OPTRIAC
  SENSORS_ACTIVATE(optriac_sensor);
  rest_activate_resource(&resource_optriac);
#endif
#if defined (PLATFORM_HAS_PIR) && (REST_RES_EVENT)
  SENSORS_ACTIVATE(pir_sensor);
  rest_activate_event_resource(&resource_pir);
  PRINTF("ACTIVATE PIR\n");
#endif
#if defined (PLATFORM_HAS_LEDS)
#if REST_RES_LEDS
  rest_activate_resource(&resource_leds);
#endif
#if REST_RES_TOGGLE
  rest_activate_resource(&resource_toggle);
#endif
#endif /* PLATFORM_HAS_LEDS */
#if defined (PLATFORM_HAS_TEMPERATURE) && REST_RES_TEMPERATURE
  SENSORS_ACTIVATE(temperature_sensor);
  rest_activate_resource(&resource_temperature);
#endif
#if defined (PLATFORM_HAS_BATTERY) && REST_RES_BATTERY
  SENSORS_ACTIVATE(battery_sensor);
  rest_activate_resource(&resource_battery);
#endif

  etimer_set(&ds_periodic_timer, MESURE_INTERVAL);
  /* Define application-specific events here. */
  while(1) {
    PROCESS_WAIT_EVENT();
#if defined (REST_RES_EVENT)
    if (ev == sensors_event ) {
      PRINTF("EVENT\n");
#if (REST_RES_EVENT && defined (PLATFORM_HAS_PIR))
    if (data == &pir_sensor) {
      PRINTF("PIR EVENT\n");
        /* Call the event_handler for this application-specific event. */
        pir_event_handler(&resource_pir);
        PRINTF("CALL EVENT HANDLER\n");
      }
#endif /* PLATFORM_HAS_PIR */
    }
#endif /* REST_RES_EVENT */
    /* Button Tric Logic */
    if(etimer_expired(&ds_periodic_timer)) {
        PRINTF("Periodic %d %d\n",ext5,ext6);
	if(ext5 != is_button_ext5()) {
	  ext5 = is_button_ext5();
          PRINTF("Toggle Triac A\n");
          // Toggle Triac A
          if(optriac_sensor.value(OPTRIAC_SENSOR_A) == 0){
            optriac_sensor.configure(OPTRIAC_SENSOR_A,1);
            led1_on();
          }else{
            optriac_sensor.configure(OPTRIAC_SENSOR_A,0);
            led1_off();
          }
	}
	if(ext6 != is_button_ext6()) {
	  ext6 = is_button_ext6();
          PRINTF("Toggle Triac B\n");
          // Toggle Triac B
          if(optriac_sensor.value(OPTRIAC_SENSOR_B) == 0){
            optriac_sensor.configure(OPTRIAC_SENSOR_B,1);
            led2_on();
          }else{
            optriac_sensor.configure(OPTRIAC_SENSOR_B,0);
            led2_off();
          }
	}
      etimer_reset(&ds_periodic_timer);
    }
  } /* while (1) */

  PROCESS_END();
}
// ****************
int main(void) {
	
	// Setup SysTick Timer to interrupt at 10 msec intervals
	if (SysTick_Config(SystemCoreClock / 100)) {
	    while (1);  // Capture error
	}

	led_init();	// Setup GPIO for LED2
	led_on(0);		// Turn LED2 on
	//led_on(0);
	//led_on(1);

	systick_delay(100);
	led_off(0);


	UARTInit(0, 115200); // baud rate setting
	UARTInit(2, 9600);	 // baud rate setting, PC
	UARTSendCRLF(0);
	UARTSendCRLF(0);
	UARTSendStringln(0, "UART2 online ...");

	drs155m_init();

	logger_setEnabled(1);
	logger_logStringln("logger online ...");
	logger_logString("BUILD ID: ");
	logger_logStringln(VERSION_BUILD_ID);
	led_off(7);

	uint16_t loop_count = 0;
	uint8_t do_start = 0;

#define METER_COUNT 4

	uint8_t error_count[METER_COUNT] = {0,0,0};

	uint8_t current_meter_index = 0;


	drs155m_t power_meters[METER_COUNT];
	power_meters[0].meter_id = "001511420141";
	power_meters[1].meter_id = "001511420142";
	power_meters[2].meter_id = "001511420143";
	power_meters[3].meter_id = "001511420149";

	drs155m_t* current_power_meter = &power_meters[0];

	uint32_t delay_value = 0;

	while(1) {

		/* process logger */
		if (console_out_dataAvailable() && UARTTXReady(0)) {
			uint8_t iCounter;
			// fill transmit FIFO with 14 bytes
			for(iCounter = 0; iCounter < 14 && console_out_dataAvailable(); iCounter++) {
				UARTSendByte(0, console_out_read());
			}
		}

		led_process(msTicks);

		s0_process(msTicks);

		drs155m_process(msTicks);

		uint32_t triggerValue = s0_triggered(0);
		if (triggerValue) {
			logger_logString("s0_0:");
			logger_logNumberln(triggerValue);
			led_signal(1, 30, msTicks);
			if (do_start) {
				do_start = 0;
			}
			else {
				do_start = 1;
			}
		}

		if (drs155m_is_ready() && do_start && math_calc_diff(msTicks, delay_value) > 20) {
			loop_count++;
			current_meter_index++;
			if (current_meter_index >= METER_COUNT) {
				current_meter_index = 0;
			}
			current_power_meter = &power_meters[current_meter_index];
			drs155m_request_data(current_power_meter);
		}

		if (drs155m_is_data_available()) {
			logger_logStringln("Meter data: ");
			logger_logNumberln(current_power_meter->voltage);
			logger_logNumberln(current_power_meter->ampere);
			logger_logNumberln(current_power_meter->frequency);
			logger_logNumberln(current_power_meter->active_power);
			logger_logNumberln(current_power_meter->reactive_power);
			logger_logNumberln(current_power_meter->total_energy);
			logger_logString("operation took ");
			logger_logNumber(drs155m_get_duration());
			logger_logStringln(" ticks");
			logger_logString("current loop: ");
			logger_logNumberln(loop_count);
			logger_logString("error count 0: ");
			logger_logNumberln(error_count[0]);
			logger_logString("error count 1: ");
			logger_logNumberln(error_count[1]);
			logger_logString("error count 2: ");
			logger_logNumberln(error_count[2]);
			logger_logString("error count 3: ");
			logger_logNumberln(error_count[3]);
			drs155m_reset();
			delay_value = msTicks;
		}

		if (drs155m_is_error()) {
			logger_logStringln("error reading meter data");
			error_count[current_meter_index]++;
			drs155m_reset();
			delay_value = msTicks;
		}

		triggerValue = s0_triggered(1);
		if (triggerValue) {
			logger_logString("s0_1:");
			logger_logNumberln(triggerValue);
			led_signal(2, 30, msTicks);
		}


		/* logger echo */
		if ( UART0Count != 0 ) {
			led2_on();
			LPC_UART0->IER = IER_THRE | IER_RLS;				/* Disable RBR */

			int i = 0;
			for(; i < UART0Count; i++) {
				logger_logByte(UART0Buffer[i]);
			}
			UART0Count = 0;
			LPC_UART0->IER = IER_THRE | IER_RLS | IER_RBR;		/* Re-enable RBR */
			led2_off();
		}



	}
	return 0 ;
}
Пример #13
0
// ****************
int main(void) {
	
	// Setup SysTick Timer to interrupt at 10 msec intervals
	if (SysTick_Config(SystemCoreClock / 100)) {
	    while (1);  // Capture error
	}

	led_init();	// Setup GPIO for LED2
	led2_on();		// Turn LED2 on
	//led_on(0);
	//led_on(1);

	systick_delay(100);
	led2_off();
	systick_delay(100);
	led2_on();


	UARTInit(0, 115200);	/* baud rate setting */
	UARTSendCRLF(0);
	UARTSendCRLF(0);
	UARTSendStringln(0, "UART2 online ...");

	//EINT3_init();





	// Enter an infinite loop, just incrementing a counter and toggling leds every second
	//led2_off();
	//int ledstate;


	//EINT3_enable();
	logger_logStringln("logger online ...");
	while(1) {

		/* process logger */
		if (logger_dataAvailable() && UARTTXReady(0)) {
			uint8_t data = logger_read();
			UARTSendByte(0,data);
		}

		process_leds(msTicks);

		process_s0(msTicks);

		uint32_t triggerValue = s0_triggered(0);
		if (triggerValue) {
			logger_logString("s0_0:");
			logger_logNumberln(triggerValue);
			led_signal(0, 30, msTicks);
		}

		triggerValue = s0_triggered(1);
		if (triggerValue) {
			logger_logString("s0_1:");
			logger_logNumberln(triggerValue);
			led_signal(1, 30, msTicks);
		}


		/*
		if (!s0_active) {
			s0_newState = ~LPC_GPIO0->FIOPIN & (S0_INPUT0 | S0_INPUT1);
			if (s0_oldState != s0_newState) {
				s0_active = 1;
				s0_msticks = msTicks;
			}
		}

		if (s0_active && s0_msticks != msTicks) {
			s0_state = ~LPC_GPIO0->FIOPIN & (S0_INPUT0 | S0_INPUT1 );
			logger_logNumberln(s0_state);
			if (s0_state == s0_newState) {
				// falling edge
				if ((s0_newState & S0_INPUT0) > 0) {
					led2_invert();
				}

				// rising edge
				if ((s0_newState & S0_INPUT1) == 0) {
					led2_invert();
				}

			}
			s0_oldState = s0_state;
			s0_active = 0;
		}
		 */
	}
	return 0 ;
}