there are four files I've created: uart.c uart.h main.c main.h. uart.h is included both in uart.c and main.c
my DSP communicates with a device via UART. The processor is BF527, the IDE is CCES 18.104.22.168.
uart functions should be in uart.c, since main.c is already very large. However, there is a problem with the location of "static ADI_UART_HANDLE hUARTDevice" declaration. I've tried three ways, only the last one works:
If "static ADI_UART_HANDLE hUARTDevice" is declared in uart.c, while declared again as extern "extern static ADI_UART_HANDLE hUARTDevice" in main.c and used in a function in main.c, e.g. adi_uart_Read(), there is an error during compilation:
[Error li1021] The following symbols referenced in processor 'p0' could not be resolved:
'hUARTDevice [_hUARTDevice]' referenced from '.\src\main.doj'
Linker finished with 1 error
cc3089: fatal error: Link failed (code:1)
make: *** [main.dxe] Error 1
If "static ADI_UART_HANDLE hUARTDevice" is declared in uart.h. No extern hUARTDevice declared in main.c.Compilation passes. However, there is a real time error is the programm is executed under debug mode:
A non-recoverable error or exception has occurred.
Description: Attempted misaligned data memory or data cache access (Exception with EXCAUSE=0x24).
General Type: UnhandledException
Specific Type: DataMisalignedAccessViolation
Error PC: 0x0180b1d4
A SDRAM is used in my case. May be this error has something to do with SDRAM.
"static ADI_UART_HANDLE hUARTDevice" is declared in uart.c. No extern hUARTDevice declared in main.c. In main.c a wrapper:
UART_Read(void *const pBuffer, uint32_t nBufSize)
is called instead of
adi_uart_Read(ADI_UART_HANDLE const hDevice, void *const pBuffer, uint32_t nBufSize)
Wrapper UART_Read(void *const pBuffer, uint32_t nBufSize) is defined in uart.c.
In this way hUARTDevice is avoided from being used in main.c. But I think this is not a decent way. If many functions which have parameter type ADI_UART_HANDLE must be called in main.c, then lots of wrappers must be written.
I want to use original APIs in main.c, while define uart functions in uart.c. Where should I declare hUARTDevice?