Ejemplo n.º 1
0
STOPWATCH* stopwatch_create()
{
	STOPWATCH* sw;

	sw = (STOPWATCH*) xmalloc(sizeof(STOPWATCH));
	stopwatch_reset(sw);

	return sw;
}
Ejemplo n.º 2
0
uint32_t usart_tx(usart_dev *dev, const uint8_t *buf, uint32_t len)
    {
    /* Check the parameters */
    assert_param(IS_USART_ALL_PERIPH(USARTx));
    assert_param(IS_USART_DATA(Data));

    uint32_t tosend = len;
    uint32_t sent = 0;

    if (dev->usetxrb)
	{
	while (tosend)
	    {
	    if (rb_is_full(dev->txrb))
		break;
	    rb_insert(dev->txrb, *buf++);
	    sent++;
	    tosend--;
	    }
	if (dev->txbusy == 0 && sent > 0)
	    {
	    dev->txbusy = 1;
	    USART_ITConfig(dev->USARTx, USART_IT_TXE, ENABLE);
	    }
	}
    else
	{
#if 0
	uint32_t rtime;
	if (dev->use_timeout)
	stopwatch_reset();
#endif
	while (tosend)
	    {
	    while (!(dev->USARTx->SR & USART_FLAG_TXE))
		{
#if 0
		if (dev->use_timeout)
		    {
		    rtime = stopwatch_getus();
		    if (rtime >= dev->tx_timeout)
			{
			return sent;
			}
		    }
#endif
		}
	    dev->USARTx->DR = *buf++;
	    tosend--;
	    sent++;
	    }
	}

    return sent;
    }
Ejemplo n.º 3
0
Archivo: main.c Proyecto: zcsevcik/edu
/*******************************************************************************
 * Hlavni funkce
*******************************************************************************/
int main(void)
{
  unsigned int cnt = 0;
  last_ch = 0;
  last_opto = 0;
  isrunning = 0;

  OPTO_dir_in();
  initialize_hardware();
  keyboard_init();

  set_led_d6(1);                       // rozsviceni D6
  set_led_d5(1);                       // rozsviceni D5

  //term_send_crlf();
  //term_send_str(" >");

  /* nastaveni casovace na periodu 10 ms */
  CCTL0 = CCIE;  // enable interrupt               
  CCR0 = 0x80;
  TACTL = TASSEL_1 + MC_2;

  stopwatch_reset();

  while (1)
  {
    delay_ms(1);

    cnt++;
    if (cnt >= 500)
        cnt = 0;

    if (cnt == 0)
    {
      cnt = 0;
      flip_led_d6();                   // negace portu na ktere je LED
    }

    if (cnt % 10 == 1) {
        keyboard_idle();                   // obsluha klavesnice
        terminal_idle();                   // obsluha terminalu
    }
    if (cnt % 100 == 2) {
        display_idle();
    }

    opto_idle();
  }         

  //CCTL0 &= ~CCIE;  // disable interrupt

}
Ejemplo n.º 4
0
/**
  * @brief  Main program.
  * @param  None
  * @retval : None
  */
int main(void)
{
    int i;    
    stopwatch_reset(&stopwatch);
	
    /*
     * Enable peripherals
     */
    rcc_init();
    gpio_init();
    nvic_init();
    usart_init();
    tim_init();

    delay_ms(1000);
    
	iprintf(ANSI_CLRSCR ANSI_BOLD("STM32 Stopwatch") " rev %s, built on %s.\r\n", build_git_description, build_git_time);
	iprintf("(c) Sami Kujala, 2012. https://github.com/skujala/stm32-stopwatch\r\n");
    iprintf("Initialization complete.\r\n");
    LED_GPIO->BSRR = (1 << BLUE_LED_PIN);

    
    while (1) {
        if (stopwatch.counter == COUNTER_STOPPED){
            for (i = 0; i < 10; i++) {
                LED_GPIO->ODR ^= (1 << BLUE_LED_PIN);
                delay_ms(50);                
            }
            iprintf("Elapsed time: " ANSI_BOLD("%d") " ms.\r\n", TIMER_COUNTS_IN_MS(stopwatch.counts_elapsed));
                
            stopwatch_reset(&stopwatch);
        }
    }

    return 0;
}
Ejemplo n.º 5
0
STOPWATCH* stopwatch_create()
{
	STOPWATCH* sw;
#ifdef _WIN32
	if (stopwatch_freq.QuadPart == 0) {
		QueryPerformanceFrequency(&stopwatch_freq);
	}
#endif

	sw = (STOPWATCH*) malloc(sizeof(STOPWATCH));
	if (!sw)
		return NULL;
	stopwatch_reset(sw);

	return sw;
}
Ejemplo n.º 6
0
Archivo: main.c Proyecto: zcsevcik/edu
/*******************************************************************************
 * Obsluha klavesnice
*******************************************************************************/
int keyboard_idle()
{
  char ch;
  ch = key_decode(read_word_keyboard_4x4());
  if (ch != last_ch) 
  {
    last_ch = ch;
    if (ch != 0) 
    {
      if (ch == '*') {
          stopwatch_reset();
      }
      else if (ch == '#' && isrunning) {
          stopwatch_stop();
      }
      else if (ch == '#' && !isrunning && (t == t0)) {
          stopwatch_start();
      }
    }
  }
  return 0;
}
Ejemplo n.º 7
0
int cardio_state(void){
	if(stopwatch_started_or_stopped()){
			switch(stopwatch_started()){
				case true:
					stop_stopwatch();
					break;
				case false:
					start_stopwatch();
					break;
				default:
					return -1;
			}
		}
		if(stopwatch_reset()){			
			reset_stopwatch(); 	   // Save observed values, set stopwatch to 00:00:00:00
			save_to_data();	   	   // Push observed values to datastate
			reset_observed_data(); // Reset the observed values
		}
			
	output_heartrate();
	output_stopwatch();
	
	return 0;
}
Ejemplo n.º 8
0
int
main (int argc, char **argv)
{
  char *s, *s2, *s3, *p, *p2, *p3;
  size_t slen, slen2;
  long s_size = 1234567;
  s = (char *)malloc(s_size * sizeof(char));
  assert(s);
  s2 = (char *)malloc(s_size * sizeof(char));
  assert(s2);
  s3 = (char *)malloc(s_size * sizeof(char));
  assert(s3);
  for (p = s, p2 = s2, p3 = s3; (p - s) < s_size; p++, p2++, p3++) {
    *p = ((p - s) % 26) + 'a';
    assert(*p != 0);
    *p2 = ((p2 - s2) % 26) + 'a';
    assert(*p2 != 0);
    *p3 = ((p3 - s3) % 26) + 'a';
    assert(*p3 != 0);
  }
  s[0] = '/'; s2[0] = '/'; s3[0] = '/'; //have a different zero'th elem, so that reverse search traverses the full array
  s[1] = ';'; s2[1] = ';'; s3[1] = ';';
  slen = s_size;//strlen(s);
  //s = argv[2];
  //slen = strlen(s);
  s[slen - 1] = '\0';
  s[slen - 2] = '\0';
  s[slen - 3] = '\0';
  s[slen - 4] = '\0';
  s[slen - 5] = '\0';
  s[slen - 6] = '\0';
  s[slen - 7] = '\0';
  s[slen - 8] = '\0';
  s[slen - 9] = '\0';
  s[slen - 10] = '\0';
  s[slen - 11] = '\0';
  s[slen - 12] = '\0';
  s[slen - 13] = '\0';
  s[slen - 14] = '\0';
  s[slen - 15] = '\0';
  s[slen - 16] = '\0';

  slen2 = s_size;
  s2[slen2 - 1] = '\0';
  s2[slen2 - 2] = '\0';
  s2[slen2 - 3] = '\0';
  s2[slen2 - 4] = '\0';
  s2[slen2 - 5] = '\0';
  s2[slen2 - 6] = '\0';
  s2[slen2 - 7] = '\0';
  s2[slen2 - 8] = '\0';
  s2[slen2 - 9] = '\0';
  s2[slen2 - 10] = '\0';
  s2[slen2 - 11] = '\0';
  s2[slen2 - 12] = '\0';
  s2[slen2 - 13] = '\0';
  s2[slen2 - 14] = '\0';
  s2[slen2 - 15] = '\0';
  s2[slen2 - 16] = '\0';

  struct time array_setl_timer;
  stopwatch_reset(&array_setl_timer);
  stopwatch_run(&array_setl_timer);
  int set1l = array_setl(s, s2[0], slen/4);
  stopwatch_stop(&array_setl_timer);

  printf("output = %d\n", set1l);
  printf("first 10 elems:");
  int i;
  for (i = 0; i < 10; i++) {
    printf(" %x", *((uint32_t *)&s[i]));
  }
  printf("\n");
  stopwatch_print(&array_setl_timer);
  return 0;
}
Ejemplo n.º 9
0
Archivo: main.c Proyecto: zcsevcik/edu
int stopwatch_start()
{
    stopwatch_reset();
    isrunning = 1;
}