Example #1
0
void jsp_hardware_transact(void)
{
  int bytes_to_send;
  int bytes_received = 8;  // can receive up to 8 bytes
  char sendbuf[8];
  char rcvbuf[8];
  int i,j;
  int ret;

  debug("JSP about to transact; Tohw buf size now %i, fromhw buf size %i\n", jsp_tohw_count, jsp_fromhw_count);

  // Get data to send, if any
  bytes_to_send = jsp_tohw_count;
  if(bytes_to_send > 8) bytes_to_send = 8;

  j = jsp_tohw_rd_idx;
  for(i = 0; i < bytes_to_send; i++)
    {
      sendbuf[i] = jsp_tohw_buf[j];
      j = (j+1) % JSP_BUFFER_SIZE;
    }

  // Do the transaction
  ret = dbg_serial_sndrcv(&bytes_to_send, sendbuf, &bytes_received, rcvbuf);
  if(ret != APP_ERR_NONE)
    {
      fprintf(stderr, "Error in JSP transaction: %s\n", get_err_string(ret));
    }
  else
    {
      debug("Transacted, bytes sent = %i, received = %i\n", bytes_to_send, bytes_received);

      // Adjust send buffer pointers as necessary - we may not have sent all 8 bytes
      jsp_tohw_count -= bytes_to_send;
      jsp_tohw_rd_idx = (jsp_tohw_rd_idx + bytes_to_send) % JSP_BUFFER_SIZE;
      
      // Queue data received, if any, and adjust the pointers
      for(i = 0; i < bytes_received; i++)
	{
	  jsp_fromhw_buf[jsp_fromhw_wr_idx] = rcvbuf[i];
	  jsp_fromhw_wr_idx = (jsp_fromhw_wr_idx + 1) % JSP_BUFFER_SIZE;
	  jsp_fromhw_count++;
	}
      
      debug("JSP transacted; Tohw buf size now %i, fromhw buf size %i\n", jsp_tohw_count, jsp_fromhw_count);
    }
}
void display_error(int err_val) {
	unsigned int type = is_mc_error(err_val);
	
	MessagePopup(get_mc_error_title(type), get_err_string(err_val, type));
}