├── examples ├── AnalogRead_DigitalRead │ └── AnalogRead_DigitalRead.ino ├── Blink_AnalogRead │ └── Blink_AnalogRead.ino ├── ExampleList.xlsx ├── GoldilocksAnalogueTestSuite │ ├── GA_Header.h │ └── GoldilocksAnalogueTestSuite.ino ├── _01-TaskSwitching │ ├── _01-TaskSwitching.JPG │ └── _01-TaskSwitching.ino ├── _02-TaskIdleHook │ ├── _02-TaskIdleHook.ino │ └── _02-TaskIdleHook.jpg ├── _03-TaskDeleteUsage │ ├── _03-TaskDeleteUsage.ino │ └── _03-TaskDeleteUsage.jpg ├── _04-CreatingTaskFromOtherTask │ ├── _04-CreatingTaskFromOtherTask.ino │ └── _04-CreatingTaskFromOtherTask.png ├── _05-TaskPriorityChange │ ├── _05-TaskPriorityChange.ino │ └── _05-TaskPriorityChange.png ├── _06-TaskPriorityChange │ ├── _06-TaskPriorityChange.ino │ └── _06-TaskPriorityChange.png ├── _07-TaskSuspendAndResume │ ├── _07-TaskSuspendAndResume.ino │ └── _07-TaskSuspendAndResume.png ├── _08-TaskSuspendAndResume │ ├── _08-TaskSuspendAndResume.ino │ └── _08-TaskSuspendAndResume.png ├── _09-ResumingTaskFromISR │ ├── _09-ResumingTaskFromISR.ino │ └── _09-ResumingTaskFromISR.png ├── _10-ReadingTaskInfo │ ├── 10-ReadingTaskInfo.png │ └── _10-ReadingTaskInfo.ino ├── _11-BinarySemaphore │ └── _11-BinarySemaphore.ino └── ~$ExampleList.xlsx ├── library.properties ├── readme.md └── src ├── .gitignore ├── Arduino_FreeRTOS.h ├── FreeRTOSConfig.h ├── FreeRTOSVariant.h ├── README.txt ├── StackMacros.h ├── croutine.c ├── croutine.h ├── event_groups.c ├── event_groups.h ├── heap_1.zip ├── heap_4.c ├── heap_4.zip ├── license.txt ├── list.c ├── list.h ├── mpu_wrappers.h ├── port.c ├── portable.h ├── portmacro.h ├── projdefs.h ├── queue.c ├── queue.h ├── semphr.h ├── task.h ├── tasks.c ├── timers.c ├── timers.h └── variantHooks.cpp /examples/AnalogRead_DigitalRead/AnalogRead_DigitalRead.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include // add the FreeRTOS functions for Semaphores (or Flags). 3 | 4 | // Declare a mutex Semaphore Handle which we will use to manage the Serial Port. 5 | // It will be used to ensure only only one Task is accessing this resource at any time. 6 | SemaphoreHandle_t xSerialSemaphore; 7 | 8 | // define two Tasks for DigitalRead & AnalogRead 9 | void TaskDigitalRead( void *pvParameters ); 10 | void TaskAnalogRead( void *pvParameters ); 11 | 12 | // the setup function runs once when you press reset or power the board 13 | void setup() { 14 | 15 | // initialize serial communication at 9600 bits per second: 16 | Serial.begin(9600); 17 | 18 | // Semaphores are useful to stop a Task proceeding, where it should be paused to wait, 19 | // because it is sharing a resource, such as the Serial port. 20 | // Semaphores should only be used whilst the scheduler is running, but we can set it up here. 21 | if ( xSerialSemaphore == NULL ) // Check to confirm that the Serial Semaphore has not already been created. 22 | { 23 | xSerialSemaphore = xSemaphoreCreateMutex(); // Create a mutex semaphore we will use to manage the Serial Port 24 | if ( ( xSerialSemaphore ) != NULL ) 25 | xSemaphoreGive( ( xSerialSemaphore ) ); // Make the Serial Port available for use, by "Giving" the Semaphore. 26 | } 27 | 28 | // Now set up two Tasks to run independently. 29 | xTaskCreate( 30 | TaskDigitalRead 31 | , (const portCHAR *)"DigitalRead" // A name just for humans 32 | , 128 // This stack size can be checked & adjusted by reading the Stack Highwater 33 | , NULL 34 | , 2 // Priority, with 1 being the highest, and 4 being the lowest. 35 | , NULL ); 36 | 37 | xTaskCreate( 38 | TaskAnalogRead 39 | , (const portCHAR *) "AnalogRead" 40 | , 128 // Stack size 41 | , NULL 42 | , 1 // Priority 43 | , NULL ); 44 | 45 | // Now the Task scheduler, which takes over control of scheduling individual Tasks, is automatically started. 46 | } 47 | 48 | void loop() 49 | { 50 | // Empty. Things are done in Tasks. 51 | } 52 | 53 | /*--------------------------------------------------*/ 54 | /*---------------------- Tasks ---------------------*/ 55 | /*--------------------------------------------------*/ 56 | 57 | void TaskDigitalRead( void *pvParameters __attribute__((unused)) ) // This is a Task. 58 | { 59 | /* 60 | DigitalReadSerial 61 | Reads a digital input on pin 2, prints the result to the serial monitor 62 | 63 | This example code is in the public domain. 64 | */ 65 | 66 | // digital pin 2 has a pushbutton attached to it. Give it a name: 67 | uint8_t pushButton = 2; 68 | 69 | // make the pushbutton's pin an input: 70 | pinMode(pushButton, INPUT); 71 | 72 | for (;;) // A Task shall never return or exit. 73 | { 74 | // read the input pin: 75 | int buttonState = digitalRead(pushButton); 76 | 77 | // See if we can obtain or "Take" the Serial Semaphore. 78 | // If the semaphore is not available, wait 5 ticks of the Scheduler to see if it becomes free. 79 | if ( xSemaphoreTake( xSerialSemaphore, ( TickType_t ) 5 ) == pdTRUE ) 80 | { 81 | // We were able to obtain or "Take" the semaphore and can now access the shared resource. 82 | // We want to have the Serial Port for us alone, as it takes some time to print, 83 | // so we don't want it getting stolen during the middle of a conversion. 84 | // print out the state of the button: 85 | Serial.println(buttonState); 86 | 87 | xSemaphoreGive( xSerialSemaphore ); // Now free or "Give" the Serial Port for others. 88 | } 89 | 90 | vTaskDelay(1); // one tick delay (15ms) in between reads for stability 91 | } 92 | } 93 | 94 | void TaskAnalogRead( void *pvParameters __attribute__((unused)) ) // This is a Task. 95 | { 96 | 97 | for (;;) 98 | { 99 | // read the input on analog pin 0: 100 | int sensorValue = analogRead(A0); 101 | 102 | // See if we can obtain or "Take" the Serial Semaphore. 103 | // If the semaphore is not available, wait 5 ticks of the Scheduler to see if it becomes free. 104 | if ( xSemaphoreTake( xSerialSemaphore, ( TickType_t ) 5 ) == pdTRUE ) 105 | { 106 | // We were able to obtain or "Take" the semaphore and can now access the shared resource. 107 | // We want to have the Serial Port for us alone, as it takes some time to print, 108 | // so we don't want it getting stolen during the middle of a conversion. 109 | // print out the value you read: 110 | Serial.println(sensorValue); 111 | 112 | xSemaphoreGive( xSerialSemaphore ); // Now free or "Give" the Serial Port for others. 113 | } 114 | 115 | vTaskDelay(1); // one tick delay (15ms) in between reads for stability 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /examples/Blink_AnalogRead/Blink_AnalogRead.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // define two tasks for Blink & AnalogRead 4 | void TaskBlink( void *pvParameters ); 5 | void TaskAnalogRead( void *pvParameters ); 6 | 7 | // the setup function runs once when you press reset or power the board 8 | void setup() { 9 | 10 | // Now set up two tasks to run independently. 11 | xTaskCreate( 12 | TaskBlink 13 | , (const portCHAR *)"Blink" // A name just for humans 14 | , 128 // This stack size can be checked & adjusted by reading the Stack Highwater 15 | , NULL 16 | , 2 // Priority, with 1 being the highest, and 4 being the lowest. 17 | , NULL ); 18 | 19 | xTaskCreate( 20 | TaskAnalogRead 21 | , (const portCHAR *) "AnalogRead" 22 | , 128 // Stack size 23 | , NULL 24 | , 1 // Priority 25 | , NULL ); 26 | 27 | // Now the task scheduler, which takes over control of scheduling individual tasks, is automatically started. 28 | } 29 | 30 | void loop() 31 | { 32 | // Empty. Things are done in Tasks. 33 | } 34 | 35 | /*--------------------------------------------------*/ 36 | /*---------------------- Tasks ---------------------*/ 37 | /*--------------------------------------------------*/ 38 | 39 | void TaskBlink(void *pvParameters) // This is a task. 40 | { 41 | (void) pvParameters; 42 | 43 | // initialize digital pin 13 as an output. 44 | pinMode(13, OUTPUT); 45 | 46 | for (;;) // A Task shall never return or exit. 47 | { 48 | digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level) 49 | vTaskDelay( 1000 / portTICK_PERIOD_MS ); // wait for one second 50 | digitalWrite(13, LOW); // turn the LED off by making the voltage LOW 51 | vTaskDelay( 1000 / portTICK_PERIOD_MS ); // wait for one second 52 | } 53 | } 54 | 55 | void TaskAnalogRead(void *pvParameters) // This is a task. 56 | { 57 | (void) pvParameters; 58 | 59 | // initialize serial communication at 9600 bits per second: 60 | Serial.begin(9600); 61 | 62 | for (;;) 63 | { 64 | // read the input on analog pin 0: 65 | int sensorValue = analogRead(A0); 66 | // print out the value you read: 67 | Serial.println(sensorValue); 68 | vTaskDelay(1); // one tick delay (30ms) in between reads for stability 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /examples/ExampleList.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ExploreEmbedded/Arduino_FreeRTOS/14b0093782c1799cf3fcdd3b99ef975362887433/examples/ExampleList.xlsx -------------------------------------------------------------------------------- /examples/GoldilocksAnalogueTestSuite/GA_Header.h: -------------------------------------------------------------------------------- 1 | #ifndef GA_HEADER_h // include guard 2 | #define GA_HEADER_h 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | /*--------------------------------------------------*/ 11 | /*------------Often Configured Parameters-----------*/ 12 | /*--------------------------------------------------*/ 13 | 14 | #define SAMPLE_RATE 16000 // samples per second 15 | #define DELAY 128000 // bytes of delay 16 | 17 | /* Working buffer */ 18 | #define CMD_BUFFER_SIZE 8192 // size of working buffer (on heap) 19 | 20 | /*--------------------------------------------------*/ 21 | /*---------------Public Functions-------------------*/ 22 | /*--------------------------------------------------*/ 23 | 24 | void AudioCodec_ADC_init(void) __attribute__((flatten)); 25 | void AudioCodec_ADC(uint16_t* _modvalue) __attribute__((hot, flatten)); 26 | 27 | void alaw_compress1(int16_t* linval, uint8_t* logval) __attribute__ ((hot, flatten)); 28 | void alaw_expand1(uint8_t* logval, int16_t* linval) __attribute__ ((hot, flatten)); 29 | 30 | void audioCodec_dsp( uint16_t* ch_A, uint16_t* ch_B) __attribute__ ((hot, flatten)); 31 | // prototype for the DSP function to be implemented. 32 | // needs to at least provide *ch_A and *ch_B 33 | // within Timer1 interrupt routine - time critical I/O. Keep it short and punchy! 34 | 35 | /*--------------------------------------------------*/ 36 | 37 | void AudioCodec_ADC_init(void) 38 | { 39 | // setup ADCs 40 | ADMUX = _BV(REFS1) | _BV(REFS0) | _BV(ADLAR) | _BV(MUX2) | _BV(MUX1) | _BV(MUX0); // 2.56V reference with external capacitor at AREF pin - left justify - start sampling MIC input ADC7 41 | ADCSRA = _BV(ADEN) | _BV(ADSC) | _BV(ADATE) | _BV(ADPS2) | _BV(ADPS1) | _BV(ADPS0); // ADC enable, auto trigger, ck/128 = 192kHz 42 | ADCSRB = 0x00; // free running mode 43 | DIDR0 = _BV(ADC7D) | _BV(ADC6D) | _BV(ADC2D) | _BV(ADC1D) | _BV(ADC0D); // turn off digital input for pin ADC6 Line and ADC7 Mic input (and ADC2, ADC1, & ADC0) 44 | 45 | // Analogue Comparator Disable 46 | // When the ACD bit is written logic one, the power to the Analogue Comparator is switched off. 47 | // This bit can be set at any time to turn off the Analogue Comparator. 48 | // This will reduce power consumption in Active and Idle mode. 49 | // When changing the ACD bit, the Analogue Comparator Interrupt must be disabled by clearing the ACIE bit in ACSR. 50 | // Otherwise an interrupt can occur when the ACD bit is changed. 51 | ACSR &= ~_BV(ACIE); 52 | ACSR |= _BV(ACD); 53 | 54 | } 55 | 56 | // adc sampling routine 57 | void AudioCodec_ADC(uint16_t* _modvalue) 58 | { 59 | if (ADCSRA & _BV(ADIF)) // check if sample ready 60 | { 61 | *_modvalue = ADCW; // fetch ADCL first to freeze sample, then ADCH. It is done by the compiler. 62 | ADCSRA |= _BV(ADIF); // reset the interrupt flag 63 | } 64 | } 65 | 66 | /* 67 | ========================================================================== 68 | 69 | FUNCTION NAME: alaw_compress11 70 | 71 | DESCRIPTION: ALaw encoding rule according ITU-T Rec. G.711. 72 | 73 | PROTOTYPE: int8_t alaw_compress1( int16_t linval ) 74 | PARAMETERS: 75 | linval: (In) linear samples (only 12 MSBits are taken into account) 76 | logval: (Out) compressed sample (8 bit right justified without sign extension) 77 | 78 | RETURN VALUE: none. 79 | 80 | ========================================================================== 81 | */ 82 | void alaw_compress1 (int16_t* linval, uint8_t* logval) 83 | { 84 | uint16_t ix, iexp; 85 | 86 | ix = *linval < 0 /* 0 <= ix < 2048 */ 87 | ? ~*linval >> 4 /* 1's complement for negative values */ 88 | : *linval >> 4; 89 | 90 | /* Do more, if exponent > 0 */ 91 | if (ix > 15) /* exponent=0 for ix <= 15 */ 92 | { 93 | iexp = 1; /* first step: */ 94 | while (ix > 16 + 15) /* find mantissa and exponent */ 95 | { 96 | ix >>= 1; 97 | iexp++; 98 | } 99 | ix -= 16; /* second step: remove leading '1' */ 100 | 101 | ix += iexp << 4; /* now compute encoded value */ 102 | } 103 | 104 | if (*linval >= 0) ix |= (0x0080); /* add sign bit */ 105 | 106 | *logval = (uint8_t)(ix ^ (0x0055)); /* toggle even bits */ 107 | } 108 | /* ................... End of alaw_compress1() ..................... */ 109 | 110 | 111 | /* 112 | ========================================================================== 113 | 114 | FUNCTION NAME: alaw_expand1 115 | 116 | DESCRIPTION: ALaw decoding rule according ITU-T Rec. G.711. 117 | 118 | PROTOTYPE: int16_t alaw_expand1( uint8_t logval ) 119 | 120 | PARAMETERS: 121 | logval: (In) buffer with compressed samples (8 bit right justified, 122 | without sign extension) 123 | linval: (Out) buffer with linear samples (13 bits left justified) 124 | 125 | RETURN VALUE: none. 126 | ============================================================================ 127 | */ 128 | void alaw_expand1(uint8_t* logval, int16_t* linval) 129 | { 130 | uint8_t ix, iexp; 131 | int16_t mant; 132 | 133 | ix = (*logval ^ (0x55)); /* re-toggle toggled even bits */ 134 | 135 | ix &= 0x7F; /* remove sign bit */ 136 | iexp = ix >> 4; /* extract exponent */ 137 | mant = ix & 0x0f; /* now get mantissa */ 138 | if (iexp > 0) 139 | mant = mant + 16; /* add leading '1', if exponent > 0 */ 140 | 141 | mant = (mant << 4) + (0x0008); /* now mantissa left justified and */ 142 | /* 1/2 quantization step added */ 143 | if (iexp > 1) /* now left shift according exponent */ 144 | mant = mant << (iexp - 1); 145 | 146 | *linval = *logval > 127 /* invert, if negative sample */ 147 | ? mant 148 | : -mant; 149 | } 150 | /* ................... End of alaw_expand1() ..................... */ 151 | 152 | #ifdef __cplusplus 153 | } 154 | #endif 155 | 156 | #endif // GA_HEADER_h end include guard 157 | -------------------------------------------------------------------------------- /examples/GoldilocksAnalogueTestSuite/GoldilocksAnalogueTestSuite.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | // This example only works with Goldilocks Analogue, as DAC and SPI SRAM is required. 15 | 16 | // INSTALLATION OF THE 4 FOLLOWING LIBRARIES REQUIRED! 17 | 18 | // From Library: FreeRTOS 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | // From Library: AVR Standard C Time Library 27 | #include 28 | 29 | // From Library: Goldilocks Analogue DAC Library 30 | #include 31 | 32 | // From Library: Goldilocks Analogue SPI RAM Library 33 | #include 34 | #include 35 | 36 | #include "GA_Header.h" 37 | 38 | /*--------------------------------------------------*/ 39 | /*------------------- Globals ----------------------*/ 40 | /*--------------------------------------------------*/ 41 | 42 | DAC_value_t mod7_value; // location to store the ADC value before it is processed. 43 | 44 | uint16_t ch_A_out; // storage for the values to be written to MCP4822 45 | uint16_t ch_B_out; 46 | 47 | SPIRAM_ringBuffer_t SRAM_delayBuffer; // structure to hold the SRAM ringbuffer info. 48 | 49 | filter_t tx_filter; // instantiate a filter, which can be initialised to be a LPF (or BPF or HPF) later. 50 | 51 | // set up variables using the SD utility library functions: 52 | Sd2Card card; 53 | SdVolume volume; 54 | SdFile root; 55 | 56 | static uint8_t * Buff = NULL; /* Put a working buffer on heap later (with pvPortMalloc). */ 57 | 58 | // change this to match your SD shield or module; 59 | // GoldilocksAnalogue SD shield: pin 14 60 | uint8_t const chipSelect = 14; 61 | 62 | // Create a Semaphore binary flag for the Serial Port. To ensure only single access. 63 | SemaphoreHandle_t xSerialSemaphore; 64 | 65 | // define two tasks to operate this test suite. 66 | static void TaskReport( void *pvParameters ); // Report on the status reguarly using USART. 67 | static void TaskAnalogue( void *pvParameters ); // Manage Analogue set-up, then sleep. 68 | 69 | // Test the SPI EEPROM device, prior to building the SPI SRAM Delay loop. 70 | static int8_t testSPIEEPROM( uint_farptr_t p1, uint16_t p2 ); 71 | // p1 = address of the SPI memory to be tested 72 | // p2 = number of bytes to be tested (allocates a RAM buffer of this size too) 73 | 74 | /*--------------------------------------------------*/ 75 | /*-------------------- Set Up ----------------------*/ 76 | /*--------------------------------------------------*/ 77 | 78 | void setup() { 79 | // put your setup code here, to run once: 80 | // Open serial communications and wait for port to open: 81 | Serial.begin(38400); 82 | 83 | Serial.println(F("Hello World!\n")); 84 | 85 | setup_RTC_interrupt(); 86 | 87 | { 88 | tm CurrTimeDate; // set up an array for the RTC info. 89 | // 90 | 91 | CurrTimeDate.tm_year = (uint8_t) ( 2016 - 1900 ); 92 | CurrTimeDate.tm_mon = (uint8_t) 1; // January is month 0, February is month 1, etc 93 | CurrTimeDate.tm_mday = (uint8_t) 18; 94 | CurrTimeDate.tm_hour = (uint8_t) 17; 95 | CurrTimeDate.tm_min = (uint8_t) 16; 96 | CurrTimeDate.tm_sec = (uint8_t) 0; 97 | 98 | set_system_time( mktime( (ptm)&CurrTimeDate)); 99 | } 100 | 101 | // Semaphores are useful to stop a task proceeding, where it should be stopped because it is using a resource, such as the Serial port. 102 | // But they should only be used whilst the scheduler is running. 103 | if ( xSerialSemaphore == NULL ) // Check to see if the Serial Semaphore has not been created. 104 | { 105 | xSerialSemaphore = xSemaphoreCreateMutex(); // mutex semaphore for Serial Port 106 | if ( ( xSerialSemaphore ) != NULL ) 107 | xSemaphoreGive( ( xSerialSemaphore ) ); // make the Serial Port available 108 | } 109 | 110 | SPI.begin(); // warm up the SPI interface, so it can be used for the SPI RAM testing. 111 | 112 | Serial.print(F("SPI SRAM Memory Testing: ")); 113 | if (testSPIEEPROM(RAM0_ADDR + 17, CMD_BUFFER_SIZE)) 114 | Serial.println(F("*** FAILED ***")); 115 | else 116 | Serial.println(F("PASSED")); 117 | 118 | Serial.print(F("SPI EEPROM Memory Testing: ")); 119 | if (testSPIEEPROM(RAM1_ADDR + 17, CMD_BUFFER_SIZE)) 120 | Serial.println(F("*** FAILED ***\n")); 121 | else 122 | Serial.println(F("PASSED\n")); 123 | 124 | // we'll use the SD Card initialization code from the utility libraries 125 | // since we're just testing if the card is working! 126 | Serial.print(F("\nInitializing SD card... ")); 127 | if (!card.init(SPI_HALF_SPEED, chipSelect)) { 128 | Serial.println(F("initialization failed.")); 129 | Serial.println(F("Is a card inserted? You must insert a formatted SD Card to proceed.")); 130 | } else { 131 | Serial.println(F("wiring is correct and a SD card is present.")); 132 | } 133 | 134 | // print the type of card 135 | Serial.print(F("\nCard type: ")); 136 | switch (card.type()) { 137 | case SD_CARD_TYPE_SD1: 138 | Serial.println(F("SD1")); 139 | break; 140 | case SD_CARD_TYPE_SD2: 141 | Serial.println(F("SD2")); 142 | break; 143 | case SD_CARD_TYPE_SDHC: 144 | Serial.println(F("SDHC")); 145 | break; 146 | default: 147 | Serial.println(F("Unknown SD Card Type")); 148 | break; 149 | } 150 | 151 | // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32 152 | if (!volume.init(card)) { 153 | Serial.println(F("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card")); 154 | return; 155 | } 156 | 157 | // print the type and size of the first FAT-type volume 158 | uint32_t volumesize; 159 | Serial.print(F("\nVolume type is FAT")); 160 | Serial.println(volume.fatType(), DEC); 161 | Serial.println(); 162 | 163 | volumesize = volume.blocksPerCluster(); // clusters are collections of blocks 164 | volumesize *= volume.clusterCount(); // we'll have a lot of clusters 165 | volumesize *= 512; // SD card blocks are always 512 bytes 166 | Serial.print(F("Volume size (bytes): ")); 167 | Serial.println(volumesize); 168 | Serial.print(F("Volume size (Kbytes): ")); 169 | volumesize /= 1024; 170 | Serial.println(volumesize); 171 | Serial.print(F("Volume size (Mbytes): ")); 172 | volumesize /= 1024; 173 | Serial.println(volumesize); 174 | 175 | Serial.println(F("\nFiles found on the card (name, date and size in bytes): ")); 176 | root.openRoot(volume); 177 | 178 | // list all files in the card with date and size 179 | root.ls(LS_R | LS_DATE | LS_SIZE); 180 | 181 | // Now set up two tasks to help us with testing. 182 | xTaskCreate( 183 | TaskReport 184 | , (const portCHAR *)"RedLED" // report reguarly on the status of its stack and the tick values. 185 | , 256 // Stack size 186 | , NULL 187 | , 2 // priority 188 | , NULL ); // */ 189 | 190 | xTaskCreate( 191 | TaskAnalogue 192 | , (const portCHAR *) "Analogue" 193 | , 256 // This stack size can be checked & adjusted by reading Highwater 194 | , NULL 195 | , 1 // priority 196 | , NULL ); // */ 197 | 198 | // Start the task scheduler, which takes over control of scheduling individual tasks. 199 | // The scheduler is started in initVariant() found in variantHooks.c 200 | } 201 | 202 | /*--------------------------------------------------*/ 203 | /*---------------------- Tasks ---------------------*/ 204 | /*--------------------------------------------------*/ 205 | 206 | static void TaskAnalogue(void *pvParameters) // Prepare the DAC 207 | { 208 | (void) pvParameters; 209 | TickType_t xLastWakeTime; 210 | /* The xLastWakeTime variable needs to be initialised with the current tick 211 | count. Note that this is the only time we access this variable. From this 212 | point on xLastWakeTime is managed automatically by the vTaskDelayUntil() 213 | API function. */ 214 | xLastWakeTime = xTaskGetTickCount(); 215 | 216 | // Create the SPI SRAM ring-buffer used by audio delay loop. 217 | SPIRAM_ringBuffer_InitBuffer( &SRAM_delayBuffer, (uint_farptr_t)(RAM0_ADDR), sizeof(uint8_t) * DELAY); 218 | 219 | // See if we can obtain the Serial Semaphore. 220 | // If the semaphore is not available, wait 5 ticks to see if it becomes free. 221 | if ( xSemaphoreTake( xSerialSemaphore, ( TickType_t ) 5 ) == pdTRUE ) 222 | { 223 | // We were able to obtain the semaphore and can now access the shared resource. 224 | // We want to have the Serial Port for us alone, as it takes some time to print, 225 | // so we don't want it getting stolen during the middle of a conversion. 226 | 227 | Serial.print(F("DAC_Codec_init ")); 228 | // initialise the USART 1 MSPIM bus specifically for DAC use, with the post-latch configuration. 229 | // pre-latch for audio or AC signals (FALSE), or post-latch for single value setting or DC values (TRUE). 230 | DAC_init(FALSE); 231 | 232 | Serial.print(F("will ")); 233 | // Initialise the sample interrupt timer. 234 | // set up the sampling Timer3 to 48000Hz (or lower), runs at audio sampling rate in Hz. 235 | DAC_Timer3_init(SAMPLE_RATE); 236 | 237 | Serial.print(F("very ")); 238 | // Initialise the filter to be a Low Pass Filter. 239 | tx_filter.cutoff = 0xc000; // set filter to 3/8 of sample frequency. 240 | setIIRFilterLPF( &tx_filter ); // initialise transmit sample filter 241 | 242 | Serial.print(F("soon ")); 243 | // set up ADC sampling on the ADC7 (Microphone). 244 | AudioCodec_ADC_init(); 245 | 246 | Serial.print (F("be ")); 247 | // Set the call back function to do the audio processing. 248 | // Done this way so that we can change the audio handling depending on what we want to achieve. 249 | DAC_setHandler(audioCodec_dsp, &ch_A_out, &ch_B_out); 250 | 251 | Serial.println(F("done.")); 252 | 253 | xSemaphoreGive( xSerialSemaphore ); // Now free the Serial Port for others. 254 | } 255 | 256 | // vTaskSuspend(NULL); // Well, we're pretty much done here. Let's suspend the Task. 257 | // vTaskEndScheduler(); // Or just kill the FreeRTOS scheduler. Rely on Timer3 Interrupt for regular output. 258 | 259 | for (;;) 260 | { 261 | // See if we can obtain the Serial Semaphore. 262 | // If the semaphore is not available, wait 5 ticks to see if it becomes free. 263 | if ( xSemaphoreTake( xSerialSemaphore, ( TickType_t ) 5 ) == pdTRUE ) 264 | { 265 | // We were able to obtain the semaphore and can now access the shared resource. 266 | // We want to have the Serial Port for us alone, as it takes some time to print, 267 | // so we don't want it getting stolen during the middle of a conversion. 268 | 269 | Serial.print(F("Audio Stack HighWater @ ")); 270 | Serial.println(uxTaskGetStackHighWaterMark(NULL)); 271 | 272 | xSemaphoreGive( xSerialSemaphore ); // Now free the Serial Port for others. 273 | } 274 | vTaskDelayUntil( &xLastWakeTime, ( 8192 / portTICK_PERIOD_MS ) ); 275 | } 276 | } 277 | 278 | static void TaskReport(void *pvParameters) // report on the status of the device 279 | { 280 | (void) pvParameters;; 281 | TickType_t xLastWakeTime; 282 | /* The xLastWakeTime variable needs to be initialised with the current tick 283 | count. Note that this is the only time we access this variable. From this 284 | point on xLastWakeTime is managed automatically by the vTaskDelayUntil() 285 | API function. */ 286 | xLastWakeTime = xTaskGetTickCount(); 287 | 288 | time_t currentTick; // set up a location for the current time stamp 289 | 290 | for (;;) 291 | { 292 | // See if we can obtain the Serial Semaphore. 293 | // If the semaphore is not available, wait 5 ticks to see if it becomes free. 294 | if ( xSemaphoreTake( xSerialSemaphore, ( TickType_t ) 5 ) == pdTRUE ) 295 | { 296 | // We were able to obtain the semaphore and can now access the shared resource. 297 | // We want to have the Serial Port for us alone, as it takes some time to print, 298 | // so we don't want it getting stolen during the middle of a conversion. 299 | 300 | Serial.print(F("Report Stack HighWater @ ")); 301 | Serial.print(uxTaskGetStackHighWaterMark(NULL)); 302 | 303 | Serial.print(F(" Current Time: ")); 304 | time((time_t *)¤tTick); 305 | Serial.println(ctime( (time_t *)¤tTick)); 306 | 307 | xSemaphoreGive( xSerialSemaphore ); // Now free the Serial Port for others. 308 | } 309 | vTaskDelayUntil( &xLastWakeTime, ( 2048 / portTICK_PERIOD_MS ) ); 310 | } 311 | } 312 | 313 | /*--------------------------------------------------*/ 314 | /*-------------------- Functions -------------------*/ 315 | /*--------------------------------------------------*/ 316 | 317 | 318 | static int8_t testSPIEEPROM( uint_farptr_t p1, uint16_t p2 ) 319 | { 320 | int8_t ReturnCode; 321 | 322 | if (Buff == NULL) // if there is no Buff buffer allocated (pointer is NULL), then allocate buffer. 323 | if ( !(Buff = (uint8_t *) pvPortMalloc( sizeof(uint8_t) * CMD_BUFFER_SIZE ))) 324 | { 325 | Serial.println(F("pvPortMalloc for *Buff fail..!")); 326 | return SPIRAM_ERROR; 327 | } 328 | 329 | if (p2 >= CMD_BUFFER_SIZE) p2 = CMD_BUFFER_SIZE; 330 | 331 | srand( p1 % 42 ); // create a random seed, based on 42. 332 | 333 | for ( uint16_t i = 0; i < p2; ++i) 334 | { 335 | Buff[i] = (uint8_t) rand(); // fill the Buff with some pseudo random numbers. 336 | } 337 | 338 | Serial.print(F("Testing at 0x")); 339 | Serial.print( (uint32_t)p1, HEX); 340 | Serial.print(F(" for ")); 341 | Serial.print( p2, DEC); 342 | Serial.println(F(" bytes.")); 343 | 344 | ReturnCode = SPIRAM_begin(); 345 | if (ReturnCode) return ReturnCode; // problem with opening the EEPROM / SRAM 346 | 347 | uint_farptr_t FarAddress = p1; 348 | 349 | ReturnCode = SPIRAM_write( FarAddress, Buff, (size_t)p2); 350 | if (ReturnCode) return ReturnCode; /* error or disk full */ 351 | 352 | for (uint16_t i = 0; i < p2; ++i) 353 | { 354 | uint8_t read_result; 355 | 356 | ReturnCode = SPIRAM_read( &read_result, (uint_farptr_t)(FarAddress + i), (size_t)1); 357 | if (ReturnCode) return ReturnCode; /* error or disk full */ 358 | 359 | // Serial.print(F("Written 0x")); 360 | // Serial.print( Buff[i], HEX); 361 | // Serial.print(F(" Read 0x")); 362 | // Serial.println( read_result, HEX); 363 | 364 | if ( Buff[i] != read_result) 365 | { 366 | Serial.print(F("Error at Address 0x")); 367 | Serial.print( (uint_farptr_t)(FarAddress + i), HEX); 368 | Serial.print(F(" with 0x")); 369 | Serial.println( read_result, HEX); 370 | return SPIRAM_ERROR; 371 | } 372 | } 373 | return SPIRAM_SUCCESS; 374 | } 375 | 376 | void audioCodec_dsp( uint16_t * ch_A, uint16_t * ch_B) 377 | { 378 | int16_t xn; 379 | uint8_t cn; 380 | 381 | if ( SPIRAM_ringBuffer_GetCount(&SRAM_delayBuffer) >= DELAY ) 382 | { 383 | cn = SPIRAM_ringBuffer_Pop(&SRAM_delayBuffer); 384 | } 385 | else 386 | { 387 | cn = 0x80 ^ 0x55; // put A-Law nulled signal on the output. 388 | } 389 | 390 | alaw_expand1(&cn, &xn); // expand the A-Law compression 391 | 392 | *ch_A = *ch_B = (uint16_t)(xn + 0x7fff); // put signal out on A & B channel. 393 | 394 | AudioCodec_ADC(&mod7_value.u16); 395 | 396 | xn = mod7_value.u16 - 0x7fe0; // centre the sample to 0 by subtracting 1/2 10bit range. 397 | 398 | IIRFilter( &tx_filter, &xn); // filter sample train 399 | 400 | alaw_compress1(&xn, &cn); // compress using A-Law 401 | 402 | if ( SPIRAM_ringBuffer_GetCount(&SRAM_delayBuffer) <= DELAY ) 403 | { 404 | SPIRAM_ringBuffer_Poke(&SRAM_delayBuffer, cn); 405 | } 406 | } 407 | 408 | 409 | /*--------------------------------------------------*/ 410 | /*---------------------- Loop ----------------------*/ 411 | /*--------------------------------------------------*/ 412 | 413 | void loop() { 414 | // Remember that loop() is simply the freeRTOS idle task. 415 | // It is only something to do, when there's nothing else to do. 416 | 417 | // There are several macros provided in the header file to put 418 | // the device into sleep mode. 419 | // SLEEP_MODE_IDLE (0) 420 | // SLEEP_MODE_ADC _BV(SM0) 421 | // SLEEP_MODE_PWR_DOWN _BV(SM1) 422 | // SLEEP_MODE_PWR_SAVE (_BV(SM0) | _BV(SM1)) 423 | // SLEEP_MODE_STANDBY (_BV(SM1) | _BV(SM2)) 424 | // SLEEP_MODE_EXT_STANDBY (_BV(SM0) | _BV(SM1) | _BV(SM2)) 425 | 426 | set_sleep_mode( SLEEP_MODE_IDLE ); 427 | 428 | ATOMIC_BLOCK(ATOMIC_RESTORESTATE) 429 | { 430 | sleep_enable(); 431 | 432 | #if defined(BODS) && defined(BODSE) // Only if there is support to disable the brown-out detection. 433 | sleep_bod_disable(); 434 | #endif 435 | } 436 | sleep_cpu(); // good night. 437 | 438 | // Ugh. I've been woken up. Better disable sleep mode. 439 | sleep_disable(); 440 | } 441 | -------------------------------------------------------------------------------- /examples/_01-TaskSwitching/_01-TaskSwitching.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ExploreEmbedded/Arduino_FreeRTOS/14b0093782c1799cf3fcdd3b99ef975362887433/examples/_01-TaskSwitching/_01-TaskSwitching.JPG -------------------------------------------------------------------------------- /examples/_01-TaskSwitching/_01-TaskSwitching.ino: -------------------------------------------------------------------------------- 1 | /*************************************************************************************************** 2 | ExploreEmbedded Copyright Notice 3 | **************************************************************************************************** 4 | * File: 01-TaskSwitching 5 | * Version: 15.0 6 | * Author: ExploreEmbedded 7 | * Website: http://www.exploreembedded.com/wiki 8 | * Description: File contains the free rtos example to demonstarte the task switching. 9 | 10 | This code has been developed and tested on ExploreEmbedded boards. 11 | We strongly believe that the library works on any of development boards for respective controllers. 12 | Check this link http://www.exploreembedded.com/wiki for awesome tutorials on 8051,PIC,AVR,ARM,Robotics,RTOS,IOT. 13 | ExploreEmbedded invests substantial time and effort developing open source HW and SW tools, to support consider 14 | buying the ExploreEmbedded boards. 15 | 16 | The ExploreEmbedded libraries and examples are licensed under the terms of the new-bsd license(two-clause bsd license). 17 | See also: http://www.opensource.org/licenses/bsd-license.php 18 | 19 | EXPLOREEMBEDDED DISCLAIMS ANY KIND OF HARDWARE FAILURE RESULTING OUT OF USAGE OF LIBRARIES, DIRECTLY OR 20 | INDIRECTLY. FILES MAY BE SUBJECT TO CHANGE WITHOUT PRIOR NOTICE. THE REVISION HISTORY CONTAINS THE INFORMATION 21 | RELATED TO UPDATES. 22 | 23 | 24 | Permission to use, copy, modify, and distribute this software and its documentation for any purpose 25 | and without fee is hereby granted, provided that this copyright notices appear in all copies 26 | and that both those copyright notices and this permission notice appear in supporting documentation. 27 | **************************************************************************************************/ 28 | 29 | #include 30 | 31 | void setup() 32 | { 33 | 34 | Serial.begin(9600); 35 | Serial.println(F("In Setup function")); 36 | 37 | /* Create two tasks with priorities 1 and 2. An idle task is also created, 38 | which will be run when there are no tasks in RUN state */ 39 | 40 | xTaskCreate(MyTask1, "Task1", 100, NULL, 1, NULL); 41 | xTaskCreate(MyTask2, "Task2", 100, NULL, 2, NULL); 42 | xTaskCreate(MyIdleTask, "IdleTask", 100, NULL, 0, NULL); 43 | } 44 | 45 | 46 | void loop() 47 | { 48 | // DO nothing 49 | } 50 | 51 | 52 | /* Task1 with priority 1 */ 53 | static void MyTask1(void* pvParameters) 54 | { 55 | while(1) 56 | { 57 | Serial.println(F("Task1")); 58 | vTaskDelay(100/portTICK_PERIOD_MS); 59 | } 60 | } 61 | 62 | 63 | /* Task2 with priority 2 */ 64 | static void MyTask2(void* pvParameters) 65 | { 66 | while(1) 67 | { 68 | Serial.println(F("Task2")); 69 | vTaskDelay(150/portTICK_PERIOD_MS); 70 | } 71 | } 72 | 73 | 74 | /* Idle Task with priority Zero */ 75 | static void MyIdleTask(void* pvParameters) 76 | { 77 | while(1) 78 | { 79 | Serial.println(F("Idle state")); 80 | delay(50); 81 | } 82 | } 83 | 84 | -------------------------------------------------------------------------------- /examples/_02-TaskIdleHook/_02-TaskIdleHook.ino: -------------------------------------------------------------------------------- 1 | /*************************************************************************************************** 2 | ExploreEmbedded Copyright Notice 3 | **************************************************************************************************** 4 | * File: 02-TaskIdleHook 5 | * Version: 15.0 6 | * Author: ExploreEmbedded 7 | * Website: http://www.exploreembedded.com/wiki 8 | * Description: File contains the free rtos example to demonstarte the task switching along with task hook function. 9 | 10 | This code has been developed and tested on ExploreEmbedded boards. 11 | We strongly believe that the library works on any of development boards for respective controllers. 12 | Check this link http://www.exploreembedded.com/wiki for awesome tutorials on 8051,PIC,AVR,ARM,Robotics,RTOS,IOT. 13 | ExploreEmbedded invests substantial time and effort developing open source HW and SW tools, to support consider 14 | buying the ExploreEmbedded boards. 15 | 16 | The ExploreEmbedded libraries and examples are licensed under the terms of the new-bsd license(two-clause bsd license). 17 | See also: http://www.opensource.org/licenses/bsd-license.php 18 | 19 | EXPLOREEMBEDDED DISCLAIMS ANY KIND OF HARDWARE FAILURE RESULTING OUT OF USAGE OF LIBRARIES, DIRECTLY OR 20 | INDIRECTLY. FILES MAY BE SUBJECT TO CHANGE WITHOUT PRIOR NOTICE. THE REVISION HISTORY CONTAINS THE INFORMATION 21 | RELATED TO UPDATES. 22 | 23 | 24 | Permission to use, copy, modify, and distribute this software and its documentation for any purpose 25 | and without fee is hereby granted, provided that this copyright notices appear in all copies 26 | and that both those copyright notices and this permission notice appear in supporting documentation. 27 | **************************************************************************************************/ 28 | 29 | #include 30 | 31 | void setup() 32 | { 33 | 34 | Serial.begin(9600); 35 | Serial.println(F("In Setup function")); 36 | 37 | /* Create two tasks with priorities 1 and 2. 38 | * Enable the Idle Task Hook by setting configUSE_IDLE_HOOK to 1, by this the loop function can be used as Idle task*/ 39 | 40 | xTaskCreate(MyTask1, "Task1", 100, NULL, 1, NULL); 41 | xTaskCreate(MyTask2, "Task2", 100, NULL, 2, NULL); 42 | } 43 | 44 | 45 | void loop() 46 | { 47 | // Hooked to IDle task, it will run whenever CPU is idle 48 | Serial.println(F("Loop function")); 49 | delay(50); 50 | } 51 | 52 | 53 | /* Task1 with priority 1 */ 54 | static void MyTask1(void* pvParameters) 55 | { 56 | while(1) 57 | { 58 | Serial.println(F("Task1")); 59 | vTaskDelay(100/portTICK_PERIOD_MS); 60 | } 61 | } 62 | 63 | 64 | /* Task2 with priority 2 */ 65 | static void MyTask2(void* pvParameters) 66 | { 67 | while(1) 68 | { 69 | Serial.println(F("Task2")); 70 | vTaskDelay(150/portTICK_PERIOD_MS); 71 | } 72 | } 73 | 74 | 75 | -------------------------------------------------------------------------------- /examples/_02-TaskIdleHook/_02-TaskIdleHook.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ExploreEmbedded/Arduino_FreeRTOS/14b0093782c1799cf3fcdd3b99ef975362887433/examples/_02-TaskIdleHook/_02-TaskIdleHook.jpg -------------------------------------------------------------------------------- /examples/_03-TaskDeleteUsage/_03-TaskDeleteUsage.ino: -------------------------------------------------------------------------------- 1 | /*************************************************************************************************** 2 | ExploreEmbedded Copyright Notice 3 | **************************************************************************************************** 4 | * File: 03-TaskDeleteUsage 5 | * Version: 15.0 6 | * Author: ExploreEmbedded 7 | * Website: http://www.exploreembedded.com/wiki 8 | * Description: File contains the free rtos example to demonstarte the task delete. 9 | 10 | This code has been developed and tested on ExploreEmbedded boards. 11 | We strongly believe that the library works on any of development boards for respective controllers. 12 | Check this link http://www.exploreembedded.com/wiki for awesome tutorials on 8051,PIC,AVR,ARM,Robotics,RTOS,IOT. 13 | ExploreEmbedded invests substantial time and effort developing open source HW and SW tools, to support consider 14 | buying the ExploreEmbedded boards. 15 | 16 | The ExploreEmbedded libraries and examples are licensed under the terms of the new-bsd license(two-clause bsd license). 17 | See also: http://www.opensource.org/licenses/bsd-license.php 18 | 19 | EXPLOREEMBEDDED DISCLAIMS ANY KIND OF HARDWARE FAILURE RESULTING OUT OF USAGE OF LIBRARIES, DIRECTLY OR 20 | INDIRECTLY. FILES MAY BE SUBJECT TO CHANGE WITHOUT PRIOR NOTICE. THE REVISION HISTORY CONTAINS THE INFORMATION 21 | RELATED TO UPDATES. 22 | 23 | 24 | Permission to use, copy, modify, and distribute this software and its documentation for any purpose 25 | and without fee is hereby granted, provided that this copyright notices appear in all copies 26 | and that both those copyright notices and this permission notice appear in supporting documentation. 27 | **************************************************************************************************/ 28 | 29 | #include 30 | 31 | TaskHandle_t TaskHandle_1; 32 | TaskHandle_t TaskHandle_2; 33 | TaskHandle_t TaskHandle_3; 34 | 35 | void setup() 36 | { 37 | 38 | Serial.begin(9600); 39 | Serial.println(F("In Setup function")); 40 | 41 | /* Create three tasks with priorities 1,2 and 3. Capture the Task details to respective handlers */ 42 | xTaskCreate(MyTask1, "Task1", 100, NULL, 1, &TaskHandle_1); 43 | xTaskCreate(MyTask2, "Task2", 100, NULL, 2, &TaskHandle_2); 44 | xTaskCreate(MyTask3, "Task3", 100, NULL, 3, &TaskHandle_3); 45 | } 46 | 47 | 48 | void loop() 49 | { 50 | // Hooked to IDle task, it will run whenever CPU is idle 51 | Serial.println(F("Loop function")); 52 | delay(50); 53 | } 54 | 55 | 56 | /* Task1 with priority 1 */ 57 | static void MyTask1(void* pvParameters) 58 | { 59 | while(1) 60 | { 61 | Serial.println(F("Task1 Running")); 62 | vTaskDelay(100/portTICK_PERIOD_MS); 63 | 64 | Serial.println(F("Back in Task1 and About to delete itself")); 65 | vTaskDelete(TaskHandle_1); // Delete the task using the TaskHandle_1 66 | } 67 | } 68 | 69 | 70 | /* Task2 with priority 2 */ 71 | static void MyTask2(void* pvParameters) 72 | { 73 | while(1) 74 | { 75 | Serial.println(F("Task2 Running")); 76 | vTaskDelay(150/portTICK_PERIOD_MS); 77 | 78 | Serial.println(F("Back in Task2 and About to delete itself")); 79 | vTaskDelete(NULL); //Delete own task by passing NULL(TaskHandle_2 can also be used) 80 | } 81 | } 82 | 83 | 84 | /* Task3 with priority 3 */ 85 | static void MyTask3(void* pvParameters) 86 | { 87 | while(1) 88 | { 89 | Serial.println(F("Task3 Running")); 90 | vTaskDelay(150/portTICK_PERIOD_MS); 91 | 92 | Serial.println(F("Back in Task3 and About to delete itself")); 93 | vTaskDelete(TaskHandle_3); 94 | } 95 | } 96 | 97 | -------------------------------------------------------------------------------- /examples/_03-TaskDeleteUsage/_03-TaskDeleteUsage.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ExploreEmbedded/Arduino_FreeRTOS/14b0093782c1799cf3fcdd3b99ef975362887433/examples/_03-TaskDeleteUsage/_03-TaskDeleteUsage.jpg -------------------------------------------------------------------------------- /examples/_04-CreatingTaskFromOtherTask/_04-CreatingTaskFromOtherTask.ino: -------------------------------------------------------------------------------- 1 | /*************************************************************************************************** 2 | ExploreEmbedded Copyright Notice 3 | **************************************************************************************************** 4 | * File: 04-CreatingTaskFromOtherTask 5 | * Version: 15.0 6 | * Author: ExploreEmbedded 7 | * Website: http://www.exploreembedded.com/wiki 8 | * Description: File contains the free rtos example to demonstarte creating tasks from other tasks. 9 | 10 | This code has been developed and tested on ExploreEmbedded boards. 11 | We strongly believe that the library works on any of development boards for respective controllers. 12 | Check this link http://www.exploreembedded.com/wiki for awesome tutorials on 8051,PIC,AVR,ARM,Robotics,RTOS,IOT. 13 | ExploreEmbedded invests substantial time and effort developing open source HW and SW tools, to support consider 14 | buying the ExploreEmbedded boards. 15 | 16 | The ExploreEmbedded libraries and examples are licensed under the terms of the new-bsd license(two-clause bsd license). 17 | See also: http://www.opensource.org/licenses/bsd-license.php 18 | 19 | EXPLOREEMBEDDED DISCLAIMS ANY KIND OF HARDWARE FAILURE RESULTING OUT OF USAGE OF LIBRARIES, DIRECTLY OR 20 | INDIRECTLY. FILES MAY BE SUBJECT TO CHANGE WITHOUT PRIOR NOTICE. THE REVISION HISTORY CONTAINS THE INFORMATION 21 | RELATED TO UPDATES. 22 | 23 | 24 | Permission to use, copy, modify, and distribute this software and its documentation for any purpose 25 | and without fee is hereby granted, provided that this copyright notices appear in all copies 26 | and that both those copyright notices and this permission notice appear in supporting documentation. 27 | **************************************************************************************************/ 28 | 29 | #include 30 | 31 | TaskHandle_t TaskHandle_1; 32 | TaskHandle_t TaskHandle_2; 33 | TaskHandle_t TaskHandle_3; 34 | TaskHandle_t TaskHandle_4; 35 | 36 | void setup() 37 | { 38 | 39 | Serial.begin(9600); 40 | Serial.println(F("In Setup function")); 41 | 42 | /* Create two tasks with priorities 1 and 3. Capture the Task details to respective handlers */ 43 | xTaskCreate(MyTask1, "Task1", 100, NULL, 1, &TaskHandle_1); 44 | xTaskCreate(MyTask3, "Task3", 120, NULL, 3, &TaskHandle_3); 45 | 46 | } 47 | 48 | 49 | void loop() 50 | { 51 | // Hooked to IDle task, it will run whenever CPU is idle 52 | Serial.println(F("Loop function")); 53 | delay(50); 54 | } 55 | 56 | 57 | /* Task1 with priority 1 */ 58 | static void MyTask1(void* pvParameters) 59 | { 60 | while(1) 61 | { 62 | Serial.println(F("Task1 Running and About to delete itself")); 63 | vTaskDelete(TaskHandle_1); // Delete the task using the TaskHandle_1 64 | } 65 | } 66 | 67 | 68 | /* Task2 with priority 2 */ 69 | static void MyTask2(void* pvParameters) 70 | { 71 | while(1) 72 | { 73 | Serial.println(F("Task2 Running and About to delete itsel")); 74 | vTaskDelete(NULL); //Delete own task by passing NULL(TaskHandle_2 can also be used) 75 | } 76 | } 77 | 78 | 79 | /* Task3 with priority 3 */ 80 | static void MyTask3(void* pvParameters) 81 | { 82 | while(1) 83 | { 84 | Serial.println(F("Task3 Running, Creating Task2 and Task4")); 85 | xTaskCreate(MyTask2, "Task2", 50, NULL, 2, &TaskHandle_2); 86 | xTaskCreate(MyTask4, "Task4", 100, NULL, 4, &TaskHandle_4); 87 | 88 | Serial.println(F("Back in Task3 and About to delete itself")); 89 | vTaskDelete(TaskHandle_3); 90 | } 91 | } 92 | 93 | 94 | /* Task4 with priority 4 */ 95 | static void MyTask4(void* pvParameters) 96 | { 97 | while(1) 98 | { 99 | Serial.println(F("Task4 Running and About to delete itself")); 100 | vTaskDelete(NULL); //Delete own task by passing NULL(TaskHandle_2 can also be used) 101 | } 102 | } -------------------------------------------------------------------------------- /examples/_04-CreatingTaskFromOtherTask/_04-CreatingTaskFromOtherTask.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ExploreEmbedded/Arduino_FreeRTOS/14b0093782c1799cf3fcdd3b99ef975362887433/examples/_04-CreatingTaskFromOtherTask/_04-CreatingTaskFromOtherTask.png -------------------------------------------------------------------------------- /examples/_05-TaskPriorityChange/_05-TaskPriorityChange.ino: -------------------------------------------------------------------------------- 1 | /*************************************************************************************************** 2 | ExploreEmbedded Copyright Notice 3 | **************************************************************************************************** 4 | * File: 05-TaskPriorityChange 5 | * Version: 15.0 6 | * Author: ExploreEmbedded 7 | * Website: http://www.exploreembedded.com/wiki 8 | * Description: File contains the free rtos example to demonstarte task priority change. 9 | 10 | This code has been developed and tested on ExploreEmbedded boards. 11 | We strongly believe that the library works on any of development boards for respective controllers. 12 | Check this link http://www.exploreembedded.com/wiki for awesome tutorials on 8051,PIC,AVR,ARM,Robotics,RTOS,IOT. 13 | ExploreEmbedded invests substantial time and effort developing open source HW and SW tools, to support consider 14 | buying the ExploreEmbedded boards. 15 | 16 | The ExploreEmbedded libraries and examples are licensed under the terms of the new-bsd license(two-clause bsd license). 17 | See also: http://www.opensource.org/licenses/bsd-license.php 18 | 19 | EXPLOREEMBEDDED DISCLAIMS ANY KIND OF HARDWARE FAILURE RESULTING OUT OF USAGE OF LIBRARIES, DIRECTLY OR 20 | INDIRECTLY. FILES MAY BE SUBJECT TO CHANGE WITHOUT PRIOR NOTICE. THE REVISION HISTORY CONTAINS THE INFORMATION 21 | RELATED TO UPDATES. 22 | 23 | 24 | Permission to use, copy, modify, and distribute this software and its documentation for any purpose 25 | and without fee is hereby granted, provided that this copyright notices appear in all copies 26 | and that both those copyright notices and this permission notice appear in supporting documentation. 27 | **************************************************************************************************/ 28 | 29 | #include 30 | 31 | TaskHandle_t TaskHandle_1; 32 | TaskHandle_t TaskHandle_2; 33 | TaskHandle_t TaskHandle_4; 34 | 35 | void setup() 36 | { 37 | Serial.begin(9600); 38 | Serial.println(F("In Setup function")); 39 | 40 | /* Create three tasks with priorities 1,2 and 3. Capture the Task details to respective handlers */ 41 | xTaskCreate(MyTask1, "Task1", 120, NULL, 1, &TaskHandle_1); 42 | } 43 | 44 | 45 | void loop() 46 | { 47 | // put your main code here, to run repeatedly: 48 | Serial.println(F("Loop function")); 49 | delay(50); 50 | } 51 | 52 | 53 | /* Task1 with priority 1 */ 54 | static void MyTask1(void* pvParameters) 55 | { 56 | while(1) 57 | { 58 | Serial.print(F("Task1 with Priority:")); 59 | Serial.print(uxTaskPriorityGet(TaskHandle_1)); 60 | Serial.println(F(" Creating Task2")); 61 | 62 | xTaskCreate(MyTask2, "Task2", 100, NULL, 3, &TaskHandle_2); 63 | 64 | Serial.print(F("Task1 with Priority:")); 65 | Serial.print(uxTaskPriorityGet(TaskHandle_1)); 66 | Serial.println(F(" Deleting All")); 67 | vTaskDelete(TaskHandle_2); // Delete task2 and task4 using their handles 68 | vTaskDelete(TaskHandle_4); 69 | vTaskDelete(TaskHandle_1); // Delete the task using the TaskHandle_1 70 | } 71 | } 72 | 73 | 74 | /* Task2 with priority 2 */ 75 | static void MyTask2(void* pvParameters) 76 | { 77 | while(1) 78 | { 79 | Serial.println(F("Task2 Running, Creating Task4")); 80 | xTaskCreate(MyTask4, "Task4", 100, NULL, 4, &TaskHandle_4); 81 | 82 | Serial.println(F("Back in Task2, Deleting itself")); 83 | vTaskDelete(NULL); //Delete own task by passing NULL(TaskHandle_2 can also be used) 84 | } 85 | } 86 | 87 | 88 | 89 | /* Task4 with priority 4 */ 90 | static void MyTask4(void* pvParameters) 91 | { 92 | Serial.println(F("Task4 Running, Changing Priority of Task1 from 1-3")); 93 | vTaskPrioritySet(TaskHandle_1,3); //Change the priority of task1 to 3 which is greater than task2 94 | 95 | while(1) 96 | { 97 | Serial.println(F("Back in Task4 ")); 98 | vTaskDelay(100/portTICK_PERIOD_MS); 99 | } 100 | } -------------------------------------------------------------------------------- /examples/_05-TaskPriorityChange/_05-TaskPriorityChange.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ExploreEmbedded/Arduino_FreeRTOS/14b0093782c1799cf3fcdd3b99ef975362887433/examples/_05-TaskPriorityChange/_05-TaskPriorityChange.png -------------------------------------------------------------------------------- /examples/_06-TaskPriorityChange/_06-TaskPriorityChange.ino: -------------------------------------------------------------------------------- 1 | /*************************************************************************************************** 2 | ExploreEmbedded Copyright Notice 3 | **************************************************************************************************** 4 | * File: 06-TaskPriorityChange 5 | * Version: 15.0 6 | * Author: ExploreEmbedded 7 | * Website: http://www.exploreembedded.com/wiki 8 | * Description: File contains the free rtos example to demonstarte task priority change. 9 | 10 | This code has been developed and tested on ExploreEmbedded boards. 11 | We strongly believe that the library works on any of development boards for respective controllers. 12 | Check this link http://www.exploreembedded.com/wiki for awesome tutorials on 8051,PIC,AVR,ARM,Robotics,RTOS,IOT. 13 | ExploreEmbedded invests substantial time and effort developing open source HW and SW tools, to support consider 14 | buying the ExploreEmbedded boards. 15 | 16 | The ExploreEmbedded libraries and examples are licensed under the terms of the new-bsd license(two-clause bsd license). 17 | See also: http://www.opensource.org/licenses/bsd-license.php 18 | 19 | EXPLOREEMBEDDED DISCLAIMS ANY KIND OF HARDWARE FAILURE RESULTING OUT OF USAGE OF LIBRARIES, DIRECTLY OR 20 | INDIRECTLY. FILES MAY BE SUBJECT TO CHANGE WITHOUT PRIOR NOTICE. THE REVISION HISTORY CONTAINS THE INFORMATION 21 | RELATED TO UPDATES. 22 | 23 | 24 | Permission to use, copy, modify, and distribute this software and its documentation for any purpose 25 | and without fee is hereby granted, provided that this copyright notices appear in all copies 26 | and that both those copyright notices and this permission notice appear in supporting documentation. 27 | **************************************************************************************************/ 28 | 29 | #include 30 | 31 | TaskHandle_t TaskHandle_1; 32 | TaskHandle_t TaskHandle_2; 33 | TaskHandle_t TaskHandle_4; 34 | 35 | void setup() 36 | { 37 | 38 | Serial.begin(9600); 39 | Serial.println(F("In Setup function")); 40 | 41 | /* Create three tasks with priorities 1,2 and 3. Capture the Task details to respective handlers */ 42 | xTaskCreate(MyTask1, "Task1", 120, NULL, 1, &TaskHandle_1); 43 | 44 | } 45 | 46 | 47 | void loop() 48 | { 49 | // Hooked to IDle task, it will run whenever CPU is idle 50 | Serial.println(F("Loop function")); 51 | delay(50); 52 | } 53 | 54 | 55 | /* Task1 with priority 1 */ 56 | static void MyTask1(void* pvParameters) 57 | { 58 | while(1) 59 | { 60 | Serial.println(F("Task1 with Priority:")); 61 | Serial.print(uxTaskPriorityGet(TaskHandle_1)); 62 | Serial.print(F("Creating Task2")); 63 | 64 | xTaskCreate(MyTask2, "Task2", 100, NULL, 3, &TaskHandle_2); 65 | 66 | Serial.println(F("Task1 with Priority:")); 67 | Serial.print(uxTaskPriorityGet(TaskHandle_1)); 68 | Serial.print(F(" Deleting All")); 69 | vTaskDelete(TaskHandle_2); // Delete task2 and task4 using their handles 70 | vTaskDelete(TaskHandle_4); 71 | vTaskDelete(TaskHandle_1); // Delete the task using the TaskHandle_1 72 | } 73 | } 74 | 75 | 76 | /* Task2 with priority 2 */ 77 | static void MyTask2(void* pvParameters) 78 | { 79 | while(1) 80 | { 81 | Serial.println(F("Task2 Running, Creating Task4")); 82 | xTaskCreate(MyTask4, "Task4", 100, NULL, 4, &TaskHandle_4); 83 | 84 | Serial.println(F("Back in Task2, Deleting itself")); 85 | vTaskDelete(NULL); //Delete own task by passing NULL(TaskHandle_2 can also be used) 86 | } 87 | } 88 | 89 | 90 | 91 | /* Task4 with priority 4 */ 92 | static void MyTask4(void* pvParameters) 93 | { 94 | Serial.println(F("Task4 Running, Changing Priority of Task1 from 1-3")); 95 | vTaskPrioritySet(TaskHandle_1,5); //Change the priority of task1 to 5 which is hisghest 96 | 97 | while(1) 98 | { 99 | Serial.println(F("Back in Task4 ")); 100 | vTaskDelay(100/portTICK_PERIOD_MS); 101 | } 102 | } -------------------------------------------------------------------------------- /examples/_06-TaskPriorityChange/_06-TaskPriorityChange.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ExploreEmbedded/Arduino_FreeRTOS/14b0093782c1799cf3fcdd3b99ef975362887433/examples/_06-TaskPriorityChange/_06-TaskPriorityChange.png -------------------------------------------------------------------------------- /examples/_07-TaskSuspendAndResume/_07-TaskSuspendAndResume.ino: -------------------------------------------------------------------------------- 1 | /*************************************************************************************************** 2 | ExploreEmbedded Copyright Notice 3 | **************************************************************************************************** 4 | * File: 07-TaskSuspendAndResume 5 | * Version: 15.0 6 | * Author: ExploreEmbedded 7 | * Website: http://www.exploreembedded.com/wiki 8 | * Description: File contains the free rtos example to demonstarte task Suspend and Resume. 9 | 10 | This code has been developed and tested on ExploreEmbedded boards. 11 | We strongly believe that the library works on any of development boards for respective controllers. 12 | Check this link http://www.exploreembedded.com/wiki for awesome tutorials on 8051,PIC,AVR,ARM,Robotics,RTOS,IOT. 13 | ExploreEmbedded invests substantial time and effort developing open source HW and SW tools, to support consider 14 | buying the ExploreEmbedded boards. 15 | 16 | The ExploreEmbedded libraries and examples are licensed under the terms of the new-bsd license(two-clause bsd license). 17 | See also: http://www.opensource.org/licenses/bsd-license.php 18 | 19 | EXPLOREEMBEDDED DISCLAIMS ANY KIND OF HARDWARE FAILURE RESULTING OUT OF USAGE OF LIBRARIES, DIRECTLY OR 20 | INDIRECTLY. FILES MAY BE SUBJECT TO CHANGE WITHOUT PRIOR NOTICE. THE REVISION HISTORY CONTAINS THE INFORMATION 21 | RELATED TO UPDATES. 22 | 23 | 24 | Permission to use, copy, modify, and distribute this software and its documentation for any purpose 25 | and without fee is hereby granted, provided that this copyright notices appear in all copies 26 | and that both those copyright notices and this permission notice appear in supporting documentation. 27 | **************************************************************************************************/ 28 | 29 | #include 30 | 31 | TaskHandle_t TaskHandle_1; 32 | TaskHandle_t TaskHandle_2; 33 | TaskHandle_t TaskHandle_3; 34 | TaskHandle_t TaskHandle_4; 35 | 36 | void setup() 37 | { 38 | Serial.begin(9600); 39 | Serial.println(F("In Setup function")); 40 | 41 | /* Create 4-tasks with priorities 1-4. Capture the Task details to respective handlers */ 42 | xTaskCreate(MyTask1, "Task1", 100, NULL, 1, &TaskHandle_1); 43 | xTaskCreate(MyTask2, "Task2", 100, NULL, 2, &TaskHandle_2); 44 | xTaskCreate(MyTask3, "Task3", 100, NULL, 3, &TaskHandle_3); 45 | xTaskCreate(MyTask4, "Task4", 100, NULL, 4, &TaskHandle_4); 46 | } 47 | 48 | 49 | void loop() 50 | { // Hooked to Idle Task, will run when CPU is Idle 51 | Serial.println(F("Loop function")); 52 | delay(50); 53 | } 54 | 55 | 56 | /* Task1 with priority 1 */ 57 | static void MyTask1(void* pvParameters) 58 | { 59 | Serial.println(F("Task1 Resuming Task2")); 60 | vTaskResume(TaskHandle_2); 61 | 62 | Serial.println(F("Task1 Resuming Task3")); 63 | vTaskResume(TaskHandle_3); 64 | 65 | Serial.println(F("Task1 Resuming Task4")); 66 | vTaskResume(TaskHandle_4); 67 | 68 | Serial.println(F("Task1 Deleting Itself")); 69 | vTaskDelete(TaskHandle_1); 70 | } 71 | 72 | 73 | /* Task2 with priority 2 */ 74 | static void MyTask2(void* pvParameters) 75 | { 76 | Serial.println(F("Task2, Deleting itself")); 77 | vTaskDelete(NULL); //Delete own task by passing NULL(TaskHandle_2 can also be used) 78 | } 79 | 80 | 81 | /* Task3 with priority 3 */ 82 | static void MyTask3(void* pvParameters) 83 | { 84 | Serial.println(F("Task3, Deleting Itself")); 85 | vTaskDelete(NULL); //Delete own task by passing NULL(TaskHandle_3 can also be used) 86 | } 87 | 88 | 89 | /* Task4 with priority 4 */ 90 | static void MyTask4(void* pvParameters) 91 | { 92 | Serial.println(F("Task4 Running, Suspending all tasks")); 93 | vTaskSuspend(TaskHandle_2); //Suspend Task2/3 94 | vTaskSuspend(TaskHandle_3); 95 | vTaskSuspend(NULL); //Suspend Own Task 96 | 97 | Serial.println(F("Back in Task4, Deleting Itself")); 98 | vTaskDelete(TaskHandle_4); 99 | } -------------------------------------------------------------------------------- /examples/_07-TaskSuspendAndResume/_07-TaskSuspendAndResume.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ExploreEmbedded/Arduino_FreeRTOS/14b0093782c1799cf3fcdd3b99ef975362887433/examples/_07-TaskSuspendAndResume/_07-TaskSuspendAndResume.png -------------------------------------------------------------------------------- /examples/_08-TaskSuspendAndResume/_08-TaskSuspendAndResume.ino: -------------------------------------------------------------------------------- 1 | /*************************************************************************************************** 2 | ExploreEmbedded Copyright Notice 3 | **************************************************************************************************** 4 | * File: 08-TaskSuspendAndResume 5 | * Version: 15.0 6 | * Author: ExploreEmbedded 7 | * Website: http://www.exploreembedded.com/wiki 8 | * Description: File contains the free rtos example to demonstarte task Suspend and Resume. 9 | 10 | This code has been developed and tested on ExploreEmbedded boards. 11 | We strongly believe that the library works on any of development boards for respective controllers. 12 | Check this link http://www.exploreembedded.com/wiki for awesome tutorials on 8051,PIC,AVR,ARM,Robotics,RTOS,IOT. 13 | ExploreEmbedded invests substantial time and effort developing open source HW and SW tools, to support consider 14 | buying the ExploreEmbedded boards. 15 | 16 | The ExploreEmbedded libraries and examples are licensed under the terms of the new-bsd license(two-clause bsd license). 17 | See also: http://www.opensource.org/licenses/bsd-license.php 18 | 19 | EXPLOREEMBEDDED DISCLAIMS ANY KIND OF HARDWARE FAILURE RESULTING OUT OF USAGE OF LIBRARIES, DIRECTLY OR 20 | INDIRECTLY. FILES MAY BE SUBJECT TO CHANGE WITHOUT PRIOR NOTICE. THE REVISION HISTORY CONTAINS THE INFORMATION 21 | RELATED TO UPDATES. 22 | 23 | 24 | Permission to use, copy, modify, and distribute this software and its documentation for any purpose 25 | and without fee is hereby granted, provided that this copyright notices appear in all copies 26 | and that both those copyright notices and this permission notice appear in supporting documentation. 27 | **************************************************************************************************/ 28 | 29 | #include 30 | 31 | TaskHandle_t TaskHandle_1; 32 | TaskHandle_t TaskHandle_2; 33 | TaskHandle_t TaskHandle_3; 34 | TaskHandle_t TaskHandle_4; 35 | 36 | void setup() 37 | { 38 | Serial.begin(9600); 39 | Serial.println(F("In Setup function")); 40 | 41 | /* Create 4-tasks with priorities 1-4. Capture the Task details to respective handlers */ 42 | xTaskCreate(MyTask1, "Task1", 100, NULL, 1, &TaskHandle_1); 43 | xTaskCreate(MyTask2, "Task2", 100, NULL, 2, &TaskHandle_2); 44 | xTaskCreate(MyTask3, "Task3", 100, NULL, 3, &TaskHandle_3); 45 | xTaskCreate(MyTask4, "Task4", 100, NULL, 4, &TaskHandle_4); 46 | } 47 | 48 | 49 | void loop() 50 | { // Hooked to Idle Task, will run when CPU is Idle 51 | Serial.println(F("Loop function")); 52 | delay(50); 53 | } 54 | 55 | 56 | /* Task1 with priority 1 */ 57 | static void MyTask1(void* pvParameters) 58 | { 59 | Serial.println("Task1 Changing its priority to 5"); 60 | vTaskPrioritySet(TaskHandle_1,5); //Now task1 is of highest priority 61 | 62 | Serial.println("Task1 Resuming Task2"); 63 | vTaskResume(TaskHandle_2); 64 | 65 | Serial.println("Task1 Resuming Task3"); 66 | vTaskResume(TaskHandle_3); 67 | 68 | Serial.println("Task1 Resuming Task4"); 69 | vTaskResume(TaskHandle_4); 70 | 71 | Serial.println("Task1 Deleting Itself"); 72 | vTaskDelete(TaskHandle_1); 73 | } 74 | 75 | 76 | /* Task2 with priority 2 */ 77 | static void MyTask2(void* pvParameters) 78 | { 79 | Serial.println(F("Task2, Deleting itself")); 80 | vTaskDelete(NULL); //Delete own task by passing NULL(TaskHandle_2 can also be used) 81 | } 82 | 83 | 84 | /* Task3 with priority 3 */ 85 | static void MyTask3(void* pvParameters) 86 | { 87 | Serial.println(F("Task3, Deleting Itself")); 88 | vTaskDelete(NULL); //Delete own task by passing NULL(TaskHandle_3 can also be used) 89 | } 90 | 91 | 92 | /* Task4 with priority 4 */ 93 | static void MyTask4(void* pvParameters) 94 | { 95 | Serial.println(F("Task4 Running, Suspending all tasks")); 96 | vTaskSuspend(TaskHandle_2); //Suspend Task2/3 97 | vTaskSuspend(TaskHandle_3); 98 | vTaskSuspend(NULL); //Suspend Own Task 99 | 100 | Serial.println(F("Back in Task4, Deleting Itself")); 101 | vTaskDelete(TaskHandle_4); 102 | } -------------------------------------------------------------------------------- /examples/_08-TaskSuspendAndResume/_08-TaskSuspendAndResume.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ExploreEmbedded/Arduino_FreeRTOS/14b0093782c1799cf3fcdd3b99ef975362887433/examples/_08-TaskSuspendAndResume/_08-TaskSuspendAndResume.png -------------------------------------------------------------------------------- /examples/_09-ResumingTaskFromISR/_09-ResumingTaskFromISR.ino: -------------------------------------------------------------------------------- 1 | /*************************************************************************************************** 2 | ExploreEmbedded Copyright Notice 3 | **************************************************************************************************** 4 | * File: 09-ResumingTaskFromISR 5 | * Version: 15.0 6 | * Author: ExploreEmbedded 7 | * Website: http://www.exploreembedded.com/wiki 8 | * Description: File contains the free rtos example to demonstarte task Suspend and Resume. 9 | 10 | This code has been developed and tested on ExploreEmbedded boards. 11 | We strongly believe that the library works on any of development boards for respective controllers. 12 | Check this link http://www.exploreembedded.com/wiki for awesome tutorials on 8051,PIC,AVR,ARM,Robotics,RTOS,IOT. 13 | ExploreEmbedded invests substantial time and effort developing open source HW and SW tools, to support consider 14 | buying the ExploreEmbedded boards. 15 | 16 | The ExploreEmbedded libraries and examples are licensed under the terms of the new-bsd license(two-clause bsd license). 17 | See also: http://www.opensource.org/licenses/bsd-license.php 18 | 19 | EXPLOREEMBEDDED DISCLAIMS ANY KIND OF HARDWARE FAILURE RESULTING OUT OF USAGE OF LIBRARIES, DIRECTLY OR 20 | INDIRECTLY. FILES MAY BE SUBJECT TO CHANGE WITHOUT PRIOR NOTICE. THE REVISION HISTORY CONTAINS THE INFORMATION 21 | RELATED TO UPDATES. 22 | 23 | 24 | Permission to use, copy, modify, and distribute this software and its documentation for any purpose 25 | and without fee is hereby granted, provided that this copyright notices appear in all copies 26 | and that both those copyright notices and this permission notice appear in supporting documentation. 27 | **************************************************************************************************/ 28 | #include 29 | 30 | TaskHandle_t TaskHandle_2; 31 | TaskHandle_t TaskHandle_3; 32 | TaskHandle_t TaskHandle_4; 33 | 34 | void setup() 35 | { 36 | Serial.begin(9600); 37 | Serial.println(F("In Setup function")); 38 | 39 | /* Use INT0(pin2) falling edge interrupt for resuming tasks */ 40 | attachInterrupt(digitalPinToInterrupt(2), ExternalInterrupt, FALLING); 41 | 42 | /* Create 3-tasks with priorities 2-4. Capture the Task details to respective handlers */ 43 | xTaskCreate(MyTask2, "Task2", 100, NULL, 2, &TaskHandle_2); 44 | xTaskCreate(MyTask3, "Task3", 100, NULL, 3, &TaskHandle_3); 45 | xTaskCreate(MyTask4, "Task4", 100, NULL, 4, &TaskHandle_4); 46 | } 47 | 48 | 49 | void loop() 50 | { 51 | // Hooked to IDle task, it will run whenever CPU is idle 52 | Serial.println(F("Loop function")); 53 | delay(1000); 54 | } 55 | 56 | 57 | /* 58 | * Tasks are resumed every time a Falling edge interrupt is detected on PIN2. 59 | * One task is resumed at a time, a counter is used to resume 3taks and after which no tasks are resumed. 60 | * xTaskResumeFromISR() returns True if Context switch is required and accordingly we need to call portYIELD_FROM_ISR/taskYield(AVR). 61 | * Serial data is printed in ISR only for demonstarting the control flow. This should not be done as it takes long time to send data on Serial port. 62 | * Tasking to much ISR time will starve the other tasks or User application. 63 | * 64 | */ 65 | static void ExternalInterrupt() 66 | { 67 | static int count=0; 68 | BaseType_t taskYieldRequired = 0; 69 | 70 | if(count<=3) 71 | { 72 | count++; 73 | } 74 | 75 | switch(count) // Resume one task at a time depending on count value 76 | { 77 | case 1: 78 | Serial.println(F("ISR Resuming Task2")); 79 | taskYieldRequired = xTaskResumeFromISR(TaskHandle_2); 80 | Serial.println(F("Leaving ISR")); 81 | break; 82 | 83 | case 2: 84 | Serial.println(F("ISR Resuming Task3")); 85 | taskYieldRequired = xTaskResumeFromISR(TaskHandle_3); 86 | Serial.println(F("Leaving ISR")); 87 | break; 88 | 89 | case 3: 90 | Serial.println(F("ISR Resuming Task4")); 91 | taskYieldRequired = xTaskResumeFromISR(TaskHandle_4); 92 | Serial.println(F("Leaving ISR")); 93 | break; 94 | 95 | default: 96 | //DO nothing 97 | break; 98 | } 99 | 100 | if(taskYieldRequired == 1) // If the taskYield is reuiqred then trigger the same. 101 | { 102 | taskYIELD(); 103 | } 104 | } 105 | 106 | 107 | 108 | /* Task2 with priority 2 */ 109 | static void MyTask2(void* pvParameters) 110 | { 111 | Serial.println(F("Task2, Deleting itself")); 112 | vTaskDelete(NULL); //Delete own task by passing NULL(TaskHandle_2 can also be used) 113 | } 114 | 115 | 116 | /* Task3 with priority 3 */ 117 | static void MyTask3(void* pvParameters) 118 | { 119 | Serial.println(F("Task3, Deleting Itself")); 120 | vTaskDelete(NULL); //Delete own task by passing NULL(TaskHandle_3 can also be used) 121 | } 122 | 123 | 124 | /* Task4 with priority 4 */ 125 | static void MyTask4(void* pvParameters) 126 | { 127 | Serial.println(F("Task4 Running, Suspending all tasks")); 128 | vTaskSuspend(TaskHandle_2); //Suspend Task2/3 129 | vTaskSuspend(TaskHandle_3); 130 | vTaskSuspend(NULL); //Suspend Own Task 131 | 132 | Serial.println(F("Back in Task4, Deleting Itself")); 133 | vTaskDelete(TaskHandle_4); 134 | } -------------------------------------------------------------------------------- /examples/_09-ResumingTaskFromISR/_09-ResumingTaskFromISR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ExploreEmbedded/Arduino_FreeRTOS/14b0093782c1799cf3fcdd3b99ef975362887433/examples/_09-ResumingTaskFromISR/_09-ResumingTaskFromISR.png -------------------------------------------------------------------------------- /examples/_10-ReadingTaskInfo/10-ReadingTaskInfo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ExploreEmbedded/Arduino_FreeRTOS/14b0093782c1799cf3fcdd3b99ef975362887433/examples/_10-ReadingTaskInfo/10-ReadingTaskInfo.png -------------------------------------------------------------------------------- /examples/_10-ReadingTaskInfo/_10-ReadingTaskInfo.ino: -------------------------------------------------------------------------------- 1 | /*************************************************************************************************** 2 | ExploreEmbedded Copyright Notice 3 | **************************************************************************************************** 4 | * File: 10-ReadTaskInfo 5 | * Version: 15.0 6 | * Author: ExploreEmbedded 7 | * Website: http://www.exploreembedded.com/wiki 8 | * Description: File contains the free rtos example to demonstarte task Suspend and Resume. 9 | 10 | This code has been developed and tested on ExploreEmbedded boards. 11 | We strongly believe that the library works on any of development boards for respective controllers. 12 | Check this link http://www.exploreembedded.com/wiki for awesome tutorials on 8051,PIC,AVR,ARM,Robotics,RTOS,IOT. 13 | ExploreEmbedded invests substantial time and effort developing open source HW and SW tools, to support consider 14 | buying the ExploreEmbedded boards. 15 | 16 | The ExploreEmbedded libraries and examples are licensed under the terms of the new-bsd license(two-clause bsd license). 17 | See also: http://www.opensource.org/licenses/bsd-license.php 18 | 19 | EXPLOREEMBEDDED DISCLAIMS ANY KIND OF HARDWARE FAILURE RESULTING OUT OF USAGE OF LIBRARIES, DIRECTLY OR 20 | INDIRECTLY. FILES MAY BE SUBJECT TO CHANGE WITHOUT PRIOR NOTICE. THE REVISION HISTORY CONTAINS THE INFORMATION 21 | RELATED TO UPDATES. 22 | 23 | 24 | Permission to use, copy, modify, and distribute this software and its documentation for any purpose 25 | and without fee is hereby granted, provided that this copyright notices appear in all copies 26 | and that both those copyright notices and this permission notice appear in supporting documentation. 27 | **************************************************************************************************/ 28 | #include 29 | 30 | TaskHandle_t TaskHandle_1; 31 | TaskHandle_t TaskHandle_2; 32 | TaskHandle_t TaskHandle_3; 33 | 34 | char ptrTaskList[250]; 35 | 36 | void setup() 37 | { 38 | Serial.begin(9600); 39 | Serial.println(F("In Setup function")); 40 | 41 | /* Use INT0(pin2) falling edge interrupt for resuming tasks */ 42 | attachInterrupt(digitalPinToInterrupt(2), ExternalInterrupt, FALLING); 43 | 44 | /* Create a task with priority 3. Capture the Task details to its handler*/ 45 | xTaskCreate(MyTask1, "Task1", 120, NULL, 1, &TaskHandle_1); 46 | xTaskCreate(MyTask2, "Task2", 120, NULL, 2, &TaskHandle_2); 47 | xTaskCreate(MyTask3, "Task3", 120, NULL, 3, &TaskHandle_3); 48 | } 49 | 50 | 51 | void loop() 52 | { 53 | // Hooked to IDle task, it will run whenever CPU is idle 54 | Serial.println(F("Loop function")); 55 | delay(1000); 56 | } 57 | 58 | 59 | /* 60 | * Task info(state, Priority, Stack available) is read immediately the switch is pressed and sent on Serial Port 61 | * Serial data is printed in ISR for demonstarting the control flow. This should not be done as it takes long time to send data on Serial port. 62 | * Taking to much ISR time will starve the other tasks or User application. * 63 | */ 64 | static void ExternalInterrupt() 65 | { 66 | vTaskList(ptrTaskList); 67 | Serial.println(F("**********************************")); 68 | Serial.println(F("Task State Prio Stack Num")); 69 | Serial.println(F("**********************************")); 70 | Serial.print(ptrTaskList); 71 | Serial.println(F("**********************************")); 72 | } 73 | 74 | 75 | 76 | /* Task1 with priority 1 */ 77 | static void MyTask1(void* pvParameters) 78 | { 79 | while(1) 80 | { 81 | Serial.println(F("Task1 Running")); 82 | delay(200); 83 | vTaskDelay(250/portTICK_PERIOD_MS); 84 | } 85 | } 86 | 87 | 88 | /* Task2 with priority 2 */ 89 | static void MyTask2(void* pvParameters) 90 | { 91 | while(1) 92 | { 93 | Serial.println(F("Task2 Running")); 94 | delay(200); 95 | vTaskDelay(300/portTICK_PERIOD_MS); 96 | } 97 | } 98 | 99 | 100 | /* Task3 with priority 3 */ 101 | static void MyTask3(void* pvParameters) 102 | { 103 | char suspendFlag=0; 104 | while(1) 105 | { 106 | Serial.println(F("Task3 Running")); 107 | 108 | if(suspendFlag==1) //Task1 is suspended and resumed alternatively whenever Task3 runs. 109 | { 110 | vTaskSuspend(TaskHandle_1); 111 | suspendFlag = 0; 112 | } 113 | else 114 | { 115 | vTaskResume(TaskHandle_1); 116 | suspendFlag = 1; 117 | } 118 | delay(200); 119 | vTaskDelay(400/portTICK_PERIOD_MS); 120 | } 121 | } -------------------------------------------------------------------------------- /examples/_11-BinarySemaphore/_11-BinarySemaphore.ino: -------------------------------------------------------------------------------- 1 | /*************************************************************************************************** 2 | ExploreEmbedded Copyright Notice 3 | **************************************************************************************************** 4 | * File: main.c 5 | * Version: 16.0 6 | * Author: ExploreEmbedded 7 | * Website: http://www.exploreembedded.com/wiki 8 | * Description: Program to demonstrate the Binary semaphore usage and priority inversion 9 | 10 | This code has been developed and tested on ExploreEmbedded boards. 11 | We strongly believe that the library works on any of development boards for respective controllers. 12 | Check this link http://www.exploreembedded.com/wiki for awesome tutorials on 8051,PIC,AVR,ARM,Robotics,RTOS,IOT. 13 | ExploreEmbedded invests substantial time and effort developing open source HW and SW tools, to support consider 14 | buying the ExploreEmbedded boards. 15 | 16 | The ExploreEmbedded libraries and examples are licensed under the terms of the new-bsd license(two-clause bsd license). 17 | See also: http://www.opensource.org/licenses/bsd-license.php 18 | 19 | EXPLOREEMBEDDED DISCLAIMS ANY KIND OF HARDWARE FAILURE RESULTING OUT OF USAGE OF LIBRARIES, DIRECTLY OR 20 | INDIRECTLY. FILES MAY BE SUBJECT TO CHANGE WITHOUT PRIOR NOTICE. THE REVISION HISTORY CONTAINS THE INFORMATION 21 | RELATED TO UPDATES. 22 | 23 | 24 | Permission to use, copy, modify, and distribute this software and its documentation for any purpose 25 | and without fee is hereby granted, provided that this copyright notices appear in all copies 26 | and that both those copyright notices and this permission notice appear in supporting documentation. 27 | **************************************************************************************************/ 28 | 29 | #include 30 | 31 | TaskHandle_t LPT_TaskHandle; 32 | TaskHandle_t MPT_TaskHandle; 33 | TaskHandle_t HPT_TaskHandle; 34 | 35 | SemaphoreHandle_t binSemaphore_A = NULL; 36 | 37 | #define printMsg(taskhandle,str) {\ 38 | Serial.print(F("Priority "));\ // Print task priority 39 | Serial.print(uxTaskPriorityGet(taskhandle));\ 40 | Serial.print(F(" : "));\ 41 | Serial.println(F(str));\ // Print user string 42 | } 43 | 44 | void setup() 45 | { 46 | Serial.begin(9600); 47 | Serial.println(F("In Setup function, Creating Binary Semaphore")); 48 | 49 | vSemaphoreCreateBinary(binSemaphore_A); /* Create binary semaphore */ 50 | 51 | if(binSemaphore_A != NULL) 52 | { 53 | Serial.println(F("Creating low priority task")); 54 | xTaskCreate(LPT_Task, "LPT_Task", 100, NULL, 1, &LPT_TaskHandle); 55 | } 56 | else 57 | { 58 | Serial.println(F("Failed to create Semaphore")); 59 | } 60 | } 61 | 62 | 63 | void loop() 64 | { // Hooked to Idle Task, will run when CPU is Idle 65 | Serial.println(F("Loop function")); 66 | delay(50); 67 | } 68 | 69 | 70 | /*LPT: Low priority task*/ 71 | void LPT_Task(void* pvParameters) 72 | { 73 | printMsg(LPT_TaskHandle,"LPT_Task Acquiring semaphore"); 74 | xSemaphoreTake(binSemaphore_A,portMAX_DELAY); 75 | 76 | printMsg(LPT_TaskHandle,"LPT_Task Creating HPT"); 77 | xTaskCreate(HPT_Task, "HPT_Task", 100, NULL, 3, &HPT_TaskHandle); 78 | 79 | 80 | printMsg(LPT_TaskHandle,"LPT_Task Creating MPT"); 81 | xTaskCreate(MPT_Task, "MPT_Task", 100, NULL, 2, &MPT_TaskHandle); 82 | 83 | printMsg(LPT_TaskHandle,"LPT_Task Releasing Semaphore"); 84 | xSemaphoreGive(binSemaphore_A); 85 | 86 | printMsg(LPT_TaskHandle,"LPT_Task Finally Exiting"); 87 | vTaskDelete(LPT_TaskHandle); 88 | } 89 | 90 | 91 | /*MPT: Medium priority task*/ 92 | void MPT_Task(void* pvParameters) 93 | { 94 | printMsg(MPT_TaskHandle,"MPT_Task Done and about to exit"); 95 | vTaskDelete(MPT_TaskHandle); 96 | } 97 | 98 | 99 | /*MPT: High priority task*/ 100 | void HPT_Task(void* pvParameters) 101 | { 102 | printMsg(HPT_TaskHandle,"HPT_Task Trying to Acquire the semaphore"); 103 | xSemaphoreTake(binSemaphore_A,portMAX_DELAY); 104 | 105 | printMsg(HPT_TaskHandle,"HPT_Task Acquired the semaphore"); 106 | 107 | printMsg(HPT_TaskHandle,"HPT_Task Releasing the semaphore"); 108 | xSemaphoreGive(binSemaphore_A); 109 | 110 | printMsg(HPT_TaskHandle,"HPT_Task About to Exit"); 111 | vTaskDelete(HPT_TaskHandle); 112 | } 113 | 114 | 115 | -------------------------------------------------------------------------------- /examples/~$ExampleList.xlsx: -------------------------------------------------------------------------------- 1 | bagwan bagwan -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=FreeRTOS 2 | version=8.2.3-14 3 | author=Richard Berry 4 | maintainer=Phillip Stevens 5 | sentence=Real Time Operating System implemented for AVR (Uno, Leonardo, Mega). 6 | paragraph=The primary design goals are: Easy to use, Small footprint, Robust. Uses Watchdog Timer for 30ms resolution. Slow blink = stack overflow. Fast blink = heap malloc() failure. 7 | category=Timing 8 | url=https://github.com/feilipu/Arduino_FreeRTOS_Library 9 | architectures=avr 10 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | This is a fork of Richard Barry's FreeRTOS, optimised for the Arduino AVR devices. 2 | 3 | It has been created to provide access to FreeRTOS capabilities, with full compatibility to the Arduino environment. 4 | It does this by keeping hands off almost everything, and only touching the minimum of hardware to be successful. 5 | 6 | ## Further Reading 7 | 8 | The canonical source for information is the [FreeRTOS Web Site](http://www.freertos.org/ "FreeRTOS"). 9 | Within this site, the [Getting Started](http://www.freertos.org/FreeRTOS-quick-start-guide.html "Quick Start Guide") page is very useful. 10 | It is worth having a view from a user, and [manicbug](https://maniacbug.wordpress.com/2012/01/31/freertos/) has some interesting examples. 11 | My other [AVRfreeRTOS Repository](https://sourceforge.net/projects/avrfreertos/) has plenty of examples, 12 | ranging from [blink](https://sourceforge.net/projects/avrfreertos/files/MegaBlink/) through to a [synthesiser](https://sourceforge.net/projects/avrfreertos/files/GA_Synth/). 13 | 14 | ## General 15 | 16 | FreeRTOS has a multitude of configuration options, which can be specified from within the FreeRTOSConfig.h file. 17 | To keep commonality with all of the Arduino hardware options, some sensible defaults have been selected. 18 | 19 | The AVR Watchdog Timer is used to generate 15ms time slices, but Tasks that finish before their allocated time will hand execution back to the Scheduler. 20 | This does not affect the use of any of the normal Timer functions in Arduino. 21 | 22 | Time slices can be selected from 15ms up to 500ms. Slower time slicing can allow the Arduino MCU to sleep for longer, without the complexity of a Tickless idle. 23 | 24 | Watchdog period options: 25 | * WDTO_15MS 26 | * WDTO_30MS 27 | * WDTO_60MS 28 | * WDTO_120MS 29 | * WDTO_250MS 30 | * WDTO_500MS 31 | 32 | Note that Timer resolution is affected by integer math division and the time slice selected. Trying to measure 100ms, using a 60ms time slice for example, won't work. 33 | 34 | Stack for the loop() function has been set at 128 bytes. This can be configured by adjusting the configIDLE_STACK_SIZE parameter. 35 | It should not be less than the configMINIMAL_STACK_SIZE. If you have stack overflow issues, just increase it. 36 | Users should prefer to allocate larger structures, arrays, or buffers using pvPortMalloc(), rather than defining them locally on the stack. 37 | 38 | Memory for the heap is allocated by the normal malloc() function, wrapped by pvPortMalloc(). 39 | This option has been selected because it is automatically adjusted to use the capabilities of each device. 40 | Other heap allocation schemes are supported by FreeRTOS, and they can used with additional configuration. 41 | 42 | ## Errors 43 | 44 | * Stack Overflow: If any stack (for the loop() or) for any Task overflows, there will be a slow LED blink, with 4 second cycle. 45 | * Heap Overflow: If any Task tries to allocate memory and that allocation fails, there will be a fast LED blink, with 100 millisecond cycle. 46 | 47 | ## Errata 48 | 49 | Testing with the Software Serial library shows some incompatibilities at low baud rates (9600), due to the extended time this library disables the global interrupt. Working on characterising and resolving the problem currently. 50 | 51 | ## Compatibility 52 | 53 | * ATmega328 @ 16MHz : Arduino UNO, Arduino Duemilanove, Arduino Diecimila, etc. 54 | * ATmega328 @ 16MHz : Adafruit Pro Trinket 5V, Adafruit Metro 328, Adafruit Metro Mini 55 | * ATmega328 @ 16MHz : Seeed Studio Stalker 56 | * ATmega328 @ 16MHz : Freetronics Eleven 57 | * ATmega328 @ 12MHz : Adafruit Pro Trinket 3V 58 | * ATmega32u4 @ 16MHz : Arduino Leonardo, Arduino Micro, Arduino Yun, Teensy 2.0 59 | * ATmega32u4 @ 8MHz : Adafruit Flora, Bluefruit Micro 60 | * ATmega1284p @ 24.576MHz : Seeed Studio Goldilocks, Seeed Studio Goldilocks Analogue 61 | * ATmega2560 @ 16MHz : Arduino Mega, Arduino ADK 62 | * ATmega2560 @ 16MHz : Seeed Studio ADK 63 | * ATmegaXXXX @ XXMHz : Anything with an ATmega MCU, really. 64 | 65 | ## Files & Configuration 66 | 67 | * Arduino_FreeRTOS.h : Must always be #include first. It references other configuration files, and sets defaults where necessary. 68 | * FreeRTOSConfig.h : Contains a multitude of API and environment configurations. 69 | * FreeRTOSVariant.h : Contains the AVR specific configurations for this port of freeRTOS. 70 | * heap_3.c : Contains the heap allocation scheme based on malloc(). Other schemes are available, but depend on user configuration for specific MCU choice. 71 | 72 | 73 | -------------------------------------------------------------------------------- /src/.gitignore: -------------------------------------------------------------------------------- 1 | /Debug/ 2 | /Release/ 3 | -------------------------------------------------------------------------------- /src/FreeRTOSConfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | FreeRTOS V8.2.3 - Copyright (C) 2015 Real Time Engineers Ltd. 3 | All rights reserved 4 | 5 | VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. 6 | 7 | This file is part of the FreeRTOS distribution. 8 | 9 | FreeRTOS is free software; you can redistribute it and/or modify it under 10 | the terms of the GNU General Public License (version 2) as published by the 11 | Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception. 12 | 13 | *************************************************************************** 14 | >>! NOTE: The modification to the GPL is included to allow you to !<< 15 | >>! distribute a combined work that includes FreeRTOS without being !<< 16 | >>! obliged to provide the source code for proprietary components !<< 17 | >>! outside of the FreeRTOS kernel. !<< 18 | *************************************************************************** 19 | 20 | FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY 21 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 22 | FOR A PARTICULAR PURPOSE. Full license text is available on the following 23 | link: http://www.freertos.org/a00114.html 24 | 25 | *************************************************************************** 26 | * * 27 | * FreeRTOS provides completely free yet professionally developed, * 28 | * robust, strictly quality controlled, supported, and cross * 29 | * platform software that is more than just the market leader, it * 30 | * is the industry's de facto standard. * 31 | * * 32 | * Help yourself get started quickly while simultaneously helping * 33 | * to support the FreeRTOS project by purchasing a FreeRTOS * 34 | * tutorial book, reference manual, or both: * 35 | * http://www.FreeRTOS.org/Documentation * 36 | * * 37 | *************************************************************************** 38 | 39 | http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading 40 | the FAQ page "My application does not run, what could be wrong?". Have you 41 | defined configASSERT()? 42 | 43 | http://www.FreeRTOS.org/support - In return for receiving this top quality 44 | embedded software for free we request you assist our global community by 45 | participating in the support forum. 46 | 47 | http://www.FreeRTOS.org/training - Investing in training allows your team to 48 | be as productive as possible as early as possible. Now you can receive 49 | FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers 50 | Ltd, and the world's leading authority on the world's leading RTOS. 51 | 52 | http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, 53 | including FreeRTOS+Trace - an indispensable productivity tool, a DOS 54 | compatible FAT file system, and our tiny thread aware UDP/IP stack. 55 | 56 | http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate. 57 | Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS. 58 | 59 | http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High 60 | Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS 61 | licenses offer ticketed support, indemnification and commercial middleware. 62 | 63 | http://www.SafeRTOS.com - High Integrity Systems also provide a safety 64 | engineered and independently SIL3 certified version for use in safety and 65 | mission critical applications that require provable dependability. 66 | 67 | 1 tab == 4 spaces! 68 | */ 69 | 70 | #ifndef FREERTOS_CONFIG_H 71 | #define FREERTOS_CONFIG_H 72 | 73 | // And on to the things the same no matter the AVR type... 74 | #define configCPU_CLOCK_HZ ( ( uint32_t ) F_CPU ) // This F_CPU variable set by the environment 75 | #define configUSE_PREEMPTION 1 76 | #define configUSE_IDLE_HOOK 1 77 | #define configUSE_TICK_HOOK 0 78 | #define configUSE_TICKLESS_IDLE 0 79 | #define configUSE_TRACE_FACILITY 1 80 | #define configUSE_16_BIT_TICKS 1 81 | #define configIDLE_SHOULD_YIELD 1 82 | #define configUSE_MUTEXES 1 83 | #define configUSE_RECURSIVE_MUTEXES 1 84 | #define configUSE_COUNTING_SEMAPHORES 1 85 | #define configUSE_ALTERNATIVE_API 0 86 | #define configUSE_QUEUE_SETS 0 87 | #define configQUEUE_REGISTRY_SIZE 0 88 | #define configUSE_TIME_SLICING 1 89 | #define configUSE_NEWLIB_REENTRANT 0 90 | #define configCHECK_FOR_STACK_OVERFLOW 1 91 | #define configUSE_MALLOC_FAILED_HOOK 1 92 | #define configMAX_PRIORITIES ( ( UBaseType_t ) 6 ) 93 | #define configMINIMAL_STACK_SIZE ( ( UBaseType_t ) 127 ) 94 | #define configIDLE_STACK_SIZE ( ( UBaseType_t ) 128 ) 95 | #define configMAX_TASK_NAME_LEN ( 8 ) 96 | #define configTOTAL_HEAP_SIZE 1200 97 | 98 | /* Timer definitions. */ 99 | #define configUSE_TIMERS 1 100 | #define configTIMER_TASK_PRIORITY ( ( UBaseType_t ) 7 ) 101 | #define configTIMER_QUEUE_LENGTH ( ( UBaseType_t ) 10 ) 102 | #define configTIMER_TASK_STACK_DEPTH configMINIMAL_STACK_SIZE 103 | 104 | /* Co-routine definitions. */ 105 | #define configUSE_CO_ROUTINES 0 106 | #define configMAX_CO_ROUTINE_PRIORITIES ( (UBaseType_t ) 2 ) 107 | 108 | /* Set the stack pointer type to be uint16_t, otherwise it defaults to unsigned long */ 109 | #define portPOINTER_SIZE_TYPE uint16_t 110 | 111 | /* Set the following definitions to 1 to include the API function, or zero 112 | to exclude the API function. */ 113 | 114 | #define INCLUDE_vTaskPrioritySet 1 115 | #define INCLUDE_uxTaskPriorityGet 1 116 | #define INCLUDE_vTaskDelete 1 117 | #define INCLUDE_vTaskCleanUpResources 0 118 | #define INCLUDE_vTaskSuspend 1 119 | #define INCLUDE_vResumeFromISR 1 120 | #define INCLUDE_vTaskDelayUntil 0 121 | #define INCLUDE_vTaskDelay 1 122 | #define INCLUDE_xTaskGetSchedulerState 0 123 | #define INCLUDE_xTaskGetIdleTaskHandle 0 // create an idle task handle. 124 | #define INCLUDE_xTaskGetCurrentTaskHandle 0 125 | #define INCLUDE_uxTaskGetStackHighWaterMark 1 126 | 127 | #endif /* FREERTOS_CONFIG_H */ 128 | -------------------------------------------------------------------------------- /src/FreeRTOSVariant.h: -------------------------------------------------------------------------------- 1 | /* freeRTOSVariant.h 2 | * 3 | * Board variant (hardware) specific definitions for the AVR boards that I use regularly. 4 | * 5 | * This file is NOT part of the FreeRTOS distribution. 6 | * 7 | */ 8 | 9 | #ifndef freeRTOSVariant_h 10 | #define freeRTOSVariant_h 11 | 12 | #include 13 | #include 14 | 15 | #include "Arduino_FreeRTOS.h" 16 | #include "task.h" 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | // System Tick - Scheduler timer 23 | // Use the Watchdog timer, and choose the rate at which scheduler interrupts will occur. 24 | 25 | #define portUSE_WDTO WDTO_15MS // portUSE_WDTO to use the Watchdog Timer for xTaskIncrementTick 26 | 27 | /* Watchdog period options: WDTO_15MS 28 | WDTO_30MS 29 | WDTO_60MS 30 | WDTO_120MS 31 | WDTO_250MS 32 | WDTO_500MS 33 | */ 34 | // xxx Watchdog Timer is 128kHz nominal, but 120 kHz at 5V DC and 25 degrees is actually more accurate, from data sheet. 35 | #define configTICK_RATE_HZ ( (TickType_t)( (uint32_t)128000 >> (portUSE_WDTO + 11) ) ) // 2^11 = 2048 WDT scaler for 128kHz Timer 36 | 37 | /*-----------------------------------------------------------*/ 38 | 39 | void initVariant(void) __attribute__((flatten)); 40 | 41 | void vApplicationIdleHook( void ) __attribute__((flatten)); 42 | 43 | void vApplicationMallocFailedHook( void ); 44 | void vApplicationStackOverflowHook( TaskHandle_t xTask, portCHAR *pcTaskName ); 45 | 46 | /*-----------------------------------------------------------*/ 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | 52 | #endif // freeRTOSVariant_h 53 | -------------------------------------------------------------------------------- /src/StackMacros.h: -------------------------------------------------------------------------------- 1 | /* 2 | FreeRTOS V8.2.3 - Copyright (C) 2015 Real Time Engineers Ltd. 3 | All rights reserved 4 | 5 | VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. 6 | 7 | This file is part of the FreeRTOS distribution. 8 | 9 | FreeRTOS is free software; you can redistribute it and/or modify it under 10 | the terms of the GNU General Public License (version 2) as published by the 11 | Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception. 12 | 13 | *************************************************************************** 14 | >>! NOTE: The modification to the GPL is included to allow you to !<< 15 | >>! distribute a combined work that includes FreeRTOS without being !<< 16 | >>! obliged to provide the source code for proprietary components !<< 17 | >>! outside of the FreeRTOS kernel. !<< 18 | *************************************************************************** 19 | 20 | FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY 21 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 22 | FOR A PARTICULAR PURPOSE. Full license text is available on the following 23 | link: http://www.freertos.org/a00114.html 24 | 25 | *************************************************************************** 26 | * * 27 | * FreeRTOS provides completely free yet professionally developed, * 28 | * robust, strictly quality controlled, supported, and cross * 29 | * platform software that is more than just the market leader, it * 30 | * is the industry's de facto standard. * 31 | * * 32 | * Help yourself get started quickly while simultaneously helping * 33 | * to support the FreeRTOS project by purchasing a FreeRTOS * 34 | * tutorial book, reference manual, or both: * 35 | * http://www.FreeRTOS.org/Documentation * 36 | * * 37 | *************************************************************************** 38 | 39 | http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading 40 | the FAQ page "My application does not run, what could be wrong?". Have you 41 | defined configASSERT()? 42 | 43 | http://www.FreeRTOS.org/support - In return for receiving this top quality 44 | embedded software for free we request you assist our global community by 45 | participating in the support forum. 46 | 47 | http://www.FreeRTOS.org/training - Investing in training allows your team to 48 | be as productive as possible as early as possible. Now you can receive 49 | FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers 50 | Ltd, and the world's leading authority on the world's leading RTOS. 51 | 52 | http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, 53 | including FreeRTOS+Trace - an indispensable productivity tool, a DOS 54 | compatible FAT file system, and our tiny thread aware UDP/IP stack. 55 | 56 | http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate. 57 | Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS. 58 | 59 | http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High 60 | Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS 61 | licenses offer ticketed support, indemnification and commercial middleware. 62 | 63 | http://www.SafeRTOS.com - High Integrity Systems also provide a safety 64 | engineered and independently SIL3 certified version for use in safety and 65 | mission critical applications that require provable dependability. 66 | 67 | 1 tab == 4 spaces! 68 | */ 69 | 70 | #ifndef STACK_MACROS_H 71 | #define STACK_MACROS_H 72 | 73 | /* 74 | * Call the stack overflow hook function if the stack of the task being swapped 75 | * out is currently overflowed, or looks like it might have overflowed in the 76 | * past. 77 | * 78 | * Setting configCHECK_FOR_STACK_OVERFLOW to 1 will cause the macro to check 79 | * the current stack state only - comparing the current top of stack value to 80 | * the stack limit. Setting configCHECK_FOR_STACK_OVERFLOW to greater than 1 81 | * will also cause the last few stack bytes to be checked to ensure the value 82 | * to which the bytes were set when the task was created have not been 83 | * overwritten. Note this second test does not guarantee that an overflowed 84 | * stack will always be recognised. 85 | */ 86 | 87 | /*-----------------------------------------------------------*/ 88 | 89 | #if( ( configCHECK_FOR_STACK_OVERFLOW == 1 ) && ( portSTACK_GROWTH < 0 ) ) 90 | 91 | /* Only the current stack state is to be checked. */ 92 | #define taskCHECK_FOR_STACK_OVERFLOW() \ 93 | { \ 94 | /* Is the currently saved stack pointer within the stack limit? */ \ 95 | if( pxCurrentTCB->pxTopOfStack <= pxCurrentTCB->pxStack ) \ 96 | { \ 97 | vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ 98 | } \ 99 | } 100 | 101 | #endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */ 102 | /*-----------------------------------------------------------*/ 103 | 104 | #if( ( configCHECK_FOR_STACK_OVERFLOW == 1 ) && ( portSTACK_GROWTH > 0 ) ) 105 | 106 | /* Only the current stack state is to be checked. */ 107 | #define taskCHECK_FOR_STACK_OVERFLOW() \ 108 | { \ 109 | \ 110 | /* Is the currently saved stack pointer within the stack limit? */ \ 111 | if( pxCurrentTCB->pxTopOfStack >= pxCurrentTCB->pxEndOfStack ) \ 112 | { \ 113 | vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ 114 | } \ 115 | } 116 | 117 | #endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */ 118 | /*-----------------------------------------------------------*/ 119 | 120 | #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH < 0 ) ) 121 | 122 | #define taskCHECK_FOR_STACK_OVERFLOW() \ 123 | { \ 124 | const uint32_t * const pulStack = ( uint32_t * ) pxCurrentTCB->pxStack; \ 125 | const uint32_t ulCheckValue = ( uint32_t ) 0xa5a5a5a5; \ 126 | \ 127 | if( ( pulStack[ 0 ] != ulCheckValue ) || \ 128 | ( pulStack[ 1 ] != ulCheckValue ) || \ 129 | ( pulStack[ 2 ] != ulCheckValue ) || \ 130 | ( pulStack[ 3 ] != ulCheckValue ) ) \ 131 | { \ 132 | vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ 133 | } \ 134 | } 135 | 136 | #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */ 137 | /*-----------------------------------------------------------*/ 138 | 139 | #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH > 0 ) ) 140 | 141 | #define taskCHECK_FOR_STACK_OVERFLOW() \ 142 | { \ 143 | int8_t *pcEndOfStack = ( int8_t * ) pxCurrentTCB->pxEndOfStack; \ 144 | static const uint8_t ucExpectedStackBytes[] = { tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ 145 | tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ 146 | tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ 147 | tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ 148 | tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE }; \ 149 | \ 150 | \ 151 | pcEndOfStack -= sizeof( ucExpectedStackBytes ); \ 152 | \ 153 | /* Has the extremity of the task stack ever been written over? */ \ 154 | if( memcmp( ( void * ) pcEndOfStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 ) \ 155 | { \ 156 | vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ 157 | } \ 158 | } 159 | 160 | #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */ 161 | /*-----------------------------------------------------------*/ 162 | 163 | /* Remove stack overflow macro if not being used. */ 164 | #ifndef taskCHECK_FOR_STACK_OVERFLOW 165 | #define taskCHECK_FOR_STACK_OVERFLOW() 166 | #endif 167 | 168 | 169 | 170 | #endif /* STACK_MACROS_H */ 171 | 172 | -------------------------------------------------------------------------------- /src/croutine.c: -------------------------------------------------------------------------------- 1 | /* 2 | FreeRTOS V8.2.3 - Copyright (C) 2015 Real Time Engineers Ltd. 3 | All rights reserved 4 | 5 | VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. 6 | 7 | This file is part of the FreeRTOS distribution. 8 | 9 | FreeRTOS is free software; you can redistribute it and/or modify it under 10 | the terms of the GNU General Public License (version 2) as published by the 11 | Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception. 12 | 13 | *************************************************************************** 14 | >>! NOTE: The modification to the GPL is included to allow you to !<< 15 | >>! distribute a combined work that includes FreeRTOS without being !<< 16 | >>! obliged to provide the source code for proprietary components !<< 17 | >>! outside of the FreeRTOS kernel. !<< 18 | *************************************************************************** 19 | 20 | FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY 21 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 22 | FOR A PARTICULAR PURPOSE. Full license text is available on the following 23 | link: http://www.freertos.org/a00114.html 24 | 25 | *************************************************************************** 26 | * * 27 | * FreeRTOS provides completely free yet professionally developed, * 28 | * robust, strictly quality controlled, supported, and cross * 29 | * platform software that is more than just the market leader, it * 30 | * is the industry's de facto standard. * 31 | * * 32 | * Help yourself get started quickly while simultaneously helping * 33 | * to support the FreeRTOS project by purchasing a FreeRTOS * 34 | * tutorial book, reference manual, or both: * 35 | * http://www.FreeRTOS.org/Documentation * 36 | * * 37 | *************************************************************************** 38 | 39 | http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading 40 | the FAQ page "My application does not run, what could be wrong?". Have you 41 | defined configASSERT()? 42 | 43 | http://www.FreeRTOS.org/support - In return for receiving this top quality 44 | embedded software for free we request you assist our global community by 45 | participating in the support forum. 46 | 47 | http://www.FreeRTOS.org/training - Investing in training allows your team to 48 | be as productive as possible as early as possible. Now you can receive 49 | FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers 50 | Ltd, and the world's leading authority on the world's leading RTOS. 51 | 52 | http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, 53 | including FreeRTOS+Trace - an indispensable productivity tool, a DOS 54 | compatible FAT file system, and our tiny thread aware UDP/IP stack. 55 | 56 | http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate. 57 | Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS. 58 | 59 | http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High 60 | Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS 61 | licenses offer ticketed support, indemnification and commercial middleware. 62 | 63 | http://www.SafeRTOS.com - High Integrity Systems also provide a safety 64 | engineered and independently SIL3 certified version for use in safety and 65 | mission critical applications that require provable dependability. 66 | 67 | 1 tab == 4 spaces! 68 | */ 69 | 70 | #include "Arduino_FreeRTOS.h" 71 | #include "task.h" 72 | #include "croutine.h" 73 | 74 | /* Remove the whole file is co-routines are not being used. */ 75 | #if( configUSE_CO_ROUTINES != 0 ) 76 | 77 | /* 78 | * Some kernel aware debuggers require data to be viewed to be global, rather 79 | * than file scope. 80 | */ 81 | #ifdef portREMOVE_STATIC_QUALIFIER 82 | #define static 83 | #endif 84 | 85 | 86 | /* Lists for ready and blocked co-routines. --------------------*/ 87 | static List_t pxReadyCoRoutineLists[ configMAX_CO_ROUTINE_PRIORITIES ]; /*< Prioritised ready co-routines. */ 88 | static List_t xDelayedCoRoutineList1; /*< Delayed co-routines. */ 89 | static List_t xDelayedCoRoutineList2; /*< Delayed co-routines (two lists are used - one for delays that have overflowed the current tick count. */ 90 | static List_t * pxDelayedCoRoutineList; /*< Points to the delayed co-routine list currently being used. */ 91 | static List_t * pxOverflowDelayedCoRoutineList; /*< Points to the delayed co-routine list currently being used to hold co-routines that have overflowed the current tick count. */ 92 | static List_t xPendingReadyCoRoutineList; /*< Holds co-routines that have been readied by an external event. They cannot be added directly to the ready lists as the ready lists cannot be accessed by interrupts. */ 93 | 94 | /* Other file private variables. --------------------------------*/ 95 | CRCB_t * pxCurrentCoRoutine = NULL; 96 | static UBaseType_t uxTopCoRoutineReadyPriority = 0; 97 | static TickType_t xCoRoutineTickCount = 0, xLastTickCount = 0, xPassedTicks = 0; 98 | 99 | /* The initial state of the co-routine when it is created. */ 100 | #define corINITIAL_STATE ( 0 ) 101 | 102 | /* 103 | * Place the co-routine represented by pxCRCB into the appropriate ready queue 104 | * for the priority. It is inserted at the end of the list. 105 | * 106 | * This macro accesses the co-routine ready lists and therefore must not be 107 | * used from within an ISR. 108 | */ 109 | #define prvAddCoRoutineToReadyQueue( pxCRCB ) \ 110 | { \ 111 | if( pxCRCB->uxPriority > uxTopCoRoutineReadyPriority ) \ 112 | { \ 113 | uxTopCoRoutineReadyPriority = pxCRCB->uxPriority; \ 114 | } \ 115 | vListInsertEnd( ( List_t * ) &( pxReadyCoRoutineLists[ pxCRCB->uxPriority ] ), &( pxCRCB->xGenericListItem ) ); \ 116 | } 117 | 118 | /* 119 | * Utility to ready all the lists used by the scheduler. This is called 120 | * automatically upon the creation of the first co-routine. 121 | */ 122 | static void prvInitialiseCoRoutineLists( void ); 123 | 124 | /* 125 | * Co-routines that are readied by an interrupt cannot be placed directly into 126 | * the ready lists (there is no mutual exclusion). Instead they are placed in 127 | * in the pending ready list in order that they can later be moved to the ready 128 | * list by the co-routine scheduler. 129 | */ 130 | static void prvCheckPendingReadyList( void ); 131 | 132 | /* 133 | * Macro that looks at the list of co-routines that are currently delayed to 134 | * see if any require waking. 135 | * 136 | * Co-routines are stored in the queue in the order of their wake time - 137 | * meaning once one co-routine has been found whose timer has not expired 138 | * we need not look any further down the list. 139 | */ 140 | static void prvCheckDelayedList( void ); 141 | 142 | /*-----------------------------------------------------------*/ 143 | 144 | BaseType_t xCoRoutineCreate( crCOROUTINE_CODE pxCoRoutineCode, UBaseType_t uxPriority, UBaseType_t uxIndex ) 145 | { 146 | BaseType_t xReturn; 147 | CRCB_t *pxCoRoutine; 148 | 149 | /* Allocate the memory that will store the co-routine control block. */ 150 | pxCoRoutine = ( CRCB_t * ) pvPortMalloc( sizeof( CRCB_t ) ); 151 | if( pxCoRoutine ) 152 | { 153 | /* If pxCurrentCoRoutine is NULL then this is the first co-routine to 154 | be created and the co-routine data structures need initialising. */ 155 | if( pxCurrentCoRoutine == NULL ) 156 | { 157 | pxCurrentCoRoutine = pxCoRoutine; 158 | prvInitialiseCoRoutineLists(); 159 | } 160 | 161 | /* Check the priority is within limits. */ 162 | if( uxPriority >= configMAX_CO_ROUTINE_PRIORITIES ) 163 | { 164 | uxPriority = configMAX_CO_ROUTINE_PRIORITIES - 1; 165 | } 166 | 167 | /* Fill out the co-routine control block from the function parameters. */ 168 | pxCoRoutine->uxState = corINITIAL_STATE; 169 | pxCoRoutine->uxPriority = uxPriority; 170 | pxCoRoutine->uxIndex = uxIndex; 171 | pxCoRoutine->pxCoRoutineFunction = pxCoRoutineCode; 172 | 173 | /* Initialise all the other co-routine control block parameters. */ 174 | vListInitialiseItem( &( pxCoRoutine->xGenericListItem ) ); 175 | vListInitialiseItem( &( pxCoRoutine->xEventListItem ) ); 176 | 177 | /* Set the co-routine control block as a link back from the ListItem_t. 178 | This is so we can get back to the containing CRCB from a generic item 179 | in a list. */ 180 | listSET_LIST_ITEM_OWNER( &( pxCoRoutine->xGenericListItem ), pxCoRoutine ); 181 | listSET_LIST_ITEM_OWNER( &( pxCoRoutine->xEventListItem ), pxCoRoutine ); 182 | 183 | /* Event lists are always in priority order. */ 184 | listSET_LIST_ITEM_VALUE( &( pxCoRoutine->xEventListItem ), ( ( TickType_t ) configMAX_CO_ROUTINE_PRIORITIES - ( TickType_t ) uxPriority ) ); 185 | 186 | /* Now the co-routine has been initialised it can be added to the ready 187 | list at the correct priority. */ 188 | prvAddCoRoutineToReadyQueue( pxCoRoutine ); 189 | 190 | xReturn = pdPASS; 191 | } 192 | else 193 | { 194 | xReturn = errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY; 195 | } 196 | 197 | return xReturn; 198 | } 199 | /*-----------------------------------------------------------*/ 200 | 201 | void vCoRoutineAddToDelayedList( TickType_t xTicksToDelay, List_t *pxEventList ) 202 | { 203 | TickType_t xTimeToWake; 204 | 205 | /* Calculate the time to wake - this may overflow but this is 206 | not a problem. */ 207 | xTimeToWake = xCoRoutineTickCount + xTicksToDelay; 208 | 209 | /* We must remove ourselves from the ready list before adding 210 | ourselves to the blocked list as the same list item is used for 211 | both lists. */ 212 | ( void ) uxListRemove( ( ListItem_t * ) &( pxCurrentCoRoutine->xGenericListItem ) ); 213 | 214 | /* The list item will be inserted in wake time order. */ 215 | listSET_LIST_ITEM_VALUE( &( pxCurrentCoRoutine->xGenericListItem ), xTimeToWake ); 216 | 217 | if( xTimeToWake < xCoRoutineTickCount ) 218 | { 219 | /* Wake time has overflowed. Place this item in the 220 | overflow list. */ 221 | vListInsert( ( List_t * ) pxOverflowDelayedCoRoutineList, ( ListItem_t * ) &( pxCurrentCoRoutine->xGenericListItem ) ); 222 | } 223 | else 224 | { 225 | /* The wake time has not overflowed, so we can use the 226 | current block list. */ 227 | vListInsert( ( List_t * ) pxDelayedCoRoutineList, ( ListItem_t * ) &( pxCurrentCoRoutine->xGenericListItem ) ); 228 | } 229 | 230 | if( pxEventList ) 231 | { 232 | /* Also add the co-routine to an event list. If this is done then the 233 | function must be called with interrupts disabled. */ 234 | vListInsert( pxEventList, &( pxCurrentCoRoutine->xEventListItem ) ); 235 | } 236 | } 237 | /*-----------------------------------------------------------*/ 238 | 239 | static void prvCheckPendingReadyList( void ) 240 | { 241 | /* Are there any co-routines waiting to get moved to the ready list? These 242 | are co-routines that have been readied by an ISR. The ISR cannot access 243 | the ready lists itself. */ 244 | while( listLIST_IS_EMPTY( &xPendingReadyCoRoutineList ) == pdFALSE ) 245 | { 246 | CRCB_t *pxUnblockedCRCB; 247 | 248 | /* The pending ready list can be accessed by an ISR. */ 249 | portDISABLE_INTERRUPTS(); 250 | { 251 | pxUnblockedCRCB = ( CRCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( (&xPendingReadyCoRoutineList) ); 252 | ( void ) uxListRemove( &( pxUnblockedCRCB->xEventListItem ) ); 253 | } 254 | portENABLE_INTERRUPTS(); 255 | 256 | ( void ) uxListRemove( &( pxUnblockedCRCB->xGenericListItem ) ); 257 | prvAddCoRoutineToReadyQueue( pxUnblockedCRCB ); 258 | } 259 | } 260 | /*-----------------------------------------------------------*/ 261 | 262 | static void prvCheckDelayedList( void ) 263 | { 264 | CRCB_t *pxCRCB; 265 | 266 | xPassedTicks = xTaskGetTickCount() - xLastTickCount; 267 | while( xPassedTicks ) 268 | { 269 | xCoRoutineTickCount++; 270 | xPassedTicks--; 271 | 272 | /* If the tick count has overflowed we need to swap the ready lists. */ 273 | if( xCoRoutineTickCount == 0 ) 274 | { 275 | List_t * pxTemp; 276 | 277 | /* Tick count has overflowed so we need to swap the delay lists. If there are 278 | any items in pxDelayedCoRoutineList here then there is an error! */ 279 | pxTemp = pxDelayedCoRoutineList; 280 | pxDelayedCoRoutineList = pxOverflowDelayedCoRoutineList; 281 | pxOverflowDelayedCoRoutineList = pxTemp; 282 | } 283 | 284 | /* See if this tick has made a timeout expire. */ 285 | while( listLIST_IS_EMPTY( pxDelayedCoRoutineList ) == pdFALSE ) 286 | { 287 | pxCRCB = ( CRCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxDelayedCoRoutineList ); 288 | 289 | if( xCoRoutineTickCount < listGET_LIST_ITEM_VALUE( &( pxCRCB->xGenericListItem ) ) ) 290 | { 291 | /* Timeout not yet expired. */ 292 | break; 293 | } 294 | 295 | portDISABLE_INTERRUPTS(); 296 | { 297 | /* The event could have occurred just before this critical 298 | section. If this is the case then the generic list item will 299 | have been moved to the pending ready list and the following 300 | line is still valid. Also the pvContainer parameter will have 301 | been set to NULL so the following lines are also valid. */ 302 | ( void ) uxListRemove( &( pxCRCB->xGenericListItem ) ); 303 | 304 | /* Is the co-routine waiting on an event also? */ 305 | if( pxCRCB->xEventListItem.pvContainer ) 306 | { 307 | ( void ) uxListRemove( &( pxCRCB->xEventListItem ) ); 308 | } 309 | } 310 | portENABLE_INTERRUPTS(); 311 | 312 | prvAddCoRoutineToReadyQueue( pxCRCB ); 313 | } 314 | } 315 | 316 | xLastTickCount = xCoRoutineTickCount; 317 | } 318 | /*-----------------------------------------------------------*/ 319 | 320 | void vCoRoutineSchedule( void ) 321 | { 322 | /* See if any co-routines readied by events need moving to the ready lists. */ 323 | prvCheckPendingReadyList(); 324 | 325 | /* See if any delayed co-routines have timed out. */ 326 | prvCheckDelayedList(); 327 | 328 | /* Find the highest priority queue that contains ready co-routines. */ 329 | while( listLIST_IS_EMPTY( &( pxReadyCoRoutineLists[ uxTopCoRoutineReadyPriority ] ) ) ) 330 | { 331 | if( uxTopCoRoutineReadyPriority == 0 ) 332 | { 333 | /* No more co-routines to check. */ 334 | return; 335 | } 336 | --uxTopCoRoutineReadyPriority; 337 | } 338 | 339 | /* listGET_OWNER_OF_NEXT_ENTRY walks through the list, so the co-routines 340 | of the same priority get an equal share of the processor time. */ 341 | listGET_OWNER_OF_NEXT_ENTRY( pxCurrentCoRoutine, &( pxReadyCoRoutineLists[ uxTopCoRoutineReadyPriority ] ) ); 342 | 343 | /* Call the co-routine. */ 344 | ( pxCurrentCoRoutine->pxCoRoutineFunction )( pxCurrentCoRoutine, pxCurrentCoRoutine->uxIndex ); 345 | 346 | return; 347 | } 348 | /*-----------------------------------------------------------*/ 349 | 350 | static void prvInitialiseCoRoutineLists( void ) 351 | { 352 | UBaseType_t uxPriority; 353 | 354 | for( uxPriority = 0; uxPriority < configMAX_CO_ROUTINE_PRIORITIES; uxPriority++ ) 355 | { 356 | vListInitialise( ( List_t * ) &( pxReadyCoRoutineLists[ uxPriority ] ) ); 357 | } 358 | 359 | vListInitialise( ( List_t * ) &xDelayedCoRoutineList1 ); 360 | vListInitialise( ( List_t * ) &xDelayedCoRoutineList2 ); 361 | vListInitialise( ( List_t * ) &xPendingReadyCoRoutineList ); 362 | 363 | /* Start with pxDelayedCoRoutineList using list1 and the 364 | pxOverflowDelayedCoRoutineList using list2. */ 365 | pxDelayedCoRoutineList = &xDelayedCoRoutineList1; 366 | pxOverflowDelayedCoRoutineList = &xDelayedCoRoutineList2; 367 | } 368 | /*-----------------------------------------------------------*/ 369 | 370 | BaseType_t xCoRoutineRemoveFromEventList( const List_t *pxEventList ) 371 | { 372 | CRCB_t *pxUnblockedCRCB; 373 | BaseType_t xReturn; 374 | 375 | /* This function is called from within an interrupt. It can only access 376 | event lists and the pending ready list. This function assumes that a 377 | check has already been made to ensure pxEventList is not empty. */ 378 | pxUnblockedCRCB = ( CRCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxEventList ); 379 | ( void ) uxListRemove( &( pxUnblockedCRCB->xEventListItem ) ); 380 | vListInsertEnd( ( List_t * ) &( xPendingReadyCoRoutineList ), &( pxUnblockedCRCB->xEventListItem ) ); 381 | 382 | if( pxUnblockedCRCB->uxPriority >= pxCurrentCoRoutine->uxPriority ) 383 | { 384 | xReturn = pdTRUE; 385 | } 386 | else 387 | { 388 | xReturn = pdFALSE; 389 | } 390 | 391 | return xReturn; 392 | } 393 | 394 | #endif /* configUSE_CO_ROUTINES == 0 */ 395 | 396 | -------------------------------------------------------------------------------- /src/heap_1.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ExploreEmbedded/Arduino_FreeRTOS/14b0093782c1799cf3fcdd3b99ef975362887433/src/heap_1.zip -------------------------------------------------------------------------------- /src/heap_4.c: -------------------------------------------------------------------------------- 1 | /* 2 | FreeRTOS V8.2.3 - Copyright (C) 2015 Real Time Engineers Ltd. 3 | All rights reserved 4 | 5 | VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. 6 | 7 | This file is part of the FreeRTOS distribution. 8 | 9 | FreeRTOS is free software; you can redistribute it and/or modify it under 10 | the terms of the GNU General Public License (version 2) as published by the 11 | Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception. 12 | 13 | *************************************************************************** 14 | >>! NOTE: The modification to the GPL is included to allow you to !<< 15 | >>! distribute a combined work that includes FreeRTOS without being !<< 16 | >>! obliged to provide the source code for proprietary components !<< 17 | >>! outside of the FreeRTOS kernel. !<< 18 | *************************************************************************** 19 | 20 | FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY 21 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 22 | FOR A PARTICULAR PURPOSE. Full license text is available on the following 23 | link: http://www.freertos.org/a00114.html 24 | 25 | *************************************************************************** 26 | * * 27 | * FreeRTOS provides completely free yet professionally developed, * 28 | * robust, strictly quality controlled, supported, and cross * 29 | * platform software that is more than just the market leader, it * 30 | * is the industry's de facto standard. * 31 | * * 32 | * Help yourself get started quickly while simultaneously helping * 33 | * to support the FreeRTOS project by purchasing a FreeRTOS * 34 | * tutorial book, reference manual, or both: * 35 | * http://www.FreeRTOS.org/Documentation * 36 | * * 37 | *************************************************************************** 38 | 39 | http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading 40 | the FAQ page "My application does not run, what could be wrong?". Have you 41 | defined configASSERT()? 42 | 43 | http://www.FreeRTOS.org/support - In return for receiving this top quality 44 | embedded software for free we request you assist our global community by 45 | participating in the support forum. 46 | 47 | http://www.FreeRTOS.org/training - Investing in training allows your team to 48 | be as productive as possible as early as possible. Now you can receive 49 | FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers 50 | Ltd, and the world's leading authority on the world's leading RTOS. 51 | 52 | http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, 53 | including FreeRTOS+Trace - an indispensable productivity tool, a DOS 54 | compatible FAT file system, and our tiny thread aware UDP/IP stack. 55 | 56 | http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate. 57 | Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS. 58 | 59 | http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High 60 | Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS 61 | licenses offer ticketed support, indemnification and commercial middleware. 62 | 63 | http://www.SafeRTOS.com - High Integrity Systems also provide a safety 64 | engineered and independently SIL3 certified version for use in safety and 65 | mission critical applications that require provable dependability. 66 | 67 | 1 tab == 4 spaces! 68 | */ 69 | 70 | /* 71 | * A sample implementation of pvPortMalloc() and vPortFree() that combines 72 | * (coalescences) adjacent memory blocks as they are freed, and in so doing 73 | * limits memory fragmentation. 74 | * 75 | * See heap_1.c, heap_2.c and heap_3.c for alternative implementations, and the 76 | * memory management pages of http://www.FreeRTOS.org for more information. 77 | */ 78 | #include 79 | 80 | /* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining 81 | all the API functions to use the MPU wrappers. That should only be done when 82 | task.h is included from an application file. */ 83 | #define MPU_WRAPPERS_INCLUDED_FROM_API_FILE 84 | 85 | #include "Arduino_FreeRTOS.h" 86 | #include "task.h" 87 | 88 | #undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE 89 | 90 | /* Block sizes must not get too small. */ 91 | #define heapMINIMUM_BLOCK_SIZE ( ( size_t ) ( xHeapStructSize << 1 ) ) 92 | 93 | /* Assumes 8bit bytes! */ 94 | #define heapBITS_PER_BYTE ( ( size_t ) 8 ) 95 | 96 | /* Allocate the memory for the heap. */ 97 | #if( configAPPLICATION_ALLOCATED_HEAP == 1 ) 98 | /* The application writer has already defined the array used for the RTOS 99 | heap - probably so it can be placed in a special segment or address. */ 100 | extern uint8_t ucHeap[ configTOTAL_HEAP_SIZE ]; 101 | #else 102 | static uint8_t ucHeap[ configTOTAL_HEAP_SIZE ]; 103 | #endif /* configAPPLICATION_ALLOCATED_HEAP */ 104 | 105 | /* Define the linked list structure. This is used to link free blocks in order 106 | of their memory address. */ 107 | typedef struct A_BLOCK_LINK 108 | { 109 | struct A_BLOCK_LINK *pxNextFreeBlock; /*<< The next free block in the list. */ 110 | size_t xBlockSize; /*<< The size of the free block. */ 111 | } BlockLink_t; 112 | 113 | /*-----------------------------------------------------------*/ 114 | 115 | /* 116 | * Inserts a block of memory that is being freed into the correct position in 117 | * the list of free memory blocks. The block being freed will be merged with 118 | * the block in front it and/or the block behind it if the memory blocks are 119 | * adjacent to each other. 120 | */ 121 | static void prvInsertBlockIntoFreeList( BlockLink_t *pxBlockToInsert ); 122 | 123 | /* 124 | * Called automatically to setup the required heap structures the first time 125 | * pvPortMalloc() is called. 126 | */ 127 | static void prvHeapInit( void ); 128 | 129 | /*-----------------------------------------------------------*/ 130 | 131 | /* The size of the structure placed at the beginning of each allocated memory 132 | block must by correctly byte aligned. */ 133 | static const size_t xHeapStructSize = ( sizeof( BlockLink_t ) + ( ( size_t ) ( portBYTE_ALIGNMENT - 1 ) ) ) & ~( ( size_t ) portBYTE_ALIGNMENT_MASK ); 134 | 135 | /* Create a couple of list links to mark the start and end of the list. */ 136 | static BlockLink_t xStart, *pxEnd = NULL; 137 | 138 | /* Keeps track of the number of free bytes remaining, but says nothing about 139 | fragmentation. */ 140 | static size_t xFreeBytesRemaining = 0U; 141 | static size_t xMinimumEverFreeBytesRemaining = 0U; 142 | 143 | /* Gets set to the top bit of an size_t type. When this bit in the xBlockSize 144 | member of an BlockLink_t structure is set then the block belongs to the 145 | application. When the bit is free the block is still part of the free heap 146 | space. */ 147 | static size_t xBlockAllocatedBit = 0; 148 | 149 | /*-----------------------------------------------------------*/ 150 | 151 | void *pvPortMalloc( size_t xWantedSize ) 152 | { 153 | BlockLink_t *pxBlock, *pxPreviousBlock, *pxNewBlockLink; 154 | void *pvReturn = NULL; 155 | 156 | vTaskSuspendAll(); 157 | { 158 | /* If this is the first call to malloc then the heap will require 159 | initialisation to setup the list of free blocks. */ 160 | if( pxEnd == NULL ) 161 | { 162 | prvHeapInit(); 163 | } 164 | else 165 | { 166 | mtCOVERAGE_TEST_MARKER(); 167 | } 168 | 169 | /* Check the requested block size is not so large that the top bit is 170 | set. The top bit of the block size member of the BlockLink_t structure 171 | is used to determine who owns the block - the application or the 172 | kernel, so it must be free. */ 173 | if( ( xWantedSize & xBlockAllocatedBit ) == 0 ) 174 | { 175 | /* The wanted size is increased so it can contain a BlockLink_t 176 | structure in addition to the requested amount of bytes. */ 177 | if( xWantedSize > 0 ) 178 | { 179 | xWantedSize += xHeapStructSize; 180 | 181 | /* Ensure that blocks are always aligned to the required number 182 | of bytes. */ 183 | if( ( xWantedSize & portBYTE_ALIGNMENT_MASK ) != 0x00 ) 184 | { 185 | /* Byte alignment required. */ 186 | xWantedSize += ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) ); 187 | configASSERT( ( xWantedSize & portBYTE_ALIGNMENT_MASK ) == 0 ); 188 | } 189 | else 190 | { 191 | mtCOVERAGE_TEST_MARKER(); 192 | } 193 | } 194 | else 195 | { 196 | mtCOVERAGE_TEST_MARKER(); 197 | } 198 | 199 | if( ( xWantedSize > 0 ) && ( xWantedSize <= xFreeBytesRemaining ) ) 200 | { 201 | /* Traverse the list from the start (lowest address) block until 202 | one of adequate size is found. */ 203 | pxPreviousBlock = &xStart; 204 | pxBlock = xStart.pxNextFreeBlock; 205 | while( ( pxBlock->xBlockSize < xWantedSize ) && ( pxBlock->pxNextFreeBlock != NULL ) ) 206 | { 207 | pxPreviousBlock = pxBlock; 208 | pxBlock = pxBlock->pxNextFreeBlock; 209 | } 210 | 211 | /* If the end marker was reached then a block of adequate size 212 | was not found. */ 213 | if( pxBlock != pxEnd ) 214 | { 215 | /* Return the memory space pointed to - jumping over the 216 | BlockLink_t structure at its start. */ 217 | pvReturn = ( void * ) ( ( ( uint8_t * ) pxPreviousBlock->pxNextFreeBlock ) + xHeapStructSize ); 218 | 219 | /* This block is being returned for use so must be taken out 220 | of the list of free blocks. */ 221 | pxPreviousBlock->pxNextFreeBlock = pxBlock->pxNextFreeBlock; 222 | 223 | /* If the block is larger than required it can be split into 224 | two. */ 225 | if( ( pxBlock->xBlockSize - xWantedSize ) > heapMINIMUM_BLOCK_SIZE ) 226 | { 227 | /* This block is to be split into two. Create a new 228 | block following the number of bytes requested. The void 229 | cast is used to prevent byte alignment warnings from the 230 | compiler. */ 231 | pxNewBlockLink = ( void * ) ( ( ( uint8_t * ) pxBlock ) + xWantedSize ); 232 | configASSERT( ( ( ( size_t ) pxNewBlockLink ) & portBYTE_ALIGNMENT_MASK ) == 0 ); 233 | 234 | /* Calculate the sizes of two blocks split from the 235 | single block. */ 236 | pxNewBlockLink->xBlockSize = pxBlock->xBlockSize - xWantedSize; 237 | pxBlock->xBlockSize = xWantedSize; 238 | 239 | /* Insert the new block into the list of free blocks. */ 240 | prvInsertBlockIntoFreeList( pxNewBlockLink ); 241 | } 242 | else 243 | { 244 | mtCOVERAGE_TEST_MARKER(); 245 | } 246 | 247 | xFreeBytesRemaining -= pxBlock->xBlockSize; 248 | 249 | if( xFreeBytesRemaining < xMinimumEverFreeBytesRemaining ) 250 | { 251 | xMinimumEverFreeBytesRemaining = xFreeBytesRemaining; 252 | } 253 | else 254 | { 255 | mtCOVERAGE_TEST_MARKER(); 256 | } 257 | 258 | /* The block is being returned - it is allocated and owned 259 | by the application and has no "next" block. */ 260 | pxBlock->xBlockSize |= xBlockAllocatedBit; 261 | pxBlock->pxNextFreeBlock = NULL; 262 | } 263 | else 264 | { 265 | mtCOVERAGE_TEST_MARKER(); 266 | } 267 | } 268 | else 269 | { 270 | mtCOVERAGE_TEST_MARKER(); 271 | } 272 | } 273 | else 274 | { 275 | mtCOVERAGE_TEST_MARKER(); 276 | } 277 | 278 | traceMALLOC( pvReturn, xWantedSize ); 279 | } 280 | ( void ) xTaskResumeAll(); 281 | 282 | #if( configUSE_MALLOC_FAILED_HOOK == 1 ) 283 | { 284 | if( pvReturn == NULL ) 285 | { 286 | extern void vApplicationMallocFailedHook( void ); 287 | vApplicationMallocFailedHook(); 288 | } 289 | else 290 | { 291 | mtCOVERAGE_TEST_MARKER(); 292 | } 293 | } 294 | #endif 295 | 296 | configASSERT( ( ( ( uint32_t ) pvReturn ) & portBYTE_ALIGNMENT_MASK ) == 0 ); 297 | return pvReturn; 298 | } 299 | /*-----------------------------------------------------------*/ 300 | 301 | void vPortFree( void *pv ) 302 | { 303 | uint8_t *puc = ( uint8_t * ) pv; 304 | BlockLink_t *pxLink; 305 | 306 | if( pv != NULL ) 307 | { 308 | /* The memory being freed will have an BlockLink_t structure immediately 309 | before it. */ 310 | puc -= xHeapStructSize; 311 | 312 | /* This casting is to keep the compiler from issuing warnings. */ 313 | pxLink = ( void * ) puc; 314 | 315 | /* Check the block is actually allocated. */ 316 | configASSERT( ( pxLink->xBlockSize & xBlockAllocatedBit ) != 0 ); 317 | configASSERT( pxLink->pxNextFreeBlock == NULL ); 318 | 319 | if( ( pxLink->xBlockSize & xBlockAllocatedBit ) != 0 ) 320 | { 321 | if( pxLink->pxNextFreeBlock == NULL ) 322 | { 323 | /* The block is being returned to the heap - it is no longer 324 | allocated. */ 325 | pxLink->xBlockSize &= ~xBlockAllocatedBit; 326 | 327 | vTaskSuspendAll(); 328 | { 329 | /* Add this block to the list of free blocks. */ 330 | xFreeBytesRemaining += pxLink->xBlockSize; 331 | traceFREE( pv, pxLink->xBlockSize ); 332 | prvInsertBlockIntoFreeList( ( ( BlockLink_t * ) pxLink ) ); 333 | } 334 | ( void ) xTaskResumeAll(); 335 | } 336 | else 337 | { 338 | mtCOVERAGE_TEST_MARKER(); 339 | } 340 | } 341 | else 342 | { 343 | mtCOVERAGE_TEST_MARKER(); 344 | } 345 | } 346 | } 347 | /*-----------------------------------------------------------*/ 348 | 349 | size_t xPortGetFreeHeapSize( void ) 350 | { 351 | return xFreeBytesRemaining; 352 | } 353 | /*-----------------------------------------------------------*/ 354 | 355 | size_t xPortGetMinimumEverFreeHeapSize( void ) 356 | { 357 | return xMinimumEverFreeBytesRemaining; 358 | } 359 | /*-----------------------------------------------------------*/ 360 | 361 | void vPortInitialiseBlocks( void ) 362 | { 363 | /* This just exists to keep the linker quiet. */ 364 | } 365 | /*-----------------------------------------------------------*/ 366 | 367 | static void prvHeapInit( void ) 368 | { 369 | BlockLink_t *pxFirstFreeBlock; 370 | uint8_t *pucAlignedHeap; 371 | size_t uxAddress; 372 | size_t xTotalHeapSize = configTOTAL_HEAP_SIZE; 373 | 374 | /* Ensure the heap starts on a correctly aligned boundary. */ 375 | uxAddress = ( size_t ) ucHeap; 376 | 377 | if( ( uxAddress & portBYTE_ALIGNMENT_MASK ) != 0 ) 378 | { 379 | uxAddress += ( portBYTE_ALIGNMENT - 1 ); 380 | uxAddress &= ~( ( size_t ) portBYTE_ALIGNMENT_MASK ); 381 | xTotalHeapSize -= uxAddress - ( size_t ) ucHeap; 382 | } 383 | 384 | pucAlignedHeap = ( uint8_t * ) uxAddress; 385 | 386 | /* xStart is used to hold a pointer to the first item in the list of free 387 | blocks. The void cast is used to prevent compiler warnings. */ 388 | xStart.pxNextFreeBlock = ( void * ) pucAlignedHeap; 389 | xStart.xBlockSize = ( size_t ) 0; 390 | 391 | /* pxEnd is used to mark the end of the list of free blocks and is inserted 392 | at the end of the heap space. */ 393 | uxAddress = ( ( size_t ) pucAlignedHeap ) + xTotalHeapSize; 394 | uxAddress -= xHeapStructSize; 395 | uxAddress &= ~( ( size_t ) portBYTE_ALIGNMENT_MASK ); 396 | pxEnd = ( void * ) uxAddress; 397 | pxEnd->xBlockSize = 0; 398 | pxEnd->pxNextFreeBlock = NULL; 399 | 400 | /* To start with there is a single free block that is sized to take up the 401 | entire heap space, minus the space taken by pxEnd. */ 402 | pxFirstFreeBlock = ( void * ) pucAlignedHeap; 403 | pxFirstFreeBlock->xBlockSize = uxAddress - ( size_t ) pxFirstFreeBlock; 404 | pxFirstFreeBlock->pxNextFreeBlock = pxEnd; 405 | 406 | /* Only one block exists - and it covers the entire usable heap space. */ 407 | xMinimumEverFreeBytesRemaining = pxFirstFreeBlock->xBlockSize; 408 | xFreeBytesRemaining = pxFirstFreeBlock->xBlockSize; 409 | 410 | /* Work out the position of the top bit in a size_t variable. */ 411 | xBlockAllocatedBit = ( ( size_t ) 1 ) << ( ( sizeof( size_t ) * heapBITS_PER_BYTE ) - 1 ); 412 | } 413 | /*-----------------------------------------------------------*/ 414 | 415 | static void prvInsertBlockIntoFreeList( BlockLink_t *pxBlockToInsert ) 416 | { 417 | BlockLink_t *pxIterator; 418 | uint8_t *puc; 419 | 420 | /* Iterate through the list until a block is found that has a higher address 421 | than the block being inserted. */ 422 | for( pxIterator = &xStart; pxIterator->pxNextFreeBlock < pxBlockToInsert; pxIterator = pxIterator->pxNextFreeBlock ) 423 | { 424 | /* Nothing to do here, just iterate to the right position. */ 425 | } 426 | 427 | /* Do the block being inserted, and the block it is being inserted after 428 | make a contiguous block of memory? */ 429 | puc = ( uint8_t * ) pxIterator; 430 | if( ( puc + pxIterator->xBlockSize ) == ( uint8_t * ) pxBlockToInsert ) 431 | { 432 | pxIterator->xBlockSize += pxBlockToInsert->xBlockSize; 433 | pxBlockToInsert = pxIterator; 434 | } 435 | else 436 | { 437 | mtCOVERAGE_TEST_MARKER(); 438 | } 439 | 440 | /* Do the block being inserted, and the block it is being inserted before 441 | make a contiguous block of memory? */ 442 | puc = ( uint8_t * ) pxBlockToInsert; 443 | if( ( puc + pxBlockToInsert->xBlockSize ) == ( uint8_t * ) pxIterator->pxNextFreeBlock ) 444 | { 445 | if( pxIterator->pxNextFreeBlock != pxEnd ) 446 | { 447 | /* Form one big block from the two blocks. */ 448 | pxBlockToInsert->xBlockSize += pxIterator->pxNextFreeBlock->xBlockSize; 449 | pxBlockToInsert->pxNextFreeBlock = pxIterator->pxNextFreeBlock->pxNextFreeBlock; 450 | } 451 | else 452 | { 453 | pxBlockToInsert->pxNextFreeBlock = pxEnd; 454 | } 455 | } 456 | else 457 | { 458 | pxBlockToInsert->pxNextFreeBlock = pxIterator->pxNextFreeBlock; 459 | } 460 | 461 | /* If the block being inserted plugged a gab, so was merged with the block 462 | before and the block after, then it's pxNextFreeBlock pointer will have 463 | already been set, and should not be set here as that would make it point 464 | to itself. */ 465 | if( pxIterator != pxBlockToInsert ) 466 | { 467 | pxIterator->pxNextFreeBlock = pxBlockToInsert; 468 | } 469 | else 470 | { 471 | mtCOVERAGE_TEST_MARKER(); 472 | } 473 | } 474 | 475 | -------------------------------------------------------------------------------- /src/heap_4.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ExploreEmbedded/Arduino_FreeRTOS/14b0093782c1799cf3fcdd3b99ef975362887433/src/heap_4.zip -------------------------------------------------------------------------------- /src/license.txt: -------------------------------------------------------------------------------- 1 | ---------------------------------------------------------------------------- 2 | 3 | NOTE: The modification to the GPL documented below is included to allow you to 4 | distribute a combined work that includes FreeRTOS without being obliged to 5 | provide the source code for proprietary components. 6 | 7 | ---------------------------------------------------------------------------- 8 | 9 | The FreeRTOS GPL Exception Text: 10 | 11 | Any FreeRTOS source code, whether modified or in it's original release form, 12 | or whether in whole or in part, can only be distributed by you under the terms 13 | of version 2 of the GNU General Public License plus this exception. An 14 | independent module is a module which is not derived from or based on FreeRTOS. 15 | 16 | Clause 1: 17 | 18 | Linking FreeRTOS with other modules is making a combined work based on FreeRTOS. 19 | Thus, the terms and conditions of the GNU General Public License V2 cover the 20 | whole combination. 21 | 22 | As a special exception, the copyright holders of FreeRTOS give you permission to 23 | link FreeRTOS with independent modules to produce a statically linked 24 | executable, regardless of the license terms of these independent modules, and to 25 | copy and distribute the resulting executable under terms of your choice, 26 | provided that you also meet, for each linked independent module, the terms and 27 | conditions of the license of that module. An independent module is a module 28 | which is not derived from or based on FreeRTOS. 29 | 30 | Clause 2: 31 | 32 | FreeRTOS may not be used for any competitive or comparative purpose, including 33 | the publication of any form of run time or compile time metric, without the 34 | express permission of Real Time Engineers Ltd. (this is the norm within the 35 | industry and is intended to ensure information accuracy). 36 | 37 | 38 | -------------------------------------------------------------------- 39 | 40 | The standard GPL v2 text follows: 41 | 42 | 43 | GNU GENERAL PUBLIC LICENSE 44 | Version 2, June 1991 45 | 46 | Copyright (C) 1989, 1991 Free Software Foundation, Inc. 47 | 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 48 | Everyone is permitted to copy and distribute verbatim copies 49 | of this license document, but changing it is not allowed. 50 | 51 | Preamble 52 | 53 | The licenses for most software are designed to take away your 54 | freedom to share and change it. By contrast, the GNU General Public 55 | License is intended to guarantee your freedom to share and change free 56 | software--to make sure the software is free for all its users. This 57 | General Public License applies to most of the Free Software 58 | Foundation's software and to any other program whose authors commit to 59 | using it. (Some other Free Software Foundation software is covered by 60 | the GNU Library General Public License instead.) You can apply it to 61 | your programs, too. 62 | 63 | When we speak of free software, we are referring to freedom, not 64 | price. Our General Public Licenses are designed to make sure that you 65 | have the freedom to distribute copies of free software (and charge for 66 | this service if you wish), that you receive source code or can get it 67 | if you want it, that you can change the software or use pieces of it 68 | in new free programs; and that you know you can do these things. 69 | 70 | To protect your rights, we need to make restrictions that forbid 71 | anyone to deny you these rights or to ask you to surrender the rights. 72 | These restrictions translate to certain responsibilities for you if you 73 | distribute copies of the software, or if you modify it. 74 | 75 | For example, if you distribute copies of such a program, whether 76 | gratis or for a fee, you must give the recipients all the rights that 77 | you have. You must make sure that they, too, receive or can get the 78 | source code. And you must show them these terms so they know their 79 | rights. 80 | 81 | We protect your rights with two steps: (1) copyright the software, and 82 | (2) offer you this license which gives you legal permission to copy, 83 | distribute and/or modify the software. 84 | 85 | Also, for each author's protection and ours, we want to make certain 86 | that everyone understands that there is no warranty for this free 87 | software. If the software is modified by someone else and passed on, we 88 | want its recipients to know that what they have is not the original, so 89 | that any problems introduced by others will not reflect on the original 90 | authors' reputations. 91 | 92 | Finally, any free program is threatened constantly by software 93 | patents. We wish to avoid the danger that redistributors of a free 94 | program will individually obtain patent licenses, in effect making the 95 | program proprietary. To prevent this, we have made it clear that any 96 | patent must be licensed for everyone's free use or not licensed at all. 97 | 98 | The precise terms and conditions for copying, distribution and 99 | modification follow. 100 | 101 | GNU GENERAL PUBLIC LICENSE 102 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 103 | 104 | 0. This License applies to any program or other work which contains 105 | a notice placed by the copyright holder saying it may be distributed 106 | under the terms of this General Public License. The "Program", below, 107 | refers to any such program or work, and a "work based on the Program" 108 | means either the Program or any derivative work under copyright law: 109 | that is to say, a work containing the Program or a portion of it, 110 | either verbatim or with modifications and/or translated into another 111 | language. (Hereinafter, translation is included without limitation in 112 | the term "modification".) Each licensee is addressed as "you". 113 | 114 | Activities other than copying, distribution and modification are not 115 | covered by this License; they are outside its scope. The act of 116 | running the Program is not restricted, and the output from the Program 117 | is covered only if its contents constitute a work based on the 118 | Program (independent of having been made by running the Program). 119 | Whether that is true depends on what the Program does. 120 | 121 | 1. You may copy and distribute verbatim copies of the Program's 122 | source code as you receive it, in any medium, provided that you 123 | conspicuously and appropriately publish on each copy an appropriate 124 | copyright notice and disclaimer of warranty; keep intact all the 125 | notices that refer to this License and to the absence of any warranty; 126 | and give any other recipients of the Program a copy of this License 127 | along with the Program. 128 | 129 | You may charge a fee for the physical act of transferring a copy, and 130 | you may at your option offer warranty protection in exchange for a fee. 131 | 132 | 2. You may modify your copy or copies of the Program or any portion 133 | of it, thus forming a work based on the Program, and copy and 134 | distribute such modifications or work under the terms of Section 1 135 | above, provided that you also meet all of these conditions: 136 | 137 | a) You must cause the modified files to carry prominent notices 138 | stating that you changed the files and the date of any change. 139 | 140 | b) You must cause any work that you distribute or publish, that in 141 | whole or in part contains or is derived from the Program or any 142 | part thereof, to be licensed as a whole at no charge to all third 143 | parties under the terms of this License. 144 | 145 | c) If the modified program normally reads commands interactively 146 | when run, you must cause it, when started running for such 147 | interactive use in the most ordinary way, to print or display an 148 | announcement including an appropriate copyright notice and a 149 | notice that there is no warranty (or else, saying that you provide 150 | a warranty) and that users may redistribute the program under 151 | these conditions, and telling the user how to view a copy of this 152 | License. (Exception: if the Program itself is interactive but 153 | does not normally print such an announcement, your work based on 154 | the Program is not required to print an announcement.) 155 | 156 | These requirements apply to the modified work as a whole. If 157 | identifiable sections of that work are not derived from the Program, 158 | and can be reasonably considered independent and separate works in 159 | themselves, then this License, and its terms, do not apply to those 160 | sections when you distribute them as separate works. But when you 161 | distribute the same sections as part of a whole which is a work based 162 | on the Program, the distribution of the whole must be on the terms of 163 | this License, whose permissions for other licensees extend to the 164 | entire whole, and thus to each and every part regardless of who wrote it. 165 | 166 | Thus, it is not the intent of this section to claim rights or contest 167 | your rights to work written entirely by you; rather, the intent is to 168 | exercise the right to control the distribution of derivative or 169 | collective works based on the Program. 170 | 171 | In addition, mere aggregation of another work not based on the Program 172 | with the Program (or with a work based on the Program) on a volume of 173 | a storage or distribution medium does not bring the other work under 174 | the scope of this License. 175 | 176 | 3. You may copy and distribute the Program (or a work based on it, 177 | under Section 2) in object code or executable form under the terms of 178 | Sections 1 and 2 above provided that you also do one of the following: 179 | 180 | a) Accompany it with the complete corresponding machine-readable 181 | source code, which must be distributed under the terms of Sections 182 | 1 and 2 above on a medium customarily used for software interchange; or, 183 | 184 | b) Accompany it with a written offer, valid for at least three 185 | years, to give any third party, for a charge no more than your 186 | cost of physically performing source distribution, a complete 187 | machine-readable copy of the corresponding source code, to be 188 | distributed under the terms of Sections 1 and 2 above on a medium 189 | customarily used for software interchange; or, 190 | 191 | c) Accompany it with the information you received as to the offer 192 | to distribute corresponding source code. (This alternative is 193 | allowed only for noncommercial distribution and only if you 194 | received the program in object code or executable form with such 195 | an offer, in accord with Subsection b above.) 196 | 197 | The source code for a work means the preferred form of the work for 198 | making modifications to it. For an executable work, complete source 199 | code means all the source code for all modules it contains, plus any 200 | associated interface definition files, plus the scripts used to 201 | control compilation and installation of the executable. However, as a 202 | special exception, the source code distributed need not include 203 | anything that is normally distributed (in either source or binary 204 | form) with the major components (compiler, kernel, and so on) of the 205 | operating system on which the executable runs, unless that component 206 | itself accompanies the executable. 207 | 208 | If distribution of executable or object code is made by offering 209 | access to copy from a designated place, then offering equivalent 210 | access to copy the source code from the same place counts as 211 | distribution of the source code, even though third parties are not 212 | compelled to copy the source along with the object code. 213 | 214 | 4. You may not copy, modify, sublicense, or distribute the Program 215 | except as expressly provided under this License. Any attempt 216 | otherwise to copy, modify, sublicense or distribute the Program is 217 | void, and will automatically terminate your rights under this License. 218 | However, parties who have received copies, or rights, from you under 219 | this License will not have their licenses terminated so long as such 220 | parties remain in full compliance. 221 | 222 | 5. You are not required to accept this License, since you have not 223 | signed it. However, nothing else grants you permission to modify or 224 | distribute the Program or its derivative works. These actions are 225 | prohibited by law if you do not accept this License. Therefore, by 226 | modifying or distributing the Program (or any work based on the 227 | Program), you indicate your acceptance of this License to do so, and 228 | all its terms and conditions for copying, distributing or modifying 229 | the Program or works based on it. 230 | 231 | 6. Each time you redistribute the Program (or any work based on the 232 | Program), the recipient automatically receives a license from the 233 | original licensor to copy, distribute or modify the Program subject to 234 | these terms and conditions. You may not impose any further 235 | restrictions on the recipients' exercise of the rights granted herein. 236 | You are not responsible for enforcing compliance by third parties to 237 | this License. 238 | 239 | 7. If, as a consequence of a court judgment or allegation of patent 240 | infringement or for any other reason (not limited to patent issues), 241 | conditions are imposed on you (whether by court order, agreement or 242 | otherwise) that contradict the conditions of this License, they do not 243 | excuse you from the conditions of this License. If you cannot 244 | distribute so as to satisfy simultaneously your obligations under this 245 | License and any other pertinent obligations, then as a consequence you 246 | may not distribute the Program at all. For example, if a patent 247 | license would not permit royalty-free redistribution of the Program by 248 | all those who receive copies directly or indirectly through you, then 249 | the only way you could satisfy both it and this License would be to 250 | refrain entirely from distribution of the Program. 251 | 252 | If any portion of this section is held invalid or unenforceable under 253 | any particular circumstance, the balance of the section is intended to 254 | apply and the section as a whole is intended to apply in other 255 | circumstances. 256 | 257 | It is not the purpose of this section to induce you to infringe any 258 | patents or other property right claims or to contest validity of any 259 | such claims; this section has the sole purpose of protecting the 260 | integrity of the free software distribution system, which is 261 | implemented by public license practices. Many people have made 262 | generous contributions to the wide range of software distributed 263 | through that system in reliance on consistent application of that 264 | system; it is up to the author/donor to decide if he or she is willing 265 | to distribute software through any other system and a licensee cannot 266 | impose that choice. 267 | 268 | This section is intended to make thoroughly clear what is believed to 269 | be a consequence of the rest of this License. 270 | 271 | 8. If the distribution and/or use of the Program is restricted in 272 | certain countries either by patents or by copyrighted interfaces, the 273 | original copyright holder who places the Program under this License 274 | may add an explicit geographical distribution limitation excluding 275 | those countries, so that distribution is permitted only in or among 276 | countries not thus excluded. In such case, this License incorporates 277 | the limitation as if written in the body of this License. 278 | 279 | 9. The Free Software Foundation may publish revised and/or new versions 280 | of the General Public License from time to time. Such new versions will 281 | be similar in spirit to the present version, but may differ in detail to 282 | address new problems or concerns. 283 | 284 | Each version is given a distinguishing version number. If the Program 285 | specifies a version number of this License which applies to it and "any 286 | later version", you have the option of following the terms and conditions 287 | either of that version or of any later version published by the Free 288 | Software Foundation. If the Program does not specify a version number of 289 | this License, you may choose any version ever published by the Free Software 290 | Foundation. 291 | 292 | 10. If you wish to incorporate parts of the Program into other free 293 | programs whose distribution conditions are different, write to the author 294 | to ask for permission. For software which is copyrighted by the Free 295 | Software Foundation, write to the Free Software Foundation; we sometimes 296 | make exceptions for this. Our decision will be guided by the two goals 297 | of preserving the free status of all derivatives of our free software and 298 | of promoting the sharing and reuse of software generally. 299 | 300 | NO WARRANTY 301 | 302 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 303 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 304 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 305 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 306 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 307 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 308 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 309 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 310 | REPAIR OR CORRECTION. 311 | 312 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 313 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 314 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 315 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 316 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 317 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 318 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 319 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 320 | POSSIBILITY OF SUCH DAMAGES. 321 | 322 | END OF TERMS AND CONDITIONS 323 | 324 | How to Apply These Terms to Your New Programs 325 | 326 | If you develop a new program, and you want it to be of the greatest 327 | possible use to the public, the best way to achieve this is to make it 328 | free software which everyone can redistribute and change under these terms. 329 | 330 | To do so, attach the following notices to the program. It is safest 331 | to attach them to the start of each source file to most effectively 332 | convey the exclusion of warranty; and each file should have at least 333 | the "copyright" line and a pointer to where the full notice is found. 334 | 335 | 336 | Copyright (C) 337 | 338 | This program is free software; you can redistribute it and/or modify 339 | it under the terms of the GNU General Public License** as published by 340 | the Free Software Foundation; either version 2 of the License, or 341 | (at your option) any later version. 342 | 343 | This program is distributed in the hope that it will be useful, 344 | but WITHOUT ANY WARRANTY; without even the implied warranty of 345 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 346 | GNU General Public License for more details. 347 | 348 | You should have received a copy of the GNU General Public License 349 | along with this program; if not, write to the Free Software 350 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 351 | 352 | 353 | Also add information on how to contact you by electronic and paper mail. 354 | 355 | If the program is interactive, make it output a short notice like this 356 | when it starts in an interactive mode: 357 | 358 | Gnomovision version 69, Copyright (C) year name of author 359 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 360 | This is free software, and you are welcome to redistribute it 361 | under certain conditions; type `show c' for details. 362 | 363 | The hypothetical commands `show w' and `show c' should show the appropriate 364 | parts of the General Public License. Of course, the commands you use may 365 | be called something other than `show w' and `show c'; they could even be 366 | mouse-clicks or menu items--whatever suits your program. 367 | 368 | You should also get your employer (if you work as a programmer) or your 369 | school, if any, to sign a "copyright disclaimer" for the program, if 370 | necessary. Here is a sample; alter the names: 371 | 372 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 373 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 374 | 375 | , 1 April 1989 376 | Ty Coon, President of Vice 377 | 378 | This General Public License does not permit incorporating your program into 379 | proprietary programs. If your program is a subroutine library, you may 380 | consider it more useful to permit linking proprietary applications with the 381 | library. If this is what you want to do, use the GNU Library General 382 | Public License instead of this License. 383 | 384 | -------------------------------------------------------------------------------- /src/list.c: -------------------------------------------------------------------------------- 1 | /* 2 | FreeRTOS V8.2.3 - Copyright (C) 2015 Real Time Engineers Ltd. 3 | All rights reserved 4 | 5 | VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. 6 | 7 | This file is part of the FreeRTOS distribution. 8 | 9 | FreeRTOS is free software; you can redistribute it and/or modify it under 10 | the terms of the GNU General Public License (version 2) as published by the 11 | Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception. 12 | 13 | *************************************************************************** 14 | >>! NOTE: The modification to the GPL is included to allow you to !<< 15 | >>! distribute a combined work that includes FreeRTOS without being !<< 16 | >>! obliged to provide the source code for proprietary components !<< 17 | >>! outside of the FreeRTOS kernel. !<< 18 | *************************************************************************** 19 | 20 | FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY 21 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 22 | FOR A PARTICULAR PURPOSE. Full license text is available on the following 23 | link: http://www.freertos.org/a00114.html 24 | 25 | *************************************************************************** 26 | * * 27 | * FreeRTOS provides completely free yet professionally developed, * 28 | * robust, strictly quality controlled, supported, and cross * 29 | * platform software that is more than just the market leader, it * 30 | * is the industry's de facto standard. * 31 | * * 32 | * Help yourself get started quickly while simultaneously helping * 33 | * to support the FreeRTOS project by purchasing a FreeRTOS * 34 | * tutorial book, reference manual, or both: * 35 | * http://www.FreeRTOS.org/Documentation * 36 | * * 37 | *************************************************************************** 38 | 39 | http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading 40 | the FAQ page "My application does not run, what could be wrong?". Have you 41 | defined configASSERT()? 42 | 43 | http://www.FreeRTOS.org/support - In return for receiving this top quality 44 | embedded software for free we request you assist our global community by 45 | participating in the support forum. 46 | 47 | http://www.FreeRTOS.org/training - Investing in training allows your team to 48 | be as productive as possible as early as possible. Now you can receive 49 | FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers 50 | Ltd, and the world's leading authority on the world's leading RTOS. 51 | 52 | http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, 53 | including FreeRTOS+Trace - an indispensable productivity tool, a DOS 54 | compatible FAT file system, and our tiny thread aware UDP/IP stack. 55 | 56 | http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate. 57 | Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS. 58 | 59 | http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High 60 | Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS 61 | licenses offer ticketed support, indemnification and commercial middleware. 62 | 63 | http://www.SafeRTOS.com - High Integrity Systems also provide a safety 64 | engineered and independently SIL3 certified version for use in safety and 65 | mission critical applications that require provable dependability. 66 | 67 | 1 tab == 4 spaces! 68 | */ 69 | 70 | 71 | #include 72 | #include "Arduino_FreeRTOS.h" 73 | #include "list.h" 74 | 75 | /*----------------------------------------------------------- 76 | * PUBLIC LIST API documented in list.h 77 | *----------------------------------------------------------*/ 78 | 79 | void vListInitialise( List_t * const pxList ) 80 | { 81 | /* The list structure contains a list item which is used to mark the 82 | end of the list. To initialise the list the list end is inserted 83 | as the only list entry. */ 84 | pxList->pxIndex = ( ListItem_t * ) &( pxList->xListEnd ); /*lint !e826 !e740 The mini list structure is used as the list end to save RAM. This is checked and valid. */ 85 | 86 | /* The list end value is the highest possible value in the list to 87 | ensure it remains at the end of the list. */ 88 | pxList->xListEnd.xItemValue = portMAX_DELAY; 89 | 90 | /* The list end next and previous pointers point to itself so we know 91 | when the list is empty. */ 92 | pxList->xListEnd.pxNext = ( ListItem_t * ) &( pxList->xListEnd ); /*lint !e826 !e740 The mini list structure is used as the list end to save RAM. This is checked and valid. */ 93 | pxList->xListEnd.pxPrevious = ( ListItem_t * ) &( pxList->xListEnd );/*lint !e826 !e740 The mini list structure is used as the list end to save RAM. This is checked and valid. */ 94 | 95 | pxList->uxNumberOfItems = ( UBaseType_t ) 0U; 96 | 97 | /* Write known values into the list if 98 | configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */ 99 | listSET_LIST_INTEGRITY_CHECK_1_VALUE( pxList ); 100 | listSET_LIST_INTEGRITY_CHECK_2_VALUE( pxList ); 101 | } 102 | /*-----------------------------------------------------------*/ 103 | 104 | void vListInitialiseItem( ListItem_t * const pxItem ) 105 | { 106 | /* Make sure the list item is not recorded as being on a list. */ 107 | pxItem->pvContainer = NULL; 108 | 109 | /* Write known values into the list item if 110 | configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */ 111 | listSET_FIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem ); 112 | listSET_SECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem ); 113 | } 114 | /*-----------------------------------------------------------*/ 115 | 116 | void vListInsertEnd( List_t * const pxList, ListItem_t * const pxNewListItem ) 117 | { 118 | ListItem_t * const pxIndex = pxList->pxIndex; 119 | 120 | /* Only effective when configASSERT() is also defined, these tests may catch 121 | the list data structures being overwritten in memory. They will not catch 122 | data errors caused by incorrect configuration or use of FreeRTOS. */ 123 | listTEST_LIST_INTEGRITY( pxList ); 124 | listTEST_LIST_ITEM_INTEGRITY( pxNewListItem ); 125 | 126 | /* Insert a new list item into pxList, but rather than sort the list, 127 | makes the new list item the last item to be removed by a call to 128 | listGET_OWNER_OF_NEXT_ENTRY(). */ 129 | pxNewListItem->pxNext = pxIndex; 130 | pxNewListItem->pxPrevious = pxIndex->pxPrevious; 131 | 132 | /* Only used during decision coverage testing. */ 133 | mtCOVERAGE_TEST_DELAY(); 134 | 135 | pxIndex->pxPrevious->pxNext = pxNewListItem; 136 | pxIndex->pxPrevious = pxNewListItem; 137 | 138 | /* Remember which list the item is in. */ 139 | pxNewListItem->pvContainer = ( void * ) pxList; 140 | 141 | ( pxList->uxNumberOfItems )++; 142 | } 143 | /*-----------------------------------------------------------*/ 144 | 145 | void vListInsert( List_t * const pxList, ListItem_t * const pxNewListItem ) 146 | { 147 | ListItem_t *pxIterator; 148 | const TickType_t xValueOfInsertion = pxNewListItem->xItemValue; 149 | 150 | /* Only effective when configASSERT() is also defined, these tests may catch 151 | the list data structures being overwritten in memory. They will not catch 152 | data errors caused by incorrect configuration or use of FreeRTOS. */ 153 | listTEST_LIST_INTEGRITY( pxList ); 154 | listTEST_LIST_ITEM_INTEGRITY( pxNewListItem ); 155 | 156 | /* Insert the new list item into the list, sorted in xItemValue order. 157 | 158 | If the list already contains a list item with the same item value then the 159 | new list item should be placed after it. This ensures that TCB's which are 160 | stored in ready lists (all of which have the same xItemValue value) get a 161 | share of the CPU. However, if the xItemValue is the same as the back marker 162 | the iteration loop below will not end. Therefore the value is checked 163 | first, and the algorithm slightly modified if necessary. */ 164 | if( xValueOfInsertion == portMAX_DELAY ) 165 | { 166 | pxIterator = pxList->xListEnd.pxPrevious; 167 | } 168 | else 169 | { 170 | /* *** NOTE *********************************************************** 171 | If you find your application is crashing here then likely causes are 172 | listed below. In addition see http://www.freertos.org/FAQHelp.html for 173 | more tips, and ensure configASSERT() is defined! 174 | http://www.freertos.org/a00110.html#configASSERT 175 | 176 | 1) Stack overflow - 177 | see http://www.freertos.org/Stacks-and-stack-overflow-checking.html 178 | 2) Incorrect interrupt priority assignment, especially on Cortex-M 179 | parts where numerically high priority values denote low actual 180 | interrupt priorities, which can seem counter intuitive. See 181 | http://www.freertos.org/RTOS-Cortex-M3-M4.html and the definition 182 | of configMAX_SYSCALL_INTERRUPT_PRIORITY on 183 | http://www.freertos.org/a00110.html 184 | 3) Calling an API function from within a critical section or when 185 | the scheduler is suspended, or calling an API function that does 186 | not end in "FromISR" from an interrupt. 187 | 4) Using a queue or semaphore before it has been initialised or 188 | before the scheduler has been started (are interrupts firing 189 | before vTaskStartScheduler() has been called?). 190 | **********************************************************************/ 191 | 192 | for( pxIterator = ( ListItem_t * ) &( pxList->xListEnd ); pxIterator->pxNext->xItemValue <= xValueOfInsertion; pxIterator = pxIterator->pxNext ) /*lint !e826 !e740 The mini list structure is used as the list end to save RAM. This is checked and valid. */ 193 | { 194 | /* There is nothing to do here, just iterating to the wanted 195 | insertion position. */ 196 | } 197 | } 198 | 199 | pxNewListItem->pxNext = pxIterator->pxNext; 200 | pxNewListItem->pxNext->pxPrevious = pxNewListItem; 201 | pxNewListItem->pxPrevious = pxIterator; 202 | pxIterator->pxNext = pxNewListItem; 203 | 204 | /* Remember which list the item is in. This allows fast removal of the 205 | item later. */ 206 | pxNewListItem->pvContainer = ( void * ) pxList; 207 | 208 | ( pxList->uxNumberOfItems )++; 209 | } 210 | /*-----------------------------------------------------------*/ 211 | 212 | UBaseType_t uxListRemove( ListItem_t * const pxItemToRemove ) 213 | { 214 | /* The list item knows which list it is in. Obtain the list from the list 215 | item. */ 216 | List_t * const pxList = ( List_t * ) pxItemToRemove->pvContainer; 217 | 218 | pxItemToRemove->pxNext->pxPrevious = pxItemToRemove->pxPrevious; 219 | pxItemToRemove->pxPrevious->pxNext = pxItemToRemove->pxNext; 220 | 221 | /* Only used during decision coverage testing. */ 222 | mtCOVERAGE_TEST_DELAY(); 223 | 224 | /* Make sure the index is left pointing to a valid item. */ 225 | if( pxList->pxIndex == pxItemToRemove ) 226 | { 227 | pxList->pxIndex = pxItemToRemove->pxPrevious; 228 | } 229 | else 230 | { 231 | mtCOVERAGE_TEST_MARKER(); 232 | } 233 | 234 | pxItemToRemove->pvContainer = NULL; 235 | ( pxList->uxNumberOfItems )--; 236 | 237 | return pxList->uxNumberOfItems; 238 | } 239 | /*-----------------------------------------------------------*/ 240 | 241 | -------------------------------------------------------------------------------- /src/mpu_wrappers.h: -------------------------------------------------------------------------------- 1 | /* 2 | FreeRTOS V8.2.3 - Copyright (C) 2015 Real Time Engineers Ltd. 3 | All rights reserved 4 | 5 | VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. 6 | 7 | This file is part of the FreeRTOS distribution. 8 | 9 | FreeRTOS is free software; you can redistribute it and/or modify it under 10 | the terms of the GNU General Public License (version 2) as published by the 11 | Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception. 12 | 13 | *************************************************************************** 14 | >>! NOTE: The modification to the GPL is included to allow you to !<< 15 | >>! distribute a combined work that includes FreeRTOS without being !<< 16 | >>! obliged to provide the source code for proprietary components !<< 17 | >>! outside of the FreeRTOS kernel. !<< 18 | *************************************************************************** 19 | 20 | FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY 21 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 22 | FOR A PARTICULAR PURPOSE. Full license text is available on the following 23 | link: http://www.freertos.org/a00114.html 24 | 25 | *************************************************************************** 26 | * * 27 | * FreeRTOS provides completely free yet professionally developed, * 28 | * robust, strictly quality controlled, supported, and cross * 29 | * platform software that is more than just the market leader, it * 30 | * is the industry's de facto standard. * 31 | * * 32 | * Help yourself get started quickly while simultaneously helping * 33 | * to support the FreeRTOS project by purchasing a FreeRTOS * 34 | * tutorial book, reference manual, or both: * 35 | * http://www.FreeRTOS.org/Documentation * 36 | * * 37 | *************************************************************************** 38 | 39 | http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading 40 | the FAQ page "My application does not run, what could be wrong?". Have you 41 | defined configASSERT()? 42 | 43 | http://www.FreeRTOS.org/support - In return for receiving this top quality 44 | embedded software for free we request you assist our global community by 45 | participating in the support forum. 46 | 47 | http://www.FreeRTOS.org/training - Investing in training allows your team to 48 | be as productive as possible as early as possible. Now you can receive 49 | FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers 50 | Ltd, and the world's leading authority on the world's leading RTOS. 51 | 52 | http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, 53 | including FreeRTOS+Trace - an indispensable productivity tool, a DOS 54 | compatible FAT file system, and our tiny thread aware UDP/IP stack. 55 | 56 | http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate. 57 | Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS. 58 | 59 | http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High 60 | Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS 61 | licenses offer ticketed support, indemnification and commercial middleware. 62 | 63 | http://www.SafeRTOS.com - High Integrity Systems also provide a safety 64 | engineered and independently SIL3 certified version for use in safety and 65 | mission critical applications that require provable dependability. 66 | 67 | 1 tab == 4 spaces! 68 | */ 69 | 70 | #ifndef MPU_WRAPPERS_H 71 | #define MPU_WRAPPERS_H 72 | 73 | /* This file redefines API functions to be called through a wrapper macro, but 74 | only for ports that are using the MPU. */ 75 | #ifdef portUSING_MPU_WRAPPERS 76 | 77 | /* MPU_WRAPPERS_INCLUDED_FROM_API_FILE will be defined when this file is 78 | included from queue.c or task.c to prevent it from having an effect within 79 | those files. */ 80 | #ifndef MPU_WRAPPERS_INCLUDED_FROM_API_FILE 81 | 82 | #define xTaskGenericCreate MPU_xTaskGenericCreate 83 | #define vTaskAllocateMPURegions MPU_vTaskAllocateMPURegions 84 | #define vTaskDelete MPU_vTaskDelete 85 | #define vTaskDelayUntil MPU_vTaskDelayUntil 86 | #define vTaskDelay MPU_vTaskDelay 87 | #define uxTaskPriorityGet MPU_uxTaskPriorityGet 88 | #define vTaskPrioritySet MPU_vTaskPrioritySet 89 | #define eTaskGetState MPU_eTaskGetState 90 | #define vTaskSuspend MPU_vTaskSuspend 91 | #define vTaskResume MPU_vTaskResume 92 | #define vTaskSuspendAll MPU_vTaskSuspendAll 93 | #define xTaskResumeAll MPU_xTaskResumeAll 94 | #define xTaskGetTickCount MPU_xTaskGetTickCount 95 | #define uxTaskGetNumberOfTasks MPU_uxTaskGetNumberOfTasks 96 | #define vTaskList MPU_vTaskList 97 | #define vTaskGetRunTimeStats MPU_vTaskGetRunTimeStats 98 | #define vTaskSetApplicationTaskTag MPU_vTaskSetApplicationTaskTag 99 | #define xTaskGetApplicationTaskTag MPU_xTaskGetApplicationTaskTag 100 | #define xTaskCallApplicationTaskHook MPU_xTaskCallApplicationTaskHook 101 | #define uxTaskGetStackHighWaterMark MPU_uxTaskGetStackHighWaterMark 102 | #define xTaskGetCurrentTaskHandle MPU_xTaskGetCurrentTaskHandle 103 | #define xTaskGetSchedulerState MPU_xTaskGetSchedulerState 104 | #define xTaskGetIdleTaskHandle MPU_xTaskGetIdleTaskHandle 105 | #define uxTaskGetSystemState MPU_uxTaskGetSystemState 106 | #define xTaskGenericNotify MPU_xTaskGenericNotify 107 | #define xTaskNotifyWait MPU_xTaskNotifyWait 108 | #define ulTaskNotifyTake MPU_ulTaskNotifyTake 109 | 110 | #define xQueueGenericCreate MPU_xQueueGenericCreate 111 | #define xQueueCreateMutex MPU_xQueueCreateMutex 112 | #define xQueueGiveMutexRecursive MPU_xQueueGiveMutexRecursive 113 | #define xQueueTakeMutexRecursive MPU_xQueueTakeMutexRecursive 114 | #define xQueueCreateCountingSemaphore MPU_xQueueCreateCountingSemaphore 115 | #define xQueueGenericSend MPU_xQueueGenericSend 116 | #define xQueueAltGenericSend MPU_xQueueAltGenericSend 117 | #define xQueueAltGenericReceive MPU_xQueueAltGenericReceive 118 | #define xQueueGenericReceive MPU_xQueueGenericReceive 119 | #define uxQueueMessagesWaiting MPU_uxQueueMessagesWaiting 120 | #define vQueueDelete MPU_vQueueDelete 121 | #define xQueueGenericReset MPU_xQueueGenericReset 122 | #define xQueueCreateSet MPU_xQueueCreateSet 123 | #define xQueueSelectFromSet MPU_xQueueSelectFromSet 124 | #define xQueueAddToSet MPU_xQueueAddToSet 125 | #define xQueueRemoveFromSet MPU_xQueueRemoveFromSet 126 | #define xQueueGetMutexHolder MPU_xQueueGetMutexHolder 127 | #define xQueueGetMutexHolder MPU_xQueueGetMutexHolder 128 | 129 | #define pvPortMalloc MPU_pvPortMalloc 130 | #define vPortFree MPU_vPortFree 131 | #define xPortGetFreeHeapSize MPU_xPortGetFreeHeapSize 132 | #define vPortInitialiseBlocks MPU_vPortInitialiseBlocks 133 | #define xPortGetMinimumEverFreeHeapSize MPU_xPortGetMinimumEverFreeHeapSize 134 | 135 | #if configQUEUE_REGISTRY_SIZE > 0 136 | #define vQueueAddToRegistry MPU_vQueueAddToRegistry 137 | #define vQueueUnregisterQueue MPU_vQueueUnregisterQueue 138 | #endif 139 | 140 | #define xTimerCreate MPU_xTimerCreate 141 | #define pvTimerGetTimerID MPU_pvTimerGetTimerID 142 | #define vTimerSetTimerID MPU_vTimerSetTimerID 143 | #define xTimerIsTimerActive MPU_xTimerIsTimerActive 144 | #define xTimerGetTimerDaemonTaskHandle MPU_xTimerGetTimerDaemonTaskHandle 145 | #define xTimerPendFunctionCall MPU_xTimerPendFunctionCall 146 | #define pcTimerGetTimerName MPU_pcTimerGetTimerName 147 | #define xTimerGenericCommand MPU_xTimerGenericCommand 148 | 149 | #define xEventGroupCreate MPU_xEventGroupCreate 150 | #define xEventGroupWaitBits MPU_xEventGroupWaitBits 151 | #define xEventGroupClearBits MPU_xEventGroupClearBits 152 | #define xEventGroupSetBits MPU_xEventGroupSetBits 153 | #define xEventGroupSync MPU_xEventGroupSync 154 | #define vEventGroupDelete MPU_vEventGroupDelete 155 | 156 | /* Remove the privileged function macro. */ 157 | #define PRIVILEGED_FUNCTION 158 | 159 | #else /* MPU_WRAPPERS_INCLUDED_FROM_API_FILE */ 160 | 161 | /* Ensure API functions go in the privileged execution section. */ 162 | #define PRIVILEGED_FUNCTION __attribute__((section("privileged_functions"))) 163 | #define PRIVILEGED_DATA __attribute__((section("privileged_data"))) 164 | 165 | #endif /* MPU_WRAPPERS_INCLUDED_FROM_API_FILE */ 166 | 167 | #else /* portUSING_MPU_WRAPPERS */ 168 | 169 | #if defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) // Mega with 2560 170 | #define PRIVILEGED_FUNCTION __attribute__ ((hot, flatten)) 171 | #define PRIVILEGED_DATA 172 | #define portUSING_MPU_WRAPPERS 0 173 | #elif defined(__AVR_ATmega640__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega1281__) || defined(__AVR_ATmega664P__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega1284PA__) // Goldilocks with 1284p 174 | #define PRIVILEGED_FUNCTION __attribute__ ((hot)) 175 | #define PRIVILEGED_DATA 176 | #define portUSING_MPU_WRAPPERS 0 177 | #else // Uno with 328p 178 | #define PRIVILEGED_FUNCTION __attribute__ ((hot)) 179 | #define PRIVILEGED_DATA 180 | #define portUSING_MPU_WRAPPERS 0 181 | #endif 182 | 183 | #endif /* portUSING_MPU_WRAPPERS */ 184 | 185 | 186 | #endif /* MPU_WRAPPERS_H */ 187 | 188 | -------------------------------------------------------------------------------- /src/portable.h: -------------------------------------------------------------------------------- 1 | /* 2 | FreeRTOS V8.2.3 - Copyright (C) 2015 Real Time Engineers Ltd. 3 | All rights reserved 4 | 5 | VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. 6 | 7 | This file is part of the FreeRTOS distribution. 8 | 9 | FreeRTOS is free software; you can redistribute it and/or modify it under 10 | the terms of the GNU General Public License (version 2) as published by the 11 | Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception. 12 | 13 | *************************************************************************** 14 | >>! NOTE: The modification to the GPL is included to allow you to !<< 15 | >>! distribute a combined work that includes FreeRTOS without being !<< 16 | >>! obliged to provide the source code for proprietary components !<< 17 | >>! outside of the FreeRTOS kernel. !<< 18 | *************************************************************************** 19 | 20 | FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY 21 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 22 | FOR A PARTICULAR PURPOSE. Full license text is available on the following 23 | link: http://www.freertos.org/a00114.html 24 | 25 | *************************************************************************** 26 | * * 27 | * FreeRTOS provides completely free yet professionally developed, * 28 | * robust, strictly quality controlled, supported, and cross * 29 | * platform software that is more than just the market leader, it * 30 | * is the industry's de facto standard. * 31 | * * 32 | * Help yourself get started quickly while simultaneously helping * 33 | * to support the FreeRTOS project by purchasing a FreeRTOS * 34 | * tutorial book, reference manual, or both: * 35 | * http://www.FreeRTOS.org/Documentation * 36 | * * 37 | *************************************************************************** 38 | 39 | http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading 40 | the FAQ page "My application does not run, what could be wrong?". Have you 41 | defined configASSERT()? 42 | 43 | http://www.FreeRTOS.org/support - In return for receiving this top quality 44 | embedded software for free we request you assist our global community by 45 | participating in the support forum. 46 | 47 | http://www.FreeRTOS.org/training - Investing in training allows your team to 48 | be as productive as possible as early as possible. Now you can receive 49 | FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers 50 | Ltd, and the world's leading authority on the world's leading RTOS. 51 | 52 | http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, 53 | including FreeRTOS+Trace - an indispensable productivity tool, a DOS 54 | compatible FAT file system, and our tiny thread aware UDP/IP stack. 55 | 56 | http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate. 57 | Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS. 58 | 59 | http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High 60 | Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS 61 | licenses offer ticketed support, indemnification and commercial middleware. 62 | 63 | http://www.SafeRTOS.com - High Integrity Systems also provide a safety 64 | engineered and independently SIL3 certified version for use in safety and 65 | mission critical applications that require provable dependability. 66 | 67 | 1 tab == 4 spaces! 68 | */ 69 | 70 | /*----------------------------------------------------------- 71 | * Portable layer API. Each function must be defined for each port. 72 | *----------------------------------------------------------*/ 73 | 74 | #ifndef PORTABLE_H 75 | #define PORTABLE_H 76 | 77 | /* Each FreeRTOS port has a unique portmacro.h header file. Originally a 78 | pre-processor definition was used to ensure the pre-processor found the correct 79 | portmacro.h file for the port being used. That scheme was deprecated in favour 80 | of setting the compiler's include path such that it found the correct 81 | portmacro.h file - removing the need for the constant and allowing the 82 | portmacro.h file to be located anywhere in relation to the port being used. 83 | Purely for reasons of backward compatibility the old method is still valid, but 84 | to make it clear that new projects should not use it, support for the port 85 | specific constants has been moved into the deprecated_definitions.h header 86 | file. */ 87 | //#include "deprecated_definitions.h" 88 | 89 | /* If portENTER_CRITICAL is not defined then including deprecated_definitions.h 90 | did not result in a portmacro.h header file being included - and it should be 91 | included here. In this case the path to the correct portmacro.h header file 92 | must be set in the compiler's include path. */ 93 | #ifndef portENTER_CRITICAL 94 | #include "portmacro.h" 95 | #endif 96 | 97 | #if portBYTE_ALIGNMENT == 32 98 | #define portBYTE_ALIGNMENT_MASK ( 0x001f ) 99 | #endif 100 | 101 | #if portBYTE_ALIGNMENT == 16 102 | #define portBYTE_ALIGNMENT_MASK ( 0x000f ) 103 | #endif 104 | 105 | #if portBYTE_ALIGNMENT == 8 106 | #define portBYTE_ALIGNMENT_MASK ( 0x0007 ) 107 | #endif 108 | 109 | #if portBYTE_ALIGNMENT == 4 110 | #define portBYTE_ALIGNMENT_MASK ( 0x0003 ) 111 | #endif 112 | 113 | #if portBYTE_ALIGNMENT == 2 114 | #define portBYTE_ALIGNMENT_MASK ( 0x0001 ) 115 | #endif 116 | 117 | #if portBYTE_ALIGNMENT == 1 118 | #define portBYTE_ALIGNMENT_MASK ( 0x0000 ) 119 | #endif 120 | 121 | #ifndef portBYTE_ALIGNMENT_MASK 122 | #error "Invalid portBYTE_ALIGNMENT definition" 123 | #endif 124 | 125 | #ifndef portNUM_CONFIGURABLE_REGIONS 126 | #define portNUM_CONFIGURABLE_REGIONS 1 127 | #endif 128 | 129 | #ifdef __cplusplus 130 | extern "C" { 131 | #endif 132 | 133 | #include "mpu_wrappers.h" 134 | 135 | /* 136 | * Setup the stack of a new task so it is ready to be placed under the 137 | * scheduler control. The registers have to be placed on the stack in 138 | * the order that the port expects to find them. 139 | * 140 | */ 141 | #if( portUSING_MPU_WRAPPERS == 1 ) 142 | StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters, BaseType_t xRunPrivileged ) PRIVILEGED_FUNCTION; 143 | #else 144 | StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters ) PRIVILEGED_FUNCTION; 145 | #endif 146 | 147 | /* Used by heap_5.c. */ 148 | typedef struct HeapRegion 149 | { 150 | uint8_t *pucStartAddress; 151 | size_t xSizeInBytes; 152 | } HeapRegion_t; 153 | 154 | /* 155 | * Used to define multiple heap regions for use by heap_5.c. This function 156 | * must be called before any calls to pvPortMalloc() - not creating a task, 157 | * queue, semaphore, mutex, software timer, event group, etc. will result in 158 | * pvPortMalloc being called. 159 | * 160 | * pxHeapRegions passes in an array of HeapRegion_t structures - each of which 161 | * defines a region of memory that can be used as the heap. The array is 162 | * terminated by a HeapRegions_t structure that has a size of 0. The region 163 | * with the lowest start address must appear first in the array. 164 | */ 165 | void vPortDefineHeapRegions( const HeapRegion_t * const pxHeapRegions ) PRIVILEGED_FUNCTION; 166 | 167 | 168 | /* 169 | * Map to the memory management routines required for the port. 170 | */ 171 | void *pvPortMalloc( size_t xSize ) PRIVILEGED_FUNCTION; 172 | void vPortFree( void *pv ) PRIVILEGED_FUNCTION; 173 | void vPortInitialiseBlocks( void ) PRIVILEGED_FUNCTION; 174 | size_t xPortGetFreeHeapSize( void ) PRIVILEGED_FUNCTION; 175 | size_t xPortGetMinimumEverFreeHeapSize( void ) PRIVILEGED_FUNCTION; 176 | 177 | /* 178 | * Setup the hardware ready for the scheduler to take control. This generally 179 | * sets up a tick interrupt and sets timers for the correct tick frequency. 180 | */ 181 | BaseType_t xPortStartScheduler( void ) PRIVILEGED_FUNCTION; 182 | 183 | /* 184 | * Undo any hardware/ISR setup that was performed by xPortStartScheduler() so 185 | * the hardware is left in its original condition after the scheduler stops 186 | * executing. 187 | */ 188 | void vPortEndScheduler( void ) PRIVILEGED_FUNCTION; 189 | 190 | /* 191 | * The structures and methods of manipulating the MPU are contained within the 192 | * port layer. 193 | * 194 | * Fills the xMPUSettings structure with the memory region information 195 | * contained in xRegions. 196 | */ 197 | #if( portUSING_MPU_WRAPPERS == 1 ) 198 | struct xMEMORY_REGION; 199 | void vPortStoreTaskMPUSettings( xMPU_SETTINGS *xMPUSettings, const struct xMEMORY_REGION * const xRegions, StackType_t *pxBottomOfStack, uint16_t usStackDepth ) PRIVILEGED_FUNCTION; 200 | #endif 201 | 202 | #ifdef __cplusplus 203 | } 204 | #endif 205 | 206 | #endif /* PORTABLE_H */ 207 | 208 | -------------------------------------------------------------------------------- /src/portmacro.h: -------------------------------------------------------------------------------- 1 | /* 2 | FreeRTOS V8.2.3 - Copyright (C) 2015 Real Time Engineers Ltd. 3 | All rights reserved 4 | 5 | VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. 6 | 7 | This file is part of the FreeRTOS distribution. 8 | 9 | FreeRTOS is free software; you can redistribute it and/or modify it under 10 | the terms of the GNU General Public License (version 2) as published by the 11 | Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception. 12 | 13 | *************************************************************************** 14 | >>! NOTE: The modification to the GPL is included to allow you to !<< 15 | >>! distribute a combined work that includes FreeRTOS without being !<< 16 | >>! obliged to provide the source code for proprietary components !<< 17 | >>! outside of the FreeRTOS kernel. !<< 18 | *************************************************************************** 19 | 20 | FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY 21 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 22 | FOR A PARTICULAR PURPOSE. Full license text is available on the following 23 | link: http://www.freertos.org/a00114.html 24 | 25 | *************************************************************************** 26 | * * 27 | * FreeRTOS provides completely free yet professionally developed, * 28 | * robust, strictly quality controlled, supported, and cross * 29 | * platform software that is more than just the market leader, it * 30 | * is the industry's de facto standard. * 31 | * * 32 | * Help yourself get started quickly while simultaneously helping * 33 | * to support the FreeRTOS project by purchasing a FreeRTOS * 34 | * tutorial book, reference manual, or both: * 35 | * http://www.FreeRTOS.org/Documentation * 36 | * * 37 | *************************************************************************** 38 | 39 | http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading 40 | the FAQ page "My application does not run, what could be wrong?". Have you 41 | defined configASSERT()? 42 | 43 | http://www.FreeRTOS.org/support - In return for receiving this top quality 44 | embedded software for free we request you assist our global community by 45 | participating in the support forum. 46 | 47 | http://www.FreeRTOS.org/training - Investing in training allows your team to 48 | be as productive as possible as early as possible. Now you can receive 49 | FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers 50 | Ltd, and the world's leading authority on the world's leading RTOS. 51 | 52 | http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, 53 | including FreeRTOS+Trace - an indispensable productivity tool, a DOS 54 | compatible FAT file system, and our tiny thread aware UDP/IP stack. 55 | 56 | http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate. 57 | Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS. 58 | 59 | http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High 60 | Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS 61 | licenses offer ticketed support, indemnification and commercial middleware. 62 | 63 | http://www.SafeRTOS.com - High Integrity Systems also provide a safety 64 | engineered and independently SIL3 certified version for use in safety and 65 | mission critical applications that require provable dependability. 66 | 67 | 1 tab == 4 spaces! 68 | */ 69 | 70 | /* 71 | Changes from V1.2.3 72 | 73 | + portCPU_CLOSK_HZ definition changed to 8MHz base 10, previously it 74 | base 16. 75 | */ 76 | 77 | #ifndef PORTMACRO_H 78 | #define PORTMACRO_H 79 | 80 | #ifdef __cplusplus 81 | extern "C" { 82 | #endif 83 | 84 | /*----------------------------------------------------------- 85 | * Port specific definitions. 86 | * 87 | * The settings in this file configure FreeRTOS correctly for the 88 | * given hardware and compiler. 89 | * 90 | * These settings should not be altered. 91 | *----------------------------------------------------------- 92 | */ 93 | 94 | /* Type definitions. */ 95 | #define portCHAR char 96 | #define portSTACK_TYPE uint8_t 97 | #define portBASE_TYPE char 98 | 99 | typedef portSTACK_TYPE StackType_t; 100 | typedef signed char BaseType_t; 101 | typedef unsigned char UBaseType_t; 102 | 103 | #if( configUSE_16_BIT_TICKS == 1 ) 104 | typedef uint16_t TickType_t; 105 | #define portMAX_DELAY ( TickType_t ) 0xffffU 106 | #else 107 | typedef uint32_t TickType_t; 108 | #define portMAX_DELAY ( TickType_t ) 0xffffffffUL 109 | #endif 110 | /*-----------------------------------------------------------*/ 111 | 112 | /* Critical section management. */ 113 | 114 | #define portENTER_CRITICAL() __asm__ __volatile__ ( \ 115 | "in __tmp_reg__, __SREG__" "\n\t" \ 116 | "cli" "\n\t" \ 117 | "push __tmp_reg__" "\n\t" \ 118 | ::: "memory" \ 119 | ) 120 | 121 | 122 | #define portEXIT_CRITICAL() __asm__ __volatile__ ( \ 123 | "pop __tmp_reg__" "\n\t" \ 124 | "out __SREG__, __tmp_reg__" "\n\t" \ 125 | ::: "memory" \ 126 | ) 127 | 128 | 129 | #define portDISABLE_INTERRUPTS() __asm__ __volatile__ ( "cli" ::: "memory") 130 | #define portENABLE_INTERRUPTS() __asm__ __volatile__ ( "sei" ::: "memory") 131 | 132 | /*-----------------------------------------------------------*/ 133 | /** 134 | Enable the watchdog timer, configuring it for expire after 135 | (value) timeout (which is a combination of the WDP0 136 | through WDP3 bits). 137 | 138 | This function is derived from but enables only 139 | the interrupt bit (WDIE), rather than the reset bit (WDE). 140 | 141 | Can't find it documented but the WDT, once enabled, 142 | rolls over and fires a new interrupt each time. 143 | 144 | See also the symbolic constants WDTO_15MS et al. 145 | */ 146 | #define wdt_interrupt_enable(value) \ 147 | __asm__ __volatile__ ( \ 148 | "in __tmp_reg__,__SREG__" "\n\t" \ 149 | "cli" "\n\t" \ 150 | "wdr" "\n\t" \ 151 | "sts %0,%1" "\n\t" \ 152 | "out __SREG__,__tmp_reg__" "\n\t" \ 153 | "sts %0,%2" "\n\t" \ 154 | : /* no outputs */ \ 155 | : "M" (_SFR_MEM_ADDR(_WD_CONTROL_REG)), \ 156 | "r" (_BV(_WD_CHANGE_BIT) | _BV(WDE)), \ 157 | "r" ((uint8_t) ((value & 0x08 ? _WD_PS3_MASK : 0x00) | \ 158 | _BV(WDIF) | _BV(WDIE) | (value & 0x07)) ) \ 159 | : "r0" \ 160 | ) 161 | 162 | /*-----------------------------------------------------------*/ 163 | /** 164 | Enable the watchdog timer, configuring it for expire after 165 | (value) timeout (which is a combination of the WDP0 166 | through WDP3 bits). 167 | 168 | This function is derived from but enables both 169 | the reset bit (WDE), and the interrupt bit (WDIE). 170 | 171 | This will ensure that if the interrupt is not serviced 172 | before the second timeout, the AVR will reset. 173 | 174 | Servicing the interrupt automatically clears it, 175 | and ensures the AVR does not reset. 176 | 177 | Can't find it documented but the WDT, once enabled, 178 | rolls over and fires a new interrupt each time. 179 | 180 | See also the symbolic constants WDTO_15MS et al. 181 | */ 182 | #define wdt_interrupt_reset_enable(value) \ 183 | __asm__ __volatile__ \ 184 | "in __tmp_reg__,__SREG__" "\n\t" \ 185 | "cli" "\n\t" \ 186 | "wdr" "\n\t" \ 187 | "sts %0,%1" "\n\t" \ 188 | "out __SREG__,__tmp_reg__" "\n\t" \ 189 | "sts %0,%2" "\n\t" \ 190 | : /* no outputs */ \ 191 | : "M" (_SFR_MEM_ADDR(_WD_CONTROL_REG)), \ 192 | "r" (_BV(_WD_CHANGE_BIT) | _BV(WDE)), \ 193 | "r" ((uint8_t) ((value & 0x08 ? _WD_PS3_MASK : 0x00) | \ 194 | _BV(WDIF) | _BV(WDIE) | _BV(WDE) | (value & 0x07)) ) \ 195 | : "r0" \ 196 | ) 197 | 198 | /*-----------------------------------------------------------*/ 199 | 200 | /* Architecture specifics. */ 201 | #define portSTACK_GROWTH ( -1 ) 202 | #define portBYTE_ALIGNMENT 1 203 | #define portNOP() __asm__ __volatile__ ( "nop" ); 204 | 205 | #define sleep_reset() do { _SLEEP_CONTROL_REG = 0; } while(0) // reset all sleep_mode() configurations. 206 | 207 | /* Timing for the scheduler. 208 | * Watchdog Timer is 128kHz nominal, 209 | * but 120 kHz at 5V DC and 25 degrees is actually more accurate, 210 | * from data sheet. 211 | */ 212 | #define portTICK_PERIOD_MS ( (TickType_t) _BV( portUSE_WDTO + 4 ) ) // Inaccurately assuming 128 kHz Watchdog Timer. 213 | // #define portTICK_PERIOD_MS ( (TickType_t)( (uint32_t) _BV( portUSE_WDTO + 11 ) / 128 ) ) // If you want accuracy, read datasheet. 214 | 215 | /*-----------------------------------------------------------*/ 216 | 217 | /* Kernel utilities. */ 218 | extern void vPortYield( void ) __attribute__ ( ( naked ) ); 219 | #define portYIELD() vPortYield() 220 | 221 | /*-----------------------------------------------------------*/ 222 | 223 | #if defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) 224 | /* Task function macros as described on the FreeRTOS.org WEB site. */ 225 | // This changed to add .lowtext tag for the linker for ATmega2560 and ATmega2561. To make sure they are loaded in low memory. 226 | #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters ) __attribute__ ((section (".lowtext"))) 227 | #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters ) 228 | 229 | #else 230 | #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters ) 231 | #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters ) 232 | 233 | #endif 234 | 235 | 236 | 237 | #ifdef __cplusplus 238 | } 239 | #endif 240 | 241 | #endif /* PORTMACRO_H */ 242 | 243 | -------------------------------------------------------------------------------- /src/projdefs.h: -------------------------------------------------------------------------------- 1 | /* 2 | FreeRTOS V8.2.3 - Copyright (C) 2015 Real Time Engineers Ltd. 3 | All rights reserved 4 | 5 | VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. 6 | 7 | This file is part of the FreeRTOS distribution. 8 | 9 | FreeRTOS is free software; you can redistribute it and/or modify it under 10 | the terms of the GNU General Public License (version 2) as published by the 11 | Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception. 12 | 13 | *************************************************************************** 14 | >>! NOTE: The modification to the GPL is included to allow you to !<< 15 | >>! distribute a combined work that includes FreeRTOS without being !<< 16 | >>! obliged to provide the source code for proprietary components !<< 17 | >>! outside of the FreeRTOS kernel. !<< 18 | *************************************************************************** 19 | 20 | FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY 21 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 22 | FOR A PARTICULAR PURPOSE. Full license text is available on the following 23 | link: http://www.freertos.org/a00114.html 24 | 25 | *************************************************************************** 26 | * * 27 | * FreeRTOS provides completely free yet professionally developed, * 28 | * robust, strictly quality controlled, supported, and cross * 29 | * platform software that is more than just the market leader, it * 30 | * is the industry's de facto standard. * 31 | * * 32 | * Help yourself get started quickly while simultaneously helping * 33 | * to support the FreeRTOS project by purchasing a FreeRTOS * 34 | * tutorial book, reference manual, or both: * 35 | * http://www.FreeRTOS.org/Documentation * 36 | * * 37 | *************************************************************************** 38 | 39 | http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading 40 | the FAQ page "My application does not run, what could be wrong?". Have you 41 | defined configASSERT()? 42 | 43 | http://www.FreeRTOS.org/support - In return for receiving this top quality 44 | embedded software for free we request you assist our global community by 45 | participating in the support forum. 46 | 47 | http://www.FreeRTOS.org/training - Investing in training allows your team to 48 | be as productive as possible as early as possible. Now you can receive 49 | FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers 50 | Ltd, and the world's leading authority on the world's leading RTOS. 51 | 52 | http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, 53 | including FreeRTOS+Trace - an indispensable productivity tool, a DOS 54 | compatible FAT file system, and our tiny thread aware UDP/IP stack. 55 | 56 | http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate. 57 | Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS. 58 | 59 | http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High 60 | Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS 61 | licenses offer ticketed support, indemnification and commercial middleware. 62 | 63 | http://www.SafeRTOS.com - High Integrity Systems also provide a safety 64 | engineered and independently SIL3 certified version for use in safety and 65 | mission critical applications that require provable dependability. 66 | 67 | 1 tab == 4 spaces! 68 | */ 69 | 70 | #ifndef PROJDEFS_H 71 | #define PROJDEFS_H 72 | 73 | /* 74 | * Defines the prototype to which task functions must conform. Defined in this 75 | * file to ensure the type is known before portable.h is included. 76 | */ 77 | typedef void (*TaskFunction_t)( void * ); 78 | 79 | /* Converts a time in milliseconds to a time in ticks. */ 80 | #define pdMS_TO_TICKS( xTimeInMs ) ( ( TickType_t ) ( ( ( TickType_t ) ( xTimeInMs ) * ( TickType_t ) configTICK_RATE_HZ ) / ( TickType_t ) 1000 ) ) 81 | 82 | #define pdFALSE ( ( BaseType_t ) 0 ) 83 | #define pdTRUE ( ( BaseType_t ) 1 ) 84 | 85 | #define pdPASS ( pdTRUE ) 86 | #define pdFAIL ( pdFALSE ) 87 | #define errQUEUE_EMPTY ( ( BaseType_t ) 0 ) 88 | #define errQUEUE_FULL ( ( BaseType_t ) 0 ) 89 | 90 | /* FreeRTOS error definitions. */ 91 | #define errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY ( -1 ) 92 | #define errQUEUE_BLOCKED ( -4 ) 93 | #define errQUEUE_YIELD ( -5 ) 94 | 95 | /* Macros used for basic data corruption checks. */ 96 | #ifndef configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES 97 | #define configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES 0 98 | #endif 99 | 100 | #if( configUSE_16_BIT_TICKS == 1 ) 101 | #define pdINTEGRITY_CHECK_VALUE 0x5a5a 102 | #else 103 | #define pdINTEGRITY_CHECK_VALUE 0x5a5a5a5aUL 104 | #endif 105 | 106 | /* The following errno values are used by FreeRTOS+ components, not FreeRTOS 107 | itself. */ 108 | #define pdFREERTOS_ERRNO_NONE 0 /* No errors */ 109 | #define pdFREERTOS_ERRNO_ENOENT 2 /* No such file or directory */ 110 | #define pdFREERTOS_ERRNO_EIO 5 /* I/O error */ 111 | #define pdFREERTOS_ERRNO_ENXIO 6 /* No such device or address */ 112 | #define pdFREERTOS_ERRNO_EBADF 9 /* Bad file number */ 113 | #define pdFREERTOS_ERRNO_EAGAIN 11 /* No more processes */ 114 | #define pdFREERTOS_ERRNO_EWOULDBLOCK 11 /* Operation would block */ 115 | #define pdFREERTOS_ERRNO_ENOMEM 12 /* Not enough memory */ 116 | #define pdFREERTOS_ERRNO_EACCES 13 /* Permission denied */ 117 | #define pdFREERTOS_ERRNO_EFAULT 14 /* Bad address */ 118 | #define pdFREERTOS_ERRNO_EBUSY 16 /* Mount device busy */ 119 | #define pdFREERTOS_ERRNO_EEXIST 17 /* File exists */ 120 | #define pdFREERTOS_ERRNO_EXDEV 18 /* Cross-device link */ 121 | #define pdFREERTOS_ERRNO_ENODEV 19 /* No such device */ 122 | #define pdFREERTOS_ERRNO_ENOTDIR 20 /* Not a directory */ 123 | #define pdFREERTOS_ERRNO_EISDIR 21 /* Is a directory */ 124 | #define pdFREERTOS_ERRNO_EINVAL 22 /* Invalid argument */ 125 | #define pdFREERTOS_ERRNO_ENOSPC 28 /* No space left on device */ 126 | #define pdFREERTOS_ERRNO_ESPIPE 29 /* Illegal seek */ 127 | #define pdFREERTOS_ERRNO_EROFS 30 /* Read only file system */ 128 | #define pdFREERTOS_ERRNO_EUNATCH 42 /* Protocol driver not attached */ 129 | #define pdFREERTOS_ERRNO_EBADE 50 /* Invalid exchange */ 130 | #define pdFREERTOS_ERRNO_EFTYPE 79 /* Inappropriate file type or format */ 131 | #define pdFREERTOS_ERRNO_ENMFILE 89 /* No more files */ 132 | #define pdFREERTOS_ERRNO_ENOTEMPTY 90 /* Directory not empty */ 133 | #define pdFREERTOS_ERRNO_ENAMETOOLONG 91 /* File or path name too long */ 134 | #define pdFREERTOS_ERRNO_EOPNOTSUPP 95 /* Operation not supported on transport endpoint */ 135 | #define pdFREERTOS_ERRNO_ENOBUFS 105 /* No buffer space available */ 136 | #define pdFREERTOS_ERRNO_ENOPROTOOPT 109 /* Protocol not available */ 137 | #define pdFREERTOS_ERRNO_EADDRINUSE 112 /* Address already in use */ 138 | #define pdFREERTOS_ERRNO_ETIMEDOUT 116 /* Connection timed out */ 139 | #define pdFREERTOS_ERRNO_EINPROGRESS 119 /* Connection already in progress */ 140 | #define pdFREERTOS_ERRNO_EALREADY 120 /* Socket already connected */ 141 | #define pdFREERTOS_ERRNO_EADDRNOTAVAIL 125 /* Address not available */ 142 | #define pdFREERTOS_ERRNO_EISCONN 127 /* Socket is already connected */ 143 | #define pdFREERTOS_ERRNO_ENOTCONN 128 /* Socket is not connected */ 144 | #define pdFREERTOS_ERRNO_ENOMEDIUM 135 /* No medium inserted */ 145 | #define pdFREERTOS_ERRNO_EILSEQ 138 /* An invalid UTF-16 sequence was encountered. */ 146 | #define pdFREERTOS_ERRNO_ECANCELED 140 /* Operation canceled. */ 147 | 148 | /* The following endian values are used by FreeRTOS+ components, not FreeRTOS 149 | itself. */ 150 | #define pdFREERTOS_LITTLE_ENDIAN 0 151 | #define pdFREERTOS_BIG_ENDIAN 1 152 | 153 | #endif /* PROJDEFS_H */ 154 | 155 | 156 | 157 | -------------------------------------------------------------------------------- /src/variantHooks.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | FreeRTOS V8.2.3 - This file is NOT part of the FreeRTOS distribution. 3 | 4 | FreeRTOS is free software; you can redistribute it and/or modify it under 5 | the terms of the GNU General Public License (version 2) as published by the 6 | Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception. 7 | 8 | *************************************************************************** 9 | >>! NOTE: The modification to the GPL is included to allow you to !<< 10 | >>! distribute a combined work that includes FreeRTOS without being !<< 11 | >>! obliged to provide the source code for proprietary components !<< 12 | >>! outside of the FreeRTOS kernel. !<< 13 | *************************************************************************** 14 | 15 | FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 17 | FOR A PARTICULAR PURPOSE. Full license text is available on the following 18 | link: http://www.freertos.org/a00114.html 19 | 20 | *************************************************************************** 21 | * * 22 | * FreeRTOS provides completely free yet professionally developed, * 23 | * robust, strictly quality controlled, supported, and cross * 24 | * platform software that is more than just the market leader, it * 25 | * is the industry's de facto standard. * 26 | * * 27 | * Help yourself get started quickly while simultaneously helping * 28 | * to support the FreeRTOS project by purchasing a FreeRTOS * 29 | * tutorial book, reference manual, or both: * 30 | * http://www.FreeRTOS.org/Documentation * 31 | * * 32 | *************************************************************************** 33 | 34 | http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading 35 | the FAQ page "My application does not run, what could be wrong?". Have you 36 | defined configASSERT()? 37 | 38 | http://www.FreeRTOS.org/support - In return for receiving this top quality 39 | embedded software for free we request you assist our global community by 40 | participating in the support forum. 41 | 42 | http://www.FreeRTOS.org/training - Investing in training allows your team to 43 | be as productive as possible as early as possible. Now you can receive 44 | FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers 45 | Ltd, and the world's leading authority on the world's leading RTOS. 46 | 47 | http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, 48 | including FreeRTOS+Trace - an indispensable productivity tool, a DOS 49 | compatible FAT file system, and our tiny thread aware UDP/IP stack. 50 | 51 | http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate. 52 | Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS. 53 | 54 | http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High 55 | Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS 56 | licenses offer ticketed support, indemnification and commercial middleware. 57 | 58 | http://www.SafeRTOS.com - High Integrity Systems also provide a safety 59 | engineered and independently SIL3 certified version for use in safety and 60 | mission critical applications that require provable dependability. 61 | 62 | 1 tab == 4 spaces! 63 | */ 64 | 65 | #include 66 | #include 67 | #include 68 | 69 | #include 70 | 71 | #include 72 | 73 | /* FreeRTOS includes. */ 74 | #include "Arduino_FreeRTOS.h" 75 | #include "task.h" 76 | #include "timers.h" 77 | 78 | extern void setup(void); 79 | extern void loop(void); 80 | 81 | /*-----------------------------------------------------------*/ 82 | 83 | void initVariant(void) __attribute__ ((flatten, OS_main)); 84 | void initVariant(void) 85 | { 86 | #if defined(USBCON) 87 | USBDevice.attach(); 88 | #endif 89 | 90 | setup(); // the normal Arduino setup() function is run here. 91 | 92 | vTaskStartScheduler(); // initialise and run the freeRTOS scheduler. Execution should never return here. 93 | 94 | vApplicationMallocFailedHook(); // Probably we've failed trying to initialise heap for the scheduler. Let someone know. 95 | } 96 | 97 | 98 | /*-----------------------------------------------------------*/ 99 | #if ( configUSE_IDLE_HOOK == 1 ) 100 | /* 101 | * Call the user defined loop() function from within the idle task. 102 | * This allows the application designer to add background functionality 103 | * without the overhead of a separate task. 104 | * 105 | * NOTE: vApplicationIdleHook() MUST NOT, UNDER ANY CIRCUMSTANCES, CALL A FUNCTION THAT MIGHT BLOCK. 106 | * 107 | */ 108 | void vApplicationIdleHook( void ) __attribute__((weak)); 109 | 110 | void vApplicationIdleHook( void ) 111 | { 112 | loop(); // the normal Arduino loop() function is run here. 113 | if (serialEventRun) serialEventRun(); 114 | } 115 | 116 | #endif /* configUSE_IDLE_HOOK == 1 */ 117 | /*-----------------------------------------------------------*/ 118 | 119 | 120 | #if ( configUSE_MALLOC_FAILED_HOOK == 1 ) 121 | /*---------------------------------------------------------------------------*\ 122 | Usage: 123 | called by task system when a malloc failure is noticed 124 | Description: 125 | Malloc failure handler -- Shut down all interrupts, send serious complaint 126 | to command port. FAST Blink on main LED. 127 | Arguments: 128 | pxTask - pointer to task handle 129 | pcTaskName - pointer to task name 130 | Results: 131 | 132 | Notes: 133 | This routine will never return. 134 | This routine is referenced in the task.c file of FreeRTOS as an extern. 135 | \*---------------------------------------------------------------------------*/ 136 | void vApplicationMallocFailedHook( void ) __attribute__((weak)); 137 | 138 | void vApplicationMallocFailedHook( void ) 139 | { 140 | #if defined(__AVR_ATmega640__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) // Arduino Mega with 2560 141 | DDRB |= _BV(DDB7); 142 | PORTB |= _BV(PORTB7); // Main (red PB7) LED on. Main LED on. 143 | 144 | #elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega1284PA__) // Seeed Goldilocks with 1284p 145 | DDRB |= _BV(DDB7); 146 | PORTB |= _BV(PORTB7); // Main (red PB7) LED on. Main LED on. 147 | 148 | #elif defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__) || defined(__AVR_ATmega8__) // assume we're using an Arduino Uno with 328p 149 | DDRB |= _BV(DDB5); 150 | PORTB |= _BV(PORTB5); // Main (red PB5) LED on. Main LED on. 151 | 152 | #elif defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega16U4__) // assume we're using an Arduino Leonardo with 32u4 153 | DDRC |= _BV(DDC7); 154 | PORTC |= _BV(PORTC7); // Main (red PC7) LED on. Main LED on. 155 | 156 | #endif 157 | 158 | for(;;) 159 | { 160 | _delay_ms(50); 161 | loop(); 162 | 163 | #if defined(__AVR_ATmega640__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) // Mega with 2560 164 | PINB |= _BV(PINB7); // Main (red PB7) LED toggle. Main LED fast blink. 165 | 166 | #elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega1284PA__) // Seeed Goldilocks with 1284p 167 | PINB |= _BV(PINB7); // Main (red PB7) LED toggle. Main LED fast blink. 168 | 169 | #elif defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__) || defined(__AVR_ATmega8__) // assume we're using an Arduino Uno with 328p 170 | PINB |= _BV(PINB5); // Main (red PB5) LED toggle. Main LED fast blink. 171 | 172 | #elif defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega16U4__) // assume we're using an Arduino Leonardo with 32u4 173 | PINC |= _BV(PINC7); // Main (red PC7) LED toggle. Main LED fast blink. 174 | 175 | #endif 176 | 177 | } 178 | } 179 | 180 | #endif /* configUSE_MALLOC_FAILED_HOOK == 1 */ 181 | /*-----------------------------------------------------------*/ 182 | 183 | 184 | #if ( configCHECK_FOR_STACK_OVERFLOW == 1 ) 185 | /*---------------------------------------------------------------------------*\ 186 | Usage: 187 | called by task system when a stack overflow is noticed 188 | Description: 189 | Stack overflow handler -- Shut down all interrupts, send serious complaint 190 | to command port. SLOW Blink on main LED. 191 | Arguments: 192 | pxTask - pointer to task handle 193 | pcTaskName - pointer to task name 194 | Results: 195 | 196 | Notes: 197 | This routine will never return. 198 | This routine is referenced in the task.c file of FreeRTOS as an extern. 199 | \*---------------------------------------------------------------------------*/ 200 | void vApplicationStackOverflowHook( TaskHandle_t xTask, portCHAR *pcTaskName ) __attribute__((weak)); 201 | 202 | void vApplicationStackOverflowHook( TaskHandle_t xTask __attribute__((unused)), portCHAR *pcTaskName __attribute__((unused)) ) 203 | { 204 | #if defined(__AVR_ATmega640__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) // Arduino Mega with 2560 205 | DDRB |= _BV(DDB7); 206 | PORTB |= _BV(PORTB7); // Main (red PB7) LED on. Main LED on. 207 | 208 | #elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega1284PA__) // Seeed Goldilocks with 1284p 209 | DDRB |= _BV(DDB7); 210 | PORTB |= _BV(PORTB7); // Main (red PB7) LED on. Main LED on. 211 | 212 | #elif defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__) || defined(__AVR_ATmega8__) // assume we're using an Arduino Uno with 328p 213 | DDRB |= _BV(DDB5); 214 | PORTB |= _BV(PORTB5); // Main (red PB5) LED on. Main LED on. 215 | 216 | #elif defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega16U4__) // assume we're using an Arduino Leonardo with 32u4 217 | DDRC |= _BV(DDC7); 218 | PORTC |= _BV(PORTC7); // Main (red PC7) LED on. Main LED on. 219 | 220 | #endif 221 | 222 | for(;;) 223 | { 224 | _delay_ms(2000); 225 | 226 | #if defined(__AVR_ATmega640__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) // Arduino Mega with 2560 227 | PINB |= _BV(PINB7); // Main (red PB7) LED toggle. Main LED slow blink. 228 | 229 | #elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega1284PA__) // Seeed Goldilocks with 1284p 230 | PINB |= _BV(PINB7); // Main (red PB7) LED toggle. Main LED slow blink. 231 | 232 | #elif defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__) || defined(__AVR_ATmega8__) // assume we're using an Arduino Uno with 328p 233 | PINB |= _BV(PINB5); // Main (red PB5) LED toggle. Main LED slow blink. 234 | 235 | #elif defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega16U4__) // assume we're using an Arduino Leonardo with 32u4 236 | PINC |= _BV(PINC7); // Main (red PC7) LED toggle. Main LED slow blink. 237 | 238 | #endif 239 | 240 | } 241 | } 242 | 243 | #endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */ 244 | /*-----------------------------------------------------------*/ 245 | --------------------------------------------------------------------------------