main_entry.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include <stdio.h>
  2. #include "ohos_init.h"
  3. #include "iot_gpio.h"
  4. #include "iot_gpio_ex.h"
  5. #include "cmsis_os2.h"
  6. unsigned char CodeArr[8] =
  7. { //2相激励
  8. 0xC, 0x6, 0x3, 0x9, 0xC, 0x6, 0x3, 0x9
  9. };
  10. void moto(void* args )
  11. {
  12. int i;
  13. printf("moto thread running...");
  14. for(i=7;i<=12;i++)
  15. {
  16. IoTGpioInit(i);
  17. IoTGpioSetDir(i,IOT_GPIO_DIR_OUT);
  18. IoTGpioSetFunc(i,0);
  19. IoTGpioSetOutputVal(i,0);
  20. }
  21. //IoTGpioSetFunc(13,IOT_GPIO_FUNC_GPIO_13_GPIO);
  22. int c = 9;
  23. int idx = 0;
  24. while(1)
  25. {
  26. unsigned char code = CodeArr[idx];
  27. for(i = 9;i<=12;i++)
  28. {
  29. IoTGpioSetOutputVal(i,code & 0x1);
  30. code = code >> 1;
  31. }
  32. printf("sleep");
  33. usleep(1000);
  34. idx = (idx+1)%8;
  35. }
  36. }
  37. void moto_entry()
  38. {
  39. printf("moto_entry called \n");
  40. osThreadAttr_t attr;
  41. attr.name = "thread_moto";
  42. attr.attr_bits = 0U; // 如果为1 ,则可以使用osThreadJoin函数
  43. attr.cb_mem = NULL; //控制快的指针
  44. attr.cb_size = 0U;
  45. attr.stack_mem = NULL; //栈内存指针
  46. attr.stack_size = 1024 * 4; //栈大小
  47. attr.priority = 25; //优先级
  48. if (osThreadNew((osThreadFunc_t)moto, NULL, &attr) == NULL)
  49. {
  50. printf("Falied to create thread!\n");
  51. }
  52. }
  53. APP_FEATURE_INIT(moto_entry);