📄 main.c
字号:
//*****************************************************************************
//
// main.c - Main application for the main CNC microcontroller.
//
// Copyright (c) 2006-2007 Luminary Micro, Inc. All rights reserved.
//
// Software License Agreement
//
// Luminary Micro, Inc. (LMI) is supplying this software for use solely and
// exclusively on LMI's microcontroller products.
//
// The software is owned by LMI and/or its suppliers, and is protected under
// applicable copyright laws. All rights are reserved. Any use in violation
// of the foregoing restrictions may subject the user to criminal sanctions
// under applicable laws, as well as to civil liability for the breach of the
// terms and conditions of this license.
//
// THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
// OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
// LMI SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
// CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
//
// This is part of revision 220 of sw01246.
//
//*****************************************************************************
#include <hw_memmap.h>
#include <hw_types.h>
#include <gpio.h>
#include <sysctl.h>
#include <systick.h>
#include "demo.h"
#include "draw.h"
#include "i2c_slave.h"
#include "images.h"
#include "main.h"
#include "stepper.h"
#include "switches.h"
#include "table.h"
#include "tool.h"
#include "virtualtimer.h"
//*****************************************************************************
//
//! \page main_main_intro Introduction
//!
//! This is the main application entry point for the main microcontroller
//! application. It is responsible for system level configuration of the
//! LM3S615 microcontroller, calling the initialization routines for the
//! various drivers and interfaces, and handling the top-level main control
//! loop.
//!
//! The top-level main control loop is responsible for waiting until the CNC
//! machine has been instructed to run and performing the requested action. It
//! can either start one of the six demos or moving the machine into the
//! shipping position. Once the requested action has been performed, it will
//! simply wait for the next action request. The main control loop will also
//! perform table homing operations when required; this will occur right before
//! a requested action is performed when the table is in need of a homing
//! operation (i.e. after the panic switch has been pressed and released).
//!
//! The code for the main application entry point is contained in
//! <tt>main_micro/main.c</tt>, with <tt>main_micro/main.h</tt> containing the
//! API definitions for use by the remainder of the application.
//
//*****************************************************************************
//*****************************************************************************
//
//! \defgroup main_main_api Definitions
//! @{
//
//*****************************************************************************
系统
//*****************************************************************************
//
//! The system clock rate. This value might not be something "clean" like系统时钟频率。
//! 50,000,000 since a combination of the input crystal frequency along with
//! the PLL multiplier and divider might make it impossible to get to an exact
//! value, though it will be real close. For the case of the 6 MHz crystal on
//! the CNC machine circuit board, it will be precisely 50,000,000.
//
//*****************************************************************************
unsigned long g_ulSysClock;
//*****************************************************************************
//
//! The demo mode that has been selected.
//
//*****************************************************************************
unsigned long g_ulDemoMode;
//*****************************************************************************
//
//! The name string that was sent over the I2C interface.
//
//*****************************************************************************
char g_pcNameString[256];
//*****************************************************************************
//
//! The set of icons that were selected.
//
//*****************************************************************************
unsigned long g_ulIcons;
//*****************************************************************************
//
//! The tool that has been selected.
//
//*****************************************************************************
unsigned long g_ulTool;
//*****************************************************************************
//
//! A set of flags providing overall control of the machine; contains the
//! #MAIN_FLAG_RUN and #MAIN_FLAG_SHIP flags.
//
//*****************************************************************************
unsigned long g_ulFlags;
//*****************************************************************************
//
//! The error routine that is called if the driver library encounters an error.
//
//*****************************************************************************
#ifdef DEBUG
void
__error__(char *pcFilename, unsigned long ulLine)
{
}
#endif
//*****************************************************************************
//
//! Handles setup of the application on the main CNC microcontroller.
//!
//! This is the main application entry point for the main CNC microcontroller.
//! It is responsible for basic system configuration, initialization of the
//! various application drivers and peripherals, and the main application loop.
//!
//! \return Never returns.
//
//*****************************************************************************
int
main(void)
{
//
// Configure the processor to run at 50MHz.
//
SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_6MHZ |
SYSCTL_OSC_MAIN | SYSCTL_INT_OSC_DIS);
g_ulSysClock = SysCtlClockGet();
//
// Enable the peripherals used by the application.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM);
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2);
//
// Enable the weak pull-downs instead of the weak pull-ups.
//
GPIOPadConfigSet(GPIO_PORTA_BASE,
(GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 |
GPIO_PIN_4 | GPIO_PIN_5), GPIO_STRENGTH_2MA,
GPIO_PIN_TYPE_STD_WPD);
GPIOPadConfigSet(GPIO_PORTB_BASE,
(GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 |
GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7),
GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPD);
GPIOPadConfigSet(GPIO_PORTC_BASE,
(GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 |
GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7),
GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPD);
GPIOPadConfigSet(GPIO_PORTD_BASE,
(GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 |
GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7),
GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPD);
GPIOPadConfigSet(GPIO_PORTE_BASE,
GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3,
GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPD);
//
// Initialize the virtual timers.
//
VirtualTimerInit();
//
// Initialize the switches.
//
SwitchesInit();
//
// Initialize the stepper motors.
//
StepperInit();
//
// Initialize the drawing routines.
//
DrawInit();
//
// Initialize the tool control.
//
ToolInit();
//
// Initialize the I2C slave interface.
//
I2CInit();
//
// Find the home position so that the table is in a known position.
//
TableHome();
//
// Uncomment the following line to enable manual mode control of the
// machine.
//
//ManualMode();
//
// Loop forever.
//
while(1)
{
//
// Wait until the machine has been told to start running.
//
while(HWREGBITW(&g_ulFlags, MAIN_FLAG_RUN) == 0)
{
}
//
// See if the table requires homing.
//
if(TableNeedsHoming() == true)
{
//
// Return the table to the home position.
//
TableHome();
}
//
// See if the machine should be put into the shipping position.
//
if(HWREGBITW(&g_ulFlags, MAIN_FLAG_SHIP) == 0)
{
//
// Determine which demo to run.
//
switch(g_ulDemoMode)
{
//
// The first demo; a logo and text on a business card.
//
case 1:
{
//
// Run the first demo.
//
Demo1();
//
// This demo is complete.
//
break;
}
//
// The second demo; a logo and text in a box.
//
case 2:
{
//
// Run the second demo.
//
Demo2();
//
// This demo is complete.
//
break;
}
//
// The third demo; a steer head.
//
case 3:
{
//
// Run the third demo.
//
Demo3();
//
// This demo is complete.
//
break;
}
//
// The fourth demo; a printed circuit board.
//
case 4:
{
//
// Run the fourth demo.
//
Demo4();
//
// This demo is complete.
//
break;
}
//
// The firth demo; the United States flag.
//
case 5:
{
//
// Run the fifth demo.
//
Demo5();
//
// This demo is complete.
//
break;
}
//
// The sixth demo; the map of the world.
//
case 6:
{
//
// Run the sixth demo.
//
Demo6();
//
// This demo is complete.
//
break;
}
}
}
else
{
//
// Move the machine to the shipping position.
//
DemoShip();
//
// Indicate that the machine no longer needs to be moved to the
// shipping position.
//
HWREGBITW(&g_ulFlags, MAIN_FLAG_SHIP) = 0;
}
//
// Indicate that the machine has finished running.
//
HWREGBITW(&g_ulFlags, MAIN_FLAG_RUN) = 0;
}
//
// The following code is unreachable; it is provided in the unlikely event
// that the above loop is broken out of (via programmer error). Turn off
// warnings that may be produced by some tool chains about this unreachable
// code.
//
#if defined(ewarm)
#pragma diag_suppress=Pe111
#endif
#if defined(rvmdk) || defined(__ARMCC_VERSION)
#pragma diag_suppress 111
#endif
//
// This should never be executed, but just in case, do a full system reset.
//
SysCtlReset();
//
// Turn the warnings back on for the remainder of the file.
//
#if defined(ewarm)
#pragma diag_warning=Pe111
#endif
#if defined(rvmdk) || defined(__ARMCC_VERSION)
#pragma diag_warning 111
#endif
}
//*****************************************************************************
//
// Close the Doxygen group.
//! @}
//
//*****************************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -