Advertisement
Eddie_1337

PATR_L13

Jan 13th, 2022
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 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. #include "partest.h"
  10.  
  11.  
  12. // Select Internal FRC at POR
  13. _FOSCSEL(FNOSC_FRC);
  14. // Enable Clock Switching and Configure
  15. _FOSC(FCKSM_CSECMD & OSCIOFNC_OFF); // FRC + PLL
  16. //_FOSC(FCKSM_CSECMD & OSCIOFNC_OFF & POSCMD_XT); // XT + PLL
  17. _FWDT(FWDTEN_OFF); // Watchdog Timer Enabled/disabled by user software
  18.  
  19. static void prvSetupHardware( void );
  20.  
  21. xSemaphoreHandle xSemaphore = NULL;
  22. int counter = 0;
  23.  
  24. void __attribute__ ((interrupt, no_auto_psv)) _INT0Interrupt(void)
  25. {
  26. portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
  27. xSemaphoreGiveFromISR( xSemaphore, &xHigherPriorityTaskWoken );
  28. if(xHigherPriorityTaskWoken)
  29. taskYELD();
  30. IFS0bits.INT0IF = 0;// Resetam flagul corespunzator intreruperii
  31. // INT0 pentru a nu se reapela rutina de intrerupere
  32. }
  33.  
  34. void T1(void *params) {
  35.  
  36. for (;;)
  37. {
  38. if( xSemaphoreTake( xSemaphore, 100 ) == pdTRUE )
  39. {
  40. counter = (counter + 1)%16;
  41. PORTB = ~counter << 12;
  42. }
  43. }
  44. }
  45.  
  46. //void T2(void *params) {
  47. // for (;;)
  48. // {
  49. // vTaskDelay(2000);
  50. // }
  51. //}
  52.  
  53. int main( void )
  54. {
  55. xSemaphore = xSemaphoreCreateBinary();
  56. prvSetupHardware();
  57.  
  58. xTaskCreate(Task1, (signed portCHAR *) "Ts1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1, NULL);
  59.  
  60. /* Finally start the scheduler. */
  61. vTaskStartScheduler();
  62.  
  63. return 0;
  64. }
  65. /*-----------------------------------------------------------*/
  66.  
  67. void initPLL(void)
  68. {
  69. // Configure PLL prescaler, PLL postscaler, PLL divisor
  70. PLLFBD = 41; // M = 43 FRC
  71. //PLLFBD = 30; // M = 32 XT
  72. CLKDIVbits.PLLPOST=0; // N1 = 2
  73. CLKDIVbits.PLLPRE=0; // N2 = 2
  74.  
  75. // Initiate Clock Switch to Internal FRC with PLL (NOSC = 0b001)
  76. __builtin_write_OSCCONH(0x01); // FRC
  77. //__builtin_write_OSCCONH(0x03); // XT
  78. __builtin_write_OSCCONL(0x01);
  79.  
  80. // Wait for Clock switch to occur
  81. while (OSCCONbits.COSC != 0b001); // FRC
  82. //while (OSCCONbits.COSC != 0b011); // XT
  83.  
  84. // Wait for PLL to lock
  85. while(OSCCONbits.LOCK!=1) {};
  86. }
  87.  
  88. static void prvSetupHardware( void )
  89. {
  90. //ADPCFG = 0xFFFF; //make ADC pins all digital - adaugat
  91. vParTestInitialise();
  92. initPLL();
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement