aboutsummaryrefslogtreecommitdiff
path: root/AT91SAM7S256/Source/c_cmd_alternate.c
blob: c892c9d86ced8f462fe941cb4112dcf2e52c6428 (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
103
104
105
106
107
108
//
// File Description:
// This file contains an alternate implementation of c_cmd for testing purposes.
// It implements the minimal standard interface for the module, and serves as
//  an example of output module control via C code.
//

void      cCmdInit(void* pHeader)
{
  pHeaders        = pHeader;

  IOMapCmd.Awake = TRUE;

  dTimerInit();
  IOMapCmd.Tick = dTimerRead();

  return;
}

//Test: Start at speed 100 when enter is pressed; then progressively ramp down every half second until -100.
void      cCmdCtrl(void)
{
  static UBYTE State = 0;
  static ULONG MyTick = 0;

  if (pMapButton->State[BTN1] & PRESSED_EV)
  {
    pMapButton->State[BTN1] &= ~PRESSED_EV;

    State = 1;
  }

  switch(State)
  {
    case 0:
    {
      //Initialize
      pMapInput->Inputs[0].SensorType = LOWSPEED;
    }
    break;

    case 1:
    {
      if (pMapLowSpeed->ChannelState[0] == LOWSPEED_IDLE)
      {
        pMapLowSpeed->OutBuf[0].InPtr = 0;
        pMapLowSpeed->OutBuf[0].OutPtr = 0;

        pMapLowSpeed->OutBuf[0].Buf[pMapLowSpeed->OutBuf[0].InPtr] = 0x88;   // I2C adress = 1000100X
        pMapLowSpeed->OutBuf[0].InPtr++;
        pMapLowSpeed->OutBuf[0].Buf[pMapLowSpeed->OutBuf[0].InPtr] = 0x00;  // Selecting register to write into
        pMapLowSpeed->OutBuf[0].InPtr++;
        pMapLowSpeed->OutBuf[0].Buf[pMapLowSpeed->OutBuf[0].InPtr] = 0x88;  // Data to set into register => Setting Control register
        pMapLowSpeed->OutBuf[0].InPtr++;

        pMapLowSpeed->InBuf[0].BytesToRx = 0;
        pMapLowSpeed->ChannelState[0]    = LOWSPEED_INIT;
        pMapLowSpeed->State              = COM_CHANNEL_ONE_ACTIVE;

        State = 2;
      }
    }
    break;

    case 2:
    {
      if (pMapLowSpeed->ChannelState[0] == LOWSPEED_IDLE)
      {
        pMapLowSpeed->OutBuf[0].InPtr = 0;
        pMapLowSpeed->OutBuf[0].OutPtr = 0;

        pMapLowSpeed->OutBuf[0].Buf[pMapLowSpeed->OutBuf[0].InPtr] = 0x88;  // I2C adress = 1000100X
        pMapLowSpeed->OutBuf[0].InPtr++;
        pMapLowSpeed->OutBuf[0].Buf[pMapLowSpeed->OutBuf[0].InPtr] = 0x04;  // Start register to read from
        pMapLowSpeed->OutBuf[0].InPtr++;

        pMapLowSpeed->InBuf[0].BytesToRx = 2;                               // Read 2 bytes from I2C unit
        pMapLowSpeed->ChannelState[0]    = LOWSPEED_INIT;
        pMapLowSpeed->State              = COM_CHANNEL_ONE_ACTIVE;

        State = 3;
      }
    }
    break;

    case 3:
    {

    }
    break;

    default:
      break;
  };

  //Busy loop to ensure return on 1ms boundary
  while (IOMapCmd.Tick == dTimerRead());

  IOMapCmd.Tick = dTimerRead();
  MyTick++;

  return;
}

void      cCmdExit(void)
{
  return;
}