Advertisement
Adytzu04

Lab 5p1

Oct 31st, 2014
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.50 KB | None | 0 0
  1. //config
  2.  
  3. //start defining macros
  4. #define traceTASK_INCREMENT_TICK(xTickCount)  _RB7=~_RB7
  5. #define traceTASK_DELAY() _RB8=~_RB8
  6. //end defining macros
  7.  
  8. //main
  9.  
  10. #include <stdio.h>
  11.  
  12. /* Scheduler includes. */
  13. #include "FreeRTOS.h"
  14. #include "task.h"
  15. #include "queue.h"
  16. #include "croutine.h"
  17.  
  18. /* Demo application includes. */
  19. #include "partest.h"
  20.  
  21.  
  22. // Select Internal FRC at POR
  23. _FOSCSEL(FNOSC_FRC);
  24. // Enable Clock Switching and Configure
  25. _FOSC(FCKSM_CSECMD & OSCIOFNC_OFF);     // FRC + PLL
  26. //_FOSC(FCKSM_CSECMD & OSCIOFNC_OFF & POSCMD_XT);       // XT + PLL
  27. _FWDT(FWDTEN_OFF);      // Watchdog Timer Enabled/disabled by user software
  28.  
  29. static void prvSetupHardware( void );
  30.  
  31.  
  32. void Task1(void *params) {
  33.     for (;;)
  34.         {      
  35.         }
  36. }
  37.  
  38. void Task2(void *params) {
  39.     for (;;)
  40.         {
  41.         vTaskDelay(2000);
  42.         }
  43. }
  44.  
  45. void Task3(void *params) {
  46.     for (;;)
  47.         {
  48.         //PORTBbits.RB13 = ~PORTBbits.RB13;
  49.         vParTestToggleLED(13);
  50.         vTaskDelay(1000);
  51.         }
  52. }
  53.  
  54. void Task4(void *params)
  55. {
  56.     for (;;)
  57.         {
  58.         //PORTBbits.RB12 = ~PORTBbits.RB12;
  59.         vParTestToggleLED(12);
  60.         vTaskDelay(1000);
  61.         }
  62. }
  63.  
  64.  
  65. int main( void )
  66. {
  67.     /* Configure any hardware required for this demo. */
  68.     prvSetupHardware();
  69.  
  70.     _TRISB7=1;
  71.     _TRISB8=1;
  72. //  xTaskCreate(Task1, (signed portCHAR *) "Ts1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1, NULL);
  73.     xTaskCreate(Task2, (signed portCHAR *) "Ts2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1, NULL);
  74. //  xTaskCreate(Task3, (signed portCHAR *) "Ts3", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1, NULL);
  75. //  xTaskCreate(Task4, (signed portCHAR *) "Ts4", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1, NULL);
  76.  
  77.     /* Finally start the scheduler. */
  78.     vTaskStartScheduler();
  79.  
  80.     return 0;
  81. }
  82. /*-----------------------------------------------------------*/
  83.  
  84. void initPLL(void)
  85. {
  86. // Configure PLL prescaler, PLL postscaler, PLL divisor
  87.     PLLFBD = 41;        // M = 43 FRC
  88.     //PLLFBD = 30;      // M = 32 XT
  89.     CLKDIVbits.PLLPOST=0;   // N1 = 2
  90.     CLKDIVbits.PLLPRE=0;    // N2 = 2
  91.  
  92. // Initiate Clock Switch to Internal FRC with PLL (NOSC = 0b001)
  93.     __builtin_write_OSCCONH(0x01);  // FRC
  94.     //__builtin_write_OSCCONH(0x03);    // XT
  95.     __builtin_write_OSCCONL(0x01);
  96.  
  97. // Wait for Clock switch to occur
  98.     while (OSCCONbits.COSC != 0b001);   // FRC
  99.     //while (OSCCONbits.COSC != 0b011); // XT
  100.  
  101. // Wait for PLL to lock
  102.     while(OSCCONbits.LOCK!=1) {};
  103. }
  104.  
  105. static void prvSetupHardware( void )
  106. {
  107.     //ADPCFG = 0xFFFF;              //make ADC pins all digital - adaugat
  108.     vParTestInitialise();
  109.     initPLL();
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement