1
0

application.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * File : application.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006, 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. * 2009-01-05 Bernard the first version
  13. */
  14. /**
  15. * @addtogroup STM32
  16. */
  17. /*@{*/
  18. #include <stdio.h>
  19. #include <board.h>
  20. #include <rtthread.h>
  21. /*
  22. LED_GREEN: PC8
  23. LED_RED : PC9
  24. */
  25. #define rt_hw_led_on() GPIO_SetBits(GPIOC, GPIO_Pin_9)
  26. #define rt_hw_led_off() GPIO_ResetBits(GPIOC, GPIO_Pin_9)
  27. static void rt_hw_led_init(void)
  28. {
  29. GPIO_InitTypeDef GPIO_InitStructure;
  30. /* Enable the GPIO_LED Clock */
  31. RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE);
  32. /* Configure the GPIO_LED pin */
  33. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
  34. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  35. GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  36. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  37. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  38. GPIO_Init(GPIOC, &GPIO_InitStructure);
  39. }
  40. ALIGN(RT_ALIGN_SIZE)
  41. static char led_stack[384];
  42. static struct rt_thread led_thread;
  43. static void led_thread_entry(void* parameter)
  44. {
  45. rt_hw_led_init();
  46. while(1)
  47. {
  48. rt_hw_led_on();
  49. rt_thread_delay(RT_TICK_PER_SECOND/4);
  50. rt_hw_led_off();
  51. rt_thread_delay(RT_TICK_PER_SECOND/4);
  52. }
  53. }
  54. int rt_application_init()
  55. {
  56. rt_err_t result;
  57. result = rt_thread_init(&led_thread,
  58. "led",
  59. led_thread_entry,
  60. RT_NULL,
  61. &led_stack[0],
  62. sizeof(led_stack),
  63. 4,
  64. 2);
  65. if(result == RT_EOK) rt_thread_startup(&led_thread);
  66. return 0;
  67. }
  68. /*@}*/