130 #if defined(HAS_SERPORT_UART)
136 #if (CLOCK_FREQ==32000000ul)
137 #ifndef UART_BAUD_1K2
138 #define UART_BAUD_1K2 3332 //0.01% error
140 #ifndef UART_BAUD_2K4
141 #define UART_BAUD_2K4 1666 //0.01% error
143 #ifndef UART_BAUD_4K8
144 #define UART_BAUD_4K8 832
146 #ifndef UART_BAUD_9K6
147 #define UART_BAUD_9K6 416 //0.07% error
149 #ifndef UART_BAUD_19K2
150 #define UART_BAUD_19K2 207 //0.16% error
152 #ifndef UART_BAUD_38K4
153 #define UART_BAUD_38K4 103 //0.16% error
155 #ifndef UART_BAUD_56K
156 #define UART_BAUD_56K 70 //0.6% error
158 #ifndef UART_BAUD_115K
159 #define UART_BAUD_115K 34 //0.62% error
161 #ifndef UART_BAUD_250K
162 #define UART_BAUD_250K 15 //0% error
166 #error "UART does not support this CLOCK_FREQ"
171 #if !defined(UART1_RXBUF_SIZE)
172 #define UART1_RXBUF_SIZE 64
174 #if !defined(UART1_TXBUF_SIZE)
175 #define UART1_TXBUF_SIZE 256
177 #if !defined(UART2_RXBUF_SIZE)
178 #define UART2_RXBUF_SIZE 32
180 #if !defined(UART2_TXBUF_SIZE)
181 #define UART2_TXBUF_SIZE 128
183 #if !defined(UART3_RXBUF_SIZE)
184 #define UART3_RXBUF_SIZE 32
186 #if !defined(UART3_TXBUF_SIZE)
187 #define UART3_TXBUF_SIZE 128
193 #define UART_TXION_STATUS_OK 0 //Currently OK, have not finished adding whole message to buffer
194 #define UART_TXION_STATUS_ADDED_TO_BUF 1 //Successfully added whole message to the buffer (from start to stop)
195 #define UART_TXION_STATUS_ERROR 4 //No space in buffer to add message
196 #define UART_TXION_STATUS_ERR_NOSPACE 5 //No space in buffer to add message
197 #define UART_TXION_STATUS_ERR_ADR_NOACK 6 //Slave did not ACK address we sent
198 #define UART_TXION_STATUS_ERR_DAT_NOACK 7 //Slave did not ACK data we sent
199 #define UART_TXION_STATUS_ERR_BUF_FRMT 8 //Buffer format error
200 #define UART_TXION_STATUS_ERR_TIMEOUT 9 //Timeout
201 #define UART_TXION_STATUS_NOT_AVAILABLE 0xFF //Status not available
204 #if (defined(HAS_SERPORT_UART1) || defined(HAS_SERPORT_UART2) || defined(HAS_SERPORT_UART3) || defined(HAS_SERPORT_UART4))
205 #if !defined(HAS_A_SERPORT)
206 #define HAS_A_SERPORT
214 #if defined(CIRBUF_USE_CIRCULAR_BUFFER_PWR2)
215 #if defined(HAS_SERPORT_UART1)
217 #if ((UART1_TXBUF_SIZE & ~(UART1_TXBUF_SIZE-1))!=UART1_TXBUF_SIZE)
218 #error "UART1 UART1_TXBUF_SIZE is not power of 2! Either change size defined in projdefs.h --OR-- use nz_circularBufferStd.c in stead of nz_circularBufferPwr2.c for project!"
222 #if ((UART1_RXBUF_SIZE & ~(UART1_RXBUF_SIZE-1))!=UART1_RXBUF_SIZE)
223 #error "UART1 UART1_RXBUF_SIZE is not power of 2! Either change size defined in projdefs.h --OR-- use nz_circularBufferStd.c in stead of nz_circularBufferPwr2.c for project!"
226 #if defined(HAS_SERPORT_UART2)
228 #if ((UART2_TXBUF_SIZE & ~(UART2_TXBUF_SIZE-1))!=UART2_TXBUF_SIZE)
229 #error "UART2 UART2_TXBUF_SIZE is not power of 2! Either change size defined in projdefs.h --OR-- use nz_circularBufferStd.c in stead of nz_circularBufferPwr2.c for project!"
233 #if ((UART2_RXBUF_SIZE & ~(UART2_RXBUF_SIZE-1))!=UART2_RXBUF_SIZE)
234 #error "UART2 UART2_RXBUF_SIZE is not power of 2! Either change size defined in projdefs.h --OR-- use nz_circularBufferStd.c in stead of nz_circularBufferPwr2.c for project!"
237 #if defined(HAS_SERPORT_UART3)
239 #if ((UART3_TXBUF_SIZE & ~(UART3_TXBUF_SIZE-1))!=UART3_TXBUF_SIZE)
240 #error "UART3 UART3_TXBUF_SIZE is not power of 2! Either change size defined in projdefs.h --OR-- use nz_circularBufferStd.c in stead of nz_circularBufferPwr2.c for project!"
244 #if ((UART3_RXBUF_SIZE & ~(UART3_RXBUF_SIZE-1))!=UART3_RXBUF_SIZE)
245 #error "UART3 UART3_RXBUF_SIZE is not power of 2! Either change size defined in projdefs.h --OR-- use nz_circularBufferStd.c in stead of nz_circularBufferPwr2.c for project!"
248 #if defined(HAS_SERPORT_UART4)
250 #if ((UART4_TXBUF_SIZE & ~(UART4_TXBUF_SIZE-1))!=UART4_TXBUF_SIZE)
251 #error "UART4 UART4_TXBUF_SIZE is not power of 2! Either change size defined in projdefs.h --OR-- use nz_circularBufferStd.c in stead of nz_circularBufferPwr2.c for project!"
255 #if ((UART4_RXBUF_SIZE & ~(UART4_RXBUF_SIZE-1))!=UART4_RXBUF_SIZE)
256 #error "UART4 UART4_RXBUF_SIZE is not power of 2! Either change size defined in projdefs.h --OR-- use nz_circularBufferStd.c in stead of nz_circularBufferPwr2.c for project!"
266 typedef struct __attribute__((aligned(2), packed))
271 unsigned int bFill : 16;
284 } SERPORT_UART_CONFIG;
287 #define RD_DEST_TYPE_LISTENERS 0
288 #define RD_DEST_TYPE_POINTER 2
289 #define RD_DEST_TYPE_CIRBUF 3
291 typedef struct __attribute__((__packed__)) UART_ISR_SMFLAGS_
297 unsigned int isrTxionStatus : 1;
298 unsigned int fill12 : 11;
305 #define UART_STATUS_BUF_SIZE 8
307 typedef struct UART_INFO_
312 BYTE bufStat[UART_STATUS_BUF_SIZE];
325 UART_ISR_SMFLAGS isr;
330 BYTE currTxionStatus;
344 void serUartInit(
void);
351 void serUartTask(UART_INFO* objUART);
367 BYTE serUartRegisterListener(
CIRBUF* pBuf);
379 UART_INFO* uartGetInfoForBus(BYTE uartBus);
392 BYTE serUartIsBusy(UART_INFO* objUART);
402 BYTE serUartWrite(UART_INFO* objUART, BYTE b);
416 BYTE serUartWriteArray(UART_INFO* objUART, BYTE* arr, BYTE size);
429 BYTE serUartWriteString(UART_INFO* objUART,
const char* str);
472 #if defined(HAS_SERPORT_UART1)
474 #if !defined(SERPORT_UART1_CREATE_OWN_CIRBUFS)
479 #ifndef THIS_IS_NZ_SERUART1_C
480 extern UART_INFO uart1Info;
482 #define UART1_INFO &uart1Info
486 #if defined(SERPORT_UART1_CREATE_OWN_CIRBUFS)
488 #ifndef THIS_IS_NZ_SERUART1_C
489 extern CIRBUF cbufTxUART1;
490 extern CIRBUF cbufRxUART1;
493 #define CIRBUF_TX_UART1 &cbufTxUART1
494 #define CIRBUF_RX_UART1 &cbufRxUART1
501 void serUart1Init(
void);
507 void serUart1Task(
void);
517 BYTE serUart1IsBusy(
void);
528 BYTE serUart1Write(BYTE b);
539 BYTE serUart1WriteArray(BYTE* arr, BYTE size);
550 BYTE serUart1WriteString(
const char* str);
556 #define serUart1GetTxBufFree() cbufGetFree(CIRBUF_TX_UART1)
562 #define serUart1EmptyTxBuf() cbufEmpty(CIRBUF_TX_UART1)
570 #define serUart1IsTxBufEmpty() cbufIsEmpty(CIRBUF_TX_UART1)
578 #define serUart1IsTxBufFull() cbufIsFull(CIRBUF_TX_UART1)
588 #define serUart1GetRxBufCount() cbufGetCount(CIRBUF_RX_UART1)
597 #define serUart1HasData() cbufHasData(CIRBUF_RX_UART1)
606 #define serUart1IsRxBufEmpty() cbufIsEmpty(CIRBUF_RX_UART1)
617 #define serUart1Read() cbufGetByte(CIRBUF_RX_UART1)
618 #define serUart1GetByte() cbufGetByte(CIRBUF_RX_UART1)
632 #define serUart1ReadArray(pDstArr, size) cbufGetArray(CIRBUF_RX_UART1, pDstArr, size)
633 #define serUart1GetArray(pDstArr, size) cbufGetArray(CIRBUF_RX_UART1, pDstArr, size)
635 #endif //#if defined(HAS_SERPORT_UART1)
637 #endif //#if defined(HAS_SERPORT_UART)
638 #endif //#ifndef NZ_SERUART_H