Inital working code
This commit is contained in:
		
							
								
								
									
										305
									
								
								mcc_generated_files/uart/eusart1.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										305
									
								
								mcc_generated_files/uart/eusart1.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,305 @@ | ||||
| /** | ||||
|  * EUSART1 Generated Driver API Header File | ||||
|  *  | ||||
|  * @file eusart1.h | ||||
|  *  | ||||
|  * @defgroup eusart1 EUSART1 | ||||
|  *  | ||||
|  * @brief This file contains API prototypes and other datatypes for the Enhanced Universal Synchronous and Asynchronous Receiver Transceiver (EUSART) module. | ||||
|  * | ||||
|  * @version EUSART1 Driver Version 3.0.1 | ||||
| */ | ||||
| /* | ||||
| <EFBFBD> [2025] 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.  | ||||
|     You are responsible for complying with 3rd party license terms   | ||||
|     applicable to your use of 3rd party software (including open source   | ||||
|     software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?  | ||||
|     NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS  | ||||
|     SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,   | ||||
|     MERCHANTABILITY, OR 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 RELATED TO THE SOFTWARE WILL NOT  | ||||
|     EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR  | ||||
|     THIS SOFTWARE. | ||||
| */ | ||||
|  | ||||
| #ifndef EUSART1_H | ||||
| #define EUSART1_H | ||||
|  | ||||
|  | ||||
| #include <stdbool.h> | ||||
| #include <stdint.h> | ||||
| /** | ||||
|     @ingroup eusart1  | ||||
|     @def Standard Input Output functions | ||||
|     @misradeviation{@required, 21.6} This inclusion is essential for UART module to use Printf function for print the character. | ||||
| */ | ||||
| /* cppcheck-suppress misra-c2012-21.6 */ | ||||
| #include <stdio.h> | ||||
| #include "../system/system.h" | ||||
| #include "uart_drv_interface.h" | ||||
|  | ||||
| #ifdef __cplusplus  // Provide C++ Compatibility | ||||
|  | ||||
|     extern "C" { | ||||
|  | ||||
| #endif | ||||
|  | ||||
|  | ||||
| #define UART1_interface UART1 | ||||
|  | ||||
|  | ||||
| #define UART1_Initialize     EUSART1_Initialize | ||||
| #define UART1_Deinitialize   EUSART1_Deinitialize | ||||
| #define UART1_Write          EUSART1_Write | ||||
| #define UART1_Read           EUSART1_Read | ||||
| #define UART1__IsRxReady     EUSART1_IsRxReady | ||||
| #define UART1_IsTxReady      EUSART1_IsTxReady | ||||
| #define UART1_IsTxDone       EUSART1_IsTxDone | ||||
|  | ||||
| #define UART1_TransmitEnable       EUSART1_TransmitEnable | ||||
| #define UART1_TransmitDisable      EUSART1_TransmitDisable | ||||
| #define UART1_AutoBaudSet          EUSART1_AutoBaudSet | ||||
| #define UART1_AutoBaudQuery        EUSART1_AutoBaudQuery | ||||
| #define UART1_BRGCountSet                (NULL) | ||||
| #define UART1_BRGCountGet                (NULL) | ||||
| #define UART1_BaudRateSet                (NULL) | ||||
| #define UART1_BaudRateGet                (NULL) | ||||
| #define UART1__AutoBaudEventEnableGet    (NULL) | ||||
| #define UART1_ErrorGet             EUSART1_ErrorGet | ||||
|  | ||||
| #define UART1_TxCompleteCallbackRegister     (NULL) | ||||
| #define UART1_RxCompleteCallbackRegister      (NULL) | ||||
| #define UART1_TxCollisionCallbackRegister  (NULL) | ||||
| #define UART1_FramingErrorCallbackRegister EUSART1_FramingErrorCallbackRegister | ||||
| #define UART1_OverrunErrorCallbackRegister EUSART1_OverrunErrorCallbackRegister | ||||
| #define UART1_ParityErrorCallbackRegister  (NULL) | ||||
| #define UART1_EventCallbackRegister        (NULL) | ||||
|  | ||||
|  | ||||
| /** | ||||
|  @ingroup eusart1 | ||||
|  @struct eusart1_status_t | ||||
|  @brief This is a structure defined for errors in reception of data. | ||||
|  */ | ||||
| typedef union { | ||||
|     struct { | ||||
|         uint8_t perr : 1;     /**<This is a bit field for Parity Error status*/ | ||||
|         uint8_t ferr : 1;     /**<This is a bit field for Framing Error status*/ | ||||
|         uint8_t oerr : 1;     /**<This is a bit field for Overfrun Error status*/ | ||||
|         uint8_t reserved : 5; /**<Reserved*/ | ||||
|     }; | ||||
|     size_t status;            /**<Group byte for status errors*/ | ||||
| }eusart1_status_t; | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
| /** | ||||
|  * @ingroup eusart1 | ||||
|  * @brief External object for eusart1_interface. | ||||
|  */ | ||||
| extern const uart_drv_interface_t UART1; | ||||
|  | ||||
| /** | ||||
|  * @ingroup eusart1 | ||||
|  * @brief Initializes the EUSART1 module. This routine is called | ||||
|  *        only once during system initialization, before calling other APIs. | ||||
|  * @param None. | ||||
|  * @return None. | ||||
|  */ | ||||
| void EUSART1_Initialize(void); | ||||
|  | ||||
| /** | ||||
|  * @ingroup eusart1 | ||||
|  * @brief Deinitializes and disables the EUSART1 module. | ||||
|  * @param None. | ||||
|  * @return None. | ||||
|  */ | ||||
| void EUSART1_Deinitialize(void); | ||||
|  | ||||
| /** | ||||
|  * @ingroup eusart1 | ||||
|  * @brief This API enables the EUSART1 module.      | ||||
|  * @param None. | ||||
|  * @return None. | ||||
|  */ | ||||
| void EUSART1_Enable(void); | ||||
|  | ||||
| /** | ||||
|  * @ingroup eusart1 | ||||
|  * @brief This API disables the EUSART1 module. | ||||
|  * @param None. | ||||
|  * @return None. | ||||
|  */ | ||||
| void EUSART1_Disable(void); | ||||
|  | ||||
| /** | ||||
|  * @ingroup eusart1 | ||||
|  * @brief This API enables the EUSART1 transmitter. | ||||
|  *        The EUSART1 must be enabled to send the bytes over to the TX pin. | ||||
|  * @param None. | ||||
|  * @return None. | ||||
|  */ | ||||
| void EUSART1_TransmitEnable(void); | ||||
|  | ||||
| /** | ||||
|  * @ingroup eusart1 | ||||
|  * @brief This API disables the EUSART1 transmitter. | ||||
|  * @param None. | ||||
|  * @return None. | ||||
|  */ | ||||
| void EUSART1_TransmitDisable(void); | ||||
|  | ||||
| /** | ||||
|  * @ingroup eusart1 | ||||
|  * @brief This API enables the EUSART1 receiver. | ||||
|  *        The EUSART1 must be enabled to receive the bytes sent by the RX pin. | ||||
|  * @param None. | ||||
|  * @return None. | ||||
|  */ | ||||
| void EUSART1_ReceiveEnable(void); | ||||
|  | ||||
| /** | ||||
|  * @ingroup eusart1 | ||||
|  * @brief This API disables the EUSART1 receiver. | ||||
|  * @param None. | ||||
|  * @return None. | ||||
|  */ | ||||
| void EUSART1_ReceiveDisable(void); | ||||
|  | ||||
|  | ||||
| /** | ||||
|  * @ingroup eusart1 | ||||
|  * @brief This API enables the EUSART1 to send a break control.  | ||||
|  * @param None. | ||||
|  * @return None. | ||||
|  */ | ||||
| void EUSART1_SendBreakControlEnable(void); | ||||
|  | ||||
| /** | ||||
|  * @ingroup eusart1 | ||||
|  * @brief This API disables the EUSART1 send break control. | ||||
|  * @param None. | ||||
|  * @return None. | ||||
|  */ | ||||
| void EUSART1_SendBreakControlDisable(void); | ||||
|  | ||||
| /** | ||||
|  * @ingroup eusart1 | ||||
|  * @brief This API enables the EUSART1 AutoBaud Detection (ABR).  | ||||
|  * @param bool enable. | ||||
|  * @return None. | ||||
|  */ | ||||
| void EUSART1_AutoBaudSet(bool enable); | ||||
|  | ||||
| /** | ||||
|  * @ingroup eusart1 | ||||
|  * @brief This API reads the EUSART1 ABR Complete bit. | ||||
|  * @param None. | ||||
|  * @return bool. | ||||
|  */ | ||||
| bool EUSART1_AutoBaudQuery(void); | ||||
|  | ||||
| /** | ||||
|  * @ingroup eusart1 | ||||
|  * @brief This API reads the EUSART1 ABR Overflow bit. | ||||
|  * @param None. | ||||
|  * @return None. | ||||
|  */ | ||||
| bool EUSART1_IsAutoBaudDetectOverflow(void); | ||||
|  | ||||
| /** | ||||
|  * @ingroup eusart1 | ||||
|  * @brief This API resets the EUSART1 ABR Overflow bit. | ||||
|  * @param None. | ||||
|  * @return None. | ||||
|  */ | ||||
| void EUSART1_AutoBaudDetectOverflowReset(void); | ||||
|  | ||||
| /** | ||||
|  * @ingroup eusart1 | ||||
|  * @brief This API checks if the EUSART1 has received available data. | ||||
|  * @param None. | ||||
|  * @retval true if EUSART1 receiver FIFO has a data | ||||
|  * @retval false EUSART1 receiver FIFO is empty | ||||
|  */ | ||||
| bool EUSART1_IsRxReady(void); | ||||
|  | ||||
| /** | ||||
|  * @ingroup eusart1 | ||||
|  * @brief This function checks if the EUSART1 transmitter is ready to accept a data byte. | ||||
|  * @param None. | ||||
|  * @retval true if EUSART1 transmitter FIFO has atleast 1 byte space | ||||
|  * @retval false if EUSART1 transmitter FIFO is full | ||||
|  */ | ||||
| bool EUSART1_IsTxReady(void); | ||||
|  | ||||
| /** | ||||
|  * @ingroup eusart1 | ||||
|  * @brief This function returns the status of Transmit Shift Register (TSR). | ||||
|  * @param None. | ||||
|  * @retval true if Data completely shifted out from the TSR | ||||
|  * @retval false if Data is present in Transmit FIFO and/or in TSR | ||||
|  */ | ||||
| bool EUSART1_IsTxDone(void); | ||||
|  | ||||
| /** | ||||
|  * @ingroup eusart1 | ||||
|  * @brief This function receives the error status of the last read byte. | ||||
|  * @param None. | ||||
|  * @return Status of the last read byte. See eusart1_status_t struct for more details. | ||||
|  */ | ||||
| size_t EUSART1_ErrorGet(void); | ||||
|  | ||||
| /** | ||||
|  * @ingroup eusart1 | ||||
|  * @brief This function reads the 8 bits from the FIFO register receiver. | ||||
|  * @pre The transfer status must be checked to see if the receiver is not empty | ||||
|  *      before calling this function. Verify the EUSART1_IsRxReady(), before calling this API. | ||||
|  * @param None. | ||||
|  * @return 8-bit data from RX FIFO register. | ||||
|  */ | ||||
| uint8_t EUSART1_Read(void); | ||||
|  | ||||
| /** | ||||
|  * @ingroup eusart1 | ||||
|  * @brief This function writes a byte of data to the transmitter FIFO register. | ||||
|  * @pre The transfer status must be checked to see if the transmitter is ready to accept a byte | ||||
|  *      before calling this function. Verify the EUSART1_IsTxReady() before calling this API. | ||||
|  * @param txData  - Data byte to write to the TX FIFO. | ||||
|  * @return None. | ||||
|  */ | ||||
| void EUSART1_Write(uint8_t txData); | ||||
|  | ||||
| /** | ||||
|  * @ingroup eusart1 | ||||
|  * @brief This API registers the function to be called upon framing error. | ||||
|  * @param callbackHandler - a function pointer which will be called upon framing error condition. | ||||
|  * @return None. | ||||
|  */ | ||||
| void EUSART1_FramingErrorCallbackRegister(void (* callbackHandler)(void)); | ||||
|  | ||||
| /** | ||||
|  * @ingroup eusart1 | ||||
|  * @brief This API registers the function to be called upon overrun error. | ||||
|  * @param callbackHandler - a function pointer which will be called upon overrun error condition. | ||||
|  * @return None. | ||||
|  */ | ||||
| void EUSART1_OverrunErrorCallbackRegister(void (* callbackHandler)(void)); | ||||
|  | ||||
| #ifdef __cplusplus  // Provide C++ Compatibility | ||||
|  | ||||
|     } | ||||
|  | ||||
| #endif | ||||
|  | ||||
| #endif  // EUSART1_H | ||||
							
								
								
									
										267
									
								
								mcc_generated_files/uart/src/eusart1.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										267
									
								
								mcc_generated_files/uart/src/eusart1.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,267 @@ | ||||
| /** | ||||
|  * EUSART1 Generated Driver API Header File | ||||
|  *  | ||||
|  * @file eusart1.c | ||||
|  *  | ||||
|  * @ingroup eusart1 | ||||
|  *  | ||||
|  * @brief This is the generated driver implementation file for the EUSART1 driver using the Enhanced Universal Synchronous and Asynchronous Receiver Transceiver (EUSART) module. | ||||
|  * | ||||
|  * @version EUSART1 Driver Version 3.0.1 | ||||
| */ | ||||
|  | ||||
| /* | ||||
| <EFBFBD> [2025] 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.  | ||||
|     You are responsible for complying with 3rd party license terms   | ||||
|     applicable to your use of 3rd party software (including open source   | ||||
|     software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?  | ||||
|     NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS  | ||||
|     SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,   | ||||
|     MERCHANTABILITY, OR 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 RELATED TO THE SOFTWARE WILL NOT  | ||||
|     EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR  | ||||
|     THIS SOFTWARE. | ||||
| */ | ||||
|  | ||||
| /** | ||||
|   Section: Included Files | ||||
| */ | ||||
| #include "../eusart1.h" | ||||
|  | ||||
| /** | ||||
|   Section: Macro Declarations | ||||
| */ | ||||
|  | ||||
| /** | ||||
|   Section: Driver Interface | ||||
|  */ | ||||
|  | ||||
| const uart_drv_interface_t UART1 = { | ||||
|     .Initialize = &EUSART1_Initialize, | ||||
|     .Deinitialize = &EUSART1_Deinitialize, | ||||
|     .Read = &EUSART1_Read, | ||||
|     .Write = &EUSART1_Write, | ||||
|     .IsRxReady = &EUSART1_IsRxReady, | ||||
|     .IsTxReady = &EUSART1_IsTxReady, | ||||
|     .IsTxDone = &EUSART1_IsTxDone, | ||||
|     .TransmitEnable = &EUSART1_TransmitEnable, | ||||
|     .TransmitDisable = &EUSART1_TransmitDisable, | ||||
|     .AutoBaudSet = &EUSART1_AutoBaudSet, | ||||
|     .AutoBaudQuery = &EUSART1_AutoBaudQuery, | ||||
|     .BRGCountSet = NULL, | ||||
|     .BRGCountGet = NULL, | ||||
|     .BaudRateSet = NULL, | ||||
|     .BaudRateGet = NULL, | ||||
|     .AutoBaudEventEnableGet = NULL, | ||||
|     .ErrorGet = &EUSART1_ErrorGet, | ||||
|     .TxCompleteCallbackRegister = NULL, | ||||
|     .RxCompleteCallbackRegister = NULL, | ||||
|     .TxCollisionCallbackRegister = NULL, | ||||
|     .FramingErrorCallbackRegister = &EUSART1_FramingErrorCallbackRegister, | ||||
|     .OverrunErrorCallbackRegister = &EUSART1_OverrunErrorCallbackRegister, | ||||
|     .ParityErrorCallbackRegister = NULL, | ||||
|     .EventCallbackRegister = NULL, | ||||
| }; | ||||
|  | ||||
| /** | ||||
|   Section: EUSART1 variables | ||||
| */ | ||||
| static volatile eusart1_status_t eusart1RxLastError; | ||||
|  | ||||
| /** | ||||
|   Section: EUSART1 APIs | ||||
| */ | ||||
|  | ||||
| static void (*EUSART1_FramingErrorHandler)(void) = NULL; | ||||
| static void (*EUSART1_OverrunErrorHandler)(void) = NULL; | ||||
|  | ||||
| static void EUSART1_DefaultFramingErrorCallback(void); | ||||
| static void EUSART1_DefaultOverrunErrorCallback(void); | ||||
|  | ||||
|  | ||||
| /** | ||||
|   Section: EUSART1  APIs | ||||
| */ | ||||
|  | ||||
| void EUSART1_Initialize(void) | ||||
| { | ||||
|     // Set the EUSART1 module to the options selected in the user interface. | ||||
|  | ||||
|     //ABDEN disabled; WUE disabled; BRG16 16bit_generator; SCKP Non-Inverted;  | ||||
|     BAUD1CON = 0x48;  | ||||
|     //ADDEN disabled; CREN enabled; SREN disabled; RX9 8-bit; SPEN enabled;  | ||||
|     RC1STA = 0x90;  | ||||
|     //TX9D 0x0; BRGH hi_speed; SENDB sync_break_complete; SYNC asynchronous; TXEN enabled; TX9 8-bit; CSRC client;  | ||||
|     TX1STA = 0x26;  | ||||
|     //SPBRGL 64;  | ||||
|     SP1BRGL = 0x40;  | ||||
|     //SPBRGH 3;  | ||||
|     SP1BRGH = 0x3;  | ||||
|  | ||||
|     EUSART1_FramingErrorCallbackRegister(EUSART1_DefaultFramingErrorCallback); | ||||
|     EUSART1_OverrunErrorCallbackRegister(EUSART1_DefaultOverrunErrorCallback); | ||||
|     eusart1RxLastError.status = 0;   | ||||
|  | ||||
| } | ||||
|  | ||||
| void EUSART1_Deinitialize(void) | ||||
| { | ||||
|     BAUD1CON = 0x00; | ||||
|     RC1STA = 0x00; | ||||
|     TX1STA = 0x00; | ||||
|     SP1BRGL = 0x00; | ||||
|     SP1BRGH = 0x00; | ||||
| } | ||||
|  | ||||
| void EUSART1_Enable(void) | ||||
| { | ||||
|     RC1STAbits.SPEN = 1; | ||||
|  | ||||
| } | ||||
|  | ||||
| void EUSART1_Disable(void) | ||||
| { | ||||
|     RC1STAbits.SPEN = 0; | ||||
| } | ||||
|  | ||||
|  | ||||
| void EUSART1_TransmitEnable(void) | ||||
| { | ||||
|     TX1STAbits.TXEN = 1; | ||||
| } | ||||
|  | ||||
| void EUSART1_TransmitDisable(void) | ||||
| { | ||||
|     TX1STAbits.TXEN = 0; | ||||
| } | ||||
|  | ||||
| void EUSART1_ReceiveEnable(void) | ||||
| { | ||||
|     RC1STAbits.CREN = 1; | ||||
| } | ||||
|  | ||||
| void EUSART1_ReceiveDisable(void) | ||||
| { | ||||
|     RC1STAbits.CREN = 0; | ||||
| } | ||||
|  | ||||
| void EUSART1_SendBreakControlEnable(void) | ||||
| { | ||||
|     TX1STAbits.SENDB = 1; | ||||
| } | ||||
|  | ||||
| void EUSART1_SendBreakControlDisable(void) | ||||
| { | ||||
|     TX1STAbits.SENDB = 0; | ||||
| } | ||||
|  | ||||
| void EUSART1_AutoBaudSet(bool enable) | ||||
| { | ||||
|     if(enable) | ||||
|     { | ||||
|         BAUD1CONbits.ABDEN = 1; | ||||
|     } | ||||
|     else | ||||
|     { | ||||
|        BAUD1CONbits.ABDEN = 0;  | ||||
|     } | ||||
| } | ||||
|  | ||||
| bool EUSART1_AutoBaudQuery(void) | ||||
| { | ||||
| return (bool)(!BAUD1CONbits.ABDEN); | ||||
| } | ||||
|  | ||||
| bool EUSART1_IsAutoBaudDetectOverflow(void) | ||||
| { | ||||
|     return (bool)BAUD1CONbits.ABDOVF;  | ||||
| } | ||||
|  | ||||
| void EUSART1_AutoBaudDetectOverflowReset(void) | ||||
| { | ||||
|     BAUD1CONbits.ABDOVF = 0;  | ||||
| } | ||||
|  | ||||
| bool EUSART1_IsRxReady(void) | ||||
| { | ||||
|     return (bool)(PIR3bits.RC1IF); | ||||
| } | ||||
|  | ||||
| bool EUSART1_IsTxReady(void) | ||||
| { | ||||
|     return (bool)(PIR3bits.TX1IF && TX1STAbits.TXEN); | ||||
| } | ||||
|  | ||||
| bool EUSART1_IsTxDone(void) | ||||
| { | ||||
|     return TX1STAbits.TRMT; | ||||
| } | ||||
|  | ||||
| size_t EUSART1_ErrorGet(void) | ||||
| { | ||||
|     return eusart1RxLastError.status; | ||||
| } | ||||
|  | ||||
| uint8_t EUSART1_Read(void) | ||||
| { | ||||
|     eusart1RxLastError.status = 0; | ||||
|     if(true == RC1STAbits.OERR) | ||||
|     { | ||||
|         eusart1RxLastError.oerr = 1; | ||||
|         if(NULL != EUSART1_OverrunErrorHandler) | ||||
|         { | ||||
|             EUSART1_OverrunErrorHandler(); | ||||
|         }    | ||||
|     } | ||||
|     if(true == RC1STAbits.FERR) | ||||
|     { | ||||
|         eusart1RxLastError.ferr = 1; | ||||
|         if(NULL != EUSART1_FramingErrorHandler) | ||||
|         { | ||||
|             EUSART1_FramingErrorHandler(); | ||||
|         }    | ||||
|     } | ||||
|     return RC1REG; | ||||
| } | ||||
|  | ||||
| void EUSART1_Write(uint8_t txData) | ||||
| { | ||||
|     TX1REG = txData; | ||||
| } | ||||
|  | ||||
| static void EUSART1_DefaultFramingErrorCallback(void) | ||||
| { | ||||
|      | ||||
| } | ||||
|  | ||||
| static void EUSART1_DefaultOverrunErrorCallback(void) | ||||
| { | ||||
|     //Continuous Receive must be cleared to clear Overrun Error else Rx will not receive upcoming bytes | ||||
|     RC1STAbits.CREN = 0; | ||||
|     RC1STAbits.CREN = 1; | ||||
| } | ||||
|  | ||||
| void EUSART1_FramingErrorCallbackRegister(void (* callbackHandler)(void)) | ||||
| { | ||||
|     if(NULL != callbackHandler) | ||||
|     { | ||||
|         EUSART1_FramingErrorHandler = callbackHandler; | ||||
|     } | ||||
| } | ||||
|  | ||||
| void EUSART1_OverrunErrorCallbackRegister(void (* callbackHandler)(void)) | ||||
| { | ||||
|     if(NULL != callbackHandler) | ||||
|     { | ||||
|         EUSART1_OverrunErrorHandler = callbackHandler; | ||||
|     }     | ||||
| } | ||||
|  | ||||
							
								
								
									
										91
									
								
								mcc_generated_files/uart/uart_drv_interface.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										91
									
								
								mcc_generated_files/uart/uart_drv_interface.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,91 @@ | ||||
| /** | ||||
|  * UART Generated Driver Interface Header File | ||||
|  *  | ||||
|  * @file uart_drv_interface.h | ||||
|  *  | ||||
|  * @defgroup uart_drv_interface UART_DRV_INTERFACE | ||||
|  *  | ||||
|  * @brief This file contains API prototypes and data types of the Universal Asynchronous Receiver and Transmitter (UART) interface. | ||||
|  * | ||||
|  * @version UART Driver Version 3.0.2 | ||||
| */ | ||||
| /* | ||||
| <EFBFBD> [2025] 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.  | ||||
|     You are responsible for complying with 3rd party license terms   | ||||
|     applicable to your use of 3rd party software (including open source   | ||||
|     software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?  | ||||
|     NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS  | ||||
|     SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,   | ||||
|     MERCHANTABILITY, OR 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 RELATED TO THE SOFTWARE WILL NOT  | ||||
|     EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR  | ||||
|     THIS SOFTWARE. | ||||
| */ | ||||
|  | ||||
| #ifndef UART_DRV_INTERFACE_H | ||||
| #define	UART_DRV_INTERFACE_H | ||||
|  | ||||
| /** | ||||
|   Section: Included Files | ||||
| */ | ||||
| #include <stdbool.h> | ||||
| #include <stdint.h> | ||||
| #include <stddef.h> | ||||
| #include "uart_types.h" | ||||
|  | ||||
| #ifdef	__cplusplus | ||||
| extern "C" { | ||||
| #endif | ||||
|  | ||||
|     | ||||
| /** | ||||
|   Section: Data Type Definitions | ||||
| */  | ||||
|        | ||||
| /** | ||||
|  @ingroup UART | ||||
|  @struct uart_drv_interface_t | ||||
|  @brief Structure containing the function pointers of UART driver. | ||||
| */ | ||||
| typedef struct { | ||||
| void (*Initialize)(void);    | ||||
| void (*Deinitialize)(void); | ||||
| uint8_t (*Read)(void); | ||||
| void (*Write)(uint8_t); | ||||
| bool (*IsRxReady)(void); | ||||
| bool (*IsTxReady)(void); | ||||
| bool (*IsTxDone)(void); | ||||
| void (*TransmitEnable)(void); | ||||
| void (*TransmitDisable)(void); | ||||
| void (*AutoBaudSet)(bool enable); | ||||
| bool (*AutoBaudQuery)(void); | ||||
| bool (*AutoBaudEventEnableGet)(void); | ||||
| void (*BRGCountSet)(uint32_t brgValue); | ||||
| uint32_t (*BRGCountGet)(void); | ||||
| void (*BaudRateSet)(uint32_t baudRate); | ||||
| uint32_t (*BaudRateGet)(void); | ||||
| size_t (*ErrorGet)(void); | ||||
| void (*TxCompleteCallbackRegister)(void (*CallbackHandler) (void)); | ||||
| void (*RxCompleteCallbackRegister)(void (*CallbackHandler) (void)); | ||||
| void (*TxCollisionCallbackRegister)(void (*CallbackHandler) (void)); | ||||
| void (*FramingErrorCallbackRegister)(void (*CallbackHandler) (void)); | ||||
| void (*OverrunErrorCallbackRegister)(void (*CallbackHandler) (void)); | ||||
| void (*ParityErrorCallbackRegister)(void (*CallbackHandler) (void)); | ||||
| void (*EventCallbackRegister)(void (*CallbackHandler) (void)); | ||||
| }uart_drv_interface_t; | ||||
|  | ||||
|  | ||||
| #ifdef	__cplusplus | ||||
| } | ||||
| #endif | ||||
|  | ||||
| #endif	/* UART_DRV_INTERFACE_H */ | ||||
|  | ||||
							
								
								
									
										81
									
								
								mcc_generated_files/uart/uart_types.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										81
									
								
								mcc_generated_files/uart/uart_types.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,81 @@ | ||||
| /** | ||||
|  * UART Generated Driver Interface Header File | ||||
|  *  | ||||
|  * @file uart_types.h | ||||
|  *  | ||||
|  * @defgroup uart_types UART_TYPES | ||||
|  *  | ||||
|  * @brief This file contains the enumeration of different Universal Asynchronous Receiver and Transmitter (UART) baud rates. | ||||
|  * | ||||
|  * @version UART Driver Version 3.0.2 | ||||
| */ | ||||
| /* | ||||
| <EFBFBD> [2025] 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.  | ||||
|     You are responsible for complying with 3rd party license terms   | ||||
|     applicable to your use of 3rd party software (including open source   | ||||
|     software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?  | ||||
|     NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS  | ||||
|     SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,   | ||||
|     MERCHANTABILITY, OR 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 RELATED TO THE SOFTWARE WILL NOT  | ||||
|     EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR  | ||||
|     THIS SOFTWARE. | ||||
| */ | ||||
|  | ||||
| #ifndef UART_TYPES_H | ||||
| #define	UART_TYPES_H | ||||
|  | ||||
| /** | ||||
|   Section: Included Files | ||||
| */ | ||||
| #include <stdbool.h> | ||||
| #include <stdint.h> | ||||
|  | ||||
| #ifdef	__cplusplus | ||||
| extern "C" { | ||||
| #endif | ||||
|  | ||||
|     | ||||
| /** | ||||
|   Section: Data Type Definitions | ||||
| */  | ||||
|        | ||||
| /** | ||||
| @ingroup uartdriver | ||||
| @enum UART_STANDARD_BAUDS | ||||
| @brief This Enum can be used to set the UART standard | ||||
| baud rates using \ref UARTx_BRGSet function e.g. \ref UART1_BRGSet. | ||||
| */ | ||||
| enum UART_STANDARD_BAUDS{ | ||||
| UART_110 = 0, | ||||
| UART_300 = 1, | ||||
| UART_600 = 2, | ||||
| UART_1200 = 3, | ||||
| UART_2400 = 4, | ||||
| UART_4800 = 5, | ||||
| UART_9600 = 6, | ||||
| UART_14400 = 7, | ||||
| UART_19200 = 8, | ||||
| UART_38400 = 9, | ||||
| UART_57600 = 10, | ||||
| UART_115200 = 11, | ||||
| UART_230400 = 12, | ||||
| UART_460800 = 13, | ||||
| UART_921600 = 14, | ||||
| }; | ||||
|  | ||||
|  | ||||
| #ifdef	__cplusplus | ||||
| } | ||||
| #endif | ||||
|  | ||||
| #endif	/* UART_TYPES_H */ | ||||
|  | ||||
		Reference in New Issue
	
	Block a user