Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dsPIC33C driver #14

Merged
merged 2 commits into from
Dec 29, 2024
Merged

Add dsPIC33C driver #14

merged 2 commits into from
Dec 29, 2024

Conversation

JuPrgn
Copy link

@JuPrgn JuPrgn commented Dec 17, 2024

This is a preliminary work, not fully tested yet. Should be helpfull for #13.

I am not using all the FIFO and new CAN module features that could speed up CAN processing there should be many improvments available here.

I am not very familiar with __eds__ there are probably some improvments that could be done there too as it seems to be the case on dsPIC24_33 driver.

And some code I am using on my user program :

/* Global variables and objects */
volatile uint16_t CO_timer1ms = 0U; /* variable increments each millisecond */

const CO_CANbitRateData_t CO_CANbitRateData[8] = {
    CO_CANbitRateDataInitializers};

/** Previous timer value to compute time difference */
STATIC uint16_t timer1msPrevious;

/** CANopen object pointer */
CO_t *CO_GLOB = NULL;

// Object Dictionnary object
extern OD_t *OD;

// TODO manage CAN errors
void __attribute__((__interrupt__, no_auto_psv)) _C1Interrupt(void)
{
    //    CO_CANinterrupt(&CO_GLOB->CANmodule[0]);
    //
    ////    TEFOVIF
    //
    IFS1bits.C1IF = 0;

    C1INTL = 0;
    C1RXOVIFH = 0;
    C1RXOVIFL = 0;
    C1TXATIFL = 0;
    C1TXATIFH = 0;
    C1TXATIFL = 0;
    C1INTL = 0;

    IFS1bits.C1IF = 0;
}

void __attribute__((__interrupt__, no_auto_psv)) _C1RXInterrupt(void)
{
    CO_CANinterruptRX(&CO_GLOB->CANmodule[0]);

    /* Clear combined Interrupt flag */
    IFS1bits.C1RXIF = 0;
}

void __attribute__((__interrupt__, no_auto_psv)) _C1TXInterrupt(void)
{
    CO_CANinterruptTX(&CO_GLOB->CANmodule[0]);

    /* Clear combined Interrupt flag */
    IFS3bits.C1TXIF = 0;
}

I call this function at initialization :

#define CO_CAN_ISR_FLAG IFS1bits.C1IF   // Interrupt Flag bit
#define CO_CAN_ISR_ENABLE IEC1bits.C1IE // Interrupt Enable bit
#define CO_CAN_TX_ISR_FLAG IFS3bits.C1TXIF   // Interrupt Flag bit
#define CO_CAN_TX_ISR_ENABLE IEC3bits.C1TXIE // Interrupt Enable bit
#define CO_CAN_RX_ISR_FLAG IFS1bits.C1RXIF   // Interrupt Flag bit
#define CO_CAN_RX_ISR_ENABLE IEC1bits.C1RXIE // Interrupt Enable bit

CO_CAN_ISR_FLAG = 0;    // CAN1 Interrupt - Clear flag
CO_CAN_TX_ISR_FLAG = 0; // CAN1 Tx Interrupt - Clear flag
CO_CAN_RX_ISR_FLAG = 0; // CAN1 Rx Interrupt - Clear flag
CO_CAN_ISR_ENABLE = 1;  // CAN1 Interrupt - Enable interrupt
CO_CAN_TX_ISR_ENABLE = 1;  // CAN1 Tx Interrupt - Enable interrupt
CO_CAN_RX_ISR_ENABLE = 1;  // CAN1 Rx Interrupt - Enable interrupt

// Start Timer4
SCCP4_Timer_Start();

And periodically call this function with timer 4 (1kHz) :

/* timer interrupt function executes every millisecond ************************/
STATIC void BSP_CANTimer_ISR(void)
{
    INCREMENT_1MS(CO_timer1ms);

    if ((bool)CO_GLOB->CANmodule[0].CANnormal)
    {
        bool syncWas;

        /* Process Sync */
        syncWas = CO_process_SYNC(CO_GLOB, TMR_TASK_INTERVAL, NULL);

        /* Read inputs */
        CO_process_RPDO(CO_GLOB, syncWas, TMR_TASK_INTERVAL, NULL);

        /* Further I/O or nonblocking application code may go here. */

        /* Write outputs */
        CO_process_TPDO(CO_GLOB, syncWas, TMR_TASK_INTERVAL, NULL);
    }
}

For information my MCC CAN configuration is as follows, but CAN configuration is also overwritten by the stack not sure what is required on MCC :
Builder
CAN1_1
CAN1_2

@CANopenNode CANopenNode merged commit 7a64bf6 into CANopenNode:master Dec 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants