fork download
  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 hTask3 = NULL;
  23. void Task1(void *params) {
  24. for (;;) {
  25. _RB15 = ~_RB15; //comutare LED-ul 15
  26. vTaskDelay(2500); // 2.5 secunde
  27.  
  28. // Suspendă T3 după 10 secunde și îl reactivează după 15 secunde
  29. if (xTaskGetTickCount()>=(10000)) {
  30. vTaskSuspend(hTask3); // Suspendă T3
  31. }
  32. if (xTaskGetTickCount() >= (15000)) {
  33. vTaskResume(hTask3); // Reia T3
  34. }
  35. }
  36. }
  37.  
  38. void Task2(void *params) {
  39. for (;;) {
  40. _RB12 = ~_RB12; // Comută LED-ul 12
  41. vTaskDelay(500); // 0.5 secunde
  42.  
  43. // Creează T3 după 4 secunde de la pornirea aplicației
  44. if ((xTaskGetTickCount() >= 4000) && (hTask3 == NULL)) {
  45. xTaskCreate(Task3,(signed portCHAR *) "Ts3", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 2, &hTask3);
  46. }
  47. }
  48. }
  49.  
  50. void Task3(void *params) {
  51. for (;;)
  52. {
  53. _RB13 =~ _RB13;
  54. vTaskDelay(1000);
  55. }
  56. }
  57.  
  58.  
  59.  
  60. int main( void )
  61. {
  62. /* Configure any hardware required for this demo. */
  63. prvSetupHardware();
  64.  
  65. xTaskCreate(Task1, (signed portCHAR *) "Ts1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1, NULL);
  66. xTaskCreate(Task2, (signed portCHAR *) "Ts2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 3, NULL);
  67.  
  68.  
  69. /* Finally start the scheduler. */
  70. vTaskStartScheduler();
  71.  
  72. return 0;
  73. }
  74. /*-----------------------------------------------------------*/
  75.  
  76. void initPLL(void)
  77. {
  78. // Configure PLL prescaler, PLL postscaler, PLL divisor
  79. PLLFBD = 41; // M = 43 FRC
  80. //PLLFBD = 30; // M = 32 XT
  81. CLKDIVbits.PLLPOST=0; // N1 = 2
  82. CLKDIVbits.PLLPRE=0; // N2 = 2
  83.  
  84. // Initiate Clock Switch to Internal FRC with PLL (NOSC = 0b001)
  85. __builtin_write_OSCCONH(0x01); // FRC
  86. //__builtin_write_OSCCONH(0x03); // XT
  87. __builtin_write_OSCCONL(0x01);
  88.  
  89. // Wait for Clock switch to occur
  90. while (OSCCONbits.COSC != 0b001); // FRC
  91. //while (OSCCONbits.COSC != 0b011); // XT
  92.  
  93. // Wait for PLL to lock
  94. while(OSCCONbits.LOCK!=1) {};
  95. }
  96.  
  97. static void prvSetupHardware( void )
  98. {
  99. //ADPCFG = 0xFFFF; //make ADC pins all digital - adaugat
  100. vParTestInitialise();
  101. initPLL();
  102. }
  103.  
  104.  
  105.  
Success #stdin #stdout 0.02s 25888KB
stdin
Standard input is empty
stdout
#include <stdio.h>

/* Scheduler includes. */
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "croutine.h"

/* Demo application includes. */
#include "partest.h"


// Select Internal FRC at POR
_FOSCSEL(FNOSC_FRC);
// Enable Clock Switching and Configure
_FOSC(FCKSM_CSECMD & OSCIOFNC_OFF);		// FRC + PLL
//_FOSC(FCKSM_CSECMD & OSCIOFNC_OFF & POSCMD_XT);		// XT + PLL
_FWDT(FWDTEN_OFF); 		// Watchdog Timer Enabled/disabled by user software

static void prvSetupHardware( void );

xTaskHandle hTask3 = NULL;
void Task1(void *params) {
for (;;) {
        _RB15 = ~_RB15; //comutare LED-ul 15
        vTaskDelay(2500);  // 2.5 secunde

        // Suspendă T3 după 10 secunde și îl reactivează după 15 secunde
        if (xTaskGetTickCount()>=(10000)) {
            vTaskSuspend(hTask3);  // Suspendă T3
        }
        if (xTaskGetTickCount() >= (15000)) {
            vTaskResume(hTask3);  // Reia T3
        }
    }
}

void Task2(void *params) {
	for (;;) {
        _RB12 = ~_RB12;  // Comută LED-ul 12
        vTaskDelay(500);  // 0.5 secunde

        // Creează T3 după 4 secunde de la pornirea aplicației
        if ((xTaskGetTickCount() >= 4000) && (hTask3 == NULL)) {
            xTaskCreate(Task3,(signed portCHAR *) "Ts3", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 2, &hTask3);
        }
    }
}

void Task3(void *params) {
	for (;;)
		{
		_RB13 =~ _RB13;
		vTaskDelay(1000);
		}
}



int main( void )
{
	/* Configure any hardware required for this demo. */
	prvSetupHardware();

	xTaskCreate(Task1, (signed portCHAR *) "Ts1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1, NULL);
	xTaskCreate(Task2, (signed portCHAR *) "Ts2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 3, NULL);
	
	
	/* Finally start the scheduler. */
	vTaskStartScheduler();

	return 0;
}
/*-----------------------------------------------------------*/

void initPLL(void)
{
// Configure PLL prescaler, PLL postscaler, PLL divisor
	PLLFBD = 41; 		// M = 43 FRC
	//PLLFBD = 30; 		// M = 32 XT
	CLKDIVbits.PLLPOST=0; 	// N1 = 2
	CLKDIVbits.PLLPRE=0; 	// N2 = 2

// Initiate Clock Switch to Internal FRC with PLL (NOSC = 0b001)
	__builtin_write_OSCCONH(0x01);	// FRC
	//__builtin_write_OSCCONH(0x03);	// XT
	__builtin_write_OSCCONL(0x01);

// Wait for Clock switch to occur
	while (OSCCONbits.COSC != 0b001);	// FRC
	//while (OSCCONbits.COSC != 0b011);	// XT

// Wait for PLL to lock
	while(OSCCONbits.LOCK!=1) {};
}

static void prvSetupHardware( void )
{
	//ADPCFG = 0xFFFF;				//make ADC pins all digital - adaugat
	vParTestInitialise();
	initPLL();
}