예제 #1
0
void sort(void* args) {
    int value = (int) args;
    sleep_proc(value*5);
         
    sem_down(insert_sem);
    sorted[size] = value;
    size++;
    sem_up(insert_sem);
}
예제 #2
0
파일: main.c 프로젝트: Farewellly/STM32
UNS8 GetChangeStateResults(UNS8 node_id, UNS8 expected_state, unsigned long timeout_ms)
   {
   unsigned long start_time = 0;
   
   // reset nodes state
   win32test_Data.NMTable[node_id] = Unknown_state;

   // request node state
   masterRequestNodeState(&win32test_Data, node_id);
   
   start_time = uptime_ms_proc();
   while(uptime_ms_proc() - start_time < timeout_ms)
      {
      if (getNodeState(&win32test_Data, node_id) == expected_state)
         return 0;
      sleep_proc(1);   
      }
   return 0xFF;
   }
예제 #3
0
파일: main.c 프로젝트: Farewellly/STM32
UNS8 ReadSDO(UNS8 nodeId, UNS16 index, UNS8 subIndex, UNS8 dataType, void* data, UNS8* size)
   {
   UNS32 abortCode = 0;
   UNS8 res = SDO_UPLOAD_IN_PROGRESS;
   // Read SDO
   UNS8 err = readNetworkDict (&win32test_Data, nodeId, index, subIndex, dataType);
   if (err)
      return 0xFF;
   for(;;)
      {
      res = getReadResultNetworkDict (&win32test_Data, nodeId, data, size, &abortCode);
      if (res != SDO_UPLOAD_IN_PROGRESS)
         break;   
      sleep_proc(1);
      continue;
      }
   closeSDOtransfer(&win32test_Data, nodeId, SDO_CLIENT);
   if (res == SDO_FINISHED)
      return 0;
   return 0xFF;   
   }
예제 #4
0
파일: main.c 프로젝트: laszuba/binary_watch
void state_machine() {
	// Spend most of the time in sleep
	switch (current_state) {
		// LEDs off, waiting for button presses
		case SLEEPING:
			next_state = SLEEPING;
			disp_time(DISABLE);

			//TODO: Go back to sleep
			sleep_proc();
			break;

		case IDLE:
			next_state = IDLE;

			if (timeout_ticks > _LED_TIMEOUT_TICKS) {
				next_state = SLEEPING;
			}

			if (SET || MODE) next_state = WAKE;

			break;

		// LEDs on, waiting for timeout
		case WAKE:
			next_state = WAKE;
			enable_pwm();
			disp_on();

			if (!SET && !MODE) {
				next_state = IDLE;
			}

			if ((debouncer_test(SET_BTN) == LONG_PRESSED) &&
			    (debouncer_test(MODE_BTN) == LONG_PRESSED)) {
				next_state = READY_TO_SET_HOURS;
			}
			break;

		case READY_TO_SET_HOURS:
			next_state = READY_TO_SET_HOURS;
			last_set_state = FALSE;

			flash_mins();
			flash_hours();

			if (!MODE && !SET) next_state = SET_HOURS;

			break;

		// Time set mode, pressing set will increment hours up to 24, then
		// roll over, pressing mode will switch to minute set mode
		case SET_HOURS:
			next_state = SET_HOURS;

			flash_mins();

			if (debouncer_test(MODE_BTN) == DEBOUNCED) {
				next_state = READY_TO_SET_MINS;
			}

			if (debouncer_test(SET_BTN) == DEBOUNCED) {
				last_set_state = TRUE;
			}
			else if (debouncer_test(SET_BTN) == LONG_PRESSED) {
				next_state = QUICK_HOURS_INC;
			}

			if ((last_set_state == TRUE) && !SET) {
				last_set_state = FALSE;
				++my_time.hours;
			}
			break;

		case QUICK_HOURS_INC:
			next_state = QUICK_HOURS_INC;

			flash_mins();

			if (!SET) next_state = SET_HOURS;

			if (quick_inc) {
				quick_inc = FALSE;
				++my_time.hours;
			}

			break;

		case READY_TO_SET_MINS:
			next_state = READY_TO_SET_MINS;
			last_set_state = FALSE;

			flash_mins();
			flash_hours();

			if (!MODE) next_state = SET_MINS;

			break;

		// Time set mode, pressing set will increment minutes up to 59, then
		// roll over, pressing mode will exit time set mode
		case SET_MINS:
			next_state = SET_MINS;

			flash_hours();

			if (debouncer_test(MODE_BTN) == DEBOUNCED) {
				next_state = WAKE;
			}

			if (debouncer_test(SET_BTN) == DEBOUNCED) {
				last_set_state = TRUE;
			}
			else if (debouncer_test(SET_BTN) == LONG_PRESSED) {
				next_state = QUICK_MINS_INC;
			}

			if ((last_set_state == TRUE) && !SET) {
				last_set_state = FALSE;
				++my_time.mins;
			}
			break;

		case QUICK_MINS_INC:
			next_state = QUICK_MINS_INC;

			flash_hours();

			if (!SET) next_state = SET_MINS;

			if (quick_inc) {
				quick_inc = FALSE;
				++my_time.mins;
			}

			break;
		default:
			next_state = IDLE;
			break;
	}

	if (current_state != SLEEPING) {
		test_buttons();
	}

	if (next_state != current_state) {
		current_state = next_state;
	}
}