#include #include "LPC23xx.h" // Pin I/O LED Control Maskbit #define LED1 0x02000000 // P3.25(0000 00x0 0000 0000 0000 0000 0000 0000) #define LED2 0x04000000 // P3.26(0000 0x00 0000 0000 0000 0000 0000 0000) #define LED1_ON() FIO3CLR = LED1 // LED1 Pin = 0 (ON LED) #define LED1_OFF() FIO3SET = LED1 // LED1 Pin = 1 (OFF LED) #define LED2_ON() FIO3CLR = LED2 // LED2 Pin = 0 (ON LED) #define LED2_OFF() FIO3SET = LED2 // LED2 Pin = 1 (OFF LED) /* pototype section */ void delay(unsigned long int); // Delay Time Function int led_1_state = 0; int led_2_state = 0; void ConfigBlinky(void) { // Config Pin GPIO3[26:25] PINSEL7 &= 0xFFC3FFFF; // P3[26:25] = GPIO Function(xxxx xxxx xx00 00xx xxxx xxxx xxxx xxxx) PINMODE7 &= 0xFFC3FFFF; // Enable Puul-Up on P3[26:25] FIO3DIR |= LED1; // Set GPIO-3[26:25] = Output(xxxx x11x xxxx xxxx xxxx xxxx xxxx xxxx) FIO3DIR |= LED2; LED1_OFF(); // Default LED Status LED2_OFF(); } /***********************/ /* Delay Time Function */ /* 1-4294967296 */ /***********************/ void delay(unsigned long int count1) { while(count1 > 0) {count1--;} // Loop Decrease Counter } void task1(void *p) { volatile int i; while (1) { for (i = 0; i < 10; i++) { i++; } if (led_1_state == 0) { LED1_ON(); led_1_state = 1; } else { LED1_OFF(); led_1_state = 0; } delay(5000000); ctl_task_reschedule(); // task code, on return task will be terminated } } void task2(void *p) { volatile int k; while (1) { for (k = 0; k < 10; k++) { k++; } if (led_2_state == 0) { LED2_ON(); led_2_state = 1; } else { LED2_OFF(); led_2_state = 0; } delay(5000000); ctl_task_reschedule(); } // task code, on return task will be terminated } static CTL_TASK_t mainTask; static CTL_TASK_t task1Task; static unsigned task1Stack[64]; static CTL_TASK_t task2Task; static unsigned task2Stack[64]; int main(void) { // Turn myself into a task running at the highest priority. ctl_task_init(&mainTask, 255, "main"); // Initialise the stack of task1. memset(task1Stack, 0xba, sizeof(task1Stack)); // Initialise the stack of task2. memset(task2Stack, 0xba, sizeof(task2Stack)); ConfigBlinky(); /* Configure LEDs */ // Make another task ready to run. ctl_task_run(&task1Task, 1, task1, 0, "task1", sizeof(task1Stack) / sizeof(unsigned), task1Stack, 0); // Make another task ready to run. ctl_task_run(&task2Task, 1, task2, 0, "task2", sizeof(task2Stack) / sizeof(unsigned), task2Stack, 0); // Now all the tasks have been created go to lowest priority. ctl_task_set_priority(&mainTask, 0); // Main task, if activated because task1 is suspended, just // enters low power mode and waits for task1 to run again // (for example, because an interrupt wakes it). for (;;) { // Go into low power mode //sleep(); } }