| 1 | /***************************************************************************//** |
| 2 | * @file Main.c |
| 3 | * @brief Implementation of the program's main function. |
| 4 | * @author DBogdan ([email protected]) |
| 5 | ******************************************************************************** |
| 6 | * Copyright 2013(c) Analog Devices, Inc. |
| 7 | * |
| 8 | * All rights reserved. |
| 9 | * |
| 10 | * Redistribution and use in source and binary forms, with or without |
| 11 | * modification, are permitted provided that the following conditions are met: |
| 12 | * - Redistributions of source code must retain the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer. |
| 14 | * - Redistributions in binary form must reproduce the above copyright |
| 15 | * notice, this list of conditions and the following disclaimer in |
| 16 | * the documentation and/or other materials provided with the |
| 17 | * distribution. |
| 18 | * - Neither the name of Analog Devices, Inc. nor the names of its |
| 19 | * contributors may be used to endorse or promote products derived |
| 20 | * from this software without specific prior written permission. |
| 21 | * - The use of this software may or may not infringe the patent rights |
| 22 | * of one or more patent holders. This license does not release you |
| 23 | * from the requirement that you obtain separate licenses from these |
| 24 | * patent holders to use this software. |
| 25 | * - Use of the software either in source or binary form, must be run |
| 26 | * on or directly connected to an Analog Devices Inc. component. |
| 27 | * |
| 28 | * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR |
| 29 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, |
| 30 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 31 | * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 32 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 33 | * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 34 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 35 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 36 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 37 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 38 | * |
| 39 | *******************************************************************************/ |
| 40 | |
| 41 | /******************************************************************************/ |
| 42 | /***************************** Include Files **********************************/ |
| 43 | /******************************************************************************/ |
| 44 | #include "Console.h" |
| 45 | #include "Command.h" |
| 46 | |
| 47 | /******************************************************************************/ |
| 48 | /*********************** Device configuration words ***************************/ |
| 49 | /******************************************************************************/ |
| 50 | /*!< DEVCFG3 */ |
| 51 | /*!< USERID = No Setting */ |
| 52 | |
| 53 | /*!< DEVCFG2 */ |
| 54 | #pragma config FPLLIDIV = DIV_2 /*!< PLL Input Divider (2x Divider) */ |
| 55 | #pragma config FPLLMUL = MUL_20 /*!< PLL Multiplier (20x Multiplier) */ |
| 56 | #pragma config FPLLODIV = DIV_1 /*!< System PLL Output Clock Divider (PLL Divide by 1) */ |
| 57 | |
| 58 | /* DEVCFG1 */ |
| 59 | #pragma config FNOSC = PRIPLL /*!< Oscillator Selection Bits (Primary Osc w/PLL (XT+,HS+,EC+PLL)) */ |
| 60 | #pragma config FSOSCEN = OFF /*!< Secondary Oscillator Enable (Disabled) */ |
| 61 | #pragma config IESO = ON /*!< Internal/External Switch Over (Enabled) */ |
| 62 | #pragma config POSCMOD = XT /*!< Primary Oscillator Configuration (XT osc mode) */ |
| 63 | #pragma config OSCIOFNC = OFF /*!< CLKO Output Signal Active on the OSCO Pin (Disabled) */ |
| 64 | #pragma config FPBDIV = DIV_1 /*!< Peripheral Clock Divisor (Pb_Clk is Sys_Clk/1) */ |
| 65 | #pragma config FCKSM = CSDCMD /*!< Clock Switching and Monitor Selection (Clock Switch Disable, FSCM Disabled) */ |
| 66 | #pragma config WDTPS = PS1048576 /*!< Watchdog Timer Postscaler (1:1048576) */ |
| 67 | #pragma config FWDTEN = OFF /*!< Watchdog Timer Enable (WDT Disabled (SWDTEN Bit Controls)) */ |
| 68 | |
| 69 | /* DEVCFG0 */ |
| 70 | #pragma config DEBUG = OFF /*!< Background Debugger Enable (Debugger is disabled) */ |
| 71 | #pragma config ICESEL = ICS_PGx2 /*!< ICE/ICD Comm Channel Select (ICE EMUC2/EMUD2 pins shared with PGC2/PGD2) */ |
| 72 | #pragma config PWP = OFF /*!< Program Flash Write Protect (Disable) */ |
| 73 | #pragma config BWP = OFF /*!< Boot Flash Write Protect bit (Protection Disabled) */ |
| 74 | #pragma config CP = OFF /*!< Code Protect (Protection Disabled) */ |
| 75 | |
| 76 | /******************************************************************************/ |
| 77 | /************************* Variables Definitions ******************************/ |
| 78 | /******************************************************************************/ |
| 79 | extern const char* cmdList[]; |
| 80 | extern const char* cmdDescription[]; |
| 81 | extern const char* cmdExample[]; |
| 82 | extern const char cmdNo; |
| 83 | extern cmdFunction cmdFunctions[]; |
| 84 | |
| 85 | /***************************************************************************//** |
| 86 | * @brief Main function. |
| 87 | * |
| 88 | * @return None. |
| 89 | *******************************************************************************/ |
| 90 | void main(void) |
| 91 | { |
| 92 | char receivedCmd[20]; |
| 93 | double param[5]; |
| 94 | char cmd = 0; |
| 95 | char paramNo = 0; |
| 96 | char cmdType = -1; |
| 97 | char invalidCmd = 0; |
| 98 | |
| 99 | /*!< Initialize the console. */ |
| 100 | CONSOLE_Init(9600); |
| 101 | TIME_DelayMs(10); |
| 102 | |
| 103 | /*!< Initialize the device. */ |
| 104 | DoDeviceInit(); |
| 105 | |
| 106 | while(1) |
| 107 | { |
| 108 | /*!< Read the command entered by user through UART. */ |
| 109 | CONSOLE_GetCommand(receivedCmd); |
| 110 | |
| 111 | invalidCmd = 0; |
| 112 | for(cmd = 0; cmd < cmdNo; cmd++) |
| 113 | { |
| 114 | paramNo = 0; |
| 115 | cmdType = CONSOLE_CheckCommands(receivedCmd, cmdList[cmd], param, ¶mNo); |
| 116 | if(cmdType == UNKNOWN_CMD) |
| 117 | { |
| 118 | invalidCmd++; |
| 119 | } |
| 120 | else |
| 121 | { |
| 122 | cmdFunctions[cmd](param, paramNo); |
| 123 | } |
| 124 | } |
| 125 | /*!< Send feedback to user, if the command entered by user is not a valid one. */ |
| 126 | if(invalidCmd == cmdNo) |
| 127 | { |
| 128 | CONSOLE_Print("Invalid command!\r\n"); |
| 129 | } |
| 130 | } |
| 131 | } |