Subversion Repositories Code-Repo

Rev

Rev 255 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 255 Rev 261
Line 88... Line 88...
88
    RCON = 0x0;
88
    RCON = 0x0;
89
    return ret;
89
    return ret;
90
}
90
}
91
 
91
 
92
// Initialize a persistent operational state machine
92
// Initialize a persistent operational state machine
93
static BOARD_STATE op_state __attribute__((persistent));
93
volatile static uint8_t op_state __attribute__((persistent));
94
 
94
 
95
uint8_t Get_Board_State(void) {
95
uint8_t Get_Board_State(void) {
96
    return op_state.cube_mode;
96
    return op_state;
97
}
97
}
98
 
98
 
99
void Reset_Board(uint8_t next_state) {
99
void Reset_Board(uint8_t next_state) {
100
    op_state.cube_mode = next_state;
100
    op_state = next_state;
101
    
101
    
102
    // Executes a software reset
102
    // Executes a software reset
103
    INTDisableInterrupts();
103
    INTDisableInterrupts();
104
    SYSKEY = 0x00000000; // Write invalid key to force lock
104
    SYSKEY = 0x00000000; // Write invalid key to force lock
105
    SYSKEY = 0xAA996655; // Write key1 to SYSKEY
105
    SYSKEY = 0xAA996655; // Write key1 to SYSKEY
Line 141... Line 141...
141
    LED1_LAT = 0;
141
    LED1_LAT = 0;
142
    LED2_LAT = 0;
142
    LED2_LAT = 0;
143
    LED3_LAT = 0;
143
    LED3_LAT = 0;
144
    LED4_LAT = 0;
144
    LED4_LAT = 0;
145
 
145
 
146
    // Initialize the Ethernet module
-
 
147
    ETH_DATA eth_data;
-
 
148
    ETH_Init(&eth_data, NULL, &Cube_Ethernet_Frame_In);
-
 
149
 
-
 
150
    // Initialize the SPI1 module
146
    // Initialize the SPI1 module
151
    SPI1_DATA spi_1_data;
147
    SPI1_DATA spi_1_data;
152
    SPI1_Init(&spi_1_data, NULL);
148
    SPI1_Init(&spi_1_data, NULL);
153
 
149
 
154
    // Initialize the SPI4 module
150
    // Initialize the SPI4 module
Line 157... Line 153...
157
 
153
 
158
    // Initialize the I2C1 module
154
    // Initialize the I2C1 module
159
    I2C1_DATA i2c_1_data;
155
    I2C1_DATA i2c_1_data;
160
    I2C1_Init(&i2c_1_data, I2C1_400KHZ, 0x20);
156
    I2C1_Init(&i2c_1_data, I2C1_400KHZ, 0x20);
161
 
157
 
162
    // Initialize the UART1 module
158
//    // Initialize the UART1 module
163
    UART1_DATA uart_data;
159
//    UART1_DATA uart_data;
164
    UART1_Init(&uart_data, &Cube_Data_In);
160
//    UART1_Init(&uart_data, &Cube_Data_In);
165
 
161
 
166
    // Initializs the PWM2 output to 20MHz
162
    // Initializs the PWM2 output to 20MHz
167
    PWM2_Init();
163
    PWM2_Init();
168
 
164
 
169
    // Initialize the cube variables
165
    // Initialize the cube variables
Line 176... Line 172...
176
    TIMER5_Init(&timer_5_data, &Cube_Timer_Interrupt, 500);
172
    TIMER5_Init(&timer_5_data, &Cube_Timer_Interrupt, 500);
177
 
173
 
178
    // Start the controller polling and overlay rotation interrupt
174
    // Start the controller polling and overlay rotation interrupt
179
    TIMER4_DATA timer_4_data;
175
    TIMER4_DATA timer_4_data;
180
    TIMER4_Init(&timer_4_data, &Controller_Update, NULL, 0);
176
    TIMER4_Init(&timer_4_data, &Controller_Update, NULL, 0);
-
 
177
//    TIMER4_Init(&timer_4_data, NULL, NULL, 0);
181
 
178
 
182
    // Process button inputs
179
    // Process button inputs
183
    BTN_DATA btn_data;
180
    BTN_DATA btn_data;
184
    BTN_Init(&btn_data, &BTN1_Interrupt, &BTN2_Interrupt, NULL);
181
    BTN_Init(&btn_data, &BTN1_Interrupt, &BTN2_Interrupt, NULL);
185
 
182
 
186
    // Initialize controllers
183
    // Initialize controllers
187
    CONTROLLER_DATA ctrl_data;
184
    CONTROLLER_DATA ctrl_data;
188
    Controller_Init(&ctrl_data, NULL);
185
    Controller_Init(&ctrl_data, NULL);
-
 
186
 
-
 
187
    // Initialize the Ethernet module
-
 
188
    ETH_DATA eth_data;
-
 
189
    ETH_Init(&eth_data, NULL, &Cube_Ethernet_Frame_In);
189
    
190
    
190
    SNAKE_DATA snake_data;
191
    SNAKE_DATA snake_data;
191
    TRON_DATA tron_data;
192
    TRON_DATA tron_data;
192
 
193
 
193
    // Determine what to do at this point. We either choose to idle (on POR)
194
    // Determine what to do at this point. We either choose to idle (on POR)
194
    // or go into a mode specified prior to the software reset event
195
    // or go into a mode specified prior to the software reset event
195
    uint8_t last_reset = Get_Reset_Condition();
196
    uint8_t last_reset = Get_Reset_Condition();
196
    if (last_reset == RESET_POR || last_reset == RESET_BOR ||
197
    if (last_reset == RESET_POR || last_reset == RESET_BOR ||
197
            last_reset == RESET_PIN || last_reset == RESET_WDT ||
198
            last_reset == RESET_PIN || last_reset == RESET_WDT ||
198
            last_reset == RESET_CFG) {
199
            last_reset == RESET_CFG) {
199
        op_state.cube_mode = BOARD_MODE_IDLE;
200
        op_state = BOARD_MODE_IDLE;
200
    }
201
    }
201
 
202
 
202
    PWM2_Start();
203
    PWM2_Start();
203
    TIMER5_Start();
204
    TIMER5_Start();
204
    TIMER4_Start();
205
    TIMER4_Start();
205
    
206
    
206
    /* -------------------- END OF INITIALIZATION -------------------- */
207
    /* -------------------- END OF INITIALIZATION -------------------- */
207
    /* ------------------------ BEGIN DISPLAY ------------------------ */
208
    /* ------------------------ BEGIN DISPLAY ------------------------ */
208
    
209
    
209
    switch (op_state.cube_mode) {
210
    switch (op_state) {
-
 
211
        case BOARD_MODE_IDLE:
-
 
212
            Idle_Animation_Sequence();
-
 
213
            break;
210
        case BOARD_MODE_SNAKE:;
214
        case BOARD_MODE_SNAKE:;
211
            Controller_Init(&ctrl_data, &Snake_Update_Direction);
215
            Controller_Init(&ctrl_data, &Snake_Update_Direction);
212
            Snake_Init(&snake_data);
216
            Snake_Init(&snake_data);
213
            Snake_Main();
217
            Snake_Main();
214
            break;
218
            break;
Line 216... Line 220...
216
            Controller_Init(&ctrl_data, &Tron_Update_Direction);
220
            Controller_Init(&ctrl_data, &Tron_Update_Direction);
217
            Tron_Init(&tron_data);
221
            Tron_Init(&tron_data);
218
            Tron_Main();
222
            Tron_Main();
219
            break;
223
            break;
220
        case BOARD_MODE_ETHERNET:
224
        case BOARD_MODE_ETHERNET:
-
 
225
            TIMER4_Stop();
221
            while(1);
226
            while(1);
222
            break;
227
            break;
223
        case BOARD_MODE_IDLE:
-
 
224
        default:
-
 
225
            Idle_Animation_Sequence();
-
 
226
            break;
-
 
227
    }
228
    }
228
 
229
 
-
 
230
    while(1);
-
 
231
 
229
}
232
}
230
 
233
 
231
void Idle_Animation_Sequence(void) {
234
void Idle_Animation_Sequence(void) {
232
      Delay_MS(250);
235
      Delay_MS(250);
233
 
236