// Function shouldn't block void Start(IPSocket *socket, char *argv[]) { IPPrintf(socket, "Hello from dlltest\n"); socket->userFunc = socket->funcPtr; //remember prev socket receive func socket->funcPtr = SocketReceive; //new socket receive function OS_ThreadCreate("MyThread", MyThread, socket, 100, 0); }
int main(int programEnd, char *argv[]) { (void)programEnd; //Pointer to end of used memory (void)argv; UartPrintfCritical("Starting RTOS\n"); #ifdef WIN32 OS_Init((uint32*)HeapSpace, sizeof(HeapSpace)); #else //Remaining space after program in 1MB external RAM OS_Init((uint32*)programEnd, RAM_EXTERNAL_BASE + RAM_EXTERNAL_SIZE - programEnd); #endif UartInit(); OS_ThreadCreate("Main", MainThread, NULL, 100, 4000); OS_Start(); /*****************************************************************/ return 0; }
static enum cmd_status cmd_mqtt_connect_exec(char *cmd) { int32_t cnt; char addr_str[15]; uint32_t port; int32_t rc; uint32_t i; /* get param */ cnt = cmd_sscanf(cmd, "server=%15s port=%u", addr_str, &port); /* check param */ if (cnt != 2) { CMD_ERR("invalid param number %d\n", cnt); return CMD_STATUS_INVALID_ARG; } i = 10; char* address = addr_str; while ((rc = ConnectNetwork(&network, address, port)) != 0) { CMD_WRN("Return code from network connect is %d\n", rc); cmd_msleep(2000); if (!(i--)) return CMD_STATUS_FAIL; } if ((rc = MQTTConnect(&client, &connectData)) != 0) { CMD_ERR("Return code from MQTT connect is %d\n", rc); return CMD_STATUS_FAIL; } else CMD_DBG("MQTT Connected\n"); if (OS_ThreadCreate(&mqtt_bg_thread, "", cmd_mqtt_bg, NULL, OS_PRIORITY_NORMAL, CMD_MQTT_BG_THREAD_STACK_SIZE) != OS_OK) { CMD_ERR("create mqtt background failed\n"); return CMD_STATUS_FAIL; } return CMD_STATUS_OK; }
void OS_Init(uint32 *heapStorage, uint32 bytes) { int i; OS_AsmInterruptInit(); //Patch interrupt vector OS_InterruptMaskClear(0xffffffff); //Disable interrupts HeapArray[0] = OS_HeapCreate("Default", heapStorage, bytes); HeapArray[1] = HeapArray[0]; SemaphoreSleep = OS_SemaphoreCreate("Sleep", 0); SemaphoreRelease = OS_SemaphoreCreate("Release", 1); SemaphoreLock = OS_SemaphoreCreate("Lock", 1); for(i = 0; i < OS_CPU_COUNT; ++i) OS_ThreadCreate("Idle", OS_IdleThread, NULL, 0, 256); #ifndef DISABLE_IRQ_SIM if((OS_InterruptStatus() & (IRQ_COUNTER18 | IRQ_COUNTER18_NOT)) == 0) { //Detected that running in simulator so create SimIsr thread UartPrintfCritical("SimIsr\n"); OS_ThreadCreate("SimIsr", OS_IdleSimulateIsr, NULL, 1, 0); } #endif //DISABLE_IRQ_SIM //Plasma hardware dependent OS_InterruptRegister(IRQ_COUNTER18 | IRQ_COUNTER18_NOT, OS_ThreadTickToggle); OS_InterruptMaskSet(IRQ_COUNTER18 | IRQ_COUNTER18_NOT); }
EButtonErrStatus OS_WorkThreadStart(SButton_dev * dev, OS_ThreadProc threadProc) { ButtonThreadHandle handle; EButtonErrStatus rslt; rslt = OS_ThreadCreate(&handle, threadProc, (void *)dev, "Button INT Worker"); if(rslt != BUTTON_OK) { printk("Create button interrupt working thread Failed! rslt = %d\n", rslt); } return rslt; }
int sntp_start() { if (OS_ThreadIsValid(&g_sntp_thread)) { CMD_ERR("sntp task is running\n"); return -1; } if (OS_ThreadCreate(&g_sntp_thread, "", sntp_run, NULL, OS_THREAD_PRIO_APP, SNTP_THREAD_STACK_SIZE) != OS_OK) { CMD_ERR("sntp task create failed\n"); return -1; } return 0; }
void OS_Job(void (*funcPtr)(), void *arg0, void *arg1, void *arg2) { uint32 message[4]; int rc; OS_SemaphorePend(SemaphoreLock, OS_WAIT_FOREVER); if(jobThread == NULL) { jobQueue = OS_MQueueCreate("job", 100, 16); jobThread = OS_ThreadCreate("job", JobThread, NULL, 150, 4000); } OS_SemaphorePost(SemaphoreLock); message[0] = (uint32)funcPtr; message[1] = (uint32)arg0; message[2] = (uint32)arg1; message[3] = (uint32)arg2; rc = OS_MQueueSend(jobQueue, message); }
/* start at command */ void atcmd_start(void) { at_serial_para_t para; at_cmd_init(); at_serial(¶); //serial_init(SERIAL_UART_ID, 115200, UART_DATA_BITS_8, UART_PARITY_NONE, UART_STOP_BITS_1, para.hwfc); serial_init(SERIAL_UART_ID, para.baudrate, UART_DATA_BITS_8, UART_PARITY_NONE, UART_STOP_BITS_1, para.hwfc); serial_start(); /* start atcmd task */ if (OS_ThreadCreate(&g_atcmd_thread, "atcmd", atcmd_task, NULL, OS_THREAD_PRIO_CONSOLE, ATCMD_THREAD_STACK_SIZE) != OS_OK) { ATCMD_ERR("create serial task failed\n"); return ; } }
OS_Timer_t *OS_TimerCreate(const char *name, OS_MQueue_t *mQueue, uint32 info) { OS_Timer_t *timer; OS_SemaphorePend(SemaphoreLock, OS_WAIT_FOREVER); if(SemaphoreTimer == NULL) { SemaphoreTimer = OS_SemaphoreCreate("Timer", 0); OS_ThreadCreate("Timer", OS_TimerThread, NULL, 250, 2000); } OS_SemaphorePost(SemaphoreLock); timer = (OS_Timer_t*)OS_HeapMalloc(HEAP_SYSTEM, sizeof(OS_Timer_t)); if(timer == NULL) return NULL; timer->name = name; timer->callback = NULL; timer->mqueue = mQueue; timer->next = NULL; timer->prev = NULL; timer->info = info; timer->active = 0; return timer; }