Edison MCU Project
 All Files Functions Typedefs Macros Pages
sample_uart_receive.c
Go to the documentation of this file.
1 /************************************************************************************
2  * Copyright (c) 2015, Intel Corporation
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice, this
9  * list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation and/or
13  * other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
19  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
20  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
23  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
24  * OF THE POSSIBILITY OF SUCH DAMAGE.
25  ************************************************************************************/
26 
31 #include "mcu_api.h"
32 #include "mcu_errno.h"
33 /*
34 * This program read data from UART1
35 */
36 void mcu_main()
37 {
38  /* your configuration code starts here */
39  unsigned char ch;
40  char buf[32];
41  unsigned int cnt;
42  unsigned int len;
43  uart_setup(1,115200);
44 
45  while (1) /* your loop code starts here */
46  {
47  cnt = uart_read(1, &ch, 1);
48  if (cnt < 0)
49  {
50  debug_print(DBG_ERROR, "mcu uart1 read fail...");
51  continue;
52  }
53  len = mcu_snprintf(buf, 32, "data from uart1: %s\n", &ch);
54  host_send((unsigned char*)buf, len);
55  }
56 }
Intel MCU API definition.
int uart_read(unsigned char port, unsigned char *buf, unsigned char len)
void debug_print(int level, const char *fmt,...)
#define DBG_ERROR
Definition: mcu_api.h:39
void mcu_main()
int host_send(unsigned char *buf, int length)
int mcu_snprintf(char *buf, unsigned int size, const char *fmt,...)
Intel MCU API error code definition.
int uart_setup(unsigned char port, int baudrate)