summaryrefslogtreecommitdiffstats
path: root/src/progs/pickit1/base/pickit1.cpp
blob: 31d5787ffaa8221386d7623cbd2ef0aa0b204d95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/***************************************************************************
 * Copyright (C) 2006 Nicolas Hadacek <hadacek@kde.org>                    *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 ***************************************************************************/
#include "pickit1.h"

bool Pickit1::Baseline::init()
{
  Array cmd;
  cmd[0] = 'c';
  cmd[1] = 0x00;  // Load Configuration
  cmd[2] = 0x02;  // Load Program latches
  cmd[3] = 0x03;  // Load Data latches
  cmd[4] = 0x04;  // Read Program memory
  cmd[5] = 0x05;  // Read Data latches
  cmd[6] = 0x06;  // Increment Address
  cmd[7] = 0x08;  // Begin programming internally timed
  if ( !hardware().port().command(cmd) ) return false;
  cmd[0] = 0x08;  // Begin Programming externally timed
  cmd[1] = 0x0E;  // End externally time programming cycle
  cmd[2] = 0x09;  // Bulk Erase program memory
  cmd[3] = 0x0B;  // Bulk Erase Data memory
  cmd[4] = 0xFF;  // Read Program memory
  cmd[5] = 0xFF;  // Read Data latches
  cmd[6] = 0xFF;  // Increment Address
  cmd[7] = 0xFF;  // Begin programming internally timed
  return hardware().port().command(cmd);
}

bool Pickit1::Baseline::incrementPC(uint nb)
{
  if ( (nb & 0xFF)!=0 ) return Pickit::Baseline::incrementPC(nb);
  // work around bugs in firmware
  Array cmd;
  uint high = (nb >> 8) & 0xFF;
  log(Log::DebugLevel::Extra, TQString("work around bug in firmware (nb_inc=%1 high=%2)")
                       .arg(toHexLabel(nb, 4)).arg(toHexLabel(high, 2)));
  if ( high==1 ) {
      cmd[0] = 'I';
      cmd[1] = 0x40;
      cmd[2] = 0x00;
      cmd[3] = 'I';
      cmd[4] = 0xC0;
      cmd[5] = 0x00;
  } else {
    cmd[0] = 'I';
    cmd[1] = 0x00;
    cmd[2] = high-1;
  }
  return hardware().port().command(cmd);
}

//----------------------------------------------------------------------------
bool Pickit1::P16F::init()
{
  Array cmd;
  cmd[0] = 'c';
  cmd[1] = 0x00;   // Load Configuration
  cmd[2] = 0x02;   // Load Program latches
  cmd[3] = 0x03;   // Load Data latches
  cmd[4] = 0x04;   // Read Program memory
  cmd[5] = 0x05;   // Read Data latches
  cmd[6] = 0x06;   // Increment Address
  cmd[7] = 0x08;   // Begin programming internally timed
  if ( !hardware().port().command(cmd) ) return false;
  cmd[0] = 0x18;   // Begin Programming externally timed
  cmd[1] = 0x0A;   // End externally time programming cycle
  cmd[2] = 0x09;  // Bulk Erase program memory
  cmd[3] = 0x0B;  // Bulk Erase Data memory
  cmd[4] = 0xFF;  // Read Program memory
  cmd[5] = 0xFF;  // Read Data latches
  cmd[6] = 0xFF;  // Increment Address
  cmd[7] = 0xFF;  // Begin programming internally timed
  return hardware().port().command(cmd);
}

bool Pickit1::P16F716::init()
{
  Array cmd;
  cmd[0] = 'c';
  cmd[1] = 0x00;   // Load Configuration
  cmd[2] = 0x02;   // Load Program latches
  cmd[3] = 0x03;   // Load Data latches
  cmd[4] = 0x04;   // Read Program memory
  cmd[5] = 0x05;   // Read Data latches
  cmd[6] = 0x06;   // Increment Address
  cmd[7] = 0x08;   // Begin programming internally timed
  if ( !hardware().port().command(cmd) ) return false;
  cmd[0] = 0x18;   // Begin Programming externally timed
  cmd[1] = 0x0E;   // End externally time programming cycle
  cmd[2] = 0x09;  // Bulk Erase program memory
  cmd[3] = 0x0B;  // Bulk Erase Data memory
  cmd[4] = 0xFF;  // Read Program memory
  cmd[5] = 0xFF;  // Read Data latches
  cmd[6] = 0xFF;  // Increment Address
  cmd[7] = 0xFF;  // Begin programming internally timed
  return hardware().port().command(cmd);
}