forked from PAWPAW-Mirror/lib_xua
Added hardware locks
This commit is contained in:
@@ -9,6 +9,7 @@
|
|||||||
#include "descriptor_defs.h"
|
#include "descriptor_defs.h"
|
||||||
#include "xua_hid_report.h"
|
#include "xua_hid_report.h"
|
||||||
#include "hid_report_descriptor.h"
|
#include "hid_report_descriptor.h"
|
||||||
|
#include "hwlock.h"
|
||||||
|
|
||||||
|
|
||||||
#define HID_REPORT_ITEM_LOCATION_SIZE ( 1 )
|
#define HID_REPORT_ITEM_LOCATION_SIZE ( 1 )
|
||||||
@@ -18,6 +19,9 @@
|
|||||||
/*
|
/*
|
||||||
* Each element in s_hidChangePending corresponds to an element in hidReports.
|
* Each element in s_hidChangePending corresponds to an element in hidReports.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
hwlock_t hidStaticVarLock = hwlock_alloc();
|
||||||
|
|
||||||
static unsigned s_hidChangePending[ HID_REPORT_COUNT ];
|
static unsigned s_hidChangePending[ HID_REPORT_COUNT ];
|
||||||
static unsigned char s_hidReportDescriptor[ HID_REPORT_DESCRIPTOR_MAX_LENGTH ];
|
static unsigned char s_hidReportDescriptor[ HID_REPORT_DESCRIPTOR_MAX_LENGTH ];
|
||||||
static size_t s_hidReportDescriptorLength;
|
static size_t s_hidReportDescriptorLength;
|
||||||
@@ -134,30 +138,36 @@ static size_t hidTranslateItem( const USB_HID_Short_Item_t* inPtr, unsigned char
|
|||||||
|
|
||||||
void hidCalcNextReportTime( const unsigned id )
|
void hidCalcNextReportTime( const unsigned id )
|
||||||
{
|
{
|
||||||
|
hwlock_acquire(hidStaticVarLock);
|
||||||
for( size_t idx = 0U; idx < HID_REPORT_COUNT; ++idx ) {
|
for( size_t idx = 0U; idx < HID_REPORT_COUNT; ++idx ) {
|
||||||
if( id == hidGetElementReportId( hidReports[ idx ]->location )) {
|
if( id == hidGetElementReportId( hidReports[ idx ]->location )) {
|
||||||
s_hidNextReportTime[ idx ] = s_hidReportTime[ idx ] + s_hidCurrentPeriod[ idx ];
|
s_hidNextReportTime[ idx ] = s_hidReportTime[ idx ] + s_hidCurrentPeriod[ idx ];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
hwlock_release(hidStaticVarLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void hidCaptureReportTime( const unsigned id, const unsigned time )
|
void hidCaptureReportTime( const unsigned id, const unsigned time )
|
||||||
{
|
{
|
||||||
|
hwlock_acquire(hidStaticVarLock);
|
||||||
for( size_t idx = 0U; idx < HID_REPORT_COUNT; ++idx ) {
|
for( size_t idx = 0U; idx < HID_REPORT_COUNT; ++idx ) {
|
||||||
if( id == hidGetElementReportId( hidReports[ idx ]->location )) {
|
if( id == hidGetElementReportId( hidReports[ idx ]->location )) {
|
||||||
s_hidReportTime[ idx ] = time;
|
s_hidReportTime[ idx ] = time;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
hwlock_release(hidStaticVarLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void hidClearChangePending( const unsigned id )
|
void hidClearChangePending( const unsigned id )
|
||||||
{
|
{
|
||||||
|
hwlock_acquire(hidStaticVarLock);
|
||||||
for( size_t idx = 0U; idx < HID_REPORT_COUNT; ++idx) {
|
for( size_t idx = 0U; idx < HID_REPORT_COUNT; ++idx) {
|
||||||
if(( id == 0U ) || ( id == hidGetElementReportId( hidReports[ idx ]->location ))) {
|
if(( id == 0U ) || ( id == hidGetElementReportId( hidReports[ idx ]->location ))) {
|
||||||
s_hidChangePending[ idx ] = 0U;
|
s_hidChangePending[ idx ] = 0U;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
hwlock_release(hidStaticVarLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned hidGetElementBitLocation( const unsigned short location )
|
static unsigned hidGetElementBitLocation( const unsigned short location )
|
||||||
@@ -202,7 +212,9 @@ static unsigned hidGetItemType( const unsigned char header )
|
|||||||
return bType;
|
return bType;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned hidGetNextReportTime( const unsigned id ) {
|
unsigned hidGetNextReportTime( const unsigned id )
|
||||||
|
{
|
||||||
|
hwlock_acquire(hidStaticVarLock);
|
||||||
unsigned retVal = 0U;
|
unsigned retVal = 0U;
|
||||||
|
|
||||||
for( size_t idx = 0U; idx < HID_REPORT_COUNT; ++idx ) {
|
for( size_t idx = 0U; idx < HID_REPORT_COUNT; ++idx ) {
|
||||||
@@ -210,28 +222,35 @@ unsigned hidGetNextReportTime( const unsigned id ) {
|
|||||||
retVal = s_hidNextReportTime[ idx ];
|
retVal = s_hidNextReportTime[ idx ];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
hwlock_release(hidStaticVarLock);
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned hidIsReportDescriptorPrepared( void )
|
unsigned hidIsReportDescriptorPrepared( void )
|
||||||
{
|
{
|
||||||
|
hwlock_acquire(hidStaticVarLock);
|
||||||
return s_hidReportDescriptorPrepared;
|
return s_hidReportDescriptorPrepared;
|
||||||
|
hwlock_release(hidStaticVarLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char* hidGetReportDescriptor( void )
|
unsigned char* hidGetReportDescriptor( void )
|
||||||
{
|
{
|
||||||
unsigned char* retVal = NULL;
|
unsigned char* retVal = NULL;
|
||||||
|
hwlock_acquire(hidStaticVarLock);
|
||||||
|
|
||||||
if( s_hidReportDescriptorPrepared ) {
|
if( s_hidReportDescriptorPrepared ) {
|
||||||
retVal = s_hidReportDescriptor;
|
retVal = s_hidReportDescriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hwlock_release(hidStaticVarLock);
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t hidGetReportDescriptorLength( void )
|
size_t hidGetReportDescriptorLength( void )
|
||||||
{
|
{
|
||||||
|
hwlock_acquire(hidStaticVarLock);
|
||||||
size_t retVal = ( s_hidReportDescriptorPrepared ) ? s_hidReportDescriptorLength : 0U;
|
size_t retVal = ( s_hidReportDescriptorPrepared ) ? s_hidReportDescriptorLength : 0U;
|
||||||
|
hwlock_release(hidStaticVarLock);
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -320,6 +339,7 @@ unsigned hidGetReportItem(
|
|||||||
|
|
||||||
size_t hidGetReportLength( const unsigned id )
|
size_t hidGetReportLength( const unsigned id )
|
||||||
{
|
{
|
||||||
|
hwlock_acquire(hidStaticVarLock);
|
||||||
size_t retVal = 0U;
|
size_t retVal = 0U;
|
||||||
if( s_hidReportDescriptorPrepared ) {
|
if( s_hidReportDescriptorPrepared ) {
|
||||||
for( size_t idx = 0U; idx < HID_REPORT_COUNT; ++idx ) {
|
for( size_t idx = 0U; idx < HID_REPORT_COUNT; ++idx ) {
|
||||||
@@ -328,11 +348,13 @@ size_t hidGetReportLength( const unsigned id )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
hwlock_release(hidStaticVarLock);
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned hidGetReportPeriod( const unsigned id )
|
unsigned hidGetReportPeriod( const unsigned id )
|
||||||
{
|
{
|
||||||
|
hwlock_acquire(hidStaticVarLock);
|
||||||
unsigned retVal = 0U;
|
unsigned retVal = 0U;
|
||||||
for( size_t idx = 0U; idx < HID_REPORT_COUNT; ++idx) {
|
for( size_t idx = 0U; idx < HID_REPORT_COUNT; ++idx) {
|
||||||
if( id == hidGetElementReportId( hidReports[ idx ]->location )) {
|
if( id == hidGetElementReportId( hidReports[ idx ]->location )) {
|
||||||
@@ -340,10 +362,13 @@ unsigned hidGetReportPeriod( const unsigned id )
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
hwlock_release(hidStaticVarLock);
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned hidGetReportTime( const unsigned id ) {
|
unsigned hidGetReportTime( const unsigned id )
|
||||||
|
{
|
||||||
|
hwlock_acquire(hidStaticVarLock);
|
||||||
unsigned retVal = 0U;
|
unsigned retVal = 0U;
|
||||||
|
|
||||||
for( size_t idx = 0U; idx < HID_REPORT_COUNT; ++idx ) {
|
for( size_t idx = 0U; idx < HID_REPORT_COUNT; ++idx ) {
|
||||||
@@ -351,6 +376,7 @@ unsigned hidGetReportTime( const unsigned id ) {
|
|||||||
retVal = s_hidReportTime[ idx ];
|
retVal = s_hidReportTime[ idx ];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
hwlock_release(hidStaticVarLock);
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -368,6 +394,7 @@ static unsigned hidGetUsagePage( const unsigned id )
|
|||||||
|
|
||||||
unsigned hidIsChangePending( const unsigned id )
|
unsigned hidIsChangePending( const unsigned id )
|
||||||
{
|
{
|
||||||
|
hwlock_acquire(hidStaticVarLock);
|
||||||
unsigned retVal = 0U;
|
unsigned retVal = 0U;
|
||||||
for( size_t idx = 0U; idx < HID_REPORT_COUNT; ++idx) {
|
for( size_t idx = 0U; idx < HID_REPORT_COUNT; ++idx) {
|
||||||
if( id == 0U && s_hidChangePending[ idx ] != 0U ) {
|
if( id == 0U && s_hidChangePending[ idx ] != 0U ) {
|
||||||
@@ -377,11 +404,13 @@ unsigned hidIsChangePending( const unsigned id )
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
hwlock_release(hidStaticVarLock);
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned hidIsIdleActive( const unsigned id )
|
unsigned hidIsIdleActive( const unsigned id )
|
||||||
{
|
{
|
||||||
|
hwlock_acquire(hidStaticVarLock);
|
||||||
unsigned retVal = 0U;
|
unsigned retVal = 0U;
|
||||||
if( 0U == id ) {
|
if( 0U == id ) {
|
||||||
retVal = 1U;
|
retVal = 1U;
|
||||||
@@ -395,11 +424,13 @@ unsigned hidIsIdleActive( const unsigned id )
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
hwlock_release(hidStaticVarLock);
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
void hidPrepareReportDescriptor( void )
|
void hidPrepareReportDescriptor( void )
|
||||||
{
|
{
|
||||||
|
hwlock_acquire(hidStaticVarLock);
|
||||||
if( !s_hidReportDescriptorPrepared ) {
|
if( !s_hidReportDescriptorPrepared ) {
|
||||||
s_hidReportDescriptorLength = 0U;
|
s_hidReportDescriptorLength = 0U;
|
||||||
unsigned char* ptr = s_hidReportDescriptor;
|
unsigned char* ptr = s_hidReportDescriptor;
|
||||||
@@ -410,49 +441,60 @@ void hidPrepareReportDescriptor( void )
|
|||||||
|
|
||||||
s_hidReportDescriptorPrepared = 1U;
|
s_hidReportDescriptorPrepared = 1U;
|
||||||
}
|
}
|
||||||
|
hwlock_release(hidStaticVarLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void hidReportInit( void )
|
void hidReportInit( void )
|
||||||
{
|
{
|
||||||
|
hwlock_acquire(hidStaticVarLock);
|
||||||
for( unsigned idx = 0U; idx < HID_REPORT_COUNT; ++idx ) {
|
for( unsigned idx = 0U; idx < HID_REPORT_COUNT; ++idx ) {
|
||||||
s_hidCurrentPeriod[ idx ] = ENDPOINT_INT_INTERVAL_IN_HID * MS_IN_TICKS;
|
s_hidCurrentPeriod[ idx ] = ENDPOINT_INT_INTERVAL_IN_HID * MS_IN_TICKS;
|
||||||
}
|
}
|
||||||
memset( s_hidIdleActive, 0, sizeof( s_hidIdleActive ) );
|
memset( s_hidIdleActive, 0, sizeof( s_hidIdleActive ) );
|
||||||
memset( s_hidChangePending, 0, sizeof( s_hidChangePending ) );
|
memset( s_hidChangePending, 0, sizeof( s_hidChangePending ) );
|
||||||
|
hwlock_release(hidStaticVarLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void hidResetReportDescriptor( void )
|
void hidResetReportDescriptor( void )
|
||||||
{
|
{
|
||||||
|
hwlock_acquire(hidStaticVarLock);
|
||||||
s_hidReportDescriptorPrepared = 0U;
|
s_hidReportDescriptorPrepared = 0U;
|
||||||
|
hwlock_release(hidStaticVarLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void hidSetChangePending( const unsigned id )
|
void hidSetChangePending( const unsigned id )
|
||||||
{
|
{
|
||||||
|
hwlock_acquire(hidStaticVarLock);
|
||||||
for( size_t idx = 0U; idx < HID_REPORT_COUNT; ++idx) {
|
for( size_t idx = 0U; idx < HID_REPORT_COUNT; ++idx) {
|
||||||
if( id == hidGetElementReportId( hidReports[ idx ]->location )) {
|
if( id == hidGetElementReportId( hidReports[ idx ]->location )) {
|
||||||
s_hidChangePending[ idx ] = 1U;
|
s_hidChangePending[ idx ] = 1U;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
hwlock_release(hidStaticVarLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void hidSetIdle( const unsigned id, const unsigned state )
|
void hidSetIdle( const unsigned id, const unsigned state )
|
||||||
{
|
{
|
||||||
|
hwlock_acquire(hidStaticVarLock);
|
||||||
for( size_t idx = 0U; idx < HID_REPORT_COUNT; ++idx) {
|
for( size_t idx = 0U; idx < HID_REPORT_COUNT; ++idx) {
|
||||||
if( id == hidGetElementReportId( hidReports[ idx ]->location )) {
|
if( id == hidGetElementReportId( hidReports[ idx ]->location )) {
|
||||||
s_hidIdleActive[ idx ] = ( state != 0U );
|
s_hidIdleActive[ idx ] = ( state != 0U );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
hwlock_release(hidStaticVarLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void hidSetNextReportTime( const unsigned id, const unsigned time )
|
void hidSetNextReportTime( const unsigned id, const unsigned time )
|
||||||
{
|
{
|
||||||
|
hwlock_acquire(hidStaticVarLock);
|
||||||
for( size_t idx = 0U; idx < HID_REPORT_COUNT; ++idx ) {
|
for( size_t idx = 0U; idx < HID_REPORT_COUNT; ++idx ) {
|
||||||
if( id == hidGetElementReportId( hidReports[ idx ]->location )) {
|
if( id == hidGetElementReportId( hidReports[ idx ]->location )) {
|
||||||
s_hidNextReportTime[ idx ] = time;
|
s_hidNextReportTime[ idx ] = time;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
hwlock_release(hidStaticVarLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned hidSetReportItem(
|
unsigned hidSetReportItem(
|
||||||
@@ -464,6 +506,7 @@ unsigned hidSetReportItem(
|
|||||||
const unsigned char data[]
|
const unsigned char data[]
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
hwlock_acquire(hidStaticVarLock);
|
||||||
unsigned retVal = HID_STATUS_IN_USE;
|
unsigned retVal = HID_STATUS_IN_USE;
|
||||||
|
|
||||||
if( !s_hidReportDescriptorPrepared ) {
|
if( !s_hidReportDescriptorPrepared ) {
|
||||||
@@ -511,17 +554,20 @@ unsigned hidSetReportItem(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hwlock_release(hidStaticVarLock);
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
void hidSetReportPeriod( const unsigned id, const unsigned period )
|
void hidSetReportPeriod( const unsigned id, const unsigned period )
|
||||||
{
|
{
|
||||||
|
hwlock_acquire(hidStaticVarLock);
|
||||||
for( size_t idx = 0U; idx < HID_REPORT_COUNT; ++idx) {
|
for( size_t idx = 0U; idx < HID_REPORT_COUNT; ++idx) {
|
||||||
if( id == hidGetElementReportId( hidReports[ idx ]->location )) {
|
if( id == hidGetElementReportId( hidReports[ idx ]->location )) {
|
||||||
s_hidCurrentPeriod[ idx ] = period;
|
s_hidCurrentPeriod[ idx ] = period;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
hwlock_release(hidStaticVarLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t hidTranslateItem( const USB_HID_Short_Item_t* inPtr, unsigned char** outPtrPtr )
|
static size_t hidTranslateItem( const USB_HID_Short_Item_t* inPtr, unsigned char** outPtrPtr )
|
||||||
|
|||||||
Reference in New Issue
Block a user