]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - apps/tidep0084.git/blob - tutorials/generic_sensor_tutorial/final/SensorToCloud/components/common/src/stream_uart_ini.c
Added Support for Generic Sensor Tutorial which provides instructions on how to add...
[apps/tidep0084.git] / tutorials / generic_sensor_tutorial / final / SensorToCloud / components / common / src / stream_uart_ini.c
1 /******************************************************************************
2  @file stream_uart_ini.c
4  @brief TIMAC 2.0 API Parse INI files to configure uart interfaces
6  Group: WCS LPC
7  $Target Devices: Linux: AM335x, Embedded Devices: CC1310, CC1350$
9  ******************************************************************************
10  $License: BSD3 2016 $
11   
12    Copyright (c) 2015, Texas Instruments Incorporated
13    All rights reserved.
14   
15    Redistribution and use in source and binary forms, with or without
16    modification, are permitted provided that the following conditions
17    are met:
18   
19    *  Redistributions of source code must retain the above copyright
20       notice, this list of conditions and the following disclaimer.
21   
22    *  Redistributions in binary form must reproduce the above copyright
23       notice, this list of conditions and the following disclaimer in the
24       documentation and/or other materials provided with the distribution.
25   
26    *  Neither the name of Texas Instruments Incorporated nor the names of
27       its contributors may be used to endorse or promote products derived
28       from this software without specific prior written permission.
29   
30    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
31    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
32    THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
33    PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
34    CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
35    EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
36    PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
37    OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
38    WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
39    OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
40    EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41  ******************************************************************************
42  $Release Name: TI-15.4Stack Linux x64 SDK$
43  $Release Date: Jun 28, 2017 (2.02.00.03)$
44  *****************************************************************************/
46 #include "compiler.h"
47 #include "stream.h"
48 #include "ini_file.h"
49 #include "stream_uart.h"
51 struct uart_cfg ALL_INI_UARTS[INI_MAX_UARTS];
53 #include <string.h>
55 /*
56  * Rd/Parse UART configuration data from an INI file
57  *
58  * Public function defined in stream_uart.h
59  */
60 int UART_INI_settingsNth(struct ini_parser *pINI, bool *handled)
61 {
63     unsigned nth;
65     if(pINI->item_name == NULL)
66     {
67         /* this is the section name, we don't care about it. */
68         return (0);
69     }
71     /* is this a UART section? */
72     if(!INI_isNth(pINI, "uart-", &nth))
73     {
74         /* Nope, then leave */
75         return (0);
76     }
77     if( nth >= INI_MAX_UARTS )
78     {
79         INI_syntaxError( pINI, "invalid uart index %u\n", nth );
80         return -1;
81     }
82     return (UART_INI_settingsOne(pINI, handled, &(ALL_INI_UARTS[nth])));
83 }
85 /*
86  * Public function defined in stream_uart.h
87  */
88 int UART_INI_settingsOne(struct ini_parser *pINI,
89                           bool *handled,
90                           struct uart_cfg *pCFG)
91 {
92 static const struct ini_flag_name uart_ini_cfg_flags[] = {
93     { .name = "rd_thread", .value = STREAM_UART_FLAG_rd_thread },
94     { .name = "hw_handshake", .value = STREAM_UART_FLAG_hw_handshake },
95     { .name = "default", .value = STREAM_UART_FLAG_default },
96     { .name = NULL }
97 };
99     int r;
100     bool is_not;
101     const struct ini_flag_name *pF;
103     if(pINI->item_name == NULL)
104     {
105         return (0);
106     }
108     r = -1;
110     /* match name? */
111     if(INI_itemMatches(pINI, NULL, "devname"))
112     {
113         INI_dequote(pINI);
114         pCFG->devname = INI_itemValue_strdup(pINI);
115         r = 0;
116     }
118     /* baudrate? */
119     if(INI_itemMatches(pINI, NULL, "baudrate"))
120     {
121         pCFG->baudrate = INI_valueAsInt(pINI);
122         r = 0;
123     }
125     /* Flags? */
126     if(INI_itemMatches(pINI, NULL, "flag"))
127     {
128         is_not = false;
129         r = 0;
130         pF = INI_flagLookup(uart_ini_cfg_flags, pINI->item_value, &is_not);
131         if(pF == NULL)
132         {
133             INI_syntaxError(pINI, "unknown flag: %s\n" , pINI->item_value);
134         }
135         else
136         {
137             if(is_not)
138             {
139                 pCFG->open_flags &= (~(pF->value));
140             }
141             else
142             {
143                 pCFG->open_flags |= ((pF->value));
144             }
145         }
146     }
148     if(r == 0)
149     {
150         /* we handle it here */
151         *handled = true;
152     }
153     else
154     {
155         INI_syntaxError(pINI, "Unknown\n");
156     }
157     return (r);
160 /*
161  *  ========================================
162  *  Texas Instruments Micro Controller Style
163  *  ========================================
164  *  Local Variables:
165  *  mode: c
166  *  c-file-style: "bsd"
167  *  tab-width: 4
168  *  c-basic-offset: 4
169  *  indent-tabs-mode: nil
170  *  End:
171  *  vim:set  filetype=c tabstop=4 shiftwidth=4 expandtab=true
172  */