~ubuntu-branches/ubuntu/quantal/picprog/quantal

« back to all changes in this revision

Viewing changes to picport.cc

  • Committer: Package Import Robot
  • Author(s): Koichi Akabe
  • Date: 2011-12-03 10:08:38 UTC
  • mfrom: (4.1.3 sid)
  • Revision ID: package-import@ubuntu.com-20111203100838-f05iyixkqjdh2byd
Tags: 1.9.1-2
* debian/control
  - changed priority from extra to optional
  - narrowed environments: linux-any kfreebsd-any

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- c++ -*-
2
2
 
3
3
This is Picprog, Microchip PIC programmer software for the serial port device.
4
 
Copyright © 1997,2002,2003,2004,2006,2007,2008 Jaakko Hyvätti
 
4
Copyright © 1997,2002,2003,2004,2006,2007,2008,2010 Jaakko Hyvätti
5
5
 
6
 
This program is free software; you can redistribute it and/or modify
7
 
it under the terms of the GNU General Public License version 2 as
8
 
published by the Free Software Foundation.
 
6
This program 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 3 of the License, or
 
9
(at your option) any later version.
9
10
 
10
11
This program is distributed in the hope that it will be useful,
11
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
14
GNU General Public License for more details.
14
15
 
15
16
You should have received a copy of the GNU General Public License
16
 
along with this program; if not, write to the Free Software Foundation,
17
 
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
17
along with this program.  If not, see http://www.gnu.org/licenses/ .
18
18
 
19
19
The author may be contacted at:
20
20
 
23
23
Phone: +358 40 5011222
24
24
 
25
25
Please send any suggestions, bug reports, success stories etc. to the
26
 
Email address above.
 
26
Email address above.  Include word 'picprog' in the subject line to
 
27
make sure your email passes my spam filtering.
27
28
 
28
29
*/
29
30
 
31
32
#include <fstream>
32
33
#include <iomanip>
33
34
#include <string>
 
35
#include <cstring>
 
36
#include <cstdlib>
 
37
#include <cerrno>
 
38
#include <ctime>
34
39
 
35
40
#include <sys/ioctl.h>
36
 
#include <sys/io.h>
 
41
 
 
42
#if defined(__i386__) || defined(__x86_64__)
 
43
  #include <sys/io.h>
 
44
  #define HAVE_IOPL
 
45
#endif
 
46
 
37
47
#include <fcntl.h>
38
 
#include <errno.h>
39
 
#include <time.h>
40
48
#include <sys/time.h>
41
 
#include <stdlib.h>
42
49
#include <unistd.h>
43
50
#include <termios.h>
44
51
#include <sysexits.h>
45
 
#include <string.h>
46
52
#include <sched.h>
47
53
 
48
54
#include "picport.h"
159
165
    // Not root.  Cannot use realtime scheduling.
160
166
    use_nanosleep = 0;
161
167
  }
 
168
#ifdef HAVE_IOPL
162
169
  if (iopl (3))
163
170
    disable_interrupts = 0;
 
171
#else
 
172
  disable_interrupts = 0;
 
173
#endif
164
174
 
165
175
#ifdef CPU_SETSIZE
166
176
  // When computing the delay loops, we do not want the cpu's to change.
277
287
  set_clock_data (0, 0);
278
288
  set_vpp (1);
279
289
  // Charge Vdd
280
 
  usleep (10000);
 
290
  usleep (25000);
281
291
 
282
292
  // Detect delays that are needed for cable lenght
283
293
  bool successful_echo = false;
402
412
{
403
413
  struct timeval tv1, tv2;
404
414
  gettimeofday (&tv1, 0);
 
415
#if defined(__i386__) or defined(__x86_64__)
405
416
  if (tsc_1000ns > 1 && disable_interrupts)
406
417
    asm volatile("pushf; cli");
 
418
#endif
407
419
  set_clock_data (1, b); // set data, clock up
408
420
  delay (cable_delay);
409
421
  set_clock_data (0, b); // clock down
 
422
#if defined(__i386__) or defined(__x86_64__)
410
423
  if (tsc_1000ns > 1 && disable_interrupts)
411
424
    asm volatile("popf");
 
425
#endif
412
426
  gettimeofday (&tv2, 0);
413
427
 
414
428
  // We may have spent a long time in an interrupt or in another task
427
441
{
428
442
  struct timeval tv1, tv2;
429
443
  gettimeofday (&tv1, 0);
 
444
#if defined(__i386__) or defined(__x86_64__)
430
445
  if (tsc_1000ns > 1 && disable_interrupts)
431
446
    asm volatile("pushf; cli");
 
447
#endif
432
448
  set_clock_data (1, 1); // clock up
433
449
  delay (cable_delay);
434
450
  set_clock_data (0, 1); // set data up, clock down
 
451
#if defined(__i386__) or defined(__x86_64__)
435
452
  if (tsc_1000ns > 1 && disable_interrupts)
436
453
    asm volatile("popf");
 
454
#endif
437
455
  gettimeofday (&tv2, 0);
438
456
 
439
457
  // We may have spent a long time in an interrupt or in another task