/***************************************************************************** * startup.c - Accu-Vote startup code * * Copyright (c) 1996 by Global Election Systems Inc. * * The authors hereby grant permission to use, copy, modify, distribute, * and license this software and its documentation for any purpose, provided * that existing copyright notices are retained in all copies and that this * notice and the following disclaimer are included verbatim in any * distributions. No written agreement, license, or royalty fee is required * for any of the authorized uses. * * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ****************************************************************************** * REVISION HISTORY * * 97-02-12 Guy Lancaster , Global Election Systems Inc. * Modified from 1.94m. *****************************************************************************/ #include "typedefs.h" #include "avconfig.h" #include "v25.h" #include "avos.h" #include "stdio.h" #include "memory.h" #include "malloc.h" #include "timer.h" #include "rand.h" #include "netbuf.h" #include "time.h" #include "poll.h" #include "devio.h" #include "siodev.h" #include "lptdev.h" #include "butctrl.h" #include "powrctrl.h" #include "fedrctrl.h" #include "motrctrl.h" #include "scanctrl.h" #include "net.h" #include "diagmode.h" #include "startup.h" #include "debug.h" void main(UINT buttonState); /*************************/ /*** LOCAL DEFINITIONS ***/ /*************************/ // The main stack needs to be large enough to handle the main application // plus all the interrupt handlers. #define STACK_MAIN_SIZE (12*1024) /***********************************/ /*** LOCAL FUNCTION DECLARATIONS ***/ /***********************************/ static void shutdown(void); static void mainTask(void *data); /*****************************/ /*** LOCAL DATA STRUCTURES ***/ /*****************************/ static char mainTaskStack[STACK_MAIN_SIZE]; /***********************************/ /*** PUBLIC FUNCTION DEFINITIONS ***/ /***********************************/ /* Startup up the system - initialize the OS and start the main task. */ void startup(void) { setvect(uCOS, OSCtxSw); OSInit(); OSTaskCreate(mainTask, NULL, mainTaskStack + STACK_MAIN_SIZE, PRI_MAIN); OSStart(); /*** Never reached! ***/ } /* * Initialize all subsystems and then call main(). */ #pragma argsused static void mainTask(void *data) { ULONG memSize, heapSize; void *heapStart; #ifndef PDR // Debugger version uses a fixed memory allocation. void *saveBlock; UINT saveSize; #endif /* * Check the buttons before running the memory test so that the user * doesn't have to hold them. */ UINT buttonStatus = buttonStatus(); debugInit(); // Initialize trace structures avosInit(shutdown); // Start the OS services memSize = memoryInit(); // Determine size of memory heapStart = heap0Start; heapSize = (memSize * KILOBYTE) - MK_LP(heapStart); mallocInit(heapStart, heapSize); // Initialize malloc space init_files(); // Open stdin, stdout, stderr printf(BOOTMSG, romRelease); // Display boot message /* Check that we have at least 128K in the heap */ if (heapSize < MAXRAMSEGMENT * KILOBYTE) { printf(MSMEMMIN, heapSize / KILOBYTE, 0); HALT(); /* not reached */ } #ifndef PDR /* System memory test */ if ((saveSize = maxalloc()) < 32U * KILOBYTE || (saveBlock = malloc(saveSize)) == NULL || (systemMemTest(saveBlock, saveSize)) != NULL) { printf(MSSTESTFAIL); HALT(); /* not reached */ } free(saveBlock); #endif sioInit(); /* Initialize the serial I/O stats. */ nBufInit(); /* Initialize the network buffers. */ timerInit(); /* Initialize timer subsystem. */ clk_init(); /* Initialize real time clock */ initPowerMonitor(); /* Initialize power fail monitor */ motorInit(); /* Initialize motor control process */ feederInit(); /* Initialize the feeder control */ scanInit(); /* Initialize the scanner driver. */ netInit(); /* Initialize network subsystems. */ avRandomInit(); /* Initialize the random number generator. */ monStart(); /* Start the diagnostics monitor (if enabled). */ OSTimeDly(10); /* Let lower priority processes run. */ if ((buttonStatus & YESNOBUTTON) == YESNOBUTTON) diagmode(); main(buttonStatus); /* NOT REACHED */ } /**********************************/ /*** LOCAL FUNCTION DEFINITIONS ***/ /**********************************/ /* * Shut down the system devices - This is the application shutdown function * submitted to AVOS for use when halting the system. This way we will * (hopefully) avoid halting with the motor or printer still running. * We assume here that task switching is disabled and that no interrupt * handler is going to undo what we've done here. */ static void shutdown(void) { /* Ensure that the printer is off. */ ptr0Off(); /* Ensure that the feeder is off. */ feederOff(); /* * Ensure that the scanner motor is stopped. We don't bother to try * to clear the scanner here since that is more likely to confuse * the operator than just stopping with an unprocessed ballot in * the scanner. */ motorStop(); }