100317

|



机。荒木取りしてシーズニングも済んだので天板の製材に。自動カンナの刃が終わっていて、筋ができてしまう。



なので刃を交換。実際、刃を見てみるとどってことなさそうなこぼれなんだけ ど。シーズニングした段階で節部分で思いっきり反っているようなのは応力が きつくてだめね。製材して数時間後からまた反りはじめてる。

H8SXはじめました。まずは本の付録のCDからルネサスのフラッシュ書き込みソ フトをインストールしてLED点滅プログラムを書き込んでピコピコするのを確認。
まずはugenからブートモードでの通信で、問合せだけ確認してみました。
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <assert.h>
#include <string.h>
#include <dev/usb/usb.h>

size_t inquire (uint8_t);

int control_pipe;
int bulkout_pipe;
int bulkin_pipe;
uint8_t buf[256];

int
main ()
{
  int i;

// コントロールパイプを開きます。
  if ((control_pipe = open ("/dev/ugen0.00", O_RDWR)) < 0)
    {
      perror ("Can't open control pipe");
      return 1;
    }

// バルクアウトパイプを開きます。
  if ((bulkout_pipe = open ("/dev/ugen0.01", O_WRONLY)) < 0)
    {
      perror ("Can't open bulk-out pipe");
      close (control_pipe);
      return 1;
    }

// バルクインパイプを開きます。
  if ((bulkin_pipe = open ("/dev/ugen0.02", O_RDONLY)) < 0)
    {
      perror ("Can't open bulk-in pipe");
      close (bulkout_pipe);
      close (control_pipe);
      return 1;
    }

// バルクインパイプはread(2)で指定されたサイズよりも少なくてもいい
// ように設定します。これがないとだめ。逆に1バイトづつというのもだめ。
  i = 1;
  if (ioctl (bulkin_pipe, USB_SET_SHORT_XFER, &i) < 0)
    {
      perror ("short xfer failed.\n");
      goto error;
    }

// ここは指定された初期手順。
  uint8_t a = 0x55;
  if (write (bulkout_pipe, &a, 1) != 1)
    {
      fprintf (stderr, "0x55 failed\n");
    }
  a = 0;
  if (read (bulkin_pipe, &a, 1) != 1)
    {
      fprintf (stderr, "no 0xx55 response\n");
      goto error;
    }
  if (a != 0xe6)
    {
      fprintf (stderr, "Invalid boot program response: %x\n", a);
      goto error;
    }

// 問合せを全て試します。
  if (!inquire (0x20))
    goto error;
  if (!inquire (0x21))
    goto error;
  if (!inquire (0x22))
    goto error;
  if (!inquire (0x23))
    goto error;
  if (!inquire (0x24))
    goto error;
  if (!inquire (0x25))
    goto error;
  if (!inquire (0x26))
    goto error;
  if (!inquire (0x27))
    goto error;
  if (!inquire (0x4f))
    goto error;

 error:
  close (bulkout_pipe);
  close (bulkin_pipe);
  close (control_pipe);

  return 0;

}

size_t
inquire (uint8_t command)
{
  uint8_t response, checksum;
  size_t sz, data_sz;
  int i;

  memset (buf, 0, sizeof buf);
  printf ("Command %x: ", command);

//コマンドを送出
  if (write (bulkout_pipe, &command, 1) != 1)
    {
      perror ("Command issue failed");
      return 0;
    }

//レスポンスを読み出し。この段階では最後のチェックサムは読みだされない。
  if ((sz = read (bulkin_pipe, buf, sizeof buf)) == -1)
    {
      perror ("Command didn't respond");
      return 0;
    }

//成功のレスポンスを確認
  if ((response = buf[0]) != command + 0x10)
    {
      perror ("Invalid response");
      return 0;
    }
//0x26の消去ブロック情報問い合わせだけはサイズが2バイトなので特別処理
//それ以外の+2はレスポンス(1バイト)+サイズ(1バイト)の2バイト
  if (command == 0x26)
    // +3 are response(1byte) + size(2byte)
    data_sz = (buf[1] << 8) | (buf[2] + 3);
  else
    // +2 are response(1byte) + size(1byte)
    data_sz = buf[1] + 2;
  if (data_sz != sz)
    {
      fprintf (stderr, "Mismatch data size. %ld != %ld\n", data_sz + 2, sz);
      return 0;
    }

  printf ("read %ldbyte\n", sz);
  printf ("{ ");
  for (i = 0, checksum = 0; i < sz; i++)
    {
      checksum += buf[i];
      printf ("0x%x, ", buf[i]);
    }
  printf ("}\n");

//ここでチェックサムの1バイトを読み込む。
  if (read (bulkin_pipe, buf, 1) < 0)
    {
      perror ("Can't read checksum");
      return 0;
    }
//チェックサムの計算。マニュアルには「コマンドからSUMまで加算し、H'00にな
//るように設定」とあるけれど間違い。「レスポンスからSUMまで加算し、
//H'00になるように設定」です。
  if ((checksum += buf[0]) != 0)
    {
      perror ("Checksum error");
      return 0;
    }

  return sz;
}
H8/1655、マニュアルがいい加減だし、更新も遅れている。