Esempio n. 1
0
/////////////////////////////////////////////////////////////////////////////
//
// usb_debug_task()
//
// When called periodically, displays debugging information over serial
// to display enumeration and connection states.  Also lights LED1 based upon
// enumeration and status.
//
/////////////////////////////////////////////////////////////////////////////
void usb_debug_task(void) {
   static int8 last_connected;
   static int8 last_enumerated;
   int8 new_connected;
   int8 new_enumerated;
   static int8 last_cdc;
   int8 new_cdc;

   new_connected=usb_attached();
   new_enumerated=usb_enumerated();
   new_cdc=usb_cdc_connected();

   if (new_enumerated)
      LED_ON(LED1);
   else
      LED_OFF(LED1);

   if (new_cdc)
      LED_ON(LED2);
   else
      LED_OFF(LED2);

   if (usb_cdc_carrier.dte_present)
      LED_ON(LED3);
   else
      LED_OFF(LED3);

   if (new_connected && !last_connected)
      printf("USB connected, waiting for enumaration...\r\n\n");
   if (!new_connected && last_connected)
      printf("USB disconnected, waiting for connection...\r\n\n");
   if (new_enumerated && !last_enumerated)
      printf("USB enumerated by PC/HOST\r\n\n");
   if (!new_enumerated && last_enumerated)
      printf("USB unenumerated by PC/HOST, waiting for enumeration...\r\n\n");
   if (new_cdc && !last_cdc) {
      printf("Serial program initiated on USB<->UART COM Port\r\n\n");
      printf(usb_cdc_putc, "\r\n\nCCS CDC (Virtual RS232) Example\r\n\n");
   }

   last_connected=new_connected;
   last_enumerated=new_enumerated;
   last_cdc=new_cdc;
}
Esempio n. 2
0
void main() {
   BYTE i, j, address, value;

   usb_init();
   while(!usb_cdc_connected()) {}

   do {
      printf(usb_cdc_putc, "\r\n\nEEPROM:\r\n");              // Display contents of the first 64
      for(i=0; i<=3; ++i) {                     // bytes of the data EEPROM in hex
         for(j=0; j<=15; ++j) {
            printf(usb_cdc_putc, "%2x ", read_eeprom( i*16+j ) );
         }
         printf(usb_cdc_putc, "\n\r");
      }
      printf(usb_cdc_putc, "\r\nLocation to change: ");
      address = gethex_usb();
      printf(usb_cdc_putc, "\r\nNew value: ");
      value = gethex_usb();

      write_eeprom( address, value );

   } while (TRUE);
}
Esempio n. 3
0
void downloadBootloader()
{
   int Buffer[SerBufferSize];    // serial input buffer   

   int1 notDone = 1;

   unsigned int recLen;   // HEX file record length
   unsigned int16 writeAddr;  // HEX file write address
   unsigned char recType;  // HEX file record type

   unsigned char i=0,j;   // general counters
///   unsigned int16 UserBootVectorAddr; // holds the address of our new boot vector
   unsigned int positionInMemoryBlock;
   unsigned int16 memoryBlockAddress;
   unsigned int bufferIndex;
   unsigned int writeLen;
   
   int16 BankAddress;
   int1 skipWriting=0;
   
   int relocateCount=0;
   #define REC_SIZE  0x10
   int relocateRecordLen[6];
   int relocateOriginalAddress[6];

//   int flashReadBuffer[getenv("FLASH_ERASE_SIZE")];  // buffer for the relocated first mem block
   int flashReadBuffer[REC_SIZE];  // buffer for the relocated first mem block

      usb_init();
      while(!usb_cdc_connected());

      while (notDone) {


         //////////////////////////////////////////
         /// Wait for ':'

         do {
            while (!usb_cdc_kbhit());
         } while (usb_cdc_getc() != ':');



         /////////////////////////////////////////
         //  Record length

         recLen = read8();

         /////////////////////////////////////////
         //  Write Address

         writeAddr  = ((int16)read8() << 8) + read8();

         /////////////////////////////////////////
         //  Rec Type

         usb_cdc_getc();  // ignore the first digit, it is always '0'
         recType = usb_cdc_getc();

         if (recType == '1') { // End of file record
            notDone = 0;

         } else if (recType == '4') {  // bank select record

            BankAddress = (read8()<<8) + read8();
            if (BankAddress != 0)
               skipWriting = 1;
            else
               skipWriting = 0;
            
         } else if ((recType == '0') && !(skipWriting)) { // data record
            

            /// get the data
            for (i=0; i < recLen ; i++) {
                Buffer[i] = read8();
                
            }
 
/*            // if data is in the EEPROM area -> do nothing
            if ((writeAddr >= 0x2100) && (writeAddr <= 0x21FF)) {
               // we don't support EEPROM records yet
            }
*/


            // if writing to the first memory block -> we need to temporarily 
            // relocate it elsewhere. Since this area contains the boot and 
            // interrupt vectors -> it should be written as the very last memory 
            // block.
            
            if (writeAddr & (0xFFFF ^ (getenv("FLASH_ERASE_SIZE")-1)) == 0) {
               relocateOriginalAddress[relocateCount] = writeAddr; // remmber the orginal location
               relocateRecordLen[relocateCount] = recLen; // remember each record's len

               writeAddr = RESERVED_MEMORY_START + (relocateCount * REC_SIZE);
               relocateCount++;
            } 
            
            positionInMemoryBlock = writeAddr & (getenv("FLASH_ERASE_SIZE")-1);
            memoryBlockAddress = writeAddr & (0xFFFF ^ (getenv("FLASH_ERASE_SIZE")-1));
            writeFlash(memoryBlockAddress, positionInMemoryBlock, recLen, Buffer);

         }
         
         if (notDone)
            // Tells the PC to send the next line
            printf(active_comm_putc, "%c",READY_FOR_NEXT);

      }
 
       // Tells the PC that we are finished
      printf(active_comm_putc,"%c", FINISH_FLAG);
 
      delay_ms(100);
      
      /////////////////////////////////////////////////////////////////////////
      //
      //  Now we move the relocated first block to its original place 
      //

      // read the entire flash block to memory

      disable_interrupts(GLOBAL);

      for (i=0;i<relocateCount;i++) {

         read_program_memory(RESERVED_MEMORY_START + (i*REC_SIZE), flashReadBuffer, REC_SIZE);

         writeAddr = relocateOriginalAddress[i];
         writeFlash(0x0, writeAddr, relocateRecordLen[i], flashReadBuffer );
      }

      output_low(USER_LED);
      delay_ms(100);

      reset_cpu();


}