trap-main.c

Description | Download | Table of Contents | Modules | Compound List | File List | Functions


Overview
Compiler
Documentation
Examples
Misc
Help
IDE & Tools

Download
Install

Links
Projects






00001 /* Trap example for 68HC11
00002    Copyright (C) 1999, 2001 Free Software Foundation, Inc.
00003    Written by Stephane Carrez (stcarrez@worldnet.fr)    
00004 
00005 This file is free software; you can redistribute it and/or modify it
00006 under the terms of the GNU General Public License as published by the
00007 Free Software Foundation; either version 2, or (at your option) any
00008 later version.
00009 
00010 In addition to the permissions in the GNU General Public License, the
00011 Free Software Foundation gives you unlimited permission to link the
00012 compiled version of this file with other programs, and to distribute
00013 those programs without any restriction coming from the use of this
00014 file.  (The General Public License restrictions do apply in other
00015 respects; for example, they cover modification of the file, and
00016 distribution when not linked into another program.)
00017 
00018 This file is distributed in the hope that it will be useful, but
00019 WITHOUT ANY WARRANTY; without even the implied warranty of
00020 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00021 General Public License for more details.
00022 
00023 You should have received a copy of the GNU General Public License
00024 along with this program; see the file COPYING.  If not, write to
00025 the Free Software Foundation, 59 Temple Place - Suite 330,
00026 Boston, MA 02111-1307, USA.  */
00027 
00051 #include "trap.h"
00052 
00053 extern int global_result;
00054 
00055 int
00056 main()
00057 {
00058   int result;
00059   int failed;
00060 
00061   /* Test with simple trap handler.  */
00062   set_interrupt_handler (SWI_VECTOR, (interrupt_t) simple_trap_handler);
00063   print ("Using simple trap handler: ");
00064   failed = 0;
00065   simple_trap_handler (1);
00066   if (global_result != 1)
00067     {
00068       print ("  Simple trap handler failed, didn't returned 1\r\n");
00069       failed = 1;
00070     }
00071   
00072   simple_trap_handler (2);
00073   if (global_result != 4)
00074     {
00075       print ("  Simple trap handler failed, didn't returned 4\r\n");
00076       failed = 1;
00077     }
00078   if (failed == 0)
00079     print ("OK\r\n");
00080 
00081   /* Test with add trap handler.  */
00082   set_interrupt_handler (SWI_VECTOR, (interrupt_t) add_trap_handler);
00083   failed = 0;
00084   print ("Using add trap handler: ");
00085   result = add_trap_handler (1, 2, 3, 4);
00086   if (result != 10)
00087     {
00088       print ("Add trap handler didn't returned 10\r\n");
00089       failed = 1;
00090     }
00091   result = add_trap_handler (5, 6, 7, 8);
00092   if (result != 26)
00093     {
00094       print ("Add trap handler didn't returned 26\r\n");
00095       failed = 1;
00096     }
00097   if (failed == 0)
00098     print ("OK\r\n");
00099 
00100   set_interrupt_handler (SWI_VECTOR, (interrupt_t) os_trap_handler);
00101   failed = 0;
00102   print ("Using OS trap handler...\r\n");
00103   result = os_trap_handler (0, "  Hello World from os_trap_handler...\r\n");
00104   if (result != 0)
00105     {
00106       print ("  OS call 0 failed\r\n");
00107       failed = 1;
00108     }
00109 
00110   result = os_trap_handler (0, "  Type a character ");
00111   if (result != 0)
00112     {
00113       print ("  OS call 0 failed\r\n");
00114       failed = 1;
00115     }
00116   
00117   result = os_trap_handler (1);
00118 
00119   result = os_trap_handler (2, 23, 44);
00120   if (result != 23 + 44)
00121     {
00122       print ("  OS add system call failed\r\n");
00123       failed = 1;
00124     }
00125   
00126   if (failed == 0)
00127     print ("OS trap call test ok.\r\n");
00128   
00129   print ("Trap handler test finished.\r\n");
00130   return 0;
00131 }

Description | Download | Table of Contents | Modules | Compound List | File List | Functions

    Last modified,
    Apr 16, 2001
[ Copying ]     [ Feedback to Stephane.Carrez@worldnet.fr ]