1 /*
2    Copyright (C) 2001 Salvador E. Tropea
3 
4 This file is part of gpsim.
5 
6 gpsim is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10 
11 gpsim is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15 
16 You should have received a copy of the GNU General Public License
17 along with gpsim; see the file COPYING.  If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.  */
20 
21 
22 #include <iostream>
23 #include <iomanip>
24 #include <string>
25 #include <vector>
26 
27 #include "command.h"
28 #include "cmd_frequency.h"
29 
30 #include "../src/pic-processor.h"
31 
32 static cmd_options cmd_frequency_options[] =
33 {
34   {0,0,0}
35 };
36 
cmd_frequency(void)37 cmd_frequency::cmd_frequency(void)
38   : command("frequency", "freq")
39 {
40 
41   brief_doc = string("Set the clock frequency");
42 
43   long_doc = string ("\nfrequency [value]\n"
44     "\tThis command sets the clock frequency. By default gpsim uses 4 MHz\n"
45     "\tas clock. The clock frequency is used to compute time in seconds.\n"
46     "\tUse this command to adjust this value.\n"
47     "\tIf no value is provided this command prints the current clock.\n"
48     "\tNote that PICs have an instruction clock that's a forth of the\n"
49     "\texternal clock. This value is the external clock.\n");
50 
51   op = cmd_frequency_options;
52 }
53 
54 
set(Expression * expr)55 void cmd_frequency::set(Expression *expr)
56 {
57 
58   Processor *pCpu = GetActiveCPU(true);
59   if(!pCpu)
60     return;
61 
62   double frequency = evaluate(expr);
63 
64   if(frequency <= 0.0)
65     cout << "Error: the clock must be a positive value.\n";
66   else
67     pCpu->set_frequency(frequency);
68 
69 }
70 
print()71 void cmd_frequency::print()
72 {
73   Processor *pCpu = GetActiveCPU(true);
74   if(pCpu)
75     cout << "Clock frequency: " << pCpu->get_frequency()/1e6 << " MHz.\n";
76 }
77 
78 cmd_frequency frequency;
79