Exemple #1
0
static u8 braking_action(pt_t* pt, void* args)
{
	frame_t fr;

	PT_BEGIN(pt);

	// signal braking state
	PT_WAIT_UNTIL(pt, frame_set_2(&fr, DPT_SELF_ADDR, DPT_SELF_ADDR, FR_STATE, 0, FR_STATE_SET, FR_STATE_BRAKING)
			&& OK == FIFO_put(&MNT.out_fifo, &fr)
	);

	// cmde cone stop
	PT_WAIT_UNTIL(pt, frame_set_2(&fr, DPT_SELF_ADDR, DPT_SELF_ADDR, FR_MINUT_SERVO_CMD, 0, FR_SERVO_CONE, FR_SERVO_OFF)
			&& OK == FIFO_put(&MNT.out_fifo, &fr)
	);

	// cmde aero open
	PT_WAIT_UNTIL(pt, frame_set_2(&fr, DPT_SELF_ADDR, DPT_SELF_ADDR, FR_MINUT_SERVO_CMD, 0, FR_SERVO_AERO, FR_SERVO_OPEN)
			&& OK == FIFO_put(&MNT.out_fifo, &fr)
	);

	// time-out 0.1s
	MNT.time_out = TIME_get() + 100 * TIME_1_MSEC;

	PT_YIELD_WHILE(pt, OK);

	PT_END(pt);
}
Exemple #2
0
static u8 cone_closed_action(pt_t* pt, void* args)
{
	frame_t fr;

	PT_BEGIN(pt);

	// signal cone closed state
	PT_WAIT_UNTIL(pt, frame_set_2(&fr, DPT_SELF_ADDR, DPT_SELF_ADDR, FR_STATE, 0, FR_STATE_SET, FR_STATE_CONE_CLOSED)
			&& OK == FIFO_put(&MNT.out_fifo, &fr)
	);

	// cmde cone close
	PT_WAIT_UNTIL(pt, frame_set_2(&fr, DPT_SELF_ADDR, DPT_SELF_ADDR, FR_MINUT_SERVO_CMD, 0, FR_SERVO_CONE, FR_SERVO_CLOSE)
			&& OK == FIFO_put(&MNT.out_fifo, &fr)
	);

	// time-out 1s
	MNT.time_out = TIME_get() + 1 * TIME_1_SEC;

	// led alive 0.1s
	PT_WAIT_UNTIL(pt, frame_set_3(&fr, DPT_SELF_ADDR, DPT_SELF_ADDR, FR_LED_CMD, 0, FR_LED_ALIVE, FR_LED_SET, 10)
			&& OK == FIFO_put(&MNT.out_fifo, &fr)
	);

	// led open off 0.0s
	PT_WAIT_UNTIL(pt, frame_set_3(&fr, DPT_SELF_ADDR, DPT_SELF_ADDR, FR_LED_CMD, 0, FR_LED_OPEN, FR_LED_SET, 0)
			&& OK == FIFO_put(&MNT.out_fifo, &fr)
	);

	PT_YIELD_WHILE(pt, OK);

	PT_END(pt);
}
Exemple #3
0
static u8 flight_action(pt_t* pt, void* args)
{
	frame_t fr;

	PT_BEGIN(pt);

	// signal flight state
	PT_WAIT_UNTIL(pt, frame_set_2(&fr, DPT_SELF_ADDR, DPT_SELF_ADDR, FR_STATE, 0, FR_STATE_SET, FR_STATE_FLIGHT)
			&& OK == FIFO_put(&MNT.out_fifo, &fr)
	);

	// cmde cone close
	PT_WAIT_UNTIL(pt, frame_set_2(&fr, DPT_SELF_ADDR, DPT_SELF_ADDR, FR_MINUT_SERVO_CMD, 0, FR_SERVO_CONE, FR_SERVO_CLOSE)
			&& OK == FIFO_put(&MNT.out_fifo, &fr)
	);

	// cmde aero close
	PT_WAIT_UNTIL(pt, frame_set_2(&fr, DPT_SELF_ADDR, DPT_SELF_ADDR, FR_MINUT_SERVO_CMD, 0, FR_SERVO_AERO, FR_SERVO_CLOSE)
			&& OK == FIFO_put(&MNT.out_fifo, &fr)
	);

	// time-out = flight time
	MNT.time_out = MNT.open_time * TIME_1_SEC / 10 + TIME_get();

	// led alive 0.1s
	PT_WAIT_UNTIL(pt, frame_set_3(&fr, DPT_SELF_ADDR, DPT_SELF_ADDR, FR_LED_CMD, 0, FR_LED_ALIVE, FR_LED_SET, 10)
			&& OK == FIFO_put(&MNT.out_fifo, &fr)
	);

	PT_YIELD_WHILE(pt, OK);

	PT_END(pt);
}
Exemple #4
0
// check a time-out has elapsed
static PT_THREAD( MNT_check_time_out(pt_t* pt) )
{
	mnt_event_t ev;

	PT_BEGIN(pt);

	// if current time is higher than the time-out target time
	PT_WAIT_UNTIL(pt, TIME_get() > MNT.time_out);

	// prevent any further time-out
	MNT.time_out = TIME_MAX;

	// generate the time-out event
	PT_WAIT_UNTIL(pt, (ev = MNT_EV_TIME_OUT) && OK == FIFO_put(&MNT.ev_fifo, &ev) );

	PT_RESTART(pt);

	PT_END(pt);
}
Exemple #5
0
// check cone changings
static PT_THREAD( MNT_check_cone(pt_t* pt) )
{
	mnt_event_t ev;

	PT_BEGIN(pt);

	// if current time is higher than the time-out target time
	PT_WAIT_UNTIL(pt, TIME_get() > MNT.sampling_rate);

	// set next sampling period
	MNT.sampling_rate += SAMPLING_PERIOD;

	// read cone state
	u8 cone_state = CONE & _BV(CONE_PIN);

	// check if the cone state has not changed
	if ( cone_state == MNT.cone_state ) {
		PT_RESTART(pt);
	}

	// save new cone state
	MNT.cone_state = cone_state;

	// else generate the correspondig change event
	switch (MNT.cone_state) {
		case CONE_STATE_OPEN:
			PT_WAIT_UNTIL(pt, (ev = MNT_EV_CONE_OPEN) && OK == FIFO_put(&MNT.ev_fifo, &ev) );
			break;

		case CONE_STATE_CLOSED:
			PT_WAIT_UNTIL(pt, (ev = MNT_EV_CONE_CLOSED) && OK == FIFO_put(&MNT.ev_fifo, &ev) );
			break;

		default:
			break;
	}

	PT_RESTART(pt);

	PT_END(pt);
}
Exemple #6
0
static u8 aero_opening_action(pt_t* pt, void* args)
{
	frame_t fr;

	PT_BEGIN(pt);

	// signal aero opening state
	PT_WAIT_UNTIL(pt, frame_set_2(&fr, DPT_SELF_ADDR, DPT_SELF_ADDR, FR_STATE, 0, FR_STATE_SET, FR_STATE_AERO_OPENING)
			&& OK == FIFO_put(&MNT.out_fifo, &fr)
	);

	// cmde aero open
	PT_WAIT_UNTIL(pt, frame_set_2(&fr, DPT_SELF_ADDR, DPT_SELF_ADDR, FR_MINUT_SERVO_CMD, 0, FR_SERVO_AERO, FR_SERVO_OPEN)
			&& OK == FIFO_put(&MNT.out_fifo, &fr)
	);

	// cmde cone open
	PT_WAIT_UNTIL(pt, frame_set_2(&fr, DPT_SELF_ADDR, DPT_SELF_ADDR, FR_MINUT_SERVO_CMD, 0, FR_SERVO_CONE, FR_SERVO_OPEN)
			&& OK == FIFO_put(&MNT.out_fifo, &fr)
	);

	// time-out 5s
	MNT.time_out = TIME_get() + 5 * TIME_1_SEC;

	// led alive 0.5s
	PT_WAIT_UNTIL(pt, frame_set_3(&fr, DPT_SELF_ADDR, DPT_SELF_ADDR, FR_LED_CMD, 0, FR_LED_ALIVE, FR_LED_SET, 50)
			&& OK == FIFO_put(&MNT.out_fifo, &fr)
	);

	// led open 0.5s
	PT_WAIT_UNTIL(pt, frame_set_3(&fr, DPT_SELF_ADDR, DPT_SELF_ADDR, FR_LED_CMD, 0, FR_LED_OPEN, FR_LED_SET, 50)
			&& OK == FIFO_put(&MNT.out_fifo, &fr)
	);

	PT_YIELD_WHILE(pt, OK);

	PT_END(pt);
}
Exemple #7
0
static u8 cone_closing_action(pt_t* pt, void* args)
{
	frame_t fr;

	PT_BEGIN(pt);

	// signal cone closing state
	PT_WAIT_UNTIL(pt, frame_set_2(&fr, DPT_SELF_ADDR, DPT_SELF_ADDR, FR_STATE, 0, FR_STATE_SET, FR_STATE_CONE_CLOSING)
			&& OK == FIFO_put(&MNT.out_fifo, &fr)
	);

	// cmde aero stop
	PT_WAIT_UNTIL(pt, frame_set_2(&fr, DPT_SELF_ADDR, DPT_SELF_ADDR, FR_MINUT_SERVO_CMD, 0, FR_SERVO_AERO, FR_SERVO_OFF)
			&& OK == FIFO_put(&MNT.out_fifo, &fr)
	);

	// time-out 5s
	MNT.time_out = TIME_get() + 5 * TIME_1_SEC;

	PT_YIELD_WHILE(pt, OK);

	PT_END(pt);
}
Exemple #8
0
void PICLANG_next()
{
  picos_size_t command;
  picos_size_t a,b,c;// parameters, can be shared
  picos_signed_t siga;// a, but signed.
  signed char sch1;// signed char parameters
  char ch1;// char parameter
  static bit flag1;

  extern char ARG_buffer[ARG_SIZE];

  if(curr_process.page_size == 0)
    return;
  
  if(picos_processes[picos_curr_process].expires == 0)
    {
      if((curr_process.bitmap & PICLANG_BLOCKING_CALL) == 0 || PICLANG_debug == true)// Check for blocking call
	{
	  PICLANG_save(PICLANG_SUSPENDED);
	  return;
	}
    }
  
  if(picos_processes[picos_curr_process].signal_sent != PICOS_NUM_SIGNALS)
    {
      if(signal_valid_id(picos_processes[picos_curr_process].signal_sent) == false)
	{
	  PICLANG_exception(THREAD_INVALID_SIGNAL);
	  return;
	}
      curr_process.pc = signals[picos_processes[picos_curr_process].signal_sent].sig_action_addr;
      signal_free(picos_processes[picos_curr_process].signal_sent);
      picos_processes[picos_curr_process].signal_sent = PICOS_NUM_SIGNALS;
    }

  command = PICLANG_get_next_word();
  if(curr_process.status != PICLANG_SUCCESS)
    return;

  if(PICLANG_debug == true)
    PICLANG_debug_out(command);


  switch(command)
    {
    case PICLANG_UMINUS:
      {
	picos_signed_t inv = (picos_signed_t)PICLANG_pop();
	PICLANG_pushl(-inv);
	break;
      }
    case PICLANG_ADD:
      PICLANG_pushl(PICLANG_pop() + PICLANG_pop());
      PICLANG_update_arith_status();
      break;
    case PICLANG_MOD:case PICLANG_DIV:
      {
	// a/b --> c rem a
	b = PICLANG_pop();
	a = PICLANG_pop();
	c = 0;
	while(a >= b)
	  {
	    a -= b;
	    c++;
	  }
	if(command == PICLANG_MOD)
	  PICLANG_pushl(a);
	else
	  PICLANG_pushl(c);
	PICLANG_update_arith_status();
	break;
      }
    case PICLANG_SUB:
      {
	b = PICLANG_pop();
	a = PICLANG_pop();
	PICLANG_pushl(a - b);
	PICLANG_update_arith_status();
	break;
      }
    case PICLANG_MULT:
      a = PICLANG_pop();
      b = PICLANG_pop();
      c = a*b;
      PICLANG_pushl(c);
      PICLANG_update_arith_status();
      break;
    case PICLANG_PUSHL:
      a = PICLANG_get_next_word();
      PICLANG_pushl(a);
      break;
    case PICLANG_PUSH:
      {
	a = PICLANG_get_next_word();
	b = PAGE_get(a,picos_curr_process);
	if(error_code != SUCCESS)
	  PICLANG_exception(error_code);
	else
	  PICLANG_pushl(b);
	break;
      }
    case PICLANG_DROP:
      PICLANG_pop();
      break;
    case PICLANG_SWAP:
      a = PICLANG_pop();
      b = PICLANG_pop();
      PICLANG_pushl(a);
      PICLANG_pushl(b);
      break;
    case PICLANG_POP:
      {
	a = PICLANG_get_next_word();
	b = PICLANG_pop();
	PAGE_set(a,b,picos_curr_process);
	break;
      }
    case PICLANG_ARGC:
      PICLANG_pushl(picos_processes[picos_curr_process].nargs);
      break;
    case PICLANG_ARGV:
      {
	a = PICLANG_pop();
	sch1 = ARG_get(a);
	if(sch1 < 0)
	  {
	    PICLANG_exception(PICLANG_INVALID_PARAMETER);
	    break;
	  }
	b = (picos_size_t)sch1;
	PICLANG_pushl(b);
	break;
      }
    case PICLANG_PRINT:
      {
	a = PICLANG_pop();
	putch(a);
	IO_flush();
	break;
      }
    case PICLANG_DEREF:
      {
	a = PICLANG_pop();// array index
	b = PICLANG_pop();// array starting address
	PICLANG_next_dereference(b+a,command);
	break;
      }
    case PICLANG_BSL: case PICLANG_BSR:// bit shifts
      {
	a /*shift_amount*/ = PICLANG_pop();
	b /*val*/ = PICLANG_pop();
	if(command == PICLANG_BSL)
	  b <<= a;
	else
	  b >>= a;
	PICLANG_pushl(b);
	PICLANG_update_arith_status();
	break;
      }
    case PICLANG_FPUTD:
      {
	char hex_val[PICOS_SIZE_T_DECIMAL_DIGITS];//ch1 = index
	dec_to_word(hex_val,PICLANG_pop());
	ch1 = 0;
	flag1 = false;
	for(;ch1 < 5;ch1++)
	  {
	    if(flag1 == true || hex_val[ch1] != 0x30)
	      {
		SRAM_write(SRAM_PICLANG_RAW_FILE_BUFFER+PICLANG_file_buffer_index++,&hex_val[ch1],sizeof(char));
		flag1 = true;
	      }
	    if(PICLANG_file_buffer_index >= FS_BUFFER_SIZE)
	      {
		picfs_dump(picos_processes[picos_curr_process].program_file);
		SRAM_write(SRAM_PICLANG_NEXT_SWAP_ADDR,(void*)picfs_buffer,FS_BUFFER_SIZE);
		memset((char*)picfs_buffer,0,FS_BUFFER_SIZE);
		SRAM_write(SRAM_PICLANG_RAW_FILE_BUFFER,(void*)picfs_buffer,FS_BUFFER_SIZE);
		SRAM_read(SRAM_PICLANG_NEXT_SWAP_ADDR,(void*)picfs_buffer,FS_BUFFER_SIZE);
		PICLANG_file_buffer_index = 0;
	      }
	  }
	if(flag1 == false)
	  {
	    ch1 = '0';
	    SRAM_write(SRAM_PICLANG_RAW_FILE_BUFFER+PICLANG_file_buffer_index++,&ch1,sizeof(char));
	    if(PICLANG_file_buffer_index >= FS_BUFFER_SIZE)
	      {
		picfs_dump(picos_processes[picos_curr_process].program_file);
		SRAM_write(SRAM_PICLANG_NEXT_SWAP_ADDR,(void*)picfs_buffer,FS_BUFFER_SIZE);
		memset((char*)picfs_buffer,0,FS_BUFFER_SIZE);
		SRAM_write(SRAM_PICLANG_RAW_FILE_BUFFER,(void*)picfs_buffer,FS_BUFFER_SIZE);
		SRAM_read(SRAM_PICLANG_NEXT_SWAP_ADDR,(void*)picfs_buffer,FS_BUFFER_SIZE);
		PICLANG_file_buffer_index = 0;
	      }
	  }
	break;
      }
    case PICLANG_PWDIR:
      PICLANG_pushl(curr_dir);
      break;
    case PICLANG_MOUNT:
      a = PICLANG_pop();// device
      b = PICLANG_pop();// address of first byte
      if(picfs_mount((picos_addr_t)b,(picos_dev_t)a) != SUCCESS)
	curr_process.status = error_code;
      break;
    case PICLANG_CHDIR:
      {
	a = PICLANG_pop();
	picfs_chdir(a);
	break;
      }
    case PICLANG_MOVE:
      a = PICLANG_pop();// y
      b = PICLANG_pop();// x
      IO_move(a,b);
      break;
    case PICLANG_GETY: case PICLANG_GETX:
      IO_getxy(&a,&b);
      if(command == PICLANG_GETX)
	PICLANG_pushl(a);
      else
	PICLANG_pushl(b);
      break;
    case PICLANG_FPUTCH:// KEEP FPUTCH before FFLUSH
      {
	ch1 = (char)PICLANG_pop();
	SRAM_write(SRAM_PICLANG_RAW_FILE_BUFFER+PICLANG_file_buffer_index++,&ch1,sizeof(char));
	if(PICLANG_file_buffer_index < FS_BUFFER_SIZE)
	  break;
      }
    case PICLANG_FFLUSH:// KEEP FPUTCH before FFLUSH  KEEP FFLUSH before FCLEAR
      picfs_dump(picos_processes[picos_curr_process].program_file);
    case PICLANG_FCLEAR:// KEEP FFLUSH before FCLEAR
      SRAM_write(SRAM_PICLANG_NEXT_SWAP_ADDR,(void*)picfs_buffer,FS_BUFFER_SIZE);
      memset((char*)picfs_buffer,0,FS_BUFFER_SIZE);
      SRAM_write(SRAM_PICLANG_RAW_FILE_BUFFER,(void*)picfs_buffer,FS_BUFFER_SIZE);
      SRAM_read(SRAM_PICLANG_NEXT_SWAP_ADDR,(void*)picfs_buffer,FS_BUFFER_SIZE);
      PICLANG_file_buffer_index = 0;
      break;
    case PICLANG_FSTAT:
      a = PICLANG_pop();
      sch1 = picfs_stat(a);
      if(sch1 < 0)
	{
	  PICLANG_set_errno();
	  sch1 = 0;
	}
      a = picfs_buffer[ST_SIZE] << 8;
      a += picfs_buffer[ST_SIZE+1];
      PICLANG_pushl(a);
      break;
    case PICLANG_READDIR:
      a = PICLANG_pop();
      sch1 = picfs_readdir(1,a);
      if(sch1 != SUCCESS)
	PICLANG_set_errno();
      PICLANG_pushl(sch1);
      break;
    case PICLANG_FOPEN:
      {
	/*	mount_t mount;
		SRAM_read(curr_dir*sizeof(mount_t)+SRAM_MTAB_ADDR,&mount,sizeof(mount_t));*/
	a = PICLANG_pop();
	if(a < ARG_SIZE)
	  {
	    sch1 = picfs_open(ARG_buffer+a,curr_dir);
	  }
	else if(a < ARG_SIZE + FS_BUFFER_SIZE)
	  {
	    a -= ARG_SIZE;
	    sch1 = picfs_open((const char*)picfs_buffer+a,curr_dir);
	  }
	else
	  {
	    c = 0;
	    a -= ARG_SIZE + picos_processes[picos_curr_process].block_size;
	    sch1 = PICLANG_next_dereference(a,command);
	  }
	if(sch1 == -1)
	  PICLANG_set_errno();
	PICLANG_pushl(sch1);
	break;
      }
    case PICLANG_FCLOSE:
      a = PICLANG_pop();
      picfs_close(a);
      break;
    case PICLANG_FREAD:
      a = PICLANG_pop();
      sch1 = picfs_load(a);
      b = sch1;
      if(sch1 < 0)
	{
	  b = -1;
	  error_code = SUCCESS;
	  PICLANG_exception(error_code);
	}
      PICLANG_pushl(b);
      break;
    case PICLANG_PRINTL:
      IO_putd(PICLANG_pop());
      IO_flush();
      break;
    case PICLANG_CLEAR:
      clear_output();
      break;
    case PICLANG_MUTEX_LOCK:
      PICLANG_block();
      break;
    case PICLANG_MUTEX_UNLOCK:
      PICLANG_unblock();
      break;
    case PICLANG_GETCH:
      {
	PICLANG_block();
	PICLANG_pushl(getch());
	PICLANG_unblock();
	break;
      }
    case PICLANG_GETD:
      {
	PICLANG_block();
	ch1 = getch();
	PICLANG_unblock();
	if(ch1 < '0' || ch1 > '9')
	  {
	    PICLANG_exception(ARG_INVALID);
	    break;
	  }
	ch1 -= 0x30;
	PICLANG_pushl(ch1);
	break;
      }
    case PICLANG_SPRINT:case PICLANG_SPRINTN:
      {
	// string addresses start with arguments then const strings in executable
	/*string_pointer*/a = PICLANG_pop();
	PICLANG_next_dereference(a,command);
	IO_flush();
	break;
      }
    case PICLANG_LSOF:
      IO_puts("Implement lsof");
      break;
    case PICLANG_LSMOUNT:
      lsmount();
      break;
    case PICLANG_ERRNO:
      PICLANG_pushl(PICLANG_get_errno());
      break;
    case PICLANG_KVERSION:
      a = PICLANG_pop();
      if(a > 3)
      {
          PICLANG_exception(PICFS_EINVAL);
          break;
      }
      if(a == 0)
          b = KERNEL_MAJOR_VERSION;
      else if(a == 1)
          b = KERNEL_MINOR_VERSION;
      else if(a == 2)
          b = KERNEL_REVISION;
      else
          b = KERNEL_ID_TAG;
      PICLANG_pushl(b);
      break;
    case PICLANG_SIGNAL:
      a = PICLANG_get_next_word();// signal id
      b = PICLANG_get_next_word();// signal action
      if(a == PICOS_NUM_SIGNALS)
	{
	  signal_free(b);
	  break;
	}
      sch1 = signal_assign(a,picos_curr_process,b);
      if(sch1 != 0)
	PICLANG_exception(error_code);
      break;
    case PICLANG_SLEEP:
      a = PICLANG_pop();
      ch1 = picos_curr_process;
      PICLANG_save(PICLANG_SUSPENDED);
      picos_processes[ch1].expires = (quantum_t)a;
      break;
    case PICLANG_MORSE:
      {
	char two[2];
	/*addr*/a = PICLANG_pop();
	two[1] = PICLANG_pop();//char or string?
	if(two[1] == PICLANG_MORSE_STRING)
	  SRAM_read(a++,two,1);
	else
	  {
	    two[0] = (char)a;
	    two[1] = 0;
	    morse_sound(two);
	    break;
	  }
	two[1] = 0;
	while(two[0] != 0)
	  {
	    morse_sound(two);
	    SRAM_read(a++,two,1);
	  }
	break;
      }
    case PICLANG_TIME:
      {
	const TIME_t *thetime = TIME_get();
	ch1 = PICLANG_pop();
	switch(ch1)
	  {
	  case 'Y':
	    PICLANG_pushl(thetime->year);
	    break;
	  case 'm':
	    PICLANG_pushl(thetime->month);
	    break;
	  case 'd':
	    PICLANG_pushl(thetime->day);
	    break;
	  case 'H':
	    PICLANG_pushl(thetime->hours);
	    break;
	  case 'M':
	    PICLANG_pushl(thetime->minutes);
	    break;
	  case 'S':
	    PICLANG_pushl(thetime->seconds);
	    break;
	  default:
	    PICLANG_exception(PICLANG_INVALID_PARAMETER);
	    break;
	  }
	break;
      }
    case PICLANG_SET_TIME:case PICLANG_SET_DATE:
      {
	TIME_t newtime = *(TIME_get());
	if(command == PICLANG_SET_TIME)
	  {
	    newtime.minutes = PICLANG_pop();
	    newtime.hours = PICLANG_pop();
	    if(newtime.minutes > 59 || newtime.hours > 23)
	      {
		newtime.minutes = newtime.hours = 0;
		PICLANG_exception(TIME_INVALID);
	      }
	  }
	else
	  {
	    newtime.year = PICLANG_pop();
	    newtime.day = PICLANG_pop();
	    newtime.month = PICLANG_pop();
	    if(newtime.month > 12 || newtime.day > 31)
	      {
		newtime.month = newtime.day = 0;
		PICLANG_exception(TIME_INVALID);
	      }
	  }
	TIME_set(&newtime);
	break;
      }
    case PICLANG_JZ:case PICLANG_JMP:case PICLANG_CALL:
      {
	b = curr_process.pc;
	a = PICLANG_get_next_word();
	if(curr_process.status != PICLANG_SUCCESS)
	  {
	    curr_process.pc = b;
	    break;
	  }
	if(command == PICLANG_CALL)
	  {
	    PICLANG_call_push(curr_process.pc);
	    curr_process.pc = a;
	  }
	else if(command == PICLANG_JMP)
	  curr_process.pc = a;
	else if((curr_process.bitmap & PICLANG_ZERO) == 0)
	  curr_process.pc = a;
	if(curr_process.status != PICLANG_SUCCESS)
	  {
	    curr_process.pc = b;
	    break;
	  }
	break;
      }
    case PICLANG_RETURN:
      {
	b = curr_process.pc;
	curr_process.pc = PICLANG_call_pop();
	if(curr_process.status != PICLANG_SUCCESS)
	  {
	    curr_process.pc = b;
	    break;
	  }
	break;
      }
    case PICLANG_EXIT:
      PICLANG_save(PICLANG_pop());
      break;
    case PICLANG_LABEL:
      break;
    case PICLANG_COMPLT:
      {
	b = PICLANG_pop();
	a = PICLANG_pop();
	if(a < b)
	  curr_process.bitmap |= PICLANG_ZERO;
	else
	  curr_process.bitmap &= ~PICLANG_ZERO;
	break;
      }
    case PICLANG_COMPGT:
      {
	b = PICLANG_pop();
	a = PICLANG_pop();
	if(a > b)
	  curr_process.bitmap |= PICLANG_ZERO;
	else
	  curr_process.bitmap &= ~PICLANG_ZERO;
	break;
      }
    case PICLANG_COMPEQ:case PICLANG_COMPNE:
      {
	b = PICLANG_pop();
	a = PICLANG_pop();
	if(a == b)
	  curr_process.bitmap |= PICLANG_ZERO;
	else
	  curr_process.bitmap &= ~PICLANG_ZERO;
	if(command == PICLANG_COMPNE)
	  curr_process.bitmap ^= PICLANG_ZERO;
	break;
      }
    case PICLANG_AND:
      a = PICLANG_pop();
      b = PICLANG_pop();
      PICLANG_pushl(a & b);
      break;
    case PICLANG_OR:
      a = PICLANG_pop();
      b = PICLANG_pop();
      PICLANG_pushl(a | b);
      break;
    case PICLANG_NOT:
      a = PICLANG_pop();
      PICLANG_pushl(~a);
      break;
    case PICLANG_RAWLOAD:
      SRAM_read(SRAM_PICLANG_RAW_FILE_BUFFER,(void*)picfs_buffer,FS_BUFFER_SIZE);
      break;
    case PICLANG_NUM_COMMANDS:default:
      PICLANG_exception(PICLANG_UNKNOWN_COMMAND);
      break;
    }

}
Exemple #9
0
static PT_THREAD( LOG_log(pt_t* pt) )
{
	u32 time;
	u8 is_filtered;
	u8 i;

	PT_BEGIN(pt);

	// systematically unlock the channel
	// because most of time no response is sent
	// when a response is needed, the channel will be locked
	DPT_unlock(&LOG.interf);

	switch ( LOG.state ) {
		case LOG_OFF:
		default:
			// empty the log fifo
			(void)FIFO_get(&LOG.in_fifo, &LOG.fr);

			// loop back for next frame
			PT_RESTART(pt);
			break;

		case LOG_RAM:
#ifdef SAVE_IN_RAM_ENABLED
#endif
			break;

		case LOG_EEPROM:
			// if address is out of range
			if ( LOG.eeprom_addr >= EEPROM_END_ADDR ) {
				// logging is no more possible
				// so quit
				PT_EXIT(pt);
			}
			break;

		case LOG_SDCARD:
			// if address is out of range
			if ( LOG.sdcard_addr >= SDCARD_END_ADDR ) {
				// logging is no more possible
				// so quit
				PT_EXIT(pt);
			}
			break;
	}

	// wait while no frame is present in the fifo
	PT_WAIT_WHILE(pt, KO == FIFO_get(&LOG.in_fifo, &LOG.fr));

	// if it is a log command
	if ( (LOG.fr.cmde == FR_LOG_CMD) && (!LOG.fr.resp) ) {
		// treat it
		LOG_command(&LOG.fr);

		// send the response
		DPT_lock(&LOG.interf);
		PT_WAIT_UNTIL(pt, OK == DPT_tx(&LOG.interf, &LOG.fr));
		DPT_unlock(&LOG.interf);


		// and wait till the next frame
		PT_RESTART(pt);
	}

	// filter the frame according to its origin
	is_filtered = OK;	// by default, every frame is filtered
	for ( i = 0; i < sizeof(LOG.orig_filter); i++ ) {
		// passthrough or frame origin and filter acceptance match
		if ( (LOG.orig_filter[i] == 0x00) || (LOG.orig_filter[i] == LOG.fr.orig) ){
			is_filtered = KO;
			break;
		}
	}

	// if frame is filtered away
	if ( is_filtered ) {
		// lop back for next frame
		PT_RESTART(pt);
	}

	// build the log packet
	LOG.block.index = LOG.index;
	time = TIME_get();
	LOG.block.time[0] = (u8)(time >> 16);
	LOG.block.time[1] = (u8)(time >>  8);
	LOG.block.fr = LOG.fr;

	switch ( LOG.state ) {
		case LOG_OFF:
		default:
			// shall never happen but just in case
			// loop back for next frame
			PT_RESTART(pt);
			break;

		case LOG_RAM:
#ifdef SAVE_IN_RAM_ENABLED
			LOG.ram_buffer[LOG.ram_index] = LOG.block;
			if ( LOG.ram_index < (RAM_BUFFER_SIZE - 1) ) {
				LOG.ram_index++;
			}
#endif
			break;

		case LOG_EEPROM:
			// save it to eeprom
			PT_WAIT_UNTIL(pt, EEP_write(LOG.eeprom_addr, (u8*)&LOG.block, sizeof(log_t)));

			// wait until saving is done
			PT_WAIT_UNTIL(pt, EEP_is_fini());
			break;

		case LOG_SDCARD:
			// save it to sdcard (fill the write buffer)
			PT_WAIT_UNTIL(pt, SD_write(LOG.sdcard_addr, (u8*)&LOG.block, sizeof(log_t)));

			// wait until saving is done

			break;
	}

	// loop back to treat the next frame to log
	PT_RESTART(pt);

	PT_END(pt);
}
Exemple #10
0
void TIME_delay_ms(uint16_t delay)
{
	const uint64_t tstop = TIME_get() + delay;
	while (TIME_get() < tstop)
		;
}
Exemple #11
0
 * http://clock.davecoss.com
 *
 * Author: David Coss, PhD
 * Date: 6 Oct 2012
 *
 * License: GNU Public License version 3.0 (see http://www.gnu.org)
 *
 * This file has the code for the abstract IO functions.
 */
  const TIME_t *time = NULL;
  char last_time = 0;
  char input;

  TRIS_init();
  TIME_init();
  time = TIME_get();
  last_time = time->minutes - 1;

  //clock_set_display(BINARY);
  clock_set_display(SEG7);

  while(true)
    {
      if(last_time != time->minutes)
	{
	  if(to_be_displayed == SHOW_TIME)
	    {
	      update_display(LEFT,time->hours);
	      update_display(RIGHT, time->minutes);
	    }
	  else if(to_be_displayed == SHOW_DATE)
Exemple #12
0
static PT_THREAD( TSN_tsn(pt_t* pt) )
{
	u32 local_time;
	union {
		u32 full;
		u8 part[4];
	} remote_time;
	dna_list_t* list;
	u8 nb_is;
	u8 nb_bs;

	PT_BEGIN(pt);

	// every second
	PT_WAIT_UNTIL(pt, TIME_get() > TSN.time_out);
	TSN.time_out += TIME_1_SEC;

	// retrieve self and BC node address
	list = DNA_list(&nb_is, &nb_bs);

	// build the time request
	TSN.fr.orig = DNA_SELF_ADDR(list);
	TSN.fr.dest = DNA_BC_ADDR(list);
	TSN.fr.cmde = FR_TIME_GET;
	TSN.fr.resp = 0;
	TSN.fr.error = 0;
	TSN.fr.eth = 0;
	TSN.fr.serial = 0;

	// send the time request
	DPT_lock(&TSN.interf);
	PT_WAIT_UNTIL(pt, OK == DPT_tx(&TSN.interf, &TSN.fr));
	DPT_unlock(&TSN.interf);

	// wait for the answer
	PT_WAIT_UNTIL(pt, FIFO_get(&TSN.queue, &TSN.fr) && TSN.fr.resp);

	// immediatly unlock
	DPT_unlock(&TSN.interf);

	// rebuild remote time (AVR is little endian)
	remote_time.part[0] = TSN.fr.argv[3];
	remote_time.part[1] = TSN.fr.argv[2];
	remote_time.part[2] = TSN.fr.argv[1];
	remote_time.part[3] = TSN.fr.argv[0];

	// read local time
	local_time = TIME_get();

	// check whether we are in the future
	if ( local_time > remote_time.full ) {
		// then the local time is running too fast
		// so slow it down
		TSN.time_correction--;
	}
	// check whether we are in the past
	if ( local_time < remote_time.full ) {
		// then the local time is running too slow
		// so speed it up
		TSN.time_correction++;
	}

	// update time increment
	TIME_set_incr(10 * TIME_1_MSEC + TSN.time_correction);

	// loop back
	PT_RESTART(pt);

	PT_END(pt);
}