Advertisement
Eddie_1337

PATR_L7_ex2

Jan 20th, 2022
689
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. xQueueHandle qh;
  22.  
  23. void Task1(void *params) {
  24.     static int i = 0;
  25.     for (;;)
  26.     {      
  27.         i++;
  28.         if (qh != NULL)
  29.         {
  30.             xQueueSend(qh, &i, 500);
  31.             vTaskDelay(500); // 5 msec
  32.         }
  33.     }
  34. }
  35.  
  36. void Task2(void *params) {
  37.     static int j = 0;
  38.     for (;;)
  39.     {
  40.         if (qh != NULL)
  41.         {
  42.             xQueueReceive(qh, &j, 500);
  43.             PORTB = ~j<<12;
  44.             vTaskDelay(10);
  45.         }
  46.     }
  47. }
  48.  
  49.  
  50. int main( void )
  51. {
  52.     /* Configure any hardware required for this demo. */
  53.     prvSetupHardware();
  54.     qh = xQueueCreate(1, sizeof(int));
  55.     xTaskCreate(Task1, (signed portCHAR *) "Ts1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1, NULL);
  56.     xTaskCreate(Task2, (signed portCHAR *) "Ts2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 3, NULL);
  57.  
  58.     /* Finally start the scheduler. */
  59.     vTaskStartScheduler();
  60.  
  61.     return 0;
  62. }
  63. /*-----------------------------------------------------------*/
  64.  
  65. void initPLL(void)
  66. {
  67. // Configure PLL prescaler, PLL postscaler, PLL divisor
  68.     PLLFBD = 41;        // M = 43 FRC
  69.     //PLLFBD = 30;      // M = 32 XT
  70.     CLKDIVbits.PLLPOST=0;   // N1 = 2
  71.     CLKDIVbits.PLLPRE=0;    // N2 = 2
  72.  
  73. // Initiate Clock Switch to Internal FRC with PLL (NOSC = 0b001)
  74.     __builtin_write_OSCCONH(0x01);  // FRC
  75.     //__builtin_write_OSCCONH(0x03);    // XT
  76.     __builtin_write_OSCCONL(0x01);
  77.  
  78. // Wait for Clock switch to occur
  79.     while (OSCCONbits.COSC != 0b001);   // FRC
  80.     //while (OSCCONbits.COSC != 0b011); // XT
  81.  
  82. // Wait for PLL to lock
  83.     while(OSCCONbits.LOCK!=1) {};
  84. }
  85.  
  86. static void prvSetupHardware( void )
  87. {
  88.     //ADPCFG = 0xFFFF;              //make ADC pins all digital - adaugat
  89.     vParTestInitialise();
  90.     initPLL();
  91. }
  92.  
  93.  
  94.  
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement