17 volatile uint16_t UartDmaTrg_Rx [] = {
18 DMATRG_UART1_RX, DMATRG_UART2_RX, DMATRG_UART3_RX, DMATRG_UART4_RX,
19 DMATRG_UART5_RX, DMATRG_UART6_RX, DMATRG_UART7_RX, DMATRG_UART8_RX
21 volatile uint16_t UartDmaTrg_Tx [] = {
22 DMATRG_UART1_TX, DMATRG_UART2_TX, DMATRG_UART3_TX, DMATRG_UART4_TX,
23 DMATRG_UART5_TX, DMATRG_UART6_TX, DMATRG_UART7_TX, DMATRG_UART8_TX
25 #elif defined (U7MODE) 26 volatile uint16_t UartDmaTrg_Rx [] = {
27 DMATRG_UART1_RX, DMATRG_UART2_RX, DMATRG_UART3_RX, DMATRG_UART4_RX,
28 DMATRG_UART5_RX, DMATRG_UART6_RX, DMATRG_UART7_RX
30 volatile uint16_t UartDmaTrg_Tx [] = {
31 DMATRG_UART1_TX, DMATRG_UART2_TX, DMATRG_UART3_TX, DMATRG_UART4_TX,
32 DMATRG_UART5_TX, DMATRG_UART6_TX, DMATRG_UART7_TX
34 #elif defined (U6MODE) 35 volatile uint16_t UartDmaTrg_Rx [] = {
36 DMATRG_UART1_RX, DMATRG_UART2_RX, DMATRG_UART3_RX, DMATRG_UART4_RX,
37 DMATRG_UART5_RX, DMATRG_UART6_RX
39 volatile uint16_t UartDmaTrg_Tx [] = {
40 DMATRG_UART1_TX, DMATRG_UART2_TX, DMATRG_UART3_TX, DMATRG_UART4_TX,
41 DMATRG_UART5_TX, DMATRG_UART6_TX
43 #elif defined (U5MODE) 44 volatile uint16_t UartDmaTrg_Rx [] = {
45 DMATRG_UART1_RX, DMATRG_UART2_RX, DMATRG_UART3_RX, DMATRG_UART4_RX,
48 volatile uint16_t UartDmaTrg_Tx [] = {
49 DMATRG_UART1_TX, DMATRG_UART2_TX, DMATRG_UART3_TX, DMATRG_UART4_TX,
52 #elif defined (U4MODE) 53 volatile uint16_t UartDmaTrg_Rx [] = {
54 DMATRG_UART1_RX, DMATRG_UART2_RX, DMATRG_UART3_RX, DMATRG_UART4_RX
56 volatile uint16_t UartDmaTrg_Tx [] = {
57 DMATRG_UART1_TX, DMATRG_UART2_TX, DMATRG_UART3_TX, DMATRG_UART4_TX
59 #elif defined (U3MODE) 60 volatile uint16_t UartDmaTrg_Rx [] = {
61 DMATRG_UART1_RX, DMATRG_UART2_RX, DMATRG_UART3_RX
63 volatile uint16_t UartDmaTrg_Tx [] = {
64 DMATRG_UART1_TX, DMATRG_UART2_TX, DMATRG_UART3_TX
66 #elif defined (U2MODE) 67 volatile uint16_t UartDmaTrg_Rx [] = {
68 DMATRG_UART1_RX, DMATRG_UART2_RX
70 volatile uint16_t UartDmaTrg_Tx [] = {
71 DMATRG_UART1_TX, DMATRG_UART2_TX
73 #elif defined (U1MODE) 74 volatile uint16_t UartDmaTrg_Rx [] = {
77 volatile uint16_t UartDmaTrg_Tx [] = {
82 #define UartInterfase_GetDmaTriggerRx(x) (volatile uint16_t)UartDmaTrg_Rx[x-1] 83 #define UartInterfase_GetDmaTriggerTx(x) (volatile uint16_t)UartDmaTrg_Tx[x-1] 85 #define UART_RXREG_ADDR_OFFSET (uint16_t)(&U1RXREG - &U1MODE) 86 #define UART_TXREG_ADDR_OFFSET (uint16_t)(&U1TXREG - &U1MODE) 139 volatile uint16_t p33c_UartPort_Initialize(
volatile struct UART_INTERFACE_s* port) {
141 volatile uint16_t retval=1;
153 p33c_PPS_RemapInput(port->
RxD.
io.
rpid, PPSIN_U1RX);
154 p33c_PPS_RemapOutput(port->
TxD.
io.
rpid, PPSOUT_U1TX);
158 gpio = p33c_GpioInstance_GetHandle(port->
TxD.
io.
port);
164 gpio = p33c_GpioInstance_GetHandle(port->
RxD.
io.
port);
171 uart = p33c_MpUartPort_GetHandle(port->
uart);
174 retval &= p33c_MpUartPort_ConfigWrite(port->
uart, uartConfigClear);
186 dmac = p33c_DmaModule_GetHandle();
189 p33c_DmaModule_ConfigWrite(dmaModuleConfigClear);
198 dma = p33c_DmaInstance_GetHandle(port->
RxD.
dma);
201 retval &= p33c_DmaInstance_ConfigWrite(port->
RxD.
dma, dmaInstanceConfigRxD);
212 dma = p33c_DmaInstance_GetHandle(port->
TxD.
dma);
215 retval &= p33c_DmaInstance_ConfigWrite(port->
TxD.
dma, dmaInstanceConfigTxD);
253 volatile uint16_t p33c_UartPort_OpenPort(
254 volatile uint16_t port_no,
volatile enum UART_BAUDRATE_e baud,
255 volatile enum UART_DATA_BITS_e data_bits,
volatile enum UART_PARITY_e parity,
256 volatile enum UART_STOP_BITS_e stop_bits,
volatile enum UART_FLOWCONRTOL_e flow_control)
259 volatile uint16_t retval=1;
263 if (port_no > P33C_UART_COUNT)
267 uart = p33c_MpUartPort_GetHandle(port_no);
270 if (SystemFrequencies.
fosc == 0)
276 case UART_DATABITS_7:
280 case UART_DATABITS_8:
285 case UART_PARITY_NONE:
288 case UART_PARITY_ODD:
291 case UART_PARITY_EVEN:
307 case UART_STOPBITS_1:
310 case UART_STOPBITS_15:
313 case UART_STOPBITS_2:
321 switch(flow_control) {
322 case UART_FLOWCONRTOL_NONE:
325 case UART_FLOWCONRTOL_HARDWARE:
328 case UART_FLOWCONRTOL_XON_XOFF:
341 retval &= p33c_UartPort_SetBaudrate (port_no, baud);
378 volatile uint16_t p33c_UartPort_Open(
volatile uint16_t port_no) {
380 volatile uint16_t retval=1;
384 if (port_no > P33C_UART_COUNT)
388 uart = p33c_MpUartPort_GetHandle(port_no);
426 volatile uint16_t p33c_UartPort_Close(
volatile uint16_t port_no) {
428 volatile uint16_t retval=1;
432 if (port_no > P33C_UART_COUNT)
436 uart = p33c_MpUartPort_GetHandle(port_no);
449 retval = (1 - (bool)(
477 volatile uint16_t p33c_UartPort_SetBaudrate(
478 volatile uint16_t port_no,
479 volatile uint32_t baud
482 volatile uint16_t retval=1;
484 volatile uint32_t _brg=0;
487 if (port_no > P33C_UART_COUNT)
491 uart = p33c_MpUartPort_GetHandle(port_no);
495 retval &= p33c_Osc_GetFrequencies();
498 _brg = (uint32_t)(SystemFrequencies.
fp / baud);
505 _brg = ((_brg >> 2)-1);
508 _brg = ((_brg >> 4)-1);
513 uart->
UxBRG.
value = (uint16_t)(_brg & 0x0000FFFF);
514 uart->
UxBRGH.
value = (uint16_t)((_brg & 0x00FF0000) >> 16);
537 volatile uint32_t p33c_UartPort_GetBaudrate(
volatile uint16_t port_no)
539 volatile uint32_t retval=1;
540 volatile uint32_t _brg=0;
541 volatile uint32_t _baud=0;
545 if (port_no > P33C_UART_COUNT)
549 uart = p33c_MpUartPort_GetHandle(port_no);
552 retval &= p33c_Osc_GetFrequencies();
564 _brg = ((_brg+1) << 2);
567 _brg = ((_brg+1) << 4);
573 _baud = (uint32_t)(SystemFrequencies.
fp / _brg);
598 volatile uint16_t p33c_UartPort_WriteByte(
volatile uint16_t port_no,
volatile char byte)
600 volatile uint16_t retval=1;
604 uart = p33c_MpUartPort_GetHandle(port_no);
625 volatile char p33c_UartPort_ReadByte(
volatile uint16_t port_no)
627 volatile uint16_t retval=1;
631 uart = p33c_MpUartPort_GetHandle(port_no);
654 volatile uint16_t p33c_UartPort_SendBufferDma(
656 volatile uint16_t start_addr,
657 volatile uint16_t length
661 volatile uint16_t retval=1;
662 volatile uint16_t timeout=0;
672 uart = p33c_MpUartPort_GetHandle(port->
uart);
673 dma = p33c_DmaInstance_GetHandle(port->
TxD.
dma);
675 if ((uart != NULL) && (dma != NULL)) {
682 if (timeout >= 50000)
return(0);
684 while((!uart->
UxSTA.
bits.TRMT) && (timeout++<50000));
685 if (timeout >= 50000)
return(0);
687 while((!uart->
UxSTAH.
bits.UTXBE) && (timeout++<50000));
688 if (timeout >= 50000)
return(0);
727 volatile uint16_t p33c_UartPort_RecieveBufferDma(
729 volatile uint16_t start_addr,
730 volatile uint16_t length
734 volatile uint16_t retval=1;
743 uart = p33c_MpUartPort_GetHandle(port->
uart);
744 dma = p33c_DmaInstance_GetHandle(port->
RxD.
dma);
746 if ((uart != NULL) && (dma != NULL)) {
775 .DMACHx.bits.TRMODE = 0b00,
776 .DMACHx.bits.SIZE = 1,
777 .DMACHx.bits.SAMODE = 0b00,
778 .DMACHx.bits.DAMODE = 0b01,
779 .DMACHx.bits.RELOAD = 0,
780 .DMACHx.bits.CHREQ = 0,
783 .DMAINTx.value = 0x0000,
784 .DMASRCx.value = 0x0000,
785 .DMADSTx.value = 0x0000,
786 .DMACNTx.value = 0x0000
792 .DMACHx.bits.TRMODE = 0b00,
793 .DMACHx.bits.SIZE = 1,
794 .DMACHx.bits.SAMODE = 0b01,
795 .DMACHx.bits.DAMODE = 0b00,
796 .DMACHx.bits.RELOAD = 0,
797 .DMACHx.bits.CHREQ = 0,
799 .DMAINTx.value = 0x0000,
800 .DMASRCx.value = 0x0000,
801 .DMADSTx.value = 0x0000,
802 .DMACNTx.value = 0x0000
union P33C_UART_INSTANCE_s::@150 UxSTAH
union P33C_GPIO_INSTANCE_s::@124 TRISx
union P33C_DMA_INSTANCE_s::@106 DMACHx
volatile struct UART_INSTANCE_STATUS_s status
Status word of the UART object.
union P33C_UART_INSTANCE_s::@148 UxMODEH
union P33C_DMA_INSTANCE_s::@107 DMAINTx
union P33C_UART_INSTANCE_s::@151 UxBRG
union P33C_UART_INSTANCE_s::@147 UxMODE
volatile uint16_t uart
UART instance of interface.
union P33C_UART_INSTANCE_s::@149 UxSTA
volatile struct UART_INTERFACE_CHANNEL_s TxD
UART Receive Channel Configuration.
union P33C_DMA_MODULE_s::@92 DmaCon
volatile uint16_t dma
DMA instance of interface.
volatile struct tagDMACH0BITS bits
union P33C_UART_INSTANCE_s::@153 UxRXREG
union P33C_DMA_INSTANCE_s::@108 DMASRCx
union P33C_DMA_INSTANCE_s::@110 DMACNTx
volatile struct tagDMACONBITS bits
volatile struct GPIO_PORT_PIN_s io
GPIO configuration.
union P33C_UART_INSTANCE_s::@152 UxBRGH
union P33C_DMA_INSTANCE_s::@109 DMADSTx
struct tagU1MODEBITS bits
volatile struct UART_INTERFACE_CHANNEL_s RxD
UART Receive Channel Configuration.
union P33C_UART_INSTANCE_s::@154 UxTXREG