Example #1
0
void do_sleep(int time) {

  while (time > 0) {
    if (time >= 8000) {
      setup_watchdog(9);
      system_sleep();
      time -= 8000;
    } else if (time >= 4000) {
      setup_watchdog(8);
      system_sleep();
      time -= 4000;
    } else if (time >= 2000) {
      setup_watchdog(7);
      system_sleep();
      time -= 2000;
    } else if (time >= 1000) {
      setup_watchdog(6);
      system_sleep();
      time -= 1000;
    } else if (time >= 500) {
      setup_watchdog(5);
      system_sleep();
      time -= 500;
    } else if (time >= 250) {
      setup_watchdog(4);
      system_sleep();
      time -= 250;
    } else if (time >= 128) {
      setup_watchdog(3);
      system_sleep();
      time -= 128;
    } else if (time >= 64) {
      setup_watchdog(2);
      system_sleep();
      time -= 64;
    } else if (time >= 32) {
      setup_watchdog(1);
      system_sleep();
      time -= 32;
    } else if (time >= 16) {
      setup_watchdog(0);
      system_sleep();
      time -= 16;
    } else {
      delay(time);
      time = 0;
    }
  }
}
Example #2
0
static void _sleep_entry(void)
{
	rt_tick_t timeout;
	rt_uint32_t ms;
	rt_uint32_t count;

	system_set_sleepmode(SYSTEM_SLEEPMODE_STANDBY);
	timeout = rt_timer_next_timeout_tick() - rt_tick_get();

	ms = timeout * (1000 / RT_TICK_PER_SECOND);
	rt_kprintf("os tick:%u entry sleep:%u tick\r\n", rt_tick_get(), timeout);

	_rtc_timer_start(ms);

	system_sleep();

	rt_enter_critical();
	count = rtc_count_get_count(&rtc_instance);
	ms = (count + 32) / 32.768;
	rtc_count_disable(&rtc_instance);
	sleep_tick_adjust(ms);
	timeout = rt_tick_get();
	rt_exit_critical();
	rt_kprintf("sleep exited, os tick:%u\n", timeout);
}
Example #3
0
// the loop routine runs over and over again forever:
void loop()  { 

  if (f_wdt==1) {  // wait for timed out watchdog / flag is set when a watchdog timeout occurs
    f_wdt=0;       // reset flag
    
    digitalWrite(buzzLedSw, HIGH);      // GREEN LED ON  
    _delay_ms(500);  // Switch the LED on for 0.5 Seconds

    averageSensor = analogRead(VsensePin);
    averageSensor = (averageSensor*calibrationFactor)/1024;   // This is the int of the real voltage
    serial.print("Analog Voltage reading: ");
    serial.println(averageSensor);

    digitalWrite(buzzLedSw, LOW);  // Green LED OFF 

    // Set the ports to be inputs - saves more power
    pinMode(txPin, INPUT);  
    pinMode(redled, INPUT);
    pinMode(buzzLedSw, INPUT);        // First want to read the switch
    pinMode(FETdriver, INPUT);
    
    system_sleep();  // Send the unit to sleep
    
    // Set the ports to be output again
    pinMode(rxPin, INPUT);
    pinMode(txPin, OUTPUT);  
    pinMode(redled, OUTPUT);
    pinMode(buzzLedSw, OUTPUT);        // First want to read the switch
    pinMode(FETdriver, OUTPUT);
    
  }
}
result_t handle_system_event(const char *request, size_t req_len) {

    // tokenize request message
    size_t num_tokens = 0;
    char **tokens = str_split(request, ": ", &num_tokens);

    if(num_tokens < 2) {
        fprintf(stderr, "Could not find correct number of tokens in rpc system request.");
        return FAILURE;
    }

    if(strncmp(tokens[1], ACTION_VOLUME_MUTE, sizeof(ACTION_VOLUME_MUTE)-1) == 0) {
        audio_output_mute(!audio_input_is_muted());
    } else if(strncmp(tokens[1], ACTION_VOLUME_LEVEL, sizeof(ACTION_VOLUME_LEVEL)-1) == 0) {
        if(num_tokens < 3) {
            fprintf(stderr, "Could not find correct number of tokens for rpc system request's action volume level");
            return FAILURE;
        }
            float volume_level = atoi(tokens[2])/100.0;
            volume_level = (volume_level < 0.0f) ? 0.0f : (volume_level > 1.0f) ? 1.0f : volume_level;
            audio_output_set_volume(volume_level);
    } else if(strncmp(tokens[1], ACTION_SHUT_DOWN, sizeof(ACTION_SHUT_DOWN)-1) == 0) {
        system_shutdown();
    } else if(strncmp(tokens[1], ACTION_RESTART, sizeof(ACTION_RESTART)-1) == 0) {
        system_restart();
    } else if(strncmp(tokens[1], ACTION_SLEEP, sizeof(ACTION_SLEEP)-1) == 0) {
        system_sleep();
    } else if(strncmp(tokens[1], ACTION_LOG_OUT, sizeof(ACTION_LOG_OUT)-1) == 0) {
        system_logout();
    }

    // free tokens
    free_tokens(tokens, num_tokens);
}
Example #5
0
void setup() {
    ledGreenLight(LOW);
    //attachInterrupt(pin, blink, RISING);
    system_set_sleepmode(SYSTEM_SLEEPMODE_STANDBY);
    
    	/* Goes in STANDBY sleep  */
    	system_sleep();
}
Example #6
0
/**
 * \brief This function puts the transceiver and device to sleep
 */
void sm_sleep(uint32_t interval)
{
	interval = interval * 1000;
	rtc_count_set_period(&rtc_instance, interval);
	rtc_count_enable(&rtc_instance);
	/*put the MCU in standby mode with RTC as wakeup source*/
	system_set_sleepmode(SYSTEM_SLEEPMODE_STANDBY);
	system_sleep();
}
Example #7
0
/** MAIN
 */
int main (void)
{  
   DDRB |= _BV(LED); // PBx as output

   DDRB  |= _BV(DRIVE); // PB0 as output for driving photoresistor
   PORTB |= _BV(DRIVE); // Power on photoresistor

   // configure negative input of analog comparator as AIN1 (see p124)
   // default value
   ADCSRB &= ~ _BV(ACME);

   // activate AC (def value)
   ACSR &= ~ _BV(ACD);
   // Select internal 1.1V reference
   ACSR |= _BV(ACBG);

   /** Power budget reduction */
   // Configure Power Reduction Register (See p39)
   // disable Timer1, USI
   PRR |= _BV(PRTIM1) | _BV(PRUSI);
   
   // switch Analog to Digitalconverter OFF
   ADCSRA &= ~_BV(ADEN);
   
   // enable input / Pull-Up on unconnected pins (See 10.2.6 p59)
   DDRB  &= ~ ( _BV(DDB0)   | _BV(DDB3)   | _BV(DDB5) );
   PORTB |= (  _BV(PORTB0) | _BV(PORTB3) | _BV(PORTB5) );
   
   // disable pull-up for connected pins
   PORTB &= ~ (  _BV(PORTB0) | _BV(PORTB3) );
   
   //disable all Digital Inputs (See p142, p125)
   DIDR0 &= ~ ( _BV(ADC0D) | _BV(ADC2D) | _BV(ADC3D) | _BV(ADC1D)
              | _BV(AIN1D) | _BV(AIN0D) );
   
   /** end of inits */
   sei(); // enable global interrupts

   // main loop
   while (1)
   {
      if ( ! bit_is_set (ACSR,ACO) ) {
         // ACO is not set --> dark, switch on led
         blink(LED);
      }
      else {
         // ACO is set --> light, switch off led
         PORTB &= ~ _BV(LED);
         system_sleep(WDTO_8S);
      }

   }

   return (0);
} /* main */
Example #8
0
static void worker(void* param)
{
	int i = 0;
	int n = *(int*)param + 1;

	while(i++ < n)
	{
#if defined(OS_MAC)
        system_sleep(arc4random() % 30);
#else
		system_sleep(rand() % 30);
#endif
		if(210 == atomic_increment32(&total))
		{
			printf("[%d] I'm the KING\n", n);
			assert(i == n);
			break;
		}
	}

	printf("[%d] done\n", n);
}
Example #9
0
void system_shutdown_if_enabled(void* data=nullptr)
{
    // shutdown if user initiated poweroff or system reset is allowed
    if (canShutdown())
    {
        if (SYSTEM_POWEROFF) {              // shutdown network module too.
            system_sleep(SLEEP_MODE_SOFTPOWEROFF, 0, 0, NULL);
        }
        else {
            System.reset();
        }
    }
}
Example #10
0
bool wait_flags (ata_probe_type *ata_probe, u8 flags)
{
  for (counter = WAIT_READY ; Temp>0 ; Temp-- )
  {
    if ((system_port_in_u8(ATA_STATUS_REGISTER(ata_probe->base_port)) & 
        flags) == 0)
    {
      return TRUE;
    }
    system_sleep(1); 
  }
  return FALSE;
}
Example #11
0
void http_client_test2(void)
{
	aio_worker_init();

	pthread_t thread;
	bool running = true;
	thread_create(&thread, http_server_thread, &running);

	struct http_header_t headers[3];
	headers[0].name = "User-Agent";
	headers[0].value = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0";
	headers[1].name = "Accept-Language";
	headers[1].value = "en-US,en;q=0.5";
	headers[2].name = "Connection";
	headers[2].value = "keep-alive";

	// block IO
	void *http = http_client_create("127.0.0.1", PORT, 1);
	assert(0 == http_client_get(http, "/", headers, sizeof(headers)/sizeof(headers[0]), http_client_test_onreply, NULL));
	assert(0 == http_client_get(http, "/img/bdlogo.png", headers, sizeof(headers)/sizeof(headers[0]), http_client_test_onreply, NULL));
	assert(0 == http_client_get(http, "/", NULL, 0, http_client_test_onreply, NULL));
	http_client_destroy(http);

	// AIO
	int32_t ref = 0;
	http = http_client_create("127.0.0.1", PORT, 0);
	assert(0 == http_client_get(http, "/", headers, sizeof(headers)/sizeof(headers[0]), http_client_test_onreply, &ref));
	while(1 != ref) system_sleep(1000);
	assert(0 == http_client_get(http, "/img/bdlogo.png", headers, sizeof(headers)/sizeof(headers[0]), http_client_test_onreply, &ref));
	while(2 != ref) system_sleep(1000);
	assert(0 == http_client_get(http, "/", NULL, 0, http_client_test_onreply, &ref));
	while(3 != ref) system_sleep(1000);
	http_client_destroy(http);

	running = false;
	thread_destroy(thread);
	aio_worker_cleanup();
}
Example #12
0
/** MAIN
 */
int main (void)
{
    DDRB |= _BV(LED); // PBx as output

    DDRB  |= _BV(DRIVE); // PB0 as output for driving photoresistor
    PORTB |= _BV(DRIVE); // Power on photoresistor

    // configure negative input of analog comparator as AIN1 (see p124)
    // default value
    ADCSRB &= ~ _BV(ACME);

    // activate AC (def value)
    ACSR &= ~ _BV(ACD);
    // Select internal 1.1V reference
    ACSR |= _BV(ACBG);

    /** end of inits */
    sei(); // enable global interrupts

    // main loop
    while (1)
    {
        if ( ! bit_is_set (ACSR,ACO) ) {
            // ACO is not set --> dark, switch on led
            PORTB |= _BV(LED);
            system_sleep(WDTO_8S);
        }
        else {
            // ACO is set --> light, switch off led
            PORTB &= ~ _BV(LED);
            system_sleep(WDTO_8S);
        }

    }

    return (0);
} /* main */
Example #13
0
int main(void)
{

	DDRB |= (1<<PB0);//set led OUTPUT
        DDRB &=~(1<<PB1);//set led INPUT

  	sbi(GIMSK,PCIE); // Turn on Pin Change interrupt
  	sbi(PCMSK,PCINT1); // Which pins are affected by the interrupt

	while (1 == 1)
	{
			PORTB |=(1<<PB0);
  			_delay_ms(3);

			PORTB &=~(1<<PB0);
 			system_sleep();
		}
   return 1;
}
static int dash_live_worker(const char* file, dash_playlist_t* dash)
{
    int r, type;
    int avcrecord = 0;
    int aacconfig = 0;
    uint32_t timestamp;
    uint32_t s_timestamp = 0;
    uint32_t diff = 0;
    uint64_t clock;

    flv_parser_t* parser = flv_parser_create(dash_live_onflv, dash);

    while (1)
    {
        void* f = flv_reader_create(file);

        clock = system_clock(); // timestamp start from 0
        while ((r = flv_reader_read(f, &type, &timestamp, dash->packet, sizeof(dash->packet))) > 0)
        {
			uint64_t t = system_clock();
			if (clock + timestamp > t && clock + timestamp < t + 3 * 1000)
				system_sleep(clock + timestamp - t);
			else if (clock + timestamp > t + 3 * 1000)
				clock = t - timestamp;

            timestamp += diff;
            s_timestamp = timestamp > s_timestamp ? timestamp : s_timestamp;
            r = flv_parser_input(parser, type, dash->packet, r, timestamp);
            if (0 != r)
            {
                assert(0);
                break; // TODO: handle send failed
            }
        }

        flv_reader_destroy(f);

        diff = s_timestamp + 30;
    }

    flv_parser_destroy(parser);
}
Example #15
0
int CYaoYao::List()
{
	char name[64] = {0};
	char name2[64] = {0};
	std::string indexFile, imageFile;
	sprintf(name, "index-%s", GetName());
	sprintf(name2, "image-%s", GetName());
	if(!g_config.GetConfig(name, indexFile) || !g_config.GetConfig(name2, imageFile)) // xml file
	{
		printf("joke_get: can't find %s xml file.\n", GetName());
		return ERROR_NOTFOUND;
	}

	char uri[256] = {0};
	for(int page=1; page < 4; page++)
	{
		// latest update
		snprintf(uri, sizeof(uri)-1, "http://www.yyxj8.com/yj/list_3_%d.html", page);

		std::vector<std::string> uris;
		int r = web_translate(uri, NULL, indexFile.c_str(), list_parser, &uris);
		printf("CYaoYao::List[%d] = %d.\n", page, r);
		if(0 != r)
			return r;

		Comics comics;
		for(size_t i = 0; i < uris.size(); ++i)
		{
			r = web_translate(uris[i].c_str(), NULL, imageFile.c_str(), image_parser, &comics);
			printf("CYaoYao::List[%d] get image[%s]= %d.\n", page, uris[i].c_str(), r);
		}

		// save
		r = jokedb_insert_comics(GetName(), comics);
		if(r < 0)
			printf("CYaoYao::List[%d] jokedb_insert=%d.\n", page, r);

		system_sleep(5000);
	}

	return 0;
}
Example #16
0
static uint16_t adc_get_value(void)
{
    uint16_t adc = 0xffff;

    /* Step 1: Enable ADC */
#if ADC_USE_STANDBY
    ADC->INTENSET.reg = ADC_INTENSET_RESRDY;
    /* clear pending IRQs */
    ADC->INTFLAG.reg |= ADC_INTFLAG_RESRDY;
    ADC->CTRLA.reg = ADC_CTRLA_RUNSTDBY | ADC_CTRLA_ENABLE;
    WAIT_ADC_SYNC();
    NVIC_EnableIRQ(ADC_IRQn);
#else
    ADC->CTRLA.reg = ADC_CTRLA_ENABLE;
    WAIT_ADC_SYNC();
#endif

    /* Step 2: Trigger ADC measurement */
    ADC->SWTRIG.reg = ADC_SWTRIG_START;
    WAIT_ADC_SYNC();

    /* Step 3: Get ADC value */
#if ADC_USE_STANDBY
    /* sleep during conversion */
    system_set_sleepmode(SYSTEM_SLEEPMODE_STANDBY);
    cpu_irq_enable();
    system_sleep();
    adc = ADC->RESULT.reg;
    NVIC_DisableIRQ(ADC_IRQn);
#else
    /* wait until conversion is ready */
    while (0 == (ADC->INTFLAG.reg & ADC_INTFLAG_RESRDY));
    adc = ADC->RESULT.reg;
#endif

    /* switch off ADC */
    ADC->CTRLA.reg = 0;
    WAIT_ADC_SYNC();

    return adc;
}
Example #17
0
static int STDCALL hls_server_worker(void* param)
{
	int r, type;
	time64_t clock;
	uint32_t timestamp;
	hls_playlist_t* playlist = (hls_playlist_t*)param;
	std::string file = playlist->file + ".flv";

	while (1)
	{
		void* flv = flv_reader_create(file.c_str());
		void* demuxer = flv_demuxer_create(flv_handler, playlist->hls);

		clock = 0;
		static unsigned char packet[2 * 1024 * 1024];
		while ((r = flv_reader_read(flv, &type, &timestamp, packet, sizeof(packet))) > 0)
		{
			time64_t now = time64_now();
			if (0 == clock)
			{
				clock = now;
			}
			else
			{
				if (timestamp > now - clock)
					system_sleep(timestamp - (now - clock));
			}

			assert(0 == flv_demuxer_input(demuxer, type, packet, r, timestamp));
		}

		flv_demuxer_destroy(demuxer);
		flv_reader_destroy(flv);
	}
	hls_media_destroy(playlist->hls);
	//hls_m3u8_destroy(playlist->m3u8);
	//s_playlists.erase();
	//delete playlist;
	return thread_destroy(playlist->t);
}
Example #18
0
void ieee_mainloop(void) {
  int16_t cmd = 0;

  set_error(ERROR_DOSVERSION);

  ieee_data.bus_state = BUS_IDLE;
  ieee_data.device_state = DEVICE_IDLE;
  for(;;) {
    switch(ieee_data.bus_state) {
      case BUS_SLEEP:                               /* BUS_SLEEP */
        set_atn_irq(0);
        ieee_bus_idle();
        set_error(ERROR_OK);
        set_busy_led(0);
        uart_puts_P(PSTR("ieee.c/sleep ")); set_dirty_led(1);

        /* Wait until the sleep key is used again */
        while (!key_pressed(KEY_SLEEP))
          system_sleep();
        reset_key(KEY_SLEEP);

        set_atn_irq(1);
        update_leds();

        ieee_data.bus_state = BUS_IDLE;
        break;

      case BUS_IDLE:                                /* BUS_IDLE */
        ieee_bus_idle();
        while(IEEE_ATN) {   ;               /* wait for ATN */
          if (key_pressed(KEY_NEXT | KEY_PREV | KEY_HOME)) {
            change_disk();
          } else if (key_pressed(KEY_SLEEP)) {
            reset_key(KEY_SLEEP);
            ieee_data.bus_state = BUS_SLEEP;
            break;
          } else if (display_found && key_pressed(KEY_DISPLAY)) {
            display_service();
            reset_key(KEY_DISPLAY);
          }
          system_sleep();
      }

      if (ieee_data.bus_state != BUS_SLEEP)
        ieee_data.bus_state = BUS_FOUNDATN;
      break;

      case BUS_FOUNDATN:                            /* BUS_FOUNDATN */
        ieee_data.bus_state = BUS_ATNPROCESS;
        cmd = ieee_getc();
      break;

      case BUS_ATNPROCESS:                          /* BUS_ATNPROCESS */
        if(cmd < 0) {
          uart_putc('c');
          ieee_data.bus_state = BUS_IDLE;
          break;
        } else cmd &= 0xFF;
        uart_puts_p("ATN "); uart_puthex(cmd);
        uart_putcrlf();

        if (cmd == 0x3f) {                                  /* UNLISTEN */
          if(ieee_data.device_state == DEVICE_LISTEN) {
            ieee_data.device_state = DEVICE_IDLE;
            uart_puts_p("UNLISTEN\r\n");
          }
          ieee_data.bus_state = BUS_IDLE;
          break;
        } else if (cmd == 0x5f) {                           /* UNTALK */
          if(ieee_data.device_state == DEVICE_TALK) {
            ieee_data.device_state = DEVICE_IDLE;
            uart_puts_p("UNTALK\r\n");
          }
          ieee_data.bus_state = BUS_IDLE;
          break;
        } else if (cmd == (0x40 + device_address)) {        /* TALK */
          uart_puts_p("TALK ");
          uart_puthex(device_address); uart_putcrlf();
          ieee_data.device_state = DEVICE_TALK;
          /* disk drives never talk immediatly after TALK, so stay idle
             and wait for a secondary address given by 0x60-0x6f DATA */
          ieee_data.bus_state = BUS_IDLE;
          break;
        } else if (cmd == (0x20 + device_address)) {        /* LISTEN */
          ieee_data.device_state = DEVICE_LISTEN;
          uart_puts_p("LISTEN ");
          uart_puthex(device_address); uart_putcrlf();
          ieee_data.bus_state = BUS_IDLE;
          break;
        } else if ((cmd & 0xf0) == 0x60) {                  /* DATA */
          /* 8250LP sends data while ATN is still active, so wait
             for bus controller to release ATN or we will misinterpret
             data as a command */
          while(!IEEE_ATN);
          if(ieee_data.device_state == DEVICE_LISTEN) {
            cmd = ieee_listen_handler(cmd);
            cmd_handler();
            break;
          } else if (ieee_data.device_state == DEVICE_TALK) {
            ieee_data.secondary_address = cmd & 0x0f;
            uart_puts_p("DATA T ");
            uart_puthex(ieee_data.secondary_address);
            uart_putcrlf();
            if(ieee_talk_handler() == TIMEOUT_ABORT) {
              ieee_data.device_state = DEVICE_IDLE;
            }
            ieee_data.bus_state = BUS_IDLE;
            break;
          } else {
            ieee_data.bus_state = BUS_IDLE;
            break;
          }
        } else if (ieee_data.device_state == DEVICE_IDLE) {
          ieee_data.bus_state = BUS_IDLE;
          break;
          /* ----- if we reach this, we're LISTENer or TALKer ----- */
        } else if ((cmd & 0xf0) == 0xe0) {                  /* CLOSE */
          ieee_data.secondary_address = cmd & 0x0f;
          uart_puts_p("CLOSE ");
          uart_puthex(ieee_data.secondary_address);
          uart_putcrlf();
          /* Close all buffers if sec. 15 is closed */
          if(ieee_data.secondary_address == 15) {
            free_multiple_buffers(FMB_USER_CLEAN);
          } else {
            /* Close a single buffer */
            buffer_t *buf;
            buf = find_buffer (ieee_data.secondary_address);
            if (buf != NULL) {
              buf->cleanup(buf);
              free_buffer(buf);
            }
          }
          ieee_data.bus_state = BUS_IDLE;
          break;
        } else if ((cmd & 0xf0) == 0xf0) {                  /* OPEN */
          cmd = ieee_listen_handler(cmd);
          cmd_handler();
          break;
        } else {
          /* Command for other device or unknown command */
          ieee_data.bus_state = BUS_IDLE;
        }
      break;
    }   /* switch   */
  }     /* for()    */
}
Example #19
0
File: udp.c Project: vladsor/chaos
return_type udp_send 
  (void *data, unsigned int length, socket_type *socket)
{
  u8 ethernet_address[NETWORK_ETHERNET_ADDRESS_LENGTH];
  ipc_structure_type *ethernet_structure;
  bool direct;
  network_ethernet_header_type *ethernet_header;
  ipv4_interface_type *interface;
  ipv4_header_type *ipv4_header;
  udp_header_type *udp_header;
  message_parameter_type message_parameter;

  log_print (&log_structure, LOG_URGENCY_DEBUG, "Sending UDP packet...");

  if (socket->protocol_type != IPC_IPV4_PROTOCOL_UDP)
  {
    return UDP_RETURN_INVALID_ARGUMENT;
  }

  /* First, find out how we should route this packet. */

  if (!route_find (socket->destination_address, &interface, 
                   &direct, &ethernet_structure))
  {
    return UDP_RETURN_DESTINATION_UNREACHABLE;
  }

  /* Get the ethernet address of the recipient. */

  while (!arp_ip_to_ethernet_address (socket->destination_address,
                                      ethernet_address))
  {
    log_print_formatted (&log_structure, LOG_URGENCY_DEBUG, 
                         "Sending ARP who-has for %lX on %s.", 
                         socket->destination_address,
                         interface->identification);
    arp_who_has (socket->destination_address, interface, ethernet_structure);
    system_sleep (500);
  }

  /* Now, construct the package, and send it. */

  memory_allocate ((void **) &ethernet_header, 
                   sizeof (network_ethernet_header_type) +
                   sizeof (ipv4_header_type) + sizeof (udp_header_type) +
                   length);

  ipv4_ethernet_header_create 
    (ethernet_address, interface->hardware_address,
     NETWORK_ETHERNET_PROTOCOL_IPV4, ethernet_header);

  ipv4_header = (ipv4_header_type *) &ethernet_header->data;

  ipv4_header_create (socket->destination_address, interface->ip_address,
                      IP_PROTOCOL_UDP, sizeof (udp_header_type) + length,
                      ipv4_header);

  udp_header = (udp_header_type *) &ipv4_header->data;
  udp_header_create (socket->destination_port, socket->source_port,
                     length, udp_header);
  memory_copy (&udp_header->data, data, length);

  message_parameter.protocol = IPC_PROTOCOL_ETHERNET;
  message_parameter.message_class = IPC_ETHERNET_PACKET_SEND;
  message_parameter.data = ethernet_header;
  message_parameter.length = (sizeof (network_ethernet_header_type) + 
                              sizeof (ipv4_header_type) + 
                              sizeof (udp_header_type) + length);

  ipc_send (ethernet_structure->output_mailbox_id, &message_parameter);
  
  return UDP_RETURN_SUCCESS;
}
Example #20
0
int main(void)
{
    /**
     * Initialize and configure system and generic clocks.
     * Use conf_clocks.h to configure system and generic clocks.
     */
    system_init();

    hal_if_usart_init();

    /**
     * Enable global interrupts.
     */
    system_interrupt_enable_global();

    /**
     * Initialize delay service.
     */
    delay_init();

    /* initialize timer */
    timer_init();

    /* Setup and enable generic clock source for PTC module. */
    surface_configure_ptc_clock();

    touch_time.measurement_period_ms = DEF_TOUCH_MEASUREMENT_PERIOD_MS;


    /* Initialize touchpad input parameters */
    qts_init_surface();

    qts_sensors_config();

    /*initialize event system*/
#if (DEF_SURF_LOW_POWER_SENSOR_ENABLE == 1)
    init_evsys_config();
#endif

    /* Configure System Sleep mode to STANDBY. */

    system_set_sleepmode(SYSTEM_SLEEPMODE_STANDBY);
#ifdef POWER_OPT_ENABLE
    turn_off_bod33();
    configure_power_manager();

#endif

    /* Calibration */
    qts_start();

    LOG("Hello QT6~\r\n");

    /* Appl maintains this flag,
     * marked as 1 initially to start measurement cycle.
     */
    qts_process_done = 1u;

    /* Appl maintains this flag,
     * marked as 1 initially to start measurement cycle.
     */
    touch_time.time_to_measure_touch = 1u;

    while (1) {
        /**
         * Start touch surface process
         */

#if DEF_SURF_LOW_POWER_SENSOR_ENABLE == 1
        qts_process_lp();
#else
        if (qts_process_done == 1) {
            qts_normal_process();
        }
#endif
        if (p_mutlcap_measure_data->measurement_done_touch == 1u) {
            p_mutlcap_measure_data->measurement_done_touch = 0u;
        }

        system_sleep();
    }
}
Example #21
0
void draw_default_internal_virtual_cockpit_3d (unsigned int flags)
{

	viewpoint
		vp;

	object_3d_sub_object_search_data
		search;

	object_3d_instance
		*virtual_cockpit_inst3d;


//#ifndef DEBUG_WIDEVIEW
   set_global_wide_cockpit(FALSE);
   edit_wide_cockpit = FALSE;
//#endif
	////////////////////////////////////////
	//
	// virtual cockpit viewpoint is placed at the main object origin
	//
	////////////////////////////////////////

	vp.x = 0.0;
	vp.y = 0.0;
	vp.z = 0.0;

	get_local_entity_attitude_matrix (get_gunship_entity (), vp.attitude);

	////////////////////////////////////////
	//
	// render displays onto textures (before draw 3D scenes)
	//
	////////////////////////////////////////

	if (flags & VIRTUAL_COCKPIT_UPFRONT_DISPLAY)
	{
		draw_default_upfront_display_on_texture ();
	}

	if (flags & VIRTUAL_COCKPIT_LHS_MFD_DISPLAY)
	{
		draw_default_mfd_on_texture (MFD_LOCATION_LHS);
	}

	if (flags & VIRTUAL_COCKPIT_RHS_MFD_DISPLAY)
	{
		draw_default_mfd_on_texture (MFD_LOCATION_RHS);
	}

	////////////////////////////////////////
	//
	// draw 3D scene with lighting
	//
	////////////////////////////////////////

	if (flags & (VIRTUAL_COCKPIT_COCKPIT))
	{
		set_cockpit_white_lighting (vp.attitude);

		set_3d_active_environment (main_3d_single_light_env);

		set_3d_view_distances (main_3d_single_light_env, 10.0, 0.1, 1.0, 0.0);

		realise_3d_clip_extents (main_3d_single_light_env);

		clear_zbuffer_screen ();

		if (begin_3d_scene ())
		{
			//
			// virtual cockpit
			//

			if (flags & VIRTUAL_COCKPIT_COCKPIT)
			{
				switch (get_local_entity_int_value (get_session_entity (), INT_TYPE_DAY_SEGMENT_TYPE))
				{
					////////////////////////////////////////
					case DAY_SEGMENT_TYPE_DAWN:
					////////////////////////////////////////
					{
						virtual_cockpit_inst3d = virtual_cockpit_level2_inst3d;

						break;
					}
					////////////////////////////////////////
					case DAY_SEGMENT_TYPE_DAY:
					////////////////////////////////////////
					{
						virtual_cockpit_inst3d = virtual_cockpit_level1_inst3d;

						break;
					}
					////////////////////////////////////////
					case DAY_SEGMENT_TYPE_DUSK:
					////////////////////////////////////////
					{
						virtual_cockpit_inst3d = virtual_cockpit_level2_inst3d;

						break;
					}
					////////////////////////////////////////
					case DAY_SEGMENT_TYPE_NIGHT:
					////////////////////////////////////////
					{
						virtual_cockpit_inst3d = virtual_cockpit_level3_inst3d;

						break;
					}
				}

				#if DEMO_VERSION

				virtual_cockpit_inst3d = virtual_cockpit_level1_inst3d;

				#endif

//VJ 28 is the subobject number of the pilot
				get_default_crew_viewpoint (28, virtual_cockpit_inst3d);

			   virtual_cockpit_inst3d->vp.x += BASE_DX;
			   virtual_cockpit_inst3d->vp.y += BASE_DY;
			   virtual_cockpit_inst3d->vp.z += BASE_DZ;

	   		if (get_global_wide_cockpit ())
				{
				   virtual_cockpit_inst3d->vp.x += wide_cockpit_position[wide_cockpit_nr].c.x;
				   virtual_cockpit_inst3d->vp.y += wide_cockpit_position[wide_cockpit_nr].c.y;
				   virtual_cockpit_inst3d->vp.z += wide_cockpit_position[wide_cockpit_nr].c.z;
					//VJ 050207 included head pitch in fixed view setting
					pilot_head_pitch_datum = rad ( wide_cockpit_position[wide_cockpit_nr].c.p );
				}

//use subnr to eliminate each sub_object one by one, in edit_wide_view press the end key
//				virtual_cockpit_inst3d->sub_objects[subnr].visible_object = FALSE;

				//rotor
				virtual_cockpit_inst3d->sub_objects[1].visible_object = FALSE;
				//pilots (28 is back, 29 is front)
				virtual_cockpit_inst3d->sub_objects[28].visible_object = FALSE;
				virtual_cockpit_inst3d->sub_objects[29].visible_object = FALSE;
				//wipers
				virtual_cockpit_inst3d->sub_objects[37].visible_object = FALSE;

			// don't do this because it mersses up change smade to virtual_cockpit_inst3d
			//	memcpy (&virtual_cockpit_inst3d->vp, &vp, sizeof (viewpoint));

				insert_relative_object_into_3d_scene (OBJECT_3D_DRAW_TYPE_ZBUFFERED_OBJECT, &virtual_cockpit_inst3d->vp.position, virtual_cockpit_inst3d);
			}

			//C:\gms\Razorworks\eech-new\modules\3d\3dobjbuf.c
			draw_3d_scene ();

			print_edit_wide_cockpit ();

			end_3d_scene ();
		}
	}

	////////////////////////////////////////
	//
	// draw 3D scene with lighting
	//
	////////////////////////////////////////

	if (flags & (VIRTUAL_COCKPIT_INSTRUMENT_NEEDLES | VIRTUAL_COCKPIT_INSTRUMENT_LARGE_NEEDLES))
	{
		set_cockpit_lighting (vp.attitude);

		set_3d_active_environment (main_3d_single_light_env);

		set_3d_view_distances (main_3d_single_light_env, 10.0, 0.1, 1.0, 0.0);

		realise_3d_clip_extents (main_3d_single_light_env);

//VJ#
		/*
		vp.x = wide_cockpit_position[wide_cockpit_nr].c.x;
		vp.y = wide_cockpit_position[wide_cockpit_nr].c.y;
		vp.z = wide_cockpit_position[wide_cockpit_nr].c.z;
		vp.x += dx;
		vp.y += dy;
		vp.z += dz;
		*/
		vp.x = BASE_DX;
		vp.y = BASE_DY - 0.0800;
		vp.z = BASE_DZ;

		clear_zbuffer_screen ();

		if (begin_3d_scene ())
		{
			//
			// instrument needles
			//

			if (flags & VIRTUAL_COCKPIT_INSTRUMENT_NEEDLES)
			{
				//
				// ADI slip
				//

				search.search_depth = 0;
				search.search_object = virtual_cockpit_instrument_needles_inst3d;
				search.sub_object_index = OBJECT_3D_SUB_OBJECT_APACHE_VIRTUAL_COCKPIT_ADI_SIDE_SLIP;

				if (find_object_3d_sub_object (&search) == SUB_OBJECT_SEARCH_RESULT_OBJECT_FOUND)
				{
					search.result_sub_object->relative_roll = get_default_virtual_cockpit_adi_slip_indicator_needle_value ();
				}

				//
				// airspeed
				//

				search.search_depth = 0;
				search.search_object = virtual_cockpit_instrument_needles_inst3d;
				search.sub_object_index = OBJECT_3D_SUB_OBJECT_APACHE_VIRTUAL_COCKPIT_AIRSPEED;

				if (find_object_3d_sub_object (&search) == SUB_OBJECT_SEARCH_RESULT_OBJECT_FOUND)
				{
					search.result_sub_object->visible_object = draw_virtual_cockpit_needles_on_fixed_cockpits;

					search.result_sub_object->relative_roll = get_default_virtual_cockpit_airspeed_indicator_needle_value ();
				}

				//
				// altimeter
				//

				search.search_depth = 0;
				search.search_object = virtual_cockpit_instrument_needles_inst3d;
				search.sub_object_index = OBJECT_3D_SUB_OBJECT_APACHE_VIRTUAL_COCKPIT_ALTIMETER;

				if (find_object_3d_sub_object (&search) == SUB_OBJECT_SEARCH_RESULT_OBJECT_FOUND)
				{
					search.result_sub_object->visible_object = draw_virtual_cockpit_needles_on_fixed_cockpits;

					search.result_sub_object->relative_roll = get_default_virtual_cockpit_barometric_altimeter_needle_value ();
				}

				//
				// clock
				//

				{
					float
						hours,
						minutes,
						seconds;

					//
					// only read clock values if drawing virtual cockpit needles to prevent speeding up clock debug values
					//

					if (draw_virtual_cockpit_needles_on_fixed_cockpits)
					{
						get_default_virtual_cockpit_clock_hand_values (&hours, &minutes, &seconds);
					}
					else
					{
						hours = 0.0;
						minutes = 0.0;
						seconds = 0.0;
					}

					//
					// hour hand
					//

					search.search_depth = 0;
					search.search_object = virtual_cockpit_instrument_needles_inst3d;
					search.sub_object_index = OBJECT_3D_SUB_OBJECT_APACHE_VIRTUAL_COCKPIT_CLOCK_HOUR_HAND;

					if (find_object_3d_sub_object (&search) == SUB_OBJECT_SEARCH_RESULT_OBJECT_FOUND)
					{
						search.result_sub_object->visible_object = draw_virtual_cockpit_needles_on_fixed_cockpits;

						search.result_sub_object->relative_roll = hours;
					}

					//
					// minute hand
					//

					search.search_depth = 0;
					search.search_object = virtual_cockpit_instrument_needles_inst3d;
					search.sub_object_index = OBJECT_3D_SUB_OBJECT_APACHE_VIRTUAL_COCKPIT_CLOCK_MINUTE_HAND;

					if (find_object_3d_sub_object (&search) == SUB_OBJECT_SEARCH_RESULT_OBJECT_FOUND)
					{
						search.result_sub_object->visible_object = draw_virtual_cockpit_needles_on_fixed_cockpits;

						search.result_sub_object->relative_roll = minutes;
					}

					//
					// second hand
					//

					search.search_depth = 0;
					search.search_object = virtual_cockpit_instrument_needles_inst3d;
					search.sub_object_index = OBJECT_3D_SUB_OBJECT_APACHE_VIRTUAL_COCKPIT_CLOCK_SECOND_HAND;

					if (find_object_3d_sub_object (&search) == SUB_OBJECT_SEARCH_RESULT_OBJECT_FOUND)
					{
						search.result_sub_object->visible_object = draw_virtual_cockpit_needles_on_fixed_cockpits;

						search.result_sub_object->relative_roll = seconds;
					}
				}

				memcpy (&virtual_cockpit_instrument_needles_inst3d->vp, &vp, sizeof (viewpoint));

				insert_relative_object_into_3d_scene (OBJECT_3D_DRAW_TYPE_ZBUFFERED_OBJECT, &virtual_cockpit_instrument_needles_inst3d->vp.position, virtual_cockpit_instrument_needles_inst3d);
			}

			//
			// instrument large needles
			//

			if (flags & VIRTUAL_COCKPIT_INSTRUMENT_LARGE_NEEDLES)
			{
				//
				// ADI slip
				//

				search.search_depth = 0;
				search.search_object = virtual_cockpit_instrument_large_needles_inst3d;
				search.sub_object_index = OBJECT_3D_SUB_OBJECT_APACHE_VIRTUAL_COCKPIT_ADI_SIDE_SLIP;

				if (find_object_3d_sub_object (&search) == SUB_OBJECT_SEARCH_RESULT_OBJECT_FOUND)
				{
					search.result_sub_object->relative_roll = get_default_virtual_cockpit_adi_slip_indicator_needle_value ();
				}

				//
				// airspeed
				//

				search.search_depth = 0;
				search.search_object = virtual_cockpit_instrument_large_needles_inst3d;
				search.sub_object_index = OBJECT_3D_SUB_OBJECT_APACHE_VIRTUAL_COCKPIT_AIRSPEED;

				if (find_object_3d_sub_object (&search) == SUB_OBJECT_SEARCH_RESULT_OBJECT_FOUND)
				{
					search.result_sub_object->relative_roll = get_default_virtual_cockpit_airspeed_indicator_needle_value ();
				}

				memcpy (&virtual_cockpit_instrument_large_needles_inst3d->vp, &vp, sizeof (viewpoint));

				insert_relative_object_into_3d_scene (OBJECT_3D_DRAW_TYPE_ZBUFFERED_OBJECT, &virtual_cockpit_instrument_large_needles_inst3d->vp.position, virtual_cockpit_instrument_large_needles_inst3d);
			}

			draw_3d_scene ();

			end_3d_scene ();
		}
	}

	////////////////////////////////////////
	//
	// draw 3D scene without lighting
	//
	////////////////////////////////////////

	if
	(
		(flags & VIRTUAL_COCKPIT_DISPLAY_VIEW) &&
		(flags & VIRTUAL_COCKPIT_LHS_MFD_DISPLAY) &&
		(flags & VIRTUAL_COCKPIT_RHS_MFD_DISPLAY)
	)
	{
		set_3d_active_environment (main_3d_env);

		set_3d_view_distances (main_3d_env, 10.0, 0.1, 1.0, 0.0);

		realise_3d_clip_extents (main_3d_env);

		recalculate_3d_environment_settings (main_3d_env);

		clear_zbuffer_screen ();

		if (begin_3d_scene ())
		{
			//
			// lhs mfd
			//

			memcpy (&virtual_cockpit_display_view_mfd_inst3d->vp, &vp, sizeof (viewpoint));

			insert_relative_object_into_3d_scene (OBJECT_3D_DRAW_TYPE_ZBUFFERED_OBJECT, &virtual_cockpit_display_view_mfd_inst3d->vp.position, virtual_cockpit_display_view_mfd_inst3d);

			//
			// rhs mfd
			//

			memcpy (&virtual_cockpit_display_view_mfd_inst3d->vp, &vp, sizeof (viewpoint));

			insert_relative_object_into_3d_scene (OBJECT_3D_DRAW_TYPE_ZBUFFERED_OBJECT, &virtual_cockpit_display_view_mfd_inst3d->vp.position, virtual_cockpit_display_view_mfd_inst3d);

			draw_3d_scene ();

			end_3d_scene ();
		}
	}
	else
	{
		if (flags & (VIRTUAL_COCKPIT_UPFRONT_DISPLAY | VIRTUAL_COCKPIT_LHS_MFD_DISPLAY | VIRTUAL_COCKPIT_RHS_MFD_DISPLAY))
		{
			set_3d_active_environment (main_3d_env);

			set_3d_view_distances (main_3d_env, 10.0, 0.1, 1.0, 0.0);

			realise_3d_clip_extents (main_3d_env);

			recalculate_3d_environment_settings (main_3d_env);

			clear_zbuffer_screen ();

//		vp.x = wide_cockpit_position[wide_cockpit_nr].c.x;
//		vp.y = wide_cockpit_position[wide_cockpit_nr].c.y;
//		vp.z = wide_cockpit_position[wide_cockpit_nr].c.z;

			if (begin_3d_scene ())
			{
				//
				// up-front display
				//

				vp.y = BASE_DY - 0.0800 - _DY;

				if (flags & VIRTUAL_COCKPIT_UPFRONT_DISPLAY)
				{
					vp.y -= 0.01;
					memcpy (&virtual_cockpit_upfront_display_inst3d->vp, &vp, sizeof (viewpoint));
					vp.y += 0.01;
//					virtual_cockpit_upfront_display_inst3d->vp.position.y = dy;

					insert_relative_object_into_3d_scene (OBJECT_3D_DRAW_TYPE_ZBUFFERED_OBJECT, &virtual_cockpit_upfront_display_inst3d->vp.position, virtual_cockpit_upfront_display_inst3d);
				}

				//
				// lhs mfd
				//

				if (flags & VIRTUAL_COCKPIT_LHS_MFD_DISPLAY)
				{
					memcpy (&virtual_cockpit_lhs_mfd_inst3d->vp, &vp, sizeof (viewpoint));
					//virtual_cockpit_lhs_mfd_inst3d->vp.position.x += dx;
					insert_relative_object_into_3d_scene (OBJECT_3D_DRAW_TYPE_ZBUFFERED_OBJECT, &virtual_cockpit_lhs_mfd_inst3d->vp.position, virtual_cockpit_lhs_mfd_inst3d);
				}

				//
				// rhs mfd
				//

				if (flags & VIRTUAL_COCKPIT_RHS_MFD_DISPLAY)
				{
					memcpy (&virtual_cockpit_rhs_mfd_inst3d->vp, &vp, sizeof (viewpoint));

					//virtual_cockpit_rhs_mfd_inst3d->vp.position.x -= dx;

					insert_relative_object_into_3d_scene (OBJECT_3D_DRAW_TYPE_ZBUFFERED_OBJECT, &virtual_cockpit_rhs_mfd_inst3d->vp.position, virtual_cockpit_rhs_mfd_inst3d);
				}

				draw_3d_scene ();

				end_3d_scene ();
			}
		}
	}

	////////////////////////////////////////
	//
	// draw 3D scene with lighting
	//
	////////////////////////////////////////

	//
	// draw fillet to mask TADS display
	//

	if
	(
		(d3d_can_render_to_texture) &&
		(flags & (VIRTUAL_COCKPIT_COCKPIT)) &&
		(flags & (VIRTUAL_COCKPIT_LHS_MFD_DISPLAY)) &&
		(flags & (VIRTUAL_COCKPIT_RHS_MFD_DISPLAY))
	)
	{
		set_cockpit_white_lighting (vp.attitude);

		set_3d_active_environment (main_3d_single_light_env);

		set_3d_view_distances (main_3d_single_light_env, 10.0, 0.1, 1.0, 0.0);

		realise_3d_clip_extents (main_3d_single_light_env);

		clear_zbuffer_screen ();

		if (begin_3d_scene ())
		{
			switch (get_local_entity_int_value (get_session_entity (), INT_TYPE_DAY_SEGMENT_TYPE))
			{
				////////////////////////////////////////
				case DAY_SEGMENT_TYPE_DAWN:
				////////////////////////////////////////
				{

					virtual_cockpit_inst3d = virtual_cockpit_fillet_level2_inst3d;

					break;
				}
				////////////////////////////////////////
				case DAY_SEGMENT_TYPE_DAY:
				////////////////////////////////////////
				{
					virtual_cockpit_inst3d = virtual_cockpit_fillet_level1_inst3d;

					break;
				}
				////////////////////////////////////////
				case DAY_SEGMENT_TYPE_DUSK:
				////////////////////////////////////////
				{
					virtual_cockpit_inst3d = virtual_cockpit_fillet_level2_inst3d;

					break;
				}
				////////////////////////////////////////
				case DAY_SEGMENT_TYPE_NIGHT:
				////////////////////////////////////////
				{
					virtual_cockpit_inst3d = virtual_cockpit_fillet_level3_inst3d;

					break;
				}
			}

			#if DEMO_VERSION

			virtual_cockpit_inst3d = virtual_cockpit_fillet_level1_inst3d;

			#endif
//VJ#
			vp.x = BASE_DX;
			vp.y = BASE_DY - 0.086 - _DY;
			vp.z = BASE_DZ-0.010;

			memcpy (&virtual_cockpit_inst3d->vp, &vp, sizeof (viewpoint));

			insert_relative_object_into_3d_scene (OBJECT_3D_DRAW_TYPE_ZBUFFERED_OBJECT, &virtual_cockpit_inst3d->vp.position, virtual_cockpit_inst3d);

			draw_3d_scene ();

			end_3d_scene ();
		}
	}


	//draw_default_indicator_lamps_3d ();
	//draw_default_lamp_on_texture ();

	//VJ wideview mod, date: 18-mar-03
#if DEBUG_WIDEVIEW
	if (edit_wide_cockpit)
	{
		if (check_key(DIK_NUMPAD7))
		{
			system_sleep(20);
			  dy+= 0.002;
		}
		if (check_key(DIK_NUMPAD9))
		{
			system_sleep(20);
			  dy-= 0.002;
		}
		if (check_key(DIK_NUMPADSLASH))
		{
			system_sleep(20);
			  dx+= 0.002;
		}
		if (check_key(DIK_NUMPADSTAR))
		{
			system_sleep(20);
			  dx-= 0.002;
		}
		if (check_key(DIK_NUMPADMINUS))
		{
			system_sleep(20);
			  dz+= 0.002;
		}
		if (check_key(DIK_NUMPADPLUS))
		{
			system_sleep(20);
			  dz-= 0.002;
		}
		if (check_key(DIK_END))
		{
			system_sleep (100);
				subnr++;
	   }
		if (check_key(DIK_NUMPAD0))
		{
				dx = 0;
				dy = 0;
				dz = 0;
		}
	}
#endif

	move_edit_wide_cockpit ();

	////////////////////////////////////////
	//
	// tidy up
	//
	////////////////////////////////////////

	#if RECOGNITION_GUIDE

	set_3d_view_distances (main_3d_env, 10000.0, 100.0, 1.0, 0.0);

	#else

	set_3d_view_distances (main_3d_env, 10000.0, 1.0, 1.0, 0.0);

	#endif

	realise_3d_clip_extents (main_3d_env);
}
Example #22
0
/** Send the device to deep sleep
 *
 * This processor is setup ready for deep sleep, and sent to sleep using __WFI(). This mode
 * has the same sleep features as sleep plus it powers down peripherals and clocks. All state
 * is still maintained.
 * @param[void] void
 * @return      void
 */
void deepsleep(void)
{
    system_set_sleepmode(SYSTEM_SLEEPMODE_STANDBY);
    system_sleep();
}
Example #23
0
/** Send the device to sleep
 *
 * The processor is setup ready for sleep, and sent to sleep using __WFI(). In this mode, the
 * system clock to the core is stopped until a reset or an interrupt occurs.
 * @param[void] void
 * @return      void
 */
void sleep(void)
{
    system_set_sleepmode(SYSTEM_SLEEPMODE_IDLE_2);
    system_sleep();
}