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(); } }
/*--- 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'); } } }
/* Get a frame from the camera. Serial protocol char: I */ void get_frame () { unsigned char ch; move_image((unsigned char *)DMA_BUF1, (unsigned char *)DMA_BUF2, (unsigned char *)FRAME_BUF, imgWidth, imgHeight); if (overlay_flag) { frame[9] = (framecount % 10) + 0x30; frame[8] = ((framecount/10)% 10) + 0x30; frame[7] = ((framecount/100)% 10) + 0x30; set_caption(frame, imgWidth); } output_start = (unsigned char *)JPEG_BUF; output_end = encode_image((unsigned char *)FRAME_BUF, output_start, quality, FOUR_TWO_TWO, imgWidth, imgHeight); image_size = (unsigned int)(output_end - output_start); led1_on(); framecount++; uart0SendString(imgHead); uart0SendChar((unsigned char)(image_size & 0x000000FF)); uart0SendChar((unsigned char)((image_size & 0x0000FF00) >> 8)); uart0SendChar((unsigned char)((image_size & 0x00FF0000) >> 16)); uart0SendChar(0x00); cp = (unsigned char *)JPEG_BUF; for (i=0; i<image_size; i++) { while (*pPORTHIO & 0x0001) { continue; } uart0SendChar(*cp++); } while (uart0GetChar(&ch)) { // flush input continue; } }
/*--- codigo de funciones ---*/ void Main(void) { /* Inicializa controladores */ sys_init(); // Inicializacion de la placa, interrupciones y puertos timer_init(); // Inicializacion del temporizador mybutton_init(); // inicializamos los pulsadores. Cada vez que se pulse se verá reflejado en el 8led D8Led_init(); // inicializamos el 8led /* Valor inicial de los leds */ leds_off(); led1_on(); while (1) { /* Cambia los leds con cada interrupcion del temporizador */ if (switch_leds == 1) { leds_switch(); switch_leds = 0; } comprobar_boton(); } }
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 led1_toggle() { if (led1_is_off()) led1_on(); else led1_off(); }
int uart_putchar_f(char c, FILE *stream) { led1_on(); if(c == '\n') uart_putchar_f('\r', stream); while( ! (UCSR0A & (1<<UDRE0)) ); UDR0 = c; led1_off(); return 0; }
/*--- codigo de funciones ---*/ void Main(void) { /* Inicializar controladores */ sys_init(); // Inicializacion de la placa, interrupciones y puertos timer_init(); // Inicializacion del temporizador /* Establecer valor inicial de los LEDs */ leds_off(); led1_on(); while (1); // espera }
void switchLed1() { /*TAREA 4a*/ /*El alumno/a debe completar esta funcion para que cambie el estado del led 1, si estaba encendido debera apagarlo y si esta apagado encenderlo */ if ((led_state == 1) || (led_state == 3)) led1_off(); else led1_on(); /*fin TAREA 4a*/ }
void led_on_id(unsigned char id) { switch (id) { case 1: led1_on();break; case 2: led2_on();break; case 3: led3_on();break; case 4: led4_on();break; default: led_all_off();break; } }
void *th_advert( void *arg ){ while(1){ pthread_mutex_lock( &mutex_lock ); led1_on(); radio_send( BROADCAST_ADDR, RADIO_PORT, sizeof( my_info_t ), (rf_pkt*)&my_info ); led1_off(); pthread_mutex_unlock( &mutex_lock ); sleep( ADVERT_BASE_PERIOD ); } }
/**@brief Application's BLE Stack event handler. * * @param[in] p_ble_evt Bluetooth stack event. */ static void on_ble_evt(ble_evt_t * p_ble_evt) { uint32_t err_code = NRF_SUCCESS; static uint16_t m_conn_handle = BLE_CONN_HANDLE_INVALID; switch (p_ble_evt->header.evt_id) { case BLE_GAP_EVT_CONNECTED: led_stop(); led1_on(); connected = true; m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle; // Start handling button presses //err_code = app_button_enable(); break; case BLE_GAP_EVT_DISCONNECTED: // Since we are not in a connection and have not started advertising, store bonds err_code = ble_bondmngr_bonded_masters_store(); APP_ERROR_CHECK(err_code); led1_off(); connected = false; // Go to system-off mode, should not return from this function, wakeup will trigger // a reset. //system_off_mode_enter(); break; case BLE_GAP_EVT_SEC_PARAMS_REQUEST: err_code = sd_ble_gap_sec_params_reply(m_conn_handle, BLE_GAP_SEC_STATUS_SUCCESS, &m_sec_params); break; case BLE_GAP_EVT_TIMEOUT: if (p_ble_evt->evt.gap_evt.params.timeout.src == BLE_GAP_TIMEOUT_SRC_ADVERTISEMENT) { led_stop(); //system_off_mode_enter(); } break; default: break; } APP_ERROR_CHECK(err_code); }
void timer2_ISR(void) { if (row) { led1_on(); DelayMs(30); led1_off(); } else { led2_on(); DelayMs(30); led2_off(); } rI_ISPC = BIT_TIMER2; }
int main(void) { gpbcon = (led1_out | led2_out | led3_out | led4_out); while(1) { delay(30000); led1_on(); delay(30000); led1_off(); } return 0; }
/*--- codigo de funciones ---*/ void Main(void) { /* Inicializar controladores */ sys_init(); // Inicializacion de la placa, interrupciones y puertos // Inicializacion del temporizador D8Led_init(); Eint4567_init(); // Inicialización del teclado matricial keyboard_init(); timers_init(); /* Establecer valor inicial de los LEDs */ leds_off(); led1_on(); while(1); // espera }
/********************************************************************************************* * 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(); }
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; }
void main( void ) { // Stop watchdog timer to prevent time out reset WDTCTL = WDTPW + WDTHOLD; button_init(); led_init(); Clock_Init(); NRF24L01_init(1,1); NRF24L01_ConfigMode(MODETX); NRF24L01_TxPacket(temp); NRF24L01_ConfigMode(MODERX); while(1) { LPM3; //SMG_Display(rece_buf[0]); led1_on(0); Delay_ms(300); led1_off(0); Delay_ms(300); } }
int main(void) { (RCC->AHBENR |= RCC_AHBENR_GPIOAEN); (RCC->AHBENR |= RCC_AHBENR_GPIOBEN); // initialize ringbuffer for received packets packet_queue_init(); switch_init(); led_init(); board_uart0_init(); //uart_init wird von syscalls schon vorher aufgerufen - hoffentlich zumindest //<just for debug> // GPIO_9 SW1 // GPIO_10 SW2 // GPIO_11 SW4 // GPIO_12 nRF-IRQ gpio_init_int(GPIO_9, GPIO_PULLDOWN, GPIO_FALLING, (void *)test, 0); //wird extern auf high gezogen gpio_irq_enable(GPIO_9); led1_on(); // </just for debug> // initialize radio driver radio_nrf_init(); radio_nrf_register_rx_callback(packet_received); //eeprom_init(); // TODO get node address from eeprom // if not available, go through algorithm to determine new address: // 1. generate randomly address of length 11 bit // 2. send PING with generated address // 3. wait X seconds for answer (ping_answer) // 4. if no answer received, accept address and save it // 5. if an answer is received, start over with 1. // (or determine another address on another way) // while (1) { // we can go to sleep here // THIS DOES NOT WAKE UP! // (if needed, thread has to be woken up externally) thread_sleep(); } return 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(); }
void optriac_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) { const char *type = NULL; const char *mode = NULL; static char namea[17]="Triac-a"; static char nameb[17]="Triac-b"; char temp[100]; int index = 0; size_t len = 0; uint8_t triac = 0; int success = 1; switch(REST.get_method_type(request)){ case METHOD_GET: // jSON Format index += sprintf(temp + index,"{\n \"%s\" : ",namea); if(optriac_sensor.value(OPTRIAC_SENSOR_A) == 0) index += sprintf(temp + index,"\"off\",\n"); if(optriac_sensor.value(OPTRIAC_SENSOR_A) == 1) index += sprintf(temp + index,"\"on\",\n"); index += sprintf(temp + index," \"%s\" : ",nameb); if(optriac_sensor.value(OPTRIAC_SENSOR_B) == 0) index += sprintf(temp + index,"\"off\"\n"); if(optriac_sensor.value(OPTRIAC_SENSOR_B) == 1) index += sprintf(temp + index,"\"on\"\n"); index += sprintf(temp + index,"}\n"); len = strlen(temp); memcpy(buffer, temp,len ); REST.set_header_content_type(response, REST.type.APPLICATION_JSON); REST.set_response_payload(response, buffer, len); break; case METHOD_POST: success = 0; break; case METHOD_PUT: if ((len=REST.get_query_variable(request, "type", &type))) { PRINTF("type %.*s\n", len, type); if (strncmp(type, "a", len)==0) { triac = OPTRIAC_SENSOR_A; } else if(strncmp(type,"b", len)==0) { triac = OPTRIAC_SENSOR_B; } else { triac = OPTRIAC_SENSOR_A; } } else { success = 0; } if (success && (len=REST.get_post_variable(request, "mode", &mode))) { PRINTF("mode %s\n", mode); if (strncmp(mode, "on", len)==0) { led1_on(); // Debug optriac_sensor.configure(triac,1); } else if (strncmp(mode, "off", len)==0) { optriac_sensor.configure(triac,0); led1_off(); // Debug } else { success = 0; } } else { success = 0; } break; default: success = 0; } if (!success) { REST.set_response_status(response, REST.status.BAD_REQUEST); } }
void led1_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) { char mode[10]; static uint8_t led1 = 0; static char name[17]="led1"; int success = 1; char temp[100]; int index = 0; size_t len = 0; const char *pmode = NULL; const char *pname = NULL; switch(REST.get_method_type(request)){ case METHOD_GET: // jSON Format index += sprintf(temp + index,"{\n \"name\" : \"%s\",\n",name); if(led1 == 0) index += sprintf(temp + index," \"mode\" : \"off\"\n"); if(led1 == 1) index += sprintf(temp + index," \"mode\" : \"on\"\n"); index += sprintf(temp + index,"}\n"); len = strlen(temp); memcpy(buffer, temp,len ); REST.set_header_content_type(response, REST.type.APPLICATION_JSON); REST.set_response_payload(response, buffer, len); break; case METHOD_POST: success = 0; break; case METHOD_PUT: if (success && (len=REST.get_post_variable(request, "mode", &pmode))) { PRINTF("name %s\n", mode); memcpy(mode, pmode,len); mode[len]=0; if (!strcmp(mode, "on")) { led1_on(); led1 = 1; } else if (!strcmp(mode, "off")) { led1_off(); led1 = 0; } else { success = 0; } } else if (success && (len=REST.get_post_variable(request, "name", &pname))) { PRINTF("name %s\n", name); memcpy(name, pname,len); name[len]=0; } else { success = 0; } break; default: success = 0; } if (!success) { REST.set_response_status(response, REST.status.BAD_REQUEST); } }
void uart_putdata(uint8_t *data, uint8_t count) { int i; led1_on(); for(i=0; i<count; i++) uart_putchar(data[i]); led1_off(); }
void uart_putchar(uint8_t c) { led1_on(); while( ! (UCSR0A & (1<<UDRE0)) ); UDR0 = c; led1_off(); }
int main() { unsigned char ch = '\0'; static char lastcommand[CFG_CBSIZE] = { 0, }; int flag = 0; int i = 0; clock_init(); led1_on(); //init_baudrate(); led2_on(); //clock_init(); initUART(); /* serial_putc('c'); serial_putc('d'); serial_putc('o'); printf("11 is %d\n", 11); */ printf("xyz.blk cblk is \n"); run_command ("download", 0); int len = 0; for (;;) { len = readline (CFG_PROMPT); if (len > 0) strcpy(lastcommand, console_buffer); if (len == -1) puts ("<INTERRUPT>\n"); else run_command (lastcommand, flag); } //printf1("code\n"); //printf1("11.1 is %s\n", "kdh"); /* ch = '\n'; serial_putc(ch/10+'0'); serial_putc(ch%10+'0'); serial_putc(' '); */ //nand_init(); /* unsigned char data[2049] = {0}; nand_read( &data[0], 0, 2048); for ( i = 0; i < 20; i++ ) { ch = data[i]; serial_putc(ch/16 >= 10 ? ch/16 - 10 +'A' : ch/16+'0'); serial_putc(ch%16 >= 10 ? ch%16 - 10 +'A' : ch%16+'0'); serial_putc(' '); } */ /* LED1_ON(); init_baudrate(); clock_init(); initUART(); serial_putc('c'); serial_putc('o'); serial_putc('d'); serial_putc('e'); serial_putc('\n'); serial_putc('\n'); ch = '\n'; serial_putc(ch/10+'0'); serial_putc(ch%10+'0'); serial_putc(' '); delay(800000); LED1_OFF(); */ //printf1("pclk scale is %d\n", get_PCLK()); while(1) { ch = serial_getc(); //if (ch <= '9' && ch >= '0') if (ch == '\r') ch = '\n'; serial_putc(ch); }; return 0; };