<commit_before>/*-------------------------------------------------------------------------
  main.c - Application main function

             (c) 2006 <NAME> <<EMAIL>> 

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
-------------------------------------------------------------------------*/

#include <pic18fregs.h>
#include "common_types.h"
#include "debug.h"
#include "boot_iface.h"


/******************************************************************/

// beware : this is not a C main function, but the application
// entry point called from the boot.

unsigned long count;

void application_main(void) 
{
    
    PORTA = 0x01;
    init_debug();
    debug("init application\n");  
    
    T0CON = 0x86; // TMR0ON, 16bits, CLKO, PSA on, 1:256
    INTCONbits.TMR0IE = 1;
    INTCONbits.GIE = 1;

    while(usb_active_cfg > 2)
    {
        //usb_sleep();
        dispatch_usb_event();
    }
}

/* Interrupt vectors */
#pragma code high_priority_isr 0x2020
void high_priority_isr(void) interrupt
{
    if(INTCONbits.TMR0IF)
    {
        toggle_A0();
        INTCONbits.TMR0IF = 0;
    }
}

#pragma code low_priority_isr 0x4000
void low_priority_isr(void) interrupt
{
}
<commit_msg>Disable tracing through the USART as it makes USB communications unstable.  init_debug is now called after a small delay to improve stability in DEBUG mode. Close bug #397.<commit_after>/*-------------------------------------------------------------------------
  main.c - Application main function

             (c) 2006 <NAME> <<EMAIL>> 

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
-------------------------------------------------------------------------*/

#include <pic18fregs.h>
#include "common_types.h"
#include "debug.h"
#include "boot_iface.h"

#define ftoggle_A0() { PORTAbits.AN0 = !PORTAbits.AN0; }


/******************************************************************/

// beware : this is not a C main function, but the application
// entry point called from the boot.

unsigned long count;

void application_main(void) 
{
    
    PORTA = 0x01;
    
    // Reset the Timer0 value
    TMR0H = 0;
    TMR0L = 0;
    
    // Configure the Timer0 and unmask ITs
    T0CON = 0x86; // TMR0ON, 16bits, CLKO, PSA on, 1:256
    INTCONbits.TMR0IE = 1;
    INTCONbits.GIE = 1;

    //
    // Process pending USB requests as soon as possible
    // because serial communications (when _DEBUG is defined) can hang 
    // the device for a too long time
    // It means the host should not send a new 
    // sequence of USB requests before something like 2s
    // 
    // In fact, the serial communication causes a lot of
    // problem with the 18F4550 when done in parallel 
    // with USB communication in polling mode.
    // It should also be verified weither or not the serial com edges 
    // disturb the USB signal...
    //
    // In the current state of this software, AVOID the use 
    // of the USART if you want something stable...
    //
#ifdef _DEBUG
    while(PORTAbits.AN0)
    {
        dispatch_usb_event();
    }
#endif // _DEBUG
    
    init_debug();
    debug("init application\n");  
    
    while(usb_active_cfg > 2)
    {
        usb_sleep();
        dispatch_usb_event();
    }
}

/* Interrupt vectors */
#pragma code high_priority_isr 0x2020
void high_priority_isr(void) interrupt
{
    if(INTCONbits.TMR0IF)
    {
        ftoggle_A0();
        INTCONbits.TMR0IF = 0;
    }
}

#pragma code low_priority_isr 0x4000
void low_priority_isr(void) interrupt
{
}

{'fraction_non_alphanumeric': 0.15616045845272206, 'fraction_numerical': 0.024969300040933277, 'mean_word_length': 2.2886944818304173, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5404524', 'n_tokens_mistral': 1440, 'n_tokens_neox': 1333, 'n_words': 541}