application.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * File : application.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2009 - 2011, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2011-05-23 aozima first implementation for PIC32.
  13. */
  14. // Adds support for PIC32 Peripheral library functions and macros
  15. #include <plib.h>
  16. #include <rtthread.h>
  17. ALIGN(RT_ALIGN_SIZE)
  18. int thread_led1_stack[512];
  19. struct rt_thread thread_led1;
  20. void thread_led1_entry(void* parameter)
  21. {
  22. // configure PORTD.RD1 = output
  23. mPORTDSetPinsDigitalOut(BIT_1);
  24. while(1)
  25. {
  26. // .. Toggle the LED
  27. mPORTDToggleBits(BIT_1);
  28. rt_thread_delay( RT_TICK_PER_SECOND ); /* delay 1s */
  29. }
  30. }
  31. static void thread_led2_entry(void* parameter)
  32. {
  33. // configure PORTD.RD2 = output
  34. mPORTDSetPinsDigitalOut(BIT_2);
  35. while (1)
  36. {
  37. // .. Toggle the LED
  38. mPORTDToggleBits(BIT_2);
  39. rt_thread_delay( RT_TICK_PER_SECOND/2 ); /* delay 0.5s */
  40. }
  41. }
  42. int rt_application_init(void)
  43. {
  44. rt_thread_t thread;
  45. rt_thread_init(&thread_led1,
  46. "led1",
  47. thread_led1_entry, RT_NULL,
  48. &thread_led1_stack[0], sizeof(thread_led1_stack),
  49. 20, 10);
  50. rt_thread_startup(&thread_led1);
  51. /* create led2 thread */
  52. thread = rt_thread_create("led2",
  53. thread_led2_entry, RT_NULL,
  54. 1024,
  55. 20, 5);
  56. if (thread != RT_NULL)
  57. rt_thread_startup(thread);
  58. return 0;
  59. }