2017-04-24 23:11:22 +02:00
|
|
|
/****************************************************************************
|
2021-03-08 22:39:04 +01:00
|
|
|
* drivers/wireless/ieee80211/bcm43xxx/bcmf_utils.c
|
2017-04-24 23:11:22 +02:00
|
|
|
*
|
2021-05-27 11:12:43 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2017-04-24 23:11:22 +02:00
|
|
|
*
|
2021-05-27 11:12:43 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2017-04-24 23:11:22 +02:00
|
|
|
*
|
2021-05-27 11:12:43 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2017-04-24 23:11:22 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-16 11:28:08 +02:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
2017-04-23 22:17:43 +02:00
|
|
|
#include <time.h>
|
2017-04-16 11:28:08 +02:00
|
|
|
#include <debug.h>
|
2017-04-23 22:17:43 +02:00
|
|
|
#include <stdio.h>
|
2017-04-30 20:29:48 +02:00
|
|
|
#include <queue.h>
|
2017-04-23 22:17:43 +02:00
|
|
|
|
|
|
|
#include "bcmf_utils.h"
|
2017-04-16 11:28:08 +02:00
|
|
|
|
2017-04-24 23:11:22 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-16 11:28:08 +02:00
|
|
|
#define LINE_LEN 16
|
|
|
|
|
2017-04-24 23:11:22 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-23 22:17:43 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: bcmf_hexdump
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-16 11:28:08 +02:00
|
|
|
void bcmf_hexdump(uint8_t *data, unsigned int len, unsigned long offset)
|
|
|
|
{
|
2017-04-24 00:24:47 +02:00
|
|
|
unsigned int i;
|
|
|
|
unsigned int char_count = 0;
|
|
|
|
char char_line[20];
|
|
|
|
char hex_line[64];
|
|
|
|
|
2017-05-04 02:20:57 +02:00
|
|
|
for (i = 0; i < len; i++)
|
2017-04-24 00:24:47 +02:00
|
|
|
{
|
|
|
|
if (char_count >= LINE_LEN)
|
2019-10-29 23:56:24 +01:00
|
|
|
{
|
|
|
|
/* Flush line */
|
2017-04-24 00:24:47 +02:00
|
|
|
|
2020-12-04 14:19:54 +01:00
|
|
|
wlinfo("%08lx: %s%s\n",
|
2019-10-29 23:56:24 +01:00
|
|
|
offset + i - char_count, hex_line, char_line);
|
|
|
|
char_count = 0;
|
|
|
|
}
|
2017-04-24 00:24:47 +02:00
|
|
|
|
2019-10-29 23:56:24 +01:00
|
|
|
sprintf(hex_line + 3 * char_count, "%02x ", data[i]);
|
|
|
|
sprintf(char_line + char_count, "%c",
|
2017-04-24 00:24:47 +02:00
|
|
|
data[i] < 0x20 || data[i] >= 0x7f? '.': data[i]);
|
2019-10-29 23:56:24 +01:00
|
|
|
char_count++;
|
2017-04-24 00:24:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (char_count > 0)
|
|
|
|
{
|
|
|
|
/* Flush last line */
|
|
|
|
|
2019-10-29 23:56:24 +01:00
|
|
|
memset(hex_line + 3 * char_count, ' ', 3 * (LINE_LEN - char_count));
|
|
|
|
hex_line[3 * LINE_LEN] = 0;
|
2020-12-04 14:19:54 +01:00
|
|
|
wlinfo("%08lx: %s%s\n", offset + i - char_count, hex_line, char_line);
|
2017-04-24 00:24:47 +02:00
|
|
|
}
|
2017-04-23 22:17:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: bcmf_sem_wait
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int bcmf_sem_wait(sem_t *sem, unsigned int timeout_ms)
|
|
|
|
{
|
|
|
|
struct timespec abstime;
|
2017-05-02 16:48:13 +02:00
|
|
|
unsigned int timeout_sec;
|
2017-04-23 22:17:43 +02:00
|
|
|
|
|
|
|
/* Get the current time */
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
clock_gettime(CLOCK_REALTIME, &abstime);
|
2017-04-23 22:17:43 +02:00
|
|
|
|
2017-05-04 02:20:57 +02:00
|
|
|
timeout_sec = timeout_ms / 1000;
|
2017-05-02 16:48:13 +02:00
|
|
|
abstime.tv_sec += timeout_sec;
|
2017-05-04 02:20:57 +02:00
|
|
|
abstime.tv_nsec += 1000 * 1000 * (timeout_ms % 1000);
|
2017-04-23 22:17:43 +02:00
|
|
|
|
|
|
|
if (abstime.tv_nsec >= 1000 * 1000 * 1000)
|
|
|
|
{
|
|
|
|
abstime.tv_sec++;
|
|
|
|
abstime.tv_nsec -= 1000 * 1000 * 1000;
|
|
|
|
}
|
|
|
|
|
2017-10-05 15:24:54 +02:00
|
|
|
return nxsem_timedwait(sem, &abstime);
|
2017-04-30 20:29:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void bcmf_dqueue_push(dq_queue_t *queue, dq_entry_t *entry)
|
|
|
|
{
|
|
|
|
if (queue->head == NULL)
|
|
|
|
{
|
|
|
|
/* List is empty */
|
|
|
|
|
|
|
|
queue->tail = entry;
|
|
|
|
|
|
|
|
entry->flink = entry;
|
|
|
|
entry->blink = entry;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Insert entry at list head */
|
|
|
|
|
|
|
|
entry->flink = queue->head;
|
|
|
|
entry->blink = queue->tail;
|
|
|
|
|
|
|
|
queue->head->blink = entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
queue->head = entry;
|
|
|
|
}
|
|
|
|
|
2017-05-04 02:20:57 +02:00
|
|
|
dq_entry_t *bcmf_dqueue_pop_tail(dq_queue_t *queue)
|
2017-04-30 20:29:48 +02:00
|
|
|
{
|
|
|
|
dq_entry_t *entry = queue->tail;
|
|
|
|
|
|
|
|
if (queue->head == queue->tail)
|
|
|
|
{
|
|
|
|
/* List is empty */
|
|
|
|
|
|
|
|
queue->head = NULL;
|
|
|
|
queue->tail = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Pop from queue tail */
|
|
|
|
|
|
|
|
queue->tail = entry->blink;
|
|
|
|
entry->blink->flink = queue->head;
|
|
|
|
}
|
|
|
|
|
|
|
|
return entry;
|
2017-05-04 02:20:57 +02:00
|
|
|
}
|