surenyi
3 weeks ago
11 changed files with 1204 additions and 536 deletions
@ -0,0 +1,127 @@ |
|||
# SPDX-License-Identifier: GPL-2.0 |
|||
# |
|||
# clang-format configuration file. Intended for clang-format >= 11. |
|||
# |
|||
# For more information, see: |
|||
# |
|||
# Documentation/process/clang-format.rst |
|||
# https://clang.llvm.org/docs/ClangFormat.html |
|||
# https://clang.llvm.org/docs/ClangFormatStyleOptions.html |
|||
# |
|||
# :lua vim.lsp.buf.format({timeout=2000}) |
|||
--- |
|||
AccessModifierOffset: -4 |
|||
AlignAfterOpenBracket: Align |
|||
AlignConsecutiveAssignments: false |
|||
AlignConsecutiveDeclarations: false |
|||
AlignEscapedNewlines: Left |
|||
AlignOperands: true |
|||
AlignTrailingComments: false |
|||
AllowAllParametersOfDeclarationOnNextLine: false |
|||
AllowShortBlocksOnASingleLine: false |
|||
AllowShortCaseLabelsOnASingleLine: false |
|||
AllowShortFunctionsOnASingleLine: None |
|||
AllowShortIfStatementsOnASingleLine: false |
|||
AllowShortLoopsOnASingleLine: false |
|||
AlwaysBreakAfterDefinitionReturnType: None |
|||
AlwaysBreakAfterReturnType: None |
|||
AlwaysBreakBeforeMultilineStrings: false |
|||
AlwaysBreakTemplateDeclarations: false |
|||
BinPackArguments: true |
|||
BinPackParameters: true |
|||
BraceWrapping: |
|||
AfterClass: false |
|||
AfterControlStatement: false |
|||
AfterEnum: false |
|||
AfterFunction: true |
|||
AfterNamespace: true |
|||
AfterObjCDeclaration: false |
|||
AfterStruct: false |
|||
AfterUnion: false |
|||
AfterExternBlock: false |
|||
BeforeCatch: false |
|||
BeforeElse: false |
|||
IndentBraces: false |
|||
SplitEmptyFunction: true |
|||
SplitEmptyRecord: true |
|||
SplitEmptyNamespace: true |
|||
BreakBeforeBinaryOperators: None |
|||
BreakBeforeBraces: Custom |
|||
BreakBeforeInheritanceComma: false |
|||
BreakBeforeTernaryOperators: false |
|||
BreakConstructorInitializersBeforeComma: false |
|||
BreakConstructorInitializers: BeforeComma |
|||
BreakAfterJavaFieldAnnotations: false |
|||
BreakStringLiterals: false |
|||
ColumnLimit: 80 |
|||
CommentPragmas: '^ IWYU pragma:' |
|||
CompactNamespaces: false |
|||
ConstructorInitializerAllOnOneLineOrOnePerLine: false |
|||
ConstructorInitializerIndentWidth: 4 |
|||
ContinuationIndentWidth: 4 |
|||
Cpp11BracedListStyle: false |
|||
DerivePointerAlignment: false |
|||
DisableFormat: false |
|||
ExperimentalAutoDetectBinPacking: false |
|||
FixNamespaceComments: false |
|||
|
|||
# Taken from: |
|||
# git grep -h '^#define [^[:space:]]*for_each[^[:space:]]*(' include/ tools/ \ |
|||
# | sed "s,^#define \([^[:space:]]*for_each[^[:space:]]*\)(.*$, - '\1'," \ |
|||
# | LC_ALL=C sort -u |
|||
ForEachMacros: |
|||
- 'list_for_each' |
|||
|
|||
IncludeBlocks: Preserve |
|||
IncludeCategories: |
|||
- Regex: '.*' |
|||
Priority: 1 |
|||
IncludeIsMainRegex: '(Test)?$' |
|||
IndentCaseLabels: false |
|||
IndentGotoLabels: false |
|||
IndentPPDirectives: None |
|||
IndentWidth: 4 |
|||
IndentWrappedFunctionNames: false |
|||
JavaScriptQuotes: Leave |
|||
JavaScriptWrapImports: true |
|||
KeepEmptyLinesAtTheStartOfBlocks: false |
|||
MacroBlockBegin: '' |
|||
MacroBlockEnd: '' |
|||
MaxEmptyLinesToKeep: 1 |
|||
NamespaceIndentation: None |
|||
ObjCBinPackProtocolList: Auto |
|||
ObjCBlockIndentWidth: 4 |
|||
ObjCSpaceAfterProperty: true |
|||
ObjCSpaceBeforeProtocolList: true |
|||
|
|||
# Taken from git's rules |
|||
PenaltyBreakAssignment: 10 |
|||
PenaltyBreakBeforeFirstCallParameter: 30 |
|||
PenaltyBreakComment: 10 |
|||
PenaltyBreakFirstLessLess: 0 |
|||
PenaltyBreakString: 10 |
|||
PenaltyExcessCharacter: 100 |
|||
PenaltyReturnTypeOnItsOwnLine: 60 |
|||
|
|||
PointerAlignment: Right |
|||
ReflowComments: false |
|||
SortIncludes: false |
|||
SortUsingDeclarations: false |
|||
SpaceAfterCStyleCast: false |
|||
SpaceAfterTemplateKeyword: true |
|||
SpaceBeforeAssignmentOperators: true |
|||
SpaceBeforeCtorInitializerColon: true |
|||
SpaceBeforeInheritanceColon: true |
|||
SpaceBeforeParens: ControlStatementsExceptForEachMacros |
|||
SpaceBeforeRangeBasedForLoopColon: true |
|||
SpaceInEmptyParentheses: false |
|||
SpacesBeforeTrailingComments: 1 |
|||
SpacesInAngles: false |
|||
SpacesInContainerLiterals: false |
|||
SpacesInCStyleCastParentheses: false |
|||
SpacesInParentheses: false |
|||
SpacesInSquareBrackets: false |
|||
Standard: Cpp03 |
|||
TabWidth: 4 |
|||
UseTab: Never |
|||
... |
@ -0,0 +1,20 @@ |
|||
/* 40vxbSm2310SpiDev.cdf - Component configuration file */ |
|||
|
|||
/* |
|||
* modification history |
|||
* -------------------- |
|||
* 2024-10-16: surenyi written. |
|||
*/ |
|||
|
|||
Component DRV_SPIDEV_SM2130 { |
|||
NAME State Micro SM2130 SPI 1553B vxBus Driver |
|||
SYNOPSIS This enables access to SM2310 1553B protocol chip |
|||
INIT_RTN vxbSm2130SpiDevRegister(); |
|||
PROTOTYPE void vxbSm2130SpiDevRegister (void); |
|||
_INIT_ORDER hardWareInterFaceBusInit |
|||
INIT_AFTER INCLUDE_SPI_BUS |
|||
REQUIRES INCLUDE_VXBUS \ |
|||
INCLUDE_PLB_BUS \ |
|||
INCLUDE_SPI_BUS |
|||
_CHILDREN FOLDER_DRIVERS |
|||
} |
@ -0,0 +1,302 @@ |
|||
#include <vxWorks.h> |
|||
#include <stdio.h> |
|||
#include <string.h> |
|||
#include <logLib.h> |
|||
#include <vxBusLib.h> |
|||
#include <semLib.h> |
|||
#include <taskLib.h> |
|||
#include <sysLib.h> |
|||
#include <tickLib.h> |
|||
#include <hwif/vxbus/vxBus.h> |
|||
#include <hwif/vxbus/hwConf.h> |
|||
#include <hwif/vxbus/vxbPlbLib.h> |
|||
#include <hwif/util/hwMemLib.h> |
|||
#include <hwif/util/vxbParamSys.h> |
|||
|
|||
#include <hwif/vxbus/vxbSpiLib.h> |
|||
#include "vxbSm2130SpiDev.h" |
|||
#include <usrLib.h> |
|||
|
|||
/* locals */ |
|||
LOCAL void sm2130SpiDevShow(VXB_DEVICE_ID pDev, int verbose); |
|||
LOCAL INT32 spiDevRead(VXB_DEVICE_ID pDev, UINT8 cmd); |
|||
LOCAL STATUS spiDevWrite(VXB_DEVICE_ID pDev, UINT8 cmd, UINT16 var); |
|||
|
|||
/* VxBus methods */ |
|||
LOCAL void sm2130SpiDevInstInit(VXB_DEVICE_ID pDev); |
|||
LOCAL void sm2130SpiDevInstInit2(VXB_DEVICE_ID pDev); |
|||
LOCAL void sm2130SpiDevInstConnect(VXB_DEVICE_ID pDev); |
|||
LOCAL STATUS sm2130SpiDevInstUnlink(VXB_DEVICE_ID pDev, void *unused); |
|||
|
|||
/* Structs */ |
|||
|
|||
LOCAL struct drvBusFuncs sm2130SpiDevFuncs = { |
|||
sm2130SpiDevInstInit, /* devInstanceInit */ |
|||
sm2130SpiDevInstInit2, /* devInstanceInit2 */ |
|||
sm2130SpiDevInstConnect /* devConnect */ |
|||
}; |
|||
|
|||
/* Publish the methods for the resources controlled with this file */ |
|||
|
|||
LOCAL struct vxbDeviceMethod sm2130SpiDevMethods[] = { |
|||
DEVMETHOD(busDevShow, sm2130SpiDevShow), |
|||
DEVMETHOD(vxbDrvUnlink, sm2130SpiDevInstUnlink), |
|||
{ 0, 0 } |
|||
}; |
|||
|
|||
LOCAL struct vxbSpiRegister sm2130SpiDevRegister = { |
|||
{ |
|||
NULL, /* pNext */ |
|||
VXB_DEVID_DEVICE, /* devID */ |
|||
VXB_BUSID_SPI, /* busID = SPI */ |
|||
VXB_VER_4_0_0, /* vxbVersion */ |
|||
SPI_DEV_SM2130, /* drvName */ |
|||
&sm2130SpiDevFuncs, /* pDrvBusFuncs */ |
|||
sm2130SpiDevMethods, /* pMethods */ |
|||
NULL, //sm2130Probe, /* devProbe */
|
|||
NULL, /* pParamDefaults */ |
|||
}, |
|||
}; |
|||
/*
|
|||
* |
|||
* vxbSm2130SpiDevRegister - register with the VxBus subsystem |
|||
* |
|||
* This routine registers the driver to VxBus Systems. |
|||
* |
|||
* RETURNS: N/A |
|||
* |
|||
* ERRNO: N/A |
|||
* |
|||
* \NOMANUAL |
|||
*/ |
|||
void vxbSm2130SpiDevRegister(void) |
|||
{ |
|||
(void)vxbDevRegister((struct vxbDevRegInfo *)&sm2130SpiDevRegister); |
|||
} |
|||
|
|||
/*
|
|||
* |
|||
* sm2130SpiDevInstInit - first level initialization routine of spi flash device |
|||
* |
|||
* RETURNS: N/A |
|||
* |
|||
* ERRNO: N/A |
|||
*/ |
|||
LOCAL void sm2130SpiDevInstInit(VXB_DEVICE_ID pDev) |
|||
{ |
|||
SM2130_SPI_DEV *pDrvCtrl; |
|||
|
|||
/* Check for vaild parameter */ |
|||
VXB_ASSERT_NONNULL_V(pDev); |
|||
|
|||
pDrvCtrl = (SM2130_SPI_DEV *)hwMemAlloc(sizeof(SM2130_SPI_DEV)); |
|||
if (pDrvCtrl == NULL) { |
|||
return; |
|||
} |
|||
|
|||
pDrvCtrl->pDev = pDev; |
|||
pDev->pDrvCtrl = pDrvCtrl; |
|||
|
|||
pDrvCtrl->read = spiDevRead; |
|||
pDrvCtrl->write = spiDevWrite; |
|||
|
|||
vxbNextUnitGet(pDev); |
|||
} |
|||
|
|||
/*
|
|||
* |
|||
* sm2130SpiDevInstInit2 - first level initialization routine of spi flash device |
|||
* |
|||
* |
|||
* RETURNS: N/A |
|||
* |
|||
* ERRNO: N/A |
|||
*/ |
|||
LOCAL void sm2130SpiDevInstInit2(VXB_DEVICE_ID pDev) |
|||
{ |
|||
SM2130_SPI_DEV *pDrvCtrl; |
|||
FUNCPTR pFunc; |
|||
|
|||
/* Check for vaild parameter */ |
|||
VXB_ASSERT_NONNULL_V(pDev); |
|||
|
|||
pDrvCtrl = (SM2130_SPI_DEV *)pDev->pDrvCtrl; |
|||
|
|||
/* Mutex semaphore is initialized and necessary at this point */ |
|||
pDrvCtrl->muteSem = semMCreate(SPI_DEV_MUTEX_OPT); |
|||
|
|||
pFunc = vxbDevMethodGet(vxbDevParent(pDev), |
|||
(VXB_METHOD_ID)vxbSpiSpecialGet_desc); |
|||
|
|||
/* Retrieve the SPI master special information */ |
|||
if (pFunc != NULL) |
|||
(*pFunc)(vxbDevParent(pDev), &pDrvCtrl->specialInfo); |
|||
} |
|||
|
|||
/*
|
|||
* sm2130SpiDevInstConnect - third level initialization routine of spi flash |
|||
* |
|||
* This function implements the VxBus instConnect handler for a SPI Flash |
|||
* device instance. |
|||
* |
|||
* RETURNS: N/A |
|||
* |
|||
* ERRNO: N/A |
|||
*/ |
|||
LOCAL void sm2130SpiDevInstConnect(VXB_DEVICE_ID pDev) |
|||
{ |
|||
SM2130_SPI_DEV *pDrvCtrl; |
|||
|
|||
/* Check for vaild parameter */ |
|||
VXB_ASSERT_NONNULL_V(pDev); |
|||
|
|||
pDrvCtrl = (SM2130_SPI_DEV *)pDev->pDrvCtrl; |
|||
} |
|||
|
|||
/*
|
|||
* sm2130SpiDevInstUnlink - VxBus unlink handler |
|||
* |
|||
* This function shuts down a SPI Flash device instance in response to an |
|||
* unlink event from VxBus. This may occur if our VxBus instance has been |
|||
* terminated, or if the driver has been unloaded. |
|||
* |
|||
* RETURNS: OK always. |
|||
* |
|||
* ERRNO: N/A |
|||
*/ |
|||
LOCAL STATUS sm2130SpiDevInstUnlink(VXB_DEVICE_ID pDev, void *unused) |
|||
{ |
|||
SM2130_SPI_DEV *pDrvCtrl; |
|||
|
|||
/* Check for vaild parameter */ |
|||
VXB_ASSERT_NONNULL_V(pDev); |
|||
|
|||
pDrvCtrl = (SM2130_SPI_DEV *)pDev->pDrvCtrl; |
|||
|
|||
if (pDrvCtrl->muteSem) { |
|||
(void)semTake(pDrvCtrl->muteSem, WAIT_FOREVER); |
|||
|
|||
(void)semDelete(pDrvCtrl->muteSem); |
|||
pDrvCtrl->muteSem = NULL; |
|||
} |
|||
#ifndef _VXBUS_BASIC_HWMEMLIB |
|||
hwMemFree((char *)pDrvCtrl); |
|||
#endif /* _VXBUS_BASIC_HWMEMLIB */ |
|||
pDev->pDrvCtrl = NULL; |
|||
return OK; |
|||
} |
|||
|
|||
/*
|
|||
* |
|||
* sm2130SpiDevShow - show the SPI 1553B info. |
|||
* |
|||
* This routine show the SPI flash info by vxBusShow. |
|||
* |
|||
* RETURNS: N/A |
|||
* |
|||
* ERRNO: N/A |
|||
*/ |
|||
LOCAL void sm2130SpiDevShow(VXB_DEVICE_ID pDev, int verbose) |
|||
{ |
|||
printf(" %s unit %d on %s @ 0x%08x", pDev->pName, pDev->unitNumber, |
|||
vxbBusTypeString(pDev->busID), pDev); |
|||
printf(" with busInfo %p\n", pDev->u.pSubordinateBus); |
|||
|
|||
if (verbose) { |
|||
|
|||
} |
|||
|
|||
return; |
|||
} |
|||
|
|||
/*
|
|||
* spiDevWrite - VxBus SPI device write by name support routine |
|||
* |
|||
* This routine firstly finds the VXB_DEVICE_ID for a given instance |
|||
* identified by name and unit number, then call vxbI2cDevWrite() routine to |
|||
* write the device. |
|||
* |
|||
* RETURNS: OK/ERROR |
|||
* |
|||
* ERRNO : N/A |
|||
*/ |
|||
LOCAL STATUS spiDevWrite(VXB_DEVICE_ID pDev, UINT8 cmd, UINT16 var) |
|||
{ |
|||
SPI_TRANSFER transInfo = {NULL, NULL, 0, 0, 0}; |
|||
UINT8 buf[3]; |
|||
/* Check if the pDev pointer is valid */ |
|||
|
|||
VXB_ASSERT(pDev != NULL, ERROR) |
|||
buf[0] = cmd; |
|||
buf[1] = var & 0xff; |
|||
buf[1] = (var >> 8) & 0xff; |
|||
|
|||
transInfo.txBuf = buf; |
|||
transInfo.txLen = 3; |
|||
|
|||
return (vxbSpiTransfer(pDev, &transInfo)); |
|||
} |
|||
|
|||
/*
|
|||
* spiDevRead - read register routine |
|||
* |
|||
* This is the SPI flash status /config register read out routine. |
|||
* |
|||
* RETURNS: status register value. |
|||
* |
|||
* ERRNO: N/A |
|||
*/ |
|||
LOCAL INT32 spiDevRead(VXB_DEVICE_ID pDev, UINT8 cmd) |
|||
{ |
|||
SPI_TRANSFER transInfo = {NULL, NULL, 0, 0, 0}; |
|||
UINT16 buffer = 0xffff; |
|||
|
|||
/* check if the pDev pointer is valid */ |
|||
|
|||
VXB_ASSERT(pDev != NULL, ERROR) |
|||
|
|||
transInfo.txBuf = &cmd; |
|||
transInfo.txLen = 1; |
|||
transInfo.rxBuf = (UINT8 *)&buffer; |
|||
transInfo.rxLen = 2; |
|||
|
|||
if (vxbSpiTransfer(pDev, &transInfo) != OK) |
|||
return ERROR; |
|||
else |
|||
return (buffer); |
|||
} |
|||
|
|||
|
|||
INT32 sm2130Read(UINT8 cmd) |
|||
{ |
|||
VXB_DEVICE_ID pDev; |
|||
SM2130_SPI_DEV * pCtrl; |
|||
|
|||
pDev = vxbInstByNameFind(SPI_DEV_SM2130, 0); |
|||
if (pDev == NULL) { |
|||
return ERROR; |
|||
} |
|||
|
|||
pCtrl = pDev->pDrvCtrl; |
|||
|
|||
/* printf("pDev @ %p, pCtrl %p\n", pDev, pCtrl); */ |
|||
|
|||
return pCtrl->read(pDev, cmd); |
|||
} |
|||
|
|||
STATUS sm2130Write(UINT8 cmd, UINT16 var) |
|||
{ |
|||
VXB_DEVICE_ID pDev; |
|||
SM2130_SPI_DEV * pCtrl; |
|||
|
|||
pDev = vxbInstByNameFind(SPI_DEV_SM2130, 0); |
|||
if (pDev == NULL) { |
|||
return ERROR; |
|||
} |
|||
|
|||
pCtrl = pDev->pDrvCtrl; |
|||
|
|||
/* printf("pDev @ %p, pCtrl %p\n", pDev, pCtrl); */ |
|||
|
|||
return pCtrl->write(pDev, cmd, var); |
|||
} |
@ -0,0 +1,23 @@ |
|||
#ifndef __VXB_SM2130_SPI_DEV_H |
|||
#define __VXB_SM2130_SPI_DEV_H |
|||
|
|||
#define SPI_DEV_SM2130 "SM2130" |
|||
|
|||
#define SPI_DEV_MUTEX_OPT \ |
|||
(SEM_Q_PRIORITY | SEM_DELETE_SAFE | SEM_INVERSION_SAFE) |
|||
|
|||
typedef struct _spi_1553b_drv_ctrl { |
|||
VXB_DEVICE_ID pDev; |
|||
|
|||
int cs; |
|||
int mode; |
|||
unsigned int freq; |
|||
|
|||
INT32 (*read)(VXB_DEVICE_ID pDev, UINT8 cmd); |
|||
STATUS (*write)(VXB_DEVICE_ID pDev, UINT8 cmd, UINT16 var); |
|||
|
|||
SEM_ID muteSem; /* operation semaphore */ |
|||
VXB_SPI_MAST_SPEC *specialInfo; |
|||
} SM2130_SPI_DEV; |
|||
|
|||
#endif |
Loading…
Reference in new issue