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

Subversion Repositories openmsp430

[/] [openmsp430/] [trunk/] [fpga/] [actel_m1a3pl_dev_kit/] [software/] [spacewar/] [hardware.c] - Blame information for rev 80

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 80 olivier.gi
#include "msp430x20x3.h"
2
#include <signal.h>                    // Needed for using interrupts with msp430-gcc
3
#include "spacewar.h"
4
 
5
//************************************************************
6
// externals
7
//
8
extern volatile unsigned char flags;
9
 
10
extern void reset_rkts(rkt_data *, rkt_data *);
11
extern void reset_game(rkt_data *);
12
 
13
//************************************************************
14
//
15
// init_hardware
16
//
17
//    initalize all the MSP430 hardware before we start
18
//
19
/* Description:
20
Sets up all the hardware in the MSP430 used by the SPACEWAR game.
21
Stops the watchdog timer.  Sets the internal cpu clock to a maximun.
22
Sets the timer to cause an interrupt every 10ms.  Sets the SPI interface
23
to talk to the dual DAC.  Sets the A to D to use an external reference
24
and unipolar operation.  Finally initializes all the variable used by the game.
25
*/
26
void init_all(rkt_data *rkt1, rkt_data *rkt2)
27
{
28
 
29
  WDTCTL = WDTPW + WDTHOLD;             // Stop watchdog timer
30
 
31
  BCSCTL1 = 0x08;                       // Setup DCO highest range
32
  DCOCTL = 0xe0;                        // biggest DCO
33
 
34
  P1OUT = 0x04;                         // TLV5618A CS high
35
  P1DIR |= 0x01+0x04;                   // P1.0=LED, P1.2=TLV5618A_cs
36
  P1SEL = 0x08;                         // P1.3 = VREF
37
 
38
  CCTL0 = CCIE;                         // CCR0 interrupt enabled
39
  CCR0 = 23500;
40
  //CCR0 = 500;
41
  TACTL = TASSEL_2 + MC_1;              // SMCLK, upmode
42
  _BIS_SR(GIE);                         // enable interrupts
43
 
44
  // USICTL0 |= USIPE7+USIPE6+USIPE5+USIMST+USIOE; // Port, SPI master
45
  // USICKCTL = USIDIV_0+USISSEL_2+USICKPL;  // divide by 1 SMCLK, inactive high
46
  // USICTL0 &= ~USISWRST;                 // release USI for operation
47
  // USICTL1 = USICKPH;                    // take data on falling edge
48
 
49
  // SD16CTL = SD16SSEL_1;                 // exter ref, SMCLK
50
  // SD16CCTL0 = SD16UNI + SD16SNGL;       // 256OSR, unipolar, inter
51
  // SD16AE = 0;                           // P1.1 A4+, A4- = VSS
52
  //                                       // P1.4 A2+, A2- = VSS
53
  // SD16INCTL0 = SD16INCH_4;              // A4+/- start with rocket 1
54
  // SD16CCTL0 |= SD16SC;                  // Start A2D conversion
55
 
56
  reset_rkts(rkt1, rkt2);               // reset rkt positons                        
57
  reset_game(rkt1);
58
  reset_game(rkt2);
59
  rkt1->game = 0;
60
  rkt2->game = 0;
61
  flags |= time_tick;                    // force an update at startup
62
}
63
 
64
 
65
//************************************************************
66
//
67
// Timer A0 interrupt service routine
68
//
69
/* Description:
70
Interrupt service routine for the timer.  The function sets a flag for the main
71
loop to update object positions.
72
*/
73
interrupt (TIMERA0_VECTOR) irq_routine(void)
74
{
75
 
76
//  P1OUT ^= 0x01;                        // Toggle P1.0
77
  flags |= time_tick;                   // flag a timer tick has occured
78
}
79
 
80
//************************************************************
81
//
82
// read_a2d
83
//
84
/* Description:
85
Waits for present A to D to finish.  Reads 16 bit A to D value.  Switches
86
A to D mux to a channel passed into function.  Starts another A to D on new
87
mux input.  Returns int value read from last mux input A to D.
88
*/
89
unsigned int read_a2d(unsigned int next_mux)
90
{
91
  unsigned int last_a2d;
92
 
93
  if (next_mux==SD16INCH_2) {
94
    last_a2d = MY_CNTRL1;
95
  } else {
96
    last_a2d = MY_CNTRL2;
97
  }
98
 
99
  if (last_a2d & 0x8) {             // CCW
100
    last_a2d = 0xE000;
101
  } else if (last_a2d & 0x4) {      // CW
102
    last_a2d = 0xB000;
103
  } else if (last_a2d & 0x2) {      // Thrust
104
    last_a2d = 0x8000;
105
  } else if (last_a2d & 0x1) {      // Fire
106
    last_a2d = 0x4000;
107
  } else {
108
    last_a2d = 0x0000;
109
  }
110
 
111
  //while ((SD16CCTL0 & SD16IFG) == 0); // wait for a2d to finish
112
  //last_a2d = SD16MEM0;                // save results from last a2d
113
  //SD16INCTL0 = next_mux;              // switch analog mux for next rocket
114
  //SD16CCTL0 |= SD16SC;                // Start another conversion
115
  return last_a2d;
116
}
117
 
118
// ************************************************************
119
//
120
//  send one 16 bit value to SPI DAC
121
//
122
/* Description:
123
First put the value into the transmit register.  Chip select the DAC.
124
Start the automatic SPI transfer.  Wait until the transfer is complete.
125
Finally remove the chip select.
126
*/
127
void set_one(int set_1)
128
{
129
 
130
  USISR = set_1;                        // send value to DAC
131
  P1OUT &= ~0x04;                       // chip select TLV5618A
132
  USICNT = 0x10 + USI16B;               // start spi
133
  while ((USIIFG & USICTL1) == 0) ;     // wait until y spi done
134
  P1OUT |= 0x04;                        // remove chip select
135
}
136
 
137
// ************************************************************
138
//
139
//  Move DAC's to dot position
140
//
141
// set_x and set_y enter as 0 to 4095
142
// Masked to 12 bit dac 0 to 4095
143
/* Description:
144
Move DAC to position set_x, set_y.  Write the set_y value into the DAC's
145
BUFFER.  Write the set_x value to DAC_x and at the same time move the BUFFER
146
value to DAC_y.  This technique removes the stair steping in lines.
147
*/
148
void set_xy(int set_x, int set_y)
149
{
150
 
151
  //set_one((set_y & 0x0FFF) | 0x5000);   // send y value to BUFFER
152
  //set_one((set_x & 0x0FFF) | 0xc000);   // send x DAC_X, BUFFER to DAC_Y
153
 
154
  while (MY_DAC_X_STAT);
155
  while (MY_DAC_Y_STAT);
156
  MY_DAC_Y = (set_y & 0x0FFF);
157
  MY_DAC_X = (set_x & 0x0FFF);
158
 
159
}

powered by: WebSVN 2.1.0

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