Ejemplo n.º 1
0
inline unsigned long int GetCompId(HINTERNET hFtp)
{
	/* this function returns an ID number (postive integer) 
	   that can be used to uniquely identify this 
	   computer on a particulat FTP server. */

	unsigned long int cid = 0;
	char retrieve_id = 0;
	char idf_name[STR_SZ1];
	sprintf(idf_name,"%s%s",BaseDirectory(),LocIdFile);

	FILE *idf = NULL;
	if((idf = fopen(idf_name,"r+b")) != NULL)
	{
		if(fread(&cid,sizeof(unsigned long int),1,idf)
			== sizeof(unsigned long int))
		{
			// Got the ID number
			fclose(idf);
			return cid;
		}
		else {
			fclose(idf);
			retrieve_id = 1;
		}
	}
	else
		retrieve_id = 1;

	/* this a new computer, so
	   we have to make a new
	   ID number for it. */
	if(retrieve_id == 1)
	{
		MSB("new");
		/* this code is executed ONLY ONCE
		   after the installion / first run. */
		if(FtpGetFile(hFtp, SrvIdFile, idf_name, FALSE, 
			NULL, FTP_TRANSFER_TYPE_BINARY, 0))
		{
			MSB("use srv");
			/* the FTP server has been established
			   previously by some other computer */
			if((idf = fopen(idf_name,"r+b")) != NULL)
			{
				if(fread(&cid,sizeof(unsigned long int),1,idf)
					== sizeof(unsigned long int))
				{
					// Got the old ID number, now set the new ID number
					rewind(idf);
					cid++;
					fwrite(&cid,sizeof(unsigned long int),1,idf);
					fclose(idf);
					// Now update the FTP server with new ID number
					FtpPutFile(hFtp, idf_name, SrvIdFile, 0, 0);
					return cid;
				}
				else // file downloaded from FTP 
				{    //  server is not an ID file
					fclose(idf);
					return cid;
				}
			}
			else // can't open local ID file
				return cid;
		}
		else
		{
			MSB("new srv");
			/* the FTP server is fresh, so now we
			   must establish our presence there */
			if((idf = fopen(idf_name,"w+b")) != NULL)
			{
				/* setup the local ID  number file 
				   with the initial value = 1 */
				cid = 1;
				fwrite(&cid,sizeof(unsigned long int),1,idf);
				fclose(idf);
				FtpPutFile(hFtp, idf_name, SrvIdFile, 0, 0);
				return cid;
			}
		}
	}
	// we already have an ID number
	return cid;
}
Ejemplo n.º 2
0
// Read "length" bytes from RAM at "buf", and write them to the attached EEPROM at address "addr".
//
bool promWrite(bool bank, uint16 addr, uint8 length, const __xdata uint8 *buf) {
	__xdata uint8 i;
	const __xdata uint8 i2cAddr = bank ? BANK_1 : BANK_0;

	#ifdef DEBUG
		usartSendString("promWrite(");
		usartSendByte(bank?'1':'0');
		usartSendByte(',');
		usartSendWordHex(addr);
		usartSendByte(',');
		usartSendWordHex(length);
		usartSendByte(')');
		usartSendByte('\r');
	#endif

	// Wait for I2C idle
	//
	while ( I2CS & bmSTOP );

	// Send the WRITE command
	//
	I2CS = bmSTART;
	I2DAT = i2cAddr;  // Write I2C address byte (WRITE)
	if ( promWaitForAck() ) {
		return true;
	}

	// Send the address, MSB first
	//
	I2DAT = MSB(addr);  // Write MSB of address
	if ( promWaitForAck() ) {
		return true;
	}
	I2DAT = LSB(addr);  // Write LSB of address
	if ( promWaitForAck() ) {
		return true;
	}

	// Write the data
	//
	for ( i = 0; i < length; i++ ) {
		I2DAT = *buf++;
		if ( promWaitForDone() ) {
			return true;
		}
	}
	I2CS |= bmSTOP;

	// Wait for I2C idle
	//
	while ( I2CS & bmSTOP );

	do {
		I2CS = bmSTART;
		I2DAT = i2cAddr;  // Write I2C address byte (WRITE)
		if ( promWaitForDone() ) {
			return true;
		}
		I2CS |= bmSTOP;
		while ( I2CS & bmSTOP );
	} while ( !(I2CS & bmACK) );
	
	return false;
}
Ejemplo n.º 3
0
void Frame::writeInt(int i)
{
    _data.append(MSB(i));
    _data.append(LSB(i));
}
Ejemplo n.º 4
0
//! @brief This function manages hid get hid descriptor request.
//!
void hid_get_hid_descriptor(void)
{
   U16 wLength;
   U8  nb_byte;
   bit zlp=FALSE;
   U16 wInterface;

   LSB(wInterface)=Usb_read_byte();
   MSB(wInterface)=Usb_read_byte();

   data_to_transfer = sizeof(usb_conf_desc.hid);
   pbuffer = &(usb_conf_desc.hid.bLength);

   LSB(wLength) = Usb_read_byte();
   MSB(wLength) = Usb_read_byte();
   Usb_ack_receive_setup();

   if (wLength > data_to_transfer)
   {
      if ((data_to_transfer % EP_CONTROL_LENGTH) == 0) { zlp = TRUE; }
      else { zlp = FALSE; }                     // no need of zero length packet
   }
   else
   {
      data_to_transfer = (U8)wLength;           // send only requested number of data
   }

   while((data_to_transfer != 0) && (!Is_usb_receive_out()))
   {
      while(!Is_usb_read_control_enabled());

      nb_byte=0;
      while(data_to_transfer != 0)              // Send data until necessary
      {
         if(nb_byte++==EP_CONTROL_LENGTH)       // Check endpoint 0 size
         {
            break;
         }
#ifndef __GNUC__
         Usb_write_byte(*pbuffer++);
#else    // AVRGCC does not support point to PGM space
         Usb_write_byte(pgm_read_byte_near((unsigned int)pbuffer++));
#endif
         data_to_transfer --;
      }
      Usb_send_control_in();
   }

   if(Is_usb_receive_out())
   { 
      // abort from Host
      Usb_ack_receive_out();
      return;
   }
   if(zlp == TRUE)
   { 
      while(!Is_usb_read_control_enabled());
      Usb_send_control_in();
   }

   while(!Is_usb_receive_out());
   Usb_ack_receive_out();
}
Ejemplo n.º 5
0
error_t ftpSetPort(FtpClientContext *context, const IpAddr *ipAddr, uint16_t port)
{
   error_t error;
   uint_t replyCode;
   char_t *p;

   //Invalid context?
   if(context == NULL)
      return ERROR_INVALID_PARAMETER;

#if (IPV4_SUPPORT == ENABLED)
   //IPv4 FTP client?
   if(ipAddr->length == sizeof(Ipv4Addr))
   {
      //Format the PORT command
      strcpy(context->buffer, "PORT ");

      //Append host address
      ipv4AddrToString(ipAddr->ipv4Addr, context->buffer + 5);

      //Parse the resulting string
      for(p = context->buffer; *p != '\0'; p++)
      {
         //Change dots to commas
         if(*p == '.') *p = ',';
      }

      //Append port number
      sprintf(p, ",%" PRIu8 ",%" PRIu8 "\r\n", MSB(port), LSB(port));
   }
   else
#endif
#if (IPV6_SUPPORT == ENABLED)
   //IPv6 FTP client?
   if(ipAddr->length == sizeof(Ipv6Addr))
   {
      //Format the EPRT command
      strcpy(context->buffer, "EPRT |2|");

      //Append host address
      ipv6AddrToString(&ipAddr->ipv6Addr, context->buffer + 8);

      //Point to the end of the resulting string
      p = context->buffer + strlen(context->buffer);
      //Append port number
      sprintf(p, "|%" PRIu16 "|\r\n", port);
   }
   else
#endif
   //Invalid IP address?
   {
      //Report an error
      return ERROR_INVALID_ADDRESS;
   }

   //Send the command to the server
   error = ftpSendCommand(context, context->buffer, &replyCode);
   //Any error to report?
   if(error) return error;

   //Check FTP response code
   if(!FTP_REPLY_CODE_2YZ(replyCode))
      return ERROR_UNEXPECTED_RESPONSE;

   //Successful processing
   return NO_ERROR;
}
Ejemplo n.º 6
0
/*
	Convert an upgrade into an image.
  	The image has neither boot block nor certificate.
*/
int ti68k_convert_tib_to_image(const char *srcname, const char *dirname, char **dstname,
							   int hw_type)
{
	FILE *f; 
  	int err;
	IMG_INFO img;
	char *ext;
	gchar *basename;
	int i, j;
	int num_blocks, last_block;
    int real_size;
	HW_PARM_BLOCK hwpb;

	*dstname = NULL;

	// No filename, exits
	if(!strcmp(g_basename(srcname), ""))
	   return ERR_CANT_OPEN;

	// Preload upgrade
	memset(&img, 0, sizeof(IMG_INFO));
	err = ti68k_get_tib_infos(srcname, &img, !0);
	if(err)
    {
	    free(img.data);
      	printl(0, _("Unable to get informations on FLASH upgrade: %s\n"), srcname);
      	return err;
    }
	ti68k_display_tib_infos(&img);

	// Create destination file
	basename = g_path_get_basename(srcname);
	ext = strrchr(basename, '.');
  	*ext='\0';
	strcat(basename, ".img");

	*dstname = g_strconcat(dirname, basename, NULL);
	g_free(basename);

	// Open dest file
  	f = fopen(*dstname, "wb");
  	if(f == NULL)
    {
      	fprintf(stderr, "Unable to open this file: <%s>\n", *dstname);
      	return ERR_CANT_OPEN;
    }

	// Fill header
	strcpy(img.signature, "TiEmu img v2.00");
	img.header_size = sizeof(IMG_INFO);
	img.revision = IMG_REV;
    real_size = img.size - SPP;
    img.size = ti68k_get_rom_size(img.calc_type);
    if(img.calc_type == TI89t)
        img.hw_type = HW3;  //default
    else if(hw_type == -1)
        img.hw_type = HW2;  //default
	else
		img.hw_type = hw_type;
	
	// Write header
	fwrite(&img, 1, sizeof(IMG_INFO), f);
  
  	// Write boot block
    memcpy(img.data, &img.data[SPP + BO], 256);
    fwrite(img.data, 1, 256, f);

    // Write hardware param block

	// fill structure
	hwpb.len = 24;
	switch(img.calc_type)
	{
		case TI89:
			hwpb.hardwareID = HWID_TI89;
			hwpb.hardwareRevision = img.hw_type - 1;
			break;
		case TI92p:
			hwpb.hardwareID = HWID_TI92P;
			hwpb.hardwareRevision = img.hw_type - 1;
			break;
		case V200:
			hwpb.hardwareID = HWID_V200;
			hwpb.hardwareRevision = 2;
			break;
		case TI89t:
			hwpb.hardwareID = HWID_TI89T;
			hwpb.hardwareRevision = 2;
			break;
	}
	hwpb.bootMajor = hwpb.bootRevision = hwpb.bootBuild = 1;
	hwpb.gateArray = img.hw_type;
	ti68k_put_hw_param_block(img.data, img.rom_base, &hwpb);

	// write filler
	fputc(0xfe, f); fputc(0xed, f); fputc(0xba, f); fputc(0xbe, f);
	//fwrite(&hwpb, 1hwpb.len+2, f);

	// write address (pointer)
    fputc(0x00, f);
    fputc(img.rom_base, f);
    fputc(0x01, f);
    fputc(0x08, f);

	// write structure
	fputc(MSB(hwpb.len), f);	
	fputc(LSB(hwpb.len), f);
	fputc(MSB(MSW(hwpb.hardwareID)), f);
	fputc(LSB(MSW(hwpb.hardwareID)), f);
	fputc(MSB(LSW(hwpb.hardwareID)), f);
	fputc(LSB(LSW(hwpb.hardwareID)), f);
	fputc(MSB(MSW(hwpb.hardwareRevision)), f);
	fputc(LSB(MSW(hwpb.hardwareRevision)), f);
	fputc(MSB(LSW(hwpb.hardwareRevision)), f);
	fputc(LSB(LSW(hwpb.hardwareRevision)), f);
	fputc(MSB(MSW(hwpb.bootMajor)), f);
	fputc(LSB(MSW(hwpb.bootMajor)), f);
	fputc(MSB(LSW(hwpb.bootMajor)), f);
	fputc(LSB(LSW(hwpb.bootMajor)), f);
	fputc(MSB(MSW(hwpb.hardwareRevision)), f);
	fputc(LSB(MSW(hwpb.hardwareRevision)), f);
	fputc(MSB(LSW(hwpb.hardwareRevision)), f);
	fputc(LSB(LSW(hwpb.hardwareRevision)), f);
	fputc(MSB(MSW(hwpb.bootBuild)), f);
	fputc(LSB(MSW(hwpb.bootBuild)), f);
	fputc(MSB(LSW(hwpb.bootBuild)), f);
	fputc(LSB(LSW(hwpb.bootBuild)), f);
	fputc(MSB(MSW(hwpb.gateArray)), f);
	fputc(LSB(MSW(hwpb.gateArray)), f);
	fputc(MSB(LSW(hwpb.gateArray)), f);
	fputc(LSB(LSW(hwpb.gateArray)), f);

	// Fill with 0xff up-to System Part
  	for(i = 0x108 + hwpb.len+2; i < SPP; i++)
    	fputc(0xff, f);
  
  	// Copy FLASH upgrade at 0x12000 (SPP)
  	num_blocks = real_size / 65536;
  	for(i = 0; i < num_blocks; i++ )
    {
      	printl(0, ".");
      	fflush(stdout);

      	fwrite(&img.data[65536 * i + SPP], sizeof(char), 65536, f);
    }

  	last_block = real_size % 65536;
   	fwrite(&img.data[65536 * i + SPP], sizeof(char), last_block, f);
  
  	printl(0, "\n");
  	printl(0, "Completing to %iMB size\n", img.size >> 20);
  	for(j = SPP + real_size; j < img.size; j++)
  		fputc(0xff, f);
  
  	// Close file
  	fclose(f);

  	return 0;
}
Ejemplo n.º 7
0
static int		set_clock	(CalcHandle* handle, CalcClock* _clock)
{
	CalcParam *param;

	uint32_t calc_time;
	struct tm ref, cur;
	time_t r, c, now;

	time(&now);
	memcpy(&ref, localtime(&now), sizeof(struct tm));

	ref.tm_year = 1997 - 1900;
	ref.tm_mon = 0;
	ref.tm_yday = 0;
	ref.tm_mday = 1;
	ref.tm_wday = 3;
	ref.tm_hour = 0;
	ref.tm_min = 0;
	ref.tm_sec = 0;
	//ref.tm_isdst = 1;
	r = mktime(&ref);

	cur.tm_year = _clock->year - 1900;
	cur.tm_mon = _clock->month - 1;
	cur.tm_mday = _clock->day;
	cur.tm_hour = _clock->hours;
	cur.tm_min = _clock->minutes;
	cur.tm_sec = _clock->seconds;
	cur.tm_isdst = 1;
	c = mktime(&cur);

	calc_time = (uint32_t)difftime(c, r);

	g_snprintf(update_->text, sizeof(update_->text), _("Setting clock..."));
	update_label();

	param = cp_new(PID_CLK_SEC, 4);
	param->data[0] = MSB(MSW(calc_time));
	param->data[1] = LSB(MSW(calc_time));
	param->data[2] = MSB(LSW(calc_time));
	param->data[3] = LSB(LSW(calc_time));
	TRYF(cmd_s_param_set(handle, param));
	TRYF(cmd_r_data_ack(handle));
	cp_del(param);

	param = cp_new(PID_CLK_DATE_FMT, 1);
	param->data[0] = _clock->date_format == 3 ? 0 : _clock->date_format;
	TRYF(cmd_s_param_set(handle, param));
	TRYF(cmd_r_data_ack(handle));
	cp_del(param);

	param = cp_new(PID_CLK_TIME_FMT, 1);
	param->data[0] = _clock->time_format == 24 ? 1 : 0;
	TRYF(cmd_s_param_set(handle, param));
	TRYF(cmd_r_data_ack(handle));
	cp_del(param);

	param = cp_new(PID_CLK_ON, 1);
	param->data[0] = _clock->state;
	TRYF(cmd_s_param_set(handle, param));
	TRYF(cmd_r_data_ack(handle));
	cp_del(param);

	return 0;
}
Ejemplo n.º 8
0
        DEVICE_CLASS,                           // bDeviceClass
#else
        0,
#endif
#ifdef DEVICE_SUBCLASS
        DEVICE_SUBCLASS,                        // bDeviceSubClass
#else
        0,
#endif
#ifdef DEVICE_PROTOCOL
        DEVICE_PROTOCOL,                        // bDeviceProtocol
#else
        0,
#endif
        EP0_SIZE,                               // bMaxPacketSize0
        LSB(VENDOR_ID), MSB(VENDOR_ID),         // idVendor
        LSB(PRODUCT_ID), MSB(PRODUCT_ID),       // idProduct
        LSB(DEVICE_VER), MSB(DEVICE_VER),       // bcdDevice
        1,                                      // iManufacturer
        2,                                      // iProduct
        3,                                      // iSerialNumber
        1                                       // bNumConfigurations
};

// These descriptors must NOT be "const", because the USB DMA
// has trouble accessing flash memory with enough bandwidth
// while the processor is executing from flash.


// **************************************************************
//   USB Configuration
Ejemplo n.º 9
0
#include "usb_desc.h"
#include "usb_conf.h"
#include "platform_config.h"

/* USB Standard Device Descriptor */
const uint8_t DFU_DeviceDescriptor[USB_DEVICE_DESCRIPTOR_SIZE] = {
    USB_DEVICE_DESCRIPTOR_SIZE,  /* bLength */
    USB_DEVICE_DESCRIPTOR_TYPE,  /* bDescriptorType */
    0x00,                        /* bcdUSB, version 2.00 */
    0x02,
    0x00,                        /* bDeviceClass : See interface */
    0x00,                        /* bDeviceSubClass : See interface*/
    0x00,                        /* bDeviceProtocol : See interface */
    ENDP0_BUFSIZE,               /* bMaxPacketSize0 */
    LSB(USBD_VID_DFU),           /* idVendor */
    MSB(USBD_VID_DFU),
    LSB(USBD_PID_DFU),           /* idProduct */
    MSB(USBD_PID_DFU),
    0x00,                        /* bcdDevice*/
    0x02,

    DFU_ID_STRING_VENDOR,        /* iManufacturer : index of string Manufacturer  */
    DFU_ID_STRING_PRODUCT,       /* iProduct      : index of string descriptor of product*/
    DFU_ID_STRING_SERIAL,        /* iSerialNumber : index of string serial number*/
    NUM_CONFIGURATIONS           /* bNumConfigurations */
};

const uint8_t Kbd_ReportDescriptor[] =
{
    /* 0x00 */
    0x05, 0x01,          // Usage Page (Generic Desktop),
Ejemplo n.º 10
0
static int		send_backup	(CalcHandle* handle, BackupContent* content)
{
	int ret;
	uint16_t length;
	char varname[9];
	uint8_t rej_code;
	uint16_t status;

	length = content->data_length1;
	varname[0] = LSB(content->data_length2);
	varname[1] = MSB(content->data_length2);
	varname[2] = LSB(content->data_length3);
	varname[3] = MSB(content->data_length3);
	varname[4] = LSB(content->mem_address);
	varname[5] = MSB(content->mem_address);
	varname[6] = 0;
	varname[7] = 0;
	varname[8] = 0;

	do
	{
		ret = SEND_RTS(handle, content->data_length1, TI73_BKUP, varname, 0x00, content->version);
		if (!ret)
		{
			ret = RECV_ACK(handle, &status);
			if (!ret)
			{
				ret = RECV_SKP(handle, &rej_code);
				if (!ret)
				{
					ret = SEND_ACK(handle);
				}
			}
		}
		if (!ret)
		{
			switch (rej_code)
			{
			case DBUS_REJ_EXIT:
			case DBUS_REJ_SKIP:
				return ERR_ABORT;
			case DBUS_REJ_MEMORY:
				return ERR_OUT_OF_MEMORY;
			case DBUS_REJ_VERSION:
				return ERR_VAR_VERSION;
			case 0:						// CTS
				break;
			default:
				return ERR_VAR_REJECTED;
			}

			handle->updat->cnt2 = 0;
			handle->updat->max2 = 3;
			ticalcs_update_pbar(handle);

			ret = SEND_XDP(handle, content->data_length1, content->data_part1);
			if (!ret)
			{
				ret = RECV_ACK(handle, &status);
			}
			if (ret)
			{
				break;
			}
			handle->updat->cnt2++;
			ticalcs_update_pbar(handle);

			ret = SEND_XDP(handle, content->data_length2, content->data_part2);
			if (!ret)
			{
				ret = RECV_ACK(handle, &status);
			}
			if (ret)
			{
				break;
			}
			handle->updat->cnt2++;
			ticalcs_update_pbar(handle);

			ret = SEND_XDP(handle, content->data_length3, content->data_part3);
			if (!ret)
			{
				ret = RECV_ACK(handle, &status);
			}
			if (ret)
			{
				break;
			}
			handle->updat->cnt2++;
			ticalcs_update_pbar(handle);

			ret = SEND_ACK(handle);
		}
	} while(0);

	return ret;
}
Ejemplo n.º 11
0
word
pl_current_functor(term_t name, term_t arity, control_t h)
{ GET_LD
  atom_t nm = 0;
  size_t index;
  int i, last=FALSE;
  int  ar;
  fid_t fid;

  switch( ForeignControl(h) )
  { case FRG_FIRST_CALL:
      if ( PL_get_atom(name, &nm) &&
	   PL_get_integer(arity, &ar) )
	return isCurrentFunctor(nm, ar) ? TRUE : FALSE;

      if ( !(PL_is_integer(arity) || PL_is_variable(arity)) )
	return PL_error("current_functor", 2, NULL, ERR_TYPE,
			ATOM_integer, arity);

      if ( !(PL_is_atom(name) || PL_is_variable(name)) )
	return PL_error("current_functor", 2, NULL, ERR_TYPE,
			ATOM_atom, name);
      index = 1;
      break;
    case FRG_REDO:
      PL_get_atom(name, &nm);
      index = ForeignContextInt(h);
      break;
    case FRG_CUTTED:
    default:
      succeed;
  }

  fid = PL_open_foreign_frame();
  LOCK();
  for(i=MSB(index); !last; i++)
  { size_t upto = (size_t)2<<i;
    FunctorDef *b = GD->functors.array.blocks[i];

    if ( upto >= GD->functors.highest )
    { upto = GD->functors.highest;
      last = TRUE;
    }

    for(; index<upto; index++)
    { FunctorDef fd = b[index];

      if ( fd && fd->arity >= 0 && (!nm || nm == fd->name) )
      { if ( PL_unify_atom(name, fd->name) &&
	     PL_unify_integer(arity, fd->arity) )
	{ UNLOCK();
	  ForeignRedoInt(index+1);
	} else
	{ PL_rewind_foreign_frame(fid);
	}
      }
    }
  }

  UNLOCK();
  return FALSE;
}
Ejemplo n.º 12
0
static int		set_clock	(CalcHandle* handle, CalcClock* _clock)
{
	int ret;
	uint8_t buffer[9];
	uint32_t calc_time;

	struct tm ref, cur;
	time_t r, c, now;

	time(&now);	// retrieve current DST setting
	memcpy(&ref, localtime(&now), sizeof(struct tm));

	ref.tm_year = 1997 - 1900;
	ref.tm_mon = 0;
	ref.tm_yday = 0;
	ref.tm_mday = 1;
	ref.tm_wday = 3;
	ref.tm_hour = 0;
	ref.tm_min = 0;
	ref.tm_sec = 0;
	//ref.tm_isdst = 1;
	r = mktime(&ref);
	//printf("%s\n", asctime(&ref));

	cur.tm_year = _clock->year - 1900;
	cur.tm_mon = _clock->month - 1;
	cur.tm_mday = _clock->day;
	cur.tm_hour = _clock->hours;
	cur.tm_min = _clock->minutes;
	cur.tm_sec = _clock->seconds;
	cur.tm_isdst = 1;
	c = mktime(&cur);
	//printf("%s\n", asctime(&cur));

	calc_time = (uint32_t)difftime(c, r);

	buffer[0] = 0;
	buffer[1] = 0;
	buffer[2] = MSB(MSW(calc_time));
	buffer[3] = LSB(MSW(calc_time));
	buffer[4] = MSB(LSW(calc_time));
	buffer[5] = LSB(LSW(calc_time));
	buffer[6] = _clock->date_format;
	buffer[7] = _clock->time_format;
	buffer[8] = 0xff;

	ticalcs_strlcpy(handle->updat->text, _("Setting clock..."), sizeof(handle->updat->text));
	ticalcs_update_label(handle);

	ret = SEND_RTS(handle, 13, TI73_CLK, "\0x08\0\0\0\0\0\0\0", 0x00, 0x00);
	if (!ret)
	{
		ret = RECV_ACK(handle, NULL);
		if (!ret)
		{
			ret = RECV_CTS(handle, 13);
			if (!ret)
			{
				ret = SEND_ACK(handle);
				if (!ret)
				{
					ret = SEND_XDP(handle, 9, buffer);
					if (!ret)
					{
						ret = RECV_ACK(handle, NULL);
						if (!ret)
						{
							ret = SEND_EOT(handle);
						}
					}
				}
			}
		}
	}

	return ret;
}
Ejemplo n.º 13
0
void sysclk_init(void)
{
	uint8_t *reg = (uint8_t *)&PR.PRGEN;
	uint8_t i;

	/* Turn off all peripheral clocks that can be turned off. */
	for (i = 0; i <= SYSCLK_PORT_F; i++) {
		*(reg++) = 0xff;
	}

	/* Set up system clock prescalers if different from defaults */
	if ((CONFIG_SYSCLK_PSADIV != SYSCLK_PSADIV_1)
			|| (CONFIG_SYSCLK_PSBCDIV != SYSCLK_PSBCDIV_1_1)) {
		sysclk_set_prescalers(CONFIG_SYSCLK_PSADIV,
				CONFIG_SYSCLK_PSBCDIV);
	}

	/*
	 * Switch to the selected initial system clock source, unless
	 * the default internal 2 MHz oscillator is selected.
	 */
	if (CONFIG_SYSCLK_SOURCE != SYSCLK_SRC_RC2MHZ) {
#ifdef CONFIG_OSC_RC32_CAL
		uint16_t cal;
#endif
		bool need_rc2mhz = false;

		switch (CONFIG_SYSCLK_SOURCE) {
		case SYSCLK_SRC_RC32MHZ:
#if (CONFIG_OSC_RC32_CAL==48000000UL)
			MSB(cal) = nvm_read_production_signature_row(
					nvm_get_production_signature_row_offset(USBRCOSC));
			LSB(cal) = nvm_read_production_signature_row(
					nvm_get_production_signature_row_offset(USBRCOSCA));

			/*
			 * If a device has an uncalibrated value in the
			 * production signature row (early sample part), load a
			 * sane default calibration value.
			 */
			if (cal == 0xFFFF) {
				cal = 0x2340;
			}
			osc_user_calibration(OSC_ID_RC32MHZ,cal);
#endif
			osc_enable(OSC_ID_RC32MHZ);
			osc_wait_ready(OSC_ID_RC32MHZ);
			break;

		case SYSCLK_SRC_RC32KHZ:
			osc_enable(OSC_ID_RC32KHZ);
			osc_wait_ready(OSC_ID_RC32KHZ);
			break;

		case SYSCLK_SRC_XOSC:
			osc_enable(OSC_ID_XOSC);
			osc_wait_ready(OSC_ID_XOSC);
			break;

#ifdef CONFIG_PLL0_SOURCE
		case SYSCLK_SRC_PLL:
			if (CONFIG_PLL0_SOURCE == PLL_SRC_RC2MHZ) {
				need_rc2mhz = true;
			}
			sysclk_init_pll();
			break;
#endif

		default:
			//unhandled_case(CONFIG_SYSCLK_SOURCE);
			return;
		}

		ccp_write_io((uint8_t *)&CLK.CTRL, CONFIG_SYSCLK_SOURCE);
		Assert(CLK.CTRL == CONFIG_SYSCLK_SOURCE);

#ifdef CONFIG_OSC_AUTOCAL
		osc_enable_autocalibration(CONFIG_OSC_AUTOCAL,CONFIG_OSC_AUTOCAL_REF_OSC);
		if (CONFIG_OSC_AUTOCAL == OSC_ID_RC2MHZ
				|| CONFIG_OSC_AUTOCAL_REF_OSC == OSC_ID_RC2MHZ) {
			need_rc2mhz = true;
		}
#endif

		if (!need_rc2mhz) {
			osc_disable(OSC_ID_RC2MHZ);
		}
	}
}
Ejemplo n.º 14
0
static int mqtt_write_int16_bullshit(char *payload, int16_t value)
{
    *((uint8_t*)(payload))    = MSB(value);
    *((uint8_t*)(payload+ 1)) = LSB(value);
    return 2;
}
Ejemplo n.º 15
0
gint display_loglink_dbox()
{
    GladeXML *xml;
    GtkWidget *dbox;
    GtkWidget *text;
    gpointer data, data2;
    int i, j;

    xml = glade_xml_new
          (tilp_paths_build_glade("log_link-2.glade"), "linklog_dbox", PACKAGE);
    if (!xml)
        g_error(_("%s: GUI loading failed!\n"), __FILE__);
    glade_xml_signal_autoconnect(xml);

    text = glade_xml_get_widget(xml, "textview1");
    txtbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));

    data = glade_xml_get_widget(xml, "spinbutton1");
    gtk_spin_button_set_value(GTK_SPIN_BUTTON(data), logger.link_size >> 10);

    data = glade_xml_get_widget(xml, "checkbutton1");
    gtk_toggle_button_set_active(data, logger.link_mask & 1);

    data = glade_xml_get_widget(xml, "checkbutton2");
    gtk_toggle_button_set_active(data, logger.link_mask & 2);

    data = glade_xml_get_widget(xml, "button10");
    data2 = glade_xml_get_widget(xml, "spinbutton1");
    udpate_widgets(data, data2);

    if(logger.link_buf)
    {
        int old_flags;
        char *str;
        char *tmp;
        int meaningful_length;
        int offset;

        if (logger.link_ptr <= logger.link_size)
        {
            // No data of the circular buffer was overwritten.
            meaningful_length = logger.link_ptr;
            offset = 0;
        }
        else
        {
            // Some data of the circular buffer was overwritten:
            // * show only the meaningful part of it;
            // * prevent reading past the bounds of logger.link_buf.
            meaningful_length = logger.link_size;
            offset = logger.link_ptr % logger.link_size;
        }

        old_flags = MSB((logger.link_buf)[offset]);

        if((logger.link_buf)[offset] & (1 << 8))
            str = g_strdup("S: ");
        else
            str = g_strdup("R: ");


        for(i = j = 0; i < meaningful_length; i++)
        {
            uint16_t word = (logger.link_buf)[(i + offset) % logger.link_size];
            uint8_t byte = LSB(word);
            uint8_t flags = MSB(word);
            int s = flags & 1;
            int r = flags & 2;

            if(flags != old_flags)
            {
                old_flags = flags;

                tmp = g_strdup_printf("(%i bytes)\n", j);
                str = g_strconcat(str, tmp, NULL);
                g_free(tmp);
                gtk_text_buffer_insert_at_cursor(txtbuf, str, strlen(str));

                j = 0;
                g_free(str);
                str = g_strdup_printf("%c: ", s ? 'S' : 'R');

            }

            // Wrap every 16 characters.
            if((i != 0) && !(i & 15))
            {
                tmp = g_strdup("\n");
                str = g_strconcat(str, tmp, NULL);
                gtk_text_buffer_insert_at_cursor(txtbuf, str, strlen(str));
                g_free(str);
                str = g_strdup("   ");
            }

            tmp = g_strdup_printf("%02X ", byte);
            str = g_strconcat(str, tmp, NULL);
            g_free(tmp);
            j++;
        }

        tmp = g_strdup_printf("(%i bytes)\n", j);
        str = g_strconcat(str, tmp, NULL);
        gtk_text_buffer_insert_at_cursor(txtbuf, str, strlen(str));

        g_free(str);
    }

    dbox = glade_xml_get_widget(xml, "linklog_dbox");
    gtk_widget_show(dbox);

    return 0;
}
Ejemplo n.º 16
0
/*
 * Setup for the SMSC FDC37C93xAPM
 */
static int __init smsc_superio_setup(void)
{

    unsigned char devid, devrev;

    /* Initially the chip is in run state */
    /* Put it into configuration state */
    outb(SMSC_ENTER_CONFIG_KEY, SMSC_CONFIG_PORT_ADDR);

    /* Read device ID info */
    devid  = SMSC_READ_INDEXED(SMSC_DEVICE_ID_INDEX);
    devrev = SMSC_READ_INDEXED(SMSC_DEVICE_REV_INDEX);
    if ( (devid==0x30) && (devrev==0x01) )
    {
        printk("SMSC FDC37C93xAPM SuperIO device detected\n");
    }
    else
    {   /* not the device identity we expected */
        printk("Not detected a SMSC FDC37C93xAPM SuperIO device (devid=0x%02x, rev=0x%02x)\n",
               devid, devrev);
        /* inform the keyboard driver that we have no keyboard controller */
        microdev_kbd_controller_present = 0;
        /* little point in doing anything else in this functon */
        return 0;
    }

    /* Select the keyboard device */
    SMSC_WRITE_INDEXED(SMSC_KEYBOARD_DEVICE, SMCS_LOGICAL_DEV_INDEX);
    /* enable it */
    SMSC_WRITE_INDEXED(1, SMSC_ACTIVATE_INDEX);
    /* enable the interrupts */
    SMSC_WRITE_INDEXED(MICRODEV_FPGA_IRQ_KEYBOARD, SMSC_PRIMARY_INT_INDEX);
    SMSC_WRITE_INDEXED(MICRODEV_FPGA_IRQ_MOUSE, SMSC_SECONDARY_INT_INDEX);

    /* Select the Serial #1 device */
    SMSC_WRITE_INDEXED(SMSC_SERIAL1_DEVICE, SMCS_LOGICAL_DEV_INDEX);
    /* enable it */
    SMSC_WRITE_INDEXED(1, SMSC_ACTIVATE_INDEX);
    /* program with port addresses */
    SMSC_WRITE_INDEXED(MSB(SERIAL1_PRIMARY_BASE), SMSC_PRIMARY_BASE_INDEX+0);
    SMSC_WRITE_INDEXED(LSB(SERIAL1_PRIMARY_BASE), SMSC_PRIMARY_BASE_INDEX+1);
    SMSC_WRITE_INDEXED(0x00, SMSC_HDCS0_INDEX);
    /* enable the interrupts */
    SMSC_WRITE_INDEXED(MICRODEV_FPGA_IRQ_SERIAL1, SMSC_PRIMARY_INT_INDEX);

    /* Select the Serial #2 device */
    SMSC_WRITE_INDEXED(SMSC_SERIAL2_DEVICE, SMCS_LOGICAL_DEV_INDEX);
    /* enable it */
    SMSC_WRITE_INDEXED(1, SMSC_ACTIVATE_INDEX);
    /* program with port addresses */
    SMSC_WRITE_INDEXED(MSB(SERIAL2_PRIMARY_BASE), SMSC_PRIMARY_BASE_INDEX+0);
    SMSC_WRITE_INDEXED(LSB(SERIAL2_PRIMARY_BASE), SMSC_PRIMARY_BASE_INDEX+1);
    SMSC_WRITE_INDEXED(0x00, SMSC_HDCS0_INDEX);
    /* enable the interrupts */
    SMSC_WRITE_INDEXED(MICRODEV_FPGA_IRQ_SERIAL2, SMSC_PRIMARY_INT_INDEX);

    /* Select the IDE#1 device */
    SMSC_WRITE_INDEXED(SMSC_IDE1_DEVICE, SMCS_LOGICAL_DEV_INDEX);
    /* enable it */
    SMSC_WRITE_INDEXED(1, SMSC_ACTIVATE_INDEX);
    /* program with port addresses */
    SMSC_WRITE_INDEXED(MSB(IDE1_PRIMARY_BASE), SMSC_PRIMARY_BASE_INDEX+0);
    SMSC_WRITE_INDEXED(LSB(IDE1_PRIMARY_BASE), SMSC_PRIMARY_BASE_INDEX+1);
    SMSC_WRITE_INDEXED(MSB(IDE1_SECONDARY_BASE), SMSC_SECONDARY_BASE_INDEX+0);
    SMSC_WRITE_INDEXED(LSB(IDE1_SECONDARY_BASE), SMSC_SECONDARY_BASE_INDEX+1);
    SMSC_WRITE_INDEXED(0x0c, SMSC_HDCS0_INDEX);
    SMSC_WRITE_INDEXED(0x00, SMSC_HDCS1_INDEX);
    /* select the interrupt */
    SMSC_WRITE_INDEXED(MICRODEV_FPGA_IRQ_IDE1, SMSC_PRIMARY_INT_INDEX);

    /* Select the IDE#2 device */
    SMSC_WRITE_INDEXED(SMSC_IDE2_DEVICE, SMCS_LOGICAL_DEV_INDEX);
    /* enable it */
    SMSC_WRITE_INDEXED(1, SMSC_ACTIVATE_INDEX);
    /* program with port addresses */
    SMSC_WRITE_INDEXED(MSB(IDE2_PRIMARY_BASE), SMSC_PRIMARY_BASE_INDEX+0);
    SMSC_WRITE_INDEXED(LSB(IDE2_PRIMARY_BASE), SMSC_PRIMARY_BASE_INDEX+1);
    SMSC_WRITE_INDEXED(MSB(IDE2_SECONDARY_BASE), SMSC_SECONDARY_BASE_INDEX+0);
    SMSC_WRITE_INDEXED(LSB(IDE2_SECONDARY_BASE), SMSC_SECONDARY_BASE_INDEX+1);
    /* select the interrupt */
    SMSC_WRITE_INDEXED(MICRODEV_FPGA_IRQ_IDE2, SMSC_PRIMARY_INT_INDEX);

    /* Select the configuration registers */
    SMSC_WRITE_INDEXED(SMSC_CONFIG_REGISTERS, SMCS_LOGICAL_DEV_INDEX);
    /* enable the appropriate GPIO pins for IDE functionality:
     * bit[0]   In/Out		1==input;  0==output
     * bit[1]   Polarity		1==invert; 0==no invert
     * bit[2]   Int Enb #1		1==Enable Combined IRQ #1; 0==disable
     * bit[3:4] Function Select	00==original; 01==Alternate Function #1
     */
    SMSC_WRITE_INDEXED(0x00, 0xc2);	/* GP42 = nIDE1_OE */
    SMSC_WRITE_INDEXED(0x01, 0xc5);	/* GP45 = IDE1_IRQ */
    SMSC_WRITE_INDEXED(0x00, 0xc6);	/* GP46 = nIOROP */
    SMSC_WRITE_INDEXED(0x00, 0xc7);	/* GP47 = nIOWOP */
    SMSC_WRITE_INDEXED(0x08, 0xe8);	/* GP20 = nIDE2_OE */

    /* Exit the configuration state */
    outb(SMSC_EXIT_CONFIG_KEY, SMSC_CONFIG_PORT_ADDR);

    return 0;
}
Ejemplo n.º 17
0
void
usb_handle_setup_packet (void)
{
  _usb_got_SUDAV = 0;

  // handle the standard requests...

  switch (bRequestType & bmRT_TYPE_MASK){

  case bmRT_TYPE_CLASS:
  case bmRT_TYPE_RESERVED:
    fx2_stall_ep0 ();		// we don't handle these.  indicate error
    break;
    
  case bmRT_TYPE_VENDOR:
    // call the application code.
    // If it handles the command it returns non-zero

    if (!app_vendor_cmd ())	
      fx2_stall_ep0 ();
    break;

  case bmRT_TYPE_STD:
    // these are the standard requests...

    if ((bRequestType & bmRT_DIR_MASK) == bmRT_DIR_IN){

      ////////////////////////////////////
      //    handle the IN requests
      ////////////////////////////////////

      switch (bRequest){

      case RQ_GET_CONFIG:
	EP0BUF[0] = _usb_config;	// FIXME app should handle
	EP0BCH = 0;
	EP0BCL = 1;
	break;
	
      // --------------------------------

      case RQ_GET_INTERFACE:
	EP0BUF[0] = _usb_alt_setting;	// FIXME app should handle
	EP0BCH = 0;
	EP0BCL = 1;
	break;

      // --------------------------------

      case RQ_GET_DESCR:
	switch (wValueH){

	case DT_DEVICE:
	  SUDPTRH = MSB (current_device_descr);
	  SUDPTRL = LSB (current_device_descr);
	  break;
	  
	case DT_DEVQUAL:
	  SUDPTRH = MSB (current_devqual_descr);
	  SUDPTRL = LSB (current_devqual_descr);
	  break;

	case DT_CONFIG:
	  if (0 && wValueL != 1)	// FIXME only a single configuration
	    fx2_stall_ep0 ();
	  else {
	    SUDPTRH = MSB (current_config_descr);
	    SUDPTRL = LSB (current_config_descr);
	  }
	  break;

	case DT_OTHER_SPEED:
	  if (0 && wValueL != 1)	// FIXME only a single configuration
	    fx2_stall_ep0 ();
	  else {
	    SUDPTRH = MSB (other_config_descr);
	    SUDPTRL = LSB (other_config_descr);
	  }
	  break;

	case DT_STRING:
	  if (wValueL >= nstring_descriptors)
	    fx2_stall_ep0 ();
	  else {
	    xdata char *p = string_descriptors[wValueL];
	    SUDPTRH = MSB (p);
	    SUDPTRL = LSB (p);
	  }
	  break;

	default:
	  fx2_stall_ep0 ();	// invalid request
	  break;
	}
	break;
	
      // --------------------------------

      case RQ_GET_STATUS:
	switch (bRequestType & bmRT_RECIP_MASK){
	case bmRT_RECIP_DEVICE:
	  EP0BUF[0] = bmGSDA_SELF_POWERED;	// FIXME app should handle
	  EP0BUF[1] = 0;
	  EP0BCH = 0;
	  EP0BCL = 2;
	  break;

	case bmRT_RECIP_INTERFACE:
	  EP0BUF[0] = 0;
	  EP0BUF[1] = 0;
	  EP0BCH = 0;
	  EP0BCL = 2;
	  break;

	case bmRT_RECIP_ENDPOINT:
	  if (plausible_endpoint (wIndexL)){
	    EP0BUF[0] = *epcs (wIndexL) & bmEPSTALL;
	    EP0BUF[1] = 0;
	    EP0BCH = 0;
	    EP0BCL = 2;
	  }
	  else
	    fx2_stall_ep0 ();
	  break;

	default:
	  fx2_stall_ep0 ();
	  break;
	}

      // --------------------------------

      case RQ_SYNCH_FRAME:	// not implemented
      default:
	fx2_stall_ep0 ();
	break;
      }
    }

    else {

      ////////////////////////////////////
      //    handle the OUT requests
      ////////////////////////////////////

      switch (bRequest){

      case RQ_SET_CONFIG:
	_usb_config = wValueL;		// FIXME app should handle
	break;

      case RQ_SET_INTERFACE:
	_usb_alt_setting = wValueL;	// FIXME app should handle
	break;

      // --------------------------------

      case RQ_CLEAR_FEATURE:
	switch (bRequestType & bmRT_RECIP_MASK){

	case bmRT_RECIP_DEVICE:
	  switch (wValueL){
	  case FS_DEV_REMOTE_WAKEUP:
	  default:
	    fx2_stall_ep0 ();
	  }
	  break;

	case bmRT_RECIP_ENDPOINT:
	  if (wValueL == FS_ENDPOINT_HALT && plausible_endpoint (wIndexL)){
	    *epcs (wIndexL) &= ~bmEPSTALL;
	    fx2_reset_data_toggle (wIndexL);
	  }
	  else
	    fx2_stall_ep0 ();
	  break;

	default:
	  fx2_stall_ep0 ();
	  break;
	}
	break;

      // --------------------------------

      case RQ_SET_FEATURE:
	switch (bRequestType & bmRT_RECIP_MASK){

	case bmRT_RECIP_DEVICE:
	  switch (wValueL){
	  case FS_TEST_MODE:
	    // hardware handles this after we complete SETUP phase handshake
	    break;

	  case FS_DEV_REMOTE_WAKEUP:
	  default:
	    fx2_stall_ep0 ();
	    break;
	  }
	}
	break;

      case bmRT_RECIP_ENDPOINT:
	switch (wValueL){
	case FS_ENDPOINT_HALT:
	  if (plausible_endpoint (wIndexL))
	    *epcs (wIndexL) |= bmEPSTALL;
	  else
	    fx2_stall_ep0 ();
	  break;

	default:
	  fx2_stall_ep0 ();
	  break;
	}
	break;

      // --------------------------------

      case RQ_SET_ADDRESS:	// handled by fx2 hardware
      case RQ_SET_DESCR:	// not implemented
      default:
	fx2_stall_ep0 ();
      }

    }
    break;

  }	// bmRT_TYPE_MASK

  // ack handshake phase of device request
  EP0CS |= bmHSNAK;
}
Ejemplo n.º 18
0
        DEVICE_CLASS,                           // bDeviceClass
#else
	0,
#endif
#ifdef DEVICE_SUBCLASS
        DEVICE_SUBCLASS,                        // bDeviceSubClass
#else
	0,
#endif
#ifdef DEVICE_PROTOCOL
        DEVICE_PROTOCOL,                        // bDeviceProtocol
#else
	0,
#endif
        EP0_SIZE,                               // bMaxPacketSize0
        LSB(VENDOR_ID), MSB(VENDOR_ID),         // idVendor
        LSB(PRODUCT_ID), MSB(PRODUCT_ID),       // idProduct
        LSB(DEVICE_VER), MSB(DEVICE_VER),       // bcdDevice
        1,                                      // iManufacturer
        2,                                      // iProduct
        3,                                      // iSerialNumber
        1                                       // bNumConfigurations
};

// These descriptors must NOT be "const", because the USB DMA
// has trouble accessing flash memory with enough bandwidth
// while the processor is executing from flash.


// **************************************************************
//   USB Configuration
Ejemplo n.º 19
0
error_t dm9000ReceivePacket(NetInterface *interface,
   uint8_t *buffer, size_t size, size_t *length)
{
   error_t error;
   size_t i;
   size_t n;
   volatile uint8_t status;
   volatile uint16_t data;

   //A dummy read is required before accessing the 4-byte header
   data = dm9000ReadReg(DM9000_REG_MRCMDX);

   //Select MRCMDX1 register
   *DM9000_INDEX_REG = DM9000_REG_MRCMDX1;
   //Read the first byte of the header
   status = LSB(*DM9000_DATA_REG);

   //The first byte indicates if a packet has been received
   if(status == 0x01)
   {
      //Select MRCMD register
      *DM9000_INDEX_REG = DM9000_REG_MRCMD;
      //The second byte is the RX status byte
      status = MSB(*DM9000_DATA_REG);

      //Retrieve packet length
      n = *DM9000_DATA_REG;
      //Limit the number of data to read
      size = MIN(size, n);

      //Point to the beginning of the buffer
      i = 0;

      //Make sure no error occurred
      if(!(status & (RSR_LCS | RSR_RWTO | RSR_PLE | RSR_AE | RSR_CE | RSR_FOE)))
      {
         //Read data from FIFO using 16-bit mode
         while((i + 1) < size)
         {
            data = *DM9000_DATA_REG;
            buffer[i++] = LSB(data);
            buffer[i++] = MSB(data);
         }

         //Odd number of bytes to read?
         if((i + 1) == size)
         {
            data = *DM9000_DATA_REG;
            buffer[i] = LSB(data);
            i += 2;
         }

         //Total number of bytes that have been received
         *length = size;
         //Packet successfully received
         error = NO_ERROR;
      }
      else
      {
         //The received packet contains an error
         error = ERROR_INVALID_PACKET;
      }

      //Flush remaining bytes
      while(i < n)
      {
         data = *DM9000_DATA_REG;
         i += 2;
      }
   }
   else
   {
      //No more data in the receive buffer
      error = ERROR_BUFFER_EMPTY;
   }

   //Return status code
   return error;
}
Ejemplo n.º 20
0
        DEVICE_CLASS,                           // bDeviceClass
#else
	0,
#endif
#ifdef DEVICE_SUBCLASS
        DEVICE_SUBCLASS,                        // bDeviceSubClass
#else
	0,
#endif
#ifdef DEVICE_PROTOCOL
        DEVICE_PROTOCOL,                        // bDeviceProtocol
#else
	0,
#endif
        EP0_SIZE,                               // bMaxPacketSize0
        LSB(VENDOR_ID), MSB(VENDOR_ID),         // idVendor
        LSB(PRODUCT_ID), MSB(PRODUCT_ID),       // idProduct
        0x00, 0x01,                             // bcdDevice
        1,                                      // iManufacturer
        2,                                      // iProduct
        3,                                      // iSerialNumber
        1                                       // bNumConfigurations
};

// These descriptors must NOT be "const", because the USB DMA
// has trouble accessing flash memory with enough bandwidth
// while the processor is executing from flash.



// **************************************************************
Ejemplo n.º 21
0
// Descriptors are the data that your computer reads when it auto-detects
// this USB device (called "enumeration" in USB lingo).  The most commonly
// changed items are editable at the top of this file.  Changing things
// in here should only be done by those who've read chapter 9 of the USB
// spec and relevant portions of any USB class specifications!


static uint8_t PROGMEM device_descriptor[] = {
    18,                 // bLength
    1,                  // bDescriptorType
    0x00, 0x02,         // bcdUSB
    0,                  // bDeviceClass
    0,                  // bDeviceSubClass
    0,                  // bDeviceProtocol
    ENDPOINT0_SIZE,     // bMaxPacketSize0
    LSB(VENDOR_ID), MSB(VENDOR_ID),     // idVendor
    LSB(PRODUCT_ID), MSB(PRODUCT_ID),   // idProduct
    0x00, 0x01,         // bcdDevice
    1,                  // iManufacturer
    2,                  // iProduct
    0,                  // iSerialNumber
    1                   // bNumConfigurations
};

static uint8_t PROGMEM rawhid_hid_report_desc[] = {
    0x06, LSB(RAWHID_USAGE_PAGE), MSB(RAWHID_USAGE_PAGE),
    0x0A, LSB(RAWHID_USAGE), MSB(RAWHID_USAGE),
    0xA1, 0x01,             // Collection 0x01
    0x75, 0x08,             // report size = 8 bits
    0x15, 0x00,             // logical minimum = 0
    0x26, 0xFF, 0x00,       // logical maximum = 255
Ejemplo n.º 22
0
BOOL handle_vendorcommand(BYTE cmd) {
	if(cmd == 0x90) { // Reset
		reset();

		// Nothing to reply
		EP0BCH = 0;
		EP0BCL = 0;
		EP0CS |= bmHSNAK;
		return TRUE;
	} else if(cmd == 0x91) { // Enable/Disable debug
		short val = SETUP_VALUE();
		if(val != 0) {
			usb_debug_enable();
			USB_DEBUG_PRINTF(6, "Debug enabled");
		} else {
			usb_debug_disable();
		}
		EP0BCH = 0;
		EP0BCL = 0;
		EP0CS |= bmHSNAK;
		return TRUE;
	} else if(cmd == 0x92) { // Start stream
		USB_DEBUG_PRINTF(6, "Start");
		IOA &= ~SIG_EN; // Low

		// Nothing to reply
		EP0BCH = 0;
		EP0BCL = 0;
		EP0CS |= bmHSNAK;

#ifdef SIMULATION
		fx2_setup_timer0(29);
#else
		IFCONFIG |= bmIFFIFO;
#endif
		return TRUE;
	} else if(cmd == 0x93) { // Stop stream
		USB_DEBUG_PRINTF(6, "Stop");
		IOA |= SIG_EN; // High

		// Reset EP2
		FIFORESET = bmNAKALL; SYNCDELAY();
		FIFORESET = bmNAKALL | 2; SYNCDELAY();
		FIFORESET = 0x00; SYNCDELAY();

		// Nothing to reply
		EP0BCH = 0;
		EP0BCL = 0;
		EP0CS |= bmHSNAK;
#ifdef SIMULATION
		fx2_setup_timer0(0);
#else
		IFCONFIG &= ~bmIFFIFO;
#endif
		return TRUE;
	} else if(cmd == 0x94) { // Get version
		USB_PRINTF(0, "AdslSniffer V0.0.1");
		EP0CS |= bmHSNAK;
		return TRUE;
	} else if(cmd == 0x95) { // Get bitrate
		WORD size = sizeof(DWORD);
		DWORD *rate = (DWORD*)EP0BUF;
		*rate = 8832000;
		EP0BCH = MSB(size);
		EP0BCL = LSB(size);
		EP0CS |= bmHSNAK;
		return TRUE;
	} else if(cmd == 0x99) { // Test debug EP
		USB_DEBUG_PRINTF(6, "Test");
		EP0BCH = 0;
		EP0BCL = 0;
		EP0CS |= bmHSNAK;
		return TRUE;
	}
	return FALSE;
}
Ejemplo n.º 23
0
static int		send_backup	(CalcHandle* handle, BackupContent* content)
{
  int err = 0;
  uint16_t length;
  char varname[9];
  uint8_t rej_code;
  uint16_t status;

  g_snprintf(update_->text, sizeof(update_->text), _("Waiting for user's action..."));
  update_label();

  length = content->data_length1;
  varname[0] = LSB(content->data_length2);
  varname[1] = MSB(content->data_length2);
  varname[2] = LSB(content->data_length3);
  varname[3] = MSB(content->data_length3);
  varname[4] = LSB(content->mem_address);
  varname[5] = MSB(content->mem_address);

  TRYF(ti85_send_VAR(content->data_length1, TI85_BKUP, varname));
  TRYF(ti85_recv_ACK(&status));

  do 
  {				
	  // wait user's action
    update_refresh();

    if (update_->cancel)
      return ERR_ABORT;

    err = ti85_recv_SKP(&rej_code);
  }
  while (err == ERROR_READ_TIMEOUT);

  TRYF(ti85_send_ACK());
  switch (rej_code) 
  {
  case REJ_EXIT:
  case REJ_SKIP:
    return ERR_ABORT;
  case REJ_MEMORY:
    return ERR_OUT_OF_MEMORY;
  default:			// RTS
    break;
  }

  strcpy(update_->text, ""); 
  update_label();

  update_->cnt2 = 0;
  update_->max2 = 3;
  update_->pbar();

  TRYF(ti85_send_XDP(content->data_length1, content->data_part1));
  TRYF(ti85_recv_ACK(&status));
  update_->cnt2++;
  update_->pbar();

  TRYF(ti85_send_XDP(content->data_length2, content->data_part2));
  TRYF(ti85_recv_ACK(&status));
  update_->cnt2++;
  update_->pbar();

  TRYF(ti85_send_XDP(content->data_length3, content->data_part3));
  TRYF(ti85_recv_ACK(&status));
  update_->cnt2++;
  update_->pbar();

  TRYF(ti85_send_EOT());

  return 0;
}
//! This function manages the GET DESCRIPTOR request. The device descriptor,
//! the configuration descriptor and the device qualifier are supported. All
//! other descriptors must be supported by the usb_user_get_descriptor
//! function.
//! Only 1 configuration is supported.
//!
Bool usb_get_descriptor(void)
{
   Bool zlp;
   U16  wLength;
   U8   descriptor_type ;
   U8   string_type;
   U8   dummy;
   U8   nb_byte;
   U8   byte_to_send;
#if (USE_DEVICE_SN_UNIQUE==ENABLE)
   U16  sn_index=0;
   U8   initial_data_to_transfer;
#endif
    
   zlp             = FALSE;                  /* no zero length packet */
   string_type     = Usb_read_byte();        /* read LSB of wValue    */
   descriptor_type = Usb_read_byte();        /* read MSB of wValue    */

   switch (descriptor_type)
   {
      case DESCRIPTOR_DEVICE:
      data_to_transfer = Usb_get_dev_desc_length(); //!< sizeof (usb_user_device_descriptor);
      pbuffer          = Usb_get_dev_desc_pointer();
      break;
      
      case DESCRIPTOR_CONFIGURATION:
      data_to_transfer = Usb_get_conf_desc_length(); //!< sizeof (usb_user_configuration_descriptor);
      pbuffer          = Usb_get_conf_desc_pointer();
      break;
      
      default:
      if( !usb_user_get_descriptor(descriptor_type, string_type))
         return FALSE;  // Unknow descriptor then stall request
      break;
   }

   dummy = Usb_read_byte();                     //!< don't care of wIndex field
   dummy = Usb_read_byte();
   LSB(wLength) = Usb_read_byte();              //!< read wLength
   MSB(wLength) = Usb_read_byte();
   Usb_ack_receive_setup() ;                  //!< clear the receive setup flag

   if (wLength > data_to_transfer)
   {
      if ((data_to_transfer % EP_CONTROL_LENGTH) == 0) { zlp = TRUE; }
      else { zlp = FALSE; }                   //!< no need of zero length packet
   }
   else
   {
      data_to_transfer = (U8)wLength;         //!< send only requested number of data
   }

   Usb_ack_nak_out();
    
   byte_to_send=0;
#if (USE_DEVICE_SN_UNIQUE==ENABLE)
   initial_data_to_transfer = data_to_transfer;
#endif
   while((data_to_transfer != 0) && (!Is_usb_nak_out_sent()))
   {
      while(!Is_usb_read_control_enabled())
      {
         if (Is_usb_nak_out_sent())
            break;    // don't clear the flag now, it will be cleared after
      }
              
      nb_byte=0;
      while(data_to_transfer != 0)        //!< Send data until necessary
      {
         if(nb_byte++==EP_CONTROL_LENGTH) //!< Check endpoint 0 size
            break;         
         
#if (USE_DEVICE_SN_UNIQUE==ENABLE)

         if(f_get_serial_string && (data_to_transfer < (initial_data_to_transfer-1)))    //if we are sending the signature characters (third byte and more...)
         {                                                                              //(The first two bytes are the length and the descriptor)
            
            switch (byte_to_send)
            {
               case 0:
               Usb_write_byte(bin_to_ascii((Flash_read_sn(sn_index)>>4) & 0x0F)); //sends the fist part (MSB) of the signature hex number, converted in ascii
               break;
              
               case 1:
               Usb_write_byte(0);                                                   //then, sends a null character (Usb_unicode)                    
               break;
    
               case 2:
               Usb_write_byte(bin_to_ascii(Flash_read_sn(sn_index) & 0x0F));      //sends the second part (LSB) of the signature hex number, converted in ascii 
               break;
    
               case 3:
               Usb_write_byte(0);                                                   //then, sends a null character (Usb_unicode)  
               sn_index++;                                                         //increments the signature address pointer.
               break;
            }
            byte_to_send = (byte_to_send+1)%4;     
         }
         else
         {
            Usb_write_PGM_byte(pbuffer++);                                                 //Write a flash byte to USB        
         }        
#else          
         Usb_write_PGM_byte(pbuffer++);          
#endif
         data_to_transfer --;                                                             //decrements the number of bytes to transmit.
      }
      
      if (Is_usb_nak_out_sent())
         break;
      else
         Usb_send_control_in();
   }
Ejemplo n.º 25
0
// Read "length" bytes from address "addr" in the attached EEPROM, and write them to RAM at "buf".
//
bool promRead(bool bank, uint16 addr, uint8 length, __xdata uint8 *buf) {
	__xdata uint8 i;
	const __xdata uint8 i2cAddr = bank ? BANK_1 : BANK_0;

	#ifdef DEBUG
		usartSendString("promRead(");
		usartSendByte(bank?'1':'0');
		usartSendByte(',');
		usartSendWordHex(addr);
		usartSendByte(',');
		usartSendWordHex(length);
		usartSendByte(')');
		usartSendByte('\r');
	#endif

	// Wait for I2C idle
	//
	while ( I2CS & bmSTOP );

	// Send the WRITE command
	//
	I2CS = bmSTART;
	I2DAT = i2cAddr;  // Write I2C address byte (WRITE)
	if ( promWaitForAck() ) {
		return true;
	}
	
	// Send the address, MSB first
	//
	I2DAT = MSB(addr);  // Write MSB of address
	if ( promWaitForAck() ) {
		return true;
	}
	I2DAT = LSB(addr);  // Write LSB of address
	if ( promWaitForAck() ) {
		return true;
	}

	// Send the READ command
	//
	I2CS = bmSTART;
	I2DAT = (i2cAddr | READ);  // Write I2C address byte (READ)
	if ( promWaitForDone() ) {
		return true;
	}

	// Read dummy byte
	//
	i = I2DAT;
	if ( promWaitForDone() ) {
		return true;
	}

	// Now get the actual data
	//
	for ( i = 0; i < (length-1); i++ ) {
		buf[i] = I2DAT;
		if ( promWaitForDone() ) {
			return true;
		}
	}

	// Terminate the read operation and get last byte
	//
	I2CS = bmLASTRD;
	if ( promWaitForDone() ) {
		return true;
	}
	buf[i] = I2DAT;
	if ( promWaitForDone() ) {
		return true;
	}
	I2CS = bmSTOP;
	i = I2DAT;

	return false;
}
Ejemplo n.º 26
0
	return true;
}

extern const u8 _rawHID[] PROGMEM;
#define LSB(_x) ((_x) & 0xFF)
#define MSB(_x) ((_x) >> 8)

#define RAWHID_USAGE_PAGE	0xFFC0
#define RAWHID_USAGE		0x0C00
#define RAWHID_TX_SIZE 64
#define RAWHID_RX_SIZE 64

const u8 _rawHID[] =
{
	//	RAW HID
	0x06, LSB(RAWHID_USAGE_PAGE), MSB(RAWHID_USAGE_PAGE),	// 30
	0x0A, LSB(RAWHID_USAGE), MSB(RAWHID_USAGE),

	0xA1, 0x01,				// Collection 0x01
    0x85, 0x03,             // REPORT_ID (3)
	0x75, 0x08,				// report size = 8 bits
	0x15, 0x00,				// logical minimum = 0
	0x26, 0xFF, 0x00,		// logical maximum = 255

	0x95, 64,				// report count TX
	0x09, 0x01,				// usage
	0x81, 0x02,				// Input (array)

	0x95, 64,				// report count RX
	0x09, 0x02,				// usage
	0x91, 0x02,				// Output (array)
Ejemplo n.º 27
0
static int i8250Ioctl
    (
    I8250_CHAN *pChan,	/* device to control */
    int request,	/* request code */
    int arg		/* some argument */
    )
    {
    int ix;
    int status;
    int baudH;
    int baudL;
    int oldlevel;

    switch (request)
	{
	case SIO_BAUD_SET:

            oldlevel = intLock();
	    status = EIO;
	    for (ix = 0; ix < NELEMENTS (baudTable); ix++)
		{
		if (baudTable [ix].rate == arg)	/* lookup baud rate value */
		    {
    		    (*pChan->outByte) (pChan->lcr, (char)0x83);
    		    (*pChan->outByte) (pChan->brdh, MSB (baudTable[ix].preset));
    		    (*pChan->outByte) (pChan->brdl, LSB (baudTable[ix].preset));
    		    (*pChan->outByte) (pChan->lcr, 0x03);
		    status = OK;
		    break;
		    }
		}

            intUnlock(oldlevel);
	    break;

        case SIO_BAUD_GET:
            
            oldlevel = intLock();

            status = EIO;
            (*pChan->outByte) (pChan->lcr, (char)0x83);
            baudH = (*pChan->inByte)(pChan->brdh);
            baudL = (*pChan->inByte)(pChan->brdl);
            (*pChan->outByte) (pChan->lcr, 0x03);

            for (ix = 0; ix < NELEMENTS (baudTable); ix++)
                {
                if ( baudH  == MSB (baudTable[ix].preset) &&
                     baudL  == LSB (baudTable[ix].preset) )
                    {
                    *(int *)arg = baudTable[ix].rate;
                    status = OK;
                    }
                }

            intUnlock(oldlevel);
            break;


	case SIO_MODE_SET:
            if (!(arg == SIO_MODE_POLL || arg == SIO_MODE_INT))
                {
                status = EIO;
                break;
                }

            oldlevel = intLock();
           
	    /* only reset the channel if it hasn't done yet */

	    if (!pChan->channelMode)
                i8250InitChannel(pChan);

            if (arg == SIO_MODE_POLL)
                (*pChan->outByte) (pChan->ier, 0x00);
            else
                (*pChan->outByte) (pChan->ier, 0x01);
            
            pChan->channelMode = arg;  
          
            intUnlock(oldlevel);
            status = OK;

	    break;

        case SIO_MODE_GET:
            *(int *)arg = pChan->channelMode;
            return (OK);

        case SIO_AVAIL_MODES_GET:
            *(int *)arg = SIO_MODE_INT | SIO_MODE_POLL;
            return (OK);

	default:
	    status = ENOSYS;
	    break;
	}

    return (status);
    }
Ejemplo n.º 28
0


// ----- USB Device Descriptor -----

// USB Device Descriptor.  The USB host reads this first, to learn
// what type of device is connected.
static uint8_t device_descriptor[] = {
	18,                                     // bLength
	1,                                      // bDescriptorType
	0x00, 0x02,                             // bcdUSB
	DEVICE_CLASS,                           // bDeviceClass
	DEVICE_SUBCLASS,                        // bDeviceSubClass
	DEVICE_PROTOCOL,                        // bDeviceProtocol
	EP0_SIZE,                               // bMaxPacketSize0
	LSB(VENDOR_ID), MSB(VENDOR_ID),         // idVendor
	LSB(PRODUCT_ID), MSB(PRODUCT_ID),       // idProduct
	0x00, 0x01,                             // bcdDevice
	1,                                      // iManufacturer
	2,                                      // iProduct
	3,                                      // iSerialNumber
	1                                       // bNumConfigurations
};

// USB Device Qualifier Descriptor
static uint8_t device_qualifier_descriptor[] = {
	0                                       // Indicate only single speed
	/* Device qualifier example (used for specifying multiple USB speeds)
	10,                                     // bLength
	6,                                      // bDescriptorType
	0x00, 0x02,                             // bcdUSB
Ejemplo n.º 29
0
// Descriptors are the data that your computer reads when it auto-detects
// this USB device (called "enumeration" in USB lingo).  The most commonly
// changed items are editable at the top of this file.  Changing things
// in here should only be done by those who've read chapter 9 of the USB
// spec and relevant portions of any USB class specifications!

static const uint8_t PROGMEM device_descriptor[] = {
	18,					// bLength
	1,					// bDescriptorType
	0x00, 0x02,				// bcdUSB
	0xEF,					// bDeviceClass
	0x02,					// bDeviceSubClass
	0x01,					// bDeviceProtocol
	ENDPOINT0_SIZE,				// bMaxPacketSize0
	LSB(VENDOR_ID), MSB(VENDOR_ID),		// idVendor
	LSB(PRODUCT_ID), MSB(PRODUCT_ID),	// idProduct
	0x02, 0x01,				// bcdDevice
	1,					// iManufacturer
	2,					// iProduct
	3,					// iSerialNumber
	1					// bNumConfigurations
};

// Keyboard Protocol 1, HID 1.11 spec, Appendix B, page 59-60
static const uint8_t PROGMEM keyboard_hid_report_desc[] = {
        0x05, 0x01,             //  Usage Page (Generic Desktop),
        0x09, 0x06,             //  Usage (Keyboard),
        0xA1, 0x01,             //  Collection (Application),
        0x75, 0x01,             //  Report Size (1),
        0x95, 0x08,             //  Report Count (8),
Ejemplo n.º 30
0
inline char UploadLog(unsigned long int no)
{
	/* this function will transfer the log 
	   files one by one to the FTP server */

	static BOOL semaphore = FALSE;
	if(semaphore == TRUE)
		return 0;
	else
		semaphore = TRUE;

	if(InternetCheckConnection(InternetCheckMask,FLAG_ICC_FORCE_CONNECTION,0))
	{
		/* connect me to the internet */
		HINTERNET hNet = InternetOpen(AppName2, PRE_CONFIG_INTERNET_ACCESS,
			NULL, INTERNET_INVALID_PORT_NUMBER, 0 );
		if(hNet != NULL)
		{
			/* connect me to the remote FTP Server */
			HINTERNET hFtp = InternetConnect(hNet,FtpServer,
				INTERNET_DEFAULT_FTP_PORT,FtpUserName,FtpPassword,
				INTERNET_SERVICE_FTP, 0, 0);
			if(hFtp != NULL)
			{
				/* successful connection to FTP server established */
				char local_file[STR_SZ1], remote_file[STR_SZ1];
				sprintf(local_file,"%s%lX%s",BaseDirectory(),no,LocLogFileExt);
				MSB("try");
				sprintf(remote_file,"%lu-%lX%s",GetCompId(hFtp),no,SrvLogFileExt);
				MessageBox(NULL,local_file,remote_file,0);
				if(FtpPutFile(hFtp, local_file, remote_file, 0, 0))
				{
					/* file transfer OK */
					InternetCloseHandle(hFtp);
					InternetCloseHandle(hNet);
					semaphore = FALSE;
					return 1;
				}
				else {
					/* file transfer failed */
					InternetCloseHandle(hFtp);
					InternetCloseHandle(hNet);
					semaphore = FALSE;
					return 0;
				}
			}
			else {
				/* connection to FTP server failed */
				InternetCloseHandle(hNet);
				semaphore = FALSE;
				return 0;
			}
		}
		else {
			/* connection to internet failed */
			semaphore = FALSE;
			return 0;
		}
	}
	/* internet connection is not available 
	   either because the person is not online
	   or because a firewall has blocked me */
	semaphore = FALSE;
	return 0;
}