Carmel (MAXREFDES18#) Code Documentation  V01.00
High Accuracy Analog Current/Voltage Output
 All Data Structures Files Functions Variables Macros Pages
utilities.h File Reference
#include "xbasic_types.h"
#include "xspi_l.h"
#include "stdio.h"
#include "xiic_l.h"
#include "xuartlite_i.h"
#include "xparameters.h"
#include "xgpio.h"
#include "xgpio_l.h"
#include "MAXREFDES18.h"

Go to the source code of this file.

Functions

void sendUartByte (u32 unUartAddress, u8 uchByte)
 Send a byte to the UART. Either directs to the full UART in the Zynq PS, or a Xilinx UartLite.
 
u8 checkUartEmpty (u32 unUartAddress)
 Check if either Uart is empty. Either directs to the full UART in the Zynq PS, or a Xilinx UartLite.
 
u8 getUartByte (u32 nUartAddress)
 Get a byte from either the full UART in the Zynq PS, or a Xilinx UartLite.
 
void print_asterisks (int nQuantity)
 Print nQuantity of asterisks to the default Hyperterminal UART.
 
int SpiRW (u32 unPeripheralAddressSPI, unsigned int unCPHA, unsigned int unCPOL, u8 *auchWriteBuf, u8 *auchReadBuf, int unNumBytes, u8 uchCsActiveHigh, u32 unSpiSS)
 Perform a SPI read or write.
 
void delay (int nStopValue)
 Loop for nStopValue iterations to provide a delay.
 
void led_knight_rider (XGpio *pLED_GPIO, int nNumberOfTimes)
 Blink a row of LEDs nNumberOfTimes times.
 
void max_set_PMOD_port (int nPortNumber, u8 uchPortType)
 Configure driving peripherals on each Pmod port.
 
void max_configure_PMOD_port (u8 uchPmodPortA, u8 uchPmodPortB, u8 uchPmodPortC, u8 uchPmodPortD)
 Configure driving peripherals on each Pmod port.
 
int number_raised_to_power (int nBase, int nExponent)
 Raise nBase to the nExponent power (operates with integers only).
 
int receive_byte_with_timeout (u32 unUartAddress, int nTimeoutInTenthsOfSeconds, u8 *uchRxData)
 Receive a byte from the UART located at *pUartAddress.
 
int GetLine (char *sInputString, unsigned int unMaxSize)
 Retrieve a line of characters from the default Hyperterminal UART (DEFAULT_HYPERTERMINAL_UART).
 
void sendOLEDSPI (u8 uchDataToWrite)
 Bit bang routine for Zedboard SPI OLED interface.
 
void initializeOLED (u8 *pFont)
 Initializes the OLED display.
 
void clearOLEDBuffer (u8 *pauchBuffer)
 Clears the OLED display buffer.
 
void displayOLEDBuffer (u8 *pauchBuffer)
 Copies the display buffer into the OLED display.
 
void putCharOLED (int x, int y, char chCharacter)
 Places a single ASCII character into the OLED display buffer.
 
void printfToBufferOLED (int x, int y, char *chString)
 Printf-like function to copy an ASCII string into the OLED display buffer.
 
void printfToOLED (int x, int y, char *chString)
 Printf-like function to copy an ASCII string into the OLED display buffer.
 
void flipAndCopyDisplayBuffer (u8 *pauchSourceBuffer, u8 *pauchDestinationBuffer)
 Copies the pixels from the source display buffer, into the destination buffer, flipping their location 180 degrees.
 

Detailed Description


      Project: Carmel (MAXREFDES18)
     Filename: utilities.h
  Description: This module contains the utility functions for the
               ZedBoard implementation of the example program
               for the MAXREFDES18.

Revision History:
08-19-2013 Rev 01.00 MG Initial release.


This code follows the following naming conventions:


char chPmodValue
char (array) sPmodString[16]
float fPmodValue
int nPmodValue
int (array) anPmodValue[16]
u16 uPmodValue
u16 (array) auPmodValue[16]
u8 uchPmodValue
u8 (array) auchPmodBuffer[16]
unsigned int unPmodValue
int * punPmodValue


Definition in file utilities.h.

Function Documentation

u8 checkUartEmpty ( u32  unUartAddress)

Check if either Uart is empty. Either directs to the full UART in the Zynq PS, or a Xilinx UartLite.

Parameters
[in]unUartAddress.32 bit UART address
Return values
Trueif empty (false if not)

Definition at line 89 of file utilities.c.

void clearOLEDBuffer ( u8 *  pauchBuffer)

Clears the OLED display buffer.

Details
This function clears the display buffer by setting all pixels to zero.
Parameters
[in]*pauchBuffer- pointer to an u8 array used for the OLED pixel buffer
Return values
None

Definition at line 633 of file utilities.c.

void delay ( int  nStopValue)

Loop for nStopValue iterations to provide a delay.

Details
It is commonly used with the constant 'ABOUT_ONE_SECOND' defined in maximPMOD.h for setting approximate delays
Parameters
[in]nStopValue- number of iterations to loop
Return values
None

Definition at line 245 of file utilities.c.

void displayOLEDBuffer ( u8 *  pauchBuffer)

Copies the display buffer into the OLED display.

Details
This function writes the the display buffer into the OLED display using the page mode setting.
Note: The Zedboard OLED display contains a Solomon SSD1306 display controller.
Parameters
[in]*pauchBuffer- pointer to an u8 array used for the OLED pixel buffer
Return values
None

Definition at line 650 of file utilities.c.

void flipAndCopyDisplayBuffer ( u8 *  pauchSourceBuffer,
u8 *  pauchDestinationBuffer 
)

Copies the pixels from the source display buffer, into the destination buffer, flipping their location 180 degrees.

Details
The (0,0) pixel location on the OLED display is in the bottom right corner. This function flips the display so that the (0,0) is in the top left corner and (131,31) is in the bottom right.
Parameters
[in]*pauchSourceBuffer- pointer to an u8 buffer used as the source display buffer
[in]*pauchDestinationBuffer- pointer to an u8 buffer used as the destination display buffer
Return values
None

Definition at line 804 of file utilities.c.

int GetLine ( char *  sInputString,
unsigned int  unMaxSize 
)

Retrieve a line of characters from the default Hyperterminal UART (DEFAULT_HYPERTERMINAL_UART).

Details
Maximum number of characters can be specified. Function will timeout after 10 seconds.
Parameters
[in]sInputString- pointer to buffer for input string
[in]unMaxSize- maximum number of characters to input
Return values
TRUEif operation succeeded

Definition at line 445 of file utilities.c.

u8 getUartByte ( u32  nUartAddress)

Get a byte from either the full UART in the Zynq PS, or a Xilinx UartLite.

Parameters
[in]unUartAddress.32 bit UART address
Return values
Returnsthe next byte from the Uart Rx FIFO

Definition at line 123 of file utilities.c.

void initializeOLED ( u8 *  pFont)

Initializes the OLED display.

Details
This function initializes the OLED display and the global data structure that holds the OLED display buffer and font.
Parameters
[in]*pFont- pointer to an u8 array containing the ASCII display font
Return values
None

Definition at line 504 of file utilities.c.

void led_knight_rider ( XGpio *  pLED_GPIO,
int  nNumberOfTimes 
)

Blink a row of LEDs nNumberOfTimes times.

Details
The Digilent NEXYS-3 and Zedboard have 8 green LEDs located above the toggle switches. This function blinks them back/forth (a bit like the KITT car from Knight Rider)
Parameters
[in]*pLED_GPIO- address of the GPIO peripheral driving the LEDs in the memory map
Return values
None

Definition at line 266 of file utilities.c.

void max_configure_PMOD_port ( u8  uchPmodPortA,
u8  uchPmodPortB,
u8  uchPmodPortC,
u8  uchPmodPortD 
)

Configure driving peripherals on each Pmod port.

Details
The Maxim HDL hardware design includes a multiplexer on each PMOD port to allow I2C, SPI, GPIO, and UART functionality to be selected on each port. The standard configuration is (PortA = I2C, PortB = SPI, PortC = GPIO, PortD = UART) This function is used to set the standard configuration in the main() function, as well as to optionally change the port config. The 2-bit number used to define the port configuration is encoded as follows:
00=UART, 01=SPI, 10=GPIO and 11=I2C
Parameters
[in]uchPmodPortA- 2-bit number to define configuration for Pmod port A
[in]uchPmodPortB- 2-bit number to define configuration for Pmod port B
[in]uchPmodPortC- 2-bit number to define configuration for Pmod port C
[in]uchPmodPortD- 2-bit number to define configuration for Pmod port D
Return values
TRUEif operation succeeded

Definition at line 325 of file utilities.c.

void max_set_PMOD_port ( int  nPortNumber,
u8  uchPortType 
)

Configure driving peripherals on each Pmod port.

Details
The Maxim HDL hardware design includes a multiplexer on each PMOD port to allow I2C, SPI, GPIO, and UART functionality to be selected on each port.

This function should be called any time a new PMOD type is plugged into a PMOD. Valid settings for uchPortType follow:
PMOD_PORT_TYPE_UART, PMOD_PORT_TYPE_SPI, PMOD_PORT_TYPE_GPIO, PMOD_PORT_TYPE_I2C

Parameters
[in]nPortNumber- integer number of the port to set (0=A, 1=B, 2=C, 3=D)
[in]uchPortType- u8 number to set type of PMOD port

Definition at line 301 of file utilities.c.

int number_raised_to_power ( int  nBase,
int  nExponent 
)

Raise nBase to the nExponent power (operates with integers only).

Details
Many applications will not have math.h included due to limited memory space. This is a simple functions to implement (nBase ^ nExponent)
Parameters
[in]nBase- base
[in]nExponent- exponent
Return values
Base^Exponent

Definition at line 361 of file utilities.c.

void print_asterisks ( int  nQuantity)

Print nQuantity of asterisks to the default Hyperterminal UART.

Parameters
[in]nQuantity- number of asterisks to print
Return values
None

Definition at line 143 of file utilities.c.

void printfToBufferOLED ( int  x,
int  y,
char *  chString 
)

Printf-like function to copy an ASCII string into the OLED display buffer.

Details
This function copies a pre-formatted ASCII string into the OLED display buffer, but does not take any action to display the buffer
Parameters
[in]x- The starting position of string within the 16x4 character display
[in]y- The starting position of string within the 16x4 character display
[in]*chString- pointer to an null terminated character string. Should be generated with sprintf (or similar).
Return values
None

Definition at line 745 of file utilities.c.

void printfToOLED ( int  x,
int  y,
char *  chString 
)

Printf-like function to copy an ASCII string into the OLED display buffer.

Details
This function copies a pre-formatted ASCII string into the OLED display buffer, flips/rotates the display pixels, and then sends the buffer to the OLED display
Parameters
[in]x- The starting position of string within the 16x4 character display
[in]y- The starting position of string within the 16x4 character display
[in]*chString- pointer to an null terminated character string. Should be generated with sprintf (or similar).
Return values
None

Definition at line 785 of file utilities.c.

void putCharOLED ( int  x,
int  y,
char  chCharacter 
)

Places a single ASCII character into the OLED display buffer.

Details
This function copies an ASCII character from the font table into the OLED display buffer (configured as a 16x4 character display).
Parameters
[in]x- The x position of the character location
[in]y- The y position of the character location
[in]chCharacter- ASCII character to be printed (ex: 0x41 = 'A')
Return values
None

Definition at line 713 of file utilities.c.

int receive_byte_with_timeout ( u32  unUartAddress,
int  nTimeoutInTenthsOfSeconds,
u8 *  uchRxData 
)

Receive a byte from the UART located at *pUartAddress.

Parameters
[in]unUartAddress- address of the UART peripheral in the memory map
[in]nTimeoutInTenthsOfSeconds- amount of time to allow before TIMEOUT
[out]*uchRxData- received data is stored at uchRxData
Return values
TRUEif operation succeeded

Definition at line 389 of file utilities.c.

void sendOLEDSPI ( u8  uchDataToWrite)

Bit bang routine for Zedboard SPI OLED interface.

Details
This function sends an (unsigned) byte (msb first) to the OLED SPI port
Parameters
[in]uchDataToWrite- u8 value to be written to OLED SPI
Return values
None

Definition at line 472 of file utilities.c.

void sendUartByte ( u32  unUartAddress,
u8  uchByte 
)

Send a byte to the UART. Either directs to the full UART in the Zynq PS, or a Xilinx UartLite.

Parameters
[in]unUartAddress.32 bit UART address
[in]uchByte.The byte to be sent to the UART
Return values
None

Definition at line 70 of file utilities.c.

int SpiRW ( u32  unPeripheralAddressSPI,
unsigned int  unCPHA,
unsigned int  unCPOL,
u8 *  auchWriteBuf,
u8 *  auchReadBuf,
int  unNumBytes,
u8  uchCsActiveHigh,
u32  unSpiSS 
)

Perform a SPI read or write.

Details
This function provides a combination SPI Read and Write to the chosen SPI port in the design CPHA and CPOL can be set to 0 or 1 Pointers are provided to u8 buffers containing the data to be written and received Data in the auchWriteBuf will be clocked out (MSB first) onto the MOSI pin Data from the MISO pin will be placed into the auchReadBuf uchCsActiveHigh==TRUE allows SS configurations to be used uchCsActiveHigh==FALSE allows SS# configurations to be used
Parameters
[in]unPeripheralAddressSPI-
[in]unCPHA- phase of SCK (edge to trigger on). 0=Leading edge, 1=Trailing edge
[in]unCPOL- polarity of SCK. 0=Active high, 1=Active low
[in]auchWriteBuf- pointer to write data buffer
[in]auchReadBuf- pointer to read data buffer
[in]unNumBytes- number of bytes to transfer
[in]uchCsActiveHigh- polarity of slave select 0=active low, 1=active high
[in]unSpiSS- one-hot 32-bit slave select register value. 0x1 = MAX15500, 0x2= MAX5316.
Return values
Alwaysreturns 0

Definition at line 157 of file utilities.c.