SPI Programming Manual (G06.24+, H06.03+, J06.03+)

SPI Programming Examples
SPI Programming Manual427506-006
E-38
Example E-10: A Simple SPI Requester in C
/*
*========================================================================
* Proc : get_string =
* Function : This procedure will prompt the home term for the function =
* and the string data on which to perform the function. =
*========================================================================
*/
void get_string (char* p_buffer, short* p_count_read)
{
short l_work_to_do;
short l_input;
short l_temp;
l_work_to_do = false;
do
{
printf (" \n");
printf (" 1 - Reverse string,\n");
printf (" 2 - Shift string to upper case, \n");
printf (" 3 - Shift string to lower case, \n");
printf (" 4 - Display SPI messages,\n");
printf (" 5 - Don’t display SPI messages, \n");
printf (" 6 - Exit\n");
printf ("Enter command: \n");
l_input = getchar();
if (l_input == EOF) /* CTL-Y entered */
{
STOP(process_id); /* Stop the server. */
STOP();
}
/* Now eat all the characters upto and including the ENTER. */
while ((l_temp = getchar()) != '\n') {}
spi_command = 0;
switch (l_input)
{
case '3':
++spi_command;
case '2':
++spi_command;
case '1':
++spi_command;
printf (" \n");
printf ("Enter string: \n");
gets (p_buffer);
*p_count_read = strlen(p_buffer);
if (p_count_read == 0) /* no input entered */
{
STOP(process_id); /* Stop the server. */
STOP();
}
l_work_to_do = true;
break;
Example E-10. C File: A Simple SPI Requester (page 2 of 8)