ADuCM302x Device Drivers API Reference Manual  Release 3.1.2.0
common.c
1 
44 #include "common.h"
45 
46 char aDebugString[150u];
47 
48 #ifdef REDIRECT_OUTPUT_TO_UART
49 
50 #include <drivers/uart/adi_uart.h>
51 #include <drivers/general/adi_drivers_general.h>
52 
53 ADI_UART_HANDLE hDevOutput = NULL;
54 
55 ADI_ALIGNED_PRAGMA(4)
56 uint8_t OutDeviceMem[ADI_UART_UNIDIR_MEMORY_SIZE] ADI_ALIGNED_ATTRIBUTE(4);
57 
58 #define UART0_TX_PORTP0_MUX (1u<<20)
59 #define UART0_RX_PORTP0_MUX (1u<<22)
60 
61 #endif /* REDIRECT_OUTPUT_TO_UART */
62 
69 void common_Init(void)
70 {
71 #ifdef REDIRECT_OUTPUT_TO_UART
72  /* Set the pinmux for the UART */
73  *pREG_GPIO0_CFG |= UART0_TX_PORTP0_MUX | UART0_RX_PORTP0_MUX;
74 
75  /* Open the UART device, data transfer is bidirectional with NORMAL mode by default */
76  adi_uart_Open(0u, ADI_UART_DIR_TRANSMIT, OutDeviceMem, sizeof OutDeviceMem, &hDevOutput);
77 #endif
78 }
79 
80 
87 void common_Pass(void)
88 {
89  char pass[] = "All done!\n\r";
90 
91 #ifdef REDIRECT_OUTPUT_TO_UART
92  uint32_t pHwError;
93  /* Ignore return codes since there's nothing we can do if it fails */
94  adi_uart_Write(hDevOutput, pass, strlen(pass), false, &pHwError);
95 #else
96  printf(pass);
97 #endif
98 }
99 
100 
109 void common_Fail(char *FailureReason)
110 {
111  char fail[] = "Failed: ";
112  char term[] = "\n\r";
113 
114 #ifdef REDIRECT_OUTPUT_TO_UART
115  uint32_t pHwError;
116  /* Ignore return codes since there's nothing we can do if it fails */
117  adi_uart_Write(hDevOutput, fail, strlen(fail), false, &pHwError);
118  adi_uart_Write(hDevOutput, FailureReason, strlen(FailureReason), false, &pHwError);
119  adi_uart_Write(hDevOutput, term, strlen(term), false, &pHwError);
120 #else
121  printf(fail);
122  printf(FailureReason);
123  printf(term);
124 #endif
125  }
126 
127 
136 void common_Perf(char *InfoString)
137 {
138  char term[] = "\n\r";
139 
140 #ifdef REDIRECT_OUTPUT_TO_UART
141  uint32_t pHwError;
142  /* Ignore return codes since there's nothing we can do if it fails */
143  adi_uart_Write(hDevOutput, InfoString, strlen(InfoString), false, &pHwError);
144  adi_uart_Write(hDevOutput, term, strlen(term), false, &pHwError);
145 #else
146  printf(InfoString);
147  printf(term);
148 #endif
149 }
ADI_UART_RESULT adi_uart_Write(ADI_UART_HANDLE const hDevice, void *const pBuffer, uint32_t const nBufSize, bool const bDMA, uint32_t *pHwError)
Submit the buffer for transmitting the data in ADI_UART_DATA_TRANSFER_MODE_BLOCKING. Call to this function will not return until the entire buffer is transmitted. Returns error if this function is called when device is operating in ADI_UART_DATA_TRANSFER_MODE_NONBLOCKING. i.e Function "adi_uart_SubmitTxBuffer()" is called and the transfer is not yet complete.
Definition: adi_uart.c:1166
struct _ADI_UART_DEVICE * ADI_UART_HANDLE
Definition: adi_uart.h:86
ADI_UART_RESULT adi_uart_Open(uint32_t const nDeviceNum, ADI_UART_DIRECTION const eDirection, void *pMemory, uint32_t const nMemSize, ADI_UART_HANDLE *const phDevice)
Initialization function for the UART device.
Definition: adi_uart.c:315
#define ADI_UART_UNIDIR_MEMORY_SIZE
Definition: adi_uart.h:76