These are the examples provided for [[/users/frank26080115/libraries/LPC1700CMSIS_Lib/]] Note, the entire "program" is not compilable!

Committer:
frank26080115
Date:
Sun Mar 20 05:38:56 2011 +0000
Revision:
0:bf7b9fba3924

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
frank26080115 0:bf7b9fba3924 1 /***
frank26080115 0:bf7b9fba3924 2 * @file uart_hw_flow_control.c
frank26080115 0:bf7b9fba3924 3 * @purpose This example describes how to using UART Hardware flow control mode
frank26080115 0:bf7b9fba3924 4 * @version 2.0
frank26080115 0:bf7b9fba3924 5 * @date 10. June. 2010
frank26080115 0:bf7b9fba3924 6 * @author NXP MCU SW Application Team
frank26080115 0:bf7b9fba3924 7 *---------------------------------------------------------------------
frank26080115 0:bf7b9fba3924 8 * Software that is described herein is for illustrative purposes only
frank26080115 0:bf7b9fba3924 9 * which provides customers with programming information regarding the
frank26080115 0:bf7b9fba3924 10 * products. This software is supplied "AS IS" without any warranties.
frank26080115 0:bf7b9fba3924 11 * NXP Semiconductors assumes no responsibility or liability for the
frank26080115 0:bf7b9fba3924 12 * use of the software, conveys no license or title under any patent,
frank26080115 0:bf7b9fba3924 13 * copyright, or mask work right to the product. NXP Semiconductors
frank26080115 0:bf7b9fba3924 14 * reserves the right to make changes in the software without
frank26080115 0:bf7b9fba3924 15 * notification. NXP Semiconductors also make no representation or
frank26080115 0:bf7b9fba3924 16 * warranty that such application will be suitable for the specified
frank26080115 0:bf7b9fba3924 17 * use without further testing or modification.
frank26080115 0:bf7b9fba3924 18 **********************************************************************/
frank26080115 0:bf7b9fba3924 19 #include "lpc17xx_uart.h"
frank26080115 0:bf7b9fba3924 20 #include "lpc17xx_libcfg.h"
frank26080115 0:bf7b9fba3924 21 #include "lpc17xx_pinsel.h"
frank26080115 0:bf7b9fba3924 22
frank26080115 0:bf7b9fba3924 23 /* Example group ----------------------------------------------------------- */
frank26080115 0:bf7b9fba3924 24 /** @defgroup UART_HWFlowControl HWFlowControl
frank26080115 0:bf7b9fba3924 25 * @ingroup UART_Examples
frank26080115 0:bf7b9fba3924 26 * @{
frank26080115 0:bf7b9fba3924 27 */
frank26080115 0:bf7b9fba3924 28
frank26080115 0:bf7b9fba3924 29 /************************** PRIVATE DEFINITIONS *************************/
frank26080115 0:bf7b9fba3924 30 #define TEST_UART (LPC_UART_TypeDef *)LPC_UART1
frank26080115 0:bf7b9fba3924 31
frank26080115 0:bf7b9fba3924 32 /************************** PRIVATE VARIABLES *************************/
frank26080115 0:bf7b9fba3924 33 uint8_t menu1[] = "Hello NXP Semiconductors \n\r";
frank26080115 0:bf7b9fba3924 34 uint8_t menu2[] = "UART hardware flow control mode demo \n\r\t MCU LPC17xx - ARM Cortex-M3 \n\r\t UART1 - 9600bps \n\r";
frank26080115 0:bf7b9fba3924 35 uint8_t menu3[] = "UART demo terminated!";
frank26080115 0:bf7b9fba3924 36
frank26080115 0:bf7b9fba3924 37 /************************** PRIVATE FUNCTIONS *************************/
frank26080115 0:bf7b9fba3924 38 void print_menu(void);
frank26080115 0:bf7b9fba3924 39
frank26080115 0:bf7b9fba3924 40 /*-------------------------PRIVATE FUNCTIONS------------------------------*/
frank26080115 0:bf7b9fba3924 41 /*********************************************************************//**
frank26080115 0:bf7b9fba3924 42 * @brief Print Welcome menu
frank26080115 0:bf7b9fba3924 43 * @param[in] none
frank26080115 0:bf7b9fba3924 44 * @return None
frank26080115 0:bf7b9fba3924 45 **********************************************************************/
frank26080115 0:bf7b9fba3924 46 void print_menu(void)
frank26080115 0:bf7b9fba3924 47 {
frank26080115 0:bf7b9fba3924 48 UART_Send(TEST_UART, menu1, sizeof(menu1), BLOCKING);
frank26080115 0:bf7b9fba3924 49 UART_Send(TEST_UART, menu2, sizeof(menu2), BLOCKING);
frank26080115 0:bf7b9fba3924 50 }
frank26080115 0:bf7b9fba3924 51
frank26080115 0:bf7b9fba3924 52 /*-------------------------MAIN FUNCTION------------------------------*/
frank26080115 0:bf7b9fba3924 53 /*********************************************************************//**
frank26080115 0:bf7b9fba3924 54 * @brief c_entry: Main UART program body
frank26080115 0:bf7b9fba3924 55 * @param[in] None
frank26080115 0:bf7b9fba3924 56 * @return int
frank26080115 0:bf7b9fba3924 57 **********************************************************************/
frank26080115 0:bf7b9fba3924 58 int c_entry(void)
frank26080115 0:bf7b9fba3924 59 {
frank26080115 0:bf7b9fba3924 60 // UART Configuration structure variable
frank26080115 0:bf7b9fba3924 61 UART_CFG_Type UARTConfigStruct;
frank26080115 0:bf7b9fba3924 62 // UART FIFO configuration Struct variable
frank26080115 0:bf7b9fba3924 63 UART_FIFO_CFG_Type UARTFIFOConfigStruct;
frank26080115 0:bf7b9fba3924 64 // Pin configuration for UART0
frank26080115 0:bf7b9fba3924 65 PINSEL_CFG_Type PinCfg;
frank26080115 0:bf7b9fba3924 66
frank26080115 0:bf7b9fba3924 67 uint32_t idx, len;
frank26080115 0:bf7b9fba3924 68 __IO FlagStatus exitflag;
frank26080115 0:bf7b9fba3924 69 uint8_t buffer[10];
frank26080115 0:bf7b9fba3924 70
frank26080115 0:bf7b9fba3924 71 /*
frank26080115 0:bf7b9fba3924 72 * Initialize UART1 pin connect
frank26080115 0:bf7b9fba3924 73 */
frank26080115 0:bf7b9fba3924 74 PinCfg.Funcnum = 2;
frank26080115 0:bf7b9fba3924 75 PinCfg.OpenDrain = 0;
frank26080115 0:bf7b9fba3924 76 PinCfg.Pinmode = 0;
frank26080115 0:bf7b9fba3924 77 PinCfg.Pinnum = 0;
frank26080115 0:bf7b9fba3924 78 PinCfg.Portnum = 2;
frank26080115 0:bf7b9fba3924 79 PINSEL_ConfigPin(&PinCfg);//P2.0 TXD1
frank26080115 0:bf7b9fba3924 80 PinCfg.Pinnum = 1;
frank26080115 0:bf7b9fba3924 81 PINSEL_ConfigPin(&PinCfg);//P2.1 RXD1
frank26080115 0:bf7b9fba3924 82 PinCfg.Pinnum = 2;
frank26080115 0:bf7b9fba3924 83 PINSEL_ConfigPin(&PinCfg);//P2.2 CTS1
frank26080115 0:bf7b9fba3924 84 PinCfg.Pinnum = 7;
frank26080115 0:bf7b9fba3924 85 PINSEL_ConfigPin(&PinCfg);//P2.7 RTS1
frank26080115 0:bf7b9fba3924 86
frank26080115 0:bf7b9fba3924 87 /* Initialize UART Configuration parameter structure to default state:
frank26080115 0:bf7b9fba3924 88 * Baudrate = 9600bps
frank26080115 0:bf7b9fba3924 89 * 8 data bit
frank26080115 0:bf7b9fba3924 90 * 1 Stop bit
frank26080115 0:bf7b9fba3924 91 * None parity
frank26080115 0:bf7b9fba3924 92 */
frank26080115 0:bf7b9fba3924 93 UART_ConfigStructInit(&UARTConfigStruct);
frank26080115 0:bf7b9fba3924 94
frank26080115 0:bf7b9fba3924 95 // Initialize UART0 peripheral with given to corresponding parameter
frank26080115 0:bf7b9fba3924 96 UART_Init(TEST_UART, &UARTConfigStruct);
frank26080115 0:bf7b9fba3924 97
frank26080115 0:bf7b9fba3924 98 /* Initialize FIFOConfigStruct to default state:
frank26080115 0:bf7b9fba3924 99 * - FIFO_DMAMode = DISABLE
frank26080115 0:bf7b9fba3924 100 * - FIFO_Level = UART_FIFO_TRGLEV0
frank26080115 0:bf7b9fba3924 101 * - FIFO_ResetRxBuf = ENABLE
frank26080115 0:bf7b9fba3924 102 * - FIFO_ResetTxBuf = ENABLE
frank26080115 0:bf7b9fba3924 103 * - FIFO_State = ENABLE
frank26080115 0:bf7b9fba3924 104 */
frank26080115 0:bf7b9fba3924 105 UART_FIFOConfigStructInit(&UARTFIFOConfigStruct);
frank26080115 0:bf7b9fba3924 106
frank26080115 0:bf7b9fba3924 107 // Initialize FIFO for UART0 peripheral
frank26080115 0:bf7b9fba3924 108 UART_FIFOConfig(TEST_UART, &UARTFIFOConfigStruct);
frank26080115 0:bf7b9fba3924 109
frank26080115 0:bf7b9fba3924 110 // Configure UART1 hardware flow control RTS/CTS
frank26080115 0:bf7b9fba3924 111 UART_FullModemForcePinState((LPC_UART1_TypeDef *)LPC_UART1,UART1_MODEM_PIN_RTS,ACTIVE);
frank26080115 0:bf7b9fba3924 112
frank26080115 0:bf7b9fba3924 113 // Enable UART Transmit
frank26080115 0:bf7b9fba3924 114 UART_TxCmd(TEST_UART, ENABLE);
frank26080115 0:bf7b9fba3924 115
frank26080115 0:bf7b9fba3924 116 // print welcome screen
frank26080115 0:bf7b9fba3924 117 print_menu();
frank26080115 0:bf7b9fba3924 118
frank26080115 0:bf7b9fba3924 119 // Reset exit flag
frank26080115 0:bf7b9fba3924 120 exitflag = RESET;
frank26080115 0:bf7b9fba3924 121
frank26080115 0:bf7b9fba3924 122 /* Read some data from the buffer */
frank26080115 0:bf7b9fba3924 123 while (exitflag == RESET)
frank26080115 0:bf7b9fba3924 124 {
frank26080115 0:bf7b9fba3924 125 len = 0;
frank26080115 0:bf7b9fba3924 126 while (len == 0)
frank26080115 0:bf7b9fba3924 127 {
frank26080115 0:bf7b9fba3924 128 len = UART_Receive(TEST_UART, buffer, sizeof(buffer), NONE_BLOCKING);
frank26080115 0:bf7b9fba3924 129 }
frank26080115 0:bf7b9fba3924 130
frank26080115 0:bf7b9fba3924 131 /* Got some data */
frank26080115 0:bf7b9fba3924 132 idx = 0;
frank26080115 0:bf7b9fba3924 133 while (idx < len)
frank26080115 0:bf7b9fba3924 134 {
frank26080115 0:bf7b9fba3924 135 if (buffer[idx] == 27)
frank26080115 0:bf7b9fba3924 136 {
frank26080115 0:bf7b9fba3924 137 /* ESC key, set exit flag */
frank26080115 0:bf7b9fba3924 138 UART_Send(TEST_UART, menu3, sizeof(menu3), BLOCKING);
frank26080115 0:bf7b9fba3924 139 exitflag = SET;
frank26080115 0:bf7b9fba3924 140 }
frank26080115 0:bf7b9fba3924 141 else if (buffer[idx] == 'r')
frank26080115 0:bf7b9fba3924 142 {
frank26080115 0:bf7b9fba3924 143 print_menu();
frank26080115 0:bf7b9fba3924 144 }
frank26080115 0:bf7b9fba3924 145 else
frank26080115 0:bf7b9fba3924 146 {
frank26080115 0:bf7b9fba3924 147 /* Echo it back */
frank26080115 0:bf7b9fba3924 148 UART_Send(TEST_UART, &buffer[idx], 1, BLOCKING);
frank26080115 0:bf7b9fba3924 149 }
frank26080115 0:bf7b9fba3924 150 idx++;
frank26080115 0:bf7b9fba3924 151 }
frank26080115 0:bf7b9fba3924 152 }
frank26080115 0:bf7b9fba3924 153
frank26080115 0:bf7b9fba3924 154 // wait for current transmission complete - THR must be empty
frank26080115 0:bf7b9fba3924 155 while (UART_CheckBusy(TEST_UART) == SET);
frank26080115 0:bf7b9fba3924 156
frank26080115 0:bf7b9fba3924 157 // DeInitialize UART0 peripheral
frank26080115 0:bf7b9fba3924 158 UART_DeInit(TEST_UART);
frank26080115 0:bf7b9fba3924 159
frank26080115 0:bf7b9fba3924 160 /* Loop forever */
frank26080115 0:bf7b9fba3924 161 while(1);
frank26080115 0:bf7b9fba3924 162 return 1;
frank26080115 0:bf7b9fba3924 163 }
frank26080115 0:bf7b9fba3924 164
frank26080115 0:bf7b9fba3924 165 /* With ARM and GHS toolsets, the entry point is main() - this will
frank26080115 0:bf7b9fba3924 166 allow the linker to generate wrapper code to setup stacks, allocate
frank26080115 0:bf7b9fba3924 167 heap area, and initialize and copy code and data segments. For GNU
frank26080115 0:bf7b9fba3924 168 toolsets, the entry point is through __start() in the crt0_gnu.asm
frank26080115 0:bf7b9fba3924 169 file, and that startup code will setup stacks and data */
frank26080115 0:bf7b9fba3924 170 int main(void)
frank26080115 0:bf7b9fba3924 171 {
frank26080115 0:bf7b9fba3924 172 return c_entry();
frank26080115 0:bf7b9fba3924 173 }
frank26080115 0:bf7b9fba3924 174
frank26080115 0:bf7b9fba3924 175
frank26080115 0:bf7b9fba3924 176 #ifdef DEBUG
frank26080115 0:bf7b9fba3924 177 /*******************************************************************************
frank26080115 0:bf7b9fba3924 178 * @brief Reports the name of the source file and the source line number
frank26080115 0:bf7b9fba3924 179 * where the CHECK_PARAM error has occurred.
frank26080115 0:bf7b9fba3924 180 * @param[in] file Pointer to the source file name
frank26080115 0:bf7b9fba3924 181 * @param[in] line assert_param error line source number
frank26080115 0:bf7b9fba3924 182 * @return None
frank26080115 0:bf7b9fba3924 183 *******************************************************************************/
frank26080115 0:bf7b9fba3924 184 void check_failed(uint8_t *file, uint32_t line)
frank26080115 0:bf7b9fba3924 185 {
frank26080115 0:bf7b9fba3924 186 /* User can add his own implementation to report the file name and line number,
frank26080115 0:bf7b9fba3924 187 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
frank26080115 0:bf7b9fba3924 188
frank26080115 0:bf7b9fba3924 189 /* Infinite loop */
frank26080115 0:bf7b9fba3924 190 while(1);
frank26080115 0:bf7b9fba3924 191 }
frank26080115 0:bf7b9fba3924 192 #endif
frank26080115 0:bf7b9fba3924 193 /*
frank26080115 0:bf7b9fba3924 194 * @}
frank26080115 0:bf7b9fba3924 195 */