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"
- #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 );
- xSemaphoreHandle xSemaphore = NULL;
- int counter = 0;
- void __attribute__ ((interrupt, no_auto_psv)) _INT0Interrupt(void)
- {
- portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
- xSemaphoreGiveFromISR( xSemaphore, &xHigherPriorityTaskWoken );
- if(xHigherPriorityTaskWoken)
- taskYELD();
- IFS0bits.INT0IF = 0;// Resetam flagul corespunzator intreruperii
- // INT0 pentru a nu se reapela rutina de intrerupere
- }
- void T1(void *params) {
- for (;;)
- {
- if( xSemaphoreTake( xSemaphore, 100 ) == pdTRUE )
- {
- counter = (counter + 1)%16;
- PORTB = ~counter << 12;
- }
- }
- }
- //void T2(void *params) {
- // for (;;)
- // {
- // vTaskDelay(2000);
- // }
- //}
- int main( void )
- {
- xSemaphore = xSemaphoreCreateBinary();
- prvSetupHardware();
- xTaskCreate(Task1, (signed portCHAR *) "Ts1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1, 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
Add Comment
Please, Sign In to add comment
Advertisement