Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #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 );
- xQueueHandle qh;
- void Task1(void *params) {
- static int i = 0;
- for (;;)
- {
- i++;
- if (qh != NULL)
- {
- xQueueSend(qh, &i, 500);
- vTaskDelay(500); // 5 msec
- }
- }
- }
- void Task2(void *params) {
- static int j = 0;
- for (;;)
- {
- if (qh != NULL)
- {
- xQueueReceive(qh, &j, 500);
- PORTB = ~j<<12;
- vTaskDelay(10);
- }
- }
- }
- int main( void )
- {
- /* Configure any hardware required for this demo. */
- prvSetupHardware();
- qh = xQueueCreate(1, sizeof(int));
- 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();
- }
Advertisement
Advertisement
Advertisement
RAW Paste Data
Copied
Advertisement