OpenCores
URL https://opencores.org/ocsvn/openmsp430/openmsp430/trunk

Subversion Repositories openmsp430

[/] [openmsp430/] [trunk/] [fpga/] [actel_m1a3pl_dev_kit/] [software/] [spacewar/] [hardware.c] - Diff between revs 80 and 84

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 80 Rev 84
#include "msp430x20x3.h"
#include "msp430x20x3.h"
#include <signal.h>                    // Needed for using interrupts with msp430-gcc
#include <signal.h>                    // Needed for using interrupts with msp430-gcc
#include "spacewar.h"
#include "spacewar.h"
 
 
//************************************************************
//************************************************************
// externals
// externals
//
//
extern volatile unsigned char flags;
extern volatile unsigned char flags;
 
 
extern void reset_rkts(rkt_data *, rkt_data *);
extern void reset_rkts(rkt_data *, rkt_data *);
extern void reset_game(rkt_data *);
extern void reset_game(rkt_data *);
 
 
//************************************************************
//************************************************************
//
//
// init_hardware
// init_hardware
//
//
//    initalize all the MSP430 hardware before we start
//    initalize all the MSP430 hardware before we start
//
//
/* Description:
/* Description:
Sets up all the hardware in the MSP430 used by the SPACEWAR game.
Sets up all the hardware in the MSP430 used by the SPACEWAR game.
Stops the watchdog timer.  Sets the internal cpu clock to a maximun.
Stops the watchdog timer.  Sets the internal cpu clock to a maximun.
Sets the timer to cause an interrupt every 10ms.  Sets the SPI interface
Sets the timer to cause an interrupt every 10ms.  Sets the SPI interface
to talk to the dual DAC.  Sets the A to D to use an external reference
to talk to the dual DAC.  Sets the A to D to use an external reference
and unipolar operation.  Finally initializes all the variable used by the game.
and unipolar operation.  Finally initializes all the variable used by the game.
*/
*/
void init_all(rkt_data *rkt1, rkt_data *rkt2)
void init_all(rkt_data *rkt1, rkt_data *rkt2)
{
{
 
 
  WDTCTL = WDTPW + WDTHOLD;             // Stop watchdog timer
  WDTCTL = WDTPW + WDTHOLD;             // Stop watchdog timer
 
 
  BCSCTL1 = 0x08;                       // Setup DCO highest range
  BCSCTL1 = 0x08;                       // Setup DCO highest range
  DCOCTL = 0xe0;                        // biggest DCO
  DCOCTL = 0xe0;                        // biggest DCO
 
 
  P1OUT = 0x04;                         // TLV5618A CS high
  P1OUT = 0x04;                         // TLV5618A CS high
  P1DIR |= 0x01+0x04;                   // P1.0=LED, P1.2=TLV5618A_cs
  P1DIR |= 0x01+0x04;                   // P1.0=LED, P1.2=TLV5618A_cs
  P1SEL = 0x08;                         // P1.3 = VREF
  P1SEL = 0x08;                         // P1.3 = VREF
 
 
 
  //BCSCTL2 = 0x00;                       // SMCLK divider = 1
 
  //BCSCTL2 = 0x02;                       // SMCLK divider = 2
 
  //BCSCTL2 = 0x04;                       // SMCLK divider = 4
 
  BCSCTL2 = 0x06;                       // SMCLK divider = 8
  CCTL0 = CCIE;                         // CCR0 interrupt enabled
  CCTL0 = CCIE;                         // CCR0 interrupt enabled
  CCR0 = 23500;
  CCR0 = 23500;
  //CCR0 = 500;
 
  TACTL = TASSEL_2 + MC_1;              // SMCLK, upmode
  TACTL = TASSEL_2 + MC_1;              // SMCLK, upmode
  _BIS_SR(GIE);                         // enable interrupts
  _BIS_SR(GIE);                         // enable interrupts
 
 
  // USICTL0 |= USIPE7+USIPE6+USIPE5+USIMST+USIOE; // Port, SPI master
  // USICTL0 |= USIPE7+USIPE6+USIPE5+USIMST+USIOE; // Port, SPI master
  // USICKCTL = USIDIV_0+USISSEL_2+USICKPL;  // divide by 1 SMCLK, inactive high
  // USICKCTL = USIDIV_0+USISSEL_2+USICKPL;  // divide by 1 SMCLK, inactive high
  // USICTL0 &= ~USISWRST;                 // release USI for operation
  // USICTL0 &= ~USISWRST;                 // release USI for operation
  // USICTL1 = USICKPH;                    // take data on falling edge
  // USICTL1 = USICKPH;                    // take data on falling edge
 
 
  // SD16CTL = SD16SSEL_1;                 // exter ref, SMCLK
  // SD16CTL = SD16SSEL_1;                 // exter ref, SMCLK
  // SD16CCTL0 = SD16UNI + SD16SNGL;       // 256OSR, unipolar, inter
  // SD16CCTL0 = SD16UNI + SD16SNGL;       // 256OSR, unipolar, inter
  // SD16AE = 0;                           // P1.1 A4+, A4- = VSS
  // SD16AE = 0;                           // P1.1 A4+, A4- = VSS
  //                                       // P1.4 A2+, A2- = VSS
  //                                       // P1.4 A2+, A2- = VSS
  // SD16INCTL0 = SD16INCH_4;              // A4+/- start with rocket 1
  // SD16INCTL0 = SD16INCH_4;              // A4+/- start with rocket 1
  // SD16CCTL0 |= SD16SC;                  // Start A2D conversion
  // SD16CCTL0 |= SD16SC;                  // Start A2D conversion
 
 
  reset_rkts(rkt1, rkt2);               // reset rkt positons                        
  reset_rkts(rkt1, rkt2);               // reset rkt positons                        
  reset_game(rkt1);
  reset_game(rkt1);
  reset_game(rkt2);
  reset_game(rkt2);
  rkt1->game = 0;
  rkt1->game = 0;
  rkt2->game = 0;
  rkt2->game = 0;
  flags |= time_tick;                    // force an update at startup
  flags |= time_tick;                    // force an update at startup
}
}
 
 
 
 
//************************************************************
//************************************************************
//
//
// Timer A0 interrupt service routine
// Timer A0 interrupt service routine
//
//
/* Description:
/* Description:
Interrupt service routine for the timer.  The function sets a flag for the main
Interrupt service routine for the timer.  The function sets a flag for the main
loop to update object positions.
loop to update object positions.
*/
*/
interrupt (TIMERA0_VECTOR) irq_routine(void)
interrupt (TIMERA0_VECTOR) irq_routine(void)
{
{
 
 
//  P1OUT ^= 0x01;                        // Toggle P1.0
//  P1OUT ^= 0x01;                        // Toggle P1.0
  flags |= time_tick;                   // flag a timer tick has occured
  flags |= time_tick;                   // flag a timer tick has occured
}
}
 
 
//************************************************************
//************************************************************
//
//
// read_a2d
// read_a2d
//
//
/* Description:
/* Description:
Waits for present A to D to finish.  Reads 16 bit A to D value.  Switches
Waits for present A to D to finish.  Reads 16 bit A to D value.  Switches
A to D mux to a channel passed into function.  Starts another A to D on new
A to D mux to a channel passed into function.  Starts another A to D on new
mux input.  Returns int value read from last mux input A to D.
mux input.  Returns int value read from last mux input A to D.
*/
*/
unsigned int read_a2d(unsigned int next_mux)
unsigned int read_a2d(unsigned int next_mux)
{
{
  unsigned int last_a2d;
  unsigned int last_a2d;
 
 
  if (next_mux==SD16INCH_2) {
  if (next_mux==SD16INCH_2) {
    last_a2d = MY_CNTRL1;
    last_a2d = MY_CNTRL1;
  } else {
  } else {
    last_a2d = MY_CNTRL2;
    last_a2d = MY_CNTRL2;
  }
  }
 
 
  if (last_a2d & 0x8) {             // CCW
  if (last_a2d & 0x8) {             // CCW
    last_a2d = 0xE000;
    last_a2d = 0xE000;
  } else if (last_a2d & 0x4) {      // CW
  } else if (last_a2d & 0x4) {      // CW
    last_a2d = 0xB000;
    last_a2d = 0xB000;
  } else if (last_a2d & 0x2) {      // Thrust
  } else if (last_a2d & 0x2) {      // Thrust
    last_a2d = 0x8000;
    last_a2d = 0x8000;
  } else if (last_a2d & 0x1) {      // Fire
  } else if (last_a2d & 0x1) {      // Fire
    last_a2d = 0x4000;
    last_a2d = 0x4000;
  } else {
  } else {
    last_a2d = 0x0000;
    last_a2d = 0x0000;
  }
  }
 
 
  //while ((SD16CCTL0 & SD16IFG) == 0); // wait for a2d to finish
  //while ((SD16CCTL0 & SD16IFG) == 0); // wait for a2d to finish
  //last_a2d = SD16MEM0;                // save results from last a2d
  //last_a2d = SD16MEM0;                // save results from last a2d
  //SD16INCTL0 = next_mux;              // switch analog mux for next rocket
  //SD16INCTL0 = next_mux;              // switch analog mux for next rocket
  //SD16CCTL0 |= SD16SC;                // Start another conversion
  //SD16CCTL0 |= SD16SC;                // Start another conversion
  return last_a2d;
  return last_a2d;
}
}
 
 
// ************************************************************
// ************************************************************
//
//
//  send one 16 bit value to SPI DAC
//  send one 16 bit value to SPI DAC
//
//
/* Description:
/* Description:
First put the value into the transmit register.  Chip select the DAC.
First put the value into the transmit register.  Chip select the DAC.
Start the automatic SPI transfer.  Wait until the transfer is complete.
Start the automatic SPI transfer.  Wait until the transfer is complete.
Finally remove the chip select.
Finally remove the chip select.
*/
*/
void set_one(int set_1)
void set_one(int set_1)
{
{
 
 
  USISR = set_1;                        // send value to DAC
  USISR = set_1;                        // send value to DAC
  P1OUT &= ~0x04;                       // chip select TLV5618A
  P1OUT &= ~0x04;                       // chip select TLV5618A
  USICNT = 0x10 + USI16B;               // start spi
  USICNT = 0x10 + USI16B;               // start spi
  while ((USIIFG & USICTL1) == 0) ;     // wait until y spi done
  while ((USIIFG & USICTL1) == 0) ;     // wait until y spi done
  P1OUT |= 0x04;                        // remove chip select
  P1OUT |= 0x04;                        // remove chip select
}
}
 
 
// ************************************************************
// ************************************************************
//
//
//  Move DAC's to dot position
//  Move DAC's to dot position
//
//
// set_x and set_y enter as 0 to 4095
// set_x and set_y enter as 0 to 4095
// Masked to 12 bit dac 0 to 4095
// Masked to 12 bit dac 0 to 4095
/* Description:
/* Description:
Move DAC to position set_x, set_y.  Write the set_y value into the DAC's
Move DAC to position set_x, set_y.  Write the set_y value into the DAC's
BUFFER.  Write the set_x value to DAC_x and at the same time move the BUFFER
BUFFER.  Write the set_x value to DAC_x and at the same time move the BUFFER
value to DAC_y.  This technique removes the stair steping in lines.
value to DAC_y.  This technique removes the stair steping in lines.
*/
*/
void set_xy(int set_x, int set_y)
void set_xy(int set_x, int set_y)
{
{
 
 
  //set_one((set_y & 0x0FFF) | 0x5000);   // send y value to BUFFER
  //set_one((set_y & 0x0FFF) | 0x5000);   // send y value to BUFFER
  //set_one((set_x & 0x0FFF) | 0xc000);   // send x DAC_X, BUFFER to DAC_Y
  //set_one((set_x & 0x0FFF) | 0xc000);   // send x DAC_X, BUFFER to DAC_Y
 
 
  while (MY_DAC_X_STAT);
  while (MY_DAC_X_STAT);
  while (MY_DAC_Y_STAT);
  while (MY_DAC_Y_STAT);
  MY_DAC_Y = (set_y & 0x0FFF);
  MY_DAC_Y = (set_y & 0x0FFF);
  MY_DAC_X = (set_x & 0x0FFF);
  MY_DAC_X = (set_x & 0x0FFF);
 
 
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.