Initial commit
This commit is contained in:
@ -0,0 +1,97 @@
|
||||
/**
|
||||
@Generated PIC10 / PIC12 / PIC16 / PIC18 MCUs Source File
|
||||
|
||||
@Company:
|
||||
Microchip Technology Inc.
|
||||
|
||||
@File Name:
|
||||
mcc.c
|
||||
|
||||
@Summary:
|
||||
This is the device_config.c file generated using PIC10 / PIC12 / PIC16 / PIC18 MCUs
|
||||
|
||||
@Description:
|
||||
This header file provides implementations for driver APIs for all modules selected in the GUI.
|
||||
Generation Information :
|
||||
Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8
|
||||
Device : PIC18F26K83
|
||||
Driver Version : 2.00
|
||||
The generated drivers are tested against the following:
|
||||
Compiler : XC8 2.36 and above or later
|
||||
MPLAB : MPLAB X 6.00
|
||||
*/
|
||||
|
||||
/*
|
||||
(c) 2018 Microchip Technology Inc. and its subsidiaries.
|
||||
|
||||
Subject to your compliance with these terms, you may use Microchip software and any
|
||||
derivatives exclusively with Microchip products. It is your responsibility to comply with third party
|
||||
license terms applicable to your use of third party software (including open source software) that
|
||||
may accompany Microchip software.
|
||||
|
||||
THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
|
||||
EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY
|
||||
IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE.
|
||||
|
||||
IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
|
||||
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
|
||||
WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP
|
||||
HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO
|
||||
THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL
|
||||
CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT
|
||||
OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
// Configuration bits: selected in the GUI
|
||||
|
||||
// CONFIG1L
|
||||
#pragma config FEXTOSC = OFF // External Oscillator Selection->Oscillator not enabled
|
||||
#pragma config RSTOSC = HFINTOSC_64MHZ // Reset Oscillator Selection->HFINTOSC with HFFRQ = 64 MHz and CDIV = 1:1
|
||||
|
||||
// CONFIG1H
|
||||
#pragma config CLKOUTEN = OFF // Clock out Enable bit->CLKOUT function is disabled
|
||||
#pragma config PR1WAY = ON // PRLOCKED One-Way Set Enable bit->PRLOCK bit can be cleared and set only once
|
||||
#pragma config CSWEN = ON // Clock Switch Enable bit->Writing to NOSC and NDIV is allowed
|
||||
#pragma config FCMEN = ON // Fail-Safe Clock Monitor Enable bit->Fail-Safe Clock Monitor enabled
|
||||
|
||||
// CONFIG2L
|
||||
#pragma config MCLRE = EXTMCLR // MCLR Enable bit->If LVP = 0, MCLR pin is MCLR; If LVP = 1, RE3 pin function is MCLR
|
||||
#pragma config PWRTS = PWRT_OFF // Power-up timer selection bits->PWRT is disabled
|
||||
#pragma config MVECEN = OFF // Multi-vector enable bit->Interrupt contoller does not use vector table to prioritze interrupts
|
||||
#pragma config IVT1WAY = ON // IVTLOCK bit One-way set enable bit->IVTLOCK bit can be cleared and set only once
|
||||
#pragma config LPBOREN = OFF // Low Power BOR Enable bit->ULPBOR disabled
|
||||
#pragma config BOREN = SBORDIS // Brown-out Reset Enable bits->Brown-out Reset enabled , SBOREN bit is ignored
|
||||
|
||||
// CONFIG2H
|
||||
#pragma config BORV = VBOR_2P45 // Brown-out Reset Voltage Selection bits->Brown-out Reset Voltage (VBOR) set to 2.45V
|
||||
#pragma config ZCD = OFF // ZCD Disable bit->ZCD disabled. ZCD can be enabled by setting the ZCDSEN bit of ZCDCON
|
||||
#pragma config PPS1WAY = ON // PPSLOCK bit One-Way Set Enable bit->PPSLOCK bit can be cleared and set only once; PPS registers remain locked after one clear/set cycle
|
||||
#pragma config STVREN = ON // Stack Full/Underflow Reset Enable bit->Stack full/underflow will cause Reset
|
||||
#pragma config DEBUG = OFF // Debugger Enable bit->Background debugger disabled
|
||||
#pragma config XINST = OFF // Extended Instruction Set Enable bit->Extended Instruction Set and Indexed Addressing Mode disabled
|
||||
|
||||
// CONFIG3L
|
||||
#pragma config WDTCPS = WDTCPS_31 // WDT Period selection bits->Divider ratio 1:65536; software control of WDTPS
|
||||
#pragma config WDTE = OFF // WDT operating mode->WDT Disabled; SWDTEN is ignored
|
||||
|
||||
// CONFIG3H
|
||||
#pragma config WDTCWS = WDTCWS_7 // WDT Window Select bits->window always open (100%); software control; keyed access not required
|
||||
#pragma config WDTCCS = SC // WDT input clock selector->Software Control
|
||||
|
||||
// CONFIG4L
|
||||
#pragma config BBSIZE = BBSIZE_512 // Boot Block Size selection bits->Boot Block size is 512 words
|
||||
#pragma config BBEN = OFF // Boot Block enable bit->Boot block disabled
|
||||
#pragma config SAFEN = OFF // Storage Area Flash enable bit->SAF disabled
|
||||
#pragma config WRTAPP = OFF // Application Block write protection bit->Application Block not write protected
|
||||
|
||||
// CONFIG4H
|
||||
#pragma config WRTB = OFF // Boot Block Write Protection bit->Boot Block not write-protected
|
||||
#pragma config WRTC = OFF // Configuration Register Write Protection bit->Configuration registers (300000-30000Bh) not write-protected
|
||||
#pragma config WRTD = OFF // Data EEPROM Write Protection bit->Data EEPROM not write-protected
|
||||
#pragma config WRTSAF = OFF // SAF Write protection bit->SAF not Write Protected
|
||||
#pragma config LVP = ON // Low Voltage Programming Enable bit->Low voltage programming enabled. MCLR/VPP pin function is MCLR. MCLRE configuration bit is ignored
|
||||
|
||||
// CONFIG5L
|
||||
#pragma config CP = OFF // PFM and Data EEPROM Code Protection bit->PFM and Data EEPROM code protection disabled
|
@ -0,0 +1,55 @@
|
||||
/**
|
||||
@Generated PIC10 / PIC12 / PIC16 / PIC18 MCUs Header File
|
||||
|
||||
@Company:
|
||||
Microchip Technology Inc.
|
||||
|
||||
@File Name:
|
||||
mcc.c
|
||||
|
||||
@Summary:
|
||||
This is the device_config.h file generated using PIC10 / PIC12 / PIC16 / PIC18 MCUs
|
||||
|
||||
@Description:
|
||||
This header file provides implementations for driver APIs for all modules selected in the GUI.
|
||||
Generation Information :
|
||||
Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8
|
||||
Device : PIC18F26K83
|
||||
Driver Version : 2.00
|
||||
The generated drivers are tested against the following:
|
||||
Compiler : XC8 2.36 and above or later
|
||||
MPLAB : MPLAB X 6.00
|
||||
*/
|
||||
|
||||
/*
|
||||
(c) 2018 Microchip Technology Inc. and its subsidiaries.
|
||||
|
||||
Subject to your compliance with these terms, you may use Microchip software and any
|
||||
derivatives exclusively with Microchip products. It is your responsibility to comply with third party
|
||||
license terms applicable to your use of third party software (including open source software) that
|
||||
may accompany Microchip software.
|
||||
|
||||
THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
|
||||
EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY
|
||||
IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE.
|
||||
|
||||
IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
|
||||
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
|
||||
WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP
|
||||
HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO
|
||||
THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL
|
||||
CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT
|
||||
OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef DEVICE_CONFIG_H
|
||||
#define DEVICE_CONFIG_H
|
||||
|
||||
#define _XTAL_FREQ 64000000
|
||||
|
||||
#endif /* DEVICE_CONFIG_H */
|
||||
/**
|
||||
End of File
|
||||
*/
|
754
306-controller_interface.X/mcc_generated_files/ecan.c
Normal file
754
306-controller_interface.X/mcc_generated_files/ecan.c
Normal file
@ -0,0 +1,754 @@
|
||||
/**
|
||||
ECAN Generated Driver File
|
||||
|
||||
@Company
|
||||
Microchip Technology Inc.
|
||||
|
||||
@File Name
|
||||
ecan.c
|
||||
|
||||
@Summary
|
||||
This is the generated driver implementation for the CAN driver using PIC10 / PIC12 / PIC16 / PIC18 MCUs
|
||||
|
||||
@Description
|
||||
This source file provides APIs for CAN.
|
||||
Generation Information :
|
||||
Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.7
|
||||
Device : PIC18F26K83
|
||||
Driver Version : 3.0.0
|
||||
The generated drivers are tested against the following:
|
||||
Compiler : XC8 2.31 and above
|
||||
MPLAB : MPLAB X 5.45
|
||||
*/
|
||||
|
||||
/*
|
||||
(c) 2018 Microchip Technology Inc. and its subsidiaries.
|
||||
|
||||
Subject to your compliance with these terms, you may use Microchip software and any
|
||||
derivatives exclusively with Microchip products. It is your responsibility to comply with third party
|
||||
license terms applicable to your use of third party software (including open source software) that
|
||||
may accompany Microchip software.
|
||||
|
||||
THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
|
||||
EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY
|
||||
IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE.
|
||||
|
||||
IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
|
||||
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
|
||||
WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP
|
||||
HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO
|
||||
THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL
|
||||
CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT
|
||||
OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
/**
|
||||
Section: Included Files
|
||||
*/
|
||||
|
||||
#include <xc.h>
|
||||
#include "ecan.h"
|
||||
|
||||
static void (*RXBnInterruptHandler)(void);
|
||||
static void (*RXBnOverflowHandler)(void);
|
||||
static void (*BusOffHandler)(void);
|
||||
static void (*TXPassiveHandler)(void);
|
||||
static void (*RXPassiveHandler)(void);
|
||||
static void (*TXWarningHandler)(void);
|
||||
static void (*RXWarningHandler)(void);
|
||||
|
||||
/**
|
||||
Local Functions
|
||||
*/
|
||||
static uint32_t convertReg2ExtendedCANid(uint8_t tempRXBn_EIDH, uint8_t tempRXBn_EIDL, uint8_t tempRXBn_SIDH, uint8_t tempRXBn_SIDL);
|
||||
static uint32_t convertReg2StandardCANid(uint8_t tempRXBn_SIDH, uint8_t tempRXBn_SIDL);
|
||||
static void convertCANid2Reg(uint32_t tempPassedInID, uint8_t canIdType, uint8_t *passedInEIDH, uint8_t *passedInEIDL, uint8_t *passedInSIDH, uint8_t *passedInSIDL);
|
||||
|
||||
static void RXBnDefaultInterruptHandler(void) {}
|
||||
static void RXBnOverflowDefaultHandler(void) {}
|
||||
static void BusOffDefaultHandler(void) {}
|
||||
static void TXPassiveDefaultHandler(void) {}
|
||||
static void RXPassiveDefaultHandler(void) {}
|
||||
static void TXWarningDefaultHandler(void) {}
|
||||
static void RXWarningDefaultHandler(void) {}
|
||||
|
||||
void ECAN_Initialize(void)
|
||||
{
|
||||
CANCON = 0x80;
|
||||
while (0x80 != (CANSTAT & 0xE0)); // wait until ECAN is in config mode
|
||||
|
||||
/**
|
||||
Mode 2
|
||||
*/
|
||||
ECANCON = 0x90;
|
||||
|
||||
/**
|
||||
Initialize CAN I/O
|
||||
*/
|
||||
CIOCON = 0x00;
|
||||
|
||||
/**
|
||||
Mask and Filter definitions
|
||||
........................................................
|
||||
CAN ID ID Type Mask Filter Buffer
|
||||
........................................................
|
||||
0x123 SID Acceptance Mask 0 Filter 0 FIFO
|
||||
........................................................
|
||||
*/
|
||||
|
||||
/**
|
||||
Configure Generic Buffers to be Transmit or Receive
|
||||
*/
|
||||
BSEL0 = 0x00;
|
||||
/**
|
||||
Mask and Filter definitions
|
||||
........................................................
|
||||
CAN ID ID Type Mask Filter Buffer
|
||||
........................................................
|
||||
........................................................
|
||||
*/
|
||||
// mask 0 is 11 bits for filter 0 and 1
|
||||
convertCANid2Reg(0x070, dSTANDARD_CAN_MSG_ID_2_0B, &RXM0EIDH, &RXM0EIDL, &RXM0SIDH, &RXM0SIDL);
|
||||
// filter 0 and 1 is broadcast message
|
||||
convertCANid2Reg(0x000, dSTANDARD_CAN_MSG_ID_2_0B, &RXF0EIDH, &RXF0EIDL, &RXF0SIDH, &RXF0SIDL);
|
||||
convertCANid2Reg(0x010, dSTANDARD_CAN_MSG_ID_2_0B, &RXF1EIDH, &RXF1EIDL, &RXF1SIDH, &RXF1SIDL);
|
||||
convertCANid2Reg(0x070, dSTANDARD_CAN_MSG_ID_2_0B, &RXF2EIDH, &RXF2EIDL, &RXF2SIDH, &RXF2SIDL);
|
||||
|
||||
/**
|
||||
Enable Filters
|
||||
*/
|
||||
RXFCON0 = 0x01; // Filter 0 is activated
|
||||
RXFCON1 = 0x00;
|
||||
|
||||
/**
|
||||
Assign Filters to Masks
|
||||
*/
|
||||
MSEL0 = 0x00; // filter 0 is assigned to mask 0
|
||||
MSEL1 = 0x00;
|
||||
MSEL2 = 0x00;
|
||||
MSEL3 = 0x00;
|
||||
|
||||
/**
|
||||
Initialize CAN Timings
|
||||
*/
|
||||
|
||||
/**
|
||||
Baud rate: 250kbps
|
||||
System frequency: 64000000
|
||||
ECAN clock frequency: 64000000
|
||||
Time quanta: 8
|
||||
Sample point: 1-1-4-2
|
||||
Sample point: 75%
|
||||
*/
|
||||
|
||||
BRGCON1 = 0x0F;
|
||||
BRGCON2 = 0x98;
|
||||
BRGCON3 = 0x81;
|
||||
|
||||
|
||||
ECAN_SetRXBnInterruptHandler(RXBnDefaultInterruptHandler);
|
||||
PIR5bits.RXBnIF = 0;
|
||||
PIE5bits.RXBnIE = 1;
|
||||
|
||||
ECAN_SetRXBnOverflowHandler(RXBnOverflowDefaultHandler);
|
||||
ECAN_SetBusOffHandler(BusOffDefaultHandler);
|
||||
ECAN_SetTXPassiveHandler(TXPassiveDefaultHandler);
|
||||
ECAN_SetRXPassiveHandler(RXPassiveDefaultHandler);
|
||||
ECAN_SetTXWarningHandler(TXWarningDefaultHandler);
|
||||
ECAN_SetRXWarningHandler(RXWarningDefaultHandler);
|
||||
PIR5bits.ERRIF = 0;
|
||||
PIE5bits.ERRIE = 1;
|
||||
|
||||
CANCON = 0x00;
|
||||
while (0x00 != (CANSTAT & 0xE0)); // wait until ECAN is in Normal mode
|
||||
|
||||
}
|
||||
/**
|
||||
Section: ECAN APIs
|
||||
*/
|
||||
void CAN_sleep(void)
|
||||
{
|
||||
CANCON = 0x20; // request disable mode
|
||||
while ((CANSTAT & 0xE0) != 0x20); // wait until ECAN is in disable mode
|
||||
//Wake up from sleep should set the CAN module straight into Normal mode
|
||||
}
|
||||
|
||||
uint8_t CAN_transmit(uCAN_MSG *tempCanMsg)
|
||||
{
|
||||
uint8_t tempEIDH = 0;
|
||||
uint8_t tempEIDL = 0;
|
||||
uint8_t tempSIDH = 0;
|
||||
uint8_t tempSIDL = 0;
|
||||
uint8_t returnValue = 0;
|
||||
|
||||
if (TXB0CONbits.TXREQ != 1)
|
||||
{
|
||||
convertCANid2Reg(tempCanMsg->frame.id, tempCanMsg->frame.idType, &tempEIDH, &tempEIDL, &tempSIDH, &tempSIDL);
|
||||
|
||||
TXB0EIDH = tempEIDH;
|
||||
TXB0EIDL = tempEIDL;
|
||||
TXB0SIDH = tempSIDH;
|
||||
TXB0SIDL = tempSIDL;
|
||||
TXB0DLC = tempCanMsg->frame.dlc | ((tempCanMsg->frame.rtr)<<6);
|
||||
TXB0D0 = tempCanMsg->frame.data0;
|
||||
TXB0D1 = tempCanMsg->frame.data1;
|
||||
TXB0D2 = tempCanMsg->frame.data2;
|
||||
TXB0D3 = tempCanMsg->frame.data3;
|
||||
TXB0D4 = tempCanMsg->frame.data4;
|
||||
TXB0D5 = tempCanMsg->frame.data5;
|
||||
TXB0D6 = tempCanMsg->frame.data6;
|
||||
TXB0D7 = tempCanMsg->frame.data7;
|
||||
|
||||
TXB0CONbits.TXREQ = 1; //Set the buffer to transmit
|
||||
returnValue = 1;
|
||||
|
||||
}
|
||||
else if (TXB1CONbits.TXREQ != 1)
|
||||
{
|
||||
|
||||
convertCANid2Reg(tempCanMsg->frame.id, tempCanMsg->frame.idType, &tempEIDH, &tempEIDL, &tempSIDH, &tempSIDL);
|
||||
|
||||
TXB1EIDH = tempEIDH;
|
||||
TXB1EIDL = tempEIDL;
|
||||
TXB1SIDH = tempSIDH;
|
||||
TXB1SIDL = tempSIDL;
|
||||
TXB1DLC = tempCanMsg->frame.dlc | ((tempCanMsg->frame.rtr)<<6);
|
||||
TXB1D0 = tempCanMsg->frame.data0;
|
||||
TXB1D1 = tempCanMsg->frame.data1;
|
||||
TXB1D2 = tempCanMsg->frame.data2;
|
||||
TXB1D3 = tempCanMsg->frame.data3;
|
||||
TXB1D4 = tempCanMsg->frame.data4;
|
||||
TXB1D5 = tempCanMsg->frame.data5;
|
||||
TXB1D6 = tempCanMsg->frame.data6;
|
||||
TXB1D7 = tempCanMsg->frame.data7;
|
||||
|
||||
TXB1CONbits.TXREQ = 1; //Set the buffer to transmit
|
||||
returnValue = 1;
|
||||
}
|
||||
else if (TXB2CONbits.TXREQ != 1)
|
||||
{
|
||||
|
||||
convertCANid2Reg(tempCanMsg->frame.id, tempCanMsg->frame.idType, &tempEIDH, &tempEIDL, &tempSIDH, &tempSIDL);
|
||||
|
||||
TXB2EIDH = tempEIDH;
|
||||
TXB2EIDL = tempEIDL;
|
||||
TXB2SIDH = tempSIDH;
|
||||
TXB2SIDL = tempSIDL;
|
||||
TXB2DLC = tempCanMsg->frame.dlc | ((tempCanMsg->frame.rtr)<<6);
|
||||
TXB2D0 = tempCanMsg->frame.data0;
|
||||
TXB2D1 = tempCanMsg->frame.data1;
|
||||
TXB2D2 = tempCanMsg->frame.data2;
|
||||
TXB2D3 = tempCanMsg->frame.data3;
|
||||
TXB2D4 = tempCanMsg->frame.data4;
|
||||
TXB2D5 = tempCanMsg->frame.data5;
|
||||
TXB2D6 = tempCanMsg->frame.data6;
|
||||
TXB2D7 = tempCanMsg->frame.data7;
|
||||
|
||||
TXB2CONbits.TXREQ = 1; //Set the buffer to transmit
|
||||
returnValue = 1;
|
||||
}
|
||||
|
||||
return (returnValue);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Version A2 has a silicon errata
|
||||
This code works for all revisions
|
||||
*/
|
||||
//Fix for Errata
|
||||
#define dRXB0CON_FIFO_POINTER_VALUE 0
|
||||
#define dRXB1CON_FIFO_POINTER_VALUE 1
|
||||
#define dB0CON_FIFO_POINTER_VALUE 2
|
||||
#define dB1CON_FIFO_POINTER_VALUE 3
|
||||
#define dB2CON_FIFO_POINTER_VALUE 4
|
||||
#define dB3CON_FIFO_POINTER_VALUE 5
|
||||
#define dB4CON_FIFO_POINTER_VALUE 6
|
||||
#define dB5CON_FIFO_POINTER_VALUE 7
|
||||
|
||||
uint8_t CAN_receive(uCAN_MSG *tempCanMsg) {
|
||||
uint8_t returnValue = 0;
|
||||
uint8_t tempECANCON;
|
||||
uint8_t tempReg;
|
||||
|
||||
tempReg = (CANCON & 0x0F); //get the next RX buffer to read
|
||||
tempECANCON = ECANCON; //Backup
|
||||
ECANCON |= (tempReg + 0x10);
|
||||
|
||||
//Per Errata need to use this method to read out BxCON register
|
||||
switch (tempReg)
|
||||
{
|
||||
case dRXB0CON_FIFO_POINTER_VALUE:
|
||||
if (RXB0CONbits.RXFUL != 0) // Check RXB0
|
||||
{
|
||||
if ((RXB0SIDL & 0x08) == 0x08) //If Extended Message
|
||||
{
|
||||
//message is extended
|
||||
tempCanMsg->frame.idType = (uint8_t) dEXTENDED_CAN_MSG_ID_2_0B;
|
||||
tempCanMsg->frame.id = convertReg2ExtendedCANid(RXB0EIDH, RXB0EIDL, RXB0SIDH, RXB0SIDL);
|
||||
}
|
||||
else
|
||||
{
|
||||
//message is standard
|
||||
tempCanMsg->frame.idType = (uint8_t) dSTANDARD_CAN_MSG_ID_2_0B;
|
||||
tempCanMsg->frame.id = convertReg2StandardCANid(RXB0SIDH, RXB0SIDL);
|
||||
}
|
||||
|
||||
tempCanMsg->frame.dlc = RXB0DLC & 0x0F;
|
||||
tempCanMsg->frame.rtr = RXB0DLC >> 6;
|
||||
tempCanMsg->frame.data0 = RXB0D0;
|
||||
tempCanMsg->frame.data1 = RXB0D1;
|
||||
tempCanMsg->frame.data2 = RXB0D2;
|
||||
tempCanMsg->frame.data3 = RXB0D3;
|
||||
tempCanMsg->frame.data4 = RXB0D4;
|
||||
tempCanMsg->frame.data5 = RXB0D5;
|
||||
tempCanMsg->frame.data6 = RXB0D6;
|
||||
tempCanMsg->frame.data7 = RXB0D7;
|
||||
RXB0CONbits.RXFUL = 0;
|
||||
returnValue = 1;
|
||||
}
|
||||
break;
|
||||
case dRXB1CON_FIFO_POINTER_VALUE:
|
||||
if (RXB1CONbits.RXFUL != 0) // Check RXB1
|
||||
{
|
||||
if ((RXB0SIDL & 0x08) == 0x08) //If Extended Message
|
||||
{
|
||||
//message is extended
|
||||
tempCanMsg->frame.idType = (uint8_t) dEXTENDED_CAN_MSG_ID_2_0B;
|
||||
tempCanMsg->frame.id = convertReg2ExtendedCANid(RXB0EIDH, RXB0EIDL, RXB0SIDH, RXB0SIDL);
|
||||
} else {
|
||||
//message is standard
|
||||
tempCanMsg->frame.idType = (uint8_t) dSTANDARD_CAN_MSG_ID_2_0B;
|
||||
tempCanMsg->frame.id = convertReg2StandardCANid(RXB0SIDH, RXB0SIDL);
|
||||
}
|
||||
|
||||
tempCanMsg->frame.dlc = RXB0DLC & 0x0F;
|
||||
tempCanMsg->frame.rtr = RXB0DLC >> 6;
|
||||
tempCanMsg->frame.data0 = RXB0D0;
|
||||
tempCanMsg->frame.data1 = RXB0D1;
|
||||
tempCanMsg->frame.data2 = RXB0D2;
|
||||
tempCanMsg->frame.data3 = RXB0D3;
|
||||
tempCanMsg->frame.data4 = RXB0D4;
|
||||
tempCanMsg->frame.data5 = RXB0D5;
|
||||
tempCanMsg->frame.data6 = RXB0D6;
|
||||
tempCanMsg->frame.data7 = RXB0D7;
|
||||
RXB1CONbits.RXFUL = 0;
|
||||
returnValue = 1;
|
||||
}
|
||||
break;
|
||||
case dB0CON_FIFO_POINTER_VALUE:
|
||||
if (B0CONbits.RXFUL != 0) //Check B0
|
||||
{
|
||||
if ((RXB0SIDL & 0x08) == 0x08) //If Extended Message
|
||||
{
|
||||
//message is extended
|
||||
tempCanMsg->frame.idType = (uint8_t) dEXTENDED_CAN_MSG_ID_2_0B;
|
||||
tempCanMsg->frame.id = convertReg2ExtendedCANid(RXB0EIDH, RXB0EIDL, RXB0SIDH, RXB0SIDL);
|
||||
} else {
|
||||
//message is standard
|
||||
tempCanMsg->frame.idType = (uint8_t) dSTANDARD_CAN_MSG_ID_2_0B;
|
||||
tempCanMsg->frame.id = convertReg2StandardCANid(RXB0SIDH, RXB0SIDL);
|
||||
}
|
||||
|
||||
tempCanMsg->frame.dlc = RXB0DLC & 0x0F;
|
||||
tempCanMsg->frame.rtr = RXB0DLC >> 6;
|
||||
tempCanMsg->frame.data0 = RXB0D0;
|
||||
tempCanMsg->frame.data1 = RXB0D1;
|
||||
tempCanMsg->frame.data2 = RXB0D2;
|
||||
tempCanMsg->frame.data3 = RXB0D3;
|
||||
tempCanMsg->frame.data4 = RXB0D4;
|
||||
tempCanMsg->frame.data5 = RXB0D5;
|
||||
tempCanMsg->frame.data6 = RXB0D6;
|
||||
tempCanMsg->frame.data7 = RXB0D7;
|
||||
B0CONbits.RXFUL = 0;
|
||||
returnValue = 1;
|
||||
}
|
||||
break;
|
||||
case dB1CON_FIFO_POINTER_VALUE:
|
||||
if (B1CONbits.RXFUL != 0) //CheckB1
|
||||
{
|
||||
if ((RXB0SIDL & 0x08) == 0x08) //If Extended Message
|
||||
{
|
||||
//message is extended
|
||||
tempCanMsg->frame.idType = (uint8_t) dEXTENDED_CAN_MSG_ID_2_0B;
|
||||
tempCanMsg->frame.id = convertReg2ExtendedCANid(RXB0EIDH, RXB0EIDL, RXB0SIDH, RXB0SIDL);
|
||||
}
|
||||
else
|
||||
{
|
||||
//message is standard
|
||||
tempCanMsg->frame.idType = (uint8_t) dSTANDARD_CAN_MSG_ID_2_0B;
|
||||
tempCanMsg->frame.id = convertReg2StandardCANid(RXB0SIDH, RXB0SIDL);
|
||||
}
|
||||
|
||||
tempCanMsg->frame.dlc = RXB0DLC & 0x0F;
|
||||
tempCanMsg->frame.rtr = RXB0DLC >> 6;
|
||||
tempCanMsg->frame.data0 = RXB0D0;
|
||||
tempCanMsg->frame.data1 = RXB0D1;
|
||||
tempCanMsg->frame.data2 = RXB0D2;
|
||||
tempCanMsg->frame.data3 = RXB0D3;
|
||||
tempCanMsg->frame.data4 = RXB0D4;
|
||||
tempCanMsg->frame.data5 = RXB0D5;
|
||||
tempCanMsg->frame.data6 = RXB0D6;
|
||||
tempCanMsg->frame.data7 = RXB0D7;
|
||||
B1CONbits.RXFUL = 0;
|
||||
returnValue = 1;
|
||||
}
|
||||
break;
|
||||
case dB2CON_FIFO_POINTER_VALUE:
|
||||
if (B2CONbits.RXFUL != 0) //CheckB2
|
||||
{
|
||||
if ((RXB0SIDL & 0x08) == 0x08) //If Extended Message
|
||||
{
|
||||
//message is extended
|
||||
tempCanMsg->frame.idType = (uint8_t) dEXTENDED_CAN_MSG_ID_2_0B;
|
||||
tempCanMsg->frame.id = convertReg2ExtendedCANid(RXB0EIDH, RXB0EIDL, RXB0SIDH, RXB0SIDL);
|
||||
}
|
||||
else
|
||||
{
|
||||
//message is standard
|
||||
tempCanMsg->frame.idType = (uint8_t) dSTANDARD_CAN_MSG_ID_2_0B;
|
||||
tempCanMsg->frame.id = convertReg2StandardCANid(RXB0SIDH, RXB0SIDL);
|
||||
}
|
||||
|
||||
tempCanMsg->frame.dlc = RXB0DLC & 0x0F;
|
||||
tempCanMsg->frame.rtr = RXB0DLC >> 6;
|
||||
tempCanMsg->frame.data0 = RXB0D0;
|
||||
tempCanMsg->frame.data1 = RXB0D1;
|
||||
tempCanMsg->frame.data2 = RXB0D2;
|
||||
tempCanMsg->frame.data3 = RXB0D3;
|
||||
tempCanMsg->frame.data4 = RXB0D4;
|
||||
tempCanMsg->frame.data5 = RXB0D5;
|
||||
tempCanMsg->frame.data6 = RXB0D6;
|
||||
tempCanMsg->frame.data7 = RXB0D7;
|
||||
B2CONbits.RXFUL = 0;
|
||||
returnValue = 1;
|
||||
}
|
||||
break;
|
||||
case dB3CON_FIFO_POINTER_VALUE:
|
||||
if (B3CONbits.RXFUL != 0) //CheckB3
|
||||
{
|
||||
if ((RXB0SIDL & 0x08) == 0x08) //If Extended Message
|
||||
{
|
||||
//message is extended
|
||||
tempCanMsg->frame.idType = (uint8_t) dEXTENDED_CAN_MSG_ID_2_0B;
|
||||
tempCanMsg->frame.id = convertReg2ExtendedCANid(RXB0EIDH, RXB0EIDL, RXB0SIDH, RXB0SIDL);
|
||||
}
|
||||
else
|
||||
{
|
||||
//message is standard
|
||||
tempCanMsg->frame.idType = (uint8_t) dSTANDARD_CAN_MSG_ID_2_0B;
|
||||
tempCanMsg->frame.id = convertReg2StandardCANid(RXB0SIDH, RXB0SIDL);
|
||||
}
|
||||
|
||||
tempCanMsg->frame.dlc = RXB0DLC & 0x0F;
|
||||
tempCanMsg->frame.rtr = RXB0DLC >> 6;
|
||||
tempCanMsg->frame.data0 = RXB0D0;
|
||||
tempCanMsg->frame.data1 = RXB0D1;
|
||||
tempCanMsg->frame.data2 = RXB0D2;
|
||||
tempCanMsg->frame.data3 = RXB0D3;
|
||||
tempCanMsg->frame.data4 = RXB0D4;
|
||||
tempCanMsg->frame.data5 = RXB0D5;
|
||||
tempCanMsg->frame.data6 = RXB0D6;
|
||||
tempCanMsg->frame.data7 = RXB0D7;
|
||||
B3CONbits.RXFUL = 0;
|
||||
returnValue = 1;
|
||||
}
|
||||
break;
|
||||
case dB4CON_FIFO_POINTER_VALUE:
|
||||
if (B4CONbits.RXFUL != 0) //CheckB4
|
||||
{
|
||||
if ((RXB0SIDL & 0x08) == 0x08) //If Extended Message
|
||||
{
|
||||
//message is extended
|
||||
tempCanMsg->frame.idType = (uint8_t) dEXTENDED_CAN_MSG_ID_2_0B;
|
||||
tempCanMsg->frame.id = convertReg2ExtendedCANid(RXB0EIDH, RXB0EIDL, RXB0SIDH, RXB0SIDL);
|
||||
}
|
||||
else
|
||||
{
|
||||
//message is standard
|
||||
tempCanMsg->frame.idType = (uint8_t) dSTANDARD_CAN_MSG_ID_2_0B;
|
||||
tempCanMsg->frame.id = convertReg2StandardCANid(RXB0SIDH, RXB0SIDL);
|
||||
}
|
||||
|
||||
tempCanMsg->frame.dlc = RXB0DLC & 0x0F;
|
||||
tempCanMsg->frame.rtr = RXB0DLC >> 6;
|
||||
tempCanMsg->frame.data0 = RXB0D0;
|
||||
tempCanMsg->frame.data1 = RXB0D1;
|
||||
tempCanMsg->frame.data2 = RXB0D2;
|
||||
tempCanMsg->frame.data3 = RXB0D3;
|
||||
tempCanMsg->frame.data4 = RXB0D4;
|
||||
tempCanMsg->frame.data5 = RXB0D5;
|
||||
tempCanMsg->frame.data6 = RXB0D6;
|
||||
tempCanMsg->frame.data7 = RXB0D7;
|
||||
B4CONbits.RXFUL = 0;
|
||||
returnValue = 1;
|
||||
}
|
||||
break;
|
||||
case dB5CON_FIFO_POINTER_VALUE:
|
||||
if (B5CONbits.RXFUL != 0) //CheckB5
|
||||
{
|
||||
if ((RXB0SIDL & 0x08) == 0x08) //If Extended Message
|
||||
{
|
||||
//message is extended
|
||||
tempCanMsg->frame.idType = (uint8_t) dEXTENDED_CAN_MSG_ID_2_0B;
|
||||
tempCanMsg->frame.id = convertReg2ExtendedCANid(RXB0EIDH, RXB0EIDL, RXB0SIDH, RXB0SIDL);
|
||||
}
|
||||
else
|
||||
{
|
||||
//message is standard
|
||||
tempCanMsg->frame.idType = (uint8_t) dSTANDARD_CAN_MSG_ID_2_0B;
|
||||
tempCanMsg->frame.id = convertReg2StandardCANid(RXB0SIDH, RXB0SIDL);
|
||||
}
|
||||
|
||||
tempCanMsg->frame.dlc = RXB0DLC & 0x0F;
|
||||
tempCanMsg->frame.rtr = RXB0DLC >> 6;
|
||||
tempCanMsg->frame.data0 = RXB0D0;
|
||||
tempCanMsg->frame.data1 = RXB0D1;
|
||||
tempCanMsg->frame.data2 = RXB0D2;
|
||||
tempCanMsg->frame.data3 = RXB0D3;
|
||||
tempCanMsg->frame.data4 = RXB0D4;
|
||||
tempCanMsg->frame.data5 = RXB0D5;
|
||||
tempCanMsg->frame.data6 = RXB0D6;
|
||||
tempCanMsg->frame.data7 = RXB0D7;
|
||||
B5CONbits.RXFUL = 0;
|
||||
returnValue = 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
ECANCON = tempECANCON;
|
||||
return (returnValue);
|
||||
}
|
||||
|
||||
uint8_t CAN_messagesInBuffer(void) {
|
||||
uint8_t messageCount = 0;
|
||||
if (RXB0CONbits.RXFUL != 0) //CheckRXB0
|
||||
{
|
||||
messageCount++;
|
||||
}
|
||||
if (RXB1CONbits.RXFUL != 0) //CheckRXB1
|
||||
{
|
||||
messageCount++;
|
||||
}
|
||||
if (B0CONbits.RXFUL_TXBIF != 0) //CheckB0
|
||||
{
|
||||
messageCount++;
|
||||
}
|
||||
if (B1CONbits.RXFUL_TXBIF != 0) //CheckB1
|
||||
{
|
||||
messageCount++;
|
||||
}
|
||||
if (B2CONbits.RXFUL_TXBIF != 0) //CheckB2
|
||||
{
|
||||
messageCount++;
|
||||
}
|
||||
if (B3CONbits.RXFUL_TXBIF != 0) //CheckB3
|
||||
{
|
||||
messageCount++;
|
||||
}
|
||||
if (B4CONbits.RXFUL_TXBIF != 0) //CheckB4
|
||||
{
|
||||
messageCount++;
|
||||
}
|
||||
if (B5CONbits.RXFUL_TXBIF != 0) //CheckB5
|
||||
{
|
||||
messageCount++;
|
||||
}
|
||||
return (messageCount);
|
||||
}
|
||||
|
||||
uint8_t CAN_isBusOff(void)
|
||||
{
|
||||
uint8_t returnValue = 0;
|
||||
|
||||
//COMSTAT bit 5 TXBO: Transmitter Bus-Off bit
|
||||
//1 = Transmit error counter > 255
|
||||
//0 = Transmit error counter less then or equal to 255
|
||||
|
||||
if (COMSTATbits.TXBO == 1) {
|
||||
returnValue = 1;
|
||||
}
|
||||
return (returnValue);
|
||||
}
|
||||
|
||||
uint8_t CAN_isRXErrorPassive(void)
|
||||
{
|
||||
uint8_t returnValue = 0;
|
||||
|
||||
//COMSTAT bit 3 RXBP: Receiver Bus Passive bit
|
||||
//1 = Receive error counter > 127
|
||||
//0 = Receive error counter less then or equal to 127
|
||||
|
||||
if (COMSTATbits.RXBP == 1) {
|
||||
returnValue = 1;
|
||||
}
|
||||
return (returnValue);
|
||||
}
|
||||
|
||||
uint8_t CAN_isTXErrorPassive(void)
|
||||
{
|
||||
uint8_t returnValue = 0;
|
||||
|
||||
//COMSTAT bit 4 TXBP: Transmitter Bus Passive bit
|
||||
//1 = Transmit error counter > 127
|
||||
//0 = Transmit error counter less then or equal to 127
|
||||
|
||||
if (COMSTATbits.TXBP == 1)
|
||||
{
|
||||
returnValue = 1;
|
||||
}
|
||||
return (returnValue);
|
||||
}
|
||||
|
||||
/**
|
||||
Internal functions
|
||||
*/
|
||||
|
||||
static uint32_t convertReg2ExtendedCANid(uint8_t tempRXBn_EIDH, uint8_t tempRXBn_EIDL, uint8_t tempRXBn_SIDH, uint8_t tempRXBn_SIDL) {
|
||||
uint32_t returnValue = 0;
|
||||
uint32_t ConvertedID = 0;
|
||||
uint8_t CAN_standardLo_ID_lo2bits;
|
||||
uint8_t CAN_standardLo_ID_hi3bits;
|
||||
|
||||
CAN_standardLo_ID_lo2bits = (uint8_t)(tempRXBn_SIDL & 0x03);
|
||||
CAN_standardLo_ID_hi3bits = (uint8_t)(tempRXBn_SIDL >> 5);
|
||||
ConvertedID = (uint32_t)(tempRXBn_SIDH << 3);
|
||||
ConvertedID = ConvertedID + CAN_standardLo_ID_hi3bits;
|
||||
ConvertedID = (ConvertedID << 2);
|
||||
ConvertedID = ConvertedID + CAN_standardLo_ID_lo2bits;
|
||||
ConvertedID = (ConvertedID << 8);
|
||||
ConvertedID = ConvertedID + tempRXBn_EIDH;
|
||||
ConvertedID = (ConvertedID << 8);
|
||||
ConvertedID = ConvertedID + tempRXBn_EIDL;
|
||||
returnValue = ConvertedID;
|
||||
return (returnValue);
|
||||
}
|
||||
|
||||
static uint32_t convertReg2StandardCANid(uint8_t tempRXBn_SIDH, uint8_t tempRXBn_SIDL) {
|
||||
uint32_t returnValue = 0;
|
||||
uint32_t ConvertedID;
|
||||
//if standard message (11 bits)
|
||||
//EIDH = 0 + EIDL = 0 + SIDH + upper three bits SIDL (3rd bit needs to be clear)
|
||||
//1111 1111 111
|
||||
ConvertedID = (uint32_t)(tempRXBn_SIDH << 3);
|
||||
ConvertedID = ConvertedID + (uint32_t)(tempRXBn_SIDL >> 5);
|
||||
returnValue = ConvertedID;
|
||||
return (returnValue);
|
||||
}
|
||||
|
||||
static void convertCANid2Reg(uint32_t tempPassedInID, uint8_t canIdType, uint8_t *passedInEIDH, uint8_t *passedInEIDL, uint8_t *passedInSIDH, uint8_t *passedInSIDL) {
|
||||
uint8_t wipSIDL = 0;
|
||||
|
||||
if (canIdType == dEXTENDED_CAN_MSG_ID_2_0B)
|
||||
{
|
||||
//EIDL
|
||||
*passedInEIDL = 0xFF & tempPassedInID; //CAN_extendedLo_ID_TX1 = &HFF And CAN_UserEnter_ID_TX1
|
||||
tempPassedInID = tempPassedInID >> 8; //CAN_UserEnter_ID_TX1 = CAN_UserEnter_ID_TX1 >> 8
|
||||
|
||||
//EIDH
|
||||
*passedInEIDH = 0xFF & tempPassedInID; //CAN_extendedHi_ID_TX1 = &HFF And CAN_UserEnter_ID_TX1
|
||||
tempPassedInID = tempPassedInID >> 8; //CAN_UserEnter_ID_TX1 = CAN_UserEnter_ID_TX1 >> 8
|
||||
|
||||
//SIDL
|
||||
//push back 5 and or it
|
||||
wipSIDL = 0x03 & tempPassedInID;
|
||||
tempPassedInID = tempPassedInID << 3; //CAN_UserEnter_ID_TX1 = CAN_UserEnter_ID_TX1 << 3
|
||||
wipSIDL = (0xE0 & tempPassedInID) + wipSIDL;
|
||||
wipSIDL = (uint8_t)(wipSIDL + 0x08); // TEMP_CAN_standardLo_ID_TX1 = TEMP_CAN_standardLo_ID_TX1 + &H8
|
||||
*passedInSIDL = (uint8_t)(0xEB & wipSIDL); //CAN_standardLo_ID_TX1 = &HEB And TEMP_CAN_standardLo_ID_TX1
|
||||
|
||||
//SIDH
|
||||
tempPassedInID = tempPassedInID >> 8;
|
||||
*passedInSIDH = 0xFF & tempPassedInID;
|
||||
}
|
||||
else //(canIdType == dSTANDARD_CAN_MSG_ID_2_0B)
|
||||
{
|
||||
*passedInEIDH = 0;
|
||||
*passedInEIDL = 0;
|
||||
tempPassedInID = tempPassedInID << 5;
|
||||
*passedInSIDL = 0xFF & tempPassedInID;
|
||||
tempPassedInID = tempPassedInID >> 8;
|
||||
*passedInSIDH = 0xFF & tempPassedInID;
|
||||
}
|
||||
}
|
||||
|
||||
void ECAN_SetRXBnInterruptHandler(void (*handler)(void))
|
||||
{
|
||||
RXBnInterruptHandler = handler;
|
||||
}
|
||||
|
||||
void ECAN_RXBnI_ISR(void)
|
||||
{
|
||||
RXBnInterruptHandler();
|
||||
PIR5bits.RXBnIF = 0; // The ECAN hardware overrides the setting of this bit (to '1') when any receive buffer is not empty.
|
||||
}
|
||||
|
||||
void ECAN_SetRXBnOverflowHandler(void (*handler)(void))
|
||||
{
|
||||
RXBnOverflowHandler = handler;
|
||||
}
|
||||
|
||||
void ECAN_SetBusOffHandler(void (*handler)(void))
|
||||
{
|
||||
BusOffHandler = handler;
|
||||
}
|
||||
|
||||
void ECAN_SetTXPassiveHandler(void (*handler)(void))
|
||||
{
|
||||
TXPassiveHandler = handler;
|
||||
}
|
||||
|
||||
void ECAN_SetRXPassiveHandler(void (*handler)(void))
|
||||
{
|
||||
RXPassiveHandler = handler;
|
||||
}
|
||||
|
||||
void ECAN_SetTXWarningHandler(void (*handler)(void))
|
||||
{
|
||||
TXWarningHandler = handler;
|
||||
}
|
||||
|
||||
void ECAN_SetRXWarningHandler(void (*handler)(void))
|
||||
{
|
||||
RXWarningHandler = handler;
|
||||
}
|
||||
|
||||
void ECAN_ERRI_ISR(void)
|
||||
{
|
||||
if (COMSTATbits.RXB1OVFL)
|
||||
{
|
||||
RXBnOverflowHandler();
|
||||
COMSTATbits.RXB1OVFL = 0; // In mode 2, this clears RXBnOVFL
|
||||
}
|
||||
|
||||
if (COMSTATbits.TXBO)
|
||||
{
|
||||
BusOffHandler();
|
||||
}
|
||||
|
||||
if (COMSTATbits.TXBP)
|
||||
{
|
||||
TXPassiveHandler();
|
||||
}
|
||||
|
||||
if (COMSTATbits.RXBP)
|
||||
{
|
||||
RXPassiveHandler();
|
||||
}
|
||||
|
||||
if (COMSTATbits.TXWARN)
|
||||
{
|
||||
TXWarningHandler();
|
||||
}
|
||||
|
||||
if (COMSTATbits.RXWARN)
|
||||
{
|
||||
RXWarningHandler();
|
||||
}
|
||||
|
||||
PIR5bits.ERRIF = 0;
|
||||
}
|
||||
|
||||
|
589
306-controller_interface.X/mcc_generated_files/ecan.h
Normal file
589
306-controller_interface.X/mcc_generated_files/ecan.h
Normal file
@ -0,0 +1,589 @@
|
||||
/**
|
||||
ECAN Generated Driver API Header File
|
||||
|
||||
@Company
|
||||
Microchip Technology Inc.
|
||||
|
||||
@File Name
|
||||
ecan.h
|
||||
|
||||
@Summary
|
||||
This is the generated header file for the ECAN driver using PIC10 / PIC12 / PIC16 / PIC18 MCUs
|
||||
|
||||
@Description
|
||||
This header file provides APIs driver for ECAN.
|
||||
Generation Information :
|
||||
Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.7
|
||||
Device : PIC18F26K83
|
||||
Driver Version : 3.0.0
|
||||
The generated drivers are tested against the following:
|
||||
Compiler : XC8 2.31 and above
|
||||
MPLAB : MPLAB X 5.45
|
||||
*/
|
||||
|
||||
/*
|
||||
(c) 2018 Microchip Technology Inc. and its subsidiaries.
|
||||
|
||||
Subject to your compliance with these terms, you may use Microchip software and any
|
||||
derivatives exclusively with Microchip products. It is your responsibility to comply with third party
|
||||
license terms applicable to your use of third party software (including open source software) that
|
||||
may accompany Microchip software.
|
||||
|
||||
THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
|
||||
EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY
|
||||
IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE.
|
||||
|
||||
IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
|
||||
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
|
||||
WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP
|
||||
HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO
|
||||
THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL
|
||||
CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT
|
||||
OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef ECAN_H
|
||||
#define ECAN_H
|
||||
|
||||
|
||||
/**
|
||||
Section: Included Files
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
|
||||
Global Defines
|
||||
|
||||
*/
|
||||
typedef union {
|
||||
|
||||
struct {
|
||||
uint8_t idType;
|
||||
uint32_t id;
|
||||
uint8_t dlc;
|
||||
uint8_t data0;
|
||||
uint8_t data1;
|
||||
uint8_t data2;
|
||||
uint8_t data3;
|
||||
uint8_t data4;
|
||||
uint8_t data5;
|
||||
uint8_t data6;
|
||||
uint8_t data7;
|
||||
uint8_t rtr;
|
||||
} frame;
|
||||
uint8_t array[15];
|
||||
} uCAN_MSG;
|
||||
|
||||
/**
|
||||
Defines
|
||||
*/
|
||||
|
||||
#define dSTANDARD_CAN_MSG_ID_2_0B 1
|
||||
#define dEXTENDED_CAN_MSG_ID_2_0B 2
|
||||
|
||||
/**
|
||||
Section: ECAN APIs
|
||||
*/
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Initializes the ECAN module.
|
||||
|
||||
@Description
|
||||
This routine sets all the set parameters to the ECAN module.
|
||||
|
||||
@Preconditions
|
||||
None
|
||||
|
||||
@Param
|
||||
None
|
||||
|
||||
@Returns
|
||||
None
|
||||
|
||||
@Example
|
||||
<code>
|
||||
ECAN_Initialize();
|
||||
</code>
|
||||
*/
|
||||
void ECAN_Initialize(void);
|
||||
|
||||
/**
|
||||
|
||||
@Summary
|
||||
CAN_sleep
|
||||
|
||||
@Description
|
||||
Puts the CAN module to sleep
|
||||
|
||||
@Param
|
||||
None
|
||||
|
||||
@Returns
|
||||
None
|
||||
|
||||
@Example
|
||||
<code>
|
||||
CAN_init();
|
||||
</code>
|
||||
|
||||
*/
|
||||
|
||||
void CAN_sleep(void);
|
||||
|
||||
/**
|
||||
@Summary
|
||||
CAN_transmit
|
||||
|
||||
@Description
|
||||
Transmits out sCAN_MSG
|
||||
|
||||
@Param
|
||||
Pointer to a sCAN_MSG
|
||||
|
||||
@Returns
|
||||
True or False if message was loaded to transmit buffer
|
||||
|
||||
@Example
|
||||
<code>
|
||||
uCAN_MSG txMessage;
|
||||
CAN_transmit(&txMessage);
|
||||
</code>
|
||||
*/
|
||||
uint8_t CAN_transmit(uCAN_MSG *tempCanMsg);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@Summary
|
||||
CAN_receive
|
||||
|
||||
@Description
|
||||
Receives CAN messages
|
||||
|
||||
@Param
|
||||
Pointer to a sCAN_MSG
|
||||
|
||||
@Returns
|
||||
True or False for a new message
|
||||
|
||||
@Example
|
||||
<code>
|
||||
uCAN_MSG rxMessage;
|
||||
CAN_receive(&rxMessage);
|
||||
</code>
|
||||
|
||||
*/
|
||||
uint8_t CAN_receive(uCAN_MSG *tempCanMsg);
|
||||
|
||||
/**
|
||||
|
||||
@Summary
|
||||
CAN_messagesInBuffer
|
||||
|
||||
@Description
|
||||
Checks to see how many messages are in the buffer
|
||||
|
||||
@Param
|
||||
None
|
||||
|
||||
@Returns
|
||||
Returns total number of messages in the buffers
|
||||
|
||||
@Example
|
||||
<code>
|
||||
uint8_t nrMsg;
|
||||
nrMsg = CAN_messagesInBuffer();
|
||||
</code>
|
||||
*/
|
||||
uint8_t CAN_messagesInBuffer(void);
|
||||
|
||||
/**
|
||||
|
||||
@Summary
|
||||
CAN_isBusOff
|
||||
|
||||
@Description
|
||||
Checks to see if module is busoff
|
||||
|
||||
@Param
|
||||
None
|
||||
|
||||
@Returns
|
||||
True if module is in Busoff, False is if it is not
|
||||
|
||||
@Example
|
||||
<code>
|
||||
uint8_t busOff;
|
||||
busOff = CAN_isBusOff();
|
||||
</code>
|
||||
|
||||
*/
|
||||
|
||||
uint8_t CAN_isBusOff(void);
|
||||
|
||||
/**
|
||||
|
||||
@Summary
|
||||
CAN_isRXErrorPassive
|
||||
|
||||
@Description
|
||||
Checks to see if module is RX Error Passive
|
||||
|
||||
@Param
|
||||
None
|
||||
|
||||
@Returns
|
||||
True if module is in RX Error Passive, False is if it is not
|
||||
|
||||
@Example
|
||||
<code>
|
||||
uint8_t errRxPasive;
|
||||
errRxPasive = CAN_isRXErrorPassive();
|
||||
</code>
|
||||
|
||||
*/
|
||||
|
||||
uint8_t CAN_isRXErrorPassive(void);
|
||||
|
||||
/**
|
||||
|
||||
@Summary
|
||||
CAN_isTXErrorPassive
|
||||
|
||||
@Description
|
||||
Checks to see if module is TX Error Passive
|
||||
|
||||
@Param
|
||||
None
|
||||
|
||||
@Returns
|
||||
True if module is in TX Error Passive, False is if it is not
|
||||
|
||||
@Example
|
||||
<code>
|
||||
uint8_t errTxPasive;
|
||||
errTxPasive = CAN_isTXErrorPassive();
|
||||
</code>
|
||||
|
||||
*/
|
||||
|
||||
uint8_t CAN_isTXErrorPassive(void);
|
||||
|
||||
/**
|
||||
@Summary
|
||||
ECAN_SetRXBnInterruptHandler
|
||||
|
||||
@Description
|
||||
Sets the ECAN Receive buffer n interrupt handler
|
||||
|
||||
@Param
|
||||
Address of the callback routine
|
||||
|
||||
@Returns
|
||||
None
|
||||
|
||||
@Example
|
||||
<code>
|
||||
volatile bool customRXBnFlag = false;
|
||||
|
||||
void CustomRXBnInterruptHandler(void)
|
||||
{
|
||||
customRXBnFlag = true;
|
||||
// ...
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
// ...
|
||||
ECAN_SetRXBnInterruptHandler(CustomRXBnInterruptHandler);
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (customRXBnFlag) {
|
||||
customRXBnFlag = false;
|
||||
// ...
|
||||
}
|
||||
}
|
||||
}
|
||||
</code>
|
||||
*/
|
||||
void ECAN_SetRXBnInterruptHandler(void (*handler)(void));
|
||||
|
||||
/**
|
||||
@Summary
|
||||
ECAN_RXBnI_ISR
|
||||
|
||||
@Description
|
||||
Implements the ECAN Receive buffer n interrupt service routine
|
||||
|
||||
@Param
|
||||
None
|
||||
|
||||
@Returns
|
||||
None
|
||||
*/
|
||||
void ECAN_RXBnI_ISR(void);
|
||||
|
||||
/**
|
||||
@Summary
|
||||
ECAN_SetRXBnOverflowHandler
|
||||
|
||||
@Description
|
||||
Sets the ECAN Receive buffer n overflow interrupt handler
|
||||
|
||||
@Param
|
||||
Address of the callback routine
|
||||
|
||||
@Returns
|
||||
None
|
||||
|
||||
@Example
|
||||
<code>
|
||||
volatile bool customRXBnOverflowFlag = false;
|
||||
|
||||
void CustomRXBnOverflowHandler(void)
|
||||
{
|
||||
customRXBnOverflowFlag = true;
|
||||
// ...
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
// ...
|
||||
ECAN_SetRXBnOverflowHandler(CustomRXBnOverflowHandler);
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (customRXBnOverflowFlag) {
|
||||
customRXBnOverflowFlag = false;
|
||||
// ...
|
||||
}
|
||||
}
|
||||
}
|
||||
</code>
|
||||
*/
|
||||
void ECAN_SetRXBnOverflowHandler(void (*handler)(void));
|
||||
|
||||
/**
|
||||
@Summary
|
||||
ECAN_SetBusOffHandler
|
||||
|
||||
@Description
|
||||
Sets the ECAN Bus off interrupt handler
|
||||
|
||||
@Param
|
||||
Address of the callback routine
|
||||
|
||||
@Returns
|
||||
None
|
||||
|
||||
@Example
|
||||
<code>
|
||||
volatile bool customBusOffFlag = false;
|
||||
|
||||
void CustomBusOffHandler(void)
|
||||
{
|
||||
customBusOffFlag = true;
|
||||
// ...
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
// ...
|
||||
ECAN_SetBusOffHandler(CustomBusOffHandler);
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (customBusOffFlag) {
|
||||
customBusOffFlag = false;
|
||||
// ...
|
||||
}
|
||||
}
|
||||
}
|
||||
</code>
|
||||
*/
|
||||
void ECAN_SetBusOffHandler(void (*handler)(void));
|
||||
|
||||
/**
|
||||
@Summary
|
||||
ECAN_SetTXPassiveHandler
|
||||
|
||||
@Description
|
||||
Sets the ECAN TX passive interrupt handler
|
||||
|
||||
@Param
|
||||
Address of the callback routine
|
||||
|
||||
@Returns
|
||||
None
|
||||
|
||||
@Example
|
||||
<code>
|
||||
volatile bool customTXPassiveFlag = false;
|
||||
|
||||
void CustomTXPassiveHandler(void)
|
||||
{
|
||||
customTXPassiveFlag = true;
|
||||
// ...
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
// ...
|
||||
ECAN_SetTXPassiveHandler(CustomTXPassiveHandler);
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (customTXPassiveFlag) {
|
||||
customTXPassiveFlag = false;
|
||||
// ...
|
||||
}
|
||||
}
|
||||
}
|
||||
</code>
|
||||
*/
|
||||
void ECAN_SetTXPassiveHandler(void (*handler)(void));
|
||||
|
||||
/**
|
||||
@Summary
|
||||
ECAN_SetRXPassiveHandler
|
||||
|
||||
@Description
|
||||
Sets the ECAN RX passive interrupt handler
|
||||
|
||||
@Param
|
||||
Address of the callback routine
|
||||
|
||||
@Returns
|
||||
None
|
||||
|
||||
@Example
|
||||
<code>
|
||||
volatile bool customRXPassiveFlag = false;
|
||||
|
||||
void CustomRXPassiveHandler(void)
|
||||
{
|
||||
customRXPassiveFlag = true;
|
||||
// ...
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
// ...
|
||||
ECAN_SetRXPassiveHandler(CustomRXPassiveHandler);
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (customRXPassiveFlag) {
|
||||
customRXPassiveFlag = false;
|
||||
// ...
|
||||
}
|
||||
}
|
||||
}
|
||||
</code>
|
||||
*/
|
||||
void ECAN_SetRXPassiveHandler(void (*handler)(void));
|
||||
|
||||
/**
|
||||
@Summary
|
||||
ECAN_SetTXWarningHandler
|
||||
|
||||
@Description
|
||||
Sets the ECAN TX warning interrupt handler
|
||||
|
||||
@Param
|
||||
Address of the callback routine
|
||||
|
||||
@Returns
|
||||
None
|
||||
|
||||
@Example
|
||||
<code>
|
||||
volatile bool customTXWarningFlag = false;
|
||||
|
||||
void CustomTXWarningHandler(void)
|
||||
{
|
||||
customTXWarningFlag = true;
|
||||
// ...
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
// ...
|
||||
ECAN_SetTXWarningHandler(CustomTXWarningHandler);
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (customTXWarningFlag) {
|
||||
customTXWarningFlag = false;
|
||||
// ...
|
||||
}
|
||||
}
|
||||
}
|
||||
</code>
|
||||
*/
|
||||
void ECAN_SetTXWarningHandler(void (*handler)(void));
|
||||
|
||||
/**
|
||||
@Summary
|
||||
ECAN_SetRXWarningHandler
|
||||
|
||||
@Description
|
||||
Sets the ECAN RX warning interrupt handler
|
||||
|
||||
@Param
|
||||
Address of the callback routine
|
||||
|
||||
@Returns
|
||||
None
|
||||
|
||||
@Example
|
||||
<code>
|
||||
volatile bool customRXWarningFlag = false;
|
||||
|
||||
void CustomRXWarningHandler(void)
|
||||
{
|
||||
customRXWarningFlag = true;
|
||||
// ...
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
// ...
|
||||
ECAN_SetRXWarningHandler(CustomRXWarningHandler);
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (customRXWarningFlag) {
|
||||
customRXWarningFlag = false;
|
||||
// ...
|
||||
}
|
||||
}
|
||||
}
|
||||
</code>
|
||||
*/
|
||||
void ECAN_SetRXWarningHandler(void (*handler)(void));
|
||||
|
||||
/**
|
||||
@Summary
|
||||
ECAN_ERRI_ISR
|
||||
|
||||
@Description
|
||||
Implements the ECAN Module error interrupt service routine
|
||||
|
||||
@Param
|
||||
None
|
||||
|
||||
@Returns
|
||||
None
|
||||
*/
|
||||
void ECAN_ERRI_ISR(void);
|
||||
|
||||
|
||||
#endif // ECAN_H
|
@ -0,0 +1,80 @@
|
||||
/**
|
||||
Generated Interrupt Manager Source File
|
||||
|
||||
@Company:
|
||||
Microchip Technology Inc.
|
||||
|
||||
@File Name:
|
||||
interrupt_manager.c
|
||||
|
||||
@Summary:
|
||||
This is the Interrupt Manager file generated using PIC10 / PIC12 / PIC16 / PIC18 MCUs
|
||||
|
||||
@Description:
|
||||
This header file provides implementations for global interrupt handling.
|
||||
For individual peripheral handlers please see the peripheral driver for
|
||||
all modules selected in the GUI.
|
||||
Generation Information :
|
||||
Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8
|
||||
Device : PIC18F26K83
|
||||
Driver Version : 2.04
|
||||
The generated drivers are tested against the following:
|
||||
Compiler : XC8 2.36 and above or later
|
||||
MPLAB : MPLAB X 6.00
|
||||
*/
|
||||
|
||||
/*
|
||||
(c) 2018 Microchip Technology Inc. and its subsidiaries.
|
||||
|
||||
Subject to your compliance with these terms, you may use Microchip software and any
|
||||
derivatives exclusively with Microchip products. It is your responsibility to comply with third party
|
||||
license terms applicable to your use of third party software (including open source software) that
|
||||
may accompany Microchip software.
|
||||
|
||||
THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
|
||||
EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY
|
||||
IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE.
|
||||
|
||||
IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
|
||||
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
|
||||
WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP
|
||||
HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO
|
||||
THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL
|
||||
CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT
|
||||
OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "interrupt_manager.h"
|
||||
#include "mcc.h"
|
||||
|
||||
void INTERRUPT_Initialize (void)
|
||||
{
|
||||
// Disable Interrupt Priority Vectors (16CXXX Compatibility Mode)
|
||||
INTCON0bits.IPEN = 0;
|
||||
}
|
||||
|
||||
void __interrupt() INTERRUPT_InterruptManager (void)
|
||||
{
|
||||
// interrupt handler
|
||||
if(PIE3bits.TMR0IE == 1 && PIR3bits.TMR0IF == 1)
|
||||
{
|
||||
TMR0_ISR();
|
||||
}
|
||||
else if(PIE5bits.ERRIE == 1 && PIR5bits.ERRIF == 1)
|
||||
{
|
||||
ECAN_ERRI_ISR();
|
||||
}
|
||||
else if(PIE5bits.RXBnIE == 1 && PIR5bits.RXBnIF == 1)
|
||||
{
|
||||
ECAN_RXBnI_ISR();
|
||||
}
|
||||
else
|
||||
{
|
||||
//Unhandled Interrupt
|
||||
}
|
||||
}
|
||||
/**
|
||||
End of File
|
||||
*/
|
@ -0,0 +1,92 @@
|
||||
/**
|
||||
Generated Interrupt Manager Header File
|
||||
|
||||
@Company:
|
||||
Microchip Technology Inc.
|
||||
|
||||
@File Name:
|
||||
interrupt_manager.h
|
||||
|
||||
@Summary:
|
||||
This is the Interrupt Manager file generated using PIC10 / PIC12 / PIC16 / PIC18 MCUs
|
||||
|
||||
@Description:
|
||||
This header file provides implementations for global interrupt handling.
|
||||
For individual peripheral handlers please see the peripheral driver for
|
||||
all modules selected in the GUI.
|
||||
Generation Information :
|
||||
Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8
|
||||
Device : PIC18F26K83
|
||||
Driver Version : 2.03
|
||||
The generated drivers are tested against the following:
|
||||
Compiler : XC8 2.36 and above or later
|
||||
MPLAB : MPLAB X 6.00
|
||||
*/
|
||||
|
||||
/*
|
||||
(c) 2018 Microchip Technology Inc. and its subsidiaries.
|
||||
|
||||
Subject to your compliance with these terms, you may use Microchip software and any
|
||||
derivatives exclusively with Microchip products. It is your responsibility to comply with third party
|
||||
license terms applicable to your use of third party software (including open source software) that
|
||||
may accompany Microchip software.
|
||||
|
||||
THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
|
||||
EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY
|
||||
IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE.
|
||||
|
||||
IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
|
||||
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
|
||||
WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP
|
||||
HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO
|
||||
THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL
|
||||
CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT
|
||||
OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef INTERRUPT_MANAGER_H
|
||||
#define INTERRUPT_MANAGER_H
|
||||
|
||||
|
||||
/**
|
||||
* @Param
|
||||
none
|
||||
* @Returns
|
||||
none
|
||||
* @Description
|
||||
This macro will enable global interrupts.
|
||||
* @Example
|
||||
INTERRUPT_GlobalInterruptEnable();
|
||||
*/
|
||||
#define INTERRUPT_GlobalInterruptEnable() (INTCON0bits.GIE = 1)
|
||||
|
||||
/**
|
||||
* @Param
|
||||
none
|
||||
* @Returns
|
||||
none
|
||||
* @Description
|
||||
This macro will disable global interrupts.
|
||||
* @Example
|
||||
INTERRUPT_GlobalInterruptDisable();
|
||||
*/
|
||||
#define INTERRUPT_GlobalInterruptDisable() (INTCON0bits.GIE = 0)
|
||||
|
||||
/**
|
||||
* @Param
|
||||
none
|
||||
* @Returns
|
||||
none
|
||||
* @Description
|
||||
Initializes PIC18 peripheral interrupt priorities; enables/disables priority vectors
|
||||
* @Example
|
||||
INTERRUPT_Initialize();
|
||||
*/
|
||||
void INTERRUPT_Initialize (void);
|
||||
|
||||
#endif // INTERRUPT_MANAGER_H
|
||||
/**
|
||||
End of File
|
||||
*/
|
97
306-controller_interface.X/mcc_generated_files/mcc.c
Normal file
97
306-controller_interface.X/mcc_generated_files/mcc.c
Normal file
@ -0,0 +1,97 @@
|
||||
/**
|
||||
@Generated PIC10 / PIC12 / PIC16 / PIC18 MCUs Source File
|
||||
|
||||
@Company:
|
||||
Microchip Technology Inc.
|
||||
|
||||
@File Name:
|
||||
mcc.c
|
||||
|
||||
@Summary:
|
||||
This is the mcc.c file generated using PIC10 / PIC12 / PIC16 / PIC18 MCUs
|
||||
|
||||
@Description:
|
||||
This header file provides implementations for driver APIs for all modules selected in the GUI.
|
||||
Generation Information :
|
||||
Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8
|
||||
Device : PIC18F26K83
|
||||
Driver Version : 2.00
|
||||
The generated drivers are tested against the following:
|
||||
Compiler : XC8 2.36 and above or later
|
||||
MPLAB : MPLAB X 6.00
|
||||
*/
|
||||
|
||||
/*
|
||||
(c) 2018 Microchip Technology Inc. and its subsidiaries.
|
||||
|
||||
Subject to your compliance with these terms, you may use Microchip software and any
|
||||
derivatives exclusively with Microchip products. It is your responsibility to comply with third party
|
||||
license terms applicable to your use of third party software (including open source software) that
|
||||
may accompany Microchip software.
|
||||
|
||||
THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
|
||||
EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY
|
||||
IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE.
|
||||
|
||||
IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
|
||||
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
|
||||
WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP
|
||||
HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO
|
||||
THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL
|
||||
CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT
|
||||
OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "mcc.h"
|
||||
|
||||
|
||||
void SYSTEM_Initialize(void)
|
||||
{
|
||||
INTERRUPT_Initialize();
|
||||
PMD_Initialize();
|
||||
PIN_MANAGER_Initialize();
|
||||
OSCILLATOR_Initialize();
|
||||
TMR0_Initialize();
|
||||
ECAN_Initialize();
|
||||
}
|
||||
|
||||
void OSCILLATOR_Initialize(void)
|
||||
{
|
||||
// NOSC HFINTOSC; NDIV 1;
|
||||
OSCCON1 = 0x60;
|
||||
// CSWHOLD may proceed; SOSCPWR Low power;
|
||||
OSCCON3 = 0x00;
|
||||
// MFOEN disabled; LFOEN disabled; ADOEN disabled; SOSCEN disabled; EXTOEN disabled; HFOEN disabled;
|
||||
OSCEN = 0x00;
|
||||
// HFFRQ 64_MHz;
|
||||
OSCFRQ = 0x08;
|
||||
// TUN 0;
|
||||
OSCTUNE = 0x00;
|
||||
}
|
||||
|
||||
void PMD_Initialize(void)
|
||||
{
|
||||
// CLKRMD CLKR enabled; SYSCMD SYSCLK enabled; SCANMD SCANNER enabled; FVRMD FVR enabled; IOCMD IOC enabled; CRCMD CRC enabled; HLVDMD HLVD enabled; NVMMD NVM enabled;
|
||||
PMD0 = 0x00;
|
||||
// NCO1MD DDS(NCO1) enabled; TMR0MD TMR0 enabled; TMR1MD TMR1 enabled; TMR4MD TMR4 enabled; TMR5MD TMR5 enabled; TMR2MD TMR2 enabled; TMR3MD TMR3 enabled; TMR6MD TMR6 enabled;
|
||||
PMD1 = 0x00;
|
||||
// ZCDMD ZCD enabled; DACMD DAC enabled; CMP1MD CMP1 enabled; ADCMD ADC enabled; CMP2MD CMP2 enabled;
|
||||
PMD2 = 0x00;
|
||||
// CCP2MD CCP2 enabled; CCP1MD CCP1 enabled; CCP4MD CCP4 enabled; CCP3MD CCP3 enabled; PWM6MD PWM6 enabled; PWM5MD PWM5 enabled; PWM8MD PWM8 enabled; PWM7MD PWM7 enabled;
|
||||
PMD3 = 0x00;
|
||||
// CWG3MD CWG3 enabled; CWG2MD CWG2 enabled; CWG1MD CWG1 enabled;
|
||||
PMD4 = 0x00;
|
||||
// U2MD UART2 enabled; U1MD UART1 enabled; SPI1MD SPI1 enabled; I2C2MD I2C2 enabled; I2C1MD I2C1 enabled;
|
||||
PMD5 = 0x00;
|
||||
// DSMMD DSM1 enabled; CLC3MD CLC3 enabled; CLC4MD CLC4 enabled; SMT1MD SMT1 enabled; SMT2MD SMT2 enabled; CLC1MD CLC1 enabled; CLC2MD CLC2 enabled;
|
||||
PMD6 = 0x00;
|
||||
// DMA1MD DMA1 enabled; DMA2MD DMA2 enabled;
|
||||
PMD7 = 0x00;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
End of File
|
||||
*/
|
105
306-controller_interface.X/mcc_generated_files/mcc.h
Normal file
105
306-controller_interface.X/mcc_generated_files/mcc.h
Normal file
@ -0,0 +1,105 @@
|
||||
/**
|
||||
@Generated PIC10 / PIC12 / PIC16 / PIC18 MCUs Header File
|
||||
|
||||
@Company:
|
||||
Microchip Technology Inc.
|
||||
|
||||
@File Name:
|
||||
mcc.h
|
||||
|
||||
@Summary:
|
||||
This is the mcc.h file generated using PIC10 / PIC12 / PIC16 / PIC18 MCUs
|
||||
|
||||
@Description:
|
||||
This header file provides implementations for driver APIs for all modules selected in the GUI.
|
||||
Generation Information :
|
||||
Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8
|
||||
Device : PIC18F26K83
|
||||
Driver Version : 2.00
|
||||
The generated drivers are tested against the following:
|
||||
Compiler : XC8 2.36 and above or later
|
||||
MPLAB : MPLAB X 6.00
|
||||
*/
|
||||
|
||||
/*
|
||||
(c) 2018 Microchip Technology Inc. and its subsidiaries.
|
||||
|
||||
Subject to your compliance with these terms, you may use Microchip software and any
|
||||
derivatives exclusively with Microchip products. It is your responsibility to comply with third party
|
||||
license terms applicable to your use of third party software (including open source software) that
|
||||
may accompany Microchip software.
|
||||
|
||||
THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
|
||||
EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY
|
||||
IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE.
|
||||
|
||||
IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
|
||||
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
|
||||
WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP
|
||||
HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO
|
||||
THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL
|
||||
CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT
|
||||
OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MCC_H
|
||||
#define MCC_H
|
||||
#include <xc.h>
|
||||
#include "device_config.h"
|
||||
#include "pin_manager.h"
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <conio.h>
|
||||
#include "interrupt_manager.h"
|
||||
#include "memory.h"
|
||||
#include "tmr0.h"
|
||||
#include "ecan.h"
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @Param
|
||||
none
|
||||
* @Returns
|
||||
none
|
||||
* @Description
|
||||
Initializes the device to the default states configured in the
|
||||
* MCC GUI
|
||||
* @Example
|
||||
SYSTEM_Initialize(void);
|
||||
*/
|
||||
void SYSTEM_Initialize(void);
|
||||
|
||||
/**
|
||||
* @Param
|
||||
none
|
||||
* @Returns
|
||||
none
|
||||
* @Description
|
||||
Initializes the oscillator to the default states configured in the
|
||||
* MCC GUI
|
||||
* @Example
|
||||
OSCILLATOR_Initialize(void);
|
||||
*/
|
||||
void OSCILLATOR_Initialize(void);
|
||||
|
||||
/**
|
||||
* @Param
|
||||
none
|
||||
* @Returns
|
||||
none
|
||||
* @Description
|
||||
Initializes the PMD module to the default states configured in the
|
||||
* MCC GUI
|
||||
* @Example
|
||||
PMD_Initialize(void);
|
||||
*/
|
||||
void PMD_Initialize(void);
|
||||
|
||||
|
||||
#endif /* MCC_H */
|
||||
/**
|
||||
End of File
|
||||
*/
|
206
306-controller_interface.X/mcc_generated_files/memory.c
Normal file
206
306-controller_interface.X/mcc_generated_files/memory.c
Normal file
@ -0,0 +1,206 @@
|
||||
/**
|
||||
MEMORY Generated Driver File
|
||||
|
||||
@Company
|
||||
Microchip Technology Inc.
|
||||
|
||||
@File Name
|
||||
memory.c
|
||||
|
||||
@Summary
|
||||
This is the generated driver implementation file for the MEMORY driver using PIC10 / PIC12 / PIC16 / PIC18 MCUs
|
||||
|
||||
@Description
|
||||
This file provides implementations of driver APIs for MEMORY.
|
||||
Generation Information :
|
||||
Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8
|
||||
Device : PIC18F26K83
|
||||
Driver Version : 2.1.3
|
||||
The generated drivers are tested against the following:
|
||||
Compiler : XC8 2.36 and above
|
||||
MPLAB : MPLAB X 6.00
|
||||
*/
|
||||
|
||||
/*
|
||||
(c) 2018 Microchip Technology Inc. and its subsidiaries.
|
||||
|
||||
Subject to your compliance with these terms, you may use Microchip software and any
|
||||
derivatives exclusively with Microchip products. It is your responsibility to comply with third party
|
||||
license terms applicable to your use of third party software (including open source software) that
|
||||
may accompany Microchip software.
|
||||
|
||||
THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
|
||||
EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY
|
||||
IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE.
|
||||
|
||||
IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
|
||||
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
|
||||
WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP
|
||||
HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO
|
||||
THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL
|
||||
CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT
|
||||
OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
/**
|
||||
Section: Included Files
|
||||
*/
|
||||
|
||||
#include <xc.h>
|
||||
#include "memory.h"
|
||||
|
||||
|
||||
/**
|
||||
Section: Flash Module APIs
|
||||
*/
|
||||
|
||||
uint8_t FLASH_ReadByte(uint32_t flashAddr)
|
||||
{
|
||||
NVMCON1bits.NVMREG = 2;
|
||||
TBLPTRU = (uint8_t)((flashAddr & 0x00FF0000) >> 16);
|
||||
TBLPTRH = (uint8_t)((flashAddr & 0x0000FF00)>> 8);
|
||||
TBLPTRL = (uint8_t)(flashAddr & 0x000000FF);
|
||||
|
||||
asm("TBLRD");
|
||||
|
||||
return (TABLAT);
|
||||
}
|
||||
|
||||
uint16_t FLASH_ReadWord(uint32_t flashAddr)
|
||||
{
|
||||
return ((((uint16_t)FLASH_ReadByte(flashAddr+1))<<8)|(FLASH_ReadByte(flashAddr)));
|
||||
}
|
||||
|
||||
void FLASH_WriteByte(uint32_t flashAddr, uint8_t *flashRdBufPtr, uint8_t byte)
|
||||
{
|
||||
uint32_t blockStartAddr = (uint32_t)(flashAddr & ((END_FLASH-1) ^ (ERASE_FLASH_BLOCKSIZE-1)));
|
||||
uint8_t offset = (uint8_t)(flashAddr & (ERASE_FLASH_BLOCKSIZE-1));
|
||||
uint8_t i;
|
||||
|
||||
// Entire row will be erased, read and save the existing data
|
||||
for (i=0; i<ERASE_FLASH_BLOCKSIZE; i++)
|
||||
{
|
||||
flashRdBufPtr[i] = FLASH_ReadByte((blockStartAddr+i));
|
||||
}
|
||||
|
||||
// Load byte at offset
|
||||
flashRdBufPtr[offset] = byte;
|
||||
|
||||
// Writes buffer contents to current block
|
||||
FLASH_WriteBlock(blockStartAddr, flashRdBufPtr);
|
||||
}
|
||||
|
||||
int8_t FLASH_WriteBlock(uint32_t writeAddr, uint8_t *flashWrBufPtr)
|
||||
{
|
||||
uint32_t blockStartAddr = (uint32_t )(writeAddr & ((END_FLASH-1) ^ (ERASE_FLASH_BLOCKSIZE-1)));
|
||||
uint8_t GIEBitValue = INTCON0bits.GIE; // Save interrupt enable
|
||||
uint8_t i;
|
||||
|
||||
// Flash write must start at the beginning of a row
|
||||
if( writeAddr != blockStartAddr )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Block erase sequence
|
||||
FLASH_EraseBlock(writeAddr);
|
||||
|
||||
// Block write sequence
|
||||
TBLPTRU = (uint8_t)((writeAddr & 0x00FF0000) >> 16); // Load Table point register
|
||||
TBLPTRH = (uint8_t)((writeAddr & 0x0000FF00)>> 8);
|
||||
TBLPTRL = (uint8_t)(writeAddr & 0x000000FF);
|
||||
|
||||
// Write block of data
|
||||
for (i=0; i<WRITE_FLASH_BLOCKSIZE; i++)
|
||||
{
|
||||
TABLAT = flashWrBufPtr[i]; // Load data byte
|
||||
|
||||
if (i == (WRITE_FLASH_BLOCKSIZE-1))
|
||||
{
|
||||
asm("TBLWT");
|
||||
}
|
||||
else
|
||||
{
|
||||
asm("TBLWTPOSTINC");
|
||||
}
|
||||
}
|
||||
|
||||
NVMCON1bits.NVMREG = 2;
|
||||
NVMCON1bits.WREN = 1;
|
||||
INTCON0bits.GIE = 0; // Disable interrupts
|
||||
NVMCON2 = 0x55;
|
||||
NVMCON2 = 0xAA;
|
||||
NVMCON1bits.WR = 1; // Start program
|
||||
INTCON0bits.GIE = GIEBitValue; // Restore interrupt enable
|
||||
NVMCON1bits.WREN = 0; // Disable writes to memory
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void FLASH_EraseBlock(uint32_t baseAddr)
|
||||
{
|
||||
uint8_t GIEBitValue = INTCON0bits.GIE; // Save interrupt enable
|
||||
|
||||
TBLPTRU = (uint8_t)((baseAddr & 0x00FF0000) >> 16);
|
||||
TBLPTRH = (uint8_t)((baseAddr & 0x0000FF00)>> 8);
|
||||
TBLPTRL = (uint8_t)(baseAddr & 0x000000FF);
|
||||
|
||||
NVMCON1bits.NVMREG = 2;
|
||||
NVMCON1bits.WREN = 1;
|
||||
NVMCON1bits.FREE = 1;
|
||||
INTCON0bits.GIE = 0; // Disable interrupts
|
||||
NVMCON2 = 0x55;
|
||||
NVMCON2 = 0xAA;
|
||||
NVMCON1bits.WR = 1; // Start program
|
||||
INTCON0bits.GIE = GIEBitValue; // Restore interrupt enable
|
||||
NVMCON1bits.WREN = 0; // Disable writes to memory
|
||||
}
|
||||
|
||||
/**
|
||||
Section: Data EEPROM Module APIs
|
||||
*/
|
||||
|
||||
void DATAEE_WriteByte(uint16_t bAdd, uint8_t bData)
|
||||
{
|
||||
uint8_t GIEBitValue = INTCON0bits.GIE;
|
||||
|
||||
NVMADRH = (uint8_t)((bAdd >> 8) & 0x03);
|
||||
NVMADRL = (uint8_t)(bAdd & 0xFF);
|
||||
NVMDAT = bData;
|
||||
NVMCON1bits.NVMREG = 0;
|
||||
NVMCON1bits.WREN = 1;
|
||||
INTCON0bits.GIE = 0; // Disable interrupts
|
||||
NVMCON2 = 0x55;
|
||||
NVMCON2 = 0xAA;
|
||||
NVMCON1bits.WR = 1;
|
||||
// Wait for write to complete
|
||||
while (NVMCON1bits.WR)
|
||||
{
|
||||
}
|
||||
|
||||
NVMCON1bits.WREN = 0;
|
||||
INTCON0bits.GIE = GIEBitValue; // restore interrupt enable
|
||||
}
|
||||
|
||||
uint8_t DATAEE_ReadByte(uint16_t bAdd)
|
||||
{
|
||||
NVMADRH = (uint8_t)((bAdd >> 8) & 0x03);
|
||||
NVMADRL = (uint8_t)(bAdd & 0xFF);
|
||||
NVMCON1bits.NVMREG = 0;
|
||||
NVMCON1bits.RD = 1;
|
||||
NOP(); // NOPs may be required for latency at high frequencies
|
||||
NOP();
|
||||
|
||||
return (NVMDAT);
|
||||
}
|
||||
|
||||
void MEMORY_Tasks( void )
|
||||
{
|
||||
/* TODO : Add interrupt handling code */
|
||||
PIR0bits.NVMIF = 0;
|
||||
}
|
||||
/**
|
||||
End of File
|
||||
*/
|
289
306-controller_interface.X/mcc_generated_files/memory.h
Normal file
289
306-controller_interface.X/mcc_generated_files/memory.h
Normal file
@ -0,0 +1,289 @@
|
||||
/**
|
||||
MEMORY Generated Driver API Header File
|
||||
|
||||
@Company
|
||||
Microchip Technology Inc.
|
||||
|
||||
@File Name
|
||||
memory.h
|
||||
|
||||
@Summary
|
||||
This is the generated header file for the MEMORY driver using PIC10 / PIC12 / PIC16 / PIC18 MCUs
|
||||
|
||||
@Description
|
||||
This header file provides APIs for driver for MEMORY.
|
||||
Generation Information :
|
||||
Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8
|
||||
Device : PIC18F26K83
|
||||
Driver Version : 2.1.3
|
||||
The generated drivers are tested against the following:
|
||||
Compiler : XC8 2.36 and above
|
||||
MPLAB : MPLAB X 6.00
|
||||
*******************************************************************************/
|
||||
|
||||
/*
|
||||
(c) 2018 Microchip Technology Inc. and its subsidiaries.
|
||||
|
||||
Subject to your compliance with these terms, you may use Microchip software and any
|
||||
derivatives exclusively with Microchip products. It is your responsibility to comply with third party
|
||||
license terms applicable to your use of third party software (including open source software) that
|
||||
may accompany Microchip software.
|
||||
|
||||
THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
|
||||
EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY
|
||||
IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE.
|
||||
|
||||
IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
|
||||
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
|
||||
WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP
|
||||
HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO
|
||||
THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL
|
||||
CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT
|
||||
OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MEMORY_H
|
||||
#define MEMORY_H
|
||||
|
||||
/**
|
||||
Section: Included Files
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus // Provide C++ Compatibility
|
||||
|
||||
extern "C" {
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
Section: Macro Declarations
|
||||
*/
|
||||
|
||||
#define WRITE_FLASH_BLOCKSIZE 128
|
||||
#define ERASE_FLASH_BLOCKSIZE 128
|
||||
#define END_FLASH 0x010000
|
||||
|
||||
/**
|
||||
Section: Flash Module APIs
|
||||
*/
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Reads a data byte from Flash
|
||||
|
||||
@Description
|
||||
This routine reads a data byte from given Flash address
|
||||
|
||||
@Preconditions
|
||||
None
|
||||
|
||||
@Param
|
||||
flashAddr - Flash program memory location from which data has to be read
|
||||
|
||||
@Returns
|
||||
Data byte read from given Flash address
|
||||
|
||||
@Example
|
||||
<code>
|
||||
uint8_t readByte;
|
||||
uint32_t flashAddr = 0x7D00;
|
||||
|
||||
readByte = FLASH_ReadByte(flashAddr);
|
||||
</code>
|
||||
*/
|
||||
uint8_t FLASH_ReadByte(uint32_t flashAddr);
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Reads a data word from Flash
|
||||
|
||||
@Description
|
||||
This routine reads a data word from given Flash address
|
||||
|
||||
@Preconditions
|
||||
None
|
||||
|
||||
@Param
|
||||
flashAddr - Flash program memory location from which data has to be read
|
||||
|
||||
@Returns
|
||||
Data word read from given Flash address
|
||||
|
||||
@Example
|
||||
<code>
|
||||
uint16_t readWord;
|
||||
uint32_t flashAddr = 0x7D00;
|
||||
|
||||
readWord = FLASH_ReadWord(flashAddr);
|
||||
</code>
|
||||
*/
|
||||
uint16_t FLASH_ReadWord(uint32_t flashAddr);
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Writes a data byte into Flash
|
||||
|
||||
@Description
|
||||
This routine writes the given data byte into mentioned Flash address.
|
||||
|
||||
This routine intially reads block of data (from Flash) into RAM, updates
|
||||
data values in RAM, and writes back updated values to Flash.
|
||||
|
||||
@Preconditions
|
||||
None
|
||||
|
||||
@Param
|
||||
flashAddr - Flash program memory location to which data has to be written
|
||||
*flashRdBufPtr - Pointer to RAM buffer of size 'ERASE_FLASH_BLOCKSIZE' at least
|
||||
byte - Data byte to be written in Flash
|
||||
|
||||
@Returns
|
||||
None
|
||||
|
||||
@Example
|
||||
<code>
|
||||
uint8_t writeData = 0xAA;
|
||||
uint32_t flashAddr = 0x7D00;
|
||||
uint8_t Buf[ERASE_FLASH_BLOCKSIZE];
|
||||
|
||||
FLASH_WriteWord(flashAddr, Buf, writeData);
|
||||
</code>
|
||||
*/
|
||||
void FLASH_WriteByte(uint32_t flashAddr, uint8_t *flashRdBufPtr, uint8_t byte);
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Writes data to complete block of Flash
|
||||
|
||||
@Description
|
||||
This routine writes data bytes to complete block in Flash program memory
|
||||
|
||||
@Preconditions
|
||||
None
|
||||
|
||||
@Param
|
||||
writeAddr - A valid block starting address in Flash
|
||||
*flashWrBufPtr - Pointer to an array of size 'WRITE_FLASH_BLOCKSIZE' at least
|
||||
|
||||
@Returns
|
||||
-1, if the given address is not a valid block starting address of Flash
|
||||
0, in case of valid block starting address
|
||||
|
||||
@Example
|
||||
<code>
|
||||
#define FLASH_ROW_ADDRESS 0x7D00
|
||||
|
||||
uint8_t wrBlockData[] =
|
||||
{
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
|
||||
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F,
|
||||
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F
|
||||
};
|
||||
|
||||
// write to Flash memory block
|
||||
FLASH_WriteBlock((uint32_t)FLASH_ROW_ADDRESS, (uint8_t *)wrBlockData);
|
||||
</code>
|
||||
*/
|
||||
int8_t FLASH_WriteBlock(uint32_t writeAddr, uint8_t *flashWrBufPtr);
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Erases complete Flash program memory block
|
||||
|
||||
@Description
|
||||
This routine erases complete Flash program memory block
|
||||
|
||||
@Preconditions
|
||||
None
|
||||
|
||||
@Param
|
||||
baseAddr - A valid block starting address in Flash program memory
|
||||
|
||||
@Returns
|
||||
None
|
||||
|
||||
@Example
|
||||
<code>
|
||||
uint32_t flashBlockStartAddr = 0x7D00;
|
||||
|
||||
FLASH_EraseBlock(flashBlockStartAddr);
|
||||
</code>
|
||||
*/
|
||||
void FLASH_EraseBlock(uint32_t baseAddr);
|
||||
|
||||
/**
|
||||
Section: Data EEPROM Module APIs
|
||||
*/
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Writes a data byte to Data EEPROM
|
||||
|
||||
@Description
|
||||
This routine writes a data byte to given Data EEPROM location
|
||||
|
||||
@Preconditions
|
||||
None
|
||||
|
||||
@Param
|
||||
bAdd - Data EEPROM location to which data to be written
|
||||
bData - Data to be written to Data EEPROM location
|
||||
|
||||
@Returns
|
||||
None
|
||||
|
||||
@Example
|
||||
<code>
|
||||
uint16_t dataeeAddr = 0x10;
|
||||
uint8_t dataeeData = 0x55;
|
||||
|
||||
DATAEE_WriteByte(dataeeAddr, dataeeData);
|
||||
</code>
|
||||
*/
|
||||
void DATAEE_WriteByte(uint16_t bAdd, uint8_t bData);
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Reads a data byte from Data EEPROM
|
||||
|
||||
@Description
|
||||
This routine reads a data byte from given Data EEPROM location
|
||||
|
||||
@Preconditions
|
||||
None
|
||||
|
||||
@Param
|
||||
bAdd - Data EEPROM location from which data has to be read
|
||||
|
||||
@Returns
|
||||
Data byte read from given Data EEPROM location
|
||||
|
||||
@Example
|
||||
<code>
|
||||
uint16_t dataeeAddr = 0x10;
|
||||
uint8_t readData;
|
||||
|
||||
readData = DATAEE_ReadByte(dataeeAddr);
|
||||
</code>
|
||||
*/
|
||||
uint8_t DATAEE_ReadByte(uint16_t bAdd);
|
||||
|
||||
void MEMORY_Tasks(void);
|
||||
|
||||
#ifdef __cplusplus // Provide C++ Compatibility
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif // MEMORY_H
|
||||
/**
|
||||
End of File
|
||||
*/
|
||||
|
124
306-controller_interface.X/mcc_generated_files/pin_manager.c
Normal file
124
306-controller_interface.X/mcc_generated_files/pin_manager.c
Normal file
@ -0,0 +1,124 @@
|
||||
/**
|
||||
Generated Pin Manager File
|
||||
|
||||
Company:
|
||||
Microchip Technology Inc.
|
||||
|
||||
File Name:
|
||||
pin_manager.c
|
||||
|
||||
Summary:
|
||||
This is the Pin Manager file generated using PIC10 / PIC12 / PIC16 / PIC18 MCUs
|
||||
|
||||
Description:
|
||||
This header file provides implementations for pin APIs for all pins selected in the GUI.
|
||||
Generation Information :
|
||||
Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8
|
||||
Device : PIC18F26K83
|
||||
Driver Version : 2.11
|
||||
The generated drivers are tested against the following:
|
||||
Compiler : XC8 2.36 and above
|
||||
MPLAB : MPLAB X 6.00
|
||||
|
||||
Copyright (c) 2013 - 2015 released Microchip Technology Inc. All rights reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
(c) 2018 Microchip Technology Inc. and its subsidiaries.
|
||||
|
||||
Subject to your compliance with these terms, you may use Microchip software and any
|
||||
derivatives exclusively with Microchip products. It is your responsibility to comply with third party
|
||||
license terms applicable to your use of third party software (including open source software) that
|
||||
may accompany Microchip software.
|
||||
|
||||
THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
|
||||
EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY
|
||||
IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE.
|
||||
|
||||
IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
|
||||
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
|
||||
WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP
|
||||
HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO
|
||||
THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL
|
||||
CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT
|
||||
OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "pin_manager.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void PIN_MANAGER_Initialize(void)
|
||||
{
|
||||
/**
|
||||
LATx registers
|
||||
*/
|
||||
LATA = 0x00;
|
||||
LATB = 0x00;
|
||||
LATC = 0x00;
|
||||
|
||||
/**
|
||||
TRISx registers
|
||||
*/
|
||||
TRISA = 0xFF;
|
||||
TRISB = 0xFE;
|
||||
TRISC = 0xFF;
|
||||
|
||||
/**
|
||||
ANSELx registers
|
||||
*/
|
||||
ANSELC = 0xFF;
|
||||
ANSELB = 0xF6;
|
||||
ANSELA = 0x7F;
|
||||
|
||||
/**
|
||||
WPUx registers
|
||||
*/
|
||||
WPUE = 0x00;
|
||||
WPUB = 0x00;
|
||||
WPUA = 0x80;
|
||||
WPUC = 0x00;
|
||||
|
||||
/**
|
||||
ODx registers
|
||||
*/
|
||||
ODCONA = 0x00;
|
||||
ODCONB = 0x00;
|
||||
ODCONC = 0x00;
|
||||
|
||||
/**
|
||||
SLRCONx registers
|
||||
*/
|
||||
SLRCONA = 0xFF;
|
||||
SLRCONB = 0xFF;
|
||||
SLRCONC = 0xFF;
|
||||
|
||||
/**
|
||||
INLVLx registers
|
||||
*/
|
||||
INLVLA = 0xFF;
|
||||
INLVLB = 0xFF;
|
||||
INLVLC = 0xFF;
|
||||
INLVLE = 0x08;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
CANRXPPS = 0x0B; //RB3->ECAN:CANRX;
|
||||
}
|
||||
|
||||
void PIN_MANAGER_IOC(void)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
End of File
|
||||
*/
|
149
306-controller_interface.X/mcc_generated_files/pin_manager.h
Normal file
149
306-controller_interface.X/mcc_generated_files/pin_manager.h
Normal file
@ -0,0 +1,149 @@
|
||||
/**
|
||||
@Generated Pin Manager Header File
|
||||
|
||||
@Company:
|
||||
Microchip Technology Inc.
|
||||
|
||||
@File Name:
|
||||
pin_manager.h
|
||||
|
||||
@Summary:
|
||||
This is the Pin Manager file generated using PIC10 / PIC12 / PIC16 / PIC18 MCUs
|
||||
|
||||
@Description
|
||||
This header file provides APIs for driver for .
|
||||
Generation Information :
|
||||
Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8
|
||||
Device : PIC18F26K83
|
||||
Driver Version : 2.11
|
||||
The generated drivers are tested against the following:
|
||||
Compiler : XC8 2.36 and above
|
||||
MPLAB : MPLAB X 6.00
|
||||
*/
|
||||
|
||||
/*
|
||||
(c) 2018 Microchip Technology Inc. and its subsidiaries.
|
||||
|
||||
Subject to your compliance with these terms, you may use Microchip software and any
|
||||
derivatives exclusively with Microchip products. It is your responsibility to comply with third party
|
||||
license terms applicable to your use of third party software (including open source software) that
|
||||
may accompany Microchip software.
|
||||
|
||||
THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
|
||||
EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY
|
||||
IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE.
|
||||
|
||||
IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
|
||||
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
|
||||
WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP
|
||||
HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO
|
||||
THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL
|
||||
CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT
|
||||
OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef PIN_MANAGER_H
|
||||
#define PIN_MANAGER_H
|
||||
|
||||
/**
|
||||
Section: Included Files
|
||||
*/
|
||||
|
||||
#include <xc.h>
|
||||
|
||||
#define INPUT 1
|
||||
#define OUTPUT 0
|
||||
|
||||
#define HIGH 1
|
||||
#define LOW 0
|
||||
|
||||
#define ANALOG 1
|
||||
#define DIGITAL 0
|
||||
|
||||
#define PULL_UP_ENABLED 1
|
||||
#define PULL_UP_DISABLED 0
|
||||
|
||||
// get/set IO_RA7 aliases
|
||||
#define IO_RA7_TRIS TRISAbits.TRISA7
|
||||
#define IO_RA7_LAT LATAbits.LATA7
|
||||
#define IO_RA7_PORT PORTAbits.RA7
|
||||
#define IO_RA7_WPU WPUAbits.WPUA7
|
||||
#define IO_RA7_OD ODCONAbits.ODCA7
|
||||
#define IO_RA7_ANS ANSELAbits.ANSELA7
|
||||
#define IO_RA7_SetHigh() do { LATAbits.LATA7 = 1; } while(0)
|
||||
#define IO_RA7_SetLow() do { LATAbits.LATA7 = 0; } while(0)
|
||||
#define IO_RA7_Toggle() do { LATAbits.LATA7 = ~LATAbits.LATA7; } while(0)
|
||||
#define IO_RA7_GetValue() PORTAbits.RA7
|
||||
#define IO_RA7_SetDigitalInput() do { TRISAbits.TRISA7 = 1; } while(0)
|
||||
#define IO_RA7_SetDigitalOutput() do { TRISAbits.TRISA7 = 0; } while(0)
|
||||
#define IO_RA7_SetPullup() do { WPUAbits.WPUA7 = 1; } while(0)
|
||||
#define IO_RA7_ResetPullup() do { WPUAbits.WPUA7 = 0; } while(0)
|
||||
#define IO_RA7_SetPushPull() do { ODCONAbits.ODCA7 = 0; } while(0)
|
||||
#define IO_RA7_SetOpenDrain() do { ODCONAbits.ODCA7 = 1; } while(0)
|
||||
#define IO_RA7_SetAnalogMode() do { ANSELAbits.ANSELA7 = 1; } while(0)
|
||||
#define IO_RA7_SetDigitalMode() do { ANSELAbits.ANSELA7 = 0; } while(0)
|
||||
|
||||
// get/set IO_RB0 aliases
|
||||
#define IO_RB0_TRIS TRISBbits.TRISB0
|
||||
#define IO_RB0_LAT LATBbits.LATB0
|
||||
#define IO_RB0_PORT PORTBbits.RB0
|
||||
#define IO_RB0_WPU WPUBbits.WPUB0
|
||||
#define IO_RB0_OD ODCONBbits.ODCB0
|
||||
#define IO_RB0_ANS ANSELBbits.ANSELB0
|
||||
#define IO_RB0_SetHigh() do { LATBbits.LATB0 = 1; } while(0)
|
||||
#define IO_RB0_SetLow() do { LATBbits.LATB0 = 0; } while(0)
|
||||
#define IO_RB0_Toggle() do { LATBbits.LATB0 = ~LATBbits.LATB0; } while(0)
|
||||
#define IO_RB0_GetValue() PORTBbits.RB0
|
||||
#define IO_RB0_SetDigitalInput() do { TRISBbits.TRISB0 = 1; } while(0)
|
||||
#define IO_RB0_SetDigitalOutput() do { TRISBbits.TRISB0 = 0; } while(0)
|
||||
#define IO_RB0_SetPullup() do { WPUBbits.WPUB0 = 1; } while(0)
|
||||
#define IO_RB0_ResetPullup() do { WPUBbits.WPUB0 = 0; } while(0)
|
||||
#define IO_RB0_SetPushPull() do { ODCONBbits.ODCB0 = 0; } while(0)
|
||||
#define IO_RB0_SetOpenDrain() do { ODCONBbits.ODCB0 = 1; } while(0)
|
||||
#define IO_RB0_SetAnalogMode() do { ANSELBbits.ANSELB0 = 1; } while(0)
|
||||
#define IO_RB0_SetDigitalMode() do { ANSELBbits.ANSELB0 = 0; } while(0)
|
||||
|
||||
// get/set RB3 procedures
|
||||
#define RB3_SetHigh() do { LATBbits.LATB3 = 1; } while(0)
|
||||
#define RB3_SetLow() do { LATBbits.LATB3 = 0; } while(0)
|
||||
#define RB3_Toggle() do { LATBbits.LATB3 = ~LATBbits.LATB3; } while(0)
|
||||
#define RB3_GetValue() PORTBbits.RB3
|
||||
#define RB3_SetDigitalInput() do { TRISBbits.TRISB3 = 1; } while(0)
|
||||
#define RB3_SetDigitalOutput() do { TRISBbits.TRISB3 = 0; } while(0)
|
||||
#define RB3_SetPullup() do { WPUBbits.WPUB3 = 1; } while(0)
|
||||
#define RB3_ResetPullup() do { WPUBbits.WPUB3 = 0; } while(0)
|
||||
#define RB3_SetAnalogMode() do { ANSELBbits.ANSELB3 = 1; } while(0)
|
||||
#define RB3_SetDigitalMode() do { ANSELBbits.ANSELB3 = 0; } while(0)
|
||||
|
||||
/**
|
||||
@Param
|
||||
none
|
||||
@Returns
|
||||
none
|
||||
@Description
|
||||
GPIO and peripheral I/O initialization
|
||||
@Example
|
||||
PIN_MANAGER_Initialize();
|
||||
*/
|
||||
void PIN_MANAGER_Initialize (void);
|
||||
|
||||
/**
|
||||
* @Param
|
||||
none
|
||||
* @Returns
|
||||
none
|
||||
* @Description
|
||||
Interrupt on Change Handling routine
|
||||
* @Example
|
||||
PIN_MANAGER_IOC();
|
||||
*/
|
||||
void PIN_MANAGER_IOC(void);
|
||||
|
||||
|
||||
|
||||
#endif // PIN_MANAGER_H
|
||||
/**
|
||||
End of File
|
||||
*/
|
145
306-controller_interface.X/mcc_generated_files/tmr0.c
Normal file
145
306-controller_interface.X/mcc_generated_files/tmr0.c
Normal file
@ -0,0 +1,145 @@
|
||||
/**
|
||||
TMR0 Generated Driver File
|
||||
|
||||
@Company
|
||||
Microchip Technology Inc.
|
||||
|
||||
@File Name
|
||||
tmr0.c
|
||||
|
||||
@Summary
|
||||
This is the generated driver implementation file for the TMR0 driver using PIC10 / PIC12 / PIC16 / PIC18 MCUs
|
||||
|
||||
@Description
|
||||
This source file provides APIs for TMR0.
|
||||
Generation Information :
|
||||
Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8
|
||||
Device : PIC18F26K83
|
||||
Driver Version : 3.10
|
||||
The generated drivers are tested against the following:
|
||||
Compiler : XC8 2.36 and above
|
||||
MPLAB : MPLAB X 6.00
|
||||
*/
|
||||
|
||||
/*
|
||||
(c) 2018 Microchip Technology Inc. and its subsidiaries.
|
||||
|
||||
Subject to your compliance with these terms, you may use Microchip software and any
|
||||
derivatives exclusively with Microchip products. It is your responsibility to comply with third party
|
||||
license terms applicable to your use of third party software (including open source software) that
|
||||
may accompany Microchip software.
|
||||
|
||||
THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
|
||||
EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY
|
||||
IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE.
|
||||
|
||||
IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
|
||||
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
|
||||
WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP
|
||||
HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO
|
||||
THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL
|
||||
CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT
|
||||
OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
/**
|
||||
Section: Included Files
|
||||
*/
|
||||
|
||||
#include <xc.h>
|
||||
#include "tmr0.h"
|
||||
|
||||
|
||||
/**
|
||||
Section: TMR0 APIs
|
||||
*/
|
||||
|
||||
void (*TMR0_InterruptHandler)(void);
|
||||
|
||||
void TMR0_Initialize(void)
|
||||
{
|
||||
// Set TMR0 to the options selected in the User Interface
|
||||
|
||||
// T0CS FOSC/4; T0CKPS 1:64; T0ASYNC synchronised;
|
||||
T0CON1 = 0x46;
|
||||
|
||||
// TMR0H 249;
|
||||
TMR0H = 0xF9;
|
||||
|
||||
// TMR0L 0;
|
||||
TMR0L = 0x00;
|
||||
|
||||
// Clear Interrupt flag before enabling the interrupt
|
||||
PIR3bits.TMR0IF = 0;
|
||||
|
||||
// Enabling TMR0 interrupt.
|
||||
PIE3bits.TMR0IE = 1;
|
||||
|
||||
// Set Default Interrupt Handler
|
||||
TMR0_SetInterruptHandler(TMR0_DefaultInterruptHandler);
|
||||
|
||||
// T0OUTPS 1:10; T0EN enabled; T016BIT 8-bit;
|
||||
T0CON0 = 0x89;
|
||||
}
|
||||
|
||||
void TMR0_StartTimer(void)
|
||||
{
|
||||
// Start the Timer by writing to TMR0ON bit
|
||||
T0CON0bits.T0EN = 1;
|
||||
}
|
||||
|
||||
void TMR0_StopTimer(void)
|
||||
{
|
||||
// Stop the Timer by writing to TMR0ON bit
|
||||
T0CON0bits.T0EN = 0;
|
||||
}
|
||||
|
||||
uint8_t TMR0_ReadTimer(void)
|
||||
{
|
||||
uint8_t readVal;
|
||||
|
||||
// read Timer0, low register only
|
||||
readVal = TMR0L;
|
||||
|
||||
return readVal;
|
||||
}
|
||||
|
||||
void TMR0_WriteTimer(uint8_t timerVal)
|
||||
{
|
||||
// Write to Timer0 registers, low register only
|
||||
TMR0L = timerVal;
|
||||
}
|
||||
|
||||
void TMR0_Reload(uint8_t periodVal)
|
||||
{
|
||||
// Write to Timer0 registers, high register only
|
||||
TMR0H = periodVal;
|
||||
}
|
||||
|
||||
void TMR0_ISR(void)
|
||||
{
|
||||
// clear the TMR0 interrupt flag
|
||||
PIR3bits.TMR0IF = 0;
|
||||
if(TMR0_InterruptHandler)
|
||||
{
|
||||
TMR0_InterruptHandler();
|
||||
}
|
||||
|
||||
// add your TMR0 interrupt custom code
|
||||
}
|
||||
|
||||
|
||||
void TMR0_SetInterruptHandler(void (* InterruptHandler)(void)){
|
||||
TMR0_InterruptHandler = InterruptHandler;
|
||||
}
|
||||
|
||||
void TMR0_DefaultInterruptHandler(void){
|
||||
// add your TMR0 interrupt custom code
|
||||
// or set custom function using TMR0_SetInterruptHandler()
|
||||
}
|
||||
|
||||
/**
|
||||
End of File
|
||||
*/
|
357
306-controller_interface.X/mcc_generated_files/tmr0.h
Normal file
357
306-controller_interface.X/mcc_generated_files/tmr0.h
Normal file
@ -0,0 +1,357 @@
|
||||
/**
|
||||
TMR0 Generated Driver API Header File
|
||||
|
||||
@Company
|
||||
Microchip Technology Inc.
|
||||
|
||||
@File Name
|
||||
tmr0.h
|
||||
|
||||
@Summary
|
||||
This is the generated header file for the TMR0 driver using PIC10 / PIC12 / PIC16 / PIC18 MCUs
|
||||
|
||||
@Description
|
||||
This header file provides APIs for TMR0.
|
||||
Generation Information :
|
||||
Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8
|
||||
Device : PIC18F26K83
|
||||
Driver Version : 3.10
|
||||
The generated drivers are tested against the following:
|
||||
Compiler : XC8 2.36 and above
|
||||
MPLAB : MPLAB X 6.00
|
||||
*/
|
||||
|
||||
/*
|
||||
(c) 2018 Microchip Technology Inc. and its subsidiaries.
|
||||
|
||||
Subject to your compliance with these terms, you may use Microchip software and any
|
||||
derivatives exclusively with Microchip products. It is your responsibility to comply with third party
|
||||
license terms applicable to your use of third party software (including open source software) that
|
||||
may accompany Microchip software.
|
||||
|
||||
THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
|
||||
EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY
|
||||
IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE.
|
||||
|
||||
IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
|
||||
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
|
||||
WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP
|
||||
HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO
|
||||
THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL
|
||||
CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT
|
||||
OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef TMR0_H
|
||||
#define TMR0_H
|
||||
|
||||
/**
|
||||
Section: Included Files
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus // Provide C++ Compatibility
|
||||
|
||||
extern "C" {
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Section: TMR0 APIs
|
||||
*/
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Initializes the TMR0.
|
||||
|
||||
@Description
|
||||
This function initializes the TMR0 Registers.
|
||||
This function must be called before any other TMR0 function is called.
|
||||
|
||||
@Preconditions
|
||||
None
|
||||
|
||||
@Param
|
||||
None
|
||||
|
||||
@Returns
|
||||
None
|
||||
|
||||
@Comment
|
||||
|
||||
|
||||
@Example
|
||||
<code>
|
||||
main()
|
||||
{
|
||||
// Initialize TMR0 module
|
||||
TMR0_Initialize();
|
||||
|
||||
// Do something else...
|
||||
}
|
||||
</code>
|
||||
*/
|
||||
void TMR0_Initialize(void);
|
||||
|
||||
/**
|
||||
@Summary
|
||||
This function starts the TMR0.
|
||||
|
||||
@Description
|
||||
This function starts the TMR0 operation.
|
||||
This function must be called after the initialization of TMR0.
|
||||
|
||||
@Preconditions
|
||||
Initialize the TMR0 before calling this function.
|
||||
|
||||
@Param
|
||||
None
|
||||
|
||||
@Returns
|
||||
None
|
||||
|
||||
@Example
|
||||
<code>
|
||||
// Initialize TMR0 module
|
||||
|
||||
// Start TMR0
|
||||
TMR0_StartTimer();
|
||||
|
||||
// Do something else...
|
||||
</code>
|
||||
*/
|
||||
void TMR0_StartTimer(void);
|
||||
|
||||
/**
|
||||
@Summary
|
||||
This function stops the TMR0.
|
||||
|
||||
@Description
|
||||
This function stops the TMR0 operation.
|
||||
This function must be called after the start of TMR0.
|
||||
|
||||
@Preconditions
|
||||
Initialize the TMR0 before calling this function.
|
||||
|
||||
@Param
|
||||
None
|
||||
|
||||
@Returns
|
||||
None
|
||||
|
||||
@Example
|
||||
<code>
|
||||
// Initialize TMR0 module
|
||||
|
||||
// Start TMR0
|
||||
TMR0_StartTimer();
|
||||
|
||||
// Do something else...
|
||||
|
||||
// Stop TMR0;
|
||||
TMR0_StopTimer();
|
||||
</code>
|
||||
*/
|
||||
void TMR0_StopTimer(void);
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Reads the 8 bits TMR0 register value.
|
||||
|
||||
@Description
|
||||
This function reads the 8 bits TMR0 register value and return it.
|
||||
|
||||
@Preconditions
|
||||
Initialize the TMR0 before calling this function.
|
||||
|
||||
@Param
|
||||
None
|
||||
|
||||
@Returns
|
||||
This function returns the 8 bits value of TMR0 register.
|
||||
|
||||
@Example
|
||||
<code>
|
||||
// Initialize TMR0 module
|
||||
|
||||
// Start TMR0
|
||||
TMR0_StartTimer();
|
||||
|
||||
// Read the current value of TMR0
|
||||
if(0 == TMR0_ReadTimer())
|
||||
{
|
||||
// Do something else...
|
||||
|
||||
// Stop TMR0;
|
||||
TMR0_StopTimer();
|
||||
}
|
||||
</code>
|
||||
*/
|
||||
uint8_t TMR0_ReadTimer(void);
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Writes the 8 bits value to TMR0 register.
|
||||
|
||||
@Description
|
||||
This function writes the 8 bits value to TMR0 register.
|
||||
This function must be called after the initialization of TMR0.
|
||||
|
||||
@Preconditions
|
||||
Initialize the TMR0 before calling this function.
|
||||
|
||||
@Param
|
||||
timerVal - Value to write into TMR0 register.
|
||||
|
||||
@Returns
|
||||
None
|
||||
|
||||
@Example
|
||||
<code>
|
||||
#define PERIOD 0x80
|
||||
#define ZERO 0x00
|
||||
|
||||
while(1)
|
||||
{
|
||||
// Read the TMR0 register
|
||||
if(ZERO == TMR0_ReadTimer())
|
||||
{
|
||||
// Do something else...
|
||||
|
||||
// Write the TMR0 register
|
||||
TMR0_WriteTimer(PERIOD);
|
||||
}
|
||||
|
||||
// Do something else...
|
||||
}
|
||||
</code>
|
||||
*/
|
||||
void TMR0_WriteTimer(uint8_t timerVal);
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Load value to Period Register.
|
||||
|
||||
@Description
|
||||
This function writes the value to TMR0H register.
|
||||
This function must be called after the initialization of TMR0.
|
||||
|
||||
@Preconditions
|
||||
Initialize the TMR0 before calling this function.
|
||||
|
||||
@Param
|
||||
periodVal - Value to load into TMR0 register.
|
||||
|
||||
@Returns
|
||||
None
|
||||
|
||||
|
||||
@Example
|
||||
<code>
|
||||
while(1)
|
||||
{
|
||||
if(TMR0IF)
|
||||
{
|
||||
// Do something else...
|
||||
|
||||
// clear the TMR0 interrupt flag
|
||||
TMR0IF = 0;
|
||||
|
||||
// Change the period value of TMR0
|
||||
TMR0_Reload(0x80);
|
||||
}
|
||||
}
|
||||
</code>
|
||||
*/
|
||||
void TMR0_Reload(uint8_t periodVal);
|
||||
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Timer Interrupt Service Routine
|
||||
|
||||
@Description
|
||||
Timer Interrupt Service Routine is called by the Interrupt Manager.
|
||||
|
||||
@Preconditions
|
||||
Initialize the TMR0 module with interrupt before calling this isr.
|
||||
|
||||
@Param
|
||||
None
|
||||
|
||||
@Returns
|
||||
None
|
||||
*/
|
||||
void TMR0_ISR(void);
|
||||
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Set Timer Interrupt Handler
|
||||
|
||||
@Description
|
||||
This sets the function to be called during the ISR
|
||||
|
||||
@Preconditions
|
||||
Initialize the TMR0 module with interrupt before calling this.
|
||||
|
||||
@Param
|
||||
Address of function to be set
|
||||
|
||||
@Returns
|
||||
None
|
||||
*/
|
||||
void TMR0_SetInterruptHandler(void (* InterruptHandler)(void));
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Timer Interrupt Handler
|
||||
|
||||
@Description
|
||||
This is a function pointer to the function that will be called during the ISR
|
||||
|
||||
@Preconditions
|
||||
Initialize the TMR0 module with interrupt before calling this isr.
|
||||
|
||||
@Param
|
||||
None
|
||||
|
||||
@Returns
|
||||
None
|
||||
*/
|
||||
extern void (*TMR0_InterruptHandler)(void);
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Default Timer Interrupt Handler
|
||||
|
||||
@Description
|
||||
This is the default Interrupt Handler function
|
||||
|
||||
@Preconditions
|
||||
Initialize the TMR0 module with interrupt before calling this isr.
|
||||
|
||||
@Param
|
||||
None
|
||||
|
||||
@Returns
|
||||
None
|
||||
*/
|
||||
void TMR0_DefaultInterruptHandler(void);
|
||||
|
||||
#ifdef __cplusplus // Provide C++ Compatibility
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif // TMR0_H
|
||||
/**
|
||||
End of File
|
||||
*/
|
Reference in New Issue
Block a user