CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

18F interrupt relocation.....Help (SOLVED)

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
jspencer



Joined: 22 Dec 2003
Posts: 57
Location: Boise, ID USA

View user's profile Send private message

18F interrupt relocation.....Help (SOLVED)
PostPosted: Thu Apr 13, 2006 4:46 pm     Reply with quote

I've looked over quite a few posts, but not sure I'm finding what I need. I am using the Microchip USB bootloader on the 18F4550 and am able to load my program to the PIC, but it looks like my remap of the interrupt handler is failing. The code runs up to the point where there is an interrupt then nothing. If anyone has done this or has any helpful comments I'd sure appreciate it.

Code:

#if defined(__PCM__)
   #define LOADER_END   0x1FF
   #define LOADER_SIZE   0x1BF
#elif defined(__PCH__)
   #define LOADER_END   0x7FF
   #define LOADER_SIZE   0x6FF
#endif

#ifndef _bootloader

#if defined(__PCM__)
   #build(reset=LOADER_END+1, interrupt=LOADER_END+5)
#elif defined(__PCH__)
   #build(reset=LOADER_END+2, interrupt=LOADER_END+9)
#endif

#org 0, LOADER_END

#endif



Thanks,

jspencer


Last edited by jspencer on Wed Apr 19, 2006 10:06 am; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Apr 14, 2006 11:30 am     Reply with quote

Quote:
I am using the Microchip USB bootloader

You should provide a link to the webpage where the bootloader source
can be downloaded.

Quote:
#ifndef _bootloader

We need to know if this "_bootloader" value is defined or not.
Your code doesn't tell us.


When posting a question like this, on some obscure issue, you should
never assume that we are mind readers. We need information.

Also post your compiler version.
jspencer



Joined: 22 Dec 2003
Posts: 57
Location: Boise, ID USA

View user's profile Send private message

PostPosted: Fri Apr 14, 2006 12:11 pm     Reply with quote

Sorry for that PCM, I should know better then that by now. The code is quite large and I didn't want to post all of it. Here is hopefully some more helpful information.

Compiler Version: PCWH Version 3.242

Here is the link to the Microchip USB bootloader:
http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=2124&param=en022627

_VIPER_H and _bootloader have not been previously defined.
DEBUG_PLATFORM has been defined

Setup of PIC code.

Code:

#ifndef _VIPER_H
#define _VIPER_H
// Define the environment specific to the 184550 chip, i.e. the dev platform.
//
#ifdef DEBUG_PLATFORM
//#device ICD=true
#FUSES WDT                    //Watch Dog Timer
#FUSES WDT512                 //512 ~ 2 seconds.
#FUSES HSPLL                    //High Speed Crystal/Resonator with PLL enabled
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOBROWNOUT             //No Reset when brownout detected
//#FUSES BORV20                   //Brownout reset at 2.0V
#FUSES PUT                      //Power Up Timer
#FUSES NOCPD                    //No EE protection
#FUSES NOSTVREN                 //Stack full/underflow will not cause reset
#FUSES NODEBUG                    //Debug mode for use with ICD
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES NOIESO                   //Internal External Switch Over mode disabled
#FUSES NOFCMEN                    //Fail-safe clock monitor enabled
#FUSES NOPBADEN                 //PORTB pins are configured as digital I/O on RESET
#FUSES NOWRTC                   //configuration registers not write protected
#FUSES WRTB                   //Boot block write protected
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES EBTRB                  //Boot block protected from table reads
#FUSES CPB                    //Boot Block code protection
#FUSES MCLR                     //Master Clear pin enabled
#FUSES NOLPT1OSC                //Timer1 configured for higher power operation
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES PLL5                     //PLL PreScaler
#FUSES USBDIV
#FUSES CPUDIV1
#FUSES VREGEN

// make sure that the EEPROM is reset to all F's
#rom 0xF00000 = { 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
                  0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
                  0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
                  0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
                  0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
                  0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
                  0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
                  0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
                  0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
                  0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
                  0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
                  0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
                  0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
                  0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
                  0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
                  0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff}

// Define the IDLEN bit so that we can make sure it goes into sleep mode
#byte OSCCON = 0xFD3 // Does this need to move when using the bootloader??
#bit IDLEN = OSCCON.7

#define GREEN_LED          PIN_D3
#define RED_LED            PIN_D2
#define I2C_SCL            PIN_B5
#define I2C_SDA            PIN_B4
#define USB_CON_SENSE_PIN  PIN_B2
#endif
//
// Define the common environment
//
// EEPROM layout definitions
#include "ext_eeprom_layout.h"

#use delay (clock=48000000)

// USB Definitions & includes
#define USB_EP1_TX_ENABLE     USB_ENABLE_INTERRUPT
#define USB_EP1_TX_SIZE       64
#define USB_EP1_RX_ENABLE     USB_ENABLE_INTERRUPT
#define USB_EP1_RX_SIZE       8
#define OUTPUT_REPORT_SIZE    USB_EP1_TX_SIZE
#include <pic18_usb.h>
#include "usb_desc_hid.h"  // the local modified version
#include <usb.c>

// I2C Clock and Data line declarations & includes
#use i2c(master, sda=I2C_SDA, scl=I2C_SCL, fast)
#include "viper_2432_ext_eeprom.h"   // the local modified version

// The data portion of the eeprom consists of a sequence of data points, each
// taking up 16bits.  A datapoint consists of a 4bit count and a 12bit
// temperature value.
// This data is sent to the PC via USB as a sequence of three Bytes, the first
// In the eeprom, this is stored as 2 bytes.  4 bits for the count and
// 12 bits for the temperature.
#define DATA_BYTES_EEPROM              2
#define DATA_BYTES_BUFFER              2
#define DATA_POINTS_IN_OUTPUT_REPORT   (OUTPUT_REPORT_SIZE / DATA_BYTES_BUFFER)

// Purpose: read the entire contents of the
//    external eeprom and send via USB.
//
void get_data_ext_eeprom () ;
void viper_init();

#endif // _VIPER_H


bootloader.h file
Code:


#if defined(__PCM__)
   #define LOADER_END   0x1FF
   //#define LOADER_SIZE   0x1BF
#elif defined(__PCH__)
   #define LOADER_END   0x7FF
   //#define LOADER_SIZE   0x6FF
#endif

#ifndef _bootloader
#define _bootloader
#if defined(__PCM__)
   #build(reset=LOADER_END+1, interrupt=LOADER_END+5)
#elif defined(__PCH__)
   #build(reset=LOADER_END+2, interrupt=LOADER_END+9)
#endif

#org 0, LOADER_END void bootloader(void) {}

#endif


Also, here is the first part of the list file:

Code:

CCS PCH C Compiler, Version 3.242, 31431               14-Apr-06 11:55

               Filename: C:\Documents and Settings\James\My Documents\Reader\source\firmware (07)\viper.lst

               ROM used: 9074 bytes (28%)
                         Largest free fragment is 21644
               RAM used: 583 (28%) at main() level
                         709 (35%) worst case
               Stack:    13 worst case (6 in main + 7 for interrupts)

*
0800:  GOTO   2932
*
0808:  MOVWF  05
080A:  MOVFF  FD8,06
080E:  MOVFF  FE0,07
0812:  MOVLB  0
0814:  MOVFF  FE9,0D
0818:  MOVFF  FEA,08
081C:  MOVFF  FE1,09
0820:  MOVFF  FE2,0A
0824:  MOVFF  FD9,0B
0828:  MOVFF  FDA,0C
082C:  MOVFF  FF3,14
0830:  MOVFF  FF4,15
0834:  MOVFF  FFA,16
0838:  MOVFF  00,0F
083C:  MOVFF  01,10
0840:  MOVFF  02,11
0844:  MOVFF  03,12
0848:  MOVFF  04,13
084C:  BTFSS  FF2.5
084E:  GOTO   0858
0852:  BTFSC  FF2.2
0854:  GOTO   15B4
0858:  BTFSS  FF2.4
085A:  GOTO   0864
085E:  BTFSC  FF2.1
0860:  GOTO   1650
0864:  BTFSS  FF0.4
0866:  GOTO   0870
086A:  BTFSC  FF0.1
086C:  GOTO   1664
0870:  BTFSS  FA0.5
0872:  GOTO   087C
0876:  BTFSC  FA1.5
0878:  GOTO   146C
087C:  MOVFF  0F,00
0880:  MOVFF  10,01
0884:  MOVFF  11,02
0888:  MOVFF  12,03
088C:  MOVFF  13,04
0890:  MOVFF  0D,FE9
0894:  MOVFF  08,FEA
0898:  MOVFF  09,FE1
089C:  MOVFF  0A,FE2
08A0:  MOVFF  0B,FD9
08A4:  MOVFF  0C,FDA
08A8:  MOVFF  14,FF3
08AC:  MOVFF  15,FF4
08B0:  MOVFF  16,FFA
08B4:  MOVF   05,W
08B6:  MOVFF  07,FE0
08BA:  MOVFF  06,FD8
08BE:  RETFIE 0
.................... //********************************************************************
.................... // Copyright 2005-2006�
.................... // PakSense, Inc.
.................... // All Rights Reserved
.................... //
.................... // Written by:                   James Spencer & Scott McLean
.................... // Initial start date:           11/08/2005
.................... //********************************************************************
.................... #define DEBUG_PLATFORM
.................... //#define RELEASE_PLATFORM
....................
.................... #ifdef DEBUG_PLATFORM
.................... #include <18F4550.h>       // This must be the FIRST include!
.................... //////// Standard Header file for the PIC18F4550 device ////////////////
.................... #device PIC18F4550
.................... #list
....................
.................... #endif
.................... #ifdef RELEASE_PLATFORM
.................... #include <18F2455.h>       // This must be the FIRST include!
.................... #endif
....................
.................... #include "bootloader.h"
.................... ///////////////////////////////////////////////////////////////////////////
.................... ////                       BOOTLOADER.H                                ////
.................... ////                                                                   ////
.................... ////  This include file must be included by any application loaded     ////
.................... ////  by the example bootloader (ex_bootloader.c).                     ////
.................... ////                                                                   ////
.................... ////  The directives in this file relocate the reset and interrupt     ////
.................... ////  vectors as well as reserving space for the bootloader.           ////
.................... ////                                                                   ////
.................... ////  LOADER_END and LOADER_SIZE may need to be adjusted for a         ////
.................... ////  specific chip and bootloader.                                    ////
.................... ///////////////////////////////////////////////////////////////////////////
.................... ////        (C) Copyright 1996,2004 Custom Computer Services           ////
.................... //// This source code may only be used by licensed users of the CCS    ////
.................... //// C compiler.  This source code may only be distributed to other    ////
.................... //// licensed users of the CCS C compiler.  No other use,              ////
.................... //// reproduction or distribution is permitted without written         ////
.................... //// permission.  Derivative programs created using this software      ////
.................... //// in object code form are not restricted in any way.                ////
.................... ///////////////////////////////////////////////////////////////////////////
....................
....................
.................... #if defined(__PCM__)
....................    #define LOADER_END   0x1FF
....................    #define LOADER_SIZE   0x1BF
.................... #elif defined(__PCH__)
....................    #define LOADER_END   0x7FF
....................    #define LOADER_SIZE   0x6FF
.................... #endif
....................
.................... #ifndef _bootloader
.................... #define _bootloader
.................... #if defined(__PCM__)
....................    #build(reset=LOADER_END+1, interrupt=LOADER_END+5)
.................... #elif defined(__PCH__)
....................    #build(reset=LOADER_END+2, interrupt=LOADER_END+9)
.................... #endif
....................
.................... #org 0, LOADER_END void bootloader(void) {}
*
0000:  RETLW  00
....................
.................... #endif


main code

Code:

//********************************************************************
// Copyright 2005-2006�
// PakSense, Inc.
// All Rights Reserved
//
// Written by:                   James Spencer & Scott McLean
// Initial start date:           11/08/2005
//********************************************************************
#define DEBUG_PLATFORM
//#define RELEASE_PLATFORM

#ifdef DEBUG_PLATFORM
#include <18F4550.h>       // This must be the FIRST include!
#endif
#ifdef RELEASE_PLATFORM
#include <18F2455.h>       // This must be the FIRST include!
#endif

#include "bootloader.h"
#include "viper.h"
#include "viper_led.h"
#include "viper_usb_output.h"
#include "viper_globals.h"
#include "viper_tag.h"


//******************************************************************************
// TIMER0_isr()
//    The RTCC timer interrupt occurs a few times a second.  We use the isr to
//    monitor the state of the system and toggle the appropriate LEDs.
//    See comments below for the specific states that are monitored.
//
//    NOTE: the ordering of the state checks is important because although
//    multiple flags could be set at the same time, we only want to process the
//    most important state.
//******************************************************************************
#int_timer0
TIMER0_isr()
{
   // The isr is triggered too quickly for some desired led toggle behavior.
   // This counter is used to keep track of how many times we have entered the
   // isr and only toggle an LED on the n'th entry.  Will over flow at 256 and
   // restart at 0
   global_interrupt_count++;

   // The global usb mode indicates that we are connected via USB.  This
   // puts us in USB mode and we ignore everything else.
   // This is the highest priority state so it is checked first.

   if(global_usb_mode == true)
   {
      // Just keep the green led on constantly...
      led_set_red(false) ;
      led_set_green(true) ;
   }
   // The global memory full state indicates that there is no more room on the
   // device for downloading tags.
   else if(global_memory_full_state == true )
   {
      // The isr is triggered faster than we want the leds to flash in this state
      // so only toggle the leds every 4th time we enter the isr.
      if( (global_interrupt_count % 4) == 0 )
      {
         led_toggle_amber() ;
      }

      if (global_memory_full_counter++ > 50) {
         global_memory_full_counter = 0;
         // Need to make sure that we set this to false so that it doesn't turn
         // green after we turn the memory full state to false.
         global_download_complete = false;
         // Set this to false just so it stops flashing, once you probe again it
         // will flash memory full again until we turn it off.
         global_memory_full_state = false;
         // Make sure the amber led is off.
         led_set_amber(false) ;
      }
   }
   // The global download complete state indicates that we have completed a
   // successful download of data from an external tag.  Be sure that the RED
   // led is turned off, or we will end up with an amber light.
   // We want this led to stay on every time the isr is triggered.
   else if( global_download_complete == true )
   {
      if (global_download_complete_counter >= 40) {
         global_download_complete = false;
         global_download_complete_counter = 0;
         led_set_red(false) ;
         led_set_green(false) ;
      } else {
         led_set_red(false) ;
         led_set_green(true) ;
         global_download_complete_counter++;
      }
      //global_downloading = false;
   }
   // The global downloading state indicates that we are actively downloading
   // data from an external tag.  Be sure that the RED led is turned off, or we
   // will end up with an amber light.
   // We want this led to flash really fast so do it every time the isr is triggered.
   else if( global_downloading == true )
   {
      led_set_red(false) ;
      led_toggle_green() ;
   }
   // The download error state indicates that we had a download failure.
   // We want this state to toggle the led really slowly so only do it every 8th
   // time the isr is triggered.
   // This is the lowest priority state so do it last.
   else if( global_download_error_state == true )
   {
      if( (global_interrupt_count % 8) == 0 )
      {
         if( global_download_error_counter >= 10 )
         {
            global_download_error_counter = 0 ;
            global_set_download_error_state(false) ;
            led_set_red(false) ;
            led_set_green(false) ;
         }
         else
         {
            led_set_green(false) ;
            led_toggle_red() ;
         }
         global_download_error_counter++ ;
      }
   }
   // Finally, if we are not in one of the recognized states, make sure the led
   // are off.
   else
   {
      led_set_green(false) ;
      led_set_red(false) ;
   }

}

//******************************************************************************
// ext_isr()
//    This interrupt is triggered by PIN_B0 going from low to high and indicates
//    that the probe was connected to a Tag (or some other conductive surface :-)
//******************************************************************************
#int_ext
ext_isr()
{
   // Set the global tag ready flag.  The main loop waits for this flag and
   // when it is true it will read the tag's eeprom into the internal buffers.
   if (!global_download_complete && !global_downloading && !global_tag_ready) {
      global_tag_ready = true;
   }
}


#int_ext2
ext_isr2()
{
#ifdef RELEASE_PLATFORM
   if (!input(PIN_B2))
      REGULATOR_ENABLE();
   else
      REGULATOR_DISABLE();

   reset_cpu() ;
#endif // RELEASE_PLATFORM
}

//******************************************************************************
// viper_device_setup()
//    Perform the device specific setup.
//    Device diagnostic setup methods are performed in viper_post()
//******************************************************************************
void viper_device_setup()
{
   #ifdef DEBUG_PLATFORM
      setup_adc_ports(NO_ANALOGS|VSS_VDD);
      setup_adc(ADC_OFF);
      setup_psp(PSP_DISABLED);
      setup_timer_0(RTCC_INTERNAL|RTCC_DIV_16);
      setup_timer_1(T1_DISABLED);
      setup_timer_2(T2_DISABLED,0,1);
      setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
      setup_comparator(NC_NC_NC_NC);
      setup_vref(FALSE);
      setup_low_volt_detect(FALSE);
      setup_oscillator(False);
      setup_wdt(WDT_ON);
   #endif

   #ifdef RELEASE_PLATFORM
      port_b_pullups(FALSE);
      setup_adc_ports(NO_ANALOGS|VSS_VDD);
      setup_adc(ADC_OFF);
      setup_spi(SPI_SS_DISABLED);
      setup_timer_0(RTCC_INTERNAL|RTCC_DIV_16);
      setup_timer_1(T1_DISABLED);
      setup_timer_2(T2_DISABLED,0,1);
      setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
      setup_comparator(NC_NC_NC_NC);
      setup_ccp1(CCP_OFF);
      setup_ccp2(CCP_OFF);
      setup_vref(FALSE);
      setup_wdt(WDT_ON);
      REGULATOR_ENABLE();
   #endif
}

//******************************************************************************
// viper_hard_reset()
//    Called when the hard reset button was pressed.
//    Reset the internal and external eeproms to all zeros
//******************************************************************************
void viper_hard_reset()
{
   led_set_red(true) ;
   global_hard_reset() ;
   led_set_red(false) ;
}



//******************************************************************************
// viper_post()
//    Viper Power On Self Test.
//    First, perform the device specific setup.
//    Then do the rest of the setup and self-test.
//******************************************************************************
void viper_post()
{
   boolean status = true ;    // Status of self-tests

   // Visually indicate that the POST has begun.
   led_post_start() ;

   // Initialize USB
   usb_init_cs();

   restart_wdt() ;

   // Turn on the red led just in case one of the self test routines hangs.
   // In all likely hood the user will never see the red led on, but if we hang
   // it will become apparant that something is wrong.
   led_set_red(true) ;

   // Initialize the non-volitile and volitile global memory variables.
   // Non-volitile memory is stored in the internal eeprom.
   global_init_memory() ;

   // Initialize and test the external eeproms.
   init_ext_eeprom();

   if( !ext_eeprom_ready(BANKA_HW_ADDR))
   {
      status = false ;
   }
   restart_wdt() ;

   if( !ext_eeprom_ready(BANKB_HW_ADDR))
   {
      status = false ;
   }
   restart_wdt() ;

   // Verify that the self-test routines succeeded.
   if( status )
   {
      // Successful POST, turn of the RED and display the success sequence.
      led_set_red( false ) ;

      if( ! global_memory_full_state && ! global_download_error_state )
      {
         led_post_success() ;
         restart_wdt() ;
      }
   }
   else
   {
      // Failure POST.  Display the failure sequence, turn on RED and hang.
      //    The Watchdog Timer will reset us eventually.
      led_post_failure() ;
      led_set_red(true) ;
      while(1) ;
   }
}


//******************************************************************************
// main()
//    Viper main routine.
//    Perform the Power On Self Test
//    Enable Interrupts
//    Enter a loop waiting for either a tag to be probed, or the usb to be
//       connected.  Both of these states are tracked in flags set in interrupt
//       service routines.
//    If a tag is probed, verify that we have a consistent and real electrical
//       connection and then read the tag.
//    If the usb is connected then prepare to download the tag via usb and wait
//       for the PC to request a packet.
//******************************************************************************
void main () {
   int bounces ;
   int pin_b0_high_count ;
   boolean download_connect ;

   int16 packetID = 0 ;
   int16 tagID ;
   int16 restartCause ;
   int16 numTags ;

   // Setup the device specific settings.
   viper_device_setup() ;

   enable_interrupts(GLOBAL);

   // Determine the reset cause.
   restartCause = restart_cause() ;
   switch( restartCause )
   {
      case MCLR_FROM_SLEEP:
      case MCLR_FROM_RUN:
         // Hard reset, from button press
         viper_hard_reset() ;
         viper_post() ;
         break ;
      case NORMAL_POWER_UP:
      case WDT_TIMEOUT:
      case WDT_FROM_SLEEP:
      case BROWNOUT_RESTART:
      case RESET_INSTRUCTION:
      default:
         // Normal reset
         viper_post() ;
         break ;
   }

   // Enable interrupts
   enable_interrupts(INT_TIMER0);
   enable_interrupts(INT_EXT);
   enable_interrupts(INT_EXT2) ;

   // Configure USB Sense interrupt to trigger when USB is connected.
   //    This will cause the device to reset and re-init.
   ext_int_edge(2, L_TO_H) ;

   ext_int_edge(0, L_TO_H) ;
   set_timer0( 0 ) ;

   led_set_green( false ) ;
   led_set_red(false) ;

   // Wait for either USB to be connected or a tag to be probed.
   while(1)
   {
      restart_wdt() ;

      // Check/update the usb state
      usb_task() ;

      // USB is the highest priority.  If USB is attached & enumerated, ignore
      // everything else.

      if( usb_attached() && usb_enumerated() )
      {
         // Configure USB Sense interrupt to trigger when USB is disconnected.
         //    This will cause the device to reset and re-init.
         ext_int_edge(2, H_TO_L) ;

         #ifdef RELEASE_PLATFORM
            REGULATOR_DISABLE();
         #endif
         // USB is enumerated, and powered so set the flag to true.
         global_set_usb_mode( true ) ;

         // Wait a while for data from the PC, if there is nothing, then
         // loop back out and start over again.
         while( usb_wait_for_pc_data()== true )
         {

            // Get the packet id requested by the PC
            restart_wdt() ;
            get_packet_request(&packetID, &tagID) ;

            restart_wdt() ;

            // if a Status Query
            if( packetID == 0 && tagID == 0 )
            {
               // Send the tag count
               numTags = viper_eeprom_map_get_tag_count( &global_eeprom_map) ;
               send_command_response( 0xffff, numTags, 0xaa ) ;
            }
            // if an Erase Request
            else if( packetID == 0xffff && tagID == 0xffff )
            {
               // Erase the eeproms
               viper_eeprom_map_init( &global_eeprom_map ) ;
               global_commit_eeprom_map() ;
               global_set_memory_full_state(false) ;
               global_set_download_error_state(false) ;
               restart_wdt() ;

               send_command_response( 0xffff, 0xffff, 0xff) ;
            }
            // if Data Request
            else
            {
               // Send a USB packet with the requested data.
               send_requested_packet(packetID++, tagID) ;
            }
         }
         restart_wdt() ;
      }
      else
      {

         #ifdef RELEASE_PLATFORM
            REGULATOR_ENABLE();
         #endif
         // USB is NOT enumerated, so set the flag to false.
         global_set_usb_mode( false ) ;

         // Check if a tag is connected and download the data.
         if(( global_tag_ready == true) & (! usb_enumerated() ))
         {
            // We have received an interrupt because PIN_B0 went high.  Use a
            // "bounce" algorithm to verify that the interrupt is legit.

            restart_wdt() ;

            // If a tag has been probed, verify that we have a valid connection.
            // Check that PIN_B0 is high 50 times.  If it is high at least half
            // of the times, then consider it a good connection.
            bounces = 0 ;
            pin_b0_high_count = 0 ;
            download_connect = false ;
            for( bounces = 0 ; bounces < 50 ; bounces++ )
            {
               if( input(PIN_B0))
               {
                  pin_b0_high_count++ ;
                  if( pin_b0_high_count >= 25 )
                  {
                     download_connect = true ;
                  }
               }
               delay_ms(10) ;
            }
            restart_wdt() ;


            if( download_connect == true )
            {
               restart_wdt() ;

               // The interrupt seems legit, try to download the tag data.
               tag_download() ;
            }
            restart_wdt();
            // Set the flag to false so to enable the interrupt.
            global_set_tag_ready( false );
         }

         // If USB is not attached and not enumerated AND we do not have a label,
         // then go to sleep


         if (!usb_attached() && !usb_enumerated() && !global_download_complete && !global_downloading && !global_tag_ready) {
            restart_wdt();
            disable_interrupts(INT_TIMER0);
            IDLEN=0 ;
            output_float(I2C_SDA);
            output_float(I2C_SCL);
            setup_wdt(WDT_OFF) ;
            sleep() ;

            restart_wdt();
            enable_interrupts(INT_TIMER0) ;
            setup_wdt(WDT_ON) ;
         }
      }
   }
}



The reset and interrupt vectors seem to be correct. I can tell that the code loaded, as I have a power on self test that runs each time the unit is powered up or reset. Once it finishes though it will either go to sleep (USB cable not plugged in) and not wake up as the interrupts do not work or it will fail enumeration if the USB cable is plugged in.

It seems like I am doing everything correctly, just missing a little piece to the puzzle.

Thanks,

jspencer
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Apr 14, 2006 2:18 pm     Reply with quote

The "LOADER_END" and "LOADER_SIZE" are very likely to be
different values than for the CCS example bootloader.
The CCS example does define "_bootloader", so in the CCS example,
the #ifndef section isn't invoked.

You're really asking for help in porting a C18 USB bootloader to PCH.
I don't know if I want to get involved in that. It's more than just a few
minutes work.
jspencer



Joined: 22 Dec 2003
Posts: 57
Location: Boise, ID USA

View user's profile Send private message

PostPosted: Wed Apr 19, 2006 10:09 am     Reply with quote

Figured out what the problem was. The USB bootloader goes into suspend mode and when it wakes up it does not clear the USBIE bit. Clear that bit and my code works just fine, interrupts and all.

jspencer
contraled
Guest







PostPosted: Tue May 08, 2007 7:24 pm     Reply with quote

Hi, I'm having the same problem too on my 18f4550. I also used the Microchip c18 bootloader. My user file is running the CCS CDC driver. All seems fine with my user file, except it always gets stuck at the usb part. I cleared the USBIE bit at the start of my user file, before I initialise my usb, but it dosen't seem to work. Can you help me?

Thanks!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group