//***************************************************************************** -1-

Size: px
Start display at page:

Download "//***************************************************************************** -1-"

Transcription

1 ***************************************************************************** uartstdio.c - Utility driver to provide simple UART console functions. Copyright (c) Texas Instruments Incorporated. All rights reserved. Software License Agreement Texas Instruments (TI) is supplying this software for use solely and exclusively on TI's microcontroller products. The software is owned by TI and/or its suppliers, and is protected under applicable copyright laws. You may not combine this software with "viral" open-source software in order to form a larger program. THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS. NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. This is part of revision 8049 of the Stellaris Firmware Development Package. ***************************************************************************** #include <stdarg.h> #include "inc/hw_ints.h" #include "inc/hw_memmap.h" #include "inc/hw_types.h" #include "inc/hw_uart.h" #include "driverlib/debug.h" #include "driverlib/interrupt.h" #include "driverlib/rom.h" #include "driverlib/rom_map.h" #include "driverlib/sysctl.h" #include "driverlib/uart.h" #include "utils/uartstdio.h" *****************************************************************************! \addtogroup ***************************************************************************** ***************************************************************************** If buffered mode is defined, set aside RX and TX buffers and read/write pointers to control them. ***************************************************************************** #ifdef UART_BUFFERED ***************************************************************************** -1-

2 This global controls whether or not we are echoing characters back to the transmitter. By default, echo is enabled but if using this module as a convenient method of implementing a buffered serial interface over which you will be running an application protocol, you are likely to want to disable echo by calling UARTEchoSet(false). ***************************************************************************** static tboolean g_bdisableecho; ***************************************************************************** Output ring buffer. Buffer is full if g_uluarttxreadindex is one ahead of g_uluarttxwriteindex. Buffer is empty if the two indices are the same. ***************************************************************************** static unsigned char g_pcuarttxbuffer[uart_tx_buffer_size]; static volatile unsigned long g_uluarttxwriteindex = 0; static volatile unsigned long g_uluarttxreadindex = 0; ***************************************************************************** Input ring buffer. Buffer is full if g_uluarttxreadindex is one ahead of g_uluarttxwriteindex. Buffer is empty if the two indices are the same. ***************************************************************************** static unsigned char g_pcuartrxbuffer[uart_rx_buffer_size]; static volatile unsigned long g_uluartrxwriteindex = 0; static volatile unsigned long g_uluartrxreadindex = 0; ***************************************************************************** Macros to determine number of free and used bytes in the transmit buffer. ***************************************************************************** #define TX_BUFFER_USED (GetBufferCount(&g_ulUARTTxReadIndex, \ &g_uluarttxwriteindex, \ UART_TX_BUFFER_SIZE)) #define TX_BUFFER_FREE (UART_TX_BUFFER_SIZE - TX_BUFFER_USED) #define TX_BUFFER_EMPTY (IsBufferEmpty(&g_ulUARTTxReadIndex, \ &g_uluarttxwriteindex)) #define TX_BUFFER_FULL (IsBufferFull(&g_ulUARTTxReadIndex, \ &g_uluarttxwriteindex, \ UART_TX_BUFFER_SIZE)) #define ADVANCE_TX_BUFFER_INDEX(Index) \ (Index) = ((Index) + 1) % UART_TX_BUFFER_SIZE ***************************************************************************** Macros to determine number of free and used bytes in the receive buffer. ***************************************************************************** #define RX_BUFFER_USED (GetBufferCount(&g_ulUARTRxReadIndex, \ -2-

3 &g_uluartrxwriteindex, \ UART_RX_BUFFER_SIZE)) #define RX_BUFFER_FREE (UART_RX_BUFFER_SIZE - RX_BUFFER_USED) #define RX_BUFFER_EMPTY (IsBufferEmpty(&g_ulUARTRxReadIndex, \ &g_uluartrxwriteindex)) #define RX_BUFFER_FULL (IsBufferFull(&g_ulUARTRxReadIndex, \ &g_uluartrxwriteindex, \ UART_RX_BUFFER_SIZE)) #define ADVANCE_RX_BUFFER_INDEX(Index) \ (Index) = ((Index) + 1) % UART_RX_BUFFER_SIZE ***************************************************************************** The base address of the chosen UART. ***************************************************************************** static unsigned long g_ulbase = 0; ***************************************************************************** A mapping from an integer between 0 and 15 to its ASCII character equivalent. ***************************************************************************** static const char * const g_pchex = " abcdef"; ***************************************************************************** The list of possible base addresses for the console UART. ***************************************************************************** static const unsigned long g_uluartbase[3] = UART0_BASE, UART1_BASE, UART2_BASE ; #ifdef UART_BUFFERED ***************************************************************************** The list of possible interrupts for the console UART. ***************************************************************************** static const unsigned long g_uluartint[3] = INT_UART0, INT_UART1, INT_UART2 ; ***************************************************************************** The port number in use. ***************************************************************************** -3-

4 static unsigned long g_ulportnum; ***************************************************************************** The list of UART peripherals. ***************************************************************************** static const unsigned long g_uluartperiph[3] = SYSCTL_PERIPH_UART0, SYSCTL_PERIPH_UART1, SYSCTL_PERIPH_UART2 ; *****************************************************************************! Determines whether the ring buffer whose pointers and size are provided! is full or not.!! \param pulread points to the read index for the buffer.! \param pulwrite points to the write index for the buffer.! \param ulsize is the size of the buffer in bytes.!! This function is used to determine whether or not a given ring buffer is! full. The structure of the code is specifically to ensure that we do not! see warnings from the compiler related to the order of volatile accesses! being undefined.!! \return Returns \b true if the buffer is full or \b false otherwise. ***************************************************************************** #ifdef UART_BUFFERED static tboolean IsBufferFull(volatile unsigned long *pulread, volatile unsigned long *pulwrite, unsigned long ulsize) unsigned long ulwrite; unsigned long ulread; ulwrite = *pulwrite; ulread = *pulread; return((((ulwrite + 1) % ulsize) == ulread)? true : false); *****************************************************************************! Determines whether the ring buffer whose pointers and size are provided! is empty or not.!! \param pulread points to the read index for the buffer.! \param pulwrite points to the write index for the buffer.! -4-

5 ! This function is used to determine whether or not a given ring buffer is! empty. The structure of the code is specifically to ensure that we do not! see warnings from the compiler related to the order of volatile accesses! being undefined.!! \return Returns \b true if the buffer is empty or \b false otherwise. ***************************************************************************** #ifdef UART_BUFFERED static tboolean IsBufferEmpty(volatile unsigned long *pulread, volatile unsigned long *pulwrite) unsigned long ulwrite; unsigned long ulread; ulwrite = *pulwrite; ulread = *pulread; return((ulwrite == ulread)? true : false); *****************************************************************************! Determines the number of bytes of data contained in a ring buffer.!! \param pulread points to the read index for the buffer.! \param pulwrite points to the write index for the buffer.! \param ulsize is the size of the buffer in bytes.!! This function is used to determine how many bytes of data a given ring! buffer currently contains. The structure of the code is specifically to! ensure that we do not see warnings from the compiler related to the order! of volatile accesses being undefined.!! \return Returns the number of bytes of data currently in the buffer. ***************************************************************************** #ifdef UART_BUFFERED static unsigned long GetBufferCount(volatile unsigned long *pulread, volatile unsigned long *pulwrite, unsigned long ulsize) unsigned long ulwrite; unsigned long ulread; ulwrite = *pulwrite; ulread = *pulread; return((ulwrite >= ulread)? (ulwrite - ulread) : (ulsize - (ulread - ulwrite))); -5-

6 ***************************************************************************** Take as many bytes from the transmit buffer as we have space for and move them into the UART transmit FIFO. ***************************************************************************** #ifdef UART_BUFFERED static void UARTPrimeTransmit(unsigned long ulbase) Do we have any data to transmit? if(!tx_buffer_empty) Disable the UART interrupt. If we don't do this there is a race condition which can cause the read index to be corrupted. MAP_IntDisable(g_ulUARTInt[g_ulPortNum]); Yes - take some characters out of the transmit buffer and feed them to the UART transmit FIFO. while(map_uartspaceavail(ulbase) &&!TX_BUFFER_EMPTY) MAP_UARTCharPutNonBlocking(ulBase, g_pcuarttxbuffer[g_uluarttxreadindex]); ADVANCE_TX_BUFFER_INDEX(g_ulUARTTxReadIndex); Reenable the UART interrupt. MAP_IntEnable(g_ulUARTInt[g_ulPortNum]); *****************************************************************************! Initializes the UART console.!! \param ulportnum is the number of UART port to use for the serial console! (0-2)!! This function will initialize the specified serial port to be used as a! serial console. The serial parameters will be set to , 8-N-1.! An application wishing to use a different baud rate may call! UARTStdioInitExpClk() instead of this function. -6-

7 !! This function or UARTStdioInitExpClk() must be called prior to using any! of the other UART console functions: UARTprintf() or UARTgets(). In order! for this function to work correctly, SysCtlClockSet() must be called prior! to calling this function.!! It is assumed that the caller has previously configured the relevant UART! pins for operation as a UART rather than as GPIOs.!! \return None. ***************************************************************************** void UARTStdioInit(unsigned long ulportnum) Pass this call on to the version of the function allowing the baud rate to be specified. UARTStdioInitExpClk(ulPortNum, ); *****************************************************************************! Initializes the UART console and allows the baud rate to be selected.!! \param ulportnum is the number of UART port to use for the serial console! (0-2)! \param ulbaud is the bit rate that the UART is to be configured to use.!! This function will initialize the specified serial port to be used as a! serial console. The serial parameters will be set to 8-N-1 and the bit! rate set according to the value of the \e ulbaud parameter.!! This function or UARTStdioInit() must be called prior to using any of the! other UART console functions: UARTprintf() or UARTgets(). In order for! this function to work correctly, SysCtlClockSet() must be called prior to! calling this function. An application wishing to use 115,200 baud may call! UARTStdioInit() instead of this function but should not call both! functions.!! It is assumed that the caller has previously configured the relevant UART! pins for operation as a UART rather than as GPIOs.!! \return None. ***************************************************************************** void UARTStdioInitExpClk(unsigned long ulportnum, unsigned long ulbaud) Check the arguments. -7-

8 ASSERT((ulPortNum == 0) (ulportnum == 1) (ulportnum == 2)); #ifdef UART_BUFFERED In buffered mode, we only allow a single instance to be opened. ASSERT(g_ulBase == 0); Check to make sure the UART peripheral is present. if(!map_sysctlperipheralpresent(g_uluartperiph[ulportnum])) return; Select the base address of the UART. g_ulbase = g_uluartbase[ulportnum]; Enable the UART peripheral for use. MAP_SysCtlPeripheralEnable(g_ulUARTPeriph[ulPortNum]); Configure the UART for , n, 8, 1 MAP_UARTConfigSetExpClk(g_ulBase, MAP_SysCtlClockGet(), ulbaud, (UART_CONFIG_PAR_NONE UART_CONFIG_STOP_ONE UART_CONFIG_WLEN_8)); #ifdef UART_BUFFERED Set the UART to interrupt whenever the TX FIFO is almost empty or when any character is received. MAP_UARTFIFOLevelSet(g_ulBase, UART_FIFO_TX1_8, UART_FIFO_RX1_8); Flush both the buffers. UARTFlushRx(); UARTFlushTx(true); Remember which interrupt we are dealing with. g_ulportnum = ulportnum; -8-

9 We are configured for buffered output so enable the master interrupt for this UART and the receive interrupts. We don't actually enable the transmit interrupt in the UART itself until some data has been placed in the transmit buffer. MAP_UARTIntDisable(g_ulBase, 0xFFFFFFFF); MAP_UARTIntEnable(g_ulBase, UART_INT_RX UART_INT_RT); MAP_IntEnable(g_ulUARTInt[ulPortNum]); Enable the UART operation. MAP_UARTEnable(g_ulBase); *****************************************************************************! Writes a string of characters to the UART output.!! \param pcbuf points to a buffer containing the string to transmit.! \param ullen is the length of the string to transmit.!! This function will transmit the string to the UART output. The number of! characters transmitted is determined by the \e ullen parameter. This! function does no interpretation or translation of any characters. Since! the output is sent to a UART, any LF (/n) characters encountered will be! replaced with a CRLF pair.!! Besides using the \e ullen parameter to stop transmitting the string, if a! null character (0) is encountered, then no more characters will be! transmitted and the function will return.!! In non-buffered mode, this function is blocking and will not return until! all the characters have been written to the output FIFO. In buffered mode,! the characters are written to the UART transmit buffer and the call returns! immediately. If insufficient space remains in the transmit buffer,! additional characters are discarded.!! \return Returns the count of characters written. ***************************************************************************** int UARTwrite(const char *pcbuf, unsigned long ullen) #ifdef UART_BUFFERED unsigned int uidx; Check for valid arguments. ASSERT(pcBuf!= 0); -9-

10 ASSERT(g_ulBase!= 0); Send the characters for(uidx = 0; uidx < ullen; uidx++) If the character to the UART is \n, then add a \r before it so that \n is translated to \n\r in the output. if(pcbuf[uidx] == '\n') if(!tx_buffer_full) g_pcuarttxbuffer[g_uluarttxwriteindex] = '\r'; ADVANCE_TX_BUFFER_INDEX(g_ulUARTTxWriteIndex); else Buffer is full - discard remaining characters and return. break; Send the character to the UART output. if(!tx_buffer_full) g_pcuarttxbuffer[g_uluarttxwriteindex] = pcbuf[uidx]; ADVANCE_TX_BUFFER_INDEX(g_ulUARTTxWriteIndex); else Buffer is full - discard remaining characters and return. break; If we have anything in the buffer, make sure that the UART is set up to transmit it. if(!tx_buffer_empty) UARTPrimeTransmit(g_ulBase); MAP_UARTIntEnable(g_ulBase, UART_INT_TX); -10-

11 Return the number of characters written. return(uidx); #else unsigned int uidx; Check for valid UART base address, and valid arguments. ASSERT(g_ulBase!= 0); ASSERT(pcBuf!= 0); Send the characters for(uidx = 0; uidx < ullen; uidx++) If the character to the UART is \n, then add a \r before it so that \n is translated to \n\r in the output. if(pcbuf[uidx] == '\n') MAP_UARTCharPut(g_ulBase, '\r'); Send the character to the UART output. MAP_UARTCharPut(g_ulBase, pcbuf[uidx]); Return the number of characters written. return(uidx); *****************************************************************************! A simple UART based get string function, with some line processing.!! \param pcbuf points to a buffer for the incoming string from the UART.! \param ullen is the length of the buffer for storage of the string,! including the trailing 0.!! This function will receive a string from the UART input and store the! characters in the buffer pointed to by \e pcbuf. The characters will! continue to be stored until a termination character is received. The! termination characters are CR, LF, or ESC. A CRLF pair is treated as a -11-

12 ! single termination character. The termination characters are not stored in! the string. The string will be terminated with a 0 and the function will! return.!! In both buffered and unbuffered modes, this function will block until! a termination character is received. If non-blocking operation is required! in buffered mode, a call to UARTPeek() may be made to determine whether! a termination character already exists in the receive buffer prior to! calling UARTgets().!! Since the string will be null terminated, the user must ensure that the! buffer is sized to allow for the additional null character.!! \return Returns the count of characters that were stored, not including! the trailing 0. ***************************************************************************** int UARTgets(char *pcbuf, unsigned long ullen) #ifdef UART_BUFFERED unsigned long ulcount = 0; char cchar; Check the arguments. ASSERT(pcBuf!= 0); ASSERT(ulLen!= 0); ASSERT(g_ulBase!= 0); Adjust the length back by 1 to leave space for the trailing null terminator. ullen--; Process characters until a newline is received. while(1) Read the next character from the receive buffer. if(!rx_buffer_empty) cchar = g_pcuartrxbuffer[g_uluartrxreadindex]; ADVANCE_RX_BUFFER_INDEX(g_ulUARTRxReadIndex); See if a newline or escape character was received. -12-

13 if((cchar == '\r') (cchar == '\n') (cchar == 0x1b)) Stop processing the input and end the line. break; Process the received character as long as we are not at the end of the buffer. If the end of the buffer has been reached then all additional characters are ignored until a newline is received. if(ulcount < ullen) Store the character in the caller supplied buffer. pcbuf[ulcount] = cchar; Increment the count of characters received. ulcount++; Add a null termination to the string. pcbuf[ulcount] = 0; Return the count of chars in the buffer, not counting the trailing 0. return(ulcount); #else unsigned long ulcount = 0; char cchar; static char blastwascr = 0; Check the arguments. ASSERT(pcBuf!= 0); ASSERT(ulLen!= 0); ASSERT(g_ulBase!= 0); Adjust the length back by 1 to leave space for the trailing null terminator. -13-

14 ullen--; Process characters until a newline is received. while(1) Read the next character from the console. cchar = MAP_UARTCharGet(g_ulBase); See if the backspace key was pressed. if(cchar == '\b') If there are any characters already in the buffer, then delete the last. if(ulcount) Rub out the previous character. UARTwrite("\b \b", 3); Decrement the number of characters in the buffer. ulcount--; Skip ahead to read the next character. continue; If this character is LF and last was CR, then just gobble up the character because the EOL processing was taken care of with the CR. if((cchar == '\n') && blastwascr) blastwascr = 0; continue; See if a newline or escape character was received. -14-

15 if((cchar == '\r') (cchar == '\n') (cchar == 0x1b)) If the character is a CR, then it may be followed by a LF which should be paired with the CR. So remember that a CR was received. if(cchar == '\r') blastwascr = 1; Stop processing the input and end the line. break; Process the received character as long as we are not at the end of the buffer. If the end of the buffer has been reached then all additional characters are ignored until a newline is received. if(ulcount < ullen) Store the character in the caller supplied buffer. pcbuf[ulcount] = cchar; Increment the count of characters received. ulcount++; Reflect the character back to the user. MAP_UARTCharPut(g_ulBase, cchar); Add a null termination to the string. pcbuf[ulcount] = 0; Send a CRLF pair to the terminal to end the line. UARTwrite("\r\n", 2); -15-

16 Return the count of chars in the buffer, not counting the trailing 0. return(ulcount); *****************************************************************************! Read a single character from the UART, blocking if necessary.!! This function will receive a single character from the UART and store it at! the supplied address.!! In both buffered and unbuffered modes, this function will block until a! character is received. If non-blocking operation is required in buffered! mode, a call to UARTRxAvail() may be made to determine whether any! characters are currently available for reading.!! \return Returns the character read. ***************************************************************************** unsigned char UARTgetc(void) #ifdef UART_BUFFERED unsigned char cchar; Wait for a character to be received. while(rx_buffer_empty) Block waiting for a character to be received (if the buffer is currently empty). Read a character from the buffer. cchar = g_pcuartrxbuffer[g_uluartrxreadindex]; ADVANCE_RX_BUFFER_INDEX(g_ulUARTRxReadIndex); Return the character to the caller. return(cchar); #else Block until a character is received by the UART then return it to the caller. -16-

17 return(map_uartcharget(g_ulbase)); *****************************************************************************! A simple UART based printf function supporting \%c, \%d, \%p, \%s, \%u,! \%x, and \%X.!! \param pcstring is the format string.! \param... are the optional arguments, which depend on the contents of the! format string.!! This function is very similar to the C library <tt>fprintf()</tt> function.! All of its output will be sent to the UART. Only the following formatting! characters are supported:!! - \%c to print a character! - \%d to print a decimal value! - \%s to print a string! - \%u to print an unsigned decimal value! - \%x to print a hexadecimal value using lower case letters! - \%X to print a hexadecimal value using lower case letters (not upper case! letters as would typically be used)! - \%p to print a pointer as a hexadecimal value! - \%\% to print out a \% character!! For \%s, \%d, \%u, \%p, \%x, and \%X, an optional number may reside! between the \% and the format character, which specifies the minimum number! of characters to use for that value; if preceded by a 0 then the extra! characters will be filled with zeros instead of spaces. For example,! ``\%8d'' will use eight characters to print the decimal value with spaces! added to reach eight; ``\%08d'' will use eight characters as well but will! add zeroes instead of spaces.!! The type of the arguments after \e pcstring must match the requirements of! the format string. For example, if an integer was passed where a string! was expected, an error of some kind will most likely occur.!! \return None. ***************************************************************************** void UARTprintf(const char *pcstring,...) unsigned long ulidx, ulvalue, ulpos, ulcount, ulbase, ulneg; char *pcstr, pcbuf[16], cfill; va_list vaargp; Check the arguments. -17-

18 ASSERT(pcString!= 0); Start the varargs processing. va_start(vaargp, pcstring); Loop while there are more characters in the string. while(*pcstring) Find the first non-% character, or the end of the string. for(ulidx = 0; (pcstring[ulidx]!= '%') && (pcstring[ulidx]!= '\0'); ulidx++) Write this portion of the string. UARTwrite(pcString, ulidx); Skip the portion of the string that was written. pcstring += ulidx; See if the next character is a %. if(*pcstring == '%') Skip the %. pcstring++; Set the digit count to zero, and the fill character to space (i.e. to the defaults). ulcount = 0; cfill = ' '; again: It may be necessary to get back here to process more characters. Goto's aren't pretty, but effective. I feel extremely dirty for using not one but two of the beasts. -18-

19 Determine how to handle the next character. switch(*pcstring++) Handle the digit characters. case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': If this is a zero, and it is the first digit, then the fill character is a zero instead of a space. if((pcstring[-1] == '0') && (ulcount == 0)) cfill = '0'; Update the digit count. ulcount *= 10; ulcount += pcstring[-1] - '0'; Get the next character. goto again; Handle the %c command. case 'c': Get the value from the varargs. ulvalue = va_arg(vaargp, unsigned long); Print out the character. -19-

20 UARTwrite((char *)&ulvalue, 1); This command has been handled. break; Handle the %d command. case 'd': Get the value from the varargs. ulvalue = va_arg(vaargp, unsigned long); Reset the buffer position. ulpos = 0; If the value is negative, make it positive and indicate that a minus sign is needed. if((long)ulvalue < 0) Make the value positive. ulvalue = -(long)ulvalue; Indicate that the value is negative. ulneg = 1; else Indicate that the value is positive so that a minus sign isn't inserted. ulneg = 0; Set the base to 10. ulbase = 10; -20-

21 Convert the value to ASCII. goto convert; Handle the %s command. case 's': Get the string pointer from the varargs. pcstr = va_arg(vaargp, char *); Determine the length of the string. for(ulidx = 0; pcstr[ulidx]!= '\0'; ulidx++) Write the string. UARTwrite(pcStr, ulidx); Write any required padding spaces if(ulcount > ulidx) ulcount -= ulidx; while(ulcount--) UARTwrite(" ", 1); This command has been handled. break; Handle the %u command. case 'u': Get the value from the varargs. -21-

22 ulvalue = va_arg(vaargp, unsigned long); Reset the buffer position. ulpos = 0; Set the base to 10. ulbase = 10; Indicate that the value is positive so that a minus sign isn't inserted. ulneg = 0; Convert the value to ASCII. goto convert; Handle the %x and %X commands. Note that they are treated identically; i.e. %X will use lower case letters for a-f instead of the upper case letters is should use. We also alias %p to %x. case 'x': case 'X': case 'p': Get the value from the varargs. ulvalue = va_arg(vaargp, unsigned long); Reset the buffer position. ulpos = 0; Set the base to 16. ulbase = 16; Indicate that the value is positive so that a minus sign isn't inserted. -22-

23 ulneg = 0; convert: Determine the number of digits in the string version of the value. for(ulidx = 1; (((ulidx * ulbase) <= ulvalue) && (((ulidx * ulbase) / ulbase) == ulidx)); ulidx *= ulbase, ulcount--) If the value is negative, reduce the count of padding characters needed. if(ulneg) ulcount--; If the value is negative and the value is padded with zeros, then place the minus sign before the padding. if(ulneg && (cfill == '0')) Place the minus sign in the output buffer. pcbuf[ulpos++] = '-'; The minus sign has been placed, so turn off the negative flag. ulneg = 0; Provide additional padding at the beginning of the string conversion if needed. if((ulcount > 1) && (ulcount < 16)) for(ulcount--; ulcount; ulcount--) pcbuf[ulpos++] = cfill; -23-

24 If the value is negative, then place the minus sign before the number. if(ulneg) Place the minus sign in the output buffer. pcbuf[ulpos++] = '-'; Convert the value into a string. for(; ulidx; ulidx /= ulbase) pcbuf[ulpos++] = g_pchex[(ulvalue / ulidx) % ulbase]; Write the string. UARTwrite(pcBuf, ulpos); This command has been handled. break; Handle the %% command. case '%': Simply write a single %. UARTwrite(pcString - 1, 1); This command has been handled. break; Handle all other commands. default: -24-

25 Indicate an error. UARTwrite("ERROR", 5); This command has been handled. break; End the varargs processing. va_end(vaargp); *****************************************************************************! Returns the number of bytes available in the receive buffer.!! This function, available only when the module is built to operate in! buffered mode using \b UART_BUFFERED, may be used to determine the number! of bytes of data currently available in the receive buffer.!! \return Returns the number of available bytes. ***************************************************************************** #if defined(uart_buffered) defined(doxygen) int UARTRxBytesAvail(void) return(rx_buffer_used); #if defined(uart_buffered) defined(doxygen) *****************************************************************************! Returns the number of bytes free in the transmit buffer.!! This function, available only when the module is built to operate in! buffered mode using \b UART_BUFFERED, may be used to determine the amount! of space currently available in the transmit buffer.!! \return Returns the number of free bytes. ***************************************************************************** int UARTTxBytesFree(void) -25-

26 return(tx_buffer_free); *****************************************************************************! Looks ahead in the receive buffer for a particular character.!! \param ucchar is the character that is to be searched for.!! This function, available only when the module is built to operate in! buffered mode using \b UART_BUFFERED, may be used to look ahead in the! receive buffer for a particular character and report its position if found.! It is typically used to determine whether a complete line of user input is! available, in which case ucchar should be set to CR ('\\r') which is used! as the line end marker in the receive buffer.!! \return Returns -1 to indicate that the requested character does not exist! in the receive buffer. Returns a non-negative number if the character was! found in which case the value represents the position of the first instance! of \e ucchar relative to the receive buffer read pointer. ***************************************************************************** #if defined(uart_buffered) defined(doxygen) int UARTPeek(unsigned char ucchar) int icount; int iavail; unsigned long ulreadindex; How many characters are there in the receive buffer? iavail = (int)rx_buffer_used; ulreadindex = g_uluartrxreadindex; Check all the unread characters looking for the one passed. for(icount = 0; icount < iavail; icount++) if(g_pcuartrxbuffer[ulreadindex] == ucchar) We found it so return the index return(icount); else -26-

27 This one didn't match so move on to the next character. ADVANCE_RX_BUFFER_INDEX(ulReadIndex); If we drop out of the loop, we didn't find the character in the receive buffer. return(-1); *****************************************************************************! Flushes the receive buffer.!! This function, available only when the module is built to operate in! buffered mode using \b UART_BUFFERED, may be used to discard any data! received from the UART but not yet read using UARTgets().!! \return None. ***************************************************************************** #if defined(uart_buffered) defined(doxygen) void UARTFlushRx(void) unsigned long ulint; Temporarily turn off interrupts. ulint = MAP_IntMasterDisable(); Flush the receive buffer. g_uluartrxreadindex = 0; g_uluartrxwriteindex = 0; If interrupts were enabled when we turned them off, turn them back on again. if(!ulint) MAP_IntMasterEnable(); -27-

28 *****************************************************************************! Flushes the transmit buffer.!! \param bdiscard indicates whether any remaining data in the buffer should! be discarded (\b true) or transmitted (\b false).!! This function, available only when the module is built to operate in! buffered mode using \b UART_BUFFERED, may be used to flush the transmit! buffer, either discarding or transmitting any data received via calls to! UARTprintf() that is waiting to be transmitted. On return, the transmit! buffer will be empty.!! \return None. ***************************************************************************** #if defined(uart_buffered) defined(doxygen) void UARTFlushTx(tBoolean bdiscard) unsigned long ulint; Should the remaining data be discarded or transmitted? if(bdiscard) The remaining data should be discarded, so temporarily turn off interrupts. ulint = MAP_IntMasterDisable(); Flush the transmit buffer. g_uluarttxreadindex = 0; g_uluarttxwriteindex = 0; If interrupts were enabled when we turned them off, turn them back on again. if(!ulint) MAP_IntMasterEnable(); else Wait for all remaining data to be transmitted before returning. -28-

29 while(!tx_buffer_empty) *****************************************************************************! Enables or disables echoing of received characters to the transmitter.!! \param benable must be set to \b true to enable echo or \b false to! disable it.!! This function, available only when the module is built to operate in! buffered mode using \b UART_BUFFERED, may be used to control whether or not! received characters are automatically echoed back to the transmitter. By! default, echo is enabled and this is typically the desired behavior if! the module is being used to support a serial command line. In applications! where this module is being used to provide a convenient, buffered serial! interface over which application-specific binary protocols are being run,! however, echo may be undesirable and this function can be used to disable! it.!! \return None. ***************************************************************************** #if defined(uart_buffered) defined(doxygen) void UARTEchoSet(tBoolean benable) g_bdisableecho =!benable; *****************************************************************************! Handles UART interrupts.!! This function handles interrupts from the UART. It will copy data from the! transmit buffer to the UART transmit FIFO if space is available, and it! will copy data from the UART receive FIFO to the receive buffer if data is! available.!! \return None. ***************************************************************************** #if defined(uart_buffered) defined(doxygen) void UARTStdioIntHandler(void) unsigned long ulints; char cchar; -29-

30 long lchar; static tboolean blastwascr = false; Get and clear the current interrupt source(s) ulints = MAP_UARTIntStatus(g_ulBase, true); MAP_UARTIntClear(g_ulBase, ulints); Are we being interrupted because the TX FIFO has space available? if(ulints & UART_INT_TX) Move as many bytes as we can into the transmit FIFO. UARTPrimeTransmit(g_ulBase); If the output buffer is empty, turn off the transmit interrupt. if(tx_buffer_empty) MAP_UARTIntDisable(g_ulBase, UART_INT_TX); Are we being interrupted due to a received character? if(ulints & (UART_INT_RX UART_INT_RT)) Get all the available characters from the UART. while(map_uartcharsavail(g_ulbase)) Read a character lchar = MAP_UARTCharGetNonBlocking(g_ulBase); cchar = (unsigned char)(lchar & 0xFF); If echo is disabled, we skip the various text filtering operations that would typically be required when supporting a command line. if(!g_bdisableecho) Handle backspace by erasing the last character in the buffer. -30-

31 if(cchar == '\b') If there are any characters already in the buffer, then delete the last. if(!rx_buffer_empty) Rub out the previous character on the users terminal. UARTwrite("\b \b", 3); Decrement the number of characters in the buffer. if(g_uluartrxwriteindex == 0) g_uluartrxwriteindex = UART_RX_BUFFER_SIZE - 1; else g_uluartrxwriteindex--; Skip ahead to read the next character. continue; If this character is LF and last was CR, then just gobble up the character since we already echoed the previous CR and we don't want to store 2 characters in the buffer if we don't need to. if((cchar == '\n') && blastwascr) blastwascr = false; continue; See if a newline or escape character was received. if((cchar == '\r') (cchar == '\n') (cchar == 0x1b)) If the character is a CR, then it may be followed by an LF which should be paired with the CR. So remember that -31-

32 a CR was received. if(cchar == '\r') blastwascr = 1; Regardless of the line termination character received, put a CR in the receive buffer as a marker telling UARTgets() where the line ends. We also send an additional LF to ensure that the local terminal echo receives both CR and LF. cchar = '\r'; UARTwrite("\n", 1); If there is space in the receive buffer, put the character there, otherwise throw it away. if(!rx_buffer_full) Store the new character in the receive buffer g_pcuartrxbuffer[g_uluartrxwriteindex] = (unsigned char)(lchar & 0xFF); ADVANCE_RX_BUFFER_INDEX(g_ulUARTRxWriteIndex); If echo is enabled, write the character to the transmit buffer so that the user gets some immediate feedback. if(!g_bdisableecho) UARTwrite(&cChar, 1); If we wrote anything to the transmit buffer, make sure it actually gets transmitted. UARTPrimeTransmit(g_ulBase); MAP_UARTIntEnable(g_ulBase, UART_INT_TX); -32-

33 ***************************************************************************** Close the Doxygen ***************************************************************************** -33-

UART. Introduction. Agenda

UART. Introduction. Agenda UART Introduction This chapter will introduce you to the capabilities of the Universal Asynchronous Receiver/Transmitter (UART). The lab uses the LaunchPad board and the Stellaris Virtual Serial Port running

More information

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14 C introduction Variables Variables 1 / 14 Contents Variables Data types Variable I/O Variables 2 / 14 Usage Declaration: t y p e i d e n t i f i e r ; Assignment: i d e n t i f i e r = v a l u e ; Definition

More information

Programming I 2 S on the Stellaris Microcontroller

Programming I 2 S on the Stellaris Microcontroller Programming I 2 S on the Stellaris Microcontroller Application Note Ryan Hunt Design Team 6 November 13, 2011 1 Contents Abstract... 3 Keywords... 3 Introduction and Background... 3 Objective... 4 Programming

More information

CS102: Standard I/O. %<flag(s)><width><precision><size>conversion-code

CS102: Standard I/O. %<flag(s)><width><precision><size>conversion-code CS102: Standard I/O Our next topic is standard input and standard output in C. The adjective "standard" when applied to "input" or "output" could be interpreted to mean "default". Typically, standard output

More information

LM3S5732 ROM USER S GUIDE ROM-LM3S5732-UG-461. Copyright Texas Instruments Incorporated

LM3S5732 ROM USER S GUIDE ROM-LM3S5732-UG-461. Copyright Texas Instruments Incorporated LM3S5732 ROM USER S GUIDE ROM-LM3S5732-UG-461 Copyright 2008-2011 Texas Instruments Incorporated Copyright Copyright 2008-2011 Texas Instruments Incorporated. All rights reserved. Stellaris and StellarisWare

More information

DECLARATIONS. Character Set, Keywords, Identifiers, Constants, Variables. Designed by Parul Khurana, LIECA.

DECLARATIONS. Character Set, Keywords, Identifiers, Constants, Variables. Designed by Parul Khurana, LIECA. DECLARATIONS Character Set, Keywords, Identifiers, Constants, Variables Character Set C uses the uppercase letters A to Z. C uses the lowercase letters a to z. C uses digits 0 to 9. C uses certain Special

More information

Arithmetic and Bitwise Operations on Binary Data

Arithmetic and Bitwise Operations on Binary Data Arithmetic and Bitwise Operations on Binary Data CSCI 2400: Computer Architecture ECE 3217: Computer Architecture and Organization Instructor: David Ferry Slides adapted from Bryant & O Hallaron s slides

More information

ITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University

ITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University ITC213: STRUCTURED PROGRAMMING Bhaskar Shrestha National College of Computer Studies Tribhuvan University Lecture 07: Data Input and Output Readings: Chapter 4 Input /Output Operations A program needs

More information

C How to Program, 6/e by Pearson Education, Inc. All Rights Reserved.

C How to Program, 6/e by Pearson Education, Inc. All Rights Reserved. C How to Program, 6/e 1992-2010 by Pearson Education, Inc. An important part of the solution to any problem is the presentation of the results. In this chapter, we discuss in depth the formatting features

More information

LM3S2D93 ROM USER S GUIDE ROM-LM3S2D93-UG-461. Copyright Texas Instruments Incorporated

LM3S2D93 ROM USER S GUIDE ROM-LM3S2D93-UG-461. Copyright Texas Instruments Incorporated LM3S2D93 ROM USER S GUIDE ROM-LM3S2D93-UG-461 Copyright 2008-2011 Texas Instruments Incorporated Copyright Copyright 2008-2011 Texas Instruments Incorporated. All rights reserved. Stellaris and StellarisWare

More information

Goals of C "" The Goals of C (cont.) "" Goals of this Lecture"" The Design of C: A Rational Reconstruction"

Goals of C  The Goals of C (cont.)  Goals of this Lecture The Design of C: A Rational Reconstruction Goals of this Lecture The Design of C: A Rational Reconstruction Help you learn about: The decisions that were available to the designers of C The decisions that were made by the designers of C Why? Learning

More information

Programming in C++ 4. The lexical basis of C++

Programming in C++ 4. The lexical basis of C++ Programming in C++ 4. The lexical basis of C++! Characters and tokens! Permissible characters! Comments & white spaces! Identifiers! Keywords! Constants! Operators! Summary 1 Characters and tokens A C++

More information

Binghamton University. CS-211 Fall Syntax. What the Compiler needs to understand your program

Binghamton University. CS-211 Fall Syntax. What the Compiler needs to understand your program Syntax What the Compiler needs to understand your program 1 Pre-Processing Any line that starts with # is a pre-processor directive Pre-processor consumes that entire line Possibly replacing it with other

More information

Preliminary File System User Manual

Preliminary File System User Manual GHI Electronics, LLC 501 E. Whitcomb Ave. Madison Heights, Michigan 48071 Phone: (248) 397-8856 Fax: (248) 397-8890 www.ghielectronics.com Preliminary File System User Manual Where Hardware Meets Software

More information

CYSE 411/AIT681 Secure Software Engineering Topic #12. Secure Coding: Formatted Output

CYSE 411/AIT681 Secure Software Engineering Topic #12. Secure Coding: Formatted Output CYSE 411/AIT681 Secure Software Engineering Topic #12. Secure Coding: Formatted Output Instructor: Dr. Kun Sun 1 This lecture: [Seacord]: Chapter 6 Readings 2 Secure Coding String management Pointer Subterfuge

More information

2/9/18. CYSE 411/AIT681 Secure Software Engineering. Readings. Secure Coding. This lecture: String management Pointer Subterfuge

2/9/18. CYSE 411/AIT681 Secure Software Engineering. Readings. Secure Coding. This lecture: String management Pointer Subterfuge CYSE 411/AIT681 Secure Software Engineering Topic #12. Secure Coding: Formatted Output Instructor: Dr. Kun Sun 1 This lecture: [Seacord]: Chapter 6 Readings 2 String management Pointer Subterfuge Secure

More information

Version N 2.0. LaurTec. RS232 Terminal. Debugging Embedded Systems. Author : Mauro Laurenti ID: PJ11004-EN. Copyright Mauro Laurenti 1/33

Version N 2.0. LaurTec. RS232 Terminal. Debugging Embedded Systems. Author : Mauro Laurenti ID: PJ11004-EN. Copyright Mauro Laurenti 1/33 Version N 2.0 LaurTec RS232 Terminal Debugging Embedded Systems Author : Mauro Laurenti ID: PJ11004-EN Copyright 2009-2017 Mauro Laurenti 1/33 License Copyright (C) 2009-2017 Author: Mauro Laurenti Web

More information

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types

More information

ME 461 C review Session Fall 2009 S. Keres

ME 461 C review Session Fall 2009 S. Keres ME 461 C review Session Fall 2009 S. Keres DISCLAIMER: These notes are in no way intended to be a complete reference for the C programming material you will need for the class. They are intended to help

More information

Stream Model of I/O. Basic I/O in C

Stream Model of I/O. Basic I/O in C Stream Model of I/O 1 A stream provides a connection between the process that initializes it and an object, such as a file, which may be viewed as a sequence of data. In the simplest view, a stream object

More information

C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee C Language Part 1 (Minor modifications by the instructor) References C for Python Programmers, by Carl Burch, 2011. http://www.toves.org/books/cpy/ The C Programming Language. 2nd ed., Kernighan, Brian,

More information

TI ARM Lab 6 UART (without Interrupt)

TI ARM Lab 6 UART (without Interrupt) TI ARM Lab 6 UART (without Interrupt) National Science Foundation Funded in part, by a grant from the National Science Foundation DUE 1068182 Acknowledgements Developed by Craig Kief, Brian Zufelt, and

More information

LM3S9D81 ROM USER S GUIDE ROM-LM3S9D81-UG-461. Copyright Texas Instruments Incorporated

LM3S9D81 ROM USER S GUIDE ROM-LM3S9D81-UG-461. Copyright Texas Instruments Incorporated LM3S9D81 ROM USER S GUIDE ROM-LM3S9D81-UG-461 Copyright 2008-2011 Texas Instruments Incorporated Copyright Copyright 2008-2011 Texas Instruments Incorporated. All rights reserved. Stellaris and StellarisWare

More information

Unit 4. Input/Output Functions

Unit 4. Input/Output Functions Unit 4 Input/Output Functions Introduction to Input/Output Input refers to accepting data while output refers to presenting data. Normally the data is accepted from keyboard and is outputted onto the screen.

More information

ECE 598 Advanced Operating Systems Lecture 6

ECE 598 Advanced Operating Systems Lecture 6 ECE 598 Advanced Operating Systems Lecture 6 Vince Weaver http://www.eece.maine.edu/~vweaver vincent.weaver@maine.edu 3 February 2015 Announcements Homework #2 will be released shortly Raspberry Pi 2???

More information

1602 SMART LCD DISPLAY MODULE HCMODU0122

1602 SMART LCD DISPLAY MODULE HCMODU0122 62 SMART LCD DISPLAY MODULE HCMODU22 Revision.. DISCLAIMER This document is provided "as is". Hobby Components Ltd makes no warranties, whether express, implied or statutory, including, but not limited

More information

ECE 598 Advanced Operating Systems Lecture 6

ECE 598 Advanced Operating Systems Lecture 6 ECE 598 Advanced Operating Systems Lecture 6 Vince Weaver http://www.eece.maine.edu/~vweaver vincent.weaver@maine.edu 4 February 2016 Homework #2 was due Announcements Homework #3 will be released shortly

More information

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath UNIT - I Introduction to C Programming Introduction to C C was originally developed in the year 1970s by Dennis Ritchie at Bell Laboratories, Inc. C is a general-purpose programming language. It has been

More information

Rule 1-3: Use white space to break a function into paragraphs. Rule 1-5: Avoid very long statements. Use multiple shorter statements instead.

Rule 1-3: Use white space to break a function into paragraphs. Rule 1-5: Avoid very long statements. Use multiple shorter statements instead. Chapter 9: Rules Chapter 1:Style and Program Organization Rule 1-1: Organize programs for readability, just as you would expect an author to organize a book. Rule 1-2: Divide each module up into a public

More information

PICkit Serial DLL (PICkitS.dll) Function Prototypes

PICkit Serial DLL (PICkitS.dll) Function Prototypes Document #: Title: PICkit Serial DLL (PICkitS.dll) Function Prototypes Subtitle: Original Date: July 12, 2007 Description: This document describes the functions available in PICkitS.dll. These functions

More information

CMPT 102 Introduction to Scientific Computer Programming. Input and Output. Your first program

CMPT 102 Introduction to Scientific Computer Programming. Input and Output. Your first program CMPT 102 Introduction to Scientific Computer Programming Input and Output Janice Regan, CMPT 102, Sept. 2006 0 Your first program /* My first C program */ /* make the computer print the string Hello world

More information

Arithmetic and Bitwise Operations on Binary Data

Arithmetic and Bitwise Operations on Binary Data Arithmetic and Bitwise Operations on Binary Data CSCI 224 / ECE 317: Computer Architecture Instructor: Prof. Jason Fritts Slides adapted from Bryant & O Hallaron s slides 1 Boolean Algebra Developed by

More information

C OVERVIEW BASIC C PROGRAM STRUCTURE. C Overview. Basic C Program Structure

C OVERVIEW BASIC C PROGRAM STRUCTURE. C Overview. Basic C Program Structure C Overview Basic C Program Structure C OVERVIEW BASIC C PROGRAM STRUCTURE Goals The function main( )is found in every C program and is where every C program begins speed execution portability C uses braces

More information

A Fast Review of C Essentials Part I

A Fast Review of C Essentials Part I A Fast Review of C Essentials Part I Structural Programming by Z. Cihan TAYSI Outline Program development C Essentials Functions Variables & constants Names Formatting Comments Preprocessor Data types

More information

EDIABAS BEST/2 LANGUAGE DESCRIPTION. VERSION 6b. Electronic Diagnostic Basic System EDIABAS - BEST/2 LANGUAGE DESCRIPTION

EDIABAS BEST/2 LANGUAGE DESCRIPTION. VERSION 6b. Electronic Diagnostic Basic System EDIABAS - BEST/2 LANGUAGE DESCRIPTION EDIABAS Electronic Diagnostic Basic System BEST/2 LANGUAGE DESCRIPTION VERSION 6b Copyright BMW AG, created by Softing AG BEST2SPC.DOC CONTENTS CONTENTS...2 1. INTRODUCTION TO BEST/2...5 2. TEXT CONVENTIONS...6

More information

C OVERVIEW. C Overview. Goals speed portability allow access to features of the architecture speed

C OVERVIEW. C Overview. Goals speed portability allow access to features of the architecture speed C Overview C OVERVIEW Goals speed portability allow access to features of the architecture speed C fast executables allows high-level structure without losing access to machine features many popular languages

More information

PICkit Serial DLL (PICkitS.dll) Function Prototypes

PICkit Serial DLL (PICkitS.dll) Function Prototypes Document #: Title: PICkit Serial DLL (PICkitS.dll) Function Prototypes Subtitle: Original Date: July 12, 2007 Description: This document describes the functions available in PICkitS.dll. These functions

More information

Introduction to C Language

Introduction to C Language Introduction to C Language Instructor: Professor I. Charles Ume ME 6405 Introduction to Mechatronics Fall 2006 Instructor: Professor Charles Ume Introduction to C Language History of C Language In 1972,

More information

LM3S6G11 ROM USER S GUIDE ROM-LM3S6G11-UG-461. Copyright Texas Instruments Incorporated

LM3S6G11 ROM USER S GUIDE ROM-LM3S6G11-UG-461. Copyright Texas Instruments Incorporated LM3S6G11 ROM USER S GUIDE ROM-LM3S6G11-UG-461 Copyright 2008-2011 Texas Instruments Incorporated Copyright Copyright 2008-2011 Texas Instruments Incorporated. All rights reserved. Stellaris and StellarisWare

More information

InfoTag KE28xx Communications for 186 CPU Firmware Version 4

InfoTag KE28xx Communications for 186 CPU Firmware Version 4 InfoTag KE28xx Communications for 186 CPU Firmware Version 4 *KE28xx models include: KE2800, KE2852, KE2853, KE2856 This document applies to printer firmware versions 4.x only. Note that changes made to

More information

Lecture 02 C FUNDAMENTALS

Lecture 02 C FUNDAMENTALS Lecture 02 C FUNDAMENTALS 1 Keywords C Fundamentals auto double int struct break else long switch case enum register typedef char extern return union const float short unsigned continue for signed void

More information

Serial to Ethernet Converter

Serial to Ethernet Converter Serial to Ethernet Converter SOFTWARE REFERENCE MANUAL sw01266-srm-195 Copyright 2007 Luminary Micro, Inc. Legal Disclaimers and Trademark Information INFORMATION IN THIS DOCUMENT IS PROVIDED IN CONNECTION

More information

The Design of C: A Rational Reconstruction (cont.)

The Design of C: A Rational Reconstruction (cont.) The Design of C: A Rational Reconstruction (cont.) 1 Goals of this Lecture Recall from last lecture Help you learn about: The decisions that were available to the designers of C The decisions that were

More information

Outline. Computer Programming. Preprocessing in C. File inclusion. Preprocessing in C

Outline. Computer Programming. Preprocessing in C. File inclusion. Preprocessing in C Outline Computer Programming The greatest gift you can give another is the purity of your attention. Richard Moss Preprocessing in C Function vs macro Conditional compilation Constant identifiers Standard

More information

C: How to Program. Week /Mar/05

C: How to Program. Week /Mar/05 1 C: How to Program Week 2 2007/Mar/05 Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers

More information

Arduino Uno. Power & Interface. Arduino Part 1. Introductory Medical Device Prototyping. Digital I/O Pins. Reset Button. USB Interface.

Arduino Uno. Power & Interface. Arduino Part 1. Introductory Medical Device Prototyping. Digital I/O Pins. Reset Button. USB Interface. Introductory Medical Device Prototyping Arduino Part 1, http://saliterman.umn.edu/ Department of Biomedical Engineering, University of Minnesota Arduino Uno Power & Interface Reset Button USB Interface

More information

AppHeader User s Guide Version 1.0

AppHeader User s Guide Version 1.0 Version 1.0 Important information Texas Instruments makes no warranty, either expressed or implied, including but not limited to any implied warranties of merchantability and fitness for a particular purpose,

More information

Why embedded systems?

Why embedded systems? MSP430 Intro Why embedded systems? Big bang-for-the-buck by adding some intelligence to systems. Embedded Systems are ubiquitous. Embedded Systems more common as prices drop, and power decreases. Which

More information

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types and

More information

Review of the C Programming Language for Principles of Operating Systems

Review of the C Programming Language for Principles of Operating Systems Review of the C Programming Language for Principles of Operating Systems Prof. James L. Frankel Harvard University Version of 7:26 PM 4-Sep-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights

More information

CS16 Exam #1 7/17/ Minutes 100 Points total

CS16 Exam #1 7/17/ Minutes 100 Points total CS16 Exam #1 7/17/2012 75 Minutes 100 Points total Name: 1. (10 pts) Write the definition of a C function that takes two integers `a` and `b` as input parameters. The function returns an integer holding

More information

The C Programming Language Guide for the Robot Course work Module

The C Programming Language Guide for the Robot Course work Module The C Programming Language Guide for the Robot Course work Module Eric Peasley 2018 v6.4 1 2 Table of Contents Variables...5 Assignments...6 Entering Numbers...6 Operators...7 Arithmetic Operators...7

More information

ICN12. I2C to UART Bridge, ADC,DAC and I/O

ICN12. I2C to UART Bridge, ADC,DAC and I/O Firmware version 1.4 Introduction ICN12 I2C to UART Bridge, ADC,DAC and I/O This is an I2C to UART bridge, designed to give an extra UART to a microcontroller when only I2C is available. It is an I2C device

More information

srl - shift right logical - 0 enters from left, bit drops off right end note: little-endian bit notation msb lsb "b" for bit

srl - shift right logical - 0 enters from left, bit drops off right end note: little-endian bit notation msb lsb b for bit Clemson University -- CPSC 231 Shifts (p. 123) srl - shift right logical - 0 enters from left, bit drops off right end 0 b 31 b 30 b 2 b 1 b 0 note: little-endian bit notation msb lsb "b" for bit a f 5

More information

AWK - PRETTY PRINTING

AWK - PRETTY PRINTING AWK - PRETTY PRINTING http://www.tutorialspoint.com/awk/awk_pretty_printing.htm Copyright tutorialspoint.com So far we have used AWK's print and printf functions to display data on standard output. But

More information

Should you know scanf and printf?

Should you know scanf and printf? C-LANGUAGE INPUT & OUTPUT C-Language Output with printf Input with scanf and gets_s and Defensive Programming Copyright 2016 Dan McElroy Should you know scanf and printf? scanf is only useful in the C-language,

More information

printf( Please enter another number: ); scanf( %d, &num2);

printf( Please enter another number: ); scanf( %d, &num2); CIT 593 Intro to Computer Systems Lecture #13 (11/1/12) Now that we've looked at how an assembly language program runs on a computer, we're ready to move up a level and start working with more powerful

More information

Chapter 2 - Introduction to C Programming

Chapter 2 - Introduction to C Programming Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers 2.4 Memory Concepts 2.5 Arithmetic

More information

Handout 7, Lex (5/30/2001)

Handout 7, Lex (5/30/2001) Handout 7, Lex (5/30/2001) Lex is a venerable Unix tool that generates scanners. Input to lex is a text file that specifies the scanner; more precisely: specifying tokens, a yet to be made scanner must

More information

AT03262: SAM D/R/L/C System Pin Multiplexer (SYSTEM PINMUX) Driver. Introduction. SMART ARM-based Microcontrollers APPLICATION NOTE

AT03262: SAM D/R/L/C System Pin Multiplexer (SYSTEM PINMUX) Driver. Introduction. SMART ARM-based Microcontrollers APPLICATION NOTE SMART ARM-based Microcontrollers AT03262: SAM D/R/L/C System Pin Multiplexer (SYSTEM PINMUX) Driver APPLICATION NOTE Introduction This driver for Atmel SMART ARM -based microcontrollers provides an interface

More information

ISPV3 Programmer s Guide. This guide addresses the features, setup and operation of the CRD89C51xxx microcontrollers with ISPV3 firmware.

ISPV3 Programmer s Guide. This guide addresses the features, setup and operation of the CRD89C51xxx microcontrollers with ISPV3 firmware. 1 Introduction Programmer s Guide This guide addresses the features, setup and operation of the CRD89C51xxx microcontrollers with firmware. The firmware is intended to provide In-system / In-application

More information

File Handling in C. EECS 2031 Fall October 27, 2014

File Handling in C. EECS 2031 Fall October 27, 2014 File Handling in C EECS 2031 Fall 2014 October 27, 2014 1 Reading from and writing to files in C l stdio.h contains several functions that allow us to read from and write to files l Their names typically

More information

GSE Scale Systems M660 CUSTOM TRANSMIT

GSE Scale Systems M660 CUSTOM TRANSMIT M660 CUSTOM TRANSMIT A custom transmit is a sequence of characters, control codes and parameter values to be transmitted out a communication port to a peripheral device such as a printer, remote display,

More information

Using printf with an AVR

Using printf with an AVR Using printf with an AVR Based on : http://efundies.com/avr/avr_printf.htm Required Functions You should keep all of the functions that you need from the previous guide: usart_init() usart_getchar() usart_purchar()

More information

Standard File Pointers

Standard File Pointers 1 Programming in C Standard File Pointers Assigned to console unless redirected Standard input = stdin Used by scan function Can be redirected: cmd < input-file Standard output = stdout Used by printf

More information

Introduction to C# Applications

Introduction to C# Applications 1 2 3 Introduction to C# Applications OBJECTIVES To write simple C# applications To write statements that input and output data to the screen. To declare and use data of various types. To write decision-making

More information

PMBus Power System Management Protocol Specification Part I General Requirements, Transport And Electrical Interface

PMBus Power System Management Protocol Specification Part I General Requirements, Transport And Electrical Interface PMBus Power System Management Protocol Specification Part I General Requirements, Transport And Electrical Interface Revision 1.0 28 March 2005 www.powersig.org 2005 System Management Interface Forum,

More information

Room 3P16 Telephone: extension ~irjohnson/uqc146s1.html

Room 3P16 Telephone: extension ~irjohnson/uqc146s1.html UQC146S1 Introductory Image Processing in C Ian Johnson Room 3P16 Telephone: extension 3167 Email: Ian.Johnson@uwe.ac.uk http://www.csm.uwe.ac.uk/ ~irjohnson/uqc146s1.html Ian Johnson 1 UQC146S1 What is

More information

Topic 6: A Quick Intro To C

Topic 6: A Quick Intro To C Topic 6: A Quick Intro To C Assumption: All of you know Java. Much of C syntax is the same. Also: Many of you have used C or C++. Goal for this topic: you can write & run a simple C program basic functions

More information

Fundamentals of Programming. Lecture 11: C Characters and Strings

Fundamentals of Programming. Lecture 11: C Characters and Strings 1 Fundamentals of Programming Lecture 11: C Characters and Strings Instructor: Fatemeh Zamani f_zamani@ce.sharif.edu Sharif University of Technology Computer Engineering Department The lectures of this

More information

PCI GS or PCIe8 LX Time Distribution Board

PCI GS or PCIe8 LX Time Distribution Board PCI GS or PCIe8 LX Time Distribution Board for use with PCI GS or PCIe8 LX Main Board August 28, 2008 008-02783-01 The information in this document is subject to change without notice and does not represent

More information

C mini reference. 5 Binary numbers 12

C mini reference. 5 Binary numbers 12 C mini reference Contents 1 Input/Output: stdio.h 2 1.1 int printf ( const char * format,... );......................... 2 1.2 int scanf ( const char * format,... );.......................... 2 1.3 char

More information

C Fundamentals & Formatted Input/Output. adopted from KNK C Programming : A Modern Approach

C Fundamentals & Formatted Input/Output. adopted from KNK C Programming : A Modern Approach C Fundamentals & Formatted Input/Output adopted from KNK C Programming : A Modern Approach C Fundamentals 2 Program: Printing a Pun The file name doesn t matter, but the.c extension is often required.

More information

Bits, Words, and Integers

Bits, Words, and Integers Computer Science 52 Bits, Words, and Integers Spring Semester, 2017 In this document, we look at how bits are organized into meaningful data. In particular, we will see the details of how integers are

More information

Fundamental of Programming (C)

Fundamental of Programming (C) Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 3 Constants, Variables, Data Types, And Operations Department of Computer Engineering

More information

Basic program The following is a basic program in C++; Basic C++ Source Code Compiler Object Code Linker (with libraries) Executable

Basic program The following is a basic program in C++; Basic C++ Source Code Compiler Object Code Linker (with libraries) Executable Basic C++ Overview C++ is a version of the older C programming language. This is a language that is used for a wide variety of applications and which has a mature base of compilers and libraries. C++ is

More information

CS102: Variables and Expressions

CS102: Variables and Expressions CS102: Variables and Expressions The topic of variables is one of the most important in C or any other high-level programming language. We will start with a simple example: int x; printf("the value of

More information

BV4626 General Purpose I/O. Product specification. Mar 2010 V0.a. ByVac Page 1 of 13

BV4626 General Purpose I/O. Product specification. Mar 2010 V0.a. ByVac Page 1 of 13 General Purpose I/O Product specification Mar 2010 V0.a ByVac Page 1 of 13 Contents 1. Introduction... 3 2. Features... 3 3. Physical Specification... 3 3.1. JP7... 3 3.2. Control Interface... 4 3.3. Serial

More information

Topic 6: A Quick Intro To C. Reading. "goto Considered Harmful" History

Topic 6: A Quick Intro To C. Reading. goto Considered Harmful History Topic 6: A Quick Intro To C Reading Assumption: All of you know basic Java. Much of C syntax is the same. Also: Some of you have used C or C++. Goal for this topic: you can write & run a simple C program

More information

Using LPC11Axx EEPROM (with IAP)

Using LPC11Axx EEPROM (with IAP) Rev. 2 1 July 2012 Application note Document information Info Content Keywords LPC11A02UK ; LPC11A04UK; LPC11A11FHN33; LPC11A12FHN33; LPC11A12FBD48; LPC11A13FHI33; LPC11A14FHN33; LPC11A14FBD48; LPC11Axx,

More information

Reserved Words and Identifiers

Reserved Words and Identifiers 1 Programming in C Reserved Words and Identifiers Reserved word Word that has a specific meaning in C Ex: int, return Identifier Word used to name and refer to a data element or object manipulated by the

More information

INTRODUCTION 1 AND REVIEW

INTRODUCTION 1 AND REVIEW INTRODUTION 1 AND REVIEW hapter SYS-ED/ OMPUTER EDUATION TEHNIQUES, IN. Programming: Advanced Objectives You will learn: Program structure. Program statements. Datatypes. Pointers. Arrays. Structures.

More information

VARIABLES AND CONSTANTS

VARIABLES AND CONSTANTS UNIT 3 Structure VARIABLES AND CONSTANTS Variables and Constants 3.0 Introduction 3.1 Objectives 3.2 Character Set 3.3 Identifiers and Keywords 3.3.1 Rules for Forming Identifiers 3.3.2 Keywords 3.4 Data

More information

Section 31. DMA Controller

Section 31. DMA Controller 31.3 MODES OF OPERATION The DMA module offers the following operating modes: Section 31. DMA Controller Basic Transfer mode Pattern Match mode Channel Chaining mode Channel Auto-Enable mode Special Function

More information

Advanced C Programming Topics

Advanced C Programming Topics Introductory Medical Device Prototyping Advanced C Programming Topics, http://saliterman.umn.edu/ Department of Biomedical Engineering, University of Minnesota Operations on Bits 1. Recall there are 8

More information

AN5179. RS232 communications with a terminal using the STM8 Nucleo-64 boards. Application note. Introduction

AN5179. RS232 communications with a terminal using the STM8 Nucleo-64 boards. Application note. Introduction Application note RS232 communications with a terminal using the STM8 Nucleo-64 boards Introduction This application note describes how to control the STM8 Nucleo-64 boards from a terminal window running

More information

LESSON 4. The DATA TYPE char

LESSON 4. The DATA TYPE char LESSON 4 This lesson introduces some of the basic ideas involved in character processing. The lesson discusses how characters are stored and manipulated by the C language, how characters can be treated

More information

Network Working Group Request for Comments: 205 NIC: August 1971

Network Working Group Request for Comments: 205 NIC: August 1971 Network Working Group R. Braden Request for Comments: 205 UCLA/CCN NIC: 7172 6 August 1971 NETCRT - A CHARACTER DISPLAY PROTOCOL At the May NWG, meeting, CCN circulated dittoed copies of a proposed character-display

More information

Lecture 3. More About C

Lecture 3. More About C Copyright 1996 David R. Hanson Computer Science 126, Fall 1996 3-1 Lecture 3. More About C Programming languages have their lingo Programming language Types are categories of values int, float, char Constants

More information

Syntax and Variables

Syntax and Variables Syntax and Variables What the Compiler needs to understand your program, and managing data 1 Pre-Processing Any line that starts with # is a pre-processor directive Pre-processor consumes that entire line

More information

Object oriented programming. Instructor: Masoud Asghari Web page: Ch: 3

Object oriented programming. Instructor: Masoud Asghari Web page:   Ch: 3 Object oriented programming Instructor: Masoud Asghari Web page: http://www.masses.ir/lectures/oops2017sut Ch: 3 1 In this slide We follow: https://docs.oracle.com/javase/tutorial/index.html Trail: Learning

More information

CS 4240: Compilers and Interpreters Project Phase 1: Scanner and Parser Due Date: October 4 th 2015 (11:59 pm) (via T-square)

CS 4240: Compilers and Interpreters Project Phase 1: Scanner and Parser Due Date: October 4 th 2015 (11:59 pm) (via T-square) CS 4240: Compilers and Interpreters Project Phase 1: Scanner and Parser Due Date: October 4 th 2015 (11:59 pm) (via T-square) Introduction This semester, through a project split into 3 phases, we are going

More information

CS164: Programming Assignment 2 Dlex Lexer Generator and Decaf Lexer

CS164: Programming Assignment 2 Dlex Lexer Generator and Decaf Lexer CS164: Programming Assignment 2 Dlex Lexer Generator and Decaf Lexer Assigned: Thursday, September 16, 2004 Due: Tuesday, September 28, 2004, at 11:59pm September 16, 2004 1 Introduction Overview In this

More information

ANSI C Programming Simple Programs

ANSI C Programming Simple Programs ANSI C Programming Simple Programs /* This program computes the distance between two points */ #include #include #include main() { /* Declare and initialize variables */ double

More information

An overview of Java, Data types and variables

An overview of Java, Data types and variables An overview of Java, Data types and variables Lecture 2 from (UNIT IV) Prepared by Mrs. K.M. Sanghavi 1 2 Hello World // HelloWorld.java: Hello World program import java.lang.*; class HelloWorld { public

More information

SAM4 Reset Controller (RSTC)

SAM4 Reset Controller (RSTC) APPLICATION NOTE AT06864: SAM4 Reset Controller (RSTC) ASF PROGRAMMERS MANUAL SAM4 Reset Controller (RSTC) This driver for SAM devices provides an interface for the configuration and management of the

More information

The Design of C: A Rational Reconstruction (cont.)" Jennifer Rexford!

The Design of C: A Rational Reconstruction (cont.) Jennifer Rexford! The Design of C: A Rational Reconstruction (cont.)" Jennifer Rexford! 1 Goals of this Lecture"" Help you learn about:! The decisions that were available to the designers of C! The decisions that were made

More information

CS 33. Data Representation, Part 1. CS33 Intro to Computer Systems VII 1 Copyright 2017 Thomas W. Doeppner. All rights reserved.

CS 33. Data Representation, Part 1. CS33 Intro to Computer Systems VII 1 Copyright 2017 Thomas W. Doeppner. All rights reserved. CS 33 Data Representation, Part 1 CS33 Intro to Computer Systems VII 1 Copyright 2017 Thomas W. Doeppner. All rights reserved. Number Representation Hindu-Arabic numerals developed by Hindus starting in

More information

Tools : The Java Compiler. The Java Interpreter. The Java Debugger

Tools : The Java Compiler. The Java Interpreter. The Java Debugger Tools : The Java Compiler javac [ options ] filename.java... -depend: Causes recompilation of class files on which the source files given as command line arguments recursively depend. -O: Optimizes code,

More information

SAINT2. System Analysis Interface Tool 2. Emulation User Guide. Version 2.5. May 27, Copyright Delphi Automotive Systems Corporation 2009, 2010

SAINT2. System Analysis Interface Tool 2. Emulation User Guide. Version 2.5. May 27, Copyright Delphi Automotive Systems Corporation 2009, 2010 SAINT2 System Analysis Interface Tool 2 Emulation User Guide Version 2.5 May 27, 2010 Copyright Delphi Automotive Systems Corporation 2009, 2010 Maintained by: SAINT2 Team Delphi www.saint2support.com

More information