void XfsTaskSetSpeakTimes(int times) { SpeakMessage *p = (SpeakMessage *)pvPortMalloc(sizeof(SpeakMessage)); p->type = TYPE_SET_SPEAKTIMES; p->len = times; if (pdTRUE != xQueueSend(speakQueue, &p, configTICK_RATE_HZ * 5)) { vPortFree(p); } }
void XfsTaskSetSpeakPause(int sec) { SpeakMessage *p = (SpeakMessage *)pvPortMalloc(sizeof(SpeakMessage)); p->type = TYPE_SET_SPEAKPAUSE; p->len = sec; if (pdTRUE != xQueueSend(speakQueue, &p, configTICK_RATE_HZ * 5)) { vPortFree(p); } }
void MPU_vPortFree( void *pv ) { portBASE_TYPE xRunningPrivileged = prvRaisePrivilege(); vPortFree( pv ); portRESET_PRIVILEGE( xRunningPrivileged ); }
void MPU_vPortFree( void *pv ) { BaseType_t xRunningPrivileged = xPortRaisePrivilege(); vPortFree( pv ); vPortResetPrivilege( xRunningPrivileged ); }
void MPU_vPortFree( void *pv ) { BaseType_t xRunningPrivileged = prvRaisePrivilege(); vPortFree( pv ); portRESET_PRIVILEGE( xRunningPrivileged ); }
/* * Starts a new thread with priority "prio" that will begin its execution in the * function "thread()". The "arg" argument will be passed as an argument to the * thread() function. The argument "ssize" is the requested stack size for the * new thread. The id of the new thread is returned. Both the id and the * priority are system dependent. */ sys_thread_t sys_thread_new(char *name, void ( *thread ) ( void *arg ), void *arg, int stacksize, int prio ) { sys_thread_t thread_hdl = SYS_THREAD_NULL; int i; sys_tcb_t *p; /* We disable the FreeRTOS scheduler because it might be the case that the new * tasks gets scheduled inside the xTaskCreate function. To prevent this we * disable the scheduling. Note that this can happen although we have interrupts * disabled because xTaskCreate contains a call to taskYIELD( ). */ vPortEnterCritical( ); p = tasks; i = 0; /* We are called the first time. Initialize it. */ if( p == NULL ) { p = (sys_tcb_t *)pvPortMalloc( sizeof( sys_tcb_t ) ); if( p != NULL ) { tasks = p; } } else { /* First task already counter. */ i++; /* Cycle to the end of the list. */ while( p->next != NULL ) { i++; p = p->next; } p->next = (sys_tcb_t *)pvPortMalloc( sizeof( sys_tcb_t ) ); p = p->next; } if( p != NULL ) { /* Memory allocated. Initialize the data structure. */ THREAD_INIT( p ); /* Now q points to a free element in the list. */ if( xTaskCreate( thread, (const signed char *)name, stacksize, arg, prio, &p->pid ) == pdPASS ) { thread_hdl = p; } else { vPortFree( p ); } } vPortExitCritical( ); return thread_hdl; }
/** * @brief Initialise the socket & buffer for HTTP server */ uint8_t init_httpd_ch(SOCKET s) { uint8_t ret; ret = 0; if( getSn_SR(s) != SOCK_CLOSED ) // Check the preferred socket is available, { s = getSocket(SOCK_CLOSED, 0); // otherwise find free socket, if(s == MAX_SOCK_NUM ) // If there is no free socket? ret = 0; } else { ret = 1; } if(!socket(s, Sn_MR_TCP, IP_PORT_HTTP, 0x00)) // initialise the socket for DHCP service { xSerialPrintf_P(PSTR("HTTPD socket: %d, initialise fail..!\r\n"),s); ret = 0; } #ifdef HTTP_DEBUG else xSerialPrintf_P(PSTR("HTTPD socket: %d, initialise success..!\r\n"),s); #endif if(pHTTPRequest == NULL) // if there is no buffer allocated (pointer is NULL), then allocate request buffer for all HTTP functions. { if( !(pHTTPRequest = (HTTP_REQUEST *) pvPortMalloc( sizeof(HTTP_REQUEST) ))) { xSerialPrint_P(PSTR("HTTP Request Buffer: malloc fail..!\r\n")); ret = 0; } #ifdef HTTP_DEBUG else xSerialPrint_P(PSTR("HTTP Request Buffer: malloc success..!\r\n")); #endif } if(pHTTPResponse == NULL) // if there is no buffer allocated (pointer is NULL), then allocate response buffer for all HTTP functions. { if( !(pHTTPResponse = (uint8_t *) pvPortMalloc( sizeof(uint8_t) * (FILE_BUFFER_SIZE + 1) ))) { xSerialPrint_P(PSTR("HTTP Response Buffer: malloc fail..!\r\n")); vPortFree(pHTTPRequest); ret = 0; } #ifdef HTTP_DEBUG else xSerialPrint_P(PSTR("HTTP Response Buffer: malloc success..!\r\n")); #endif } HTTPD_SOCK = s; return ret; }
static void sensorsBiasFree(BiasObj* bias) { /* unset buffer is full */ bias->bufIsFull = 0; /* free buffer memory */ vPortFree(bias->bufStart); bias->bufStart = NULL; bias->bufPtr = NULL; }
void eagle_lwip_if_free(struct myif_state *state) { if(state->dhcps_if == 0) { netif_remove(state->myif); // if(lwip_if_queues[0] != NULL) vPortFree(lwip_if_queues[0]); } else { if(dhcps_flag) dhcps_stop(); netif_remove(state->myif); // if(lwip_if_queues[1] != NULL) vPortFree(lwip_if_queues[1]); } if(state->myif != NULL) { vPortFree(state->myif); state->myif = NULL; } }
static void __sendToNumber(const char *number, const char *content, int len) { char *pdu = pvPortMalloc(300); if (number == NULL) { return; } len = SMSEncodePduUCS2(pdu, number, content, len); GsmTaskSendSMS(pdu, len); vPortFree(pdu); }
void eagle_lwip_if_free(struct ieee80211_conn *conn) { if(conn->dhcps_if == 0) { netif_remove(conn->myif); // if(lwip_if_queues[0] != NULL) vPortFree(lwip_if_queues[0]); } else { if(dhcps_flag) dhcps_stop(); netif_remove(conn->myif); // if(lwip_if_queues[1] != NULL) vPortFree(lwip_if_queues[1]); } if(conn->myif != NULL) { vPortFree(conn->myif); conn->myif = NULL; } }
void *pvPortRealloc(void *mem, size_t newsize, const char *file, unsigned line) { if (newsize == 0) { vPortFree(mem, file, line); return NULL; } void *p; p = pvPortMalloc(newsize, file, line, false); if (p) { /* zero the memory */ if (mem != NULL) { memcpy(p, mem, newsize); vPortFree(mem, file, line); } } return p; }
void *pvPortRealloc(void *mem, size_t newsize) { if (newsize == 0) { vPortFree(mem); return NULL; } void *p; p = pvPortMalloc(newsize); if (p) { /* zero the memory */ if (mem != NULL) { memcpy(p, mem, newsize); vPortFree(mem); } } return p; }
static void xfsSpeak(const char *s, int len, short type) { SpeakMessage *p = (SpeakMessage *)pvPortMalloc(sizeof(SpeakMessage) + len); p->type = type; p->len = len; memcpy(&p[1], s, len); if (pdTRUE != xQueueSend(speakQueue, &p, configTICK_RATE_HZ * 5)) { vPortFree(p); } }
static void esp_apptrace_dummy_task(void *p) { esp_apptrace_test_task_arg_t *arg = (esp_apptrace_test_task_arg_t *) p; int res, flags = 0, i; timer_isr_handle_t *inth = NULL; TickType_t tmo_ticks = arg->data.period / (1000 * portTICK_PERIOD_MS); ESP_APPTRACE_TEST_LOGI("%x: run dummy task (period %u us, %u timers)", xTaskGetCurrentTaskHandle(), arg->data.period, arg->timers_num); if (arg->timers_num > 0) { inth = pvPortMalloc(arg->timers_num * sizeof(timer_isr_handle_t)); if (!inth) { ESP_APPTRACE_TEST_LOGE("Failed to alloc timer ISR handles!"); goto on_fail; } memset(inth, 0, arg->timers_num * sizeof(timer_isr_handle_t)); for (int i = 0; i < arg->timers_num; i++) { esp_apptrace_test_timer_init(arg->timers[i].group, arg->timers[i].id, arg->timers[i].data.period); res = timer_isr_register(arg->timers[i].group, arg->timers[i].id, arg->timers[i].isr_func, &arg->timers[i], flags, &inth[i]); if (res != ESP_OK) { ESP_APPTRACE_TEST_LOGE("Failed to timer_isr_register (%d)!", res); goto on_fail; } *(uint32_t *)arg->timers[i].data.buf = (uint32_t)inth[i] | (1 << 31); ESP_APPTRACE_TEST_LOGI("%x: start timer %x period %u us", xTaskGetCurrentTaskHandle(), inth[i], arg->timers[i].data.period); res = timer_start(arg->timers[i].group, arg->timers[i].id); if (res != ESP_OK) { ESP_APPTRACE_TEST_LOGE("Failed to timer_start (%d)!", res); goto on_fail; } } } i = 0; while (!arg->stop) { ESP_APPTRACE_TEST_LOGD("%x: dummy task work %d.%d", xTaskGetCurrentTaskHandle(), xPortGetCoreID(), i++); if (tmo_ticks) { vTaskDelay(tmo_ticks); } } on_fail: if (inth) { for (int i = 0; i < arg->timers_num; i++) { timer_pause(arg->timers[i].group, arg->timers[i].id); timer_disable_intr(arg->timers[i].group, arg->timers[i].id); if (inth[i]) { esp_intr_free(inth[i]); } } vPortFree(inth); } xSemaphoreGive(arg->done); vTaskDelay(1); vTaskDelete(NULL); }
static void do_ls_test(const char *pre) { char **dirs, *msg; int x; printk("ls %s...\n", pre); msg = xenbus_ls(XBT_NIL, pre, &dirs); if (msg) { printk("Error in xenbus ls: %s\n", msg); vPortFree(msg); return; } for (x = 0; dirs[x]; x++) { printk("ls %s[%d] -> %s\n", pre, x, dirs[x]); vPortFree(dirs[x]); } vPortFree(dirs); }
/* * Free the provided tag list. */ void freefare_free_tags (MifareTag *tags) { if (tags) { for (int i=0; tags[i] && i< MAX_CANDIDATES; i++) { freefare_free_tag(tags[i]); } vPortFree (tags); } }
/*******************************************************************************//*! * \brief Close a connection on a USART * * The buffers allocated to the connection are released. USART registers are configure to turn off reception and * transmission. Interrups are also turned off. * @param usartId ******************************************************************************************/ void usartClose(USART_ID usartId ) { uint8_t ucByte; /* Turn off the interrupts. We may also want to delete the queues and/or re-install the original ISR. */ vPortFree( usartComBuf[usartId].workBuffer ); vPortFree( usartComBuf[usartId].xRxedChars.start ); vPortFree( usartComBuf[usartId].xCharsForTx.start ); portENTER_CRITICAL(); // Turn off interrupts xmitInterrupt_Off(usartId); // ucByte = *usartReg[usartId].ucsrBPtr; ucByte &= ~RXCIE_BIT; *usartReg[usartId].ucsrBPtr = ucByte; portEXIT_CRITICAL(); // Enable interrupts }
/********************************************************************* * * _cbSendTaskList() * * Function description * This function is part of the link between FreeRTOS and SYSVIEW. * Called from SystemView when asked by the host, it uses SYSVIEW * functions to send the entire task list to the host. */ static void _cbSendTaskList(void) { TaskStatus_t* pxTaskStatusArray; UBaseType_t uxArraySize; UBaseType_t x; char cStatus; #if INCLUDE_xTaskGetIdleTaskHandle TaskHandle_t hIdle; hIdle = xTaskGetIdleTaskHandle(); #endif /* Take a snapshot of the number of tasks in case it changes while this function is executing. */ uxArraySize = uxTaskGetNumberOfTasks(); /* Allocate an array index for each task. */ pxTaskStatusArray = pvPortMalloc( uxArraySize * sizeof( TaskStatus_t ) ); if( pxTaskStatusArray != NULL ) { /* Generate the (binary) data. */ uxArraySize = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, NULL ); #if INCLUDE_xTaskGetIdleTaskHandle /* only get Idle task handle if scheduler has been started */ if (xTaskGetSchedulerState()!=taskSCHEDULER_NOT_STARTED) { hIdle = xTaskGetIdleTaskHandle(); } else { hIdle = NULL; } #endif /* Create a human readable table from the binary data. */ for( x = 0; x < uxArraySize; x++ ) { uint8_t* pStack; #if INCLUDE_pxTaskGetStackStart pStack = pxTaskGetStackStart(pxTaskStatusArray[x].xHandle); #else pStack = (uint8_t*)0; #endif #if INCLUDE_xTaskGetIdleTaskHandle if (pxTaskStatusArray[x].xHandle != hIdle) { SYSVIEW_SendTaskInfo((unsigned)pxTaskStatusArray[x].xHandle, pxTaskStatusArray[x].pcTaskName, pxTaskStatusArray[x].uxCurrentPriority, (unsigned int)pStack, 0); } #else if (memcmp(pxTaskStatusArray[x].pcTaskName, "IDLE", 5) != 0) { SYSVIEW_SendTaskInfo((unsigned)pxTaskStatusArray[x].xHandle, pxTaskStatusArray[x].pcTaskName, pxTaskStatusArray[x].uxCurrentPriority, (unsigned int)pStack, 0); } #endif } /* Free the array again. */ vPortFree( pxTaskStatusArray ); } }
/***************************udp related*********************************/ int udpclient() { int cli_sockfd; socklen_t addrlen; struct sockaddr_in cli_addr; int loop= 0; char *buffer ; // int delay = 2; if(!g_ulPacketCount) g_ulPacketCount = 100; if(!g_cli_buf_size) g_cli_buf_size = 1500; buffer = (char*)pvPortMalloc(g_cli_buf_size); if(NULL == buffer){ printf("\n\rudpclient: Allocate buffer failed.\n"); return -1; } /*create socket*/ memset(buffer, 0, g_cli_buf_size); cli_sockfd=socket(AF_INET,SOCK_DGRAM,0); if (cli_sockfd<0) { printf("create socket failed\r\n\n"); return 1; } /* fill sockaddr_in*/ addrlen=sizeof(struct sockaddr_in); memset(&cli_addr, 0, addrlen); cli_addr.sin_family=AF_INET; cli_addr.sin_addr.s_addr=inet_addr(g_server_ip); cli_addr.sin_port=htons(5001); /* send data to server*/ while(loop < g_ulPacketCount && !g_terminate) { if(sendto(cli_sockfd, buffer, g_cli_buf_size, 0,(struct sockaddr*)&cli_addr, addrlen) < 0) { // Dynamic delay to prevent send fail due to limited skb, this will degrade throughtput // if(delay < 100) // delay += 2; } // vTaskDelay(delay); loop++; } close(cli_sockfd); //free buffer vPortFree(buffer); return 0; }
/** @brief Handler for IPMI_OEM_CMD_I2C_TRANSFER IPMI command * * Performs a raw I2C master read on the selected bus and return the data * Req data: * [0] - Bus ID @see i2c_mapping.h * [1] - #Chip/Address identification - (0) = ChipID identification on byte 2 * (1) = I2C Address identification on byte 2 * [2] - ChipID/I2C_Address - 8 bit address * [3] - Data Write len (n) * [4] - Data to Write * [4+n] - Data Read len (m) * * @param req[in] * @param rsp[out] * * @return */ IPMI_HANDLER(ipmi_oem_cmd_i2c_transfer, NETFN_CUSTOM_OEM, IPMI_OEM_CMD_I2C_TRANSFER, ipmi_msg *req, ipmi_msg* rsp) { uint8_t bus_id = req->data[0]; uint8_t chipid_sel = req->data[1]; uint8_t chipid_i2caddr = req->data[2]; uint8_t write_len = req->data[3]; uint8_t read_len = req->data[4+write_len]; uint8_t *read_data; uint8_t semph_err; uint8_t i2c_interf; uint8_t i2c_addr; if ( chipid_sel == 0 ) { /* Use chip id to take the bus */ semph_err = i2c_take_by_chipid( chipid_i2caddr, &i2c_addr, &i2c_interf, (TickType_t)10); } else { semph_err = i2c_take_by_busid( bus_id, &i2c_interf, (TickType_t)10 ); i2c_addr = chipid_i2caddr; } if ( semph_err == 0 ) { rsp->completion_code = IPMI_CC_UNSPECIFIED_ERROR; return; } if ( write_len > 0 ) { if (xI2CMasterWrite( i2c_interf, i2c_addr, &req->data[4], write_len ) == write_len) { rsp->completion_code = IPMI_CC_OK; } else { rsp->completion_code = IPMI_CC_UNSPECIFIED_ERROR; return; } } if ( read_len > 0 ) { read_data = pvPortMalloc( read_len ); memset( read_data, read_len, 0 ); if ( xI2CMasterRead( i2c_interf, i2c_addr, read_data, read_len ) == read_len ) { rsp->data[0] = read_len; memcpy( &rsp->data[1], read_data, read_len ); rsp->data_len = read_len+1; rsp->completion_code = IPMI_CC_OK; } else { rsp->data_len = 0; rsp->completion_code = IPMI_CC_UNSPECIFIED_ERROR; } vPortFree( read_data ); } i2c_give( i2c_interf ); }
static void vLogTask( void *pvParameters ) { const char *p, *p2; message_param_t *param; messageQueue = xQueueCreate( MESSAGE_Q_SIZE, sizeof(message_t)); for (;;) { xQueueReceive( messageQueue, &next_msg, portMAX_DELAY); printf("LOG:"); p=next_msg.msg; param = next_msg.params; while(*p) { if (*p == '%') { p++; if (*p == '%') { p++; putchar('%'); } else { if (next_msg.num_params) { p2 = param->param.string_param; while(*p2) { putchar(*p2); p2++; } vPortFree(param->param.string_param); next_msg.num_params--; param++; } else { /* no params left - output the placeholder */ putchar('%'); putchar(*p); } p++; } } else { putchar(*p); p++; } } vPortFree(param); } }
void vEthernetBufferRelease( uint8_t *pucEthernetBuffer ) { /* There is space before the Ethernet buffer in which a pointer to the network buffer that references this Ethernet buffer is stored. Remove the space before freeing the buffer. */ if( pucEthernetBuffer != NULL ) { pucEthernetBuffer -= ipBUFFER_PADDING; vPortFree( ( void * ) pucEthernetBuffer ); } }
static void __cmd_IMEI_Handler(const SMSInfo *p) { char buf[16]; int len; char *pdu; sprintf(buf, "<IMEI>%s", GsmGetIMEI()); pdu = pvPortMalloc(300); len = SMSEncodePdu8bit(pdu, (const char *)p->number, buf); GsmTaskSendSMS(pdu, len); vPortFree(pdu); }
void odp_uds_freeTPBuffers(struct TPElement *tpList) { struct TPElement *actElement = tpList; while (tpList != NULL) { actElement = tpList->next; vPortFree(tpList); tpList = actElement; } DEBUGPRINT("remove all Tester Present Buffers\n", "a"); }
void erts_do_exit_process(ErlProcess* p, Eterm reason) { #if (DEBUG_OP == 1) char buf[45]; sprintf(buf, "process %d exited with reason %d\n", p->id, reason); debug(buf); #endif p->flags |= F_EXITING; //cancel timer; erts_cancel_timer(&p->timer); //delete potential interrupts delete_interrupt(p->id); //propagate information if(reason != atom_normal) { ErtsLink* link = p->links; Eterm* hp = (Eterm*)pvPortMalloc(4*sizeof(Eterm)); hp[0] = make_arityval(3); hp[1] = atom_EXIT; hp[2] = p->id; hp[3] = reason; Eterm exit_message = make_tuple(hp); while(link != NULL) { ErlProcess* linked = (ErlProcess*)&proc_tab[pid2pix(link->pid)]; if(!(linked->flags & F_EXITING)) { erts_remove_link(&linked->links, p->id); } if(linked->flags & F_TRAP_EXIT && reason != atom_kill) { erts_send_message(p, link->pid, exit_message, 0); } else { if(!(linked->flags & F_EXITING)) { erts_do_exit_process(linked, reason); } } link = link->next; } vPortFree(hp); } //clean flags since they will be reused free_process(p); suspended++; vTaskSuspend(*(p->handle)); continued++; }
void *pvPortRealloc(void *mem, size_t newsize) { void *p; p = pvPortMalloc(newsize); if (p) { /* zero the memory */ memcpy(p, mem, newsize); vPortFree(mem); } return p; }
static void do_write_test(const char *path, const char *val) { char *msg; printk("Write %s to %s...\n", val, path); msg = xenbus_write(XBT_NIL, path, val); if (msg) { printk("Result %s\n", msg); vPortFree(msg); } else { printk("Success.\n"); } }
static void __cmd_LOCATION_Handler(const SMSInfo *sms) { char __touser[80] = {0}; char *pdu = NULL; int len; extern char longitude[], latitude[]; sprintf(__touser, "longitude:%.10s,latitude:%.10s", longitude, latitude); pdu = pvPortMalloc(100); len = SMSEncodePdu8bit(pdu, sms->number, (char *)__touser); GsmTaskSendSMS(pdu, len); vPortFree(pdu); }
static void do_rm_test(const char *path) { char *msg; printk("rm %s...\n", path); msg = xenbus_rm(XBT_NIL, path); if (msg) { printk("Result %s\n", msg); vPortFree(msg); } else { printk("Success.\n"); } }