1 /*
2 * baudrateselect.c
3 *
4 * Forwards baudrade change requests to individual peripheral modules.
5 *
6 * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
7 *
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the
19 * distribution.
20 *
21 * Neither the name of Texas Instruments Incorporated nor the names of
22 * its contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 *
37 */
39 #include <MSP430.h>
40 #include "uart.h"
41 #include "i2c.h"
42 #include "main.h"
44 extern enum active_peripherals active_peripheral;
46 /* Configures the peripheral module selected by baudrate change */
47 BYTE BaudrateSelect(ULONG lBaudrate)
48 {
49 BYTE baudIndex;
51 switch(lBaudrate)
52 {
53 /* UART peripheral */
54 case 1200:
55 active_peripheral = UART;
56 baudIndex = InitUart(lBaudrate);
57 break;
58 case 2400:
59 active_peripheral = UART;
60 baudIndex = InitUart(lBaudrate);
61 break;
62 case 4800:
63 active_peripheral = UART;
64 baudIndex = InitUart(lBaudrate);
65 break;
66 case 4801:
67 active_peripheral = UART;
68 baudIndex = InitUart(lBaudrate);
69 break;
70 case 4802:
71 active_peripheral = UART;
72 baudIndex = InitUart(lBaudrate);
73 break;
74 case 9600:
75 active_peripheral = UART;
76 baudIndex = InitUart(lBaudrate);
77 break;
78 case 9601:
79 active_peripheral = UART;
80 baudIndex = InitUart(lBaudrate);
81 break;
82 /* reserved for future devices invoke sequence
83 case 9602: newInvoke(2); break;
84 case 9603: newInvoke(3); break;
85 case 9604: newInvoke(4); break;
86 case 9605: newInvoke(5); break;
87 case 9606: newInvoke(6); break;
88 case 9607: newInvoke(7); break;
89 case 9608: newInvoke(8); break;
90 case 9609: newInvoke(9); break;
91 case 9610: newInvoke(10); break;
92 case 9611: newInvoke(11); break;
93 case 9612: newInvoke(12); break;
94 case 9613: newInvoke(13); break;
95 case 9614: newInvoke(14); break;
96 case 9615: newInvoke(15); break;
97 case 9616: newInvoke(16); break;
98 case 9617: newInvoke(17); break;
99 case 9618: newInvoke(18); break;
100 */
101 case 19200:
102 active_peripheral = UART;
103 baudIndex = InitUart(lBaudrate);
104 break;
105 case 38400:
106 active_peripheral = UART;
107 baudIndex = InitUart(lBaudrate);
108 break;
109 case 57600:
110 active_peripheral = UART;
111 baudIndex = InitUart(lBaudrate);
112 break;
113 case 115200:
114 active_peripheral = UART;
115 baudIndex = InitUart(lBaudrate);
116 break;
117 case 230400:
118 active_peripheral = UART;
119 baudIndex = InitUart(lBaudrate);
120 break;
121 case 460800:
122 active_peripheral = UART;
123 baudIndex = InitUart(lBaudrate);
124 break;
125 case 921600:
126 active_peripheral = UART;
127 baudIndex = InitUart(lBaudrate);
128 break;
130 /* I2C peripheral */
131 case 100000:
132 active_peripheral = I2C;
133 baudIndex = InitI2C(BSL_SLAVE_ADDR, lBaudrate);
134 break;
135 case 100001:
136 active_peripheral = I2C;
137 baudIndex = InitI2C(BSL_SLAVE_ADDR, lBaudrate);
138 break;
139 case 400000:
140 active_peripheral = I2C;
141 baudIndex = InitI2C(BSL_SLAVE_ADDR, lBaudrate);
142 break;
143 case 400001:
144 active_peripheral = I2C;
145 baudIndex = InitI2C(BSL_SLAVE_ADDR, lBaudrate);
146 break;
148 default:
149 baudIndex = 0;
150 break;
152 }
154 return baudIndex;
155 }