void sct_fsm_init (void) { /*The SCT operates as a unified 32-bit counter*/ LPC_SCT->CONFIG = (LPC_SCT->CONFIG & ~0x00060001) | 0x00000001; /* UNIFIED */ /* MATCH/CAPTURE registers */ LPC_SCT->REGMODE_L = 0x00000000; LPC_SCT->MATCH[0].U = entry_mat; /* entry_match */ LPC_SCT->MATCHREL[0].U = entry_mat; LPC_SCT->MATCH[1].U = flash; /* flash_mat0 */ LPC_SCT->MATCHREL[1].U = flash; LPC_SCT->MATCH[2].U = flash1; /* flash_mat1 */ LPC_SCT->MATCHREL[2].U = flash1; LPC_SCT->MATCH[3].U = delay; /* match0 */ LPC_SCT->MATCHREL[3].U = delay; LPC_SCT->MATCH[4].U = yel_delay; /* yel_delay_mat */ LPC_SCT->MATCHREL[4].U = yel_delay; LPC_SCT->MATCH[5].U = yel_flash; /* yel_flash_mat */ LPC_SCT->MATCHREL[5].U = yel_flash; /* OUTPUT registers */ /*Event 1 set the output*/ LPC_SCT->OUT[5].SET = 0x00000002; /* out_track */ /*Event 3 clear the output*/ LPC_SCT->OUT[5].CLR = 0x00000008; /*Event 0 and 3 set the output*/ LPC_SCT->OUT[2].SET = 0x00000009; /* turn_green */ /*Event 7 clear the output*/ LPC_SCT->OUT[2].CLR = 0x00000080; /*Event 1 set the output*/ LPC_SCT->OUT[0].SET = 0x00000002; /* turn_red */ /*Event 0 and 6 clear the output*/ LPC_SCT->OUT[0].CLR = 0x00000041; /*Event 0, 2, 4, 5, 6 and 7 set the output*/ LPC_SCT->OUT[1].SET = 0x000000F5; /* turn_yellow */ /*Event 1, 3, 4, 5 set the output*/ LPC_SCT->OUT[1].CLR = 0x0000003A; /* Unused outputs must not be affected by any event */ LPC_SCT->OUT[3].SET = 0; LPC_SCT->OUT[3].CLR = 0; LPC_SCT->OUT[4].SET = 0; LPC_SCT->OUT[4].CLR = 0; /* Conflict resolution register */ LPC_SCT->RES = (LPC_SCT->RES & ~0x0000000C) | 0x0000000C; /* Set COMBMODE = 0x1. Event 0 uses match condition only. Set MATCHSEL = 0x0. Select match value of match register 0. The match value of MAT0 is associated with event 0 Set STATEV bits to 1 and the STATED bit to 1. Event 0 changes the state to state 1 */ LPC_SCT->EV[0].CTRL = 0x0000D000; /* U: --> state RED */ LPC_SCT->EV[0].STATE = 0x00000001; /* Set COMBMODE = 0x1. Event 1 uses match condition only. Set MATCHSEL = 0x3. Select match value of match register 3. The match value of MAT3 is associated with event 1 Set STATEV bits to 2 and the STATED bit to 1. Event 1 changes the state to state 2 */ LPC_SCT->EV[1].CTRL = 0x00015003; /* U: --> state YELLOW */ LPC_SCT->EV[1].STATE = 0x00000002; /* Set COMBMODE = 0x1. Event 1 uses match condition only. Set MATCHSEL = 0x4. Select match value of match register 4. The match value of MAT4 is associated with event 2 Set STATEV bits to 4 and the STATED bit to 1. Event 1 changes the state to state 4 */ LPC_SCT->EV[2].CTRL = 0x00025004; /* U: --> state YELLOW_FLASH */ LPC_SCT->EV[2].STATE = 0x00000004; /* Set COMBMODE = 0x1. Event 1 uses match condition only. Set MATCHSEL = 0x3. Select match value of match register 3. The match value of MAT3 is associated with event3 Set STATEV bits to 2 and the STATED bit to 1. Event 1 changes the state to state 2 */ LPC_SCT->EV[3].CTRL = 0x00015003; /* U: --> state YELLOW */ LPC_SCT->EV[3].STATE = 0x00000008; /* Set COMBMODE = 0x3. Event 6 uses when match and I/O condition occur. Set MATCHSEL = 0x5. Select match value of match register 5. Set OUTSEL = 1. Select output. Set IOSEL = 5. Select output 5. Set IOCOND = 0x0. Output 0 is Low The match value of MAT5 is associated with event 6 Set STATEV bits to 1 and the STATED bit to 1. Event 1 changes the state to state 1 */ LPC_SCT->EV[6].CTRL = 0x0000F165; /* U: --> state RED */ LPC_SCT->EV[6].STATE = 0x00000010; /* Set COMBMODE = 0x3. Event 6 uses when match and I/O condition occur. Set MATCHSEL = 0x5. Select match value of match register 5. Set OUTSEL = 1. Select output. Set IOSEL = 5. Select output 5. Set IOCOND = 0x3. Output 0 is High The match value of MAT5 is associated with event 7 Set STATEV bits to 3 and the STATED bit to 1. Event 7 changes the state to state 3 */ LPC_SCT->EV[7].CTRL = 0x0001FD65; /* U: --> state GREEN */ LPC_SCT->EV[7].STATE = 0x00000010; /* Set COMBMODE = 0x1. Event 1 uses match condition only. Set MATCHSEL = 0x1. Select match value of match register 1. The match value of MAT1 is associated with event4 Set STATEV bits to 4 and the STATED bit to 1. Event 1 changes the state to state 4 */ LPC_SCT->EV[4].CTRL = 0x00025001; /* U: --> state YELLOW_FLASH */ LPC_SCT->EV[4].STATE = 0x00000010; /* Set COMBMODE = 0x1. Event 1 uses match condition only. Set MATCHSEL = 0x2. Select match value of match register 2. The match value of MAT2 is associated with event5 Set STATEV bits to 4 and the STATED bit to 1. Event 1 changes the state to state 4 */ LPC_SCT->EV[5].CTRL = 0x00025002; /* U: --> state YELLOW_FLASH */ LPC_SCT->EV[5].STATE = 0x00000010; /* STATE registers */ LPC_SCT->STATE_L = 0; /* state names assignment: */ /* State U 0: U_ENTRY */ /* State U 1: RED */ /* State U 2: YELLOW */ /* State U 3: GREEN */ /* State U 4: YELLOW_FLASH */ /* CORE registers */ LPC_SCT->START_L = 0x00000000; LPC_SCT->STOP_L = 0x00000000; LPC_SCT->HALT_L = 0x00000000; /* Event0, 1, 2, 3, 6 and 7 reset the counter register */ LPC_SCT->LIMIT_L = 0x000000CF; LPC_SCT->EVEN = 0x00000000; LPC_SCT->DMAREQ0 = 0x00000000; LPC_SCT->DMAREQ1 = 0x00000000; } |