Subversion Repositories Code-Repo

Rev

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

Rev 237 Rev 240
Line 85... Line 85...
85
    // Clear the RCON register
85
    // Clear the RCON register
86
    RCON = 0x0;
86
    RCON = 0x0;
87
    return ret;
87
    return ret;
88
}
88
}
89
 
89
 
-
 
90
// Initialize a persistent operational state machine
-
 
91
static BOARD_STATE op_state __attribute__((persistent));
-
 
92
 
90
void Reset_Board(void) {
93
uint8_t Get_Board_State(void) {
-
 
94
    return op_state.cube_mode;
-
 
95
}
-
 
96
 
-
 
97
void Reset_Board(uint8_t next_state) {
-
 
98
    op_state.cube_mode = next_state;
-
 
99
    
91
    // Executes a software reset
100
    // Executes a software reset
92
    INTDisableInterrupts();
101
    INTDisableInterrupts();
93
    SYSKEY = 0x00000000; // Write invalid key to force lock
102
    SYSKEY = 0x00000000; // Write invalid key to force lock
94
    SYSKEY = 0xAA996655; // Write key1 to SYSKEY
103
    SYSKEY = 0xAA996655; // Write key1 to SYSKEY
95
    SYSKEY = 0x556699AA; // Write key2 to SYSKEY
104
    SYSKEY = 0x556699AA; // Write key2 to SYSKEY
Line 130... Line 139...
130
    LED1_LAT = 0;
139
    LED1_LAT = 0;
131
    LED2_LAT = 0;
140
    LED2_LAT = 0;
132
    LED3_LAT = 0;
141
    LED3_LAT = 0;
133
    LED4_LAT = 0;
142
    LED4_LAT = 0;
134
 
143
 
135
    // Initialize a persistent operational state machine
-
 
136
    BOARD_STATE op_state __attribute__((persistent));
-
 
137
 
-
 
138
    // Initialize the SPI1 module
144
    // Initialize the SPI1 module
139
    SPI1_DATA spi_1_data;
145
    SPI1_DATA spi_1_data;
140
    SPI1_Init(&spi_1_data, NULL);
146
    SPI1_Init(&spi_1_data, NULL);
141
 
147
 
142
    // Initialize the SPI4 module
148
    // Initialize the SPI4 module
Line 169... Line 175...
169
 
175
 
170
    // Process button inputs
176
    // Process button inputs
171
    BTN_DATA btn_data;
177
    BTN_DATA btn_data;
172
    BTN_Init(&btn_data, &BTN1_Interrupt, &BTN2_Interrupt, NULL);
178
    BTN_Init(&btn_data, &BTN1_Interrupt, &BTN2_Interrupt, NULL);
173
 
179
 
-
 
180
    // Initialize controllers
174
    CONTROLLER_DATA ctrl_data;
181
    CONTROLLER_DATA ctrl_data;
175
    Controller_Init(&ctrl_data, &op_state, &Controller_Set_Leds);
182
    Controller_Init(&ctrl_data, &Snake_Update_Direction);
-
 
183
    
-
 
184
    SNAKE_DATA snake_data;
176
 
185
 
177
    // Determine what to do at this point. We either choose to idle (on POR)
186
    // Determine what to do at this point. We either choose to idle (on POR)
178
    // or go into a mode specified prior to the software reset event
187
    // or go into a mode specified prior to the software reset event
179
    uint8_t last_reset = Get_Reset_Condition();
188
    uint8_t last_reset = Get_Reset_Condition();
180
    switch (last_reset) {
189
    switch (last_reset) {
Line 195... Line 204...
195
    /* -------------------- END OF INITIALIZATION -------------------- */
204
    /* -------------------- END OF INITIALIZATION -------------------- */
196
    /* ------------------------ BEGIN DISPLAY ------------------------ */
205
    /* ------------------------ BEGIN DISPLAY ------------------------ */
197
    
206
    
198
    switch (op_state.cube_mode) {
207
    switch (op_state.cube_mode) {
199
        case BOARD_MODE_SNAKE:
208
        case BOARD_MODE_SNAKE:
200
            LED3_LAT = 1;
-
 
201
            LED4_LAT = 0;
-
 
202
            SNAKE_DATA snake_data;
-
 
203
            Snake_Init(&snake_data);
209
            Snake_Init(&snake_data);
204
            while(1);
210
            Snake_Main();
205
            break;
211
            break;
206
        case BOARD_MODE_TRON:
212
        case BOARD_MODE_TRON:
207
            LED3_LAT = 0;
-
 
208
            LED4_LAT = 1;
-
 
209
            while(1);
213
            while(1);
210
            break;
214
            break;
211
        case BOARD_MODE_IDLE:
215
        case BOARD_MODE_IDLE:
212
        default:
216
        default:
213
            Idle_Animation_Sequence();
217
            Idle_Animation_Sequence();
Line 215... Line 219...
215
    }
219
    }
216
 
220
 
217
}
221
}
218
 
222
 
219
void Idle_Animation_Sequence(void) {
223
void Idle_Animation_Sequence(void) {
-
 
224
      Delay_MS(250);
220
 
225
 
221
//    Cube_Set_All(RED);
226
//    Cube_Set_All(RED);
222
//    Delay_MS(2000);
227
//    Delay_MS(2000);
223
//    Cube_Set_All(GREEN);
228
//    Cube_Set_All(GREEN);
224
//    Delay_MS(2000);
229
//    Delay_MS(2000);
225
//    Cube_Set_All(BLUE);
230
//    Cube_Set_All(BLUE);
226
//    Delay_MS(2000);
231
//    Delay_MS(2000);
227
    Animation_Pseudo_Random_Colors(200);
232
//    Animation_Pseudo_Random_Colors(200);
228
    Animation_Pseudo_Random_Colors(200);
233
//    Animation_Pseudo_Random_Colors(200);
229
    Animation_Pseudo_Random_Colors(200);
234
//    Animation_Pseudo_Random_Colors(200);
230
    Animation_Pseudo_Random_Colors(200);
235
//    Animation_Pseudo_Random_Colors(200);
231
    Animation_Pseudo_Random_Colors(200);
236
//    Animation_Pseudo_Random_Colors(200);
232
    Animation_Pseudo_Random_Colors(200);
237
//    Animation_Pseudo_Random_Colors(200);
233
 
238
 
234
    // Start the scrolling text
239
    // Start the scrolling text
235
    TIMER4_Stop();
240
    TIMER4_Stop();
236
    TIMER4_Init(NULL, &Controller_Update, &Cube_Text_Interrupt, 100);
241
    TIMER4_Init(NULL, &Controller_Update, &Cube_Text_Interrupt, 100);
237
    TIMER4_Start();
242
    TIMER4_Start();