Skip to content

Instantly share code, notes, and snippets.

/app_task.c Secret

Created September 14, 2016 08:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/fd82d7455f09d01fc850adb0b770669d to your computer and use it in GitHub Desktop.
Save anonymous/fd82d7455f09d01fc850adb0b770669d to your computer and use it in GitHub Desktop.
#include "common/cs_dbg.h"
#include <oslib/osi.h>
#include <stdbool.h>
#include <string.h>
#include "app_task.h"
#include "cc3200_main_task.h"
#include "FreeRTOS.h"
#include "task.h"
static OsiMsgQ_t msgq;
static OsiTaskHandle th;
void _invoke_cb(void *arg) {
LOG(LL_INFO, ("invoke cb"));
app_task_msg_t* msg = (app_task_msg_t*)arg;
msg->cb(msg);
free(msg);
}
void msg_cb(app_task_msg_t* msg) {
LOG(LL_INFO, ("Message cb executed"));
}
bool app_task_post(app_task_msg_t* msg) {
return osi_MsgQWrite(&msgq, msg, OSI_NO_WAIT) == OSI_OK;
}
void apptask_msg() {
app_task_msg_t msg;
msg.cmd = APPCMD_DO_SOMETHING;
msg.data = 20;
msg.cb = msg_cb;
app_task_post(&msg);
}
void _app_run(void *arg) {
app_task_msg_t msg;
while (1) {
memset(&msg, 0, sizeof(msg));
if (osi_MsgQRead(&msgq, &msg, OSI_WAIT_FOREVER) != OSI_OK) {
LOG(LL_WARN, ("IMPOSSIBRU!"));
osi_Sleep(10);
continue;
}
switch (msg.cmd) {
case APPCMD_DO_SOMETHING: {
LOG(LL_INFO, ("APPCMD_DO_SOMETHING received"));
if (msg.cb != NULL) {
app_task_msg_t* msg2 = (app_task_msg_t*) malloc(sizeof(app_task_msg_t));
if (msg2) {
memcpy(msg2, &msg, sizeof(app_task_msg_t));
LOG(LL_INFO, ("cb : %p data %d ", msg2->cb,msg2->data));
invoke_cb(_invoke_cb, (void *)msg2);
}
}
break;
}
default: {
LOG(LL_WARN, ("unhandled command %d", msg.cmd));
}
}
} // end while 1
}
OsiMsgQ_t *apptask_start() {
OsiReturnVal_e retval;
retval = osi_MsgQCreate(&msgq, "appq", sizeof(app_task_msg_t), APP_TASK_QUEUE_LEN);
if (retval != OSI_OK) {
LOG(LL_ERROR, ("osi_MsgQCreate appq failed: %d", retval));
return NULL;
}
retval = osi_TaskCreate(_app_run, (const signed char *)"app_task",
APP_TASK_STACK_SIZE, NULL, APP_TASK_PRIORITY, &th);
if (retval != OSI_OK) {
LOG(LL_ERROR, ("osi_TaskCreate app_task failed: %d", retval));
return NULL;
}
LOG(LL_INFO, ("started apptask, msgsize=%d", sizeof(app_task_msg_t)));
return &msgq;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment