Index: firmware/App/Controllers/RTC.c =================================================================== diff -u -r6deface076f5ce0351b44055118efa1936771776 -r526902d0a427e330e23ae5eaf433e89298643ac7 --- firmware/App/Controllers/RTC.c (.../RTC.c) (revision 6deface076f5ce0351b44055118efa1936771776) +++ firmware/App/Controllers/RTC.c (.../RTC.c) (revision 526902d0a427e330e23ae5eaf433e89298643ac7) @@ -13,13 +13,13 @@ * @brief Monitor/Controller Real Time Clock * **************************************************************************/ +#include // For calculating epoch #include "Common.h" #include "Timers.h" #include "RTC.h" #include "mibspi.h" -#include // ********** private definitions ********** #define RTC_REG_1_12_HOUR_MODE 0X0004 #define RTC_REG_1_PORO 0X0008 @@ -46,15 +46,29 @@ // This command puts RTC into read mode from // address 0 #define RTC_READ_FROM_REG0 0x00A0 - #define RTC_WRITE_TO_REG3 0x0023 +// For read or write operations in RAM, 1h and 1Ah +// must be sent that becomes 0x003A +#define RTC_PREP_RAM_READ_WRITE 0x003A +// For write operation in RAM, 1h and 1Ch will +// combined to 0x003C +#define RTC_WRITE_TO_RAM 0x003C + +#define RTC_READ_FROM_RAM 0x00BD + #define RTC_ACCURACY_TIMEOUT 1000 //ms #define RTC_ACCURACY_TIMEOUT_TOLERANCE 1050 //ms -#define NUM_OF_ITEMS_TO_READ 11 -#define TIMER_COUNTER_TO_REQUEST_READ 19 +#define TIMER_COUNTER_TO_REQUEST_READ 18 +#define MAX_ALLOWED_FAILED_RTC_TRANSFERS 2 + + +#define GENERAL_NUM_OF_ITEMS_TO_READ 11 +#define MAXIMUM_NUM_OF_BUFFER 129 + + typedef enum RTC_Self_Test_States { RTC_SELF_TEST_STATE_START = 0, @@ -75,6 +89,8 @@ { RTC_EXEC_STATE_WAIT_FOR_POST = 0, RTC_EXEC_STATE_IDLE, + RTC_EXEC_STATE_PREP_RAM, + RTC_EXEC_STATE_RAM, RTC_EXEC_STATE_READ, RTC_EXEC_STATE_WRITE, RTC_EXEC_STATE_FAULT @@ -102,26 +118,169 @@ U16 years; } write_ts; -static RTC_SELF_TEST_STATE_T RTCSelfTestState = RTC_SELF_TEST_STATE_START; -static RTC_GET_DATA_STATE_T RTCServiceState = RTC_SEND_COMMAND; -static RTC_EXEC_STATE_T RTCExecState = RTC_EXEC_STATE_WAIT_FOR_POST; +static RTC_SELF_TEST_STATE_T RTCSelfTestState = RTC_SELF_TEST_STATE_START; +static RTC_GET_DATA_STATE_T RTCServiceState = RTC_SEND_COMMAND; +static RTC_EXEC_STATE_T RTCExecState = RTC_EXEC_STATE_WAIT_FOR_POST; +static SELF_TEST_STATUS_T RTCSelfTestResult = SELF_TEST_STATUS_IN_PROGRESS; static U32 RTCSelfTestTimer = 0; static U32 RTCPreviousSecond = 0; static U32 timeCounter = 1; +static U32 numberOfFailedRTCTransfers = 0; -static BOOL hasWriteTimestampRequested = FALSE; +static BOOL hasWriteToRTCRequested = FALSE; +static BOOL hasWriteToRAMRequested = FALSE; +static BOOL hasReadFromRAMRequested = TRUE; -static U16 rxBuffer[NUM_OF_ITEMS_TO_READ]; -static U16 txBuffer[] = {RTC_READ_FROM_REG0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000}; +static U16 rxBuffer[MAXIMUM_NUM_OF_BUFFER]; +//static U16 txBuffer[] = {RTC_READ_FROM_REG0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, +// 0x0000, 0x0000, 0x0000, 0x0000, 0x0000}; +static U16 txBuffer[MAXIMUM_NUM_OF_BUFFER]; + // ********** Private functions prototype ********* +static BOOL serviceRTC( U16* buffer ); +static BOOL isRTCFunctional(); +static U08 convertBCD2Decimal( U08 bcd ); +static U08 convertDecimal2BCD( U08 decimal ); +static U32 convertTime2Epoch(); +static void updateReadTimestampStruct(); +static RTC_SELF_TEST_STATE_T handleSelfTestStart(); +static RTC_SELF_TEST_STATE_T handleSelfTestCheckCtrlRegs(); +static RTC_SELF_TEST_STATE_T handleSelfTestCompareSeconds(); +static RTC_SELF_TEST_STATE_T handleSelfTestCheckAccuracy(); + +static RTC_EXEC_STATE_T handleExecIdleState(); +static RTC_EXEC_STATE_T handleExecReadState(); +static RTC_EXEC_STATE_T handleExecPrepRAMState(); +static RTC_EXEC_STATE_T handleExecRAMState(U08* address, U08* data, U32 length); +static RTC_EXEC_STATE_T handleExecRAMState(U08* address, U08* data, U32 length); +static RTC_EXEC_STATE_T handleExecWriteState(); + +static BOOL setMibSPIBufferLength(U16 length); + +// ********** Public functions ********** +void initRTC() +{ + // Do nothing for now +} + +void setRTCTimestamp( U08 secs, U08 mins, U08 hours, U08 days, U08 months, U16 years ) +{ + hasWriteToRTCRequested = TRUE; + + U16 decimalSeconds = convertDecimal2BCD( secs ); + U16 decimalMins = convertDecimal2BCD( mins ); + U16 decimalHours = convertDecimal2BCD( hours ); + U16 decimalDays = convertDecimal2BCD( days ); + U16 decimalMonths = convertDecimal2BCD( months ); + U16 decimalYears = convertDecimal2BCD( years - 2000 ); + + write_ts.seconds = decimalSeconds; + write_ts.minutes = decimalMins; + write_ts.hours = decimalHours; + write_ts.days = decimalDays; + write_ts.weekdays = 0; // Weekdays will not be used + write_ts.months = decimalMonths; + write_ts.years = decimalYears; +} + +SELF_TEST_STATUS_T execRTCSelfTest( void ) +{ + switch ( RTCSelfTestState ) + { + case RTC_SELF_TEST_STATE_START: + + RTCSelfTestState = handleSelfTestStart(); + break; + + case RTC_SELF_TEST_STATE_CHECK_CTRL_REGS: + + RTCSelfTestState = handleSelfTestCheckCtrlRegs(); + break; + + case RTC_SELF_TEST_STATE_COMPARE_SECONDS: + + RTCSelfTestState = handleSelfTestCompareSeconds(); + break; + + case RTC_SELF_TEST_STATE_CHECK_ACCURACY: + + RTCSelfTestState = handleSelfTestCheckAccuracy(); + break; + + case RTC_SELF_TEST_STATE_COMPLETE: + break; + + default: + // TODO: Add the alarms + RTCSelfTestResult = SELF_TEST_STATUS_FAILED; + break; + } + + return RTCSelfTestResult; +} + +void execRTC() +{ + switch ( RTCExecState ) + { + case RTC_EXEC_STATE_WAIT_FOR_POST: + + if ( RTCSelfTestState == RTC_SELF_TEST_STATE_COMPLETE && + RTCSelfTestResult == SELF_TEST_STATUS_PASSED ) + { + RTCExecState = RTC_EXEC_STATE_IDLE; + } + else if ( RTCSelfTestState == RTC_SELF_TEST_STATE_COMPLETE && + RTCSelfTestResult == SELF_TEST_STATUS_FAILED ) + { + RTCExecState = RTC_EXEC_STATE_FAULT; + } + break; + + case RTC_EXEC_STATE_IDLE: + + RTCExecState = handleExecIdleState(); + break; + + case RTC_EXEC_STATE_PREP_RAM: + + RTCExecState = handleExecRAMState(0, 0, 0); + break; + + case RTC_EXEC_STATE_RAM: + + RTCExecState = handleExecRAMState(0, 0, 0); + break; + + case RTC_EXEC_STATE_WRITE: + + RTCExecState = handleExecWriteState(); + break; + + case RTC_EXEC_STATE_READ: + + RTCExecState = handleExecReadState(); + break; + + case RTC_EXEC_STATE_FAULT: + + // Something failed set the alarms + // TODO: set the alarms and stuff + break; + + default: + break; + } +} // ********** Private functions ********* -static void serviceRTC( U16* buffer ) +static BOOL serviceRTC( U16* buffer ) { + BOOL result = FALSE; + switch ( RTCServiceState ) { case RTC_SEND_COMMAND: @@ -140,17 +299,34 @@ mibspiGetData(mibspiREG3, 0, rxBuffer); RTCServiceState = RTC_READ_COMPLETE; + + result = TRUE; } + else if ( numberOfFailedRTCTransfers >= MAX_ALLOWED_FAILED_RTC_TRANSFERS ) + { + RTCServiceState = RTC_READ_COMPLETE; + } + else + { + // Transfer to RTC failed. This transfer + // should be done in 50ms + numberOfFailedRTCTransfers++; + + RTCServiceState = RTC_SEND_COMMAND; + } break; case RTC_READ_COMPLETE: + // Done with reading and transfer do nothing break; default: - // TODO: Set an alarm or try multiple times (3 times) before failing + // We should never get here break; } + + return result; } static BOOL isRTCFunctional() @@ -265,215 +441,329 @@ read_ts.years = decimalYears; } -// ********** Public functions ********** -void initRTC() +static RTC_EXEC_STATE_T handleExecWriteState() { - // Do nothing for now + RTC_EXEC_STATE_T result = RTC_EXEC_STATE_WRITE; + + // FOR DEBUGGING ONLY, REMOVE THIS CODE + setRTCTimestamp(0, 10, 17, 8, 12, 2019); + + U16 timestamp[8] = {RTC_WRITE_TO_REG3, write_ts.seconds, write_ts.minutes, write_ts.hours, + write_ts.days, write_ts.weekdays, write_ts.months, + write_ts.years}; + + serviceRTC( ×tamp[0] ); + + if ( RTCServiceState == RTC_READ_COMPLETE ) + { + // Reset the counter + timeCounter = 1; + hasWriteToRTCRequested = FALSE; + RTCExecState = RTC_EXEC_STATE_IDLE; + } + + return result; } -void setRTCTimestamp( U08 secs, U08 mins, U08 hours, U08 days, U08 months, U16 years ) +static RTC_EXEC_STATE_T handleExecIdleState() { - hasWriteTimestampRequested = TRUE; + RTC_EXEC_STATE_T result = RTC_EXEC_STATE_IDLE; - U16 decimalSeconds = convertDecimal2BCD( secs ); - U16 decimalMins = convertDecimal2BCD( mins ); - U16 decimalHours = convertDecimal2BCD( hours ); - U16 decimalDays = convertDecimal2BCD( days ); - U16 decimalMonths = convertDecimal2BCD( months ); - U16 decimalYears = convertDecimal2BCD( years - 2000 ); + if ( hasWriteToRTCRequested ) + { + result = RTC_EXEC_STATE_WRITE; + } + else if ( hasWriteToRAMRequested || hasReadFromRAMRequested ) + { + result = RTC_EXEC_STATE_PREP_RAM; + } + // If write to RTC has been requested, we don't have to read + // write must be finished first + else if ( timeCounter == TIMER_COUNTER_TO_REQUEST_READ ) + { + // Reset the RTC Service commands + RTCServiceState = RTC_SEND_COMMAND; - write_ts.seconds = decimalSeconds; - write_ts.minutes = decimalMins; - write_ts.hours = decimalHours; - write_ts.days = decimalDays; - write_ts.weekdays = 0; // Weekdays will not be used - write_ts.months = decimalMonths; - write_ts.years = decimalYears; + setMibSPIBufferLength(GENERAL_NUM_OF_ITEMS_TO_READ); + + txBuffer[0] = RTC_READ_FROM_REG0; + + U08 i; + for (i=1; i< GENERAL_NUM_OF_ITEMS_TO_READ; i++) + { + txBuffer[i] = 0x0000; + } + result = RTC_EXEC_STATE_READ; + } + else + { + timeCounter++; + } + + return result; } -SELF_TEST_STATUS_T execRTCSelfTest( void ) +static RTC_EXEC_STATE_T handleExecPrepRAMState(U08* address) { - SELF_TEST_STATUS_T result = SELF_TEST_STATUS_IN_PROGRESS; + RTC_EXEC_STATE_T result = RTCExecState; - switch ( RTCSelfTestState ) - { - case RTC_SELF_TEST_STATE_START: + txBuffer[0] = RTC_PREP_RAM_READ_WRITE; + txBuffer[1] = 0x0000; + txBuffer[2] = 0x0000; - serviceRTC( &txBuffer[0] ); + setMibSPIBufferLength(3); - RTCSelfTestState = RTC_SELF_TEST_STATE_CHECK_CTRL_REGS; - break; + BOOL isStatusOk = serviceRTC( &txBuffer[0] ); - case RTC_SELF_TEST_STATE_CHECK_CTRL_REGS: + if ( RTCServiceState == RTC_READ_COMPLETE && isStatusOk ) + { + result = RTC_EXEC_STATE_RAM; + } + else if ( RTCServiceState == RTC_READ_COMPLETE && ! isStatusOk ) + { + result = RTC_EXEC_STATE_FAULT; + } - serviceRTC( &txBuffer[0] ); + return result; +} - if ( RTCServiceState == RTC_READ_COMPLETE ) - { - // Reset the states - RTCServiceState = RTC_SEND_COMMAND; +static RTC_EXEC_STATE_T handleExecRAMState(U08* address, U08* data, U32 length) +{ + RTC_EXEC_STATE_T result = RTCExecState; - if ( isRTCFunctional() ) - { - RTCSelfTestState = RTC_SELF_TEST_STATE_COMPARE_SECONDS; - } - else - { - result = SELF_TEST_STATUS_FAILED; - RTCSelfTestState = RTC_SELF_TEST_STATE_COMPLETE; - } - } - break; + if ( RTCExecState == RTC_EXEC_STATE_PREP_RAM ) + { + txBuffer[0] = RTC_PREP_RAM_READ_WRITE; + txBuffer[1] = 0x0000; + txBuffer[2] = 0x0000; - case RTC_SELF_TEST_STATE_COMPARE_SECONDS: + setMibSPIBufferLength(3); - serviceRTC( &txBuffer[0] ); + result = RTC_EXEC_STATE_PREP_RAM; + } + else if ( RTCExecState == RTC_EXEC_STATE_RAM ) + { + if ( hasWriteToRAMRequested ) + { + txBuffer[0] = RTC_WRITE_TO_RAM; + } + else if ( hasReadFromRAMRequested ) + { + txBuffer[0] = RTC_READ_FROM_RAM; + } - if ( RTCServiceState == RTC_READ_COMPLETE ) - { - // Reset the states - RTCServiceState = RTC_SEND_COMMAND; + txBuffer[1] = 0x0000; + txBuffer[2] = 0x0000; - U32 RTCCurrentSecond = rxBuffer[RTC_SECONDS_INDEX]; + setMibSPIBufferLength(3); - if ( RTCPreviousSecond == 0 ) - { - RTCPreviousSecond = RTCCurrentSecond; - } - else if ( RTCCurrentSecond > RTCPreviousSecond ) - { - RTCSelfTestTimer = getMSTimerCount(); + result = RTC_EXEC_STATE_RAM; + } - RTCSelfTestState = RTC_SELF_TEST_STATE_CHECK_ACCURACY; - } - } - break; + BOOL isStatusOk = serviceRTC( &txBuffer[0] ); - case RTC_SELF_TEST_STATE_CHECK_ACCURACY: + if ( RTCServiceState == RTC_READ_COMPLETE && isStatusOk ) + { + if ( RTCExecState == RTC_EXEC_STATE_PREP_RAM ) + { + result = RTC_EXEC_STATE_RAM; + // Reset the RTC Service commands + RTCServiceState = RTC_SEND_COMMAND; + } + else + { + result = RTC_EXEC_STATE_IDLE; + hasWriteToRAMRequested = FALSE; + hasReadFromRAMRequested = FALSE; + } + } + else if ( RTCServiceState == RTC_READ_COMPLETE && ! isStatusOk ) + { + result = RTC_EXEC_STATE_FAULT; + } - if ( didTimeout( RTCSelfTestTimer, RTC_ACCURACY_TIMEOUT ) ) - { - U32 elapsedTime = calcTimeSince(RTCSelfTestTimer); + return result; +} - if ( elapsedTime > RTC_ACCURACY_TIMEOUT_TOLERANCE ) - { - result = SELF_TEST_STATUS_FAILED; - } - else - { - result = SELF_TEST_STATUS_PASSED; - } +static RTC_EXEC_STATE_T handleExecReadState() +{ + RTC_EXEC_STATE_T result = RTC_EXEC_STATE_READ; - RTCSelfTestState = RTC_SELF_TEST_STATE_COMPLETE; - } - break; + BOOL isStatusOk = serviceRTC( &txBuffer[0] ); - case RTC_SELF_TEST_STATE_COMPLETE: - break; + if ( RTCServiceState == RTC_READ_COMPLETE && isStatusOk ) + { + if ( isRTCFunctional() ) + { + updateReadTimestampStruct(); - default: - // TODO: Add the alarms - result = SELF_TEST_STATUS_FAILED; - break; + convertTime2Epoch(); + + timeCounter = 1; + result = RTC_EXEC_STATE_IDLE; + } } + else if ( RTCServiceState == RTC_READ_COMPLETE && ! isStatusOk ) + { + result = RTC_EXEC_STATE_FAULT; + } return result; } -void execRTC() + +// Private self test functions +static RTC_SELF_TEST_STATE_T handleSelfTestStart() { - switch ( RTCExecState ) + RTC_SELF_TEST_STATE_T result = RTC_SELF_TEST_STATE_START; + + setMibSPIBufferLength(GENERAL_NUM_OF_ITEMS_TO_READ); + + txBuffer[0] = RTC_READ_FROM_REG0; + + U08 i; + for (i=1; i< GENERAL_NUM_OF_ITEMS_TO_READ; i++) { - case RTC_EXEC_STATE_WAIT_FOR_POST: + txBuffer[i] = 0x0000; + } - if ( RTCSelfTestState == RTC_SELF_TEST_STATE_COMPLETE ) - { - RTCExecState = RTC_EXEC_STATE_IDLE; - } - break; + result = RTC_SELF_TEST_STATE_CHECK_CTRL_REGS; - case RTC_EXEC_STATE_IDLE: + return result; +} - if ( hasWriteTimestampRequested ) - { - // FOR DEBUGGING ONLY, REMOVE THIS CODE - setRTCTimestamp(0, 10, 17, 8, 12, 2019); +static RTC_SELF_TEST_STATE_T handleSelfTestCheckCtrlRegs() +{ + RTC_SELF_TEST_STATE_T result = RTC_SELF_TEST_STATE_CHECK_CTRL_REGS; - U16 timestamp[8] = {RTC_WRITE_TO_REG3, write_ts.seconds, write_ts.minutes, write_ts.hours, - write_ts.days, write_ts.weekdays, write_ts.months, - write_ts.years}; + serviceRTC( &txBuffer[0] ); - serviceRTC( ×tamp[0] ); + if ( RTCServiceState == RTC_READ_COMPLETE ) + { + // Reset the states + RTCServiceState = RTC_SEND_COMMAND; - RTCExecState = RTC_EXEC_STATE_WRITE; - } - // If write to RTC has been requested, we don't have to read - // write must be finished first - else if ( timeCounter == TIMER_COUNTER_TO_REQUEST_READ ) - { - // Reset the states - RTCServiceState = RTC_SEND_COMMAND; + if ( isRTCFunctional() ) + { + result = RTC_SELF_TEST_STATE_COMPARE_SECONDS; + } + else + { + RTCSelfTestResult = SELF_TEST_STATUS_FAILED; + result = RTC_SELF_TEST_STATE_COMPLETE; + } + } - serviceRTC( &txBuffer[0] ); - RTCExecState = RTC_EXEC_STATE_READ; - } - else - { - timeCounter++; - } - break; - case RTC_EXEC_STATE_WRITE: + return result; +} - serviceRTC( 0 ); +static RTC_SELF_TEST_STATE_T handleSelfTestCompareSeconds() +{ + RTC_SELF_TEST_STATE_T result = RTC_SELF_TEST_STATE_COMPARE_SECONDS; - if ( RTCServiceState == RTC_READ_COMPLETE ) - { - // Write finished. Reset the counter to start - // the read again - timeCounter = 1; - hasWriteTimestampRequested = FALSE; - RTCExecState = RTC_EXEC_STATE_IDLE; - } + serviceRTC( &txBuffer[0] ); - break; + if ( RTCServiceState == RTC_READ_COMPLETE ) + { + // Reset the states + RTCServiceState = RTC_SEND_COMMAND; - case RTC_EXEC_STATE_READ: + U32 RTCCurrentSecond = rxBuffer[RTC_SECONDS_INDEX]; - serviceRTC( &txBuffer[0] ); + if ( RTCPreviousSecond == 0 ) + { + RTCPreviousSecond = RTCCurrentSecond; + } + else if ( RTCCurrentSecond > RTCPreviousSecond ) + { + RTCSelfTestTimer = getMSTimerCount(); - if ( RTCServiceState == RTC_READ_COMPLETE ) - { - if ( isRTCFunctional() ) - { - // FOR TESTING ONLY REMOVE THE CODE - //U08 testDate = (U08)rxBuffer[RTC_SECONDS_INDEX]; - //convertBCD2Decimal( testDate ); + result = RTC_SELF_TEST_STATE_CHECK_ACCURACY; + } + } - updateReadTimestampStruct(); - convertTime2Epoch(); + return result; +} +static RTC_SELF_TEST_STATE_T handleSelfTestCheckAccuracy() +{ + RTC_SELF_TEST_STATE_T result = RTC_SELF_TEST_STATE_CHECK_ACCURACY; - timeCounter = 1; - RTCExecState = RTC_EXEC_STATE_IDLE; - } - else - { - RTCExecState = RTC_EXEC_STATE_FAULT; - } - } - break; + if ( didTimeout( RTCSelfTestTimer, RTC_ACCURACY_TIMEOUT ) ) + { + U32 elapsedTime = calcTimeSince(RTCSelfTestTimer); - case RTC_EXEC_STATE_FAULT: - // Something failed set the alarms - // TODO: set the alarms and stuff - break; + if ( elapsedTime > RTC_ACCURACY_TIMEOUT_TOLERANCE ) + { + RTCSelfTestResult = SELF_TEST_STATUS_FAILED; + } + else + { + RTCSelfTestResult = SELF_TEST_STATUS_PASSED; + } - default: - break; + result = RTC_SELF_TEST_STATE_COMPLETE; } + + return result; } +static BOOL setMibSPIBufferLength( U16 length ) +{ + // TODO: Check for the length of the buffer + U32 i = 0; + mibspiREG3->TGCTRL[0U] &= ~(uint32)((uint32)127U << 8U); + mibspiREG3->TGCTRL[1U] &= ~(uint32)((uint32)127U << 8U); + mibspiREG3->TGCTRL[1U] |= (uint32)((uint32)length << 8U); + mibspiREG3->TGCTRL[2U] &= ~(uint32)((uint32)127U << 8U); + mibspiREG3->TGCTRL[2U] |= (uint32)((uint32)(length+0U) << 8U); + + mibspiREG3->TGCTRL[3U] &= ~(uint32)((uint32)127U << 8U); + mibspiREG3->TGCTRL[3U] |= (uint32)((uint32)(length+0U+0U) << 8U); + + mibspiREG3->TGCTRL[4U] &= ~(uint32)((uint32)127U << 8U); + mibspiREG3->TGCTRL[4U] |= (uint32)((uint32)(length+0U+0U+0U) << 8U); + + mibspiREG3->TGCTRL[5U] &= ~(uint32)((uint32)127U << 8U); + mibspiREG3->TGCTRL[5U] |= (uint32)((uint32)(length+0U+0U+0U+0U) << 8U); + + mibspiREG3->TGCTRL[6U] &= ~(uint32)((uint32)127U << 8U); + mibspiREG3->TGCTRL[6U] |= (uint32)((uint32)(length+0U+0U+0U+0U+0U) << 8U); + + mibspiREG3->TGCTRL[7U] &= ~(uint32)((uint32)127U << 8U); + mibspiREG3->TGCTRL[7U] |= (uint32)((uint32)(length+0U+0U+0U+0U+0U+0U) << 8U); + + mibspiREG3->TGCTRL[8U] = (uint32)(length+0U+0U+0U+0U+0U+0U+0U) << 8U; + + mibspiREG3->LTGPEND = (mibspiREG3->LTGPEND & 0xFFFF00FFU) | + (uint32)(((uint32)(length+0U+0U+0U+0U+0U+0U+0U)-1U) << 8U); + + while (i < (length-1U)) + { + mibspiRAM3->tx[i].control = (uint16)((uint16)4U << 13U) /* buffer mode */ + | (uint16)((uint16)1U << 12U) /* chip select hold */ + | (uint16)((uint16)0U << 10U) /* enable WDELAY */ + | (uint16)((uint16)0U << 11U) /* lock transmission */ + | (uint16)((uint16)0U << 8U) /* data format */ + /*SAFETYMCUSW 334 S MR:10.5 "LDRA Tool issue" */ + | ((uint16)(~((uint16)0xFFU ^ (uint16)CS_0)) & (uint16)0x00FFU); /* chip select */ + i++; + } + mibspiRAM3->tx[i].control = (uint16)((uint16)4U << 13U) /* buffer mode */ + | (uint16)((uint16)0U << 12U) /* chip select hold */ + | (uint16)((uint16)0U << 10U) /* enable WDELAY */ + | (uint16)((uint16)0U << 8U) /* data format */ + /*SAFETYMCUSW 334 S MR:10.5 "LDRA Tool issue" */ + | ((uint16)(~((uint16)0xFFU ^ (uint16)CS_0)) & (uint16)0x00FFU); /* chip select */ + + + i++; + + return TRUE; + +} +