Modified the behaviour of deleted tasks in freeRTOS, started to add a new task to have the shell remotely, changed the way the status led blinks, now it pulses with a fading effect
This commit is contained in:
parent
61cb730733
commit
ad70e850cd
43
app/main.c
43
app/main.c
@ -12,13 +12,13 @@
|
|||||||
* Date : 2014-6-14
|
* Date : 2014-6-14
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include "nano_shell_server_task.h"
|
||||||
#include "wm_include.h"
|
#include "wm_include.h"
|
||||||
#include "wm_gpio_afsel.h"
|
#include "wm_gpio_afsel.h"
|
||||||
#include "nano_shell.h"
|
#include "nano_shell.h"
|
||||||
#include "lwip/netif.h"
|
#include "lwip/netif.h"
|
||||||
#include "FreeRTOS.h"
|
#include "FreeRTOS.h"
|
||||||
#include "FreeRTOSConfig.h"
|
#include "FreeRTOSConfig.h"
|
||||||
#include "rtostimers.h"
|
|
||||||
|
|
||||||
tls_os_task_t nano_shell_task_handle = NULL;
|
tls_os_task_t nano_shell_task_handle = NULL;
|
||||||
extern s16 uart0_rx_callback(u16 len, void *user_data);
|
extern s16 uart0_rx_callback(u16 len, void *user_data);
|
||||||
@ -26,7 +26,18 @@ extern s16 uart1_rx_callback(u16 len, void *user_data);
|
|||||||
extern int shell_printf(const char *format, ...);
|
extern int shell_printf(const char *format, ...);
|
||||||
|
|
||||||
#define NANO_SHELL_TASK_STK_SIZE 1024
|
#define NANO_SHELL_TASK_STK_SIZE 1024
|
||||||
|
#define NANO_SHELL_SERVER_TASK_STK_SIZE 640
|
||||||
#define STATUS_LED WM_IO_PB_18
|
#define STATUS_LED WM_IO_PB_18
|
||||||
|
#define PWM_STATUS_LED WM_IO_PB_25
|
||||||
|
#define FADE_DOWN 1
|
||||||
|
#define FADE_UP -1
|
||||||
|
#define FADE_LOW_THRESHOLD 255
|
||||||
|
#define FADE_HIGH_THRESHOLD 200
|
||||||
|
#define PULSE_FAST 3
|
||||||
|
#define PULSE_SLOW 12
|
||||||
|
|
||||||
|
|
||||||
|
u8 pulse_rate = PULSE_SLOW;
|
||||||
|
|
||||||
void tls_netif_status_event_cb(u8 status)
|
void tls_netif_status_event_cb(u8 status)
|
||||||
{
|
{
|
||||||
@ -41,11 +52,13 @@ void tls_netif_status_event_cb(u8 status)
|
|||||||
break;
|
break;
|
||||||
case NETIF_WIFI_DISCONNECTED:
|
case NETIF_WIFI_DISCONNECTED:
|
||||||
shell_printf("Evt : NETIF_WIFI_DISCONNECTED\n");
|
shell_printf("Evt : NETIF_WIFI_DISCONNECTED\n");
|
||||||
|
pulse_rate = PULSE_SLOW;
|
||||||
break;
|
break;
|
||||||
case NETIF_IP_NET_UP:
|
case NETIF_IP_NET_UP:
|
||||||
shell_printf("Evt : NETIF_IP_NET_UP\nip addr : %v\nnetmask : %v\ngateway : %v\n", netif->ip_addr.addr,
|
shell_printf("Evt : NETIF_IP_NET_UP\nip addr : %v\nnetmask : %v\ngateway : %v\n", netif->ip_addr.addr,
|
||||||
netif->netmask.addr,
|
netif->netmask.addr,
|
||||||
netif->gw.addr);
|
netif->gw.addr);
|
||||||
|
pulse_rate = PULSE_FAST;
|
||||||
break;
|
break;
|
||||||
case NETIF_WIFI_SOFTAP_SUCCESS:
|
case NETIF_WIFI_SOFTAP_SUCCESS:
|
||||||
shell_printf("Evt : NETIF_WIFI_SOFTAP_SUCCESS\n");
|
shell_printf("Evt : NETIF_WIFI_SOFTAP_SUCCESS\n");
|
||||||
@ -82,8 +95,12 @@ void tls_gpio_irq_cb(void *arg)
|
|||||||
|
|
||||||
void user_main(void *param)
|
void user_main(void *param)
|
||||||
{
|
{
|
||||||
|
u8 pwm_led_duty_cycle = 255;
|
||||||
|
s8 fading_direction = FADE_UP;
|
||||||
|
|
||||||
//We initialize input/output used by the app
|
//We initialize input/output used by the app
|
||||||
tls_gpio_cfg(STATUS_LED, WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_FLOATING);
|
wm_pwm3_config(PWM_STATUS_LED);
|
||||||
|
tls_pwm_init(3, 1000, 0, 0);
|
||||||
wm_uart1_tx_config(WM_IO_PB_06);
|
wm_uart1_tx_config(WM_IO_PB_06);
|
||||||
wm_uart1_rx_config(WM_IO_PB_07);
|
wm_uart1_rx_config(WM_IO_PB_07);
|
||||||
tls_gpio_irq_enable(WM_IO_PB_07, WM_GPIO_IRQ_TRIG_DOUBLE_EDGE);
|
tls_gpio_irq_enable(WM_IO_PB_07, WM_GPIO_IRQ_TRIG_DOUBLE_EDGE);
|
||||||
@ -100,11 +117,13 @@ void user_main(void *param)
|
|||||||
|
|
||||||
|
|
||||||
//We create a task for the nano_shell process
|
//We create a task for the nano_shell process
|
||||||
u8 *nano_shell_task_stack = NULL;
|
u8 *nano_shell_task_stack = NULL, *nano_shell_server_task_stack = NULL;
|
||||||
|
|
||||||
tls_uart_rx_callback_register(TLS_UART_0, &(uart0_rx_callback), NULL);
|
tls_uart_rx_callback_register(TLS_UART_0, &(uart0_rx_callback), NULL);
|
||||||
tls_uart_rx_callback_register(TLS_UART_1, &(uart1_rx_callback), NULL);
|
tls_uart_rx_callback_register(TLS_UART_1, &(uart1_rx_callback), NULL);
|
||||||
|
|
||||||
|
nano_shell_server_task_stack = tls_mem_alloc(sizeof(u32) * NANO_SHELL_SERVER_TASK_STK_SIZE);
|
||||||
|
|
||||||
nano_shell_task_stack = tls_mem_alloc(sizeof(u32) * NANO_SHELL_TASK_STK_SIZE);
|
nano_shell_task_stack = tls_mem_alloc(sizeof(u32) * NANO_SHELL_TASK_STK_SIZE);
|
||||||
if(nano_shell_task_stack != NULL)
|
if(nano_shell_task_stack != NULL)
|
||||||
{
|
{
|
||||||
@ -139,9 +158,21 @@ void user_main(void *param)
|
|||||||
|
|
||||||
for(;;)
|
for(;;)
|
||||||
{
|
{
|
||||||
//shell_printf("Waiting for clients\n");
|
tls_pwm_duty_set(3, pwm_led_duty_cycle);
|
||||||
tls_gpio_write(STATUS_LED, !tls_gpio_read(STATUS_LED));
|
if(pwm_led_duty_cycle == FADE_LOW_THRESHOLD)
|
||||||
tls_os_time_delay(pdMS_TO_TICKS(1000));
|
{
|
||||||
|
fading_direction = FADE_UP;
|
||||||
|
tls_os_time_delay(pdMS_TO_TICKS(pulse_rate == PULSE_SLOW ? 500 : 100));
|
||||||
|
}
|
||||||
|
else if(pwm_led_duty_cycle == FADE_HIGH_THRESHOLD)
|
||||||
|
{
|
||||||
|
fading_direction = FADE_DOWN;
|
||||||
|
tls_os_time_delay(pdMS_TO_TICKS(pulse_rate == PULSE_SLOW ? 500 : 100));
|
||||||
|
}
|
||||||
|
|
||||||
|
pwm_led_duty_cycle+=fading_direction;
|
||||||
|
|
||||||
|
tls_os_time_delay(pdMS_TO_TICKS(pulse_rate));
|
||||||
/*client_socket = accept(listening_socket, (struct sockaddr *)&client, &socklent);
|
/*client_socket = accept(listening_socket, (struct sockaddr *)&client, &socklent);
|
||||||
shell_printf("Client got accepted\n");
|
shell_printf("Client got accepted\n");
|
||||||
while(recv(client_socket, buffer, 99, 0) > 0)
|
while(recv(client_socket, buffer, 99, 0) > 0)
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
extern int shell_printf(const char *format, ...);
|
extern int shell_printf(const char *format, ...);
|
||||||
extern int wm_printf(const char *fmt,...);
|
extern int wm_printf(const char *fmt,...);
|
||||||
|
extern u32 tls_mem_get_avail_heapsize(void);
|
||||||
|
|
||||||
extern int demo_bt_enable();
|
extern int demo_bt_enable();
|
||||||
extern int demo_bt_destroy();
|
extern int demo_bt_destroy();
|
||||||
@ -106,7 +107,7 @@ int _system(const shell_cmd_t *pcmd, int argc, char *const argv[])
|
|||||||
}
|
}
|
||||||
else if(strcmp(argv[1], "ram_usage") == 0)
|
else if(strcmp(argv[1], "ram_usage") == 0)
|
||||||
{
|
{
|
||||||
shell_printf("Free heap : %u byte(s)\n", xPortGetFreeHeapSize());
|
shell_printf("Free OS heap : %u/%u byte(s)\ntls heap size : %u\n", xPortGetFreeHeapSize(), configTOTAL_HEAP_SIZE, tls_mem_get_avail_heapsize());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -177,7 +178,7 @@ int _soft_ap(const shell_cmd_t *pcmd, int argc, char *const argv[])
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
shell_printf("Unknown soft_ap action\n");
|
shell_printf("Unknown %s action\n", argv[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -228,7 +229,7 @@ int _station(const shell_cmd_t *pcmd, int argc, char *const argv[])
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
shell_printf("Unknown station action\n");
|
shell_printf("Unknown %s action\n", argv[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -299,7 +300,7 @@ int _wifi(const shell_cmd_t *pcmd, int argc, char *const argv[])
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
shell_printf("Unknown wifi action\n");
|
shell_printf("Unknown %s action\n", argv[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -325,7 +326,7 @@ int _wifi_sleep(const shell_cmd_t *pcmd, int argc, char *const argv[])
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
shell_printf("Unknown wifi_sleep action\n");
|
shell_printf("Unknown %s action\n", argv[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -360,7 +361,7 @@ int _pmu(const shell_cmd_t *pcmd, int argc, char *const argv[])
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
shell_printf("Unknown pmu action\n");
|
shell_printf("Unknown %s action\n", argv[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -432,7 +433,7 @@ int _rtc(const shell_cmd_t *pcmd, int argc, char *const argv[])
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
shell_printf("Unknown rtc action\n");
|
shell_printf("Unknown %s action\n", argv[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -448,11 +449,13 @@ int _bluetooth(const shell_cmd_t *pcmd, int argc, char *const argv[])
|
|||||||
{
|
{
|
||||||
if(strcmp(argv[1], "enable") == 0)
|
if(strcmp(argv[1], "enable") == 0)
|
||||||
{
|
{
|
||||||
shell_printf("Enabling bluetooth : %d\n", demo_bt_enable());
|
//shell_printf("Enabling bluetooth : %d\n", demo_bt_enable());
|
||||||
|
shell_printf("Enabling bluetooth test\n");
|
||||||
}
|
}
|
||||||
else if(strcmp(argv[1], "disable") == 0)
|
else if(strcmp(argv[1], "disable") == 0)
|
||||||
{
|
{
|
||||||
shell_printf("Disabling bluetooth : %d\n", demo_bt_destroy());
|
//shell_printf("Disabling bluetooth : %d\n", demo_bt_destroy());
|
||||||
|
shell_printf("Disabling bluetooth test\n");
|
||||||
}
|
}
|
||||||
else if(strcmp(argv[1], "start_demo") == 0)
|
else if(strcmp(argv[1], "start_demo") == 0)
|
||||||
{
|
{
|
||||||
@ -464,7 +467,7 @@ int _bluetooth(const shell_cmd_t *pcmd, int argc, char *const argv[])
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
shell_printf("Unknown bluetooth action\n");
|
shell_printf("Unknown %s action\n", argv[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -3,10 +3,14 @@
|
|||||||
|
|
||||||
static_fifo_declare(uart_char_fifo, 256, unsigned char, char);
|
static_fifo_declare(uart_char_fifo, 256, unsigned char, char);
|
||||||
extern int sendchar(int ch);
|
extern int sendchar(int ch);
|
||||||
|
extern void network_write(char c);
|
||||||
extern tls_os_task_t nano_shell_task_handle;
|
extern tls_os_task_t nano_shell_task_handle;
|
||||||
|
|
||||||
s16 uart0_rx_callback(u16 len, void *user_data)
|
s16 uart0_rx_callback(u16 len, void *user_data)
|
||||||
{
|
{
|
||||||
|
(void)len;
|
||||||
|
(void)user_data;
|
||||||
|
|
||||||
u8 buff[256] = "";
|
u8 buff[256] = "";
|
||||||
int data_len = tls_uart_read(TLS_UART_0, (u8 *) buff, 256);
|
int data_len = tls_uart_read(TLS_UART_0, (u8 *) buff, 256);
|
||||||
for(int i = 0; i < data_len; i++)
|
for(int i = 0; i < data_len; i++)
|
||||||
@ -14,12 +18,15 @@ s16 uart0_rx_callback(u16 len, void *user_data)
|
|||||||
fifo_push(uart_char_fifo, buff[i]);
|
fifo_push(uart_char_fifo, buff[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
tls_os_task_resume_from_isr(nano_shell_task_handle);
|
(void)tls_os_task_resume_from_isr(nano_shell_task_handle);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
s16 uart1_rx_callback(u16 len, void *user_data)
|
s16 uart1_rx_callback(u16 len, void *user_data)
|
||||||
{
|
{
|
||||||
|
(void)len;
|
||||||
|
(void)user_data;
|
||||||
|
|
||||||
u8 buff[256] = "";
|
u8 buff[256] = "";
|
||||||
int data_len = tls_uart_read(TLS_UART_1, (u8 *) buff, 256);
|
int data_len = tls_uart_read(TLS_UART_1, (u8 *) buff, 256);
|
||||||
for(int i = 0; i < data_len; i++)
|
for(int i = 0; i < data_len; i++)
|
||||||
@ -27,10 +34,22 @@ s16 uart1_rx_callback(u16 len, void *user_data)
|
|||||||
fifo_push(uart_char_fifo, buff[i]);
|
fifo_push(uart_char_fifo, buff[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
tls_os_task_resume_from_isr(nano_shell_task_handle);
|
(void)tls_os_task_resume_from_isr(nano_shell_task_handle);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void network_rx_callback(u16 len, char *data)
|
||||||
|
{
|
||||||
|
if(!len)return;
|
||||||
|
|
||||||
|
for(int i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
fifo_push(uart_char_fifo, data[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
(void)tls_os_task_resume(nano_shell_task_handle);
|
||||||
|
}
|
||||||
|
|
||||||
int shell_getc(char *ch)
|
int shell_getc(char *ch)
|
||||||
{
|
{
|
||||||
if(is_fifo_empty(uart_char_fifo))
|
if(is_fifo_empty(uart_char_fifo))
|
||||||
@ -49,4 +68,5 @@ void low_level_write_char(char ch)
|
|||||||
{
|
{
|
||||||
(void)sendchar((int)ch);
|
(void)sendchar((int)ch);
|
||||||
(void)tls_uart_write(TLS_UART_1, &ch, 1);
|
(void)tls_uart_write(TLS_UART_1, &ch, 1);
|
||||||
|
network_write(ch);
|
||||||
}
|
}
|
||||||
|
6
app/nano_shell_server_task.c
Normal file
6
app/nano_shell_server_task.c
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#include "nano_shell_server_task.h"
|
||||||
|
|
||||||
|
void network_write(char c)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
0
app/nano_shell_server_task.h
Normal file
0
app/nano_shell_server_task.h
Normal file
@ -453,7 +453,7 @@ void task_start (void *data)
|
|||||||
if (tststarthdl)
|
if (tststarthdl)
|
||||||
{
|
{
|
||||||
tls_os_task_del_by_task_handle(tststarthdl,task_start_free);
|
tls_os_task_del_by_task_handle(tststarthdl,task_start_free);
|
||||||
}
|
}
|
||||||
tls_os_time_delay(0x10000000);
|
tls_os_time_delay(0x10000000);
|
||||||
#else
|
#else
|
||||||
#if 1
|
#if 1
|
||||||
|
@ -77,7 +77,7 @@
|
|||||||
#define configTICK_RATE_HZ ( ( portTickType ) 500u ) //ʱ<><CAB1>Ƭ<EFBFBD>жϵ<D0B6>Ƶ<EFBFBD><C6B5>
|
#define configTICK_RATE_HZ ( ( portTickType ) 500u ) //ʱ<><CAB1>Ƭ<EFBFBD>жϵ<D0B6>Ƶ<EFBFBD><C6B5>
|
||||||
#define configMAX_PRIORITIES ( ( unsigned portBASE_TYPE ) 63) //Ӧ<>ó<EFBFBD><C3B3><EFBFBD><EFBFBD>п<EFBFBD><D0BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD><C8BC><EFBFBD><EFBFBD><EFBFBD>Ŀ
|
#define configMAX_PRIORITIES ( ( unsigned portBASE_TYPE ) 63) //Ӧ<>ó<EFBFBD><C3B3><EFBFBD><EFBFBD>п<EFBFBD><D0BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD><C8BC><EFBFBD><EFBFBD><EFBFBD>Ŀ
|
||||||
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 90 ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>õĶ<C3B5>ջ<EFBFBD><D5BB>С
|
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 90 ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>õĶ<C3B5>ջ<EFBFBD><D5BB>С
|
||||||
#define configTOTAL_HEAP_SIZE ( ( size_t ) 12 * 1024 ) //<2F>ں<EFBFBD><DABA>п<EFBFBD><D0BF>õ<EFBFBD>RAM<41><4D><EFBFBD><EFBFBD>,heap2ʹ<32><CAB9>
|
#define configTOTAL_HEAP_SIZE ( ( size_t ) 20 * 1024 ) //<2F>ں<EFBFBD><DABA>п<EFBFBD><D0BF>õ<EFBFBD>RAM<41><4D><EFBFBD><EFBFBD>,heap2ʹ<32><CAB9>
|
||||||
#define configMAX_TASK_NAME_LEN ( 8 ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
#define configMAX_TASK_NAME_LEN ( 8 ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
#define configUSE_TRACE_FACILITY 1 //<2F>Ƿ<EFBFBD>ʹ<EFBFBD>ÿ<EFBFBD><C3BF>ӻ<EFBFBD><EFBFBD><D7B7>
|
#define configUSE_TRACE_FACILITY 1 //<2F>Ƿ<EFBFBD>ʹ<EFBFBD>ÿ<EFBFBD><C3BF>ӻ<EFBFBD><EFBFBD><D7B7>
|
||||||
#define configUSE_STATS_FORMATTING_FUNCTIONS 1
|
#define configUSE_STATS_FORMATTING_FUNCTIONS 1
|
||||||
|
@ -487,7 +487,7 @@ void vTaskAllocateMPURegions( TaskHandle_t xTask, const MemoryRegion_t * const p
|
|||||||
* \ingroup Tasks
|
* \ingroup Tasks
|
||||||
*/
|
*/
|
||||||
void vTaskDelete( TaskHandle_t xTaskToDelete ) PRIVILEGED_FUNCTION;
|
void vTaskDelete( TaskHandle_t xTaskToDelete ) PRIVILEGED_FUNCTION;
|
||||||
|
void vTaskDeleteByHandle( TaskHandle_t xTaskToDelete, void (*freeStackfunc)(void));
|
||||||
/*-----------------------------------------------------------
|
/*-----------------------------------------------------------
|
||||||
* TASK CONTROL API
|
* TASK CONTROL API
|
||||||
*----------------------------------------------------------*/
|
*----------------------------------------------------------*/
|
||||||
|
@ -169,6 +169,7 @@ typedef struct tskTaskControlBlock
|
|||||||
implements a system-wide malloc() that must be provided with locks. */
|
implements a system-wide malloc() that must be provided with locks. */
|
||||||
struct _reent xNewLib_reent;
|
struct _reent xNewLib_reent;
|
||||||
#endif
|
#endif
|
||||||
|
void (*freeStackfunc)(void);
|
||||||
|
|
||||||
} tskTCB;
|
} tskTCB;
|
||||||
|
|
||||||
@ -768,6 +769,80 @@ TCB_t * pxNewTCB;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void vTaskDeleteByHandle( TaskHandle_t xTaskToDelete, void (*freeStackfunc)(void))
|
||||||
|
{
|
||||||
|
TCB_t *pxTCB;
|
||||||
|
|
||||||
|
taskENTER_CRITICAL();
|
||||||
|
{
|
||||||
|
/* If null is passed in here then it is the calling task that is
|
||||||
|
being deleted. */
|
||||||
|
pxTCB = prvGetTCBFromHandle( xTaskToDelete );
|
||||||
|
pxTCB->freeStackfunc = freeStackfunc;
|
||||||
|
|
||||||
|
/* Remove task from the ready list and place in the termination list.
|
||||||
|
This will stop the task from be scheduled. The idle task will check
|
||||||
|
the termination list and free up any memory allocated by the
|
||||||
|
scheduler for the TCB and stack. */
|
||||||
|
if( uxListRemove( &( pxTCB->xGenericListItem ) ) == ( UBaseType_t ) 0 )
|
||||||
|
{
|
||||||
|
taskRESET_READY_PRIORITY( pxTCB->uxPriority );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mtCOVERAGE_TEST_MARKER();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Is the task waiting on an event also? */
|
||||||
|
if( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) != NULL )
|
||||||
|
{
|
||||||
|
( void ) uxListRemove( &( pxTCB->xEventListItem ) );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mtCOVERAGE_TEST_MARKER();
|
||||||
|
}
|
||||||
|
|
||||||
|
vListInsertEnd( &xTasksWaitingTermination, &( pxTCB->xGenericListItem ) );
|
||||||
|
|
||||||
|
/* Increment the ucTasksDeleted variable so the idle task knows
|
||||||
|
there is a task that has been deleted and that it should therefore
|
||||||
|
check the xTasksWaitingTermination list. */
|
||||||
|
++uxTasksDeleted;
|
||||||
|
|
||||||
|
/* Increment the uxTaskNumberVariable also so kernel aware debuggers
|
||||||
|
can detect that the task lists need re-generating. */
|
||||||
|
uxTaskNumber++;
|
||||||
|
|
||||||
|
traceTASK_DELETE( pxTCB );
|
||||||
|
}
|
||||||
|
taskEXIT_CRITICAL();
|
||||||
|
|
||||||
|
/* Force a reschedule if it is the currently running task that has just
|
||||||
|
been deleted. */
|
||||||
|
if( xSchedulerRunning != pdFALSE )
|
||||||
|
{
|
||||||
|
if( pxTCB == pxCurrentTCB )
|
||||||
|
{
|
||||||
|
configASSERT( uxSchedulerSuspended == 0 );
|
||||||
|
|
||||||
|
/* The pre-delete hook is primarily for the Windows simulator,
|
||||||
|
in which Windows specific clean up operations are performed,
|
||||||
|
after which it is not possible to yield away from this task -
|
||||||
|
hence xYieldPending is used to latch that a context switch is
|
||||||
|
required. */
|
||||||
|
portPRE_TASK_DELETE_HOOK( pxTCB, &xYieldPending );
|
||||||
|
portYIELD_WITHIN_API();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Reset the next expected unblock time in case it referred to
|
||||||
|
the task that has just been deleted. */
|
||||||
|
prvResetNextTaskUnblockTime();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* INCLUDE_vTaskDelete */
|
#endif /* INCLUDE_vTaskDelete */
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
@ -2857,6 +2932,11 @@ static void prvCheckTasksWaitingTermination( void )
|
|||||||
( void ) uxListRemove( &( pxTCB->xGenericListItem ) );
|
( void ) uxListRemove( &( pxTCB->xGenericListItem ) );
|
||||||
--uxCurrentNumberOfTasks;
|
--uxCurrentNumberOfTasks;
|
||||||
--uxTasksDeleted;
|
--uxTasksDeleted;
|
||||||
|
|
||||||
|
if(pxTCB->freeStackfunc)
|
||||||
|
{
|
||||||
|
pxTCB->freeStackfunc();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
taskEXIT_CRITICAL();
|
taskEXIT_CRITICAL();
|
||||||
|
|
||||||
@ -2926,6 +3006,7 @@ TCB_t *pxNewTCB;
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
pxNewTCB->stacksize = ( StackType_t ) usStackDepth * sizeof(StackType_t);
|
pxNewTCB->stacksize = ( StackType_t ) usStackDepth * sizeof(StackType_t);
|
||||||
|
pxNewTCB->freeStackfunc = NULL;
|
||||||
/* Avoid dependency on memset() if it is not required. */
|
/* Avoid dependency on memset() if it is not required. */
|
||||||
#if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) || ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) )
|
#if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) || ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) )
|
||||||
{
|
{
|
||||||
@ -3084,7 +3165,11 @@ TCB_t *pxNewTCB;
|
|||||||
|
|
||||||
/* Free up the memory allocated by the scheduler for the task. It is up to
|
/* Free up the memory allocated by the scheduler for the task. It is up to
|
||||||
the task to free any memory allocated at the application level. */
|
the task to free any memory allocated at the application level. */
|
||||||
vPortFreeAligned( pxTCB->pxStack );
|
|
||||||
|
//Only if we did not provide a custom free function, we free it using freeRTOS func
|
||||||
|
if(!pxTCB->freeStackfunc)
|
||||||
|
vPortFreeAligned( pxTCB->pxStack );
|
||||||
|
|
||||||
vPortFree( pxTCB );
|
vPortFree( pxTCB );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,10 +145,7 @@ tls_os_status_t tls_os_task_del(u8 prio,void (*freefun)(void))
|
|||||||
|
|
||||||
tls_os_status_t tls_os_task_del_by_task_handle(void *handle, void (*freefun)(void))
|
tls_os_status_t tls_os_task_del_by_task_handle(void *handle, void (*freefun)(void))
|
||||||
{
|
{
|
||||||
//vTaskDeleteByHandle(handle, freefun);
|
vTaskDeleteByHandle(handle, freefun);
|
||||||
vTaskDelete(handle);
|
|
||||||
if(freefun != NULL)
|
|
||||||
freefun();
|
|
||||||
return TLS_OS_SUCCESS;
|
return TLS_OS_SUCCESS;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -220,7 +217,8 @@ tls_os_status_t tls_os_task_resume(tls_os_task_t task)
|
|||||||
|
|
||||||
tls_os_status_t tls_os_task_resume_from_isr(tls_os_task_t task)
|
tls_os_status_t tls_os_task_resume_from_isr(tls_os_task_t task)
|
||||||
{
|
{
|
||||||
return (tls_os_status_t)xTaskResumeFromISR(task);
|
(void)xTaskResumeFromISR(task);
|
||||||
|
return TLS_OS_SUCCESS;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user