ADuCM4x50 Device Drivers API Reference Manual  Release 4.0.0.0
common.c
1 
13 #include "common.h"
14 
15 char aDebugString[150u];
16 
17 #ifdef REDIRECT_OUTPUT_TO_UART
18 
19 #include <drivers/uart/adi_uart.h>
20 #include <drivers/general/adi_drivers_general.h>
21 
22 ADI_UART_HANDLE hDevOutput = NULL;
23 
24 ADI_ALIGNED_PRAGMA(4)
25 uint8_t OutDeviceMem[ADI_UART_UNIDIR_MEMORY_SIZE] ADI_ALIGNED_ATTRIBUTE(4);
26 
27 #define UART0_TX_PORTP0_MUX (1u<<20)
28 #define UART0_RX_PORTP0_MUX (1u<<22)
29 
30 #endif /* REDIRECT_OUTPUT_TO_UART */
31 
38 void common_Init(void)
39 {
40 #ifdef REDIRECT_OUTPUT_TO_UART
41  /* Set the pinmux for the UART */
42  *pREG_GPIO0_CFG |= UART0_TX_PORTP0_MUX | UART0_RX_PORTP0_MUX;
43 
44  /* Open the UART device, data transfer is bidirectional with NORMAL mode by default */
45  adi_uart_Open(0u, ADI_UART_DIR_TRANSMIT, OutDeviceMem, sizeof OutDeviceMem, &hDevOutput);
46 #endif
47 }
48 
49 
56 void common_Pass(void)
57 {
58  char pass[] = "All done!\n\r";
59 
60 #ifdef REDIRECT_OUTPUT_TO_UART
61  uint32_t pHwError;
62  /* Ignore return codes since there's nothing we can do if it fails */
63  adi_uart_Write(hDevOutput, pass, strlen(pass), false, &pHwError);
64 #else
65  printf(pass);
66 #endif
67 }
68 
69 
78 void common_Fail(char *FailureReason)
79 {
80  char fail[] = "Failed: ";
81  char term[] = "\n\r";
82 
83 #ifdef REDIRECT_OUTPUT_TO_UART
84  uint32_t pHwError;
85  /* Ignore return codes since there's nothing we can do if it fails */
86  adi_uart_Write(hDevOutput, fail, strlen(fail), false, &pHwError);
87  adi_uart_Write(hDevOutput, FailureReason, strlen(FailureReason), false, &pHwError);
88  adi_uart_Write(hDevOutput, term, strlen(term), false, &pHwError);
89 #else
90  printf(fail);
91  printf(FailureReason);
92  printf(term);
93 #endif
94  }
95 
96 
105 void common_Perf(char *InfoString)
106 {
107  char term[] = "\n\r";
108 
109 #ifdef REDIRECT_OUTPUT_TO_UART
110  uint32_t pHwError;
111  /* Ignore return codes since there's nothing we can do if it fails */
112  adi_uart_Write(hDevOutput, InfoString, strlen(InfoString), false, &pHwError);
113  adi_uart_Write(hDevOutput, term, strlen(term), false, &pHwError);
114 #else
115  printf(InfoString);
116  printf(term);
117 #endif
118 }
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....
Definition: adi_uart.c:1490
struct _ADI_UART_DEVICE * ADI_UART_HANDLE
Definition: adi_uart.h:55
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:284
#define ADI_UART_UNIDIR_MEMORY_SIZE
Definition: adi_uart.h:45