Removed EEPROM define (bug)
[hackover2013-badge-firmware.git] / project / commands / cmd_uart.c
1 /**************************************************************************/
2 /*!
3 @file cmd_uart.c
4 @author K. Townsend (microBuilder.eu)
5
6 @brief Code to execute for cmd_uart in the 'core/cmd'
7 command-line interpretter.
8
9 @section LICENSE
10
11 Software License Agreement (BSD License)
12
13 Copyright (c) 2010, microBuilder SARL
14 All rights reserved.
15
16 Redistribution and use in source and binary forms, with or without
17 modification, are permitted provided that the following conditions are met:
18 1. Redistributions of source code must retain the above copyright
19 notice, this list of conditions and the following disclaimer.
20 2. Redistributions in binary form must reproduce the above copyright
21 notice, this list of conditions and the following disclaimer in the
22 documentation and/or other materials provided with the distribution.
23 3. Neither the name of the copyright holders nor the
24 names of its contributors may be used to endorse or promote products
25 derived from this software without specific prior written permission.
26
27 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
28 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
29 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
30 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
31 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
32 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
33 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
34 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 */
38 /**************************************************************************/
39 #include <stdio.h>
40
41 #include "projectconfig.h"
42 #include "core/cmd/cmd.h"
43 #include "project/commands.h" // Generic helper functions
44
45 #ifdef CFG_I2CEEPROM
46 #include "drivers/storage/eeprom/eeprom.h"
47 #include "core/uart/uart.h"
48
49 /**************************************************************************/
50 /*!
51 Gets or sets the UART speed from EEPROM.
52 */
53 /**************************************************************************/
54 void cmd_uart(uint8_t argc, char **argv)
55 {
56 if (argc > 0)
57 {
58 // Try to convert supplied value to an integer
59 int32_t speed;
60 getNumber (argv[0], &speed);
61
62 // Check for invalid values (getNumber may complain about this as well)
63 if (speed < 9600 || speed > 115200)
64 {
65 printf("Invalid baud rate: 9600-115200 required.%s", CFG_PRINTF_NEWLINE);
66 return;
67 }
68
69 // Write baud rate to EEPROM and reinitialise UART if using it
70 printf("Setting UART to: %d%s", (int)speed, CFG_PRINTF_NEWLINE);
71 eepromWriteU32(CFG_EEPROM_UART_SPEED, speed);
72 #ifdef CFG_PRINTF_UART
73 uartInit(speed);
74 #endif
75 }
76 else
77 {
78 // Display the current baud rate
79 #ifdef CFG_PRINTF_UART
80 uart_pcb_t *pcb = uartGetPCB();
81 printf("%u%s", (unsigned int)(pcb->baudrate), CFG_PRINTF_NEWLINE);
82 #else
83 // Try to get UART from EEPROM
84 uint32_t uartEEPROM = eepromReadU32(CFG_EEPROM_UART_SPEED);
85 if ((uartEEPROM < 9600) || (uartEEPROM > 115200))
86 {
87 printf("UART not set in EEPROM%s", CFG_PRINTF_NEWLINE);
88 }
89 else
90 {
91 printf("%u%s", (unsigned int)uartEEPROM, CFG_PRINTF_NEWLINE);
92 }
93 #endif
94 }
95 }
96
97 #endif
This page took 0.057037 seconds and 5 git commands to generate.