├── sw ├── Barebone-Echo │ ├── Makefile │ └── echo.c ├── Barebone-Hello │ ├── Makefile │ └── hello.c ├── Barebone-Timer │ ├── Makefile │ ├── timer.c │ └── isr.S ├── Lab1 │ ├── Makefile │ ├── freertos_risc_v_trap.c │ ├── main.c │ └── FreeRTOSConfig.h ├── Lab2 │ ├── run.sh │ ├── Makefile │ ├── freertos_risc_v_trap.c │ ├── main.c │ ├── FreeRTOSConfig.h │ └── task.h.txt ├── Lab3 │ ├── Makefile │ ├── freertos_risc_v_trap.c │ ├── main.c │ └── FreeRTOSConfig.h ├── FreeRTOS-Demo-Hello │ ├── Makefile │ ├── hello.c │ └── FreeRTOSConfig.h ├── drivers │ ├── mmap_regs.h │ ├── mmio.h │ ├── uart.h │ ├── uart.c │ ├── gpio.h │ └── gpio.c └── common │ ├── common.h │ ├── common.c │ ├── link.ld │ ├── crt0.S │ ├── barebone.mk │ ├── freertos_risc_v_chip_specific_extensions.h │ └── freertos.mk ├── .gitmodules ├── .gitignore ├── LICENSE ├── pynq_z2 └── ps │ └── ibex_ctrl.ipynb └── README.md /sw/Barebone-Echo/Makefile: -------------------------------------------------------------------------------- 1 | PROGRAM := Barebone-Echo 2 | 3 | ASFLAGS := -DDEFAULT_TRAP_HANDLER=simple_trap_handler 4 | 5 | include ../common/barebone.mk 6 | -------------------------------------------------------------------------------- /sw/Barebone-Hello/Makefile: -------------------------------------------------------------------------------- 1 | PROGRAM := Barebone-Hello 2 | 3 | ASFLAGS := -DDEFAULT_TRAP_HANDLER=simple_trap_handler 4 | 5 | include ../common/barebone.mk 6 | -------------------------------------------------------------------------------- /sw/Barebone-Timer/Makefile: -------------------------------------------------------------------------------- 1 | PROGRAM := Barebone-Timer 2 | 3 | ASFLAGS := -DDEFAULT_TRAP_HANDLER=timer_interrupt_handler 4 | 5 | include ../common/barebone.mk 6 | -------------------------------------------------------------------------------- /sw/Barebone-Hello/hello.c: -------------------------------------------------------------------------------- 1 | #include "printf.h" 2 | #include "uart.h" 3 | 4 | int main() 5 | { 6 | uart_init(); 7 | for (;;) { 8 | printf("Hello!\n"); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /sw/Lab1/Makefile: -------------------------------------------------------------------------------- 1 | # define the program name 2 | PROGRAM := Lab1 3 | 4 | # set trap handlers 5 | ASFLAGS := -DDEFAULT_TRAP_HANDLER=freertos_risc_v_trap_handler 6 | 7 | include ../common/freertos.mk 8 | -------------------------------------------------------------------------------- /sw/Lab2/run.sh: -------------------------------------------------------------------------------- 1 | make clean 2 | 3 | cp task.h.txt ../FreeRTOS/include/task.h 4 | cp tasks.c.txt ../FreeRTOS/tasks.c 5 | 6 | make 7 | 8 | cd ../FreeRTOS/ 9 | git reset --hard HEAD 10 | 11 | -------------------------------------------------------------------------------- /sw/Lab3/Makefile: -------------------------------------------------------------------------------- 1 | # define the program name 2 | PROGRAM := Lab3 3 | 4 | # set trap handlers 5 | ASFLAGS := -DDEFAULT_TRAP_HANDLER=freertos_risc_v_trap_handler 6 | 7 | include ../common/freertos.mk 8 | -------------------------------------------------------------------------------- /sw/Lab2/Makefile: -------------------------------------------------------------------------------- 1 | # define the program name 2 | PROGRAM := Lab2 3 | 4 | # set trap handlers 5 | ASFLAGS := -DDEFAULT_TRAP_HANDLER=freertos_risc_v_trap_handler -specs=nosys.specs 6 | 7 | include ../common/freertos.mk 8 | -------------------------------------------------------------------------------- /sw/FreeRTOS-Demo-Hello/Makefile: -------------------------------------------------------------------------------- 1 | # define the program name 2 | PROGRAM := FreeRTOS-Demo-Hello 3 | 4 | # set trap handlers 5 | ASFLAGS := -DDEFAULT_TRAP_HANDLER=freertos_risc_v_trap_handler 6 | 7 | include ../common/freertos.mk 8 | -------------------------------------------------------------------------------- /sw/drivers/mmap_regs.h: -------------------------------------------------------------------------------- 1 | #ifndef DRIVERS_MMAP_REGS_H_ 2 | #define DRIVERS_MMAP_REGS_H_ 3 | 4 | // GPIO 5 | #define GPIO_BASE 0x41200000 6 | 7 | // UART 8 | #define UART_BASE 0x42c00000 9 | 10 | #endif // DRIVERS_MMAP_REGS_H_ 11 | -------------------------------------------------------------------------------- /sw/common/common.h: -------------------------------------------------------------------------------- 1 | #ifndef COMMON_COMMON_H_ 2 | #define COMMON_COMMON_H_ 3 | 4 | // wrapper function to get CSR values 5 | unsigned int get_mepc(); 6 | unsigned int get_mcause(); 7 | unsigned int get_mtval(); 8 | 9 | #endif // COMMON_COMMON_H_ 10 | -------------------------------------------------------------------------------- /sw/drivers/mmio.h: -------------------------------------------------------------------------------- 1 | #ifndef DRIVERS_MMIO_H_ 2 | #define DRIVERS_MMIO_H_ 3 | 4 | #include 5 | 6 | #define MMIO_WRITE(addr, val) (*((volatile uint32_t *)(addr)) = val) 7 | #define MMIO_READ(addr) (*((volatile uint32_t *)(addr))) 8 | 9 | #endif // DRIVERS_MMIO_H_ 10 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "pynq_z2/pl"] 2 | path = pynq_z2/pl 3 | url = https://github.com/choucl/Ibex_AXI.git 4 | [submodule "sw/FreeRTOS"] 5 | path = sw/FreeRTOS 6 | url = https://github.com/FreeRTOS/FreeRTOS-Kernel.git 7 | [submodule "sw/printf"] 8 | path = sw/printf 9 | url = https://github.com/mpaland/printf.git 10 | -------------------------------------------------------------------------------- /sw/drivers/uart.h: -------------------------------------------------------------------------------- 1 | #ifndef DRIVERS_UART_H_ 2 | #define DRIVERS_UART_H_ 3 | 4 | #define UART_RX_FIFO 0x0 5 | #define UART_TX_FIFO 0x4 6 | #define UART_STAT_REG 0x8 7 | #define UART_CTRL_REG 0xc 8 | 9 | void uart_init(); 10 | 11 | void uart_putchar(char c); 12 | 13 | int uart_getchar(); 14 | 15 | #endif // DRIVERS_UART_H_ 16 | -------------------------------------------------------------------------------- /sw/Barebone-Echo/echo.c: -------------------------------------------------------------------------------- 1 | #include "printf.h" 2 | #include "uart.h" 3 | #include "mmio.h" 4 | 5 | void readline(char *buf) 6 | { 7 | char c; 8 | for (;;) { 9 | c = uart_getchar(); 10 | *(buf++) = c; 11 | 12 | // check if `return` is pressed 13 | if (c == 13) { 14 | *buf = 0; 15 | break; 16 | } 17 | } 18 | } 19 | 20 | int main() 21 | { 22 | uart_init(); 23 | for (;;) { 24 | char buf[128]; 25 | printf("Enter: "); 26 | readline(buf); 27 | printf("You entered: %s\n", buf); 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /sw/Lab1/freertos_risc_v_trap.c: -------------------------------------------------------------------------------- 1 | #include "FreeRTOS.h" 2 | #include "printf.h" 3 | 4 | /* 5 | * Application exception handler for FreeRTOS 6 | */ 7 | void freertos_risc_v_application_exception_handler( uint32_t cause ) 8 | { 9 | printf("Application Exception Handler Called By FreeRTOS!!!\n"); 10 | printf("MCAUSE: 0x%x\n", cause); 11 | return; 12 | } 13 | 14 | /* 15 | * Application interrupt handler for FreeRTOS 16 | */ 17 | void freertos_risc_v_application_interrupt_handler( uint32_t cause ) 18 | { 19 | printf("Application Interrupt Handler Called By FreeRTOS!!!\n"); 20 | printf("MCAUSE: 0x%x\n", cause); 21 | return; 22 | } 23 | -------------------------------------------------------------------------------- /sw/Lab2/freertos_risc_v_trap.c: -------------------------------------------------------------------------------- 1 | #include "FreeRTOS.h" 2 | #include "printf.h" 3 | 4 | /* 5 | * Application exception handler for FreeRTOS 6 | */ 7 | void freertos_risc_v_application_exception_handler( uint32_t cause ) 8 | { 9 | printf("Application Exception Handler Called By FreeRTOS!!!\n"); 10 | printf("MCAUSE: 0x%x\n", cause); 11 | return; 12 | } 13 | 14 | /* 15 | * Application interrupt handler for FreeRTOS 16 | */ 17 | void freertos_risc_v_application_interrupt_handler( uint32_t cause ) 18 | { 19 | printf("Application Interrupt Handler Called By FreeRTOS!!!\n"); 20 | printf("MCAUSE: 0x%x\n", cause); 21 | return; 22 | } 23 | -------------------------------------------------------------------------------- /sw/drivers/uart.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "mmap_regs.h" 4 | #include "mmio.h" 5 | #include "uart.h" 6 | 7 | void uart_init() 8 | { 9 | // reset rx and tx fifo 10 | uint32_t data = 0b00011; 11 | MMIO_WRITE(UART_BASE + UART_CTRL_REG, data); 12 | } 13 | 14 | void uart_putchar(char c) 15 | { 16 | // busy waiting until tx fifo has room 17 | while ((MMIO_READ(UART_BASE + UART_STAT_REG) >> 3) & 0b1); 18 | MMIO_WRITE(UART_BASE + UART_TX_FIFO, c); 19 | } 20 | 21 | int uart_getchar() 22 | { 23 | // busy waiting until rx fifo has data to read 24 | while ((MMIO_READ(UART_BASE + UART_STAT_REG) & 0b1) == 0); 25 | return MMIO_READ(UART_BASE + UART_RX_FIFO); 26 | } 27 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Object files 5 | *.o 6 | *.ko 7 | *.obj 8 | *.elf 9 | 10 | # Binary files 11 | *.bin 12 | 13 | # Disassembly files 14 | *.dis 15 | 16 | # Linker output 17 | *.ilk 18 | *.map 19 | *.exp 20 | 21 | # Precompiled Headers 22 | *.gch 23 | *.pch 24 | 25 | # Libraries 26 | *.lib 27 | *.a 28 | *.la 29 | *.lo 30 | 31 | # Shared objects (inc. Windows DLLs) 32 | *.dll 33 | *.so 34 | *.so.* 35 | *.dylib 36 | 37 | # Executables 38 | *.exe 39 | *.out 40 | *.app 41 | *.i*86 42 | *.x86_64 43 | *.hex 44 | 45 | # Debug files 46 | *.dSYM/ 47 | *.su 48 | *.idb 49 | *.pdb 50 | 51 | # Kernel Module Compile Results 52 | *.mod* 53 | *.cmd 54 | .tmp_versions/ 55 | modules.order 56 | Module.symvers 57 | Mkfile.old 58 | dkms.conf 59 | 60 | # fusesoc 61 | fusesoc_libraries 62 | fusesoc.conf 63 | build 64 | -------------------------------------------------------------------------------- /sw/drivers/gpio.h: -------------------------------------------------------------------------------- 1 | #ifndef DRIVERS_GPIO_H_ 2 | #define DRIVERS_GPIO_H_ 3 | 4 | #include 5 | 6 | // GPIO is configured as output by default 7 | #define GPIO_DATA 0x0000 8 | #define GPIO_TRI 0x0004 9 | 10 | // GPIO2 is configured as input by default 11 | #define GPIO2_DATA 0x0008 12 | #define GPIO2_TRI 0x000c 13 | 14 | // GPIO tri-state control 15 | #define GPIO_INPUT -1 16 | #define GPIO_OUTPUT 0 17 | 18 | // Configure GPIO as output and GPIO2 as input 19 | void gpio_init(); 20 | 21 | // General method to read the value from `gpio` register 22 | uint32_t gpio_read(void *gpio); 23 | 24 | // General method to write the value to `gpio` register 25 | void gpio_write(void *gpio, uint32_t data); 26 | 27 | // Read a pin value from GPIO2 28 | uint32_t gpio_read_pin(uint32_t pin); 29 | 30 | // Write a pin value to GPIO 31 | void gpio_write_pin(uint32_t pin, uint32_t val); 32 | 33 | // Toggle a pin value to GPIO 34 | void gpio_toggle_pin(uint32_t pin); 35 | 36 | #endif // DRIVERS_GPIO_H_ 37 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Yu-Yu Hsiao, Liang-Chou Chen, and Bo-Wei Lin 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /sw/common/common.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "uart.h" 4 | #include "printf.h" 5 | #include "common.h" 6 | 7 | /* 8 | * Basic function for the system to output a character, used by printf.c 9 | */ 10 | void _putchar(char character) 11 | { 12 | if (character == '\n') { 13 | uart_putchar('\r'); 14 | } 15 | uart_putchar(character); 16 | } 17 | 18 | /* 19 | * Simple trap handler (actually handle nothing) 20 | */ 21 | void simple_trap_handler() 22 | { 23 | printf("EXCEPTION!!!\n"); 24 | printf("============\n"); 25 | printf("MEPC: 0x%x\n", get_mepc()); 26 | printf("MCAUSE: 0x%x\n", get_mcause()); 27 | printf("MTVAL: 0x%x\n", get_mtval()); 28 | while (1); // die 29 | } 30 | 31 | unsigned int get_mepc() 32 | { 33 | uint32_t result; 34 | __asm__ volatile("csrr %0, mepc;" : "=r"(result)); 35 | return result; 36 | } 37 | 38 | unsigned int get_mcause() 39 | { 40 | uint32_t result; 41 | __asm__ volatile("csrr %0, mcause;" : "=r"(result)); 42 | return result; 43 | } 44 | 45 | unsigned int get_mtval() 46 | { 47 | uint32_t result; 48 | __asm__ volatile("csrr %0, mtval;" : "=r"(result)); 49 | return result; 50 | } 51 | -------------------------------------------------------------------------------- /sw/Barebone-Timer/timer.c: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | #include "uart.h" 3 | #include "mmio.h" 4 | #include "printf.h" 5 | 6 | int main() 7 | { 8 | uart_init(); 9 | printf("Setting mtimecmp\n"); 10 | 11 | // set mtimecmp to 0x10000000 12 | MMIO_WRITE(0x43c0000c, 0x0); 13 | MMIO_WRITE(0x43c00008, 0x08000000); 14 | 15 | printf("Enable global interrupt\n"); 16 | // enable global interrupt 17 | __asm__ volatile("csrs mstatus, 0x8"); 18 | 19 | printf("Enable timer interrupt\n"); 20 | // enable mcahine timer interrupt 21 | __asm__ volatile("li t0, (1 << 7)"); 22 | __asm__ volatile("csrs mie, t0"); 23 | 24 | for (;;) { 25 | unsigned int mtime = MMIO_READ(0x43c00000); 26 | unsigned int mtimeh = MMIO_READ(0x43c00004); 27 | unsigned int mtimecmp = MMIO_READ(0x43c00008); 28 | unsigned int mtimecmph = MMIO_READ(0x43c0000c); 29 | printf("mtime = 0x%08x%08x, mtimecmp = 0x%08x%08x\r", 30 | mtimeh, mtime, mtimecmph, mtimecmp); 31 | } 32 | } 33 | 34 | void reset_mtime() 35 | { 36 | printf("EXCEPTION!!!\n"); 37 | printf("============\n"); 38 | printf("MEPC: 0x%x\n", get_mepc()); 39 | printf("MCAUSE: 0x%x\n", get_mcause()); 40 | printf("MTVAL: 0x%x\n", get_mtval()); 41 | 42 | // reset mtime 43 | printf("RESET MTIME\n"); 44 | MMIO_WRITE(0x43c00004, 0x0); 45 | MMIO_WRITE(0x43c00000, 0x0); 46 | } 47 | -------------------------------------------------------------------------------- /sw/drivers/gpio.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "gpio.h" 4 | #include "mmio.h" 5 | #include "mmap_regs.h" 6 | 7 | void gpio_init() 8 | { 9 | // GPIO is configured as output by default 10 | MMIO_WRITE(GPIO_BASE + GPIO_TRI, GPIO_OUTPUT); 11 | 12 | // GPIO2 is configured as input by default 13 | MMIO_WRITE(GPIO_BASE + GPIO2_TRI, GPIO_INPUT); 14 | } 15 | 16 | uint32_t __attribute__((optimize("O1"))) gpio_read(void *gpio) 17 | { 18 | uint32_t data = MMIO_READ(GPIO_BASE + gpio); 19 | return data; 20 | } 21 | 22 | void __attribute__((optimize("O1"))) gpio_write(void *gpio, uint32_t data) 23 | { 24 | MMIO_WRITE(GPIO_BASE + gpio, data); 25 | } 26 | 27 | 28 | uint32_t gpio_read_pin(uint32_t pin) 29 | { 30 | uint32_t data = gpio_read((void *)GPIO2_DATA); 31 | data = (data >> pin) & 0b1; 32 | return data; 33 | } 34 | 35 | void gpio_write_pin(uint32_t pin, uint32_t val) 36 | { 37 | uint32_t data = gpio_read((void *)GPIO_DATA); 38 | if (val) { 39 | // set the corresponding bit 40 | data |= (0b1 << pin); 41 | } else { 42 | // clear the corresponding bit 43 | data &= ~(0b1 << pin); 44 | } 45 | gpio_write(GPIO_DATA, data); 46 | } 47 | 48 | void gpio_toggle_pin(uint32_t pin) 49 | { 50 | uint32_t data = gpio_read((void *)GPIO_DATA); 51 | // toggle the corresponding bit 52 | data ^= (0b1 << pin); 53 | gpio_write(GPIO_DATA, data); 54 | } 55 | -------------------------------------------------------------------------------- /sw/Lab3/freertos_risc_v_trap.c: -------------------------------------------------------------------------------- 1 | #include "FreeRTOS.h" 2 | #include "printf.h" 3 | #include "gpio.h" 4 | #include "semphr.h" 5 | 6 | #define LED_RED_PIN 0 7 | #define LED_GREEN_PIN 1 8 | #define LED_ORANGE_PIN 2 9 | #define BTN_BLUE_PIN 0 10 | 11 | #define GPIO_PIN_SET 1 12 | #define GPIO_PIN_RESET 0 13 | 14 | extern SemaphoreHandle_t xBinarySemaphore; 15 | 16 | /* 17 | * Application exception handler for FreeRTOS 18 | */ 19 | void freertos_risc_v_application_exception_handler( uint32_t cause ) 20 | { 21 | printf("Application Exception Handler Called By FreeRTOS!!!\n"); 22 | printf("MCAUSE: 0x%x\n", cause); 23 | for ( ; ; ) { } 24 | return; 25 | } 26 | 27 | /* 28 | * Application interrupt handler for FreeRTOS 29 | */ 30 | void freertos_risc_v_application_interrupt_handler( uint32_t cause ) 31 | { 32 | // Disable MEIE (bit 11) in MIE Register 33 | __asm__ volatile ( 34 | "li t0, 1<<11\n\t" 35 | "csrc mie, t0\n\t" 36 | ); 37 | 38 | printf("Application Interrupt Handler Called By FreeRTOS!!!\n"); 39 | printf("MCAUSE: 0x%x\n", cause); 40 | 41 | // Red toggle 42 | gpio_toggle_pin(LED_RED_PIN); 43 | 44 | // Give the semaphore to unblock the handler task 45 | BaseType_t xHigherPriorityTaskWoken = pdFALSE; 46 | xSemaphoreGiveFromISR(xBinarySemaphore, &xHigherPriorityTaskWoken); 47 | portYIELD_FROM_ISR(xHigherPriorityTaskWoken); 48 | 49 | return; 50 | } 51 | 52 | -------------------------------------------------------------------------------- /sw/Barebone-Timer/isr.S: -------------------------------------------------------------------------------- 1 | .section .text 2 | 3 | .global timer_interrupt_handler 4 | timer_interrupt_handler: 5 | addi sp, sp, -4*31 6 | sw x1, 0*4(sp) 7 | sw x2, 1*4(sp) 8 | sw x3, 2*4(sp) 9 | sw x4, 3*4(sp) 10 | sw x5, 4*4(sp) 11 | sw x6, 5*4(sp) 12 | sw x7, 6*4(sp) 13 | sw x8, 7*4(sp) 14 | sw x9, 8*4(sp) 15 | sw x10, 9*4(sp) 16 | sw x11, 10*4(sp) 17 | sw x12, 11*4(sp) 18 | sw x13, 12*4(sp) 19 | sw x14, 13*4(sp) 20 | sw x15, 14*4(sp) 21 | sw x16, 15*4(sp) 22 | sw x17, 16*4(sp) 23 | sw x18, 17*4(sp) 24 | sw x19, 18*4(sp) 25 | sw x20, 19*4(sp) 26 | sw x21, 20*4(sp) 27 | sw x22, 21*4(sp) 28 | sw x23, 22*4(sp) 29 | sw x24, 23*4(sp) 30 | sw x25, 24*4(sp) 31 | sw x26, 25*4(sp) 32 | sw x27, 26*4(sp) 33 | sw x28, 27*4(sp) 34 | sw x29, 28*4(sp) 35 | sw x30, 29*4(sp) 36 | sw x31, 30*4(sp) 37 | jal reset_mtime 38 | lw x1, 0*4(sp) 39 | lw x2, 1*4(sp) 40 | lw x3, 2*4(sp) 41 | lw x4, 3*4(sp) 42 | lw x5, 4*4(sp) 43 | lw x6, 5*4(sp) 44 | lw x7, 6*4(sp) 45 | lw x8, 7*4(sp) 46 | lw x9, 8*4(sp) 47 | lw x10, 9*4(sp) 48 | lw x11, 10*4(sp) 49 | lw x12, 11*4(sp) 50 | lw x13, 12*4(sp) 51 | lw x14, 13*4(sp) 52 | lw x15, 14*4(sp) 53 | lw x16, 15*4(sp) 54 | lw x17, 16*4(sp) 55 | lw x18, 17*4(sp) 56 | lw x19, 18*4(sp) 57 | lw x20, 19*4(sp) 58 | lw x21, 20*4(sp) 59 | lw x22, 21*4(sp) 60 | lw x23, 22*4(sp) 61 | lw x24, 23*4(sp) 62 | lw x25, 24*4(sp) 63 | lw x26, 25*4(sp) 64 | lw x27, 26*4(sp) 65 | lw x28, 27*4(sp) 66 | lw x29, 28*4(sp) 67 | lw x30, 29*4(sp) 68 | lw x31, 30*4(sp) 69 | addi sp, sp, 4*31 70 | mret 71 | -------------------------------------------------------------------------------- /sw/common/link.ld: -------------------------------------------------------------------------------- 1 | /* Copyright lowRISC contributors. 2 | Licensed under the Apache License, Version 2.0, see LICENSE for details. 3 | SPDX-License-Identifier: Apache-2.0 */ 4 | 5 | OUTPUT_ARCH(riscv) 6 | 7 | MEMORY 8 | { 9 | ram : ORIGIN = 0x40000000, LENGTH = 0x20000 /* 128 KiB */ 10 | stack : ORIGIN = 0x40020000, LENGTH = 0x20000 /* 128 KiB */ 11 | } 12 | 13 | /* Stack information variables */ 14 | _min_stack = 0x10000; /* 64K - minimum stack space to reserve */ 15 | _stack_len = LENGTH(stack); 16 | _stack_start = ORIGIN(stack) + LENGTH(stack); 17 | 18 | _entry_point = _vectors_start + 0x80; 19 | ENTRY(_entry_point) 20 | 21 | SECTIONS 22 | { 23 | .text : { 24 | . = ALIGN(4); 25 | _vectors_start = .; 26 | KEEP(*(.vectors)) 27 | _vectors_end = .; 28 | *(.text) 29 | *(.text.*) 30 | . = ALIGN(4); 31 | } > ram 32 | 33 | .rodata : { 34 | . = ALIGN(4); 35 | /* Small RO data before large RO data */ 36 | *(.srodata) 37 | *(.srodata.*) 38 | *(.rodata); 39 | *(.rodata.*) 40 | . = ALIGN(4); 41 | } > ram 42 | 43 | .data : { 44 | . = ALIGN(4); 45 | /* Small data before large data */ 46 | *(.sdata) 47 | *(.sdata.*) 48 | *(.data); 49 | *(.data.*) 50 | . = ALIGN(4); 51 | } > ram 52 | 53 | .bss : 54 | { 55 | . = ALIGN(4); 56 | _bss_start = .; 57 | /* Small BSS before large BSS */ 58 | *(.sbss) 59 | *(.sbss.*) 60 | *(.bss) 61 | *(.bss.*) 62 | *(COMMON) 63 | _bss_end = .; 64 | . = ALIGN(4); 65 | } > ram 66 | 67 | /* ensure there is enough room for stack */ 68 | .stack (NOLOAD): { 69 | . = ALIGN(4); 70 | . = . + _min_stack ; 71 | . = ALIGN(4); 72 | stack = . ; 73 | _stack = . ; 74 | } > stack 75 | } 76 | -------------------------------------------------------------------------------- /sw/Lab2/main.c: -------------------------------------------------------------------------------- 1 | #include "FreeRTOS.h" 2 | #include "task.h" 3 | #include "queue.h" 4 | #include "gpio.h" 5 | #include "printf.h" 6 | 7 | #define LED_RED_PIN 0 8 | #define LED_GREEN_PIN 1 9 | #define LED_ORANGE_PIN 2 10 | 11 | void TaskMonitor_App (void *pvParameters) { 12 | for ( ; ; ) { 13 | Taskmonitor(); 14 | vTaskDelay(1000); 15 | } 16 | } 17 | 18 | void Red_LED_App (void *pvParameters) { 19 | uint32_t Redtimer = 40; 20 | for ( ; ; ) { 21 | gpio_toggle_pin(LED_RED_PIN); 22 | vTaskDelay(Redtimer); 23 | Redtimer += 1; 24 | } 25 | } 26 | 27 | void Green_LED_App (void *pvParameters) { 28 | uint32_t Greentimer = 50; 29 | for ( ; ; ) { 30 | gpio_toggle_pin(LED_GREEN_PIN); 31 | vTaskDelay(Greentimer); 32 | Greentimer += 2; 33 | } 34 | } 35 | 36 | void Delay_App (void *pvParameters) { 37 | int delayflag = 0; 38 | uint32_t delaytime; 39 | while (1) { 40 | if ( delayflag == 0 ) { 41 | delaytime = 100; 42 | delayflag = 1; 43 | } else { 44 | delaytime = 0xFFFFFFFF; 45 | } 46 | vTaskDelay(delaytime); 47 | } 48 | } 49 | 50 | /** 51 | * @brief The application entry point. 52 | * @retval int 53 | */ 54 | int main(void) 55 | { 56 | gpio_init(); 57 | 58 | xTaskCreate ( 59 | Red_LED_App, 60 | "Red_LED_App", 61 | 256, 62 | NULL, 63 | 1, 64 | NULL ); 65 | 66 | xTaskCreate ( 67 | Green_LED_App, 68 | "Green_LED_App", 69 | 256, 70 | NULL, 71 | 1, 72 | NULL ); 73 | 74 | xTaskCreate ( 75 | Delay_App, 76 | "Delay_App", 77 | 256, 78 | NULL, 79 | 14, 80 | NULL ); 81 | 82 | xTaskCreate ( 83 | TaskMonitor_App, 84 | "TaskMonitor_App", 85 | 256, 86 | NULL, 87 | 3, 88 | NULL ); 89 | 90 | vTaskStartScheduler(); 91 | /* Infinite loop */ 92 | while (1) { } 93 | } 94 | -------------------------------------------------------------------------------- /sw/common/crt0.S: -------------------------------------------------------------------------------- 1 | # Copyright lowRISC contributors. 2 | # Licensed under the Apache License, Version 2.0, see LICENSE for details. 3 | # SPDX-License-Identifier: Apache-2.0 4 | 5 | .section .text 6 | 7 | // Unimplemented trap handler goes here 8 | .weak default_trap_handler 9 | default_trap_handler: 10 | j . 11 | 12 | reset_handler: 13 | /* set all registers to zero */ 14 | mv x1, x0 15 | mv x2, x1 16 | mv x3, x1 17 | mv x4, x1 18 | mv x5, x1 19 | mv x6, x1 20 | mv x7, x1 21 | mv x8, x1 22 | mv x9, x1 23 | mv x10, x1 24 | mv x11, x1 25 | mv x12, x1 26 | mv x13, x1 27 | mv x14, x1 28 | mv x15, x1 29 | mv x16, x1 30 | mv x17, x1 31 | mv x18, x1 32 | mv x19, x1 33 | mv x20, x1 34 | mv x21, x1 35 | mv x22, x1 36 | mv x23, x1 37 | mv x24, x1 38 | mv x25, x1 39 | mv x26, x1 40 | mv x27, x1 41 | mv x28, x1 42 | mv x29, x1 43 | mv x30, x1 44 | mv x31, x1 45 | 46 | /* stack initilization */ 47 | la x2, _stack_start 48 | 49 | _start: 50 | .global _start 51 | 52 | /* clear BSS */ 53 | la x26, _bss_start 54 | la x27, _bss_end 55 | 56 | bge x26, x27, zero_loop_end 57 | 58 | zero_loop: 59 | sw x0, 0(x26) 60 | addi x26, x26, 4 61 | ble x26, x27, zero_loop 62 | zero_loop_end: 63 | 64 | 65 | main_entry: 66 | /* jump to main program entry point (argc = argv = 0) */ 67 | addi x10, x0, 0 68 | addi x11, x0, 0 69 | jal x1, main 70 | 71 | /* If execution ends up here just put the core to sleep */ 72 | sleep_loop: 73 | wfi 74 | j sleep_loop 75 | 76 | /* =================================================== [ exceptions ] === */ 77 | /* This section has to be down here, since we have to disable rvc for it */ 78 | 79 | .section .vectors, "ax" 80 | .option norvc; 81 | 82 | // Fill in vector tables with DEFAULT_TRAP_HANDLERs 83 | #ifndef DEFAULT_TRAP_HANDLER 84 | #warning DEFAULT_TRAP_HANDLER not defined, use default trap handler 85 | #define DEFAULT_TRAP_HANDLER default_trap_handler 86 | #endif 87 | .org 0x00 88 | .rept 32 89 | j DEFAULT_TRAP_HANDLER 90 | .endr 91 | 92 | // reset vector 93 | .org 0x80 94 | j reset_handler 95 | -------------------------------------------------------------------------------- /sw/FreeRTOS-Demo-Hello/hello.c: -------------------------------------------------------------------------------- 1 | #include "FreeRTOS.h" 2 | #include "task.h" 3 | #include "printf.h" 4 | 5 | #define STACK_SIZE 1024 6 | 7 | /* Task to be created. */ 8 | void vTaskTest( void * pvParameters ) 9 | { 10 | for( ;; ) 11 | { 12 | vTaskDelay(1000); 13 | printf("hello\n"); 14 | } 15 | } 16 | 17 | void vTaskTest2( void * pvParameters ) 18 | { 19 | for( ;; ) 20 | { 21 | vTaskDelay(2000); 22 | printf("world\n"); 23 | } 24 | } 25 | 26 | int main() 27 | { 28 | BaseType_t xReturned; 29 | TaskHandle_t xHandle = NULL; 30 | TaskHandle_t xHandle2 = NULL; 31 | 32 | printf("Create task\n"); 33 | 34 | /* Create the task, storing the handle. */ 35 | xReturned = xTaskCreate( 36 | vTaskTest, /* Function that implements the task. */ 37 | "Test", /* Text name for the task. */ 38 | STACK_SIZE, /* Stack size in words, not bytes. */ 39 | NULL, /* Parameter passed into the task. */ 40 | tskIDLE_PRIORITY,/* Priority at which the task is created. */ 41 | &xHandle ); /* Used to pass out the created task's handle. */ 42 | 43 | if( xReturned != pdPASS ) 44 | { 45 | printf("Task create fail\n"); 46 | goto dead; 47 | } 48 | 49 | xReturned = xTaskCreate( 50 | vTaskTest2, /* Function that implements the task. */ 51 | "Test", /* Text name for the task. */ 52 | STACK_SIZE, /* Stack size in words, not bytes. */ 53 | NULL, /* Parameter passed into the task. */ 54 | tskIDLE_PRIORITY,/* Priority at which the task is created. */ 55 | &xHandle2 ); /* Used to pass out the created task's handle. */ 56 | 57 | if( xReturned != pdPASS ) 58 | { 59 | printf("Task create fail\n"); 60 | goto dead; 61 | } 62 | 63 | vTaskStartScheduler(); 64 | 65 | dead: 66 | while (1); 67 | /* Should never get here! */ 68 | return 0; 69 | } 70 | -------------------------------------------------------------------------------- /sw/Lab3/main.c: -------------------------------------------------------------------------------- 1 | #include "printf.h" 2 | #include "FreeRTOS.h" 3 | #include "task.h" 4 | #include "semphr.h" 5 | #include "gpio.h" 6 | #include "mmio.h" 7 | 8 | 9 | #define LED_RED_PIN 0 10 | #define LED_GREEN_PIN 1 11 | #define LED_ORANGE_PIN 2 12 | #define BTN_BLUE_PIN 0 13 | 14 | #define GPIO_PIN_SET 1 15 | #define GPIO_PIN_RESET 0 16 | 17 | SemaphoreHandle_t xBinarySemaphore; 18 | 19 | 20 | uint32_t get_time() 21 | { 22 | uint32_t mtime = MMIO_READ(0x43c00000); 23 | 24 | return mtime; 25 | } 26 | 27 | 28 | void Green_LED_Task(void *pvParameters) 29 | { 30 | // Green Blinking 31 | for( ; ; ) { 32 | gpio_toggle_pin(LED_GREEN_PIN); 33 | vTaskDelay(1000); 34 | } 35 | } 36 | 37 | 38 | void vHandlerTask( void *pvParameters ) 39 | { 40 | 41 | for( ; ; ) { 42 | // Take the semaphore 43 | xSemaphoreTake(xBinarySemaphore, portMAX_DELAY); 44 | 45 | // Semaphore was obtained 46 | 47 | // Orange Blinks 5 times 48 | for (int i = 0 ; i < 10 ; i++) { 49 | uint32_t From_begin_time = get_time(); 50 | gpio_toggle_pin(LED_ORANGE_PIN); 51 | while (get_time() - From_begin_time < 7000000); 52 | } 53 | 54 | // Reset interrupt register 55 | __asm__ volatile ( 56 | "li t0, 1<<11\n\t" 57 | "csrs mie, t0\n\t" 58 | ); 59 | } 60 | } 61 | 62 | 63 | /** 64 | * @brief The application entry point. 65 | * @retval int 66 | */ 67 | int main(void) 68 | { 69 | // Create the semaphore // 70 | xBinarySemaphore = xSemaphoreCreateBinary(); 71 | 72 | if (xBinarySemaphore == NULL) 73 | return 0; 74 | 75 | // Initialize gpio 76 | gpio_init(); 77 | 78 | // task create // 79 | xTaskCreate ( 80 | Green_LED_Task, 81 | "Green_LED_Task", 82 | 256, 83 | NULL, 84 | 1, 85 | NULL ); 86 | 87 | xTaskCreate ( 88 | vHandlerTask, 89 | "vHandlerTask", 90 | 256, 91 | NULL, 92 | 3, 93 | NULL ); 94 | 95 | // Start Scaheduler 96 | vTaskStartScheduler(); 97 | 98 | // Infinite loop 99 | while (1) { } 100 | } 101 | 102 | -------------------------------------------------------------------------------- /sw/common/barebone.mk: -------------------------------------------------------------------------------- 1 | ######################### 2 | # RISC-V GCC toolchains # 3 | ######################### 4 | RISCV_PREFIX = ~/.local/lowrisc-toolchain-gcc-rv32imcb-20230427-1/bin/riscv32-unknown-elf- 5 | AR = $(RISCV_PREFIX)ar 6 | CC = $(RISCV_PREFIX)gcc 7 | OBJDUMP = $(RISCV_PREFIX)objdump 8 | OBJCOPY = $(RISCV_PREFIX)objcopy 9 | READELF = $(RISCV_PREFIX)readelf 10 | RISCV_GCC_OPTS = -march=rv32imcb -mabi=ilp32 -mcmodel=medany -nostartfiles -nostdlib 11 | 12 | ########### 13 | # Sources # 14 | ########### 15 | 16 | ifndef PROGRAM 17 | $(error "Must define PROGRAM first") 18 | endif 19 | 20 | # root of the sw directory 21 | SW_ROOT ?= $(shell cd .. && pwd) 22 | 23 | # root to sources 24 | PRINTF_SOURCE_DIR = $(SW_ROOT)/printf 25 | COMMON_SOURCE_DIR = $(SW_ROOT)/common 26 | DRIVER_SOURCE_DIR = $(SW_ROOT)/drivers 27 | PROGRAM_SOURCE_DIR = $(SW_ROOT)/$(PROGRAM) 28 | 29 | # collect printf source 30 | PRINTF_SRC = $(PRINTF_SOURCE_DIR)/printf.c 31 | 32 | # collect common sources 33 | PORT_SRC = \ 34 | $(COMMON_SOURCE_DIR)/common.c 35 | 36 | # collect all assembly codes 37 | PORT_ASM = \ 38 | $(COMMON_SOURCE_DIR)/crt0.S 39 | 40 | # collect all driver codes 41 | DRIVER_SRC = \ 42 | $(DRIVER_SOURCE_DIR)/gpio.c \ 43 | $(DRIVER_SOURCE_DIR)/uart.c 44 | 45 | # collect all program sources 46 | PROGRAM_SRC = $(wildcard $(PROGRAM_SOURCE_DIR)/*.c) 47 | PROGRAM_ASM = $(wildcard $(PROGRAM_SOURCE_DIR)/*.S) 48 | 49 | #################### 50 | # Compiler options # 51 | #################### 52 | # setup include paths 53 | INCLUDES = \ 54 | -I$(PRINTF_SOURCE_DIR) \ 55 | -I$(COMMON_SOURCE_DIR) \ 56 | -I$(DRIVER_SOURCE_DIR) \ 57 | -I$(PROGRAM_SOURCE_DIR) 58 | 59 | # setup flags (may be pre-set before including this file) 60 | CFLAGS += -O2 -g -Wall $(INCLUDES) $(RISCV_GCC_OPTS) 61 | ASFLAGS += 62 | LDFLAGS += -L. -T $(SW_ROOT)/common/link.ld $(RISCV_GCC_OPTS) 63 | LIBS += -lm -lc -lgcc 64 | 65 | ########### 66 | # Targets # 67 | ########### 68 | # convert all sources to objects 69 | PRINTF_OBJ = $(PRINTF_SRC:.c=.o) 70 | PORT_OBJ = $(PORT_SRC:.c=.o) $(PORT_ASM:.S=.o) 71 | DRIVER_OBJ = $(DRIVER_SRC:.c=.o) 72 | PROGRAM_OBJ = $(PROGRAM_SRC:.c=.o) $(PROGRAM_ASM:.S=.o) 73 | OBJS = $(PRINTF_OBJ) $(PORT_OBJ) $(DRIVER_OBJ) $(PROGRAM_OBJ) 74 | 75 | # determine output files 76 | OUTFILES := $(PROGRAM).elf $(PROGRAM).dis $(PROGRAM).bin 77 | 78 | ########### 79 | # Recipes # 80 | ########### 81 | 82 | .PHONY: all clean 83 | 84 | all: $(OUTFILES) 85 | 86 | $(PROGRAM).elf: $(OBJS) $(LINKER_SCRIPT) 87 | $(CC) -o $@ $(OBJS) $(CFLAGS) $(LDFLAGS) $(LIBS) 88 | 89 | $(PROGRAM).dis: $(PROGRAM).elf 90 | $(OBJDUMP) -xsd $< > $@ 91 | 92 | $(PROGRAM).bin: $(PROGRAM).elf 93 | $(OBJCOPY) -O binary $^ $@ 94 | 95 | %.o: %.c 96 | $(CC) -c $(CFLAGS) -o $@ $< 97 | 98 | %.o: %.S 99 | $(CC) -c $(CFLAGS) $(ASFLAGS) -o $@ $< 100 | 101 | clean: 102 | $(RM) $(OBJS) $(OUTFILES) 103 | -------------------------------------------------------------------------------- /sw/Lab1/main.c: -------------------------------------------------------------------------------- 1 | #include "FreeRTOS.h" 2 | #include "task.h" 3 | #include "queue.h" 4 | #include "gpio.h" 5 | 6 | #define LED_RED_PIN 0 7 | #define LED_GREEN_PIN 1 8 | #define LED_ORANGE_PIN 2 9 | #define BTN_BLUE_PIN 0 10 | 11 | #define GPIO_PIN_SET 1 12 | #define GPIO_PIN_RESET 0 13 | 14 | QueueHandle_t xQueue1; 15 | 16 | static void pvLedTask(void *p) 17 | { 18 | // 0: red 19 | // 1: green 20 | // 2: after red 21 | // 3: after green 22 | // 4: orange 23 | // 5: after orange 24 | int state = 0; 25 | int nstate[6] = {2, 3, 1, 0, 5, 4}; 26 | int msg; 27 | for (;;) { 28 | switch (state) { 29 | case 0: 30 | gpio_write_pin(LED_RED_PIN, GPIO_PIN_SET); 31 | gpio_write_pin(LED_GREEN_PIN, GPIO_PIN_RESET); 32 | gpio_write_pin(LED_ORANGE_PIN, GPIO_PIN_RESET); 33 | break; 34 | case 1: 35 | gpio_write_pin(LED_RED_PIN, GPIO_PIN_RESET); 36 | gpio_write_pin(LED_GREEN_PIN, GPIO_PIN_SET); 37 | gpio_write_pin(LED_ORANGE_PIN, GPIO_PIN_RESET); 38 | break; 39 | case 2: 40 | gpio_write_pin(LED_RED_PIN, GPIO_PIN_RESET); 41 | gpio_write_pin(LED_GREEN_PIN, GPIO_PIN_RESET); 42 | gpio_write_pin(LED_ORANGE_PIN, GPIO_PIN_RESET); 43 | break; 44 | case 3: 45 | gpio_write_pin(LED_RED_PIN, GPIO_PIN_RESET); 46 | gpio_write_pin(LED_GREEN_PIN, GPIO_PIN_RESET); 47 | gpio_write_pin(LED_ORANGE_PIN, GPIO_PIN_RESET); 48 | break; 49 | case 4: 50 | gpio_write_pin(LED_RED_PIN, GPIO_PIN_RESET); 51 | gpio_write_pin(LED_GREEN_PIN, GPIO_PIN_RESET); 52 | gpio_write_pin(LED_ORANGE_PIN, GPIO_PIN_SET); 53 | break; 54 | case 5: 55 | gpio_write_pin(LED_RED_PIN, GPIO_PIN_RESET); 56 | gpio_write_pin(LED_GREEN_PIN, GPIO_PIN_RESET); 57 | gpio_write_pin(LED_ORANGE_PIN, GPIO_PIN_RESET); 58 | break; 59 | default: 60 | gpio_write_pin(LED_RED_PIN, GPIO_PIN_RESET); 61 | gpio_write_pin(LED_GREEN_PIN, GPIO_PIN_RESET); 62 | gpio_write_pin(LED_ORANGE_PIN, GPIO_PIN_RESET); 63 | break; 64 | } 65 | vTaskDelay(500); 66 | 67 | msg = 0; 68 | xQueueReceive(xQueue1, &msg, (TickType_t)0); 69 | if (msg) { 70 | state = (state < 4) ? 4 : 0; 71 | } else { 72 | state = nstate[state]; 73 | } 74 | } 75 | } 76 | 77 | static void pvBtnTask(void *p) 78 | { 79 | for (;;) { 80 | if (gpio_read_pin(BTN_BLUE_PIN)) { 81 | int data = 1; 82 | xQueueSend(xQueue1, (void *)&data, (TickType_t)10); 83 | vTaskDelay(200); 84 | } 85 | } 86 | } 87 | 88 | int main(void) 89 | { 90 | gpio_init(); 91 | 92 | xQueue1 = xQueueCreate(1, sizeof(int)); 93 | 94 | xTaskCreate( 95 | pvLedTask, 96 | "LedTask", 97 | 512, 98 | NULL, 99 | 1, 100 | NULL); 101 | 102 | xTaskCreate( 103 | pvBtnTask, 104 | "BtnTask", 105 | 512, 106 | NULL, 107 | 1, 108 | NULL); 109 | 110 | vTaskStartScheduler(); 111 | 112 | /* Infinite loop */ 113 | while (1) { } 114 | } 115 | -------------------------------------------------------------------------------- /sw/common/freertos_risc_v_chip_specific_extensions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS Kernel 3 | * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | * this software and associated documentation files (the "Software"), to deal in 9 | * the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | * the Software, and to permit persons to whom the Software is furnished to do so, 12 | * subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | * 24 | * https://www.FreeRTOS.org 25 | * https://github.com/FreeRTOS 26 | * 27 | */ 28 | 29 | /* 30 | * The FreeRTOS kernel's RISC-V port is split between the the code that is 31 | * common across all currently supported RISC-V chips (implementations of the 32 | * RISC-V ISA), and code that tailors the port to a specific RISC-V chip: 33 | * 34 | * + FreeRTOS\Source\portable\GCC\RISC-V\portASM.S contains the code that 35 | * is common to all currently supported RISC-V chips. There is only one 36 | * portASM.S file because the same file is built for all RISC-V target chips. 37 | * 38 | * + Header files called freertos_risc_v_chip_specific_extensions.h contain the 39 | * code that tailors the FreeRTOS kernel's RISC-V port to a specific RISC-V 40 | * chip. There are multiple freertos_risc_v_chip_specific_extensions.h files 41 | * as there are multiple RISC-V chip implementations. 42 | * 43 | * !!!NOTE!!! 44 | * TAKE CARE TO INCLUDE THE CORRECT freertos_risc_v_chip_specific_extensions.h 45 | * HEADER FILE FOR THE CHIP IN USE. This is done using the assembler's (not the 46 | * compiler's!) include path. For example, if the chip in use includes a core 47 | * local interrupter (CLINT) and does not include any chip specific register 48 | * extensions then add the path below to the assembler's include path: 49 | * FreeRTOS\Source\portable\GCC\RISC-V\chip_specific_extensions\RISCV_MTIME_CLINT_no_extensions 50 | * 51 | */ 52 | 53 | 54 | #ifndef __FREERTOS_RISC_V_EXTENSIONS_H__ 55 | #define __FREERTOS_RISC_V_EXTENSIONS_H__ 56 | 57 | #define portasmHAS_SIFIVE_CLINT 0 58 | #define portasmHAS_MTIME 1 59 | #define portasmADDITIONAL_CONTEXT_SIZE 0 60 | 61 | .macro portasmSAVE_ADDITIONAL_REGISTERS 62 | /* No additional registers to save, so this macro does nothing. */ 63 | .endm 64 | 65 | .macro portasmRESTORE_ADDITIONAL_REGISTERS 66 | /* No additional registers to restore, so this macro does nothing. */ 67 | .endm 68 | 69 | #endif /* __FREERTOS_RISC_V_EXTENSIONS_H__ */ 70 | -------------------------------------------------------------------------------- /pynq_z2/ps/ibex_ctrl.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "id": "9bc41b99", 7 | "metadata": {}, 8 | "outputs": [ 9 | { 10 | "data": { 11 | "application/javascript": [ 12 | "\n", 13 | "try {\n", 14 | "require(['notebook/js/codecell'], function(codecell) {\n", 15 | " codecell.CodeCell.options_default.highlight_modes[\n", 16 | " 'magic_text/x-csrc'] = {'reg':[/^%%microblaze/]};\n", 17 | " Jupyter.notebook.events.one('kernel_ready.Kernel', function(){\n", 18 | " Jupyter.notebook.get_cells().map(function(cell){\n", 19 | " if (cell.cell_type == 'code'){ cell.auto_highlight(); } }) ;\n", 20 | " });\n", 21 | "});\n", 22 | "} catch (e) {};\n" 23 | ] 24 | }, 25 | "metadata": {}, 26 | "output_type": "display_data" 27 | }, 28 | { 29 | "data": { 30 | "application/javascript": [ 31 | "\n", 32 | "try {\n", 33 | "require(['notebook/js/codecell'], function(codecell) {\n", 34 | " codecell.CodeCell.options_default.highlight_modes[\n", 35 | " 'magic_text/x-csrc'] = {'reg':[/^%%pybind11/]};\n", 36 | " Jupyter.notebook.events.one('kernel_ready.Kernel', function(){\n", 37 | " Jupyter.notebook.get_cells().map(function(cell){\n", 38 | " if (cell.cell_type == 'code'){ cell.auto_highlight(); } }) ;\n", 39 | " });\n", 40 | "});\n", 41 | "} catch (e) {};\n" 42 | ] 43 | }, 44 | "metadata": {}, 45 | "output_type": "display_data" 46 | }, 47 | { 48 | "name": "stdout", 49 | "output_type": "stream", 50 | "text": [ 51 | "Done loading bitfile: ./caslab_rtos_ibex_soc_design_2.bit\n", 52 | "Done loading bin: Lab1.bin\n", 53 | "Done reset ibex\n" 54 | ] 55 | } 56 | ], 57 | "source": [ 58 | "from pynq import Overlay\n", 59 | "from pynq import MMIO\n", 60 | "\n", 61 | "# select the bitstrem to load\n", 62 | "bitfile_name = \"./caslab_rtos_ibex_soc_design_2.bit\"\n", 63 | "\n", 64 | "# select the program (*.bin) to load\n", 65 | "bin_name = \"Lab1.bin\"\n", 66 | "\n", 67 | "# loading overlay\n", 68 | "ol = Overlay(bitfile_name)\n", 69 | "print(\"Done loading bitfile:\", bitfile_name)\n", 70 | "\n", 71 | "# loading program to BRAM\n", 72 | "ol.device.load_ip_data(\"axi_bram_ctrl_0\", bin_name)\n", 73 | "print(\"Done loading bin:\", bin_name)\n", 74 | "\n", 75 | "# reset ibex and start running\n", 76 | "ibex_rst = ol.axi_gpio_1\n", 77 | "ibex_rst.write(0x0, 0x0)\n", 78 | "ibex_rst.write(0x8, 0x40000080) # start address\n", 79 | "ibex_rst.write(0x0, 0x1)\n", 80 | "print(\"Done reset ibex\")" 81 | ] 82 | } 83 | ], 84 | "metadata": { 85 | "kernelspec": { 86 | "display_name": "Python 3 (ipykernel)", 87 | "language": "python", 88 | "name": "python3" 89 | }, 90 | "language_info": { 91 | "codemirror_mode": { 92 | "name": "ipython", 93 | "version": 3 94 | }, 95 | "file_extension": ".py", 96 | "mimetype": "text/x-python", 97 | "name": "python", 98 | "nbconvert_exporter": "python", 99 | "pygments_lexer": "ipython3", 100 | "version": "3.10.4" 101 | } 102 | }, 103 | "nbformat": 4, 104 | "nbformat_minor": 5 105 | } 106 | -------------------------------------------------------------------------------- /sw/common/freertos.mk: -------------------------------------------------------------------------------- 1 | ######################### 2 | # RISC-V GCC toolchains # 3 | ######################### 4 | RISCV_PREFIX = ~/.local/lowrisc-toolchain-gcc-rv32imcb-20230427-1/bin/riscv32-unknown-elf- 5 | AR = $(RISCV_PREFIX)ar 6 | CC = $(RISCV_PREFIX)gcc 7 | OBJDUMP = $(RISCV_PREFIX)objdump 8 | OBJCOPY = $(RISCV_PREFIX)objcopy 9 | READELF = $(RISCV_PREFIX)readelf 10 | RISCV_GCC_OPTS = -march=rv32imcb -mabi=ilp32 -mcmodel=medany -nostartfiles -nostdlib 11 | 12 | ########### 13 | # Sources # 14 | ########### 15 | 16 | ifndef PROGRAM 17 | $(error "Must define PROGRAM first") 18 | endif 19 | 20 | # root of the sw directory 21 | SW_ROOT ?= $(shell cd .. && pwd) 22 | 23 | # root to sources 24 | FREERTOS_SOURCE_DIR = $(SW_ROOT)/FreeRTOS 25 | PRINTF_SOURCE_DIR = $(SW_ROOT)/printf 26 | COMMON_SOURCE_DIR = $(SW_ROOT)/common 27 | DRIVER_SOURCE_DIR = $(SW_ROOT)/drivers 28 | PROGRAM_SOURCE_DIR = $(SW_ROOT)/$(PROGRAM) 29 | 30 | # use heap_4 by default 31 | HEAP_CONFIG ?= 4 32 | 33 | # collect all FreeRTOS sources 34 | FREERTOS_SRC = \ 35 | $(FREERTOS_SOURCE_DIR)/croutine.c \ 36 | $(FREERTOS_SOURCE_DIR)/list.c \ 37 | $(FREERTOS_SOURCE_DIR)/queue.c \ 38 | $(FREERTOS_SOURCE_DIR)/tasks.c \ 39 | $(FREERTOS_SOURCE_DIR)/timers.c \ 40 | $(FREERTOS_SOURCE_DIR)/stream_buffer.c \ 41 | $(FREERTOS_SOURCE_DIR)/event_groups.c \ 42 | $(FREERTOS_SOURCE_DIR)/portable/MemMang/heap_$(HEAP_CONFIG).c 43 | 44 | # collect printf source 45 | PRINTF_SRC = $(PRINTF_SOURCE_DIR)/printf.c 46 | 47 | # collect common sources 48 | PORT_SRC = \ 49 | $(FREERTOS_SOURCE_DIR)/portable/GCC/RISC-V/port.c \ 50 | $(COMMON_SOURCE_DIR)/common.c 51 | 52 | # collect all assembly codes 53 | PORT_ASM = \ 54 | $(FREERTOS_SOURCE_DIR)/portable/GCC/RISC-V/portASM.S \ 55 | $(COMMON_SOURCE_DIR)/crt0.S 56 | 57 | # collect all driver codes 58 | DRIVER_SRC = \ 59 | $(DRIVER_SOURCE_DIR)/gpio.c \ 60 | $(DRIVER_SOURCE_DIR)/uart.c 61 | 62 | # collect all program sources 63 | PROGRAM_SRC = $(wildcard $(PROGRAM_SOURCE_DIR)/*.c) 64 | 65 | #################### 66 | # Compiler options # 67 | #################### 68 | # setup include paths 69 | INCLUDES = \ 70 | -I$(FREERTOS_SOURCE_DIR)/include \ 71 | -I$(FREERTOS_SOURCE_DIR)/portable/GCC/RISC-V \ 72 | -I$(PRINTF_SOURCE_DIR) \ 73 | -I$(COMMON_SOURCE_DIR) \ 74 | -I$(DRIVER_SOURCE_DIR) \ 75 | -I$(PROGRAM_SOURCE_DIR) 76 | 77 | # setup flags (may be pre-set before including this file) 78 | CFLAGS += -O2 -g -Wall $(INCLUDES) $(RISCV_GCC_OPTS) 79 | ASFLAGS += 80 | LDFLAGS += -L. -T $(SW_ROOT)/common/link.ld $(RISCV_GCC_OPTS) 81 | LIBS += -lm -lc -lgcc 82 | 83 | ########### 84 | # Targets # 85 | ########### 86 | # convert all sources to objects 87 | FREERTOS_OBJ = $(FREERTOS_SRC:.c=.o) 88 | PRINTF_OBJ = $(PRINTF_SRC:.c=.o) 89 | PORT_OBJ = $(PORT_SRC:.c=.o) $(PORT_ASM:.S=.o) 90 | DRIVER_OBJ = $(DRIVER_SRC:.c=.o) 91 | PROGRAM_OBJ = $(PROGRAM_SRC:.c=.o) 92 | OBJS = $(FREERTOS_OBJ) $(PRINTF_OBJ) $(PORT_OBJ) $(DRIVER_OBJ) $(PROGRAM_OBJ) 93 | 94 | # determine output files 95 | OUTFILES := $(PROGRAM).elf $(PROGRAM).dis $(PROGRAM).bin 96 | 97 | ########### 98 | # Recipes # 99 | ########### 100 | 101 | .PHONY: all clean 102 | 103 | all: $(OUTFILES) 104 | 105 | $(PROGRAM).elf: $(OBJS) $(LINKER_SCRIPT) 106 | $(CC) -o $@ $(OBJS) $(CFLAGS) $(LDFLAGS) $(LIBS) 107 | 108 | $(PROGRAM).dis: $(PROGRAM).elf 109 | $(OBJDUMP) -xsd $< > $@ 110 | 111 | $(PROGRAM).bin: $(PROGRAM).elf 112 | $(OBJCOPY) -O binary $^ $@ 113 | 114 | %.o: %.c 115 | $(CC) -c $(CFLAGS) -o $@ $< 116 | 117 | %.o: %.S 118 | $(CC) -c $(CFLAGS) $(ASFLAGS) -o $@ $< 119 | 120 | clean: 121 | $(RM) $(OBJS) $(OUTFILES) 122 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RTOS-Project-2023-riscv-freertos-on-pynq 2 | 3 | Porting FreeRTOS to a RISC-V based system on PYNQ-Z2 4 | 5 | ## Port Introduction 6 | 7 | ### Hardware 8 | 9 | - **Board**: PYNQ-Z2 10 | 11 | - **Processor**: [lowRISC Ibex RISC-V core](https://github.com/lowRISC/ibex) on [Zynq 7000 SoC](https://www.xilinx.com/products/silicon-devices/soc/zynq-7000.html) 12 | 13 | ### Compiler 14 | 15 | - [lowRISC GCC toolchain](https://github.com/lowRISC/lowrisc-toolchains) targeting Ibex 16 | 17 | ## System Architecture 18 | 19 | The hardware platform is built on ZYNQ FPGA 20 | 21 | ### PS side 22 | 23 | - Dual-core ARM Coretex-A9 running Linux (for debugging) 24 | 25 | ### PL side 26 | 27 | - Ibex: Soft-core RISC-V CPU 28 | 29 | - System AXI Bus 30 | 31 | - BRAM (on-chip SRAM) 32 | 33 | - UART, GPIO and Timer 34 | 35 | ![image](https://github.com/yuyuranium/RTOS-Project-2023-riscv-freertos-on-pynq/assets/79467307/90f93d9e-dacb-4372-a015-3781cbefbcb3) 36 | 37 | ## 38 | 39 | ## Result 40 | 41 | ### Schematic Diagram 42 | 43 | ![image](https://github.com/yuyuranium/RTOS-Project-2023-riscv-freertos-on-pynq/assets/79467307/f5dedabd-8453-4b07-9d76-6f4a79b81a12) 44 | 45 | ### Synthesis and Implementation 46 | 47 | ![image](https://github.com/yuyuranium/RTOS-Project-2023-riscv-freertos-on-pynq/assets/79467307/1d4aca44-1970-4537-a5f9-85f7a549d9ab) 48 | 49 | ## Build Hardware Platform with FuseSoC 50 | 51 | ### Steps 52 | 53 | - Install [fusesoc](https://github.com/olofk/fusesoc) 54 | 55 | ``` 56 | $ pip3 install fusesoc==2.1 57 | ``` 58 | 59 | - Install git libraries 60 | 61 | ``` 62 | $ cd pynq_z2/pl 63 | $ fusesoc library add --sync-type git ibex https://github.com/lowRISC/ibex.git # ibex library 64 | $ fusesoc library add --sync-type git pulp-axi https://github.com/pulp-platform/axi.git # pulp-axi library 65 | $ fusesoc library add --sync-type git pulp-common-cells https://github.com/pulp-platform/common_cells.git # pulp-common-cells library 66 | $ fusesoc library add --sync-type local ibex-axi . # ibex-axi local library 67 | ``` 68 | 69 | - Install ibex dependencies 70 | 71 | ``` 72 | $ cd fusesoc_libraries/ibex 73 | $ pip3 install -r python-requirements.txt 74 | ``` 75 | 76 | - Build and run vivado Project 77 | 78 | ``` 79 | $ bash scripts/build_proj.sh 80 | ``` 81 | 82 | ### Output 83 | 84 | You will get a bitstream file and a hardware handoff file inside the build directory. 85 | 86 | ``` 87 | build/caslab_rtos_ibex_axi_1.0.0/default-vivado/caslab_rtos_ibex_axi_1.0.0.bit 88 | build/caslab_rtos_ibex_axi_1.0.0/default-vivado/caslab_rtos_ibex_axi_1.0.0.hwh 89 | ``` 90 | 91 | ## Build Software 92 | 93 | You can use GNU make to build the software. 94 | 95 | ``` 96 | $ make -C sw/Barebone-Hello 97 | ``` 98 | 99 | Or for FreeRTOS applications 100 | 101 | ``` 102 | $ make -C sw/FreeRTOS-Demo-Hello 103 | ``` 104 | 105 | ### Porting new program to the system 106 | 107 | 1. Make a directory in `sw` 108 | 109 | 2. Write your program and main function 110 | 111 | 3. Write a `Makefile` and define your program name 112 | 113 | ``` 114 | PROGRAM := 115 | ``` 116 | 117 | **Note:** The program name must be the same as the directory name you created 118 | 119 | 4. Include the Makefile under `common` directory 120 | 121 | 1. If you are writing a baremetal program 122 | 123 | ``` 124 | include ../common/barebone.mk 125 | ``` 126 | 127 | 2. If you are using FreeRTOS 128 | 129 | ``` 130 | include ../common/freertos.mk 131 | ``` 132 | 133 | ## Boot Flow 134 | 135 | 1. Generate the bitstream (`*.bit`) and hardware handoff (`*.hwh`) 136 | 137 | 2. Copy the bitstrem and hardware handoff to the PS of PYNQ-Z2 138 | 139 | 3. Compile the software and get the binary file (`*.bin`) 140 | 141 | 4. Copy the binary file to the PS of PYNQ-Z2 142 | 143 | 5. Run the cell of in the [python notebook](https://github.com/yuyuranium/RTOS-Project-2023-riscv-freertos-on-pynq/blob/main/pynq_z2/ps/ibex_ctrl.ipynb) in PS to reset Ibex and boot 144 | 145 | ![image](https://github.com/yuyuranium/RTOS-Project-2023-riscv-freertos-on-pynq/assets/79467307/d1153f7b-bce9-45f2-a33d-0f00dec12c5a) 146 | -------------------------------------------------------------------------------- /sw/FreeRTOS-Demo-Hello/FreeRTOSConfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS V202212.00 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * https://www.FreeRTOS.org 23 | * https://github.com/FreeRTOS 24 | * 25 | */ 26 | 27 | #ifndef FREERTOS_CONFIG_H 28 | #define FREERTOS_CONFIG_H 29 | 30 | /*----------------------------------------------------------- 31 | * Application specific definitions. 32 | * 33 | * These definitions should be adjusted for your particular hardware and 34 | * application requirements. 35 | * 36 | * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE 37 | * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. 38 | * 39 | * See http://www.freertos.org/a00110.html. 40 | *----------------------------------------------------------*/ 41 | 42 | #define configISR_STACK_SIZE_WORDS ( 500 ) 43 | #define configMTIME_BASE_ADDRESS ( 0x43c00000UL ) 44 | #define configMTIMECMP_BASE_ADDRESS ( 0x43c00008UL ) 45 | 46 | #define configUSE_PREEMPTION 1 47 | #define configUSE_IDLE_HOOK 0 48 | #define configUSE_TICK_HOOK 0 49 | #define configCPU_CLOCK_HZ ( ( uint32_t ) ( 25000000 ) ) /* 25 MHz */ 50 | #define configTICK_RATE_HZ ( ( TickType_t ) 1000 ) /* 1 KHz (TBD) */ 51 | #define configMAX_PRIORITIES ( 7 ) 52 | #define configMINIMAL_STACK_SIZE ( ( uint32_t ) 100 ) /* Can be as low as 60 but some of the demo tasks that use this constant require it to be higher. */ 53 | #define configTOTAL_HEAP_SIZE ( ( size_t ) ( 12 * 1024 ) ) 54 | #define configMAX_TASK_NAME_LEN ( 16 ) 55 | #define configUSE_TRACE_FACILITY 0 56 | #define configUSE_16_BIT_TICKS 0 57 | #define configIDLE_SHOULD_YIELD 1 58 | #define configUSE_MUTEXES 1 59 | #define configQUEUE_REGISTRY_SIZE 8 60 | #define configCHECK_FOR_STACK_OVERFLOW 0 61 | #define configUSE_RECURSIVE_MUTEXES 1 62 | #define configUSE_MALLOC_FAILED_HOOK 0 63 | #define configUSE_APPLICATION_TASK_TAG 0 64 | #define configUSE_COUNTING_SEMAPHORES 1 65 | #define configGENERATE_RUN_TIME_STATS 0 66 | 67 | /* Software timer definitions. */ 68 | #define configUSE_TIMERS 1 69 | #define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 ) 70 | #define configTIMER_QUEUE_LENGTH 4 71 | #define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE ) 72 | 73 | /* Set the following definitions to 1 to include the API function, or zero 74 | * to exclude the API function. */ 75 | #define INCLUDE_vTaskPrioritySet 1 76 | #define INCLUDE_uxTaskPriorityGet 1 77 | #define INCLUDE_vTaskDelete 1 78 | #define INCLUDE_vTaskCleanUpResources 1 79 | #define INCLUDE_vTaskSuspend 1 80 | #define INCLUDE_vTaskDelayUntil 1 81 | #define INCLUDE_vTaskDelay 1 82 | #define INCLUDE_eTaskGetState 1 83 | #define INCLUDE_xTimerPendFunctionCall 1 84 | #define INCLUDE_xTaskAbortDelay 1 85 | #define INCLUDE_xTaskGetHandle 1 86 | #define INCLUDE_xSemaphoreGetMutexHolder 1 87 | 88 | /* Normal assert() semantics without relying on the provision of an assert.h 89 | * header file. */ 90 | #define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); } 91 | 92 | #endif /* FREERTOS_CONFIG_H */ 93 | -------------------------------------------------------------------------------- /sw/Lab1/FreeRTOSConfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS V202212.00 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * https://www.FreeRTOS.org 23 | * https://github.com/FreeRTOS 24 | * 25 | */ 26 | 27 | #ifndef FREERTOS_CONFIG_H 28 | #define FREERTOS_CONFIG_H 29 | 30 | /*----------------------------------------------------------- 31 | * Application specific definitions. 32 | * 33 | * These definitions should be adjusted for your particular hardware and 34 | * application requirements. 35 | * 36 | * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE 37 | * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. 38 | * 39 | * See http://www.freertos.org/a00110.html. 40 | *----------------------------------------------------------*/ 41 | 42 | #define configISR_STACK_SIZE_WORDS ( 500 ) 43 | #define configMTIME_BASE_ADDRESS ( 0x43c00000UL ) 44 | #define configMTIMECMP_BASE_ADDRESS ( 0x43c00008UL ) 45 | 46 | #define configUSE_PREEMPTION 1 47 | #define configUSE_TIME_SLICING 1 48 | #define configUSE_IDLE_HOOK 0 49 | #define configUSE_TICK_HOOK 0 50 | #define configCPU_CLOCK_HZ ( ( uint32_t ) ( 25000000 ) ) /* 25 MHz */ 51 | #define configTICK_RATE_HZ ( ( TickType_t ) 1000 ) /* 1 KHz (TBD) */ 52 | #define configMAX_PRIORITIES ( 7 ) 53 | #define configMINIMAL_STACK_SIZE ( ( uint32_t ) 100 ) /* Can be as low as 60 but some of the demo tasks that use this constant require it to be higher. */ 54 | #define configTOTAL_HEAP_SIZE ( ( size_t ) ( 12 * 1024 ) ) 55 | #define configMAX_TASK_NAME_LEN ( 16 ) 56 | #define configUSE_TRACE_FACILITY 0 57 | #define configUSE_16_BIT_TICKS 0 58 | #define configIDLE_SHOULD_YIELD 1 59 | #define configUSE_MUTEXES 1 60 | #define configQUEUE_REGISTRY_SIZE 8 61 | #define configCHECK_FOR_STACK_OVERFLOW 0 62 | #define configUSE_RECURSIVE_MUTEXES 1 63 | #define configUSE_MALLOC_FAILED_HOOK 0 64 | #define configUSE_APPLICATION_TASK_TAG 0 65 | #define configUSE_COUNTING_SEMAPHORES 1 66 | #define configGENERATE_RUN_TIME_STATS 0 67 | 68 | /* Software timer definitions. */ 69 | #define configUSE_TIMERS 1 70 | #define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 ) 71 | #define configTIMER_QUEUE_LENGTH 4 72 | #define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE ) 73 | 74 | /* Set the following definitions to 1 to include the API function, or zero 75 | * to exclude the API function. */ 76 | #define INCLUDE_vTaskPrioritySet 1 77 | #define INCLUDE_uxTaskPriorityGet 1 78 | #define INCLUDE_vTaskDelete 1 79 | #define INCLUDE_vTaskCleanUpResources 1 80 | #define INCLUDE_vTaskSuspend 1 81 | #define INCLUDE_vTaskDelayUntil 1 82 | #define INCLUDE_vTaskDelay 1 83 | #define INCLUDE_eTaskGetState 1 84 | #define INCLUDE_xTimerPendFunctionCall 1 85 | #define INCLUDE_xTaskAbortDelay 1 86 | #define INCLUDE_xTaskGetHandle 1 87 | #define INCLUDE_xSemaphoreGetMutexHolder 1 88 | 89 | /* Normal assert() semantics without relying on the provision of an assert.h 90 | * header file. */ 91 | #define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); } 92 | 93 | #endif /* FREERTOS_CONFIG_H */ 94 | -------------------------------------------------------------------------------- /sw/Lab2/FreeRTOSConfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS V202212.00 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * https://www.FreeRTOS.org 23 | * https://github.com/FreeRTOS 24 | * 25 | */ 26 | 27 | #ifndef FREERTOS_CONFIG_H 28 | #define FREERTOS_CONFIG_H 29 | 30 | /*----------------------------------------------------------- 31 | * Application specific definitions. 32 | * 33 | * These definitions should be adjusted for your particular hardware and 34 | * application requirements. 35 | * 36 | * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE 37 | * FreeRTOS API DOCUMENTATION AVAILABLE on the freertos.org web site. 38 | * 39 | * see http://www.freertos.org/a00110.html. 40 | *----------------------------------------------------------*/ 41 | 42 | #define configISR_STACK_SIZE_WORDS ( 500 ) 43 | #define configMTIME_BASE_ADDRESS ( 0x43c00000UL ) 44 | #define configMTIMECMP_BASE_ADDRESS ( 0x43c00008UL ) 45 | 46 | #define configUSE_PREEMPTION 1 47 | #define configUSE_TIME_SLICING 1 48 | #define configUSE_IDLE_HOOK 0 49 | #define configUSE_TICK_HOOK 0 50 | #define configCPU_CLOCK_HZ ( ( uint32_t ) ( 25000000 ) ) /* 100 MHz */ 51 | #define configTICK_RATE_HZ ( ( TickType_t ) 1000 ) /* 1 KHz (TBD) */ 52 | #define configMAX_PRIORITIES ( 15 ) 53 | #define configMINIMAL_STACK_SIZE ( ( uint32_t ) 100 ) /* Can be as low as 60 but some of the demo tasks that use this constant require it to be higher. */ 54 | #define configTOTAL_HEAP_SIZE ( ( size_t ) ( 12 * 1024 ) ) 55 | #define configMAX_TASK_NAME_LEN ( 16 ) 56 | #define configUSE_TRACE_FACILITY 0 57 | #define configUSE_16_BIT_TICKS 0 58 | #define configIDLE_SHOULD_YIELD 1 59 | #define configUSE_MUTEXES 1 60 | #define configQUEUE_REGISTRY_SIZE 8 61 | #define configCHECK_FOR_STACK_OVERFLOW 0 62 | #define configUSE_RECURSIVE_MUTEXES 1 63 | #define configUSE_MALLOC_FAILED_HOOK 0 64 | #define configUSE_APPLICATION_TASK_TAG 0 65 | #define configUSE_COUNTING_SEMAPHORES 1 66 | #define configGENERATE_RUN_TIME_STATS 0 67 | 68 | /* Software timer definitions. */ 69 | #define configUSE_TIMERS 1 70 | #define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 ) 71 | #define configTIMER_QUEUE_LENGTH 4 72 | #define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE ) 73 | 74 | /* Set the following definitions to 1 to include the API function, or zero 75 | * to exclude the API function. */ 76 | #define INCLUDE_vTaskPrioritySet 1 77 | #define INCLUDE_uxTaskPriorityGet 1 78 | #define INCLUDE_vTaskDelete 1 79 | #define INCLUDE_vTaskCleanUpResources 1 80 | #define INCLUDE_vTaskSuspend 1 81 | #define INCLUDE_vTaskDelayUntil 1 82 | #define INCLUDE_vTaskDelay 1 83 | #define INCLUDE_eTaskGetState 1 84 | #define INCLUDE_xTimerPendFunctionCall 1 85 | #define INCLUDE_xTaskAbortDelay 1 86 | #define INCLUDE_xTaskGetHandle 1 87 | #define INCLUDE_xSemaphoreGetMutexHolder 1 88 | 89 | /* Normal assert() semantics without relying on the provision of an assert.h 90 | * header file. */ 91 | #define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); } 92 | 93 | #endif /* FREERTOS_CONFIG_H */ 94 | -------------------------------------------------------------------------------- /sw/Lab3/FreeRTOSConfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS V202212.00 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * https://www.FreeRTOS.org 23 | * https://github.com/FreeRTOS 24 | * 25 | */ 26 | 27 | #ifndef FREERTOS_CONFIG_H 28 | #define FREERTOS_CONFIG_H 29 | 30 | /*----------------------------------------------------------- 31 | * Application specific definitions. 32 | * 33 | * These definitions should be adjusted for your particular hardware and 34 | * application requirements. 35 | * 36 | * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE 37 | * FreeRTOS API DOCUMENTATION AVAILABLE on the freertos.org web site. 38 | * 39 | * see http://www.freertos.org/a00110.html. 40 | *----------------------------------------------------------*/ 41 | 42 | #define configISR_STACK_SIZE_WORDS ( 500 ) 43 | #define configMTIME_BASE_ADDRESS ( 0x43c00000UL ) 44 | #define configMTIMECMP_BASE_ADDRESS ( 0x43c00008UL ) 45 | 46 | #define configUSE_PREEMPTION 1 47 | #define configUSE_TIME_SLICING 1 48 | #define configUSE_IDLE_HOOK 0 49 | #define configUSE_TICK_HOOK 0 50 | #define configCPU_CLOCK_HZ ( ( uint32_t ) ( 25000000 ) ) /* 100 MHz */ 51 | #define configTICK_RATE_HZ ( ( TickType_t ) 1000 ) /* 1 KHz (TBD) */ 52 | #define configMAX_PRIORITIES ( 15 ) 53 | #define configMINIMAL_STACK_SIZE ( ( uint32_t ) 100 ) /* Can be as low as 60 but some of the demo tasks that use this constant require it to be higher. */ 54 | #define configTOTAL_HEAP_SIZE ( ( size_t ) ( 12 * 1024 ) ) 55 | #define configMAX_TASK_NAME_LEN ( 16 ) 56 | #define configUSE_TRACE_FACILITY 0 57 | #define configUSE_16_BIT_TICKS 0 58 | #define configIDLE_SHOULD_YIELD 1 59 | #define configUSE_MUTEXES 1 60 | #define configQUEUE_REGISTRY_SIZE 8 61 | #define configCHECK_FOR_STACK_OVERFLOW 0 62 | #define configUSE_RECURSIVE_MUTEXES 1 63 | #define configUSE_MALLOC_FAILED_HOOK 0 64 | #define configUSE_APPLICATION_TASK_TAG 0 65 | #define configUSE_COUNTING_SEMAPHORES 1 66 | #define configGENERATE_RUN_TIME_STATS 0 67 | 68 | /* Software timer definitions. */ 69 | #define configUSE_TIMERS 1 70 | #define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 ) 71 | #define configTIMER_QUEUE_LENGTH 4 72 | #define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE ) 73 | 74 | /* Set the following definitions to 1 to include the API function, or zero 75 | * to exclude the API function. */ 76 | #define INCLUDE_vTaskPrioritySet 1 77 | #define INCLUDE_uxTaskPriorityGet 1 78 | #define INCLUDE_vTaskDelete 1 79 | #define INCLUDE_vTaskCleanUpResources 1 80 | #define INCLUDE_vTaskSuspend 1 81 | #define INCLUDE_vTaskDelayUntil 1 82 | #define INCLUDE_vTaskDelay 1 83 | #define INCLUDE_eTaskGetState 1 84 | #define INCLUDE_xTimerPendFunctionCall 1 85 | #define INCLUDE_xTaskAbortDelay 1 86 | #define INCLUDE_xTaskGetHandle 1 87 | #define INCLUDE_xSemaphoreGetMutexHolder 1 88 | 89 | /* Normal assert() semantics without relying on the provision of an assert.h 90 | * header file. */ 91 | #define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); } 92 | 93 | #endif /* FREERTOS_CONFIG_H */ 94 | -------------------------------------------------------------------------------- /sw/Lab2/task.h.txt: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS Kernel V10.5.1 3 | * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | * this software and associated documentation files (the "Software"), to deal in 9 | * the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | * the Software, and to permit persons to whom the Software is furnished to do so, 12 | * subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | * 24 | * https://www.FreeRTOS.org 25 | * https://github.com/FreeRTOS 26 | * 27 | */ 28 | 29 | 30 | #ifndef INC_TASK_H 31 | #define INC_TASK_H 32 | 33 | #ifndef INC_FREERTOS_H 34 | #error "include FreeRTOS.h must appear in source files before include task.h" 35 | #endif 36 | 37 | #include "list.h" 38 | 39 | /* *INDENT-OFF* */ 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | /* *INDENT-ON* */ 44 | 45 | //extern UART_HandleTypeDef huart2; // for USART2 46 | void Taskmonitor(void); 47 | /*----------------------------------------------------------- 48 | * MACROS AND DEFINITIONS 49 | *----------------------------------------------------------*/ 50 | 51 | /* 52 | * If tskKERNEL_VERSION_NUMBER ends with + it represents the version in development 53 | * after the numbered release. 54 | * 55 | * The tskKERNEL_VERSION_MAJOR, tskKERNEL_VERSION_MINOR, tskKERNEL_VERSION_BUILD 56 | * values will reflect the last released version number. 57 | */ 58 | #define tskKERNEL_VERSION_NUMBER "V10.5.1" 59 | #define tskKERNEL_VERSION_MAJOR 10 60 | #define tskKERNEL_VERSION_MINOR 5 61 | #define tskKERNEL_VERSION_BUILD 1 62 | 63 | /* MPU region parameters passed in ulParameters 64 | * of MemoryRegion_t struct. */ 65 | #define tskMPU_REGION_READ_ONLY ( 1UL << 0UL ) 66 | #define tskMPU_REGION_READ_WRITE ( 1UL << 1UL ) 67 | #define tskMPU_REGION_EXECUTE_NEVER ( 1UL << 2UL ) 68 | #define tskMPU_REGION_NORMAL_MEMORY ( 1UL << 3UL ) 69 | #define tskMPU_REGION_DEVICE_MEMORY ( 1UL << 4UL ) 70 | 71 | /* The direct to task notification feature used to have only a single notification 72 | * per task. Now there is an array of notifications per task that is dimensioned by 73 | * configTASK_NOTIFICATION_ARRAY_ENTRIES. For backward compatibility, any use of the 74 | * original direct to task notification defaults to using the first index in the 75 | * array. */ 76 | #define tskDEFAULT_INDEX_TO_NOTIFY ( 0 ) 77 | 78 | /** 79 | * task. h 80 | * 81 | * Type by which tasks are referenced. For example, a call to xTaskCreate 82 | * returns (via a pointer parameter) an TaskHandle_t variable that can then 83 | * be used as a parameter to vTaskDelete to delete the task. 84 | * 85 | * \defgroup TaskHandle_t TaskHandle_t 86 | * \ingroup Tasks 87 | */ 88 | struct tskTaskControlBlock; /* The old naming convention is used to prevent breaking kernel aware debuggers. */ 89 | typedef struct tskTaskControlBlock * TaskHandle_t; 90 | 91 | /* 92 | * Defines the prototype to which the application task hook function must 93 | * conform. 94 | */ 95 | typedef BaseType_t (* TaskHookFunction_t)( void * ); 96 | 97 | /* Task states returned by eTaskGetState. */ 98 | typedef enum 99 | { 100 | eRunning = 0, /* A task is querying the state of itself, so must be running. */ 101 | eReady, /* The task being queried is in a ready or pending ready list. */ 102 | eBlocked, /* The task being queried is in the Blocked state. */ 103 | eSuspended, /* The task being queried is in the Suspended state, or is in the Blocked state with an infinite time out. */ 104 | eDeleted, /* The task being queried has been deleted, but its TCB has not yet been freed. */ 105 | eInvalid /* Used as an 'invalid state' value. */ 106 | } eTaskState; 107 | 108 | /* Actions that can be performed when vTaskNotify() is called. */ 109 | typedef enum 110 | { 111 | eNoAction = 0, /* Notify the task without updating its notify value. */ 112 | eSetBits, /* Set bits in the task's notification value. */ 113 | eIncrement, /* Increment the task's notification value. */ 114 | eSetValueWithOverwrite, /* Set the task's notification value to a specific value even if the previous value has not yet been read by the task. */ 115 | eSetValueWithoutOverwrite /* Set the task's notification value if the previous value has been read by the task. */ 116 | } eNotifyAction; 117 | 118 | /* 119 | * Used internally only. 120 | */ 121 | typedef struct xTIME_OUT 122 | { 123 | BaseType_t xOverflowCount; 124 | TickType_t xTimeOnEntering; 125 | } TimeOut_t; 126 | 127 | /* 128 | * Defines the memory ranges allocated to the task when an MPU is used. 129 | */ 130 | typedef struct xMEMORY_REGION 131 | { 132 | void * pvBaseAddress; 133 | uint32_t ulLengthInBytes; 134 | uint32_t ulParameters; 135 | } MemoryRegion_t; 136 | 137 | /* 138 | * Parameters required to create an MPU protected task. 139 | */ 140 | typedef struct xTASK_PARAMETERS 141 | { 142 | TaskFunction_t pvTaskCode; 143 | const char * pcName; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ 144 | configSTACK_DEPTH_TYPE usStackDepth; 145 | void * pvParameters; 146 | UBaseType_t uxPriority; 147 | StackType_t * puxStackBuffer; 148 | MemoryRegion_t xRegions[ portNUM_CONFIGURABLE_REGIONS ]; 149 | #if ( ( portUSING_MPU_WRAPPERS == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) ) 150 | StaticTask_t * const pxTaskBuffer; 151 | #endif 152 | } TaskParameters_t; 153 | 154 | /* Used with the uxTaskGetSystemState() function to return the state of each task 155 | * in the system. */ 156 | typedef struct xTASK_STATUS 157 | { 158 | TaskHandle_t xHandle; /* The handle of the task to which the rest of the information in the structure relates. */ 159 | const char * pcTaskName; /* A pointer to the task's name. This value will be invalid if the task was deleted since the structure was populated! */ /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ 160 | UBaseType_t xTaskNumber; /* A number unique to the task. */ 161 | eTaskState eCurrentState; /* The state in which the task existed when the structure was populated. */ 162 | UBaseType_t uxCurrentPriority; /* The priority at which the task was running (may be inherited) when the structure was populated. */ 163 | UBaseType_t uxBasePriority; /* The priority to which the task will return if the task's current priority has been inherited to avoid unbounded priority inversion when obtaining a mutex. Only valid if configUSE_MUTEXES is defined as 1 in FreeRTOSConfig.h. */ 164 | configRUN_TIME_COUNTER_TYPE ulRunTimeCounter; /* The total run time allocated to the task so far, as defined by the run time stats clock. See https://www.FreeRTOS.org/rtos-run-time-stats.html. Only valid when configGENERATE_RUN_TIME_STATS is defined as 1 in FreeRTOSConfig.h. */ 165 | StackType_t * pxStackBase; /* Points to the lowest address of the task's stack area. */ 166 | #if ( ( portSTACK_GROWTH > 0 ) && ( configRECORD_STACK_HIGH_ADDRESS == 1 ) ) 167 | StackType_t * pxTopOfStack; /* Points to the top address of the task's stack area. */ 168 | StackType_t * pxEndOfStack; /* Points to the end address of the task's stack area. */ 169 | #endif 170 | configSTACK_DEPTH_TYPE usStackHighWaterMark; /* The minimum amount of stack space that has remained for the task since the task was created. The closer this value is to zero the closer the task has come to overflowing its stack. */ 171 | } TaskStatus_t; 172 | 173 | /* Possible return values for eTaskConfirmSleepModeStatus(). */ 174 | typedef enum 175 | { 176 | eAbortSleep = 0, /* A task has been made ready or a context switch pended since portSUPPRESS_TICKS_AND_SLEEP() was called - abort entering a sleep mode. */ 177 | eStandardSleep, /* Enter a sleep mode that will not last any longer than the expected idle time. */ 178 | #if ( INCLUDE_vTaskSuspend == 1 ) 179 | eNoTasksWaitingTimeout /* No tasks are waiting for a timeout so it is safe to enter a sleep mode that can only be exited by an external interrupt. */ 180 | #endif /* INCLUDE_vTaskSuspend */ 181 | } eSleepModeStatus; 182 | 183 | /** 184 | * Defines the priority used by the idle task. This must not be modified. 185 | * 186 | * \ingroup TaskUtils 187 | */ 188 | #define tskIDLE_PRIORITY ( ( UBaseType_t ) 0U ) 189 | 190 | /** 191 | * task. h 192 | * 193 | * Macro for forcing a context switch. 194 | * 195 | * \defgroup taskYIELD taskYIELD 196 | * \ingroup SchedulerControl 197 | */ 198 | #define taskYIELD() portYIELD() 199 | 200 | /** 201 | * task. h 202 | * 203 | * Macro to mark the start of a critical code region. Preemptive context 204 | * switches cannot occur when in a critical region. 205 | * 206 | * NOTE: This may alter the stack (depending on the portable implementation) 207 | * so must be used with care! 208 | * 209 | * \defgroup taskENTER_CRITICAL taskENTER_CRITICAL 210 | * \ingroup SchedulerControl 211 | */ 212 | #define taskENTER_CRITICAL() portENTER_CRITICAL() 213 | #define taskENTER_CRITICAL_FROM_ISR() portSET_INTERRUPT_MASK_FROM_ISR() 214 | 215 | /** 216 | * task. h 217 | * 218 | * Macro to mark the end of a critical code region. Preemptive context 219 | * switches cannot occur when in a critical region. 220 | * 221 | * NOTE: This may alter the stack (depending on the portable implementation) 222 | * so must be used with care! 223 | * 224 | * \defgroup taskEXIT_CRITICAL taskEXIT_CRITICAL 225 | * \ingroup SchedulerControl 226 | */ 227 | #define taskEXIT_CRITICAL() portEXIT_CRITICAL() 228 | #define taskEXIT_CRITICAL_FROM_ISR( x ) portCLEAR_INTERRUPT_MASK_FROM_ISR( x ) 229 | 230 | /** 231 | * task. h 232 | * 233 | * Macro to disable all maskable interrupts. 234 | * 235 | * \defgroup taskDISABLE_INTERRUPTS taskDISABLE_INTERRUPTS 236 | * \ingroup SchedulerControl 237 | */ 238 | #define taskDISABLE_INTERRUPTS() portDISABLE_INTERRUPTS() 239 | 240 | /** 241 | * task. h 242 | * 243 | * Macro to enable microcontroller interrupts. 244 | * 245 | * \defgroup taskENABLE_INTERRUPTS taskENABLE_INTERRUPTS 246 | * \ingroup SchedulerControl 247 | */ 248 | #define taskENABLE_INTERRUPTS() portENABLE_INTERRUPTS() 249 | 250 | /* Definitions returned by xTaskGetSchedulerState(). taskSCHEDULER_SUSPENDED is 251 | * 0 to generate more optimal code when configASSERT() is defined as the constant 252 | * is used in assert() statements. */ 253 | #define taskSCHEDULER_SUSPENDED ( ( BaseType_t ) 0 ) 254 | #define taskSCHEDULER_NOT_STARTED ( ( BaseType_t ) 1 ) 255 | #define taskSCHEDULER_RUNNING ( ( BaseType_t ) 2 ) 256 | 257 | 258 | /*----------------------------------------------------------- 259 | * TASK CREATION API 260 | *----------------------------------------------------------*/ 261 | 262 | /** 263 | * task. h 264 | * @code{c} 265 | * BaseType_t xTaskCreate( 266 | * TaskFunction_t pxTaskCode, 267 | * const char *pcName, 268 | * configSTACK_DEPTH_TYPE usStackDepth, 269 | * void *pvParameters, 270 | * UBaseType_t uxPriority, 271 | * TaskHandle_t *pxCreatedTask 272 | * ); 273 | * @endcode 274 | * 275 | * Create a new task and add it to the list of tasks that are ready to run. 276 | * 277 | * Internally, within the FreeRTOS implementation, tasks use two blocks of 278 | * memory. The first block is used to hold the task's data structures. The 279 | * second block is used by the task as its stack. If a task is created using 280 | * xTaskCreate() then both blocks of memory are automatically dynamically 281 | * allocated inside the xTaskCreate() function. (see 282 | * https://www.FreeRTOS.org/a00111.html). If a task is created using 283 | * xTaskCreateStatic() then the application writer must provide the required 284 | * memory. xTaskCreateStatic() therefore allows a task to be created without 285 | * using any dynamic memory allocation. 286 | * 287 | * See xTaskCreateStatic() for a version that does not use any dynamic memory 288 | * allocation. 289 | * 290 | * xTaskCreate() can only be used to create a task that has unrestricted 291 | * access to the entire microcontroller memory map. Systems that include MPU 292 | * support can alternatively create an MPU constrained task using 293 | * xTaskCreateRestricted(). 294 | * 295 | * @param pxTaskCode Pointer to the task entry function. Tasks 296 | * must be implemented to never return (i.e. continuous loop). 297 | * 298 | * @param pcName A descriptive name for the task. This is mainly used to 299 | * facilitate debugging. Max length defined by configMAX_TASK_NAME_LEN - default 300 | * is 16. 301 | * 302 | * @param usStackDepth The size of the task stack specified as the number of 303 | * variables the stack can hold - not the number of bytes. For example, if 304 | * the stack is 16 bits wide and usStackDepth is defined as 100, 200 bytes 305 | * will be allocated for stack storage. 306 | * 307 | * @param pvParameters Pointer that will be used as the parameter for the task 308 | * being created. 309 | * 310 | * @param uxPriority The priority at which the task should run. Systems that 311 | * include MPU support can optionally create tasks in a privileged (system) 312 | * mode by setting bit portPRIVILEGE_BIT of the priority parameter. For 313 | * example, to create a privileged task at priority 2 the uxPriority parameter 314 | * should be set to ( 2 | portPRIVILEGE_BIT ). 315 | * 316 | * @param pxCreatedTask Used to pass back a handle by which the created task 317 | * can be referenced. 318 | * 319 | * @return pdPASS if the task was successfully created and added to a ready 320 | * list, otherwise an error code defined in the file projdefs.h 321 | * 322 | * Example usage: 323 | * @code{c} 324 | * // Task to be created. 325 | * void vTaskCode( void * pvParameters ) 326 | * { 327 | * for( ;; ) 328 | * { 329 | * // Task code goes here. 330 | * } 331 | * } 332 | * 333 | * // Function that creates a task. 334 | * void vOtherFunction( void ) 335 | * { 336 | * static uint8_t ucParameterToPass; 337 | * TaskHandle_t xHandle = NULL; 338 | * 339 | * // Create the task, storing the handle. Note that the passed parameter ucParameterToPass 340 | * // must exist for the lifetime of the task, so in this case is declared static. If it was just an 341 | * // an automatic stack variable it might no longer exist, or at least have been corrupted, by the time 342 | * // the new task attempts to access it. 343 | * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, &ucParameterToPass, tskIDLE_PRIORITY, &xHandle ); 344 | * configASSERT( xHandle ); 345 | * 346 | * // Use the handle to delete the task. 347 | * if( xHandle != NULL ) 348 | * { 349 | * vTaskDelete( xHandle ); 350 | * } 351 | * } 352 | * @endcode 353 | * \defgroup xTaskCreate xTaskCreate 354 | * \ingroup Tasks 355 | */ 356 | #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) 357 | BaseType_t xTaskCreate( TaskFunction_t pxTaskCode, 358 | const char * const pcName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ 359 | const configSTACK_DEPTH_TYPE usStackDepth, 360 | void * const pvParameters, 361 | UBaseType_t uxPriority, 362 | TaskHandle_t * const pxCreatedTask ) PRIVILEGED_FUNCTION; 363 | #endif 364 | 365 | /** 366 | * task. h 367 | * @code{c} 368 | * TaskHandle_t xTaskCreateStatic( TaskFunction_t pxTaskCode, 369 | * const char *pcName, 370 | * uint32_t ulStackDepth, 371 | * void *pvParameters, 372 | * UBaseType_t uxPriority, 373 | * StackType_t *puxStackBuffer, 374 | * StaticTask_t *pxTaskBuffer ); 375 | * @endcode 376 | * 377 | * Create a new task and add it to the list of tasks that are ready to run. 378 | * 379 | * Internally, within the FreeRTOS implementation, tasks use two blocks of 380 | * memory. The first block is used to hold the task's data structures. The 381 | * second block is used by the task as its stack. If a task is created using 382 | * xTaskCreate() then both blocks of memory are automatically dynamically 383 | * allocated inside the xTaskCreate() function. (see 384 | * https://www.FreeRTOS.org/a00111.html). If a task is created using 385 | * xTaskCreateStatic() then the application writer must provide the required 386 | * memory. xTaskCreateStatic() therefore allows a task to be created without 387 | * using any dynamic memory allocation. 388 | * 389 | * @param pxTaskCode Pointer to the task entry function. Tasks 390 | * must be implemented to never return (i.e. continuous loop). 391 | * 392 | * @param pcName A descriptive name for the task. This is mainly used to 393 | * facilitate debugging. The maximum length of the string is defined by 394 | * configMAX_TASK_NAME_LEN in FreeRTOSConfig.h. 395 | * 396 | * @param ulStackDepth The size of the task stack specified as the number of 397 | * variables the stack can hold - not the number of bytes. For example, if 398 | * the stack is 32-bits wide and ulStackDepth is defined as 100 then 400 bytes 399 | * will be allocated for stack storage. 400 | * 401 | * @param pvParameters Pointer that will be used as the parameter for the task 402 | * being created. 403 | * 404 | * @param uxPriority The priority at which the task will run. 405 | * 406 | * @param puxStackBuffer Must point to a StackType_t array that has at least 407 | * ulStackDepth indexes - the array will then be used as the task's stack, 408 | * removing the need for the stack to be allocated dynamically. 409 | * 410 | * @param pxTaskBuffer Must point to a variable of type StaticTask_t, which will 411 | * then be used to hold the task's data structures, removing the need for the 412 | * memory to be allocated dynamically. 413 | * 414 | * @return If neither puxStackBuffer nor pxTaskBuffer are NULL, then the task 415 | * will be created and a handle to the created task is returned. If either 416 | * puxStackBuffer or pxTaskBuffer are NULL then the task will not be created and 417 | * NULL is returned. 418 | * 419 | * Example usage: 420 | * @code{c} 421 | * 422 | * // Dimensions of the buffer that the task being created will use as its stack. 423 | * // NOTE: This is the number of words the stack will hold, not the number of 424 | * // bytes. For example, if each stack item is 32-bits, and this is set to 100, 425 | * // then 400 bytes (100 * 32-bits) will be allocated. 426 | #define STACK_SIZE 200 427 | * 428 | * // Structure that will hold the TCB of the task being created. 429 | * StaticTask_t xTaskBuffer; 430 | * 431 | * // Buffer that the task being created will use as its stack. Note this is 432 | * // an array of StackType_t variables. The size of StackType_t is dependent on 433 | * // the RTOS port. 434 | * StackType_t xStack[ STACK_SIZE ]; 435 | * 436 | * // Function that implements the task being created. 437 | * void vTaskCode( void * pvParameters ) 438 | * { 439 | * // The parameter value is expected to be 1 as 1 is passed in the 440 | * // pvParameters value in the call to xTaskCreateStatic(). 441 | * configASSERT( ( uint32_t ) pvParameters == 1UL ); 442 | * 443 | * for( ;; ) 444 | * { 445 | * // Task code goes here. 446 | * } 447 | * } 448 | * 449 | * // Function that creates a task. 450 | * void vOtherFunction( void ) 451 | * { 452 | * TaskHandle_t xHandle = NULL; 453 | * 454 | * // Create the task without using any dynamic memory allocation. 455 | * xHandle = xTaskCreateStatic( 456 | * vTaskCode, // Function that implements the task. 457 | * "NAME", // Text name for the task. 458 | * STACK_SIZE, // Stack size in words, not bytes. 459 | * ( void * ) 1, // Parameter passed into the task. 460 | * tskIDLE_PRIORITY,// Priority at which the task is created. 461 | * xStack, // Array to use as the task's stack. 462 | * &xTaskBuffer ); // Variable to hold the task's data structure. 463 | * 464 | * // puxStackBuffer and pxTaskBuffer were not NULL, so the task will have 465 | * // been created, and xHandle will be the task's handle. Use the handle 466 | * // to suspend the task. 467 | * vTaskSuspend( xHandle ); 468 | * } 469 | * @endcode 470 | * \defgroup xTaskCreateStatic xTaskCreateStatic 471 | * \ingroup Tasks 472 | */ 473 | #if ( configSUPPORT_STATIC_ALLOCATION == 1 ) 474 | TaskHandle_t xTaskCreateStatic( TaskFunction_t pxTaskCode, 475 | const char * const pcName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ 476 | const uint32_t ulStackDepth, 477 | void * const pvParameters, 478 | UBaseType_t uxPriority, 479 | StackType_t * const puxStackBuffer, 480 | StaticTask_t * const pxTaskBuffer ) PRIVILEGED_FUNCTION; 481 | #endif /* configSUPPORT_STATIC_ALLOCATION */ 482 | 483 | /** 484 | * task. h 485 | * @code{c} 486 | * BaseType_t xTaskCreateRestricted( TaskParameters_t *pxTaskDefinition, TaskHandle_t *pxCreatedTask ); 487 | * @endcode 488 | * 489 | * Only available when configSUPPORT_DYNAMIC_ALLOCATION is set to 1. 490 | * 491 | * xTaskCreateRestricted() should only be used in systems that include an MPU 492 | * implementation. 493 | * 494 | * Create a new task and add it to the list of tasks that are ready to run. 495 | * The function parameters define the memory regions and associated access 496 | * permissions allocated to the task. 497 | * 498 | * See xTaskCreateRestrictedStatic() for a version that does not use any 499 | * dynamic memory allocation. 500 | * 501 | * @param pxTaskDefinition Pointer to a structure that contains a member 502 | * for each of the normal xTaskCreate() parameters (see the xTaskCreate() API 503 | * documentation) plus an optional stack buffer and the memory region 504 | * definitions. 505 | * 506 | * @param pxCreatedTask Used to pass back a handle by which the created task 507 | * can be referenced. 508 | * 509 | * @return pdPASS if the task was successfully created and added to a ready 510 | * list, otherwise an error code defined in the file projdefs.h 511 | * 512 | * Example usage: 513 | * @code{c} 514 | * // Create an TaskParameters_t structure that defines the task to be created. 515 | * static const TaskParameters_t xCheckTaskParameters = 516 | * { 517 | * vATask, // pvTaskCode - the function that implements the task. 518 | * "ATask", // pcName - just a text name for the task to assist debugging. 519 | * 100, // usStackDepth - the stack size DEFINED IN WORDS. 520 | * NULL, // pvParameters - passed into the task function as the function parameters. 521 | * ( 1UL | portPRIVILEGE_BIT ),// uxPriority - task priority, set the portPRIVILEGE_BIT if the task should run in a privileged state. 522 | * cStackBuffer,// puxStackBuffer - the buffer to be used as the task stack. 523 | * 524 | * // xRegions - Allocate up to three separate memory regions for access by 525 | * // the task, with appropriate access permissions. Different processors have 526 | * // different memory alignment requirements - refer to the FreeRTOS documentation 527 | * // for full information. 528 | * { 529 | * // Base address Length Parameters 530 | * { cReadWriteArray, 32, portMPU_REGION_READ_WRITE }, 531 | * { cReadOnlyArray, 32, portMPU_REGION_READ_ONLY }, 532 | * { cPrivilegedOnlyAccessArray, 128, portMPU_REGION_PRIVILEGED_READ_WRITE } 533 | * } 534 | * }; 535 | * 536 | * int main( void ) 537 | * { 538 | * TaskHandle_t xHandle; 539 | * 540 | * // Create a task from the const structure defined above. The task handle 541 | * // is requested (the second parameter is not NULL) but in this case just for 542 | * // demonstration purposes as its not actually used. 543 | * xTaskCreateRestricted( &xRegTest1Parameters, &xHandle ); 544 | * 545 | * // Start the scheduler. 546 | * vTaskStartScheduler(); 547 | * 548 | * // Will only get here if there was insufficient memory to create the idle 549 | * // and/or timer task. 550 | * for( ;; ); 551 | * } 552 | * @endcode 553 | * \defgroup xTaskCreateRestricted xTaskCreateRestricted 554 | * \ingroup Tasks 555 | */ 556 | #if ( portUSING_MPU_WRAPPERS == 1 ) 557 | BaseType_t xTaskCreateRestricted( const TaskParameters_t * const pxTaskDefinition, 558 | TaskHandle_t * pxCreatedTask ) PRIVILEGED_FUNCTION; 559 | #endif 560 | 561 | /** 562 | * task. h 563 | * @code{c} 564 | * BaseType_t xTaskCreateRestrictedStatic( TaskParameters_t *pxTaskDefinition, TaskHandle_t *pxCreatedTask ); 565 | * @endcode 566 | * 567 | * Only available when configSUPPORT_STATIC_ALLOCATION is set to 1. 568 | * 569 | * xTaskCreateRestrictedStatic() should only be used in systems that include an 570 | * MPU implementation. 571 | * 572 | * Internally, within the FreeRTOS implementation, tasks use two blocks of 573 | * memory. The first block is used to hold the task's data structures. The 574 | * second block is used by the task as its stack. If a task is created using 575 | * xTaskCreateRestricted() then the stack is provided by the application writer, 576 | * and the memory used to hold the task's data structure is automatically 577 | * dynamically allocated inside the xTaskCreateRestricted() function. If a task 578 | * is created using xTaskCreateRestrictedStatic() then the application writer 579 | * must provide the memory used to hold the task's data structures too. 580 | * xTaskCreateRestrictedStatic() therefore allows a memory protected task to be 581 | * created without using any dynamic memory allocation. 582 | * 583 | * @param pxTaskDefinition Pointer to a structure that contains a member 584 | * for each of the normal xTaskCreate() parameters (see the xTaskCreate() API 585 | * documentation) plus an optional stack buffer and the memory region 586 | * definitions. If configSUPPORT_STATIC_ALLOCATION is set to 1 the structure 587 | * contains an additional member, which is used to point to a variable of type 588 | * StaticTask_t - which is then used to hold the task's data structure. 589 | * 590 | * @param pxCreatedTask Used to pass back a handle by which the created task 591 | * can be referenced. 592 | * 593 | * @return pdPASS if the task was successfully created and added to a ready 594 | * list, otherwise an error code defined in the file projdefs.h 595 | * 596 | * Example usage: 597 | * @code{c} 598 | * // Create an TaskParameters_t structure that defines the task to be created. 599 | * // The StaticTask_t variable is only included in the structure when 600 | * // configSUPPORT_STATIC_ALLOCATION is set to 1. The PRIVILEGED_DATA macro can 601 | * // be used to force the variable into the RTOS kernel's privileged data area. 602 | * static PRIVILEGED_DATA StaticTask_t xTaskBuffer; 603 | * static const TaskParameters_t xCheckTaskParameters = 604 | * { 605 | * vATask, // pvTaskCode - the function that implements the task. 606 | * "ATask", // pcName - just a text name for the task to assist debugging. 607 | * 100, // usStackDepth - the stack size DEFINED IN WORDS. 608 | * NULL, // pvParameters - passed into the task function as the function parameters. 609 | * ( 1UL | portPRIVILEGE_BIT ),// uxPriority - task priority, set the portPRIVILEGE_BIT if the task should run in a privileged state. 610 | * cStackBuffer,// puxStackBuffer - the buffer to be used as the task stack. 611 | * 612 | * // xRegions - Allocate up to three separate memory regions for access by 613 | * // the task, with appropriate access permissions. Different processors have 614 | * // different memory alignment requirements - refer to the FreeRTOS documentation 615 | * // for full information. 616 | * { 617 | * // Base address Length Parameters 618 | * { cReadWriteArray, 32, portMPU_REGION_READ_WRITE }, 619 | * { cReadOnlyArray, 32, portMPU_REGION_READ_ONLY }, 620 | * { cPrivilegedOnlyAccessArray, 128, portMPU_REGION_PRIVILEGED_READ_WRITE } 621 | * } 622 | * 623 | * &xTaskBuffer; // Holds the task's data structure. 624 | * }; 625 | * 626 | * int main( void ) 627 | * { 628 | * TaskHandle_t xHandle; 629 | * 630 | * // Create a task from the const structure defined above. The task handle 631 | * // is requested (the second parameter is not NULL) but in this case just for 632 | * // demonstration purposes as its not actually used. 633 | * xTaskCreateRestrictedStatic( &xRegTest1Parameters, &xHandle ); 634 | * 635 | * // Start the scheduler. 636 | * vTaskStartScheduler(); 637 | * 638 | * // Will only get here if there was insufficient memory to create the idle 639 | * // and/or timer task. 640 | * for( ;; ); 641 | * } 642 | * @endcode 643 | * \defgroup xTaskCreateRestrictedStatic xTaskCreateRestrictedStatic 644 | * \ingroup Tasks 645 | */ 646 | #if ( ( portUSING_MPU_WRAPPERS == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) ) 647 | BaseType_t xTaskCreateRestrictedStatic( const TaskParameters_t * const pxTaskDefinition, 648 | TaskHandle_t * pxCreatedTask ) PRIVILEGED_FUNCTION; 649 | #endif 650 | 651 | /** 652 | * task. h 653 | * @code{c} 654 | * void vTaskAllocateMPURegions( TaskHandle_t xTask, const MemoryRegion_t * const pxRegions ); 655 | * @endcode 656 | * 657 | * Memory regions are assigned to a restricted task when the task is created by 658 | * a call to xTaskCreateRestricted(). These regions can be redefined using 659 | * vTaskAllocateMPURegions(). 660 | * 661 | * @param xTask The handle of the task being updated. 662 | * 663 | * @param xRegions A pointer to a MemoryRegion_t structure that contains the 664 | * new memory region definitions. 665 | * 666 | * Example usage: 667 | * @code{c} 668 | * // Define an array of MemoryRegion_t structures that configures an MPU region 669 | * // allowing read/write access for 1024 bytes starting at the beginning of the 670 | * // ucOneKByte array. The other two of the maximum 3 definable regions are 671 | * // unused so set to zero. 672 | * static const MemoryRegion_t xAltRegions[ portNUM_CONFIGURABLE_REGIONS ] = 673 | * { 674 | * // Base address Length Parameters 675 | * { ucOneKByte, 1024, portMPU_REGION_READ_WRITE }, 676 | * { 0, 0, 0 }, 677 | * { 0, 0, 0 } 678 | * }; 679 | * 680 | * void vATask( void *pvParameters ) 681 | * { 682 | * // This task was created such that it has access to certain regions of 683 | * // memory as defined by the MPU configuration. At some point it is 684 | * // desired that these MPU regions are replaced with that defined in the 685 | * // xAltRegions const struct above. Use a call to vTaskAllocateMPURegions() 686 | * // for this purpose. NULL is used as the task handle to indicate that this 687 | * // function should modify the MPU regions of the calling task. 688 | * vTaskAllocateMPURegions( NULL, xAltRegions ); 689 | * 690 | * // Now the task can continue its function, but from this point on can only 691 | * // access its stack and the ucOneKByte array (unless any other statically 692 | * // defined or shared regions have been declared elsewhere). 693 | * } 694 | * @endcode 695 | * \defgroup vTaskAllocateMPURegions vTaskAllocateMPURegions 696 | * \ingroup Tasks 697 | */ 698 | void vTaskAllocateMPURegions( TaskHandle_t xTask, 699 | const MemoryRegion_t * const pxRegions ) PRIVILEGED_FUNCTION; 700 | 701 | /** 702 | * task. h 703 | * @code{c} 704 | * void vTaskDelete( TaskHandle_t xTaskToDelete ); 705 | * @endcode 706 | * 707 | * INCLUDE_vTaskDelete must be defined as 1 for this function to be available. 708 | * See the configuration section for more information. 709 | * 710 | * Remove a task from the RTOS real time kernel's management. The task being 711 | * deleted will be removed from all ready, blocked, suspended and event lists. 712 | * 713 | * NOTE: The idle task is responsible for freeing the kernel allocated 714 | * memory from tasks that have been deleted. It is therefore important that 715 | * the idle task is not starved of microcontroller processing time if your 716 | * application makes any calls to vTaskDelete (). Memory allocated by the 717 | * task code is not automatically freed, and should be freed before the task 718 | * is deleted. 719 | * 720 | * See the demo application file death.c for sample code that utilises 721 | * vTaskDelete (). 722 | * 723 | * @param xTaskToDelete The handle of the task to be deleted. Passing NULL will 724 | * cause the calling task to be deleted. 725 | * 726 | * Example usage: 727 | * @code{c} 728 | * void vOtherFunction( void ) 729 | * { 730 | * TaskHandle_t xHandle; 731 | * 732 | * // Create the task, storing the handle. 733 | * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle ); 734 | * 735 | * // Use the handle to delete the task. 736 | * vTaskDelete( xHandle ); 737 | * } 738 | * @endcode 739 | * \defgroup vTaskDelete vTaskDelete 740 | * \ingroup Tasks 741 | */ 742 | void vTaskDelete( TaskHandle_t xTaskToDelete ) PRIVILEGED_FUNCTION; 743 | 744 | /*----------------------------------------------------------- 745 | * TASK CONTROL API 746 | *----------------------------------------------------------*/ 747 | 748 | /** 749 | * task. h 750 | * @code{c} 751 | * void vTaskDelay( const TickType_t xTicksToDelay ); 752 | * @endcode 753 | * 754 | * Delay a task for a given number of ticks. The actual time that the 755 | * task remains blocked depends on the tick rate. The constant 756 | * portTICK_PERIOD_MS can be used to calculate real time from the tick 757 | * rate - with the resolution of one tick period. 758 | * 759 | * INCLUDE_vTaskDelay must be defined as 1 for this function to be available. 760 | * See the configuration section for more information. 761 | * 762 | * 763 | * vTaskDelay() specifies a time at which the task wishes to unblock relative to 764 | * the time at which vTaskDelay() is called. For example, specifying a block 765 | * period of 100 ticks will cause the task to unblock 100 ticks after 766 | * vTaskDelay() is called. vTaskDelay() does not therefore provide a good method 767 | * of controlling the frequency of a periodic task as the path taken through the 768 | * code, as well as other task and interrupt activity, will affect the frequency 769 | * at which vTaskDelay() gets called and therefore the time at which the task 770 | * next executes. See xTaskDelayUntil() for an alternative API function designed 771 | * to facilitate fixed frequency execution. It does this by specifying an 772 | * absolute time (rather than a relative time) at which the calling task should 773 | * unblock. 774 | * 775 | * @param xTicksToDelay The amount of time, in tick periods, that 776 | * the calling task should block. 777 | * 778 | * Example usage: 779 | * 780 | * void vTaskFunction( void * pvParameters ) 781 | * { 782 | * // Block for 500ms. 783 | * const TickType_t xDelay = 500 / portTICK_PERIOD_MS; 784 | * 785 | * for( ;; ) 786 | * { 787 | * // Simply toggle the LED every 500ms, blocking between each toggle. 788 | * vToggleLED(); 789 | * vTaskDelay( xDelay ); 790 | * } 791 | * } 792 | * 793 | * \defgroup vTaskDelay vTaskDelay 794 | * \ingroup TaskCtrl 795 | */ 796 | void vTaskDelay( const TickType_t xTicksToDelay ) PRIVILEGED_FUNCTION; 797 | 798 | /** 799 | * task. h 800 | * @code{c} 801 | * BaseType_t xTaskDelayUntil( TickType_t *pxPreviousWakeTime, const TickType_t xTimeIncrement ); 802 | * @endcode 803 | * 804 | * INCLUDE_xTaskDelayUntil must be defined as 1 for this function to be available. 805 | * See the configuration section for more information. 806 | * 807 | * Delay a task until a specified time. This function can be used by periodic 808 | * tasks to ensure a constant execution frequency. 809 | * 810 | * This function differs from vTaskDelay () in one important aspect: vTaskDelay () will 811 | * cause a task to block for the specified number of ticks from the time vTaskDelay () is 812 | * called. It is therefore difficult to use vTaskDelay () by itself to generate a fixed 813 | * execution frequency as the time between a task starting to execute and that task 814 | * calling vTaskDelay () may not be fixed [the task may take a different path though the 815 | * code between calls, or may get interrupted or preempted a different number of times 816 | * each time it executes]. 817 | * 818 | * Whereas vTaskDelay () specifies a wake time relative to the time at which the function 819 | * is called, xTaskDelayUntil () specifies the absolute (exact) time at which it wishes to 820 | * unblock. 821 | * 822 | * The macro pdMS_TO_TICKS() can be used to calculate the number of ticks from a 823 | * time specified in milliseconds with a resolution of one tick period. 824 | * 825 | * @param pxPreviousWakeTime Pointer to a variable that holds the time at which the 826 | * task was last unblocked. The variable must be initialised with the current time 827 | * prior to its first use (see the example below). Following this the variable is 828 | * automatically updated within xTaskDelayUntil (). 829 | * 830 | * @param xTimeIncrement The cycle time period. The task will be unblocked at 831 | * time *pxPreviousWakeTime + xTimeIncrement. Calling xTaskDelayUntil with the 832 | * same xTimeIncrement parameter value will cause the task to execute with 833 | * a fixed interface period. 834 | * 835 | * @return Value which can be used to check whether the task was actually delayed. 836 | * Will be pdTRUE if the task way delayed and pdFALSE otherwise. A task will not 837 | * be delayed if the next expected wake time is in the past. 838 | * 839 | * Example usage: 840 | * @code{c} 841 | * // Perform an action every 10 ticks. 842 | * void vTaskFunction( void * pvParameters ) 843 | * { 844 | * TickType_t xLastWakeTime; 845 | * const TickType_t xFrequency = 10; 846 | * BaseType_t xWasDelayed; 847 | * 848 | * // Initialise the xLastWakeTime variable with the current time. 849 | * xLastWakeTime = xTaskGetTickCount (); 850 | * for( ;; ) 851 | * { 852 | * // Wait for the next cycle. 853 | * xWasDelayed = xTaskDelayUntil( &xLastWakeTime, xFrequency ); 854 | * 855 | * // Perform action here. xWasDelayed value can be used to determine 856 | * // whether a deadline was missed if the code here took too long. 857 | * } 858 | * } 859 | * @endcode 860 | * \defgroup xTaskDelayUntil xTaskDelayUntil 861 | * \ingroup TaskCtrl 862 | */ 863 | BaseType_t xTaskDelayUntil( TickType_t * const pxPreviousWakeTime, 864 | const TickType_t xTimeIncrement ) PRIVILEGED_FUNCTION; 865 | 866 | /* 867 | * vTaskDelayUntil() is the older version of xTaskDelayUntil() and does not 868 | * return a value. 869 | */ 870 | #define vTaskDelayUntil( pxPreviousWakeTime, xTimeIncrement ) \ 871 | do { \ 872 | ( void ) xTaskDelayUntil( ( pxPreviousWakeTime ), ( xTimeIncrement ) ); \ 873 | } while( 0 ) 874 | 875 | 876 | /** 877 | * task. h 878 | * @code{c} 879 | * BaseType_t xTaskAbortDelay( TaskHandle_t xTask ); 880 | * @endcode 881 | * 882 | * INCLUDE_xTaskAbortDelay must be defined as 1 in FreeRTOSConfig.h for this 883 | * function to be available. 884 | * 885 | * A task will enter the Blocked state when it is waiting for an event. The 886 | * event it is waiting for can be a temporal event (waiting for a time), such 887 | * as when vTaskDelay() is called, or an event on an object, such as when 888 | * xQueueReceive() or ulTaskNotifyTake() is called. If the handle of a task 889 | * that is in the Blocked state is used in a call to xTaskAbortDelay() then the 890 | * task will leave the Blocked state, and return from whichever function call 891 | * placed the task into the Blocked state. 892 | * 893 | * There is no 'FromISR' version of this function as an interrupt would need to 894 | * know which object a task was blocked on in order to know which actions to 895 | * take. For example, if the task was blocked on a queue the interrupt handler 896 | * would then need to know if the queue was locked. 897 | * 898 | * @param xTask The handle of the task to remove from the Blocked state. 899 | * 900 | * @return If the task referenced by xTask was not in the Blocked state then 901 | * pdFAIL is returned. Otherwise pdPASS is returned. 902 | * 903 | * \defgroup xTaskAbortDelay xTaskAbortDelay 904 | * \ingroup TaskCtrl 905 | */ 906 | BaseType_t xTaskAbortDelay( TaskHandle_t xTask ) PRIVILEGED_FUNCTION; 907 | 908 | /** 909 | * task. h 910 | * @code{c} 911 | * UBaseType_t uxTaskPriorityGet( const TaskHandle_t xTask ); 912 | * @endcode 913 | * 914 | * INCLUDE_uxTaskPriorityGet must be defined as 1 for this function to be available. 915 | * See the configuration section for more information. 916 | * 917 | * Obtain the priority of any task. 918 | * 919 | * @param xTask Handle of the task to be queried. Passing a NULL 920 | * handle results in the priority of the calling task being returned. 921 | * 922 | * @return The priority of xTask. 923 | * 924 | * Example usage: 925 | * @code{c} 926 | * void vAFunction( void ) 927 | * { 928 | * TaskHandle_t xHandle; 929 | * 930 | * // Create a task, storing the handle. 931 | * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle ); 932 | * 933 | * // ... 934 | * 935 | * // Use the handle to obtain the priority of the created task. 936 | * // It was created with tskIDLE_PRIORITY, but may have changed 937 | * // it itself. 938 | * if( uxTaskPriorityGet( xHandle ) != tskIDLE_PRIORITY ) 939 | * { 940 | * // The task has changed it's priority. 941 | * } 942 | * 943 | * // ... 944 | * 945 | * // Is our priority higher than the created task? 946 | * if( uxTaskPriorityGet( xHandle ) < uxTaskPriorityGet( NULL ) ) 947 | * { 948 | * // Our priority (obtained using NULL handle) is higher. 949 | * } 950 | * } 951 | * @endcode 952 | * \defgroup uxTaskPriorityGet uxTaskPriorityGet 953 | * \ingroup TaskCtrl 954 | */ 955 | UBaseType_t uxTaskPriorityGet( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION; 956 | 957 | /** 958 | * task. h 959 | * @code{c} 960 | * UBaseType_t uxTaskPriorityGetFromISR( const TaskHandle_t xTask ); 961 | * @endcode 962 | * 963 | * A version of uxTaskPriorityGet() that can be used from an ISR. 964 | */ 965 | UBaseType_t uxTaskPriorityGetFromISR( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION; 966 | 967 | /** 968 | * task. h 969 | * @code{c} 970 | * eTaskState eTaskGetState( TaskHandle_t xTask ); 971 | * @endcode 972 | * 973 | * INCLUDE_eTaskGetState must be defined as 1 for this function to be available. 974 | * See the configuration section for more information. 975 | * 976 | * Obtain the state of any task. States are encoded by the eTaskState 977 | * enumerated type. 978 | * 979 | * @param xTask Handle of the task to be queried. 980 | * 981 | * @return The state of xTask at the time the function was called. Note the 982 | * state of the task might change between the function being called, and the 983 | * functions return value being tested by the calling task. 984 | */ 985 | eTaskState eTaskGetState( TaskHandle_t xTask ) PRIVILEGED_FUNCTION; 986 | 987 | /** 988 | * task. h 989 | * @code{c} 990 | * void vTaskGetInfo( TaskHandle_t xTask, TaskStatus_t *pxTaskStatus, BaseType_t xGetFreeStackSpace, eTaskState eState ); 991 | * @endcode 992 | * 993 | * configUSE_TRACE_FACILITY must be defined as 1 for this function to be 994 | * available. See the configuration section for more information. 995 | * 996 | * Populates a TaskStatus_t structure with information about a task. 997 | * 998 | * @param xTask Handle of the task being queried. If xTask is NULL then 999 | * information will be returned about the calling task. 1000 | * 1001 | * @param pxTaskStatus A pointer to the TaskStatus_t structure that will be 1002 | * filled with information about the task referenced by the handle passed using 1003 | * the xTask parameter. 1004 | * 1005 | * @param xGetFreeStackSpace The TaskStatus_t structure contains a member to report 1006 | * the stack high water mark of the task being queried. Calculating the stack 1007 | * high water mark takes a relatively long time, and can make the system 1008 | * temporarily unresponsive - so the xGetFreeStackSpace parameter is provided to 1009 | * allow the high water mark checking to be skipped. The high watermark value 1010 | * will only be written to the TaskStatus_t structure if xGetFreeStackSpace is 1011 | * not set to pdFALSE; 1012 | * 1013 | * @param eState The TaskStatus_t structure contains a member to report the 1014 | * state of the task being queried. Obtaining the task state is not as fast as 1015 | * a simple assignment - so the eState parameter is provided to allow the state 1016 | * information to be omitted from the TaskStatus_t structure. To obtain state 1017 | * information then set eState to eInvalid - otherwise the value passed in 1018 | * eState will be reported as the task state in the TaskStatus_t structure. 1019 | * 1020 | * Example usage: 1021 | * @code{c} 1022 | * void vAFunction( void ) 1023 | * { 1024 | * TaskHandle_t xHandle; 1025 | * TaskStatus_t xTaskDetails; 1026 | * 1027 | * // Obtain the handle of a task from its name. 1028 | * xHandle = xTaskGetHandle( "Task_Name" ); 1029 | * 1030 | * // Check the handle is not NULL. 1031 | * configASSERT( xHandle ); 1032 | * 1033 | * // Use the handle to obtain further information about the task. 1034 | * vTaskGetInfo( xHandle, 1035 | * &xTaskDetails, 1036 | * pdTRUE, // Include the high water mark in xTaskDetails. 1037 | * eInvalid ); // Include the task state in xTaskDetails. 1038 | * } 1039 | * @endcode 1040 | * \defgroup vTaskGetInfo vTaskGetInfo 1041 | * \ingroup TaskCtrl 1042 | */ 1043 | void vTaskGetInfo( TaskHandle_t xTask, 1044 | TaskStatus_t * pxTaskStatus, 1045 | BaseType_t xGetFreeStackSpace, 1046 | eTaskState eState ) PRIVILEGED_FUNCTION; 1047 | 1048 | /** 1049 | * task. h 1050 | * @code{c} 1051 | * void vTaskPrioritySet( TaskHandle_t xTask, UBaseType_t uxNewPriority ); 1052 | * @endcode 1053 | * 1054 | * INCLUDE_vTaskPrioritySet must be defined as 1 for this function to be available. 1055 | * See the configuration section for more information. 1056 | * 1057 | * Set the priority of any task. 1058 | * 1059 | * A context switch will occur before the function returns if the priority 1060 | * being set is higher than the currently executing task. 1061 | * 1062 | * @param xTask Handle to the task for which the priority is being set. 1063 | * Passing a NULL handle results in the priority of the calling task being set. 1064 | * 1065 | * @param uxNewPriority The priority to which the task will be set. 1066 | * 1067 | * Example usage: 1068 | * @code{c} 1069 | * void vAFunction( void ) 1070 | * { 1071 | * TaskHandle_t xHandle; 1072 | * 1073 | * // Create a task, storing the handle. 1074 | * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle ); 1075 | * 1076 | * // ... 1077 | * 1078 | * // Use the handle to raise the priority of the created task. 1079 | * vTaskPrioritySet( xHandle, tskIDLE_PRIORITY + 1 ); 1080 | * 1081 | * // ... 1082 | * 1083 | * // Use a NULL handle to raise our priority to the same value. 1084 | * vTaskPrioritySet( NULL, tskIDLE_PRIORITY + 1 ); 1085 | * } 1086 | * @endcode 1087 | * \defgroup vTaskPrioritySet vTaskPrioritySet 1088 | * \ingroup TaskCtrl 1089 | */ 1090 | void vTaskPrioritySet( TaskHandle_t xTask, 1091 | UBaseType_t uxNewPriority ) PRIVILEGED_FUNCTION; 1092 | 1093 | /** 1094 | * task. h 1095 | * @code{c} 1096 | * void vTaskSuspend( TaskHandle_t xTaskToSuspend ); 1097 | * @endcode 1098 | * 1099 | * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available. 1100 | * See the configuration section for more information. 1101 | * 1102 | * Suspend any task. When suspended a task will never get any microcontroller 1103 | * processing time, no matter what its priority. 1104 | * 1105 | * Calls to vTaskSuspend are not accumulative - 1106 | * i.e. calling vTaskSuspend () twice on the same task still only requires one 1107 | * call to vTaskResume () to ready the suspended task. 1108 | * 1109 | * @param xTaskToSuspend Handle to the task being suspended. Passing a NULL 1110 | * handle will cause the calling task to be suspended. 1111 | * 1112 | * Example usage: 1113 | * @code{c} 1114 | * void vAFunction( void ) 1115 | * { 1116 | * TaskHandle_t xHandle; 1117 | * 1118 | * // Create a task, storing the handle. 1119 | * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle ); 1120 | * 1121 | * // ... 1122 | * 1123 | * // Use the handle to suspend the created task. 1124 | * vTaskSuspend( xHandle ); 1125 | * 1126 | * // ... 1127 | * 1128 | * // The created task will not run during this period, unless 1129 | * // another task calls vTaskResume( xHandle ). 1130 | * 1131 | * //... 1132 | * 1133 | * 1134 | * // Suspend ourselves. 1135 | * vTaskSuspend( NULL ); 1136 | * 1137 | * // We cannot get here unless another task calls vTaskResume 1138 | * // with our handle as the parameter. 1139 | * } 1140 | * @endcode 1141 | * \defgroup vTaskSuspend vTaskSuspend 1142 | * \ingroup TaskCtrl 1143 | */ 1144 | void vTaskSuspend( TaskHandle_t xTaskToSuspend ) PRIVILEGED_FUNCTION; 1145 | 1146 | /** 1147 | * task. h 1148 | * @code{c} 1149 | * void vTaskResume( TaskHandle_t xTaskToResume ); 1150 | * @endcode 1151 | * 1152 | * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available. 1153 | * See the configuration section for more information. 1154 | * 1155 | * Resumes a suspended task. 1156 | * 1157 | * A task that has been suspended by one or more calls to vTaskSuspend () 1158 | * will be made available for running again by a single call to 1159 | * vTaskResume (). 1160 | * 1161 | * @param xTaskToResume Handle to the task being readied. 1162 | * 1163 | * Example usage: 1164 | * @code{c} 1165 | * void vAFunction( void ) 1166 | * { 1167 | * TaskHandle_t xHandle; 1168 | * 1169 | * // Create a task, storing the handle. 1170 | * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle ); 1171 | * 1172 | * // ... 1173 | * 1174 | * // Use the handle to suspend the created task. 1175 | * vTaskSuspend( xHandle ); 1176 | * 1177 | * // ... 1178 | * 1179 | * // The created task will not run during this period, unless 1180 | * // another task calls vTaskResume( xHandle ). 1181 | * 1182 | * //... 1183 | * 1184 | * 1185 | * // Resume the suspended task ourselves. 1186 | * vTaskResume( xHandle ); 1187 | * 1188 | * // The created task will once again get microcontroller processing 1189 | * // time in accordance with its priority within the system. 1190 | * } 1191 | * @endcode 1192 | * \defgroup vTaskResume vTaskResume 1193 | * \ingroup TaskCtrl 1194 | */ 1195 | void vTaskResume( TaskHandle_t xTaskToResume ) PRIVILEGED_FUNCTION; 1196 | 1197 | /** 1198 | * task. h 1199 | * @code{c} 1200 | * void xTaskResumeFromISR( TaskHandle_t xTaskToResume ); 1201 | * @endcode 1202 | * 1203 | * INCLUDE_xTaskResumeFromISR must be defined as 1 for this function to be 1204 | * available. See the configuration section for more information. 1205 | * 1206 | * An implementation of vTaskResume() that can be called from within an ISR. 1207 | * 1208 | * A task that has been suspended by one or more calls to vTaskSuspend () 1209 | * will be made available for running again by a single call to 1210 | * xTaskResumeFromISR (). 1211 | * 1212 | * xTaskResumeFromISR() should not be used to synchronise a task with an 1213 | * interrupt if there is a chance that the interrupt could arrive prior to the 1214 | * task being suspended - as this can lead to interrupts being missed. Use of a 1215 | * semaphore as a synchronisation mechanism would avoid this eventuality. 1216 | * 1217 | * @param xTaskToResume Handle to the task being readied. 1218 | * 1219 | * @return pdTRUE if resuming the task should result in a context switch, 1220 | * otherwise pdFALSE. This is used by the ISR to determine if a context switch 1221 | * may be required following the ISR. 1222 | * 1223 | * \defgroup vTaskResumeFromISR vTaskResumeFromISR 1224 | * \ingroup TaskCtrl 1225 | */ 1226 | BaseType_t xTaskResumeFromISR( TaskHandle_t xTaskToResume ) PRIVILEGED_FUNCTION; 1227 | 1228 | /*----------------------------------------------------------- 1229 | * SCHEDULER CONTROL 1230 | *----------------------------------------------------------*/ 1231 | 1232 | /** 1233 | * task. h 1234 | * @code{c} 1235 | * void vTaskStartScheduler( void ); 1236 | * @endcode 1237 | * 1238 | * Starts the real time kernel tick processing. After calling the kernel 1239 | * has control over which tasks are executed and when. 1240 | * 1241 | * See the demo application file main.c for an example of creating 1242 | * tasks and starting the kernel. 1243 | * 1244 | * Example usage: 1245 | * @code{c} 1246 | * void vAFunction( void ) 1247 | * { 1248 | * // Create at least one task before starting the kernel. 1249 | * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL ); 1250 | * 1251 | * // Start the real time kernel with preemption. 1252 | * vTaskStartScheduler (); 1253 | * 1254 | * // Will not get here unless a task calls vTaskEndScheduler () 1255 | * } 1256 | * @endcode 1257 | * 1258 | * \defgroup vTaskStartScheduler vTaskStartScheduler 1259 | * \ingroup SchedulerControl 1260 | */ 1261 | void vTaskStartScheduler( void ) PRIVILEGED_FUNCTION; 1262 | 1263 | /** 1264 | * task. h 1265 | * @code{c} 1266 | * void vTaskEndScheduler( void ); 1267 | * @endcode 1268 | * 1269 | * NOTE: At the time of writing only the x86 real mode port, which runs on a PC 1270 | * in place of DOS, implements this function. 1271 | * 1272 | * Stops the real time kernel tick. All created tasks will be automatically 1273 | * deleted and multitasking (either preemptive or cooperative) will 1274 | * stop. Execution then resumes from the point where vTaskStartScheduler () 1275 | * was called, as if vTaskStartScheduler () had just returned. 1276 | * 1277 | * See the demo application file main. c in the demo/PC directory for an 1278 | * example that uses vTaskEndScheduler (). 1279 | * 1280 | * vTaskEndScheduler () requires an exit function to be defined within the 1281 | * portable layer (see vPortEndScheduler () in port. c for the PC port). This 1282 | * performs hardware specific operations such as stopping the kernel tick. 1283 | * 1284 | * vTaskEndScheduler () will cause all of the resources allocated by the 1285 | * kernel to be freed - but will not free resources allocated by application 1286 | * tasks. 1287 | * 1288 | * Example usage: 1289 | * @code{c} 1290 | * void vTaskCode( void * pvParameters ) 1291 | * { 1292 | * for( ;; ) 1293 | * { 1294 | * // Task code goes here. 1295 | * 1296 | * // At some point we want to end the real time kernel processing 1297 | * // so call ... 1298 | * vTaskEndScheduler (); 1299 | * } 1300 | * } 1301 | * 1302 | * void vAFunction( void ) 1303 | * { 1304 | * // Create at least one task before starting the kernel. 1305 | * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL ); 1306 | * 1307 | * // Start the real time kernel with preemption. 1308 | * vTaskStartScheduler (); 1309 | * 1310 | * // Will only get here when the vTaskCode () task has called 1311 | * // vTaskEndScheduler (). When we get here we are back to single task 1312 | * // execution. 1313 | * } 1314 | * @endcode 1315 | * 1316 | * \defgroup vTaskEndScheduler vTaskEndScheduler 1317 | * \ingroup SchedulerControl 1318 | */ 1319 | void vTaskEndScheduler( void ) PRIVILEGED_FUNCTION; 1320 | 1321 | /** 1322 | * task. h 1323 | * @code{c} 1324 | * void vTaskSuspendAll( void ); 1325 | * @endcode 1326 | * 1327 | * Suspends the scheduler without disabling interrupts. Context switches will 1328 | * not occur while the scheduler is suspended. 1329 | * 1330 | * After calling vTaskSuspendAll () the calling task will continue to execute 1331 | * without risk of being swapped out until a call to xTaskResumeAll () has been 1332 | * made. 1333 | * 1334 | * API functions that have the potential to cause a context switch (for example, 1335 | * xTaskDelayUntil(), xQueueSend(), etc.) must not be called while the scheduler 1336 | * is suspended. 1337 | * 1338 | * Example usage: 1339 | * @code{c} 1340 | * void vTask1( void * pvParameters ) 1341 | * { 1342 | * for( ;; ) 1343 | * { 1344 | * // Task code goes here. 1345 | * 1346 | * // ... 1347 | * 1348 | * // At some point the task wants to perform a long operation during 1349 | * // which it does not want to get swapped out. It cannot use 1350 | * // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the 1351 | * // operation may cause interrupts to be missed - including the 1352 | * // ticks. 1353 | * 1354 | * // Prevent the real time kernel swapping out the task. 1355 | * vTaskSuspendAll (); 1356 | * 1357 | * // Perform the operation here. There is no need to use critical 1358 | * // sections as we have all the microcontroller processing time. 1359 | * // During this time interrupts will still operate and the kernel 1360 | * // tick count will be maintained. 1361 | * 1362 | * // ... 1363 | * 1364 | * // The operation is complete. Restart the kernel. 1365 | * xTaskResumeAll (); 1366 | * } 1367 | * } 1368 | * @endcode 1369 | * \defgroup vTaskSuspendAll vTaskSuspendAll 1370 | * \ingroup SchedulerControl 1371 | */ 1372 | void vTaskSuspendAll( void ) PRIVILEGED_FUNCTION; 1373 | 1374 | /** 1375 | * task. h 1376 | * @code{c} 1377 | * BaseType_t xTaskResumeAll( void ); 1378 | * @endcode 1379 | * 1380 | * Resumes scheduler activity after it was suspended by a call to 1381 | * vTaskSuspendAll(). 1382 | * 1383 | * xTaskResumeAll() only resumes the scheduler. It does not unsuspend tasks 1384 | * that were previously suspended by a call to vTaskSuspend(). 1385 | * 1386 | * @return If resuming the scheduler caused a context switch then pdTRUE is 1387 | * returned, otherwise pdFALSE is returned. 1388 | * 1389 | * Example usage: 1390 | * @code{c} 1391 | * void vTask1( void * pvParameters ) 1392 | * { 1393 | * for( ;; ) 1394 | * { 1395 | * // Task code goes here. 1396 | * 1397 | * // ... 1398 | * 1399 | * // At some point the task wants to perform a long operation during 1400 | * // which it does not want to get swapped out. It cannot use 1401 | * // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the 1402 | * // operation may cause interrupts to be missed - including the 1403 | * // ticks. 1404 | * 1405 | * // Prevent the real time kernel swapping out the task. 1406 | * vTaskSuspendAll (); 1407 | * 1408 | * // Perform the operation here. There is no need to use critical 1409 | * // sections as we have all the microcontroller processing time. 1410 | * // During this time interrupts will still operate and the real 1411 | * // time kernel tick count will be maintained. 1412 | * 1413 | * // ... 1414 | * 1415 | * // The operation is complete. Restart the kernel. We want to force 1416 | * // a context switch - but there is no point if resuming the scheduler 1417 | * // caused a context switch already. 1418 | * if( !xTaskResumeAll () ) 1419 | * { 1420 | * taskYIELD (); 1421 | * } 1422 | * } 1423 | * } 1424 | * @endcode 1425 | * \defgroup xTaskResumeAll xTaskResumeAll 1426 | * \ingroup SchedulerControl 1427 | */ 1428 | BaseType_t xTaskResumeAll( void ) PRIVILEGED_FUNCTION; 1429 | 1430 | /*----------------------------------------------------------- 1431 | * TASK UTILITIES 1432 | *----------------------------------------------------------*/ 1433 | 1434 | /** 1435 | * task. h 1436 | * @code{c} 1437 | * TickType_t xTaskGetTickCount( void ); 1438 | * @endcode 1439 | * 1440 | * @return The count of ticks since vTaskStartScheduler was called. 1441 | * 1442 | * \defgroup xTaskGetTickCount xTaskGetTickCount 1443 | * \ingroup TaskUtils 1444 | */ 1445 | TickType_t xTaskGetTickCount( void ) PRIVILEGED_FUNCTION; 1446 | 1447 | /** 1448 | * task. h 1449 | * @code{c} 1450 | * TickType_t xTaskGetTickCountFromISR( void ); 1451 | * @endcode 1452 | * 1453 | * @return The count of ticks since vTaskStartScheduler was called. 1454 | * 1455 | * This is a version of xTaskGetTickCount() that is safe to be called from an 1456 | * ISR - provided that TickType_t is the natural word size of the 1457 | * microcontroller being used or interrupt nesting is either not supported or 1458 | * not being used. 1459 | * 1460 | * \defgroup xTaskGetTickCountFromISR xTaskGetTickCountFromISR 1461 | * \ingroup TaskUtils 1462 | */ 1463 | TickType_t xTaskGetTickCountFromISR( void ) PRIVILEGED_FUNCTION; 1464 | 1465 | /** 1466 | * task. h 1467 | * @code{c} 1468 | * uint16_t uxTaskGetNumberOfTasks( void ); 1469 | * @endcode 1470 | * 1471 | * @return The number of tasks that the real time kernel is currently managing. 1472 | * This includes all ready, blocked and suspended tasks. A task that 1473 | * has been deleted but not yet freed by the idle task will also be 1474 | * included in the count. 1475 | * 1476 | * \defgroup uxTaskGetNumberOfTasks uxTaskGetNumberOfTasks 1477 | * \ingroup TaskUtils 1478 | */ 1479 | UBaseType_t uxTaskGetNumberOfTasks( void ) PRIVILEGED_FUNCTION; 1480 | 1481 | /** 1482 | * task. h 1483 | * @code{c} 1484 | * char *pcTaskGetName( TaskHandle_t xTaskToQuery ); 1485 | * @endcode 1486 | * 1487 | * @return The text (human readable) name of the task referenced by the handle 1488 | * xTaskToQuery. A task can query its own name by either passing in its own 1489 | * handle, or by setting xTaskToQuery to NULL. 1490 | * 1491 | * \defgroup pcTaskGetName pcTaskGetName 1492 | * \ingroup TaskUtils 1493 | */ 1494 | char * pcTaskGetName( TaskHandle_t xTaskToQuery ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ 1495 | 1496 | /** 1497 | * task. h 1498 | * @code{c} 1499 | * TaskHandle_t xTaskGetHandle( const char *pcNameToQuery ); 1500 | * @endcode 1501 | * 1502 | * NOTE: This function takes a relatively long time to complete and should be 1503 | * used sparingly. 1504 | * 1505 | * @return The handle of the task that has the human readable name pcNameToQuery. 1506 | * NULL is returned if no matching name is found. INCLUDE_xTaskGetHandle 1507 | * must be set to 1 in FreeRTOSConfig.h for pcTaskGetHandle() to be available. 1508 | * 1509 | * \defgroup pcTaskGetHandle pcTaskGetHandle 1510 | * \ingroup TaskUtils 1511 | */ 1512 | TaskHandle_t xTaskGetHandle( const char * pcNameToQuery ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ 1513 | 1514 | /** 1515 | * task.h 1516 | * @code{c} 1517 | * UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask ); 1518 | * @endcode 1519 | * 1520 | * INCLUDE_uxTaskGetStackHighWaterMark must be set to 1 in FreeRTOSConfig.h for 1521 | * this function to be available. 1522 | * 1523 | * Returns the high water mark of the stack associated with xTask. That is, 1524 | * the minimum free stack space there has been (in words, so on a 32 bit machine 1525 | * a value of 1 means 4 bytes) since the task started. The smaller the returned 1526 | * number the closer the task has come to overflowing its stack. 1527 | * 1528 | * uxTaskGetStackHighWaterMark() and uxTaskGetStackHighWaterMark2() are the 1529 | * same except for their return type. Using configSTACK_DEPTH_TYPE allows the 1530 | * user to determine the return type. It gets around the problem of the value 1531 | * overflowing on 8-bit types without breaking backward compatibility for 1532 | * applications that expect an 8-bit return type. 1533 | * 1534 | * @param xTask Handle of the task associated with the stack to be checked. 1535 | * Set xTask to NULL to check the stack of the calling task. 1536 | * 1537 | * @return The smallest amount of free stack space there has been (in words, so 1538 | * actual spaces on the stack rather than bytes) since the task referenced by 1539 | * xTask was created. 1540 | */ 1541 | UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask ) PRIVILEGED_FUNCTION; 1542 | 1543 | /** 1544 | * task.h 1545 | * @code{c} 1546 | * configSTACK_DEPTH_TYPE uxTaskGetStackHighWaterMark2( TaskHandle_t xTask ); 1547 | * @endcode 1548 | * 1549 | * INCLUDE_uxTaskGetStackHighWaterMark2 must be set to 1 in FreeRTOSConfig.h for 1550 | * this function to be available. 1551 | * 1552 | * Returns the high water mark of the stack associated with xTask. That is, 1553 | * the minimum free stack space there has been (in words, so on a 32 bit machine 1554 | * a value of 1 means 4 bytes) since the task started. The smaller the returned 1555 | * number the closer the task has come to overflowing its stack. 1556 | * 1557 | * uxTaskGetStackHighWaterMark() and uxTaskGetStackHighWaterMark2() are the 1558 | * same except for their return type. Using configSTACK_DEPTH_TYPE allows the 1559 | * user to determine the return type. It gets around the problem of the value 1560 | * overflowing on 8-bit types without breaking backward compatibility for 1561 | * applications that expect an 8-bit return type. 1562 | * 1563 | * @param xTask Handle of the task associated with the stack to be checked. 1564 | * Set xTask to NULL to check the stack of the calling task. 1565 | * 1566 | * @return The smallest amount of free stack space there has been (in words, so 1567 | * actual spaces on the stack rather than bytes) since the task referenced by 1568 | * xTask was created. 1569 | */ 1570 | configSTACK_DEPTH_TYPE uxTaskGetStackHighWaterMark2( TaskHandle_t xTask ) PRIVILEGED_FUNCTION; 1571 | 1572 | /* When using trace macros it is sometimes necessary to include task.h before 1573 | * FreeRTOS.h. When this is done TaskHookFunction_t will not yet have been defined, 1574 | * so the following two prototypes will cause a compilation error. This can be 1575 | * fixed by simply guarding against the inclusion of these two prototypes unless 1576 | * they are explicitly required by the configUSE_APPLICATION_TASK_TAG configuration 1577 | * constant. */ 1578 | #ifdef configUSE_APPLICATION_TASK_TAG 1579 | #if configUSE_APPLICATION_TASK_TAG == 1 1580 | 1581 | /** 1582 | * task.h 1583 | * @code{c} 1584 | * void vTaskSetApplicationTaskTag( TaskHandle_t xTask, TaskHookFunction_t pxHookFunction ); 1585 | * @endcode 1586 | * 1587 | * Sets pxHookFunction to be the task hook function used by the task xTask. 1588 | * Passing xTask as NULL has the effect of setting the calling tasks hook 1589 | * function. 1590 | */ 1591 | void vTaskSetApplicationTaskTag( TaskHandle_t xTask, 1592 | TaskHookFunction_t pxHookFunction ) PRIVILEGED_FUNCTION; 1593 | 1594 | /** 1595 | * task.h 1596 | * @code{c} 1597 | * void xTaskGetApplicationTaskTag( TaskHandle_t xTask ); 1598 | * @endcode 1599 | * 1600 | * Returns the pxHookFunction value assigned to the task xTask. Do not 1601 | * call from an interrupt service routine - call 1602 | * xTaskGetApplicationTaskTagFromISR() instead. 1603 | */ 1604 | TaskHookFunction_t xTaskGetApplicationTaskTag( TaskHandle_t xTask ) PRIVILEGED_FUNCTION; 1605 | 1606 | /** 1607 | * task.h 1608 | * @code{c} 1609 | * void xTaskGetApplicationTaskTagFromISR( TaskHandle_t xTask ); 1610 | * @endcode 1611 | * 1612 | * Returns the pxHookFunction value assigned to the task xTask. Can 1613 | * be called from an interrupt service routine. 1614 | */ 1615 | TaskHookFunction_t xTaskGetApplicationTaskTagFromISR( TaskHandle_t xTask ) PRIVILEGED_FUNCTION; 1616 | #endif /* configUSE_APPLICATION_TASK_TAG ==1 */ 1617 | #endif /* ifdef configUSE_APPLICATION_TASK_TAG */ 1618 | 1619 | #if ( configNUM_THREAD_LOCAL_STORAGE_POINTERS > 0 ) 1620 | 1621 | /* Each task contains an array of pointers that is dimensioned by the 1622 | * configNUM_THREAD_LOCAL_STORAGE_POINTERS setting in FreeRTOSConfig.h. The 1623 | * kernel does not use the pointers itself, so the application writer can use 1624 | * the pointers for any purpose they wish. The following two functions are 1625 | * used to set and query a pointer respectively. */ 1626 | void vTaskSetThreadLocalStoragePointer( TaskHandle_t xTaskToSet, 1627 | BaseType_t xIndex, 1628 | void * pvValue ) PRIVILEGED_FUNCTION; 1629 | void * pvTaskGetThreadLocalStoragePointer( TaskHandle_t xTaskToQuery, 1630 | BaseType_t xIndex ) PRIVILEGED_FUNCTION; 1631 | 1632 | #endif 1633 | 1634 | #if ( configCHECK_FOR_STACK_OVERFLOW > 0 ) 1635 | 1636 | /** 1637 | * task.h 1638 | * @code{c} 1639 | * void vApplicationStackOverflowHook( TaskHandle_t xTask char *pcTaskName); 1640 | * @endcode 1641 | * 1642 | * The application stack overflow hook is called when a stack overflow is detected for a task. 1643 | * 1644 | * Details on stack overflow detection can be found here: https://www.FreeRTOS.org/Stacks-and-stack-overflow-checking.html 1645 | * 1646 | * @param xTask the task that just exceeded its stack boundaries. 1647 | * @param pcTaskName A character string containing the name of the offending task. 1648 | */ 1649 | void vApplicationStackOverflowHook( TaskHandle_t xTask, 1650 | char * pcTaskName ); 1651 | 1652 | #endif 1653 | 1654 | #if ( configUSE_TICK_HOOK > 0 ) 1655 | 1656 | /** 1657 | * task.h 1658 | * @code{c} 1659 | * void vApplicationTickHook( void ); 1660 | * @endcode 1661 | * 1662 | * This hook function is called in the system tick handler after any OS work is completed. 1663 | */ 1664 | void vApplicationTickHook( void ); /*lint !e526 Symbol not defined as it is an application callback. */ 1665 | 1666 | #endif 1667 | 1668 | #if ( configSUPPORT_STATIC_ALLOCATION == 1 ) 1669 | 1670 | /** 1671 | * task.h 1672 | * @code{c} 1673 | * void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer, StackType_t ** ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize ) 1674 | * @endcode 1675 | * 1676 | * This function is used to provide a statically allocated block of memory to FreeRTOS to hold the Idle Task TCB. This function is required when 1677 | * configSUPPORT_STATIC_ALLOCATION is set. For more information see this URI: https://www.FreeRTOS.org/a00110.html#configSUPPORT_STATIC_ALLOCATION 1678 | * 1679 | * @param ppxIdleTaskTCBBuffer A handle to a statically allocated TCB buffer 1680 | * @param ppxIdleTaskStackBuffer A handle to a statically allocated Stack buffer for the idle task 1681 | * @param pulIdleTaskStackSize A pointer to the number of elements that will fit in the allocated stack buffer 1682 | */ 1683 | void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer, 1684 | StackType_t ** ppxIdleTaskStackBuffer, 1685 | uint32_t * pulIdleTaskStackSize ); /*lint !e526 Symbol not defined as it is an application callback. */ 1686 | #endif 1687 | 1688 | /** 1689 | * task.h 1690 | * @code{c} 1691 | * BaseType_t xTaskCallApplicationTaskHook( TaskHandle_t xTask, void *pvParameter ); 1692 | * @endcode 1693 | * 1694 | * Calls the hook function associated with xTask. Passing xTask as NULL has 1695 | * the effect of calling the Running tasks (the calling task) hook function. 1696 | * 1697 | * pvParameter is passed to the hook function for the task to interpret as it 1698 | * wants. The return value is the value returned by the task hook function 1699 | * registered by the user. 1700 | */ 1701 | BaseType_t xTaskCallApplicationTaskHook( TaskHandle_t xTask, 1702 | void * pvParameter ) PRIVILEGED_FUNCTION; 1703 | 1704 | /** 1705 | * xTaskGetIdleTaskHandle() is only available if 1706 | * INCLUDE_xTaskGetIdleTaskHandle is set to 1 in FreeRTOSConfig.h. 1707 | * 1708 | * Simply returns the handle of the idle task. It is not valid to call 1709 | * xTaskGetIdleTaskHandle() before the scheduler has been started. 1710 | */ 1711 | TaskHandle_t xTaskGetIdleTaskHandle( void ) PRIVILEGED_FUNCTION; 1712 | 1713 | /** 1714 | * configUSE_TRACE_FACILITY must be defined as 1 in FreeRTOSConfig.h for 1715 | * uxTaskGetSystemState() to be available. 1716 | * 1717 | * uxTaskGetSystemState() populates an TaskStatus_t structure for each task in 1718 | * the system. TaskStatus_t structures contain, among other things, members 1719 | * for the task handle, task name, task priority, task state, and total amount 1720 | * of run time consumed by the task. See the TaskStatus_t structure 1721 | * definition in this file for the full member list. 1722 | * 1723 | * NOTE: This function is intended for debugging use only as its use results in 1724 | * the scheduler remaining suspended for an extended period. 1725 | * 1726 | * @param pxTaskStatusArray A pointer to an array of TaskStatus_t structures. 1727 | * The array must contain at least one TaskStatus_t structure for each task 1728 | * that is under the control of the RTOS. The number of tasks under the control 1729 | * of the RTOS can be determined using the uxTaskGetNumberOfTasks() API function. 1730 | * 1731 | * @param uxArraySize The size of the array pointed to by the pxTaskStatusArray 1732 | * parameter. The size is specified as the number of indexes in the array, or 1733 | * the number of TaskStatus_t structures contained in the array, not by the 1734 | * number of bytes in the array. 1735 | * 1736 | * @param pulTotalRunTime If configGENERATE_RUN_TIME_STATS is set to 1 in 1737 | * FreeRTOSConfig.h then *pulTotalRunTime is set by uxTaskGetSystemState() to the 1738 | * total run time (as defined by the run time stats clock, see 1739 | * https://www.FreeRTOS.org/rtos-run-time-stats.html) since the target booted. 1740 | * pulTotalRunTime can be set to NULL to omit the total run time information. 1741 | * 1742 | * @return The number of TaskStatus_t structures that were populated by 1743 | * uxTaskGetSystemState(). This should equal the number returned by the 1744 | * uxTaskGetNumberOfTasks() API function, but will be zero if the value passed 1745 | * in the uxArraySize parameter was too small. 1746 | * 1747 | * Example usage: 1748 | * @code{c} 1749 | * // This example demonstrates how a human readable table of run time stats 1750 | * // information is generated from raw data provided by uxTaskGetSystemState(). 1751 | * // The human readable table is written to pcWriteBuffer 1752 | * void vTaskGetRunTimeStats( char *pcWriteBuffer ) 1753 | * { 1754 | * TaskStatus_t *pxTaskStatusArray; 1755 | * volatile UBaseType_t uxArraySize, x; 1756 | * configRUN_TIME_COUNTER_TYPE ulTotalRunTime, ulStatsAsPercentage; 1757 | * 1758 | * // Make sure the write buffer does not contain a string. 1759 | * pcWriteBuffer = 0x00; 1760 | * 1761 | * // Take a snapshot of the number of tasks in case it changes while this 1762 | * // function is executing. 1763 | * uxArraySize = uxTaskGetNumberOfTasks(); 1764 | * 1765 | * // Allocate a TaskStatus_t structure for each task. An array could be 1766 | * // allocated statically at compile time. 1767 | * pxTaskStatusArray = pvPortMalloc( uxArraySize * sizeof( TaskStatus_t ) ); 1768 | * 1769 | * if( pxTaskStatusArray != NULL ) 1770 | * { 1771 | * // Generate raw status information about each task. 1772 | * uxArraySize = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, &ulTotalRunTime ); 1773 | * 1774 | * // For percentage calculations. 1775 | * ulTotalRunTime /= 100UL; 1776 | * 1777 | * // Avoid divide by zero errors. 1778 | * if( ulTotalRunTime > 0 ) 1779 | * { 1780 | * // For each populated position in the pxTaskStatusArray array, 1781 | * // format the raw data as human readable ASCII data 1782 | * for( x = 0; x < uxArraySize; x++ ) 1783 | * { 1784 | * // What percentage of the total run time has the task used? 1785 | * // This will always be rounded down to the nearest integer. 1786 | * // ulTotalRunTimeDiv100 has already been divided by 100. 1787 | * ulStatsAsPercentage = pxTaskStatusArray[ x ].ulRunTimeCounter / ulTotalRunTime; 1788 | * 1789 | * if( ulStatsAsPercentage > 0UL ) 1790 | * { 1791 | * sprintf( pcWriteBuffer, "%s\t\t%lu\t\t%lu%%\r\n", pxTaskStatusArray[ x ].pcTaskName, pxTaskStatusArray[ x ].ulRunTimeCounter, ulStatsAsPercentage ); 1792 | * } 1793 | * else 1794 | * { 1795 | * // If the percentage is zero here then the task has 1796 | * // consumed less than 1% of the total run time. 1797 | * sprintf( pcWriteBuffer, "%s\t\t%lu\t\t<1%%\r\n", pxTaskStatusArray[ x ].pcTaskName, pxTaskStatusArray[ x ].ulRunTimeCounter ); 1798 | * } 1799 | * 1800 | * pcWriteBuffer += strlen( ( char * ) pcWriteBuffer ); 1801 | * } 1802 | * } 1803 | * 1804 | * // The array is no longer needed, free the memory it consumes. 1805 | * vPortFree( pxTaskStatusArray ); 1806 | * } 1807 | * } 1808 | * @endcode 1809 | */ 1810 | UBaseType_t uxTaskGetSystemState( TaskStatus_t * const pxTaskStatusArray, 1811 | const UBaseType_t uxArraySize, 1812 | configRUN_TIME_COUNTER_TYPE * const pulTotalRunTime ) PRIVILEGED_FUNCTION; 1813 | 1814 | /** 1815 | * task. h 1816 | * @code{c} 1817 | * void vTaskList( char *pcWriteBuffer ); 1818 | * @endcode 1819 | * 1820 | * configUSE_TRACE_FACILITY and configUSE_STATS_FORMATTING_FUNCTIONS must 1821 | * both be defined as 1 for this function to be available. See the 1822 | * configuration section of the FreeRTOS.org website for more information. 1823 | * 1824 | * NOTE 1: This function will disable interrupts for its duration. It is 1825 | * not intended for normal application runtime use but as a debug aid. 1826 | * 1827 | * Lists all the current tasks, along with their current state and stack 1828 | * usage high water mark. 1829 | * 1830 | * Tasks are reported as blocked ('B'), ready ('R'), deleted ('D') or 1831 | * suspended ('S'). 1832 | * 1833 | * PLEASE NOTE: 1834 | * 1835 | * This function is provided for convenience only, and is used by many of the 1836 | * demo applications. Do not consider it to be part of the scheduler. 1837 | * 1838 | * vTaskList() calls uxTaskGetSystemState(), then formats part of the 1839 | * uxTaskGetSystemState() output into a human readable table that displays task: 1840 | * names, states, priority, stack usage and task number. 1841 | * Stack usage specified as the number of unused StackType_t words stack can hold 1842 | * on top of stack - not the number of bytes. 1843 | * 1844 | * vTaskList() has a dependency on the sprintf() C library function that might 1845 | * bloat the code size, use a lot of stack, and provide different results on 1846 | * different platforms. An alternative, tiny, third party, and limited 1847 | * functionality implementation of sprintf() is provided in many of the 1848 | * FreeRTOS/Demo sub-directories in a file called printf-stdarg.c (note 1849 | * printf-stdarg.c does not provide a full snprintf() implementation!). 1850 | * 1851 | * It is recommended that production systems call uxTaskGetSystemState() 1852 | * directly to get access to raw stats data, rather than indirectly through a 1853 | * call to vTaskList(). 1854 | * 1855 | * @param pcWriteBuffer A buffer into which the above mentioned details 1856 | * will be written, in ASCII form. This buffer is assumed to be large 1857 | * enough to contain the generated report. Approximately 40 bytes per 1858 | * task should be sufficient. 1859 | * 1860 | * \defgroup vTaskList vTaskList 1861 | * \ingroup TaskUtils 1862 | */ 1863 | void vTaskList( char * pcWriteBuffer ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ 1864 | 1865 | /** 1866 | * task. h 1867 | * @code{c} 1868 | * void vTaskGetRunTimeStats( char *pcWriteBuffer ); 1869 | * @endcode 1870 | * 1871 | * configGENERATE_RUN_TIME_STATS and configUSE_STATS_FORMATTING_FUNCTIONS 1872 | * must both be defined as 1 for this function to be available. The application 1873 | * must also then provide definitions for 1874 | * portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and portGET_RUN_TIME_COUNTER_VALUE() 1875 | * to configure a peripheral timer/counter and return the timers current count 1876 | * value respectively. The counter should be at least 10 times the frequency of 1877 | * the tick count. 1878 | * 1879 | * NOTE 1: This function will disable interrupts for its duration. It is 1880 | * not intended for normal application runtime use but as a debug aid. 1881 | * 1882 | * Setting configGENERATE_RUN_TIME_STATS to 1 will result in a total 1883 | * accumulated execution time being stored for each task. The resolution 1884 | * of the accumulated time value depends on the frequency of the timer 1885 | * configured by the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() macro. 1886 | * Calling vTaskGetRunTimeStats() writes the total execution time of each 1887 | * task into a buffer, both as an absolute count value and as a percentage 1888 | * of the total system execution time. 1889 | * 1890 | * NOTE 2: 1891 | * 1892 | * This function is provided for convenience only, and is used by many of the 1893 | * demo applications. Do not consider it to be part of the scheduler. 1894 | * 1895 | * vTaskGetRunTimeStats() calls uxTaskGetSystemState(), then formats part of the 1896 | * uxTaskGetSystemState() output into a human readable table that displays the 1897 | * amount of time each task has spent in the Running state in both absolute and 1898 | * percentage terms. 1899 | * 1900 | * vTaskGetRunTimeStats() has a dependency on the sprintf() C library function 1901 | * that might bloat the code size, use a lot of stack, and provide different 1902 | * results on different platforms. An alternative, tiny, third party, and 1903 | * limited functionality implementation of sprintf() is provided in many of the 1904 | * FreeRTOS/Demo sub-directories in a file called printf-stdarg.c (note 1905 | * printf-stdarg.c does not provide a full snprintf() implementation!). 1906 | * 1907 | * It is recommended that production systems call uxTaskGetSystemState() directly 1908 | * to get access to raw stats data, rather than indirectly through a call to 1909 | * vTaskGetRunTimeStats(). 1910 | * 1911 | * @param pcWriteBuffer A buffer into which the execution times will be 1912 | * written, in ASCII form. This buffer is assumed to be large enough to 1913 | * contain the generated report. Approximately 40 bytes per task should 1914 | * be sufficient. 1915 | * 1916 | * \defgroup vTaskGetRunTimeStats vTaskGetRunTimeStats 1917 | * \ingroup TaskUtils 1918 | */ 1919 | void vTaskGetRunTimeStats( char * pcWriteBuffer ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ 1920 | 1921 | /** 1922 | * task. h 1923 | * @code{c} 1924 | * configRUN_TIME_COUNTER_TYPE ulTaskGetIdleRunTimeCounter( void ); 1925 | * configRUN_TIME_COUNTER_TYPE ulTaskGetIdleRunTimePercent( void ); 1926 | * @endcode 1927 | * 1928 | * configGENERATE_RUN_TIME_STATS, configUSE_STATS_FORMATTING_FUNCTIONS and 1929 | * INCLUDE_xTaskGetIdleTaskHandle must all be defined as 1 for these functions 1930 | * to be available. The application must also then provide definitions for 1931 | * portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and portGET_RUN_TIME_COUNTER_VALUE() 1932 | * to configure a peripheral timer/counter and return the timers current count 1933 | * value respectively. The counter should be at least 10 times the frequency of 1934 | * the tick count. 1935 | * 1936 | * Setting configGENERATE_RUN_TIME_STATS to 1 will result in a total 1937 | * accumulated execution time being stored for each task. The resolution 1938 | * of the accumulated time value depends on the frequency of the timer 1939 | * configured by the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() macro. 1940 | * While uxTaskGetSystemState() and vTaskGetRunTimeStats() writes the total 1941 | * execution time of each task into a buffer, ulTaskGetIdleRunTimeCounter() 1942 | * returns the total execution time of just the idle task and 1943 | * ulTaskGetIdleRunTimePercent() returns the percentage of the CPU time used by 1944 | * just the idle task. 1945 | * 1946 | * Note the amount of idle time is only a good measure of the slack time in a 1947 | * system if there are no other tasks executing at the idle priority, tickless 1948 | * idle is not used, and configIDLE_SHOULD_YIELD is set to 0. 1949 | * 1950 | * @return The total run time of the idle task or the percentage of the total 1951 | * run time consumed by the idle task. This is the amount of time the 1952 | * idle task has actually been executing. The unit of time is dependent on the 1953 | * frequency configured using the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and 1954 | * portGET_RUN_TIME_COUNTER_VALUE() macros. 1955 | * 1956 | * \defgroup ulTaskGetIdleRunTimeCounter ulTaskGetIdleRunTimeCounter 1957 | * \ingroup TaskUtils 1958 | */ 1959 | configRUN_TIME_COUNTER_TYPE ulTaskGetIdleRunTimeCounter( void ) PRIVILEGED_FUNCTION; 1960 | configRUN_TIME_COUNTER_TYPE ulTaskGetIdleRunTimePercent( void ) PRIVILEGED_FUNCTION; 1961 | 1962 | /** 1963 | * task. h 1964 | * @code{c} 1965 | * BaseType_t xTaskNotifyIndexed( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction ); 1966 | * BaseType_t xTaskNotify( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction ); 1967 | * @endcode 1968 | * 1969 | * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details. 1970 | * 1971 | * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for these 1972 | * functions to be available. 1973 | * 1974 | * Sends a direct to task notification to a task, with an optional value and 1975 | * action. 1976 | * 1977 | * Each task has a private array of "notification values" (or 'notifications'), 1978 | * each of which is a 32-bit unsigned integer (uint32_t). The constant 1979 | * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the 1980 | * array, and (for backward compatibility) defaults to 1 if left undefined. 1981 | * Prior to FreeRTOS V10.4.0 there was only one notification value per task. 1982 | * 1983 | * Events can be sent to a task using an intermediary object. Examples of such 1984 | * objects are queues, semaphores, mutexes and event groups. Task notifications 1985 | * are a method of sending an event directly to a task without the need for such 1986 | * an intermediary object. 1987 | * 1988 | * A notification sent to a task can optionally perform an action, such as 1989 | * update, overwrite or increment one of the task's notification values. In 1990 | * that way task notifications can be used to send data to a task, or be used as 1991 | * light weight and fast binary or counting semaphores. 1992 | * 1993 | * A task can use xTaskNotifyWaitIndexed() or ulTaskNotifyTakeIndexed() to 1994 | * [optionally] block to wait for a notification to be pending. The task does 1995 | * not consume any CPU time while it is in the Blocked state. 1996 | * 1997 | * A notification sent to a task will remain pending until it is cleared by the 1998 | * task calling xTaskNotifyWaitIndexed() or ulTaskNotifyTakeIndexed() (or their 1999 | * un-indexed equivalents). If the task was already in the Blocked state to 2000 | * wait for a notification when the notification arrives then the task will 2001 | * automatically be removed from the Blocked state (unblocked) and the 2002 | * notification cleared. 2003 | * 2004 | * **NOTE** Each notification within the array operates independently - a task 2005 | * can only block on one notification within the array at a time and will not be 2006 | * unblocked by a notification sent to any other array index. 2007 | * 2008 | * Backward compatibility information: 2009 | * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and 2010 | * all task notification API functions operated on that value. Replacing the 2011 | * single notification value with an array of notification values necessitated a 2012 | * new set of API functions that could address specific notifications within the 2013 | * array. xTaskNotify() is the original API function, and remains backward 2014 | * compatible by always operating on the notification value at index 0 in the 2015 | * array. Calling xTaskNotify() is equivalent to calling xTaskNotifyIndexed() 2016 | * with the uxIndexToNotify parameter set to 0. 2017 | * 2018 | * @param xTaskToNotify The handle of the task being notified. The handle to a 2019 | * task can be returned from the xTaskCreate() API function used to create the 2020 | * task, and the handle of the currently running task can be obtained by calling 2021 | * xTaskGetCurrentTaskHandle(). 2022 | * 2023 | * @param uxIndexToNotify The index within the target task's array of 2024 | * notification values to which the notification is to be sent. uxIndexToNotify 2025 | * must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES. xTaskNotify() does 2026 | * not have this parameter and always sends notifications to index 0. 2027 | * 2028 | * @param ulValue Data that can be sent with the notification. How the data is 2029 | * used depends on the value of the eAction parameter. 2030 | * 2031 | * @param eAction Specifies how the notification updates the task's notification 2032 | * value, if at all. Valid values for eAction are as follows: 2033 | * 2034 | * eSetBits - 2035 | * The target notification value is bitwise ORed with ulValue. 2036 | * xTaskNotifyIndexed() always returns pdPASS in this case. 2037 | * 2038 | * eIncrement - 2039 | * The target notification value is incremented. ulValue is not used and 2040 | * xTaskNotifyIndexed() always returns pdPASS in this case. 2041 | * 2042 | * eSetValueWithOverwrite - 2043 | * The target notification value is set to the value of ulValue, even if the 2044 | * task being notified had not yet processed the previous notification at the 2045 | * same array index (the task already had a notification pending at that index). 2046 | * xTaskNotifyIndexed() always returns pdPASS in this case. 2047 | * 2048 | * eSetValueWithoutOverwrite - 2049 | * If the task being notified did not already have a notification pending at the 2050 | * same array index then the target notification value is set to ulValue and 2051 | * xTaskNotifyIndexed() will return pdPASS. If the task being notified already 2052 | * had a notification pending at the same array index then no action is 2053 | * performed and pdFAIL is returned. 2054 | * 2055 | * eNoAction - 2056 | * The task receives a notification at the specified array index without the 2057 | * notification value at that index being updated. ulValue is not used and 2058 | * xTaskNotifyIndexed() always returns pdPASS in this case. 2059 | * 2060 | * pulPreviousNotificationValue - 2061 | * Can be used to pass out the subject task's notification value before any 2062 | * bits are modified by the notify function. 2063 | * 2064 | * @return Dependent on the value of eAction. See the description of the 2065 | * eAction parameter. 2066 | * 2067 | * \defgroup xTaskNotifyIndexed xTaskNotifyIndexed 2068 | * \ingroup TaskNotifications 2069 | */ 2070 | BaseType_t xTaskGenericNotify( TaskHandle_t xTaskToNotify, 2071 | UBaseType_t uxIndexToNotify, 2072 | uint32_t ulValue, 2073 | eNotifyAction eAction, 2074 | uint32_t * pulPreviousNotificationValue ) PRIVILEGED_FUNCTION; 2075 | #define xTaskNotify( xTaskToNotify, ulValue, eAction ) \ 2076 | xTaskGenericNotify( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( ulValue ), ( eAction ), NULL ) 2077 | #define xTaskNotifyIndexed( xTaskToNotify, uxIndexToNotify, ulValue, eAction ) \ 2078 | xTaskGenericNotify( ( xTaskToNotify ), ( uxIndexToNotify ), ( ulValue ), ( eAction ), NULL ) 2079 | 2080 | /** 2081 | * task. h 2082 | * @code{c} 2083 | * BaseType_t xTaskNotifyAndQueryIndexed( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotifyValue ); 2084 | * BaseType_t xTaskNotifyAndQuery( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotifyValue ); 2085 | * @endcode 2086 | * 2087 | * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details. 2088 | * 2089 | * xTaskNotifyAndQueryIndexed() performs the same operation as 2090 | * xTaskNotifyIndexed() with the addition that it also returns the subject 2091 | * task's prior notification value (the notification value at the time the 2092 | * function is called rather than when the function returns) in the additional 2093 | * pulPreviousNotifyValue parameter. 2094 | * 2095 | * xTaskNotifyAndQuery() performs the same operation as xTaskNotify() with the 2096 | * addition that it also returns the subject task's prior notification value 2097 | * (the notification value as it was at the time the function is called, rather 2098 | * than when the function returns) in the additional pulPreviousNotifyValue 2099 | * parameter. 2100 | * 2101 | * \defgroup xTaskNotifyAndQueryIndexed xTaskNotifyAndQueryIndexed 2102 | * \ingroup TaskNotifications 2103 | */ 2104 | #define xTaskNotifyAndQuery( xTaskToNotify, ulValue, eAction, pulPreviousNotifyValue ) \ 2105 | xTaskGenericNotify( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( ulValue ), ( eAction ), ( pulPreviousNotifyValue ) ) 2106 | #define xTaskNotifyAndQueryIndexed( xTaskToNotify, uxIndexToNotify, ulValue, eAction, pulPreviousNotifyValue ) \ 2107 | xTaskGenericNotify( ( xTaskToNotify ), ( uxIndexToNotify ), ( ulValue ), ( eAction ), ( pulPreviousNotifyValue ) ) 2108 | 2109 | /** 2110 | * task. h 2111 | * @code{c} 2112 | * BaseType_t xTaskNotifyIndexedFromISR( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction, BaseType_t *pxHigherPriorityTaskWoken ); 2113 | * BaseType_t xTaskNotifyFromISR( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, BaseType_t *pxHigherPriorityTaskWoken ); 2114 | * @endcode 2115 | * 2116 | * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details. 2117 | * 2118 | * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for these 2119 | * functions to be available. 2120 | * 2121 | * A version of xTaskNotifyIndexed() that can be used from an interrupt service 2122 | * routine (ISR). 2123 | * 2124 | * Each task has a private array of "notification values" (or 'notifications'), 2125 | * each of which is a 32-bit unsigned integer (uint32_t). The constant 2126 | * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the 2127 | * array, and (for backward compatibility) defaults to 1 if left undefined. 2128 | * Prior to FreeRTOS V10.4.0 there was only one notification value per task. 2129 | * 2130 | * Events can be sent to a task using an intermediary object. Examples of such 2131 | * objects are queues, semaphores, mutexes and event groups. Task notifications 2132 | * are a method of sending an event directly to a task without the need for such 2133 | * an intermediary object. 2134 | * 2135 | * A notification sent to a task can optionally perform an action, such as 2136 | * update, overwrite or increment one of the task's notification values. In 2137 | * that way task notifications can be used to send data to a task, or be used as 2138 | * light weight and fast binary or counting semaphores. 2139 | * 2140 | * A task can use xTaskNotifyWaitIndexed() to [optionally] block to wait for a 2141 | * notification to be pending, or ulTaskNotifyTakeIndexed() to [optionally] block 2142 | * to wait for a notification value to have a non-zero value. The task does 2143 | * not consume any CPU time while it is in the Blocked state. 2144 | * 2145 | * A notification sent to a task will remain pending until it is cleared by the 2146 | * task calling xTaskNotifyWaitIndexed() or ulTaskNotifyTakeIndexed() (or their 2147 | * un-indexed equivalents). If the task was already in the Blocked state to 2148 | * wait for a notification when the notification arrives then the task will 2149 | * automatically be removed from the Blocked state (unblocked) and the 2150 | * notification cleared. 2151 | * 2152 | * **NOTE** Each notification within the array operates independently - a task 2153 | * can only block on one notification within the array at a time and will not be 2154 | * unblocked by a notification sent to any other array index. 2155 | * 2156 | * Backward compatibility information: 2157 | * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and 2158 | * all task notification API functions operated on that value. Replacing the 2159 | * single notification value with an array of notification values necessitated a 2160 | * new set of API functions that could address specific notifications within the 2161 | * array. xTaskNotifyFromISR() is the original API function, and remains 2162 | * backward compatible by always operating on the notification value at index 0 2163 | * within the array. Calling xTaskNotifyFromISR() is equivalent to calling 2164 | * xTaskNotifyIndexedFromISR() with the uxIndexToNotify parameter set to 0. 2165 | * 2166 | * @param uxIndexToNotify The index within the target task's array of 2167 | * notification values to which the notification is to be sent. uxIndexToNotify 2168 | * must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES. xTaskNotifyFromISR() 2169 | * does not have this parameter and always sends notifications to index 0. 2170 | * 2171 | * @param xTaskToNotify The handle of the task being notified. The handle to a 2172 | * task can be returned from the xTaskCreate() API function used to create the 2173 | * task, and the handle of the currently running task can be obtained by calling 2174 | * xTaskGetCurrentTaskHandle(). 2175 | * 2176 | * @param ulValue Data that can be sent with the notification. How the data is 2177 | * used depends on the value of the eAction parameter. 2178 | * 2179 | * @param eAction Specifies how the notification updates the task's notification 2180 | * value, if at all. Valid values for eAction are as follows: 2181 | * 2182 | * eSetBits - 2183 | * The task's notification value is bitwise ORed with ulValue. xTaskNotify() 2184 | * always returns pdPASS in this case. 2185 | * 2186 | * eIncrement - 2187 | * The task's notification value is incremented. ulValue is not used and 2188 | * xTaskNotify() always returns pdPASS in this case. 2189 | * 2190 | * eSetValueWithOverwrite - 2191 | * The task's notification value is set to the value of ulValue, even if the 2192 | * task being notified had not yet processed the previous notification (the 2193 | * task already had a notification pending). xTaskNotify() always returns 2194 | * pdPASS in this case. 2195 | * 2196 | * eSetValueWithoutOverwrite - 2197 | * If the task being notified did not already have a notification pending then 2198 | * the task's notification value is set to ulValue and xTaskNotify() will 2199 | * return pdPASS. If the task being notified already had a notification 2200 | * pending then no action is performed and pdFAIL is returned. 2201 | * 2202 | * eNoAction - 2203 | * The task receives a notification without its notification value being 2204 | * updated. ulValue is not used and xTaskNotify() always returns pdPASS in 2205 | * this case. 2206 | * 2207 | * @param pxHigherPriorityTaskWoken xTaskNotifyFromISR() will set 2208 | * *pxHigherPriorityTaskWoken to pdTRUE if sending the notification caused the 2209 | * task to which the notification was sent to leave the Blocked state, and the 2210 | * unblocked task has a priority higher than the currently running task. If 2211 | * xTaskNotifyFromISR() sets this value to pdTRUE then a context switch should 2212 | * be requested before the interrupt is exited. How a context switch is 2213 | * requested from an ISR is dependent on the port - see the documentation page 2214 | * for the port in use. 2215 | * 2216 | * @return Dependent on the value of eAction. See the description of the 2217 | * eAction parameter. 2218 | * 2219 | * \defgroup xTaskNotifyIndexedFromISR xTaskNotifyIndexedFromISR 2220 | * \ingroup TaskNotifications 2221 | */ 2222 | BaseType_t xTaskGenericNotifyFromISR( TaskHandle_t xTaskToNotify, 2223 | UBaseType_t uxIndexToNotify, 2224 | uint32_t ulValue, 2225 | eNotifyAction eAction, 2226 | uint32_t * pulPreviousNotificationValue, 2227 | BaseType_t * pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION; 2228 | #define xTaskNotifyFromISR( xTaskToNotify, ulValue, eAction, pxHigherPriorityTaskWoken ) \ 2229 | xTaskGenericNotifyFromISR( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( ulValue ), ( eAction ), NULL, ( pxHigherPriorityTaskWoken ) ) 2230 | #define xTaskNotifyIndexedFromISR( xTaskToNotify, uxIndexToNotify, ulValue, eAction, pxHigherPriorityTaskWoken ) \ 2231 | xTaskGenericNotifyFromISR( ( xTaskToNotify ), ( uxIndexToNotify ), ( ulValue ), ( eAction ), NULL, ( pxHigherPriorityTaskWoken ) ) 2232 | 2233 | /** 2234 | * task. h 2235 | * @code{c} 2236 | * BaseType_t xTaskNotifyAndQueryIndexedFromISR( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotificationValue, BaseType_t *pxHigherPriorityTaskWoken ); 2237 | * BaseType_t xTaskNotifyAndQueryFromISR( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotificationValue, BaseType_t *pxHigherPriorityTaskWoken ); 2238 | * @endcode 2239 | * 2240 | * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details. 2241 | * 2242 | * xTaskNotifyAndQueryIndexedFromISR() performs the same operation as 2243 | * xTaskNotifyIndexedFromISR() with the addition that it also returns the 2244 | * subject task's prior notification value (the notification value at the time 2245 | * the function is called rather than at the time the function returns) in the 2246 | * additional pulPreviousNotifyValue parameter. 2247 | * 2248 | * xTaskNotifyAndQueryFromISR() performs the same operation as 2249 | * xTaskNotifyFromISR() with the addition that it also returns the subject 2250 | * task's prior notification value (the notification value at the time the 2251 | * function is called rather than at the time the function returns) in the 2252 | * additional pulPreviousNotifyValue parameter. 2253 | * 2254 | * \defgroup xTaskNotifyAndQueryIndexedFromISR xTaskNotifyAndQueryIndexedFromISR 2255 | * \ingroup TaskNotifications 2256 | */ 2257 | #define xTaskNotifyAndQueryIndexedFromISR( xTaskToNotify, uxIndexToNotify, ulValue, eAction, pulPreviousNotificationValue, pxHigherPriorityTaskWoken ) \ 2258 | xTaskGenericNotifyFromISR( ( xTaskToNotify ), ( uxIndexToNotify ), ( ulValue ), ( eAction ), ( pulPreviousNotificationValue ), ( pxHigherPriorityTaskWoken ) ) 2259 | #define xTaskNotifyAndQueryFromISR( xTaskToNotify, ulValue, eAction, pulPreviousNotificationValue, pxHigherPriorityTaskWoken ) \ 2260 | xTaskGenericNotifyFromISR( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( ulValue ), ( eAction ), ( pulPreviousNotificationValue ), ( pxHigherPriorityTaskWoken ) ) 2261 | 2262 | /** 2263 | * task. h 2264 | * @code{c} 2265 | * BaseType_t xTaskNotifyWaitIndexed( UBaseType_t uxIndexToWaitOn, uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait ); 2266 | * 2267 | * BaseType_t xTaskNotifyWait( uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait ); 2268 | * @endcode 2269 | * 2270 | * Waits for a direct to task notification to be pending at a given index within 2271 | * an array of direct to task notifications. 2272 | * 2273 | * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details. 2274 | * 2275 | * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this 2276 | * function to be available. 2277 | * 2278 | * Each task has a private array of "notification values" (or 'notifications'), 2279 | * each of which is a 32-bit unsigned integer (uint32_t). The constant 2280 | * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the 2281 | * array, and (for backward compatibility) defaults to 1 if left undefined. 2282 | * Prior to FreeRTOS V10.4.0 there was only one notification value per task. 2283 | * 2284 | * Events can be sent to a task using an intermediary object. Examples of such 2285 | * objects are queues, semaphores, mutexes and event groups. Task notifications 2286 | * are a method of sending an event directly to a task without the need for such 2287 | * an intermediary object. 2288 | * 2289 | * A notification sent to a task can optionally perform an action, such as 2290 | * update, overwrite or increment one of the task's notification values. In 2291 | * that way task notifications can be used to send data to a task, or be used as 2292 | * light weight and fast binary or counting semaphores. 2293 | * 2294 | * A notification sent to a task will remain pending until it is cleared by the 2295 | * task calling xTaskNotifyWaitIndexed() or ulTaskNotifyTakeIndexed() (or their 2296 | * un-indexed equivalents). If the task was already in the Blocked state to 2297 | * wait for a notification when the notification arrives then the task will 2298 | * automatically be removed from the Blocked state (unblocked) and the 2299 | * notification cleared. 2300 | * 2301 | * A task can use xTaskNotifyWaitIndexed() to [optionally] block to wait for a 2302 | * notification to be pending, or ulTaskNotifyTakeIndexed() to [optionally] block 2303 | * to wait for a notification value to have a non-zero value. The task does 2304 | * not consume any CPU time while it is in the Blocked state. 2305 | * 2306 | * **NOTE** Each notification within the array operates independently - a task 2307 | * can only block on one notification within the array at a time and will not be 2308 | * unblocked by a notification sent to any other array index. 2309 | * 2310 | * Backward compatibility information: 2311 | * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and 2312 | * all task notification API functions operated on that value. Replacing the 2313 | * single notification value with an array of notification values necessitated a 2314 | * new set of API functions that could address specific notifications within the 2315 | * array. xTaskNotifyWait() is the original API function, and remains backward 2316 | * compatible by always operating on the notification value at index 0 in the 2317 | * array. Calling xTaskNotifyWait() is equivalent to calling 2318 | * xTaskNotifyWaitIndexed() with the uxIndexToWaitOn parameter set to 0. 2319 | * 2320 | * @param uxIndexToWaitOn The index within the calling task's array of 2321 | * notification values on which the calling task will wait for a notification to 2322 | * be received. uxIndexToWaitOn must be less than 2323 | * configTASK_NOTIFICATION_ARRAY_ENTRIES. xTaskNotifyWait() does 2324 | * not have this parameter and always waits for notifications on index 0. 2325 | * 2326 | * @param ulBitsToClearOnEntry Bits that are set in ulBitsToClearOnEntry value 2327 | * will be cleared in the calling task's notification value before the task 2328 | * checks to see if any notifications are pending, and optionally blocks if no 2329 | * notifications are pending. Setting ulBitsToClearOnEntry to ULONG_MAX (if 2330 | * limits.h is included) or 0xffffffffUL (if limits.h is not included) will have 2331 | * the effect of resetting the task's notification value to 0. Setting 2332 | * ulBitsToClearOnEntry to 0 will leave the task's notification value unchanged. 2333 | * 2334 | * @param ulBitsToClearOnExit If a notification is pending or received before 2335 | * the calling task exits the xTaskNotifyWait() function then the task's 2336 | * notification value (see the xTaskNotify() API function) is passed out using 2337 | * the pulNotificationValue parameter. Then any bits that are set in 2338 | * ulBitsToClearOnExit will be cleared in the task's notification value (note 2339 | * *pulNotificationValue is set before any bits are cleared). Setting 2340 | * ulBitsToClearOnExit to ULONG_MAX (if limits.h is included) or 0xffffffffUL 2341 | * (if limits.h is not included) will have the effect of resetting the task's 2342 | * notification value to 0 before the function exits. Setting 2343 | * ulBitsToClearOnExit to 0 will leave the task's notification value unchanged 2344 | * when the function exits (in which case the value passed out in 2345 | * pulNotificationValue will match the task's notification value). 2346 | * 2347 | * @param pulNotificationValue Used to pass the task's notification value out 2348 | * of the function. Note the value passed out will not be effected by the 2349 | * clearing of any bits caused by ulBitsToClearOnExit being non-zero. 2350 | * 2351 | * @param xTicksToWait The maximum amount of time that the task should wait in 2352 | * the Blocked state for a notification to be received, should a notification 2353 | * not already be pending when xTaskNotifyWait() was called. The task 2354 | * will not consume any processing time while it is in the Blocked state. This 2355 | * is specified in kernel ticks, the macro pdMS_TO_TICKS( value_in_ms ) can be 2356 | * used to convert a time specified in milliseconds to a time specified in 2357 | * ticks. 2358 | * 2359 | * @return If a notification was received (including notifications that were 2360 | * already pending when xTaskNotifyWait was called) then pdPASS is 2361 | * returned. Otherwise pdFAIL is returned. 2362 | * 2363 | * \defgroup xTaskNotifyWaitIndexed xTaskNotifyWaitIndexed 2364 | * \ingroup TaskNotifications 2365 | */ 2366 | BaseType_t xTaskGenericNotifyWait( UBaseType_t uxIndexToWaitOn, 2367 | uint32_t ulBitsToClearOnEntry, 2368 | uint32_t ulBitsToClearOnExit, 2369 | uint32_t * pulNotificationValue, 2370 | TickType_t xTicksToWait ) PRIVILEGED_FUNCTION; 2371 | #define xTaskNotifyWait( ulBitsToClearOnEntry, ulBitsToClearOnExit, pulNotificationValue, xTicksToWait ) \ 2372 | xTaskGenericNotifyWait( tskDEFAULT_INDEX_TO_NOTIFY, ( ulBitsToClearOnEntry ), ( ulBitsToClearOnExit ), ( pulNotificationValue ), ( xTicksToWait ) ) 2373 | #define xTaskNotifyWaitIndexed( uxIndexToWaitOn, ulBitsToClearOnEntry, ulBitsToClearOnExit, pulNotificationValue, xTicksToWait ) \ 2374 | xTaskGenericNotifyWait( ( uxIndexToWaitOn ), ( ulBitsToClearOnEntry ), ( ulBitsToClearOnExit ), ( pulNotificationValue ), ( xTicksToWait ) ) 2375 | 2376 | /** 2377 | * task. h 2378 | * @code{c} 2379 | * BaseType_t xTaskNotifyGiveIndexed( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify ); 2380 | * BaseType_t xTaskNotifyGive( TaskHandle_t xTaskToNotify ); 2381 | * @endcode 2382 | * 2383 | * Sends a direct to task notification to a particular index in the target 2384 | * task's notification array in a manner similar to giving a counting semaphore. 2385 | * 2386 | * See https://www.FreeRTOS.org/RTOS-task-notifications.html for more details. 2387 | * 2388 | * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for these 2389 | * macros to be available. 2390 | * 2391 | * Each task has a private array of "notification values" (or 'notifications'), 2392 | * each of which is a 32-bit unsigned integer (uint32_t). The constant 2393 | * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the 2394 | * array, and (for backward compatibility) defaults to 1 if left undefined. 2395 | * Prior to FreeRTOS V10.4.0 there was only one notification value per task. 2396 | * 2397 | * Events can be sent to a task using an intermediary object. Examples of such 2398 | * objects are queues, semaphores, mutexes and event groups. Task notifications 2399 | * are a method of sending an event directly to a task without the need for such 2400 | * an intermediary object. 2401 | * 2402 | * A notification sent to a task can optionally perform an action, such as 2403 | * update, overwrite or increment one of the task's notification values. In 2404 | * that way task notifications can be used to send data to a task, or be used as 2405 | * light weight and fast binary or counting semaphores. 2406 | * 2407 | * xTaskNotifyGiveIndexed() is a helper macro intended for use when task 2408 | * notifications are used as light weight and faster binary or counting 2409 | * semaphore equivalents. Actual FreeRTOS semaphores are given using the 2410 | * xSemaphoreGive() API function, the equivalent action that instead uses a task 2411 | * notification is xTaskNotifyGiveIndexed(). 2412 | * 2413 | * When task notifications are being used as a binary or counting semaphore 2414 | * equivalent then the task being notified should wait for the notification 2415 | * using the ulTaskNotifyTakeIndexed() API function rather than the 2416 | * xTaskNotifyWaitIndexed() API function. 2417 | * 2418 | * **NOTE** Each notification within the array operates independently - a task 2419 | * can only block on one notification within the array at a time and will not be 2420 | * unblocked by a notification sent to any other array index. 2421 | * 2422 | * Backward compatibility information: 2423 | * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and 2424 | * all task notification API functions operated on that value. Replacing the 2425 | * single notification value with an array of notification values necessitated a 2426 | * new set of API functions that could address specific notifications within the 2427 | * array. xTaskNotifyGive() is the original API function, and remains backward 2428 | * compatible by always operating on the notification value at index 0 in the 2429 | * array. Calling xTaskNotifyGive() is equivalent to calling 2430 | * xTaskNotifyGiveIndexed() with the uxIndexToNotify parameter set to 0. 2431 | * 2432 | * @param xTaskToNotify The handle of the task being notified. The handle to a 2433 | * task can be returned from the xTaskCreate() API function used to create the 2434 | * task, and the handle of the currently running task can be obtained by calling 2435 | * xTaskGetCurrentTaskHandle(). 2436 | * 2437 | * @param uxIndexToNotify The index within the target task's array of 2438 | * notification values to which the notification is to be sent. uxIndexToNotify 2439 | * must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES. xTaskNotifyGive() 2440 | * does not have this parameter and always sends notifications to index 0. 2441 | * 2442 | * @return xTaskNotifyGive() is a macro that calls xTaskNotify() with the 2443 | * eAction parameter set to eIncrement - so pdPASS is always returned. 2444 | * 2445 | * \defgroup xTaskNotifyGiveIndexed xTaskNotifyGiveIndexed 2446 | * \ingroup TaskNotifications 2447 | */ 2448 | #define xTaskNotifyGive( xTaskToNotify ) \ 2449 | xTaskGenericNotify( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( 0 ), eIncrement, NULL ) 2450 | #define xTaskNotifyGiveIndexed( xTaskToNotify, uxIndexToNotify ) \ 2451 | xTaskGenericNotify( ( xTaskToNotify ), ( uxIndexToNotify ), ( 0 ), eIncrement, NULL ) 2452 | 2453 | /** 2454 | * task. h 2455 | * @code{c} 2456 | * void vTaskNotifyGiveIndexedFromISR( TaskHandle_t xTaskHandle, UBaseType_t uxIndexToNotify, BaseType_t *pxHigherPriorityTaskWoken ); 2457 | * void vTaskNotifyGiveFromISR( TaskHandle_t xTaskHandle, BaseType_t *pxHigherPriorityTaskWoken ); 2458 | * @endcode 2459 | * 2460 | * A version of xTaskNotifyGiveIndexed() that can be called from an interrupt 2461 | * service routine (ISR). 2462 | * 2463 | * See https://www.FreeRTOS.org/RTOS-task-notifications.html for more details. 2464 | * 2465 | * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this macro 2466 | * to be available. 2467 | * 2468 | * Each task has a private array of "notification values" (or 'notifications'), 2469 | * each of which is a 32-bit unsigned integer (uint32_t). The constant 2470 | * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the 2471 | * array, and (for backward compatibility) defaults to 1 if left undefined. 2472 | * Prior to FreeRTOS V10.4.0 there was only one notification value per task. 2473 | * 2474 | * Events can be sent to a task using an intermediary object. Examples of such 2475 | * objects are queues, semaphores, mutexes and event groups. Task notifications 2476 | * are a method of sending an event directly to a task without the need for such 2477 | * an intermediary object. 2478 | * 2479 | * A notification sent to a task can optionally perform an action, such as 2480 | * update, overwrite or increment one of the task's notification values. In 2481 | * that way task notifications can be used to send data to a task, or be used as 2482 | * light weight and fast binary or counting semaphores. 2483 | * 2484 | * vTaskNotifyGiveIndexedFromISR() is intended for use when task notifications 2485 | * are used as light weight and faster binary or counting semaphore equivalents. 2486 | * Actual FreeRTOS semaphores are given from an ISR using the 2487 | * xSemaphoreGiveFromISR() API function, the equivalent action that instead uses 2488 | * a task notification is vTaskNotifyGiveIndexedFromISR(). 2489 | * 2490 | * When task notifications are being used as a binary or counting semaphore 2491 | * equivalent then the task being notified should wait for the notification 2492 | * using the ulTaskNotifyTakeIndexed() API function rather than the 2493 | * xTaskNotifyWaitIndexed() API function. 2494 | * 2495 | * **NOTE** Each notification within the array operates independently - a task 2496 | * can only block on one notification within the array at a time and will not be 2497 | * unblocked by a notification sent to any other array index. 2498 | * 2499 | * Backward compatibility information: 2500 | * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and 2501 | * all task notification API functions operated on that value. Replacing the 2502 | * single notification value with an array of notification values necessitated a 2503 | * new set of API functions that could address specific notifications within the 2504 | * array. xTaskNotifyFromISR() is the original API function, and remains 2505 | * backward compatible by always operating on the notification value at index 0 2506 | * within the array. Calling xTaskNotifyGiveFromISR() is equivalent to calling 2507 | * xTaskNotifyGiveIndexedFromISR() with the uxIndexToNotify parameter set to 0. 2508 | * 2509 | * @param xTaskToNotify The handle of the task being notified. The handle to a 2510 | * task can be returned from the xTaskCreate() API function used to create the 2511 | * task, and the handle of the currently running task can be obtained by calling 2512 | * xTaskGetCurrentTaskHandle(). 2513 | * 2514 | * @param uxIndexToNotify The index within the target task's array of 2515 | * notification values to which the notification is to be sent. uxIndexToNotify 2516 | * must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES. 2517 | * xTaskNotifyGiveFromISR() does not have this parameter and always sends 2518 | * notifications to index 0. 2519 | * 2520 | * @param pxHigherPriorityTaskWoken vTaskNotifyGiveFromISR() will set 2521 | * *pxHigherPriorityTaskWoken to pdTRUE if sending the notification caused the 2522 | * task to which the notification was sent to leave the Blocked state, and the 2523 | * unblocked task has a priority higher than the currently running task. If 2524 | * vTaskNotifyGiveFromISR() sets this value to pdTRUE then a context switch 2525 | * should be requested before the interrupt is exited. How a context switch is 2526 | * requested from an ISR is dependent on the port - see the documentation page 2527 | * for the port in use. 2528 | * 2529 | * \defgroup vTaskNotifyGiveIndexedFromISR vTaskNotifyGiveIndexedFromISR 2530 | * \ingroup TaskNotifications 2531 | */ 2532 | void vTaskGenericNotifyGiveFromISR( TaskHandle_t xTaskToNotify, 2533 | UBaseType_t uxIndexToNotify, 2534 | BaseType_t * pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION; 2535 | #define vTaskNotifyGiveFromISR( xTaskToNotify, pxHigherPriorityTaskWoken ) \ 2536 | vTaskGenericNotifyGiveFromISR( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( pxHigherPriorityTaskWoken ) ) 2537 | #define vTaskNotifyGiveIndexedFromISR( xTaskToNotify, uxIndexToNotify, pxHigherPriorityTaskWoken ) \ 2538 | vTaskGenericNotifyGiveFromISR( ( xTaskToNotify ), ( uxIndexToNotify ), ( pxHigherPriorityTaskWoken ) ) 2539 | 2540 | /** 2541 | * task. h 2542 | * @code{c} 2543 | * uint32_t ulTaskNotifyTakeIndexed( UBaseType_t uxIndexToWaitOn, BaseType_t xClearCountOnExit, TickType_t xTicksToWait ); 2544 | * 2545 | * uint32_t ulTaskNotifyTake( BaseType_t xClearCountOnExit, TickType_t xTicksToWait ); 2546 | * @endcode 2547 | * 2548 | * Waits for a direct to task notification on a particular index in the calling 2549 | * task's notification array in a manner similar to taking a counting semaphore. 2550 | * 2551 | * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details. 2552 | * 2553 | * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this 2554 | * function to be available. 2555 | * 2556 | * Each task has a private array of "notification values" (or 'notifications'), 2557 | * each of which is a 32-bit unsigned integer (uint32_t). The constant 2558 | * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the 2559 | * array, and (for backward compatibility) defaults to 1 if left undefined. 2560 | * Prior to FreeRTOS V10.4.0 there was only one notification value per task. 2561 | * 2562 | * Events can be sent to a task using an intermediary object. Examples of such 2563 | * objects are queues, semaphores, mutexes and event groups. Task notifications 2564 | * are a method of sending an event directly to a task without the need for such 2565 | * an intermediary object. 2566 | * 2567 | * A notification sent to a task can optionally perform an action, such as 2568 | * update, overwrite or increment one of the task's notification values. In 2569 | * that way task notifications can be used to send data to a task, or be used as 2570 | * light weight and fast binary or counting semaphores. 2571 | * 2572 | * ulTaskNotifyTakeIndexed() is intended for use when a task notification is 2573 | * used as a faster and lighter weight binary or counting semaphore alternative. 2574 | * Actual FreeRTOS semaphores are taken using the xSemaphoreTake() API function, 2575 | * the equivalent action that instead uses a task notification is 2576 | * ulTaskNotifyTakeIndexed(). 2577 | * 2578 | * When a task is using its notification value as a binary or counting semaphore 2579 | * other tasks should send notifications to it using the xTaskNotifyGiveIndexed() 2580 | * macro, or xTaskNotifyIndex() function with the eAction parameter set to 2581 | * eIncrement. 2582 | * 2583 | * ulTaskNotifyTakeIndexed() can either clear the task's notification value at 2584 | * the array index specified by the uxIndexToWaitOn parameter to zero on exit, 2585 | * in which case the notification value acts like a binary semaphore, or 2586 | * decrement the notification value on exit, in which case the notification 2587 | * value acts like a counting semaphore. 2588 | * 2589 | * A task can use ulTaskNotifyTakeIndexed() to [optionally] block to wait for 2590 | * a notification. The task does not consume any CPU time while it is in the 2591 | * Blocked state. 2592 | * 2593 | * Where as xTaskNotifyWaitIndexed() will return when a notification is pending, 2594 | * ulTaskNotifyTakeIndexed() will return when the task's notification value is 2595 | * not zero. 2596 | * 2597 | * **NOTE** Each notification within the array operates independently - a task 2598 | * can only block on one notification within the array at a time and will not be 2599 | * unblocked by a notification sent to any other array index. 2600 | * 2601 | * Backward compatibility information: 2602 | * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and 2603 | * all task notification API functions operated on that value. Replacing the 2604 | * single notification value with an array of notification values necessitated a 2605 | * new set of API functions that could address specific notifications within the 2606 | * array. ulTaskNotifyTake() is the original API function, and remains backward 2607 | * compatible by always operating on the notification value at index 0 in the 2608 | * array. Calling ulTaskNotifyTake() is equivalent to calling 2609 | * ulTaskNotifyTakeIndexed() with the uxIndexToWaitOn parameter set to 0. 2610 | * 2611 | * @param uxIndexToWaitOn The index within the calling task's array of 2612 | * notification values on which the calling task will wait for a notification to 2613 | * be non-zero. uxIndexToWaitOn must be less than 2614 | * configTASK_NOTIFICATION_ARRAY_ENTRIES. xTaskNotifyTake() does 2615 | * not have this parameter and always waits for notifications on index 0. 2616 | * 2617 | * @param xClearCountOnExit if xClearCountOnExit is pdFALSE then the task's 2618 | * notification value is decremented when the function exits. In this way the 2619 | * notification value acts like a counting semaphore. If xClearCountOnExit is 2620 | * not pdFALSE then the task's notification value is cleared to zero when the 2621 | * function exits. In this way the notification value acts like a binary 2622 | * semaphore. 2623 | * 2624 | * @param xTicksToWait The maximum amount of time that the task should wait in 2625 | * the Blocked state for the task's notification value to be greater than zero, 2626 | * should the count not already be greater than zero when 2627 | * ulTaskNotifyTake() was called. The task will not consume any processing 2628 | * time while it is in the Blocked state. This is specified in kernel ticks, 2629 | * the macro pdMS_TO_TICKS( value_in_ms ) can be used to convert a time 2630 | * specified in milliseconds to a time specified in ticks. 2631 | * 2632 | * @return The task's notification count before it is either cleared to zero or 2633 | * decremented (see the xClearCountOnExit parameter). 2634 | * 2635 | * \defgroup ulTaskNotifyTakeIndexed ulTaskNotifyTakeIndexed 2636 | * \ingroup TaskNotifications 2637 | */ 2638 | uint32_t ulTaskGenericNotifyTake( UBaseType_t uxIndexToWaitOn, 2639 | BaseType_t xClearCountOnExit, 2640 | TickType_t xTicksToWait ) PRIVILEGED_FUNCTION; 2641 | #define ulTaskNotifyTake( xClearCountOnExit, xTicksToWait ) \ 2642 | ulTaskGenericNotifyTake( ( tskDEFAULT_INDEX_TO_NOTIFY ), ( xClearCountOnExit ), ( xTicksToWait ) ) 2643 | #define ulTaskNotifyTakeIndexed( uxIndexToWaitOn, xClearCountOnExit, xTicksToWait ) \ 2644 | ulTaskGenericNotifyTake( ( uxIndexToWaitOn ), ( xClearCountOnExit ), ( xTicksToWait ) ) 2645 | 2646 | /** 2647 | * task. h 2648 | * @code{c} 2649 | * BaseType_t xTaskNotifyStateClearIndexed( TaskHandle_t xTask, UBaseType_t uxIndexToCLear ); 2650 | * 2651 | * BaseType_t xTaskNotifyStateClear( TaskHandle_t xTask ); 2652 | * @endcode 2653 | * 2654 | * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details. 2655 | * 2656 | * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for these 2657 | * functions to be available. 2658 | * 2659 | * Each task has a private array of "notification values" (or 'notifications'), 2660 | * each of which is a 32-bit unsigned integer (uint32_t). The constant 2661 | * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the 2662 | * array, and (for backward compatibility) defaults to 1 if left undefined. 2663 | * Prior to FreeRTOS V10.4.0 there was only one notification value per task. 2664 | * 2665 | * If a notification is sent to an index within the array of notifications then 2666 | * the notification at that index is said to be 'pending' until it is read or 2667 | * explicitly cleared by the receiving task. xTaskNotifyStateClearIndexed() 2668 | * is the function that clears a pending notification without reading the 2669 | * notification value. The notification value at the same array index is not 2670 | * altered. Set xTask to NULL to clear the notification state of the calling 2671 | * task. 2672 | * 2673 | * Backward compatibility information: 2674 | * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and 2675 | * all task notification API functions operated on that value. Replacing the 2676 | * single notification value with an array of notification values necessitated a 2677 | * new set of API functions that could address specific notifications within the 2678 | * array. xTaskNotifyStateClear() is the original API function, and remains 2679 | * backward compatible by always operating on the notification value at index 0 2680 | * within the array. Calling xTaskNotifyStateClear() is equivalent to calling 2681 | * xTaskNotifyStateClearIndexed() with the uxIndexToNotify parameter set to 0. 2682 | * 2683 | * @param xTask The handle of the RTOS task that will have a notification state 2684 | * cleared. Set xTask to NULL to clear a notification state in the calling 2685 | * task. To obtain a task's handle create the task using xTaskCreate() and 2686 | * make use of the pxCreatedTask parameter, or create the task using 2687 | * xTaskCreateStatic() and store the returned value, or use the task's name in 2688 | * a call to xTaskGetHandle(). 2689 | * 2690 | * @param uxIndexToClear The index within the target task's array of 2691 | * notification values to act upon. For example, setting uxIndexToClear to 1 2692 | * will clear the state of the notification at index 1 within the array. 2693 | * uxIndexToClear must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES. 2694 | * ulTaskNotifyStateClear() does not have this parameter and always acts on the 2695 | * notification at index 0. 2696 | * 2697 | * @return pdTRUE if the task's notification state was set to 2698 | * eNotWaitingNotification, otherwise pdFALSE. 2699 | * 2700 | * \defgroup xTaskNotifyStateClearIndexed xTaskNotifyStateClearIndexed 2701 | * \ingroup TaskNotifications 2702 | */ 2703 | BaseType_t xTaskGenericNotifyStateClear( TaskHandle_t xTask, 2704 | UBaseType_t uxIndexToClear ) PRIVILEGED_FUNCTION; 2705 | #define xTaskNotifyStateClear( xTask ) \ 2706 | xTaskGenericNotifyStateClear( ( xTask ), ( tskDEFAULT_INDEX_TO_NOTIFY ) ) 2707 | #define xTaskNotifyStateClearIndexed( xTask, uxIndexToClear ) \ 2708 | xTaskGenericNotifyStateClear( ( xTask ), ( uxIndexToClear ) ) 2709 | 2710 | /** 2711 | * task. h 2712 | * @code{c} 2713 | * uint32_t ulTaskNotifyValueClearIndexed( TaskHandle_t xTask, UBaseType_t uxIndexToClear, uint32_t ulBitsToClear ); 2714 | * 2715 | * uint32_t ulTaskNotifyValueClear( TaskHandle_t xTask, uint32_t ulBitsToClear ); 2716 | * @endcode 2717 | * 2718 | * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details. 2719 | * 2720 | * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for these 2721 | * functions to be available. 2722 | * 2723 | * Each task has a private array of "notification values" (or 'notifications'), 2724 | * each of which is a 32-bit unsigned integer (uint32_t). The constant 2725 | * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the 2726 | * array, and (for backward compatibility) defaults to 1 if left undefined. 2727 | * Prior to FreeRTOS V10.4.0 there was only one notification value per task. 2728 | * 2729 | * ulTaskNotifyValueClearIndexed() clears the bits specified by the 2730 | * ulBitsToClear bit mask in the notification value at array index uxIndexToClear 2731 | * of the task referenced by xTask. 2732 | * 2733 | * Backward compatibility information: 2734 | * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and 2735 | * all task notification API functions operated on that value. Replacing the 2736 | * single notification value with an array of notification values necessitated a 2737 | * new set of API functions that could address specific notifications within the 2738 | * array. ulTaskNotifyValueClear() is the original API function, and remains 2739 | * backward compatible by always operating on the notification value at index 0 2740 | * within the array. Calling ulTaskNotifyValueClear() is equivalent to calling 2741 | * ulTaskNotifyValueClearIndexed() with the uxIndexToClear parameter set to 0. 2742 | * 2743 | * @param xTask The handle of the RTOS task that will have bits in one of its 2744 | * notification values cleared. Set xTask to NULL to clear bits in a 2745 | * notification value of the calling task. To obtain a task's handle create the 2746 | * task using xTaskCreate() and make use of the pxCreatedTask parameter, or 2747 | * create the task using xTaskCreateStatic() and store the returned value, or 2748 | * use the task's name in a call to xTaskGetHandle(). 2749 | * 2750 | * @param uxIndexToClear The index within the target task's array of 2751 | * notification values in which to clear the bits. uxIndexToClear 2752 | * must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES. 2753 | * ulTaskNotifyValueClear() does not have this parameter and always clears bits 2754 | * in the notification value at index 0. 2755 | * 2756 | * @param ulBitsToClear Bit mask of the bits to clear in the notification value of 2757 | * xTask. Set a bit to 1 to clear the corresponding bits in the task's notification 2758 | * value. Set ulBitsToClear to 0xffffffff (UINT_MAX on 32-bit architectures) to clear 2759 | * the notification value to 0. Set ulBitsToClear to 0 to query the task's 2760 | * notification value without clearing any bits. 2761 | * 2762 | * 2763 | * @return The value of the target task's notification value before the bits 2764 | * specified by ulBitsToClear were cleared. 2765 | * \defgroup ulTaskNotifyValueClear ulTaskNotifyValueClear 2766 | * \ingroup TaskNotifications 2767 | */ 2768 | uint32_t ulTaskGenericNotifyValueClear( TaskHandle_t xTask, 2769 | UBaseType_t uxIndexToClear, 2770 | uint32_t ulBitsToClear ) PRIVILEGED_FUNCTION; 2771 | #define ulTaskNotifyValueClear( xTask, ulBitsToClear ) \ 2772 | ulTaskGenericNotifyValueClear( ( xTask ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( ulBitsToClear ) ) 2773 | #define ulTaskNotifyValueClearIndexed( xTask, uxIndexToClear, ulBitsToClear ) \ 2774 | ulTaskGenericNotifyValueClear( ( xTask ), ( uxIndexToClear ), ( ulBitsToClear ) ) 2775 | 2776 | /** 2777 | * task.h 2778 | * @code{c} 2779 | * void vTaskSetTimeOutState( TimeOut_t * const pxTimeOut ); 2780 | * @endcode 2781 | * 2782 | * Capture the current time for future use with xTaskCheckForTimeOut(). 2783 | * 2784 | * @param pxTimeOut Pointer to a timeout object into which the current time 2785 | * is to be captured. The captured time includes the tick count and the number 2786 | * of times the tick count has overflowed since the system first booted. 2787 | * \defgroup vTaskSetTimeOutState vTaskSetTimeOutState 2788 | * \ingroup TaskCtrl 2789 | */ 2790 | void vTaskSetTimeOutState( TimeOut_t * const pxTimeOut ) PRIVILEGED_FUNCTION; 2791 | 2792 | /** 2793 | * task.h 2794 | * @code{c} 2795 | * BaseType_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut, TickType_t * const pxTicksToWait ); 2796 | * @endcode 2797 | * 2798 | * Determines if pxTicksToWait ticks has passed since a time was captured 2799 | * using a call to vTaskSetTimeOutState(). The captured time includes the tick 2800 | * count and the number of times the tick count has overflowed. 2801 | * 2802 | * @param pxTimeOut The time status as captured previously using 2803 | * vTaskSetTimeOutState. If the timeout has not yet occurred, it is updated 2804 | * to reflect the current time status. 2805 | * @param pxTicksToWait The number of ticks to check for timeout i.e. if 2806 | * pxTicksToWait ticks have passed since pxTimeOut was last updated (either by 2807 | * vTaskSetTimeOutState() or xTaskCheckForTimeOut()), the timeout has occurred. 2808 | * If the timeout has not occurred, pxTicksToWait is updated to reflect the 2809 | * number of remaining ticks. 2810 | * 2811 | * @return If timeout has occurred, pdTRUE is returned. Otherwise pdFALSE is 2812 | * returned and pxTicksToWait is updated to reflect the number of remaining 2813 | * ticks. 2814 | * 2815 | * @see https://www.FreeRTOS.org/xTaskCheckForTimeOut.html 2816 | * 2817 | * Example Usage: 2818 | * @code{c} 2819 | * // Driver library function used to receive uxWantedBytes from an Rx buffer 2820 | * // that is filled by a UART interrupt. If there are not enough bytes in the 2821 | * // Rx buffer then the task enters the Blocked state until it is notified that 2822 | * // more data has been placed into the buffer. If there is still not enough 2823 | * // data then the task re-enters the Blocked state, and xTaskCheckForTimeOut() 2824 | * // is used to re-calculate the Block time to ensure the total amount of time 2825 | * // spent in the Blocked state does not exceed MAX_TIME_TO_WAIT. This 2826 | * // continues until either the buffer contains at least uxWantedBytes bytes, 2827 | * // or the total amount of time spent in the Blocked state reaches 2828 | * // MAX_TIME_TO_WAIT - at which point the task reads however many bytes are 2829 | * // available up to a maximum of uxWantedBytes. 2830 | * 2831 | * size_t xUART_Receive( uint8_t *pucBuffer, size_t uxWantedBytes ) 2832 | * { 2833 | * size_t uxReceived = 0; 2834 | * TickType_t xTicksToWait = MAX_TIME_TO_WAIT; 2835 | * TimeOut_t xTimeOut; 2836 | * 2837 | * // Initialize xTimeOut. This records the time at which this function 2838 | * // was entered. 2839 | * vTaskSetTimeOutState( &xTimeOut ); 2840 | * 2841 | * // Loop until the buffer contains the wanted number of bytes, or a 2842 | * // timeout occurs. 2843 | * while( UART_bytes_in_rx_buffer( pxUARTInstance ) < uxWantedBytes ) 2844 | * { 2845 | * // The buffer didn't contain enough data so this task is going to 2846 | * // enter the Blocked state. Adjusting xTicksToWait to account for 2847 | * // any time that has been spent in the Blocked state within this 2848 | * // function so far to ensure the total amount of time spent in the 2849 | * // Blocked state does not exceed MAX_TIME_TO_WAIT. 2850 | * if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) != pdFALSE ) 2851 | * { 2852 | * //Timed out before the wanted number of bytes were available, 2853 | * // exit the loop. 2854 | * break; 2855 | * } 2856 | * 2857 | * // Wait for a maximum of xTicksToWait ticks to be notified that the 2858 | * // receive interrupt has placed more data into the buffer. 2859 | * ulTaskNotifyTake( pdTRUE, xTicksToWait ); 2860 | * } 2861 | * 2862 | * // Attempt to read uxWantedBytes from the receive buffer into pucBuffer. 2863 | * // The actual number of bytes read (which might be less than 2864 | * // uxWantedBytes) is returned. 2865 | * uxReceived = UART_read_from_receive_buffer( pxUARTInstance, 2866 | * pucBuffer, 2867 | * uxWantedBytes ); 2868 | * 2869 | * return uxReceived; 2870 | * } 2871 | * @endcode 2872 | * \defgroup xTaskCheckForTimeOut xTaskCheckForTimeOut 2873 | * \ingroup TaskCtrl 2874 | */ 2875 | BaseType_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut, 2876 | TickType_t * const pxTicksToWait ) PRIVILEGED_FUNCTION; 2877 | 2878 | /** 2879 | * task.h 2880 | * @code{c} 2881 | * BaseType_t xTaskCatchUpTicks( TickType_t xTicksToCatchUp ); 2882 | * @endcode 2883 | * 2884 | * This function corrects the tick count value after the application code has held 2885 | * interrupts disabled for an extended period resulting in tick interrupts having 2886 | * been missed. 2887 | * 2888 | * This function is similar to vTaskStepTick(), however, unlike 2889 | * vTaskStepTick(), xTaskCatchUpTicks() may move the tick count forward past a 2890 | * time at which a task should be removed from the blocked state. That means 2891 | * tasks may have to be removed from the blocked state as the tick count is 2892 | * moved. 2893 | * 2894 | * @param xTicksToCatchUp The number of tick interrupts that have been missed due to 2895 | * interrupts being disabled. Its value is not computed automatically, so must be 2896 | * computed by the application writer. 2897 | * 2898 | * @return pdTRUE if moving the tick count forward resulted in a task leaving the 2899 | * blocked state and a context switch being performed. Otherwise pdFALSE. 2900 | * 2901 | * \defgroup xTaskCatchUpTicks xTaskCatchUpTicks 2902 | * \ingroup TaskCtrl 2903 | */ 2904 | BaseType_t xTaskCatchUpTicks( TickType_t xTicksToCatchUp ) PRIVILEGED_FUNCTION; 2905 | 2906 | 2907 | /*----------------------------------------------------------- 2908 | * SCHEDULER INTERNALS AVAILABLE FOR PORTING PURPOSES 2909 | *----------------------------------------------------------*/ 2910 | 2911 | /* 2912 | * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS ONLY 2913 | * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS 2914 | * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER. 2915 | * 2916 | * Called from the real time kernel tick (either preemptive or cooperative), 2917 | * this increments the tick count and checks if any tasks that are blocked 2918 | * for a finite period required removing from a blocked list and placing on 2919 | * a ready list. If a non-zero value is returned then a context switch is 2920 | * required because either: 2921 | * + A task was removed from a blocked list because its timeout had expired, 2922 | * or 2923 | * + Time slicing is in use and there is a task of equal priority to the 2924 | * currently running task. 2925 | */ 2926 | BaseType_t xTaskIncrementTick( void ) PRIVILEGED_FUNCTION; 2927 | 2928 | /* 2929 | * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN 2930 | * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER. 2931 | * 2932 | * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED. 2933 | * 2934 | * Removes the calling task from the ready list and places it both 2935 | * on the list of tasks waiting for a particular event, and the 2936 | * list of delayed tasks. The task will be removed from both lists 2937 | * and replaced on the ready list should either the event occur (and 2938 | * there be no higher priority tasks waiting on the same event) or 2939 | * the delay period expires. 2940 | * 2941 | * The 'unordered' version replaces the event list item value with the 2942 | * xItemValue value, and inserts the list item at the end of the list. 2943 | * 2944 | * The 'ordered' version uses the existing event list item value (which is the 2945 | * owning task's priority) to insert the list item into the event list in task 2946 | * priority order. 2947 | * 2948 | * @param pxEventList The list containing tasks that are blocked waiting 2949 | * for the event to occur. 2950 | * 2951 | * @param xItemValue The item value to use for the event list item when the 2952 | * event list is not ordered by task priority. 2953 | * 2954 | * @param xTicksToWait The maximum amount of time that the task should wait 2955 | * for the event to occur. This is specified in kernel ticks, the constant 2956 | * portTICK_PERIOD_MS can be used to convert kernel ticks into a real time 2957 | * period. 2958 | */ 2959 | void vTaskPlaceOnEventList( List_t * const pxEventList, 2960 | const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION; 2961 | void vTaskPlaceOnUnorderedEventList( List_t * pxEventList, 2962 | const TickType_t xItemValue, 2963 | const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION; 2964 | 2965 | /* 2966 | * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN 2967 | * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER. 2968 | * 2969 | * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED. 2970 | * 2971 | * This function performs nearly the same function as vTaskPlaceOnEventList(). 2972 | * The difference being that this function does not permit tasks to block 2973 | * indefinitely, whereas vTaskPlaceOnEventList() does. 2974 | * 2975 | */ 2976 | void vTaskPlaceOnEventListRestricted( List_t * const pxEventList, 2977 | TickType_t xTicksToWait, 2978 | const BaseType_t xWaitIndefinitely ) PRIVILEGED_FUNCTION; 2979 | 2980 | /* 2981 | * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN 2982 | * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER. 2983 | * 2984 | * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED. 2985 | * 2986 | * Removes a task from both the specified event list and the list of blocked 2987 | * tasks, and places it on a ready queue. 2988 | * 2989 | * xTaskRemoveFromEventList()/vTaskRemoveFromUnorderedEventList() will be called 2990 | * if either an event occurs to unblock a task, or the block timeout period 2991 | * expires. 2992 | * 2993 | * xTaskRemoveFromEventList() is used when the event list is in task priority 2994 | * order. It removes the list item from the head of the event list as that will 2995 | * have the highest priority owning task of all the tasks on the event list. 2996 | * vTaskRemoveFromUnorderedEventList() is used when the event list is not 2997 | * ordered and the event list items hold something other than the owning tasks 2998 | * priority. In this case the event list item value is updated to the value 2999 | * passed in the xItemValue parameter. 3000 | * 3001 | * @return pdTRUE if the task being removed has a higher priority than the task 3002 | * making the call, otherwise pdFALSE. 3003 | */ 3004 | BaseType_t xTaskRemoveFromEventList( const List_t * const pxEventList ) PRIVILEGED_FUNCTION; 3005 | void vTaskRemoveFromUnorderedEventList( ListItem_t * pxEventListItem, 3006 | const TickType_t xItemValue ) PRIVILEGED_FUNCTION; 3007 | 3008 | /* 3009 | * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS ONLY 3010 | * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS 3011 | * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER. 3012 | * 3013 | * Sets the pointer to the current TCB to the TCB of the highest priority task 3014 | * that is ready to run. 3015 | */ 3016 | portDONT_DISCARD void vTaskSwitchContext( void ) PRIVILEGED_FUNCTION; 3017 | 3018 | /* 3019 | * THESE FUNCTIONS MUST NOT BE USED FROM APPLICATION CODE. THEY ARE USED BY 3020 | * THE EVENT BITS MODULE. 3021 | */ 3022 | TickType_t uxTaskResetEventItemValue( void ) PRIVILEGED_FUNCTION; 3023 | 3024 | /* 3025 | * Return the handle of the calling task. 3026 | */ 3027 | TaskHandle_t xTaskGetCurrentTaskHandle( void ) PRIVILEGED_FUNCTION; 3028 | 3029 | /* 3030 | * Shortcut used by the queue implementation to prevent unnecessary call to 3031 | * taskYIELD(); 3032 | */ 3033 | void vTaskMissedYield( void ) PRIVILEGED_FUNCTION; 3034 | 3035 | /* 3036 | * Returns the scheduler state as taskSCHEDULER_RUNNING, 3037 | * taskSCHEDULER_NOT_STARTED or taskSCHEDULER_SUSPENDED. 3038 | */ 3039 | BaseType_t xTaskGetSchedulerState( void ) PRIVILEGED_FUNCTION; 3040 | 3041 | /* 3042 | * Raises the priority of the mutex holder to that of the calling task should 3043 | * the mutex holder have a priority less than the calling task. 3044 | */ 3045 | BaseType_t xTaskPriorityInherit( TaskHandle_t const pxMutexHolder ) PRIVILEGED_FUNCTION; 3046 | 3047 | /* 3048 | * Set the priority of a task back to its proper priority in the case that it 3049 | * inherited a higher priority while it was holding a semaphore. 3050 | */ 3051 | BaseType_t xTaskPriorityDisinherit( TaskHandle_t const pxMutexHolder ) PRIVILEGED_FUNCTION; 3052 | 3053 | /* 3054 | * If a higher priority task attempting to obtain a mutex caused a lower 3055 | * priority task to inherit the higher priority task's priority - but the higher 3056 | * priority task then timed out without obtaining the mutex, then the lower 3057 | * priority task will disinherit the priority again - but only down as far as 3058 | * the highest priority task that is still waiting for the mutex (if there were 3059 | * more than one task waiting for the mutex). 3060 | */ 3061 | void vTaskPriorityDisinheritAfterTimeout( TaskHandle_t const pxMutexHolder, 3062 | UBaseType_t uxHighestPriorityWaitingTask ) PRIVILEGED_FUNCTION; 3063 | 3064 | /* 3065 | * Get the uxTaskNumber assigned to the task referenced by the xTask parameter. 3066 | */ 3067 | UBaseType_t uxTaskGetTaskNumber( TaskHandle_t xTask ) PRIVILEGED_FUNCTION; 3068 | 3069 | /* 3070 | * Set the uxTaskNumber of the task referenced by the xTask parameter to 3071 | * uxHandle. 3072 | */ 3073 | void vTaskSetTaskNumber( TaskHandle_t xTask, 3074 | const UBaseType_t uxHandle ) PRIVILEGED_FUNCTION; 3075 | 3076 | /* 3077 | * Only available when configUSE_TICKLESS_IDLE is set to 1. 3078 | * If tickless mode is being used, or a low power mode is implemented, then 3079 | * the tick interrupt will not execute during idle periods. When this is the 3080 | * case, the tick count value maintained by the scheduler needs to be kept up 3081 | * to date with the actual execution time by being skipped forward by a time 3082 | * equal to the idle period. 3083 | */ 3084 | void vTaskStepTick( TickType_t xTicksToJump ) PRIVILEGED_FUNCTION; 3085 | 3086 | /* 3087 | * Only available when configUSE_TICKLESS_IDLE is set to 1. 3088 | * Provided for use within portSUPPRESS_TICKS_AND_SLEEP() to allow the port 3089 | * specific sleep function to determine if it is ok to proceed with the sleep, 3090 | * and if it is ok to proceed, if it is ok to sleep indefinitely. 3091 | * 3092 | * This function is necessary because portSUPPRESS_TICKS_AND_SLEEP() is only 3093 | * called with the scheduler suspended, not from within a critical section. It 3094 | * is therefore possible for an interrupt to request a context switch between 3095 | * portSUPPRESS_TICKS_AND_SLEEP() and the low power mode actually being 3096 | * entered. eTaskConfirmSleepModeStatus() should be called from a short 3097 | * critical section between the timer being stopped and the sleep mode being 3098 | * entered to ensure it is ok to proceed into the sleep mode. 3099 | */ 3100 | eSleepModeStatus eTaskConfirmSleepModeStatus( void ) PRIVILEGED_FUNCTION; 3101 | 3102 | /* 3103 | * For internal use only. Increment the mutex held count when a mutex is 3104 | * taken and return the handle of the task that has taken the mutex. 3105 | */ 3106 | TaskHandle_t pvTaskIncrementMutexHeldCount( void ) PRIVILEGED_FUNCTION; 3107 | 3108 | /* 3109 | * For internal use only. Same as vTaskSetTimeOutState(), but without a critical 3110 | * section. 3111 | */ 3112 | void vTaskInternalSetTimeOutState( TimeOut_t * const pxTimeOut ) PRIVILEGED_FUNCTION; 3113 | 3114 | 3115 | /* *INDENT-OFF* */ 3116 | #ifdef __cplusplus 3117 | } 3118 | #endif 3119 | /* *INDENT-ON* */ 3120 | #endif /* INC_TASK_H */ 3121 | --------------------------------------------------------------------------------