build: W600-SDK importiert, Firmware-Build und Hello am EVK
Docker-Build mit gcc-arm-none-eabi 4.9-2014q4 (statt Homebrew-Cask) verwendet, Dockerfile/tools/docker.sh dafür aus Task 13 vorgezogen. cmake/sdk.cmake schont gcc 4.9 (kennt -fcommon/-Wno-error=... nicht). Zwei zusätzliche SDK-Stubs (EarlyInit, pre_gpio_config) in src/sys/sdk_stubs.c ergänzt, siehe sdk/PATCHES.md.
This commit is contained in:
@@ -0,0 +1,160 @@
|
||||
/**
|
||||
* @file wm_wl_mbox.c
|
||||
*
|
||||
* @brief mailbox (mbox) APIs
|
||||
*
|
||||
* @author dave
|
||||
*
|
||||
* Copyright (c) 2015 Winner Microelectronics Co., Ltd.
|
||||
*/
|
||||
#include "wm_mem.h"
|
||||
#include "wm_wl_mbox.h"
|
||||
#include "wm_wl_task.h"
|
||||
const void * const tls_null_pointer = (void *)0;
|
||||
|
||||
/**
|
||||
* @brief create a malibox
|
||||
*
|
||||
* @param[out] *mbox pointer to the mailbox
|
||||
* @param[in] size size of mailbox
|
||||
*
|
||||
* @retval TLS_OS_SUCCESS success
|
||||
* @retval TLS_OS_ERROR failed
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
s8 tls_mbox_new(tls_mbox_t *mbox, int size)
|
||||
{
|
||||
s8 err;
|
||||
tls_os_status_t status;
|
||||
|
||||
if (size == 0)
|
||||
size = 10;
|
||||
|
||||
status = tls_os_queue_create(mbox, size);
|
||||
if (status == TLS_OS_SUCCESS) {
|
||||
err = TLS_OS_SUCCESS;
|
||||
}
|
||||
else
|
||||
err = TLS_OS_ERROR;
|
||||
return err;
|
||||
}
|
||||
|
||||
#ifndef tls_mbox_valid
|
||||
/**
|
||||
* @brief check if an mbox is valid/allocated
|
||||
*
|
||||
* @param[in] mbox pointer to the mailbox
|
||||
*
|
||||
* @retval 0 invalid
|
||||
* @retval 1 valid
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
int tls_mbox_valid(tls_mbox_t mbox)
|
||||
{
|
||||
if (mbox == NULL)
|
||||
return 0;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief sends a message to a mailbox
|
||||
*
|
||||
* @param[in] mbox pointer to the mailbox
|
||||
* @param[in] *msg pointer to the message to be post
|
||||
*
|
||||
* @return None
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
void tls_mbox_post(tls_mbox_t mbox, void *msg)
|
||||
{
|
||||
u8 err;
|
||||
u8 i=0;
|
||||
|
||||
if(msg == NULL )
|
||||
msg = (void*)tls_null_pointer;
|
||||
|
||||
/* try 10 times */
|
||||
while (i < 10)
|
||||
{
|
||||
err = tls_os_queue_send(mbox, msg, 0);
|
||||
if(err == TLS_OS_SUCCESS)
|
||||
break;
|
||||
i++;
|
||||
tls_os_time_delay(5);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief posts the "msg" to the mailbox.
|
||||
*
|
||||
* @param[in] mbox pointer to the mailbox
|
||||
* @param[in] *msg pointer to the message to be post
|
||||
*
|
||||
* @retval TLS_OS_SUCCESS success
|
||||
* @retval TLS_OS_ERROR failed
|
||||
*
|
||||
* @note this function have to block until the "msg" is really posted.
|
||||
*/
|
||||
s8 tls_mbox_trypost(tls_mbox_t mbox, void *msg)
|
||||
{
|
||||
u8 err;
|
||||
|
||||
if( msg == NULL )
|
||||
{
|
||||
msg = (void*)tls_null_pointer;
|
||||
}
|
||||
|
||||
err = tls_os_queue_send(mbox, msg, 0);
|
||||
if(err == TLS_OS_SUCCESS)
|
||||
return TLS_OS_SUCCESS;
|
||||
|
||||
return TLS_OS_ERROR;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief waits for a message within the specified time
|
||||
*
|
||||
* @param[in] mbox pointer to the mailbox
|
||||
* @param[out] **msg pointer to the message to be received
|
||||
* @param[in] timeout the specified time
|
||||
*
|
||||
* @retval SYS_ARCH_TIMEOUT time out
|
||||
* @retval other time of elapsed
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
u32 tls_arch_mbox_fetch(tls_mbox_t mbox, void **msg, u32 timeout)
|
||||
{
|
||||
u8 err;
|
||||
u32 ucos_timeout = 0;
|
||||
u32 in_timeout = timeout * HZ / 1000;
|
||||
u32 tick_start, tick_stop, tick_elapsed;
|
||||
|
||||
if(timeout && in_timeout == 0)
|
||||
in_timeout = 1;
|
||||
|
||||
tick_start = tls_os_get_time();
|
||||
// *msg = OSQPend(mbox, in_timeout, &err);
|
||||
err = tls_os_queue_receive(mbox,msg,0,in_timeout);
|
||||
// if (err == OS_ERR_TIMEOUT ) {
|
||||
if (err != TLS_OS_SUCCESS ) {
|
||||
ucos_timeout = SYS_ARCH_TIMEOUT;
|
||||
return ucos_timeout;
|
||||
}
|
||||
tick_stop = tls_os_get_time();
|
||||
|
||||
// Take care of wrap-around.
|
||||
if( tick_stop >= tick_start )
|
||||
tick_elapsed = tick_stop - tick_start;
|
||||
else
|
||||
tick_elapsed = 0xFFFFFFFF - tick_start + tick_stop ;
|
||||
|
||||
|
||||
return tick_elapsed * 1000/HZ;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,164 @@
|
||||
#include "wm_mem.h"
|
||||
#include "wm_wl_timers.h"
|
||||
#include "wm_wl_task.h"
|
||||
#include <string.h>
|
||||
|
||||
static tls_mbox_t task_mbox[TLS_MBOX_ALL_COUNT];
|
||||
struct task_msg wl_msg[TLS_MSG_ALL_COUONT];
|
||||
//#define TLS_MSG_ID_TX_MGMT_CMPLT 0
|
||||
//#define TLS_MSG_ID_MLME_TASK 1
|
||||
|
||||
static void
|
||||
task_thread(void *arg)
|
||||
{
|
||||
struct task_msg *msg;
|
||||
start_routine fun;
|
||||
void * argu;
|
||||
struct task_parameter *task_param = (struct task_parameter *)arg;
|
||||
|
||||
while (1) { /* MAIN Loop */
|
||||
/* wait for a message, timeouts are processed while waiting */
|
||||
tls_timeouts_mbox_fetch_p(task_param->timeo_id, task_mbox[task_param->mbox_id], (void **)&msg);
|
||||
switch (msg->type) {
|
||||
case TASK_MSG_CALLBACK:
|
||||
msg->msg.cb.function(msg->msg.cb.ctx);
|
||||
tls_mem_free(msg);
|
||||
break;
|
||||
case TASK_MSG_CALLBACK_STATIC:
|
||||
fun = msg->msg.cbs.function;
|
||||
argu = msg->msg.cbs.ctx;
|
||||
msg->msg.cbs.cnt--;
|
||||
fun(argu);
|
||||
break;
|
||||
case TASK_MSG_TIMEOUT:
|
||||
tls_timeout_p(task_param->timeo_id, msg->msg.tmo.msecs, msg->msg.tmo.h, msg->msg.tmo.arg);
|
||||
tls_mem_free(msg);
|
||||
break;
|
||||
case TASK_MSG_UNTIMEOUT:
|
||||
tls_untimeout_p(task_param->timeo_id, msg->msg.tmo.h, msg->msg.tmo.arg);
|
||||
tls_mem_free(msg);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
s8 tls_wl_task_run(struct task_parameter *task_param)
|
||||
{
|
||||
if(tls_mbox_new(&task_mbox[task_param->mbox_id], task_param->mbox_size) != TLS_OS_SUCCESS) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
tls_os_task_create(NULL, "WL_TSK",
|
||||
//tls_os_task_create(NULL, task_param->name,
|
||||
task_thread,
|
||||
(void *)task_param,
|
||||
(void *)(task_param->stk_start),
|
||||
task_param->stk_size * sizeof(u32),
|
||||
TLS_TASK_START_PRIO+task_param->task_id,
|
||||
0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
s8
|
||||
tls_wl_task_callback_static(struct task_parameter *task_param, start_routine function, void *ctx, u8 block, u8 msg_id)
|
||||
{
|
||||
struct task_msg *msg = &wl_msg[msg_id];
|
||||
|
||||
if (msg->msg.cbs.cnt > 0)
|
||||
return TLS_OS_ERROR;
|
||||
|
||||
if (tls_mbox_valid(task_mbox[task_param->mbox_id])) {
|
||||
msg->type = TASK_MSG_CALLBACK_STATIC;
|
||||
msg->msg.cbs.function = function;
|
||||
msg->msg.cbs.ctx = ctx;
|
||||
if (block) {
|
||||
tls_mbox_post(task_mbox[task_param->mbox_id], (void *)msg);
|
||||
}
|
||||
else {
|
||||
if (tls_mbox_trypost(task_mbox[task_param->mbox_id], (void *)msg) != TLS_OS_SUCCESS)
|
||||
return TLS_OS_ERROR;
|
||||
}
|
||||
msg->msg.cbs.cnt++;
|
||||
return TLS_OS_SUCCESS;
|
||||
}
|
||||
return TLS_OS_ERROR;
|
||||
}
|
||||
|
||||
s8
|
||||
tls_wl_task_callback(struct task_parameter *task_param, start_routine function, void *ctx, u8 block)
|
||||
{
|
||||
struct task_msg *msg;
|
||||
|
||||
if (tls_mbox_valid(task_mbox[task_param->mbox_id])) {
|
||||
msg = (struct task_msg *)tls_mem_alloc(sizeof(struct task_msg));
|
||||
if (msg == NULL) {
|
||||
return TLS_OS_ERROR;
|
||||
}
|
||||
|
||||
msg->type = TASK_MSG_CALLBACK;
|
||||
msg->msg.cb.function = function;
|
||||
msg->msg.cb.ctx = ctx;
|
||||
if (block) {
|
||||
tls_mbox_post(task_mbox[task_param->mbox_id], msg);
|
||||
} else {
|
||||
if (tls_mbox_trypost(task_mbox[task_param->mbox_id], msg) != TLS_OS_SUCCESS) {
|
||||
//printf("tls_mbox_trypost error.\n");
|
||||
tls_mem_free(msg);
|
||||
return TLS_OS_ERROR;
|
||||
}
|
||||
}
|
||||
return TLS_OS_SUCCESS;
|
||||
}
|
||||
return TLS_OS_ERROR;
|
||||
}
|
||||
|
||||
s8
|
||||
tls_wl_task_add_timeout(struct task_parameter *task_param, u32 msecs, tls_timeout_handler h, void *arg)
|
||||
{
|
||||
struct task_msg *msg;
|
||||
|
||||
if (tls_mbox_valid(task_mbox[task_param->mbox_id])) {
|
||||
msg = (struct task_msg *)tls_mem_alloc(sizeof(struct task_msg));
|
||||
if (msg == NULL) {
|
||||
return TLS_OS_ERROR;
|
||||
}
|
||||
|
||||
msg->type = TASK_MSG_TIMEOUT;
|
||||
msg->msg.tmo.msecs = msecs;
|
||||
msg->msg.tmo.h = h;
|
||||
msg->msg.tmo.arg = arg;
|
||||
tls_mbox_post(task_mbox[task_param->mbox_id], msg);
|
||||
return TLS_OS_SUCCESS;
|
||||
}
|
||||
return TLS_OS_ERROR;
|
||||
}
|
||||
|
||||
s8
|
||||
tls_wl_task_untimeout(struct task_parameter *task_param, tls_timeout_handler h, void *arg)
|
||||
{
|
||||
struct task_msg *msg;
|
||||
|
||||
if (tls_mbox_valid(task_mbox[task_param->mbox_id])) {
|
||||
msg = (struct task_msg *)tls_mem_alloc(sizeof(struct task_msg));
|
||||
if (msg == NULL) {
|
||||
return TLS_OS_ERROR;
|
||||
}
|
||||
|
||||
msg->type = TASK_MSG_UNTIMEOUT;
|
||||
msg->msg.tmo.h = h;
|
||||
msg->msg.tmo.arg = arg;
|
||||
tls_mbox_post(task_mbox[task_param->mbox_id], msg);
|
||||
return TLS_OS_SUCCESS;
|
||||
}
|
||||
return TLS_OS_ERROR;
|
||||
}
|
||||
|
||||
s8
|
||||
tls_wl_task_init(void)
|
||||
{
|
||||
memset(wl_msg, 0, sizeof(struct task_msg));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,180 @@
|
||||
#include <string.h>
|
||||
#include "wm_mem.h"
|
||||
#include "wm_wl_timers.h"
|
||||
#include "wm_wl_task.h"
|
||||
|
||||
struct tls_timeo {
|
||||
struct tls_timeo *next;
|
||||
u32 time;
|
||||
tls_timeout_handler h;
|
||||
void *arg;
|
||||
};
|
||||
|
||||
/** The one and only timeout list */
|
||||
struct tls_timeo *next_timeout[TLS_TIMEO_ALL_COUONT];
|
||||
|
||||
/**
|
||||
* @brief Wait (forever) for a message to arrive in an mbox.
|
||||
* While waiting, timeouts are processed
|
||||
*
|
||||
* @param[in] timeo_assigned timer NO. by assigned
|
||||
* @param[in] mbox the mbox to fetch the message from
|
||||
* @param[out] **msg the place to store the message
|
||||
*
|
||||
* @return None
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
void tls_timeouts_mbox_fetch_p(u8 timeo_assigned, tls_mbox_t mbox, void **msg)
|
||||
{
|
||||
u32 time_needed;
|
||||
struct tls_timeo *tmptimeout;
|
||||
tls_timeout_handler handler;
|
||||
void *arg;
|
||||
|
||||
struct tls_timeo **timeo = &next_timeout[timeo_assigned];
|
||||
|
||||
again:
|
||||
if (!(*timeo)) {
|
||||
time_needed = tls_arch_mbox_fetch(mbox, msg, 0);
|
||||
} else {
|
||||
if ((*timeo)->time > 0) {
|
||||
time_needed = tls_arch_mbox_fetch(mbox, msg, (*timeo)->time);
|
||||
} else {
|
||||
time_needed = SYS_ARCH_TIMEOUT;
|
||||
}
|
||||
|
||||
if (time_needed == SYS_ARCH_TIMEOUT) {
|
||||
/* If time == SYS_ARCH_TIMEOUT, a timeout occured before a message
|
||||
could be fetched. We should now call the timeout handler and
|
||||
deallocate the memory allocated for the timeout. */
|
||||
tmptimeout = *timeo;
|
||||
*timeo = tmptimeout->next;
|
||||
handler = tmptimeout->h;
|
||||
arg = tmptimeout->arg;
|
||||
tls_mem_free(tmptimeout);
|
||||
if (handler != NULL) {
|
||||
handler(arg);
|
||||
}
|
||||
|
||||
/* We try again to fetch a message from the mbox. */
|
||||
goto again;
|
||||
} else {
|
||||
/* If time != SYS_ARCH_TIMEOUT, a message was received before the timeout
|
||||
occured. The time variable is set to the number of
|
||||
milliseconds we waited for the message. */
|
||||
if (time_needed < (*timeo)->time) {
|
||||
(*timeo)->time -= time_needed;
|
||||
} else {
|
||||
(*timeo)->time = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief create a one-shot timer (aka timeout)
|
||||
*
|
||||
* @param[in] timeo_assigned timer NO. by assigned
|
||||
* @param[in] msecs time in milliseconds after that the timer should expire
|
||||
* @param[in] handler callback function that would be called by the timeout
|
||||
* @param[in] *arg callback argument that would be passed to handler
|
||||
*
|
||||
* @return None
|
||||
*
|
||||
* @note while waiting for a message using sys_timeouts_mbox_fetch()
|
||||
*/
|
||||
void tls_timeout_p(u8 timeo_assigned, u32 msecs, tls_timeout_handler handler, void *arg)
|
||||
{
|
||||
struct tls_timeo *timeout, *t;
|
||||
struct tls_timeo **timeo = &next_timeout[timeo_assigned];
|
||||
|
||||
timeout = (struct tls_timeo *)tls_mem_alloc(sizeof(struct tls_timeo));
|
||||
if (timeout == NULL) {
|
||||
return;
|
||||
}
|
||||
timeout->next = NULL;
|
||||
timeout->h = handler;
|
||||
timeout->arg = arg;
|
||||
timeout->time = msecs;
|
||||
|
||||
if (*timeo == NULL) {
|
||||
*timeo = timeout;
|
||||
return;
|
||||
}
|
||||
|
||||
if ((*timeo)->time > msecs) {
|
||||
(*timeo)->time -= msecs;
|
||||
timeout->next = *timeo;
|
||||
*timeo = timeout;
|
||||
} else {
|
||||
for(t = *timeo; t != NULL; t = t->next) {
|
||||
timeout->time -= t->time;
|
||||
if (t->next == NULL || t->next->time > timeout->time) {
|
||||
if (t->next != NULL) {
|
||||
t->next->time -= timeout->time;
|
||||
}
|
||||
timeout->next = t->next;
|
||||
t->next = timeout;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Go through timeout list (for this task only) and remove the first
|
||||
* matching entry, even though the timeout has not triggered yet
|
||||
*
|
||||
* @param[in] timeo_assigned timer NO. by assigned
|
||||
* @param[in] handler callback function that would be called by the timeout
|
||||
* @param[in] *arg callback argument that would be passed to handler
|
||||
*
|
||||
* @return None
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
void tls_untimeout_p(u8 timeo_assigned, tls_timeout_handler handler, void *arg)
|
||||
{
|
||||
struct tls_timeo *prev_t, *t;
|
||||
struct tls_timeo **timeo = &next_timeout[timeo_assigned];
|
||||
|
||||
if (*timeo == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (t = *timeo, prev_t = NULL; t != NULL; prev_t = t, t = t->next) {
|
||||
if ((t->h == handler) && (t->arg == arg)) {
|
||||
/* We have a match */
|
||||
/* Unlink from previous in list */
|
||||
if (prev_t == NULL) {
|
||||
*timeo = t->next;
|
||||
} else {
|
||||
prev_t->next = t->next;
|
||||
}
|
||||
/* If not the last one, add time of this one back to next */
|
||||
if (t->next != NULL) {
|
||||
t->next->time += t->time;
|
||||
}
|
||||
tls_mem_free(t);
|
||||
return;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief timer initialized
|
||||
*
|
||||
* @param None
|
||||
*
|
||||
* @return None
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
s8 tls_wl_timer_init(void)
|
||||
{
|
||||
memset(next_timeout, 0, sizeof(struct tls_timeo *) * TLS_TIMEO_ALL_COUONT);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user