Advertisement
urbmal

PATR_lab4

Oct 22nd, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. /* Scheduler includes. */
  4. #include "FreeRTOS.h"
  5. #include "task.h"
  6. #include "queue.h"
  7. #include "croutine.h"
  8.  
  9. /* Demo application includes. */
  10. #include "partest.h"
  11.  
  12.  
  13. // Select Internal FRC at POR
  14. _FOSCSEL(FNOSC_FRC);
  15. // Enable Clock Switching and Configure
  16. _FOSC(FCKSM_CSECMD & OSCIOFNC_OFF); // FRC + PLL
  17. //_FOSC(FCKSM_CSECMD & OSCIOFNC_OFF & POSCMD_XT); // XT + PLL
  18. _FWDT(FWDTEN_OFF); // Watchdog Timer Enabled/disabled by user software
  19.  
  20. static void prvSetupHardware( void );
  21.  
  22. xTaskHandle T1H,T2H,T3H;
  23. unsigned int prioT1,prioT2;
  24.  
  25. void Task1(void *params) {
  26.  
  27. for (;;)
  28. {
  29.  
  30. //PORTBbits.RB15 = ~PORTBbits.RB15;
  31. vParTestToggleLED(15);
  32. vTaskDelay(2000);
  33. }
  34. }
  35.  
  36. void Task2(void *params) {
  37. for (;;)
  38. {
  39. //PORTBbits.RB14 = ~PORTBbits.RB14;
  40. vParTestToggleLED(14);
  41. vTaskDelay(500);
  42. }
  43. }
  44.  
  45. void Task3(void *params) {
  46. // portTickType timp; // am folosit port ticktype sa declaram variabila timp. apoi folosim functia xtaskgettickcount sa luam timpul!
  47. // timp=xTaskGetTickCount;
  48. for (;;)
  49. {
  50. prioT1=uxTaskPriorityGet(T1H);
  51. prioT2=uxTaskPriorityGet(T2H);
  52.  
  53. if(xTaskGetTickCount()>=12345)
  54. {
  55. prioT1=prioT1+2;
  56. prioT2=prioT2+2;
  57. }
  58. //PORTBbits.RB13 = ~PORTBbits.RB13;
  59. vParTestToggleLED(13);
  60. vTaskDelay(250);
  61. }
  62. }
  63.  
  64. /*void Task4(void *params)
  65. {
  66. for (;;)
  67. {
  68.  
  69. //PORTBbits.RB12 = ~PORTBbits.RB12;
  70. vParTestToggleLED(12);
  71. vTaskDelay(1000);
  72. }
  73. }*/
  74.  
  75.  
  76. int main( void )
  77. {
  78. /* Configure any hardware required for this demo. */
  79. prvSetupHardware();
  80.  
  81. xTaskCreate(Task1, (signed portCHAR *) "Ts1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1, &T1H);
  82. xTaskCreate(Task2, (signed portCHAR *) "Ts2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1, &T2H);
  83. xTaskCreate(Task3, (signed portCHAR *) "Ts3", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 3, &T3H);
  84. // xTaskCreate(Task4, (signed portCHAR *) "Ts4", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1, NULL);
  85.  
  86. /* Finally start the scheduler. */
  87. vTaskStartScheduler();
  88.  
  89. return 0;
  90. }
  91. /*-----------------------------------------------------------*/
  92.  
  93. void initPLL(void)
  94. {
  95. // Configure PLL prescaler, PLL postscaler, PLL divisor
  96. PLLFBD = 41; // M = 43 FRC
  97. //PLLFBD = 30; // M = 32 XT
  98. CLKDIVbits.PLLPOST=0; // N1 = 2
  99. CLKDIVbits.PLLPRE=0; // N2 = 2
  100.  
  101. // Initiate Clock Switch to Internal FRC with PLL (NOSC = 0b001)
  102. __builtin_write_OSCCONH(0x01); // FRC
  103. //__builtin_write_OSCCONH(0x03); // XT
  104. __builtin_write_OSCCONL(0x01);
  105.  
  106. // Wait for Clock switch to occur
  107. while (OSCCONbits.COSC != 0b001); // FRC
  108. //while (OSCCONbits.COSC != 0b011); // XT
  109.  
  110. // Wait for PLL to lock
  111. while(OSCCONbits.LOCK!=1) {};
  112. }
  113.  
  114. static void prvSetupHardware( void )
  115. {
  116. //ADPCFG = 0xFFFF; //make ADC pins all digital - adaugat
  117. vParTestInitialise();
  118. initPLL();
  119. }
  120.  
  121. __________________
  122.  
  123.  
  124. mergem in view watch si alegem variabilele
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement