Initial commit: TXW82x FPV v2.7.0.7-42229 SDK + project sources

This commit is contained in:
2026-07-06 11:30:13 +08:00
commit e76462eeb7
3451 changed files with 1415300 additions and 0 deletions

View File

@@ -0,0 +1,333 @@
/*
* Copyright (C) 2017 Alibaba Group Holding Limited
*/
/*
modification history
--------------------
2017_12_27,WangMin(Rocky) created.
*/
/*
* DESCRIPTION
* This library is used to provide the atomic operators for CPU
* which do not support native atomic operations.
*
* The design principle is disable the interrupt when execute the
* atomic operations and enable the interrupt after finish the
* operation.
*/
#include "k_api.h"
#include "k_atomic.h"
/**
* This routine atomically adds <*target> and <value>, placing the result in
* <*target>. The operation is done using unsigned integer arithmetic.
*
* This routine can be used from both task and interrupt context.
*
* @param target memory location to add to
* @param value the value to add
*
* @return The previous value from <target>
*/
atomic_val_t rhino_atomic_add(atomic_t *target, atomic_val_t value)
{
CPSR_ALLOC();
atomic_val_t old_value;
RHINO_CPU_INTRPT_DISABLE();
old_value = *target;
*target += value;
RHINO_CPU_INTRPT_ENABLE();
return old_value;
}
/**
* This routine atomically subtracts <value> from <*target>, result is placed
* in <*target>. The operation is done using unsigned integer arithmetic.
*
* This routine can be used from both task and interrupt context.
*
* @param target the memory location to subtract from
* @param value the value to subtract
*
* @return The previous value from <target>
*/
atomic_val_t rhino_atomic_sub(atomic_t *target, atomic_val_t value)
{
CPSR_ALLOC();
atomic_val_t old_value;
RHINO_CPU_INTRPT_DISABLE();
old_value = *target;
*target -= value;
RHINO_CPU_INTRPT_ENABLE();
return old_value;
}
/**
* This routine atomically increments the value in <*target>. The operation is
* done using unsigned integer arithmetic.
*
* This routine can be used from both task and interrupt context.
*
* @return The value from <target> before the increment
*/
atomic_val_t rhino_atomic_inc(atomic_t *target)
{
CPSR_ALLOC();
atomic_val_t old_value;
RHINO_CPU_INTRPT_DISABLE();
old_value = *target;
(*target)++;
RHINO_CPU_INTRPT_ENABLE();
return old_value;
}
/**
* This routine atomically decrement the value in <*target>. The operation is
* done using unsigned integer arithmetic.
*
* This routine can be used from both task and interrupt context.
*
* @return The value from <target> before the increment
*/
atomic_val_t rhino_atomic_dec(atomic_t *target)
{
CPSR_ALLOC();
atomic_val_t old_value;
RHINO_CPU_INTRPT_DISABLE();
old_value = *target;
(*target)--;
RHINO_CPU_INTRPT_ENABLE();
return old_value;
}
/**
* This routine atomically sets <*target> to <value> and returns the old value
* that was in <*target>. Normally all CPU architectures can atomically write
* to a variable of size atomic_t without the help of this routine.
* This routine is intended for software that needs to atomically fetch and
* replace the value of a memory location.
*
* This routine can be used from both task and interrupt context.
*
* @param target the memory location to write to
* @param value the value to write
*
* @return The previous value from <target>
*/
atomic_val_t rhino_atomic_set(atomic_t *target, atomic_val_t value)
{
CPSR_ALLOC();
atomic_val_t old_value;
RHINO_CPU_INTRPT_DISABLE();
old_value = *target;
*target = value;
RHINO_CPU_INTRPT_ENABLE();
return old_value;
}
/**
* This routine atomically read a value from <target>.
* This routine can be used from both task and interrupt context.
*
* @return The value read from <target>
*/
atomic_val_t rhino_atomic_get(const atomic_t *target)
{
return *target;
}
/**
* This routine atomically performs a bitwise OR operation of <*target>
* and <value>, placing the result in <*target>.
*
* This routine can be used from both task and interrupt context.
*
* @param target the memory location to be modified
* @param value the value to OR
*
* @return The previous value from <target>
*/
atomic_val_t rhino_atomic_or(atomic_t *target, atomic_val_t value)
{
CPSR_ALLOC();
atomic_val_t old_value;
RHINO_CPU_INTRPT_DISABLE();
old_value = *target;
*target |= value;
RHINO_CPU_INTRPT_ENABLE();
return old_value;
}
/**
* This routine atomically performs a bitwise XOR operation of <*target> and
* <value>, placing the result in <*target>.
*
* This routine can be used from both task and interrupt context.
*
* @param target the memory location to be modified
* @param value the value to XOR
*
* @return The previous value from <target>
*/
atomic_val_t rhino_atomic_xor(atomic_t *target, atomic_val_t value)
{
CPSR_ALLOC();
atomic_val_t old_value;
RHINO_CPU_INTRPT_DISABLE();
old_value = *target;
*target ^= value;
RHINO_CPU_INTRPT_ENABLE();
return old_value;
}
/**
* This routine atomically performs a bitwise AND operation of <*target> and
* <value>, placing the result in <*target>.
*
* This routine can be used from both task and interrupt context.
*
* @param target the memory location to be modified
* @param value the value to AND
*
* @return The previous value from <target>
*/
atomic_val_t rhino_atomic_and(atomic_t *target, atomic_val_t value)
{
CPSR_ALLOC();
atomic_val_t old_value;
RHINO_CPU_INTRPT_DISABLE();
old_value = *target;
*target &= value;
RHINO_CPU_INTRPT_ENABLE();
return old_value;
}
/**
* This routine atomically performs a bitwise NAND operation of <*target> and
* <value>, placing the result in <*target>.
*
* This routine can be used from both task and interrupt context.
*
* @param target the memory location to be modified
* @param value the value to NAND
*
* @return The previous value from <target>
*/
atomic_val_t rhino_atomic_nand(atomic_t *target, atomic_val_t value)
{
CPSR_ALLOC();
atomic_val_t old_value;
RHINO_CPU_INTRPT_DISABLE();
old_value = *target;
*target = ~(*target & value);
RHINO_CPU_INTRPT_ENABLE();
return old_value;
}
/**
* This routine provides the atomic clear operator. The value of 0 is atomically
* written at <target> and the previous value at <target> is returned.
*
* This routine can be used from both task and interrupt context.
*
* @param target the memory location to write
*
* @return The previous value from <target>
*/
atomic_val_t rhino_atomic_clear(atomic_t *target)
{
CPSR_ALLOC();
atomic_val_t old_value;
RHINO_CPU_INTRPT_DISABLE();
old_value = *target;
*target = 0;
RHINO_CPU_INTRPT_ENABLE();
return old_value;
}
/**
* This routine performs an atomic compare-and-swap, it test that whether
* <*target> equal to <oldValue>, and if TRUE, setting the value of <*target>
* to <newValue> and return 1.
*
* If the original value at <target> does not equal <oldValue>, then the target
* will not be updated and return 0.
*
* @param target address to be tested
* @param old_value value to compare against
* @param new_value value to compare against
* @return Returns 1 if <new_value> is written, 0 otherwise.
*/
int rhino_atomic_cas(atomic_t *target, atomic_val_t old_value,
atomic_val_t new_value)
{
CPSR_ALLOC();
int ret = 0;
RHINO_CPU_INTRPT_DISABLE();
if (*target == old_value)
{
*target = new_value;
ret = 1;
}
RHINO_CPU_INTRPT_ENABLE();
return ret;
}

View File

@@ -0,0 +1,40 @@
/*
* Copyright (C) 2017 Alibaba Group Holding Limited
*/
/*
modification history
--------------------
2017_12_27,WangMin(Rocky) created.
*/
#ifndef K_ATOMIC_H
#define K_ATOMIC_H
#ifdef __cplusplus
extern "C" {
#endif
typedef unsigned int atomic_t;
typedef atomic_t atomic_val_t;
extern atomic_val_t rhino_atomic_add(atomic_t *target, atomic_val_t value);
extern atomic_val_t rhino_atomic_sub(atomic_t *target, atomic_val_t value);
extern atomic_val_t rhino_atomic_inc(atomic_t *target);
extern atomic_val_t rhino_atomic_dec(atomic_t *target);
extern atomic_val_t rhino_atomic_set(atomic_t *target, atomic_val_t value);
extern atomic_val_t rhino_atomic_get(const atomic_t *target);
extern atomic_val_t rhino_atomic_or(atomic_t *target, atomic_val_t value);
extern atomic_val_t rhino_atomic_xor(atomic_t *target, atomic_val_t value);
extern atomic_val_t rhino_atomic_and(atomic_t *target, atomic_val_t value);
extern atomic_val_t rhino_atomic_nand(atomic_t *target, atomic_val_t value);
extern atomic_val_t rhino_atomic_clear(atomic_t *target);
extern int rhino_atomic_cas(atomic_t *target, atomic_val_t old_value,
atomic_val_t new_value);
#ifdef __cplusplus
}
#endif
#endif /* K_ATOMIC_H */

View File

@@ -0,0 +1,47 @@
/*
* Copyright (C) 2018 Alibaba Group Holding Limited
*/
/*
modification history
--------------------
21jan2018,WangMin writen.
*/
/*
DESCRIPTION
This file provides base type of cpu set and method for cpu set.
*/
#ifndef __cpuset_h__
#define __cpuset_h__
#include "k_atomic.h"
#ifdef __cplusplus
extern "C" {
#endif
/* typedefs */
typedef unsigned int cpuset_t;
#define CPUSET_ATOMIC_SET(cpuset, n) \
(void) rhino_atomic_or ((atomic_t *) &(cpuset), 1 << (n))
#define CPUSET_ATOMIC_CLR(cpuset, n) \
(void) rhino_atomic_and ((atomic_t *) &(cpuset), ~((1 << (n))))
#define CPUSET_ATOMIC_COPY(cpusetDst, cpusetSrc) \
(void) rhino_atomic_set ((atomic_t *) &(cpusetDst), (atomic_t) (cpusetSrc))
#define CPUSET_CLR(cpuset, n) ((cpuset) &= ~(1 << (n)))
#define CPUSET_ZERO(cpuset) ((cpuset) = 0)
#define CPUSET_IS_ZERO(cpuset) ((cpuset) == 0)
#define CPUSET_SET(cpuset, n) ((cpuset) |= (1 << (n)))
#define CPUSET_ISSET(cpuset, n) ((cpuset) & (1 << (n)))
#ifdef __cplusplus
}
#endif
#endif /* __cpuset_h__ */

View File

@@ -0,0 +1,45 @@
/*
* Copyright (C) 2018 Alibaba Group Holding Limited
*/
/*
DESCRIPTION
This file provides method to find the least/most significant bit in 32 bit
fields.
*/
#include "k_api.h"
#include "k_ffs.h"
#include "k_bitmap.h"
/* find most significant bit set */
int ffs32_msb(uint32_t bitmap)
{
if (bitmap == 0)
{
return 0;
}
return 32 - krhino_find_first_bit(&bitmap);
}
/* find least significant bit set */
int ffs32_lsb(uint32_t bitmap)
{
uint32_t x;
int lsbit;
if (bitmap == 0)
{
return 0;
}
x = bitmap & -bitmap;
lsbit = krhino_find_first_bit((uint32_t *)(&x));
return 32 - lsbit;
}

View File

@@ -0,0 +1,25 @@
/*
* Copyright (C) 2018 Alibaba Group Holding Limited
*/
#ifndef __k_ffs_h__
#define __k_ffs_h__
#ifdef __cplusplus
extern "C" {
#endif
/* function declarations */
extern int ffs32_lsb (uint32_t i);
extern int ffs32_msb (uint32_t i);
#define FFS_LSB(i) ffs32_lsb(i)
#define FFS_MSB(i) ffs32_msb(i)
#ifdef __cplusplus
}
#endif
#endif /* __k_ffs_h__ */

View File

@@ -0,0 +1,177 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#include <k_api.h>
/*
* internal helper to calculate the unused elements in a fifo
*/
static uint32_t fifo_unused(struct k_fifo *fifo)
{
return (fifo->mask + 1) - (fifo->in - fifo->out);
}
static int8_t is_power_of_2(uint32_t n)
{
return (n != 0 && ((n & (n - 1)) == 0));
}
int8_t fifo_init(struct k_fifo *fifo, void *buffer, uint32_t size)
{
/*
* round down to the next power of 2, since our 'let the indices
* wrap' technique works only in this case.
*/
if (!is_power_of_2(size)) {
return 1;
}
fifo->in = 0;
fifo->out = 0;
fifo->data = buffer;
if (size < 2) {
fifo->mask = 0;
return 1;
}
fifo->mask = size - 1;
fifo->free_bytes = size;
fifo->size = size;
return 0;
}
static void fifo_copy_in(struct k_fifo *fifo, const void *src,
uint32_t len, uint32_t off)
{
uint32_t l;
uint32_t size = fifo->mask + 1;
off &= fifo->mask;
l = fifo_min(len, size - off);
memcpy((unsigned char *)fifo->data + off, src, l);
memcpy(fifo->data, (unsigned char *)src + l, len - l);
}
uint32_t fifo_in(struct k_fifo *fifo, const void *buf, uint32_t len)
{
uint32_t l;
CPSR_ALLOC();
RHINO_CRITICAL_ENTER();
l = fifo_unused(fifo);
if (len > l) {
len = l;
}
fifo_copy_in(fifo, buf, len, fifo->in);
fifo->in += len;
fifo->free_bytes -= len;
RHINO_CRITICAL_EXIT();
return len;
}
static void kfifo_copy_out(struct k_fifo *fifo, void *dst,
uint32_t len, uint32_t off)
{
uint32_t l;
uint32_t size = fifo->mask + 1;
off &= fifo->mask;
l = fifo_min(len, size - off);
memcpy(dst, (unsigned char *)fifo->data + off, l);
memcpy((unsigned char *)dst + l, fifo->data, len - l);
}
static uint32_t internal_fifo_out_peek(struct k_fifo *fifo,
void *buf, uint32_t len)
{
uint32_t l;
l = fifo->in - fifo->out;
if (len > l) {
len = l;
}
kfifo_copy_out(fifo, buf, len, fifo->out);
return len;
}
uint32_t fifo_out_peek(struct k_fifo *fifo,
void *buf, uint32_t len)
{
uint32_t ret_len;
CPSR_ALLOC();
RHINO_CRITICAL_ENTER();
ret_len = internal_fifo_out_peek(fifo, buf, len);
RHINO_CRITICAL_EXIT();
return ret_len;
}
uint32_t fifo_out(struct k_fifo *fifo, void *buf, uint32_t len)
{
CPSR_ALLOC();
RHINO_CRITICAL_ENTER();
len = internal_fifo_out_peek(fifo, buf, len);
fifo->out += len;
fifo->free_bytes += len;
RHINO_CRITICAL_EXIT();
return len;
}
uint32_t fifo_out_all(struct k_fifo *fifo, void *buf)
{
uint32_t len;
CPSR_ALLOC();
RHINO_CRITICAL_ENTER();
len = fifo->size - fifo->free_bytes;
if (len == 0) {
RHINO_CRITICAL_EXIT();
return 0;
}
len = internal_fifo_out_peek(fifo, buf, len);
fifo->out += len;
fifo->free_bytes += len;
RHINO_CRITICAL_EXIT();
return len;
}

File diff suppressed because it is too large Load Diff