diff --git a/bsp/pic32ethernet/application.c b/bsp/pic32ethernet/application.c index f0d6e3c3b8ffc77aaec95ab5ec2310447e80903a..19e7479d400c9c0688a180eeea7dfe876173d23b 100644 --- a/bsp/pic32ethernet/application.c +++ b/bsp/pic32ethernet/application.c @@ -14,37 +14,54 @@ // Adds support for PIC32 Peripheral library functions and macros #include +#include -static void delay(void) +ALIGN(RT_ALIGN_SIZE) +int thread_led1_stack[512]; +struct rt_thread thread_led1; +void thread_led1_entry(void* parameter) { - volatile unsigned long i; - for(i=0;i<500000;i++); + // configure PORTD.RD1 = output + mPORTDSetPinsDigitalOut(BIT_1); + while(1) + { + // .. Toggle the LED + mPORTDToggleBits(BIT_1); + rt_thread_delay( RT_TICK_PER_SECOND ); /* delay 1s */ + } +} + +static void thread_led2_entry(void* parameter) +{ + // configure PORTD.RD2 = output + mPORTDSetPinsDigitalOut(BIT_2); + + while (1) + { + // .. Toggle the LED + mPORTDToggleBits(BIT_2); + rt_thread_delay( RT_TICK_PER_SECOND*5 ); /* delay 1s */ + } } int rt_application_init(void) { - PORTSetPinsDigitalOut(IOPORT_D, BIT_0); - - while(1) - { - delay(); - delay(); - delay(); - delay(); - delay(); - delay(); - delay(); - delay(); - delay(); - delay(); - delay(); - delay(); - delay(); - delay(); - PORTSetBits(IOPORT_D, BIT_0); - delay(); - PORTClearBits(IOPORT_D, BIT_0); - } + rt_thread_t thread; + + rt_thread_init(&thread_led1, + "led1", + thread_led1_entry, RT_NULL, + &thread_led1_stack[0], sizeof(thread_led1_stack), + 20, 10); + rt_thread_startup(&thread_led1); + + /* create led2 thread */ + thread = rt_thread_create("led2", + thread_led2_entry, RT_NULL, + 1024, + 20, 5); + if (thread != RT_NULL) + rt_thread_startup(thread); return 0; } diff --git a/bsp/pic32ethernet/board.c b/bsp/pic32ethernet/board.c index b247c9c54b2544fb2d94b069bbb1dbb08af82ae6..ba16e5cbc60b0dd76a291f6a978e10300fb6ce37 100644 --- a/bsp/pic32ethernet/board.c +++ b/bsp/pic32ethernet/board.c @@ -14,6 +14,7 @@ // Adds support for PIC32 Peripheral library functions and macros #include +#include // Configuration Bits #pragma config FNOSC = PRIPLL // Oscillator Selection @@ -35,7 +36,12 @@ #pragma config DEBUG = OFF // Debugger Disabled for Starter Kit // The following is used by the main application -#define SYS_FREQ (80000000) +#define SYS_FREQ (80000000UL) + +#define PB_DIV 8 +#define PRESCALE 256 +#define TOGGLES_PER_SEC RT_TICK_PER_SECOND +#define T1_TICK (SYS_FREQ/PB_DIV/PRESCALE/TOGGLES_PER_SEC) static void rt_hw_show_info(void) { @@ -45,6 +51,17 @@ static void rt_hw_show_info(void) rt_kprintf("CPU_FREQ: %uMHz\r\n",SYS_FREQ/1000000UL); } +static void rt_hw_timer_handler(void) +{ + /* enter interrupt */ + rt_interrupt_enter(); + + rt_tick_increase(); + + /* leave interrupt */ + rt_interrupt_leave(); +} + /** * This function will initial FM3 Easy Kit board. */ @@ -59,5 +76,56 @@ void rt_hw_board_init() rt_hw_console_init(); rt_hw_show_info(); + + // enable multi-vector interrupts + INTEnableSystemMultiVectoredInt(); + rt_hw_interrupt_disable(); + +// // STEP 2. configure the core timer +// OpenCoreTimer(CORE_TICK_RATE); +// +// // set up the core timer interrupt with a prioirty of 2 and zero sub-priority +// mConfigIntCoreTimer((CT_INT_ON | CT_INT_PRIOR_2 | CT_INT_SUB_PRIOR_0)); + + // STEP 2. configure Timer 1 using internal clock, 1:256 prescale + OpenTimer1(T1_ON | T1_SOURCE_INT | T1_PS_1_256, T1_TICK); + // set up the timer interrupt with a priority of 2 + ConfigIntTimer1(T1_INT_ON | T1_INT_PRIOR_2); + + /* Setup the software interrupt. */ + mConfigIntCoreSW0( CSW_INT_ON | CSW_INT_PRIOR_1 | CSW_INT_SUB_PRIOR_0 ); + + // configure PORTD.RD0 = output,Toggle in CoreSW0Handler. + mPORTDSetPinsDigitalOut(BIT_0); } +void __ISR(_TIMER_1_VECTOR, ipl2) Timer1Handler(void) +{ + // clear the interrupt flag + mT1ClearIntFlag(); + + // .. things to do + rt_hw_timer_handler(); + +// // .. in this case, toggle the LED +// mPORTDToggleBits(BIT_1); +} + +//void __ISR(_CORE_TIMER_VECTOR, ipl2) CoreTimerHandler(void) +//{ +// // clear the interrupt flag +// mCTClearIntFlag(); +// +// // .. things to do +// rt_hw_timer_handler(); +// +// // update the period +// UpdateCoreTimer(CORE_TICK_RATE); +// +// // .. Toggle the LED +// mPORTDToggleBits(BIT_1); +//} + + +void __ISR(_CORE_SOFTWARE_0_VECTOR, ipl2) CoreSW0Handler(void); + diff --git a/bsp/pic32ethernet/console.c b/bsp/pic32ethernet/console.c index 09295bfc8daae0d62bb496c71e9ec5b5df8e3dab..dc31ad406e6701d2a2f4058d589825da941266d6 100644 --- a/bsp/pic32ethernet/console.c +++ b/bsp/pic32ethernet/console.c @@ -24,7 +24,7 @@ void rt_hw_console_init(void) { //Initialize the DB_UTILS IO channel - DBINIT(); +// DBINIT(); } /** @@ -34,6 +34,6 @@ void rt_hw_console_init(void) */ void rt_hw_console_output(const char* str) { - DBPRINTF(str); +// DBPRINTF(str); } diff --git a/bsp/pic32ethernet/project.cbp b/bsp/pic32ethernet/project.cbp index 16cb7c2de652394970aa9b23a00106c32554eb6f..28543d7b5994c07837b4b376157933565a9ed96b 100644 --- a/bsp/pic32ethernet/project.cbp +++ b/bsp/pic32ethernet/project.cbp @@ -36,6 +36,16 @@ + + + + + + + + +