/* GNU license implied
    Copyright (C) 2001 Matthias Schoeldgen DC7UR (m.schoeldgen@b-cool.de)
    
    short program to set the SPI to a value from command line.
   connected to the serial port is a shift register with 8 outputs.
   the higher 4 bits are connected to the motor driver chip L293D
   in the following manner :
    bit 4 = motor 1 pin +
    bit 5 = motor 1 pin -
    bit 6 = motor 2 pin +
    bit 7 = motor 2 pin -
    Example : 
    0xa0 : both motors forward
    0x50 : both motors reverse
    0x60 : motor 2 reverse, motor 1 forward
    0x90 : motor 2 forward, motor 1 reverse
    0x00 : both motors braking
    the driving force is set by the PWM output, enabling the driver chip.
    reading from spi is not yet implemented.
    For initialising the CPU hardware, refer to inithard.c.
    */	
    
#include <asm/MC68EZ328.h> 
//#include <stdlib.h>
/* #include <string.h>
*/
#include <stdio.h>
void set_spi(unsigned short value)
{
    SPIMDATA = value;    /* poke data*/
    SPIMCONT |= 0x0100 ; /* transfer start */
}

int main(int argc, char *argv[])
{
unsigned int val;
switch (argc) {
    case 2:	sscanf(argv[1], "%d",&val);
		if (val > 255) val = 255;
		set_spi(val);
		break;
    default : 	printf("Sets SPI for MC68EZ328. usage: setspi value\n");
		break;
	}
exit(0);
}
