From f53e61d578594946c35aece8706c71fc893678db Mon Sep 17 00:00:00 2001 From: RobertK66 Date: Mon, 4 Dec 2023 16:12:33 +0100 Subject: [PATCH 1/6] starting data transfer code.... --- ClimbObc/src/mod/srs/radsensor.c | 46 +++++++++++++++++++++++++++++--- ClimbObc/src/mod/srs/radsensor.h | 3 +++ 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/ClimbObc/src/mod/srs/radsensor.c b/ClimbObc/src/mod/srs/radsensor.c index da50a65..74b4fc0 100644 --- a/ClimbObc/src/mod/srs/radsensor.c +++ b/ClimbObc/src/mod/srs/radsensor.c @@ -62,6 +62,12 @@ #define SRS_DATARESP_NOMMOREDATA 0x16 #define SRS_CMDEXEC_REQDATA 0x00000800 // Only one bit is enough here because ctrl of data transfer is done in other structures.... +// Data transfer adjustable: +#define SRS_DATABLOCK_SIZE 1000 // 1000 is MAX val! +#define SRS_BLOCKDELAY_MS 10 +#define SRS_BLOCKBURST_CNT 42 +#define SRS_BLOCKBURST_DEALY_MS 100 + static uint8_t PowerOnCmd[2] = {0x00, SRS_POWERBUS_ENABLECMD}; static uint8_t PowerOffCmd[2] = {0x00, SRS_POWERBUS_DISABLECMD}; @@ -76,13 +82,23 @@ static bool srsIsPowerJob = false; static I2C_Data srsJob; + static uint32_t srsCmdExecutes = 0; static uint32_t srsPendingCmdExec = 0; -//static bool srsCmdSynctime = false; -static uint8_t srsTx[20]; -static uint8_t srsRx[128]; +static uint8_t srsTx[20]; +static uint8_t srsRx[SRS_DATABLOCK_SIZE+20]; static uint32_t val32ToSend = 0; + + +typedef enum {SRSD_IDLE, SRS_DATA_GETADDRESSES, SRS_DATA_WAITFORADDRESSES } srs_transfer_stat; + +static srs_transfer_stat srsDataTransferStatus = SRSD_IDLE +static uint32_t srsDataPtrStart; +static uint32_t srsDataPtrEnd; + + + // local module prototypes uint8_t srs_crc(uint8_t *data, int len); @@ -92,7 +108,7 @@ void srsExecuteRequestSyncTime(void); void srsExecuteRequestStatus(uint8_t statusType); void srsExecuteRequestIntervals(void); void srsExecuteSendInterval(uint8_t type, uint32_t val); - +void srsExecuteRequestDataAddresses(void); // Module API // ---------- @@ -237,6 +253,10 @@ void srs_main() { srsCmdExecutes &= (~SRS_CMDEXEC_SHUTDOWN); srsPendingCmdExec = SRS_CMDEXEC_SHUTDOWN; srsExecuteRequestShutdown(); + } else if (srsCmdExecutes & SRS_CMDEXEC_REQDATAADDR) { + srsCmdExecutes &= (~SRS_CMDEXEC_REQDATAADDR); + srsPendingCmdExec = SRS_CMDEXEC_REQDATAADDR; + srsExecuteRequestDataAddresses(); } } @@ -289,6 +309,20 @@ void srs_getstatus(uint8_t statusType) { } + // TODO: either direct errors or callback !? -> events + // At this moment we alwys initarte a 'download all new data' sequence. + // TODO: allow for specific Adresses to be fetached (again). + void srs_maketransfer(void) { + if (srsDataTransferStatus == SRSD_IDLE) { + srsDataTransferStatus = SRS_DATA_GETADDRESSES; + srsCmdExecutes |= SRS_CMDEXEC_REQDATAADDR; + } else { + SysEvent(MODULE_ID_RADSENSOR, EVENT_WARNING, EID_SRS_TRANSFERBUSY, 0, 0); + } + + } + + // Module local functions // ---------------------- @@ -440,6 +474,10 @@ void srs_cmd(int argc, char *argv[]) { srs_shutdown(); break; + case 'd': + srs_maketransfer(); + break; + default: break; } diff --git a/ClimbObc/src/mod/srs/radsensor.h b/ClimbObc/src/mod/srs/radsensor.h index f140fdb..c2c778e 100644 --- a/ClimbObc/src/mod/srs/radsensor.h +++ b/ClimbObc/src/mod/srs/radsensor.h @@ -39,6 +39,9 @@ void srs_cmd(int argc, char *argv[]); #define EID_SRS_INTERVAL 0x07 #define EID_SRS_SHUTDOWN 0x08 #define EID_SRS_ERROR 0x80 +#define EID_SRS_TRANSFERBUSY 0x81 + + #endif /* MOD_SRS_RADSENSOR_H_ */ From 5b696759491516c5fd96f0c98d9cf2c758090d30 Mon Sep 17 00:00:00 2001 From: RobertK66 Date: Sat, 9 Dec 2023 15:51:25 +0100 Subject: [PATCH 2/6] dta transfer first function tested. --- ClimbObc/src/mod/srs/radsensor.c | 139 +++++++++++++++++++++++++++++-- ClimbObc/src/mod/srs/radsensor.h | 5 ++ 2 files changed, 139 insertions(+), 5 deletions(-) diff --git a/ClimbObc/src/mod/srs/radsensor.c b/ClimbObc/src/mod/srs/radsensor.c index 74b4fc0..09ed042 100644 --- a/ClimbObc/src/mod/srs/radsensor.c +++ b/ClimbObc/src/mod/srs/radsensor.c @@ -63,7 +63,7 @@ #define SRS_CMDEXEC_REQDATA 0x00000800 // Only one bit is enough here because ctrl of data transfer is done in other structures.... // Data transfer adjustable: -#define SRS_DATABLOCK_SIZE 1000 // 1000 is MAX val! +#define SRS_DATABLOCK_SIZE 200 // TODO: expand I2C job to uint16 rxsize!!!! 1000 // 1000 is MAX val! #define SRS_BLOCKDELAY_MS 10 #define SRS_BLOCKBURST_CNT 42 #define SRS_BLOCKBURST_DEALY_MS 100 @@ -91,11 +91,14 @@ static uint8_t srsRx[SRS_DATABLOCK_SIZE+20]; static uint32_t val32ToSend = 0; -typedef enum {SRSD_IDLE, SRS_DATA_GETADDRESSES, SRS_DATA_WAITFORADDRESSES } srs_transfer_stat; +typedef enum {SRS_DATA_IDLE, SRS_DATA_GETADDRESSES, SRS_DATA_INIT, SRS_DATA_BLOCKREAD, SRS_DATA_STOP, SRS_DATA_ERROR } srs_transfer_stat; -static srs_transfer_stat srsDataTransferStatus = SRSD_IDLE +static srs_transfer_stat srsDataTransferStatus = SRS_DATA_IDLE; static uint32_t srsDataPtrStart; static uint32_t srsDataPtrEnd; +static uint16_t srsBlockSize; +static uint32_t srsBlocksToRead; + @@ -136,6 +139,9 @@ void srs_main() { if (srsJob.rx_size >= 3) { // Check for errors if (srsJob.rx_data[0] == 0xFF) { + if ((srsPendingCmdExec == SRS_CMDEXEC_REQDATAADDR) || (srsPendingCmdExec == SRS_CMDEXEC_REQDATA)) { + srsDataTransferStatus = SRS_DATA_ERROR; + } srsPendingCmdExec = 0; // No valid answer to process SysEvent(MODULE_ID_RADSENSOR, EVENT_ERROR, EID_SRS_ERROR, &srsJob.rx_data[1], 1); } @@ -179,6 +185,54 @@ void srs_main() { SysEvent(MODULE_ID_RADSENSOR, EVENT_INFO, EID_SRS_SHUTDOWN, 0, 0 ); break; + case SRS_CMDEXEC_REQDATAADDR: + SysEvent(MODULE_ID_RADSENSOR, EVENT_INFO, EID_SRS_ADDRINFO, &srsJob.rx_data[2], 8); + // srsJob.RxData[1] // Status -> laut doku immer 0 !? + memcpy(&srsDataPtrStart, &srsJob.rx_data[2] , 4); + memcpy(&srsDataPtrEnd, &srsJob.rx_data[6] , 4); + srsDataTransferStatus = SRS_DATA_INIT; + srs_transfer(); // Initiate next job for transfer. + break; + + case SRS_CMDEXEC_REQDATA: + //SysEvent(MODULE_ID_RADSENSOR, EVENT_INFO, EID_SRS_DATARX, srsJob.rx_data, srsJob); + if (srsDataTransferStatus == SRS_DATA_INIT) { + if (srsJob.rx_data[1] != SRS_DATACMD_INIT) { + // Error ocured. + SysEvent(MODULE_ID_RADSENSOR, EVENT_ERROR, EID_SRS_ERROR, &srsJob.rx_data[1], 1); + srsDataTransferStatus = SRS_DATA_ERROR; // TODO: Hoiw to clear/leave from here.....??? + } else { + memcpy(&srsBlockSize, &srsJob.rx_data[2], 2); // Block size to use is decided by SRS here. + // Skip start address -> why bothering here . When could this be different than requested one!? + memcpy(&srsBlocksToRead, &srsJob.rx_data[8], 4); // Number of blocks to be expeted by this transfer. + SysEvent(MODULE_ID_RADSENSOR, EVENT_INFO, EID_SRS_TRANSFERINIT, &srsJob.rx_data[2], 10); + srsDataTransferStatus = SRS_DATA_BLOCKREAD; + srs_transfer(); + } + } else if (srsDataTransferStatus == SRS_DATA_BLOCKREAD) { + if (srsJob.rx_data[1] == SRS_DATACMD_TRANSFER) { + // a valid data block + // Start addr / end addr -> into extra event + // -> CRC Check!!!! -> resend + //SysEvent(MODULE_ID_RADSENSOR, EVENT_INFO, EID_SRS_BLOCKDATA, &srsJob.rx_data[2], srsJob.rx_size-2 ); + SysEvent(MODULE_ID_RADSENSOR, EVENT_INFO, EID_SRS_BLOCKDATA, &srsJob.rx_data[2], 50 ); + srs_transfer(); + } else { + // Error or no more data + SysEvent(MODULE_ID_RADSENSOR, EVENT_ERROR, EID_SRS_ERROR, &srsJob.rx_data[1], 1); + srsDataTransferStatus = SRS_DATA_STOP; + srs_transfer(); + } + } else if (srsDataTransferStatus == SRS_DATA_STOP) { + if (srsJob.rx_data[1] == SRS_DATACMD_STOP) { + srsDataTransferStatus = SRS_DATA_IDLE; + SysEvent(MODULE_ID_RADSENSOR, EVENT_INFO, EID_SRS_TRANSFERSTOP, 0, 0); + } else { + srsDataTransferStatus = SRS_DATA_ERROR; // TODO: Hoiw to clear/leave from here.....??? + SysEvent(MODULE_ID_RADSENSOR, EVENT_ERROR, EID_SRS_ERROR, &srsJob.rx_data[1], 1); + } + } + break; default: SysEvent(MODULE_ID_RADSENSOR, EVENT_INFO, EID_SRS_DATARX, srsJob.rx_data, srsJob.rx_size); @@ -311,9 +365,9 @@ void srs_getstatus(uint8_t statusType) { // TODO: either direct errors or callback !? -> events // At this moment we alwys initarte a 'download all new data' sequence. - // TODO: allow for specific Adresses to be fetached (again). + // TODO: allow for specific Adresses to be fetched (again). void srs_maketransfer(void) { - if (srsDataTransferStatus == SRSD_IDLE) { + if ((srsDataTransferStatus == SRS_DATA_IDLE) || (srsDataTransferStatus == SRS_DATA_ERROR)) { srsDataTransferStatus = SRS_DATA_GETADDRESSES; srsCmdExecutes |= SRS_CMDEXEC_REQDATAADDR; } else { @@ -432,6 +486,81 @@ void srsExecuteRequestShutdown(void) { } +void srsExecuteRequestDataAddresses(void) { + srsJob.device = srs->pI2C; + srsJob.adress = SRS_CTRL_ADDR; + srsTx[0] = SRS_CTRLCMD_REQDATAADDR; + srsTx[1] = srs_crc(srsTx, 1); + srsJob.tx_size = 2; + srsJob.tx_data = srsTx; + srsJob.rx_size = 11; + srsJob.rx_data = srsRx; + srsJobInProgress = true; + i2c_add_job(&srsJob); +} + +// This is called direct from main (after analyses of last JobFinished). So we can setup the next job here. +void srs_transfer() { + switch (srsDataTransferStatus) { + case SRS_DATA_INIT: + srsJob.device = srs->pI2C; + srsJob.adress = SRS_CTRL_ADDR; + srsTx[0] = SRS_CTRLCMD_REQDATA; + srsTx[1] = SRS_DATACMD_INIT; + srsTx[2] = (uint8_t)(SRS_DATABLOCK_SIZE & 0x00FF); + srsTx[3] = (uint8_t)(SRS_DATABLOCK_SIZE>>8 & 0x00FF); + memcpy(&srsTx[4],&srsDataPtrStart, 4); + uint32_t numBlocks = (srsDataPtrEnd - srsDataPtrStart)/SRS_DATABLOCK_SIZE; + if ((srsDataPtrEnd - srsDataPtrStart)%SRS_DATABLOCK_SIZE != 0) { + numBlocks++; + } + memcpy(&srsTx[8],&numBlocks, 4); + srsTx[12] = srs_crc(srsTx, 12); + srsJob.tx_size = 13; + srsJob.tx_data = srsTx; + srsJob.rx_size = 13; + srsJob.rx_data = srsRx; + srsJobInProgress = true; + srsPendingCmdExec = SRS_CMDEXEC_REQDATA; + i2c_add_job(&srsJob); + break; + case SRS_DATA_BLOCKREAD: + srsJob.device = srs->pI2C; + srsJob.adress = SRS_CTRL_ADDR; + srsTx[0] = SRS_CTRLCMD_REQDATA; + if (srsBlocksToRead>0) { + srsTx[1] = SRS_DATACMD_TRANSFER; + srsBlocksToRead--; + } else { + srsTx[1] = SRS_DATACMD_STOP; + srsDataTransferStatus = SRS_DATA_STOP; + } + srsTx[2] = srs_crc(srsTx, 2); + srsJob.tx_size = 3; + srsJob.tx_data = srsTx; + srsJob.rx_size = 17 + srsBlockSize; + srsJob.rx_data = srsRx; + srsJobInProgress = true; + srsPendingCmdExec = SRS_CMDEXEC_REQDATA; + i2c_add_job(&srsJob); + break; + case SRS_DATA_STOP: + srsJob.device = srs->pI2C; + srsJob.adress = SRS_CTRL_ADDR; + srsTx[0] = SRS_CTRLCMD_REQDATA; + srsTx[1] = SRS_DATACMD_STOP; + srsTx[2] = srs_crc(srsTx, 2); + srsJob.tx_size = 3; + srsJob.tx_data = srsTx; + srsJob.rx_size = 3; + srsJob.rx_data = srsRx; + srsJobInProgress = true; + srsPendingCmdExec = SRS_CMDEXEC_REQDATA; + i2c_add_job(&srsJob); + break; + } +} + // Module L7 API - TODO: move to higher level commanding layer (Scripting!) diff --git a/ClimbObc/src/mod/srs/radsensor.h b/ClimbObc/src/mod/srs/radsensor.h index c2c778e..18c4faf 100644 --- a/ClimbObc/src/mod/srs/radsensor.h +++ b/ClimbObc/src/mod/srs/radsensor.h @@ -38,6 +38,11 @@ void srs_cmd(int argc, char *argv[]); #define EID_SRS_INTERVALS 0x06 #define EID_SRS_INTERVAL 0x07 #define EID_SRS_SHUTDOWN 0x08 +#define EID_SRS_ADDRINFO 0x09 +#define EID_SRS_TRANSFERINIT 0x0a +#define EID_SRS_BLOCKDATA 0x0b +#define EID_SRS_TRANSFERSTOP 0x0c + #define EID_SRS_ERROR 0x80 #define EID_SRS_TRANSFERBUSY 0x81 From 7e0e99ce82d2fbeba0ffdbf9fe2ba1ef32ebd54e Mon Sep 17 00:00:00 2001 From: RobertK66 Date: Tue, 12 Dec 2023 09:40:00 +0100 Subject: [PATCH 3/6] check crc and request resend if error. --- ClimbObc/src/mod/srs/radsensor.c | 68 +++++++++++++++++++++++++++----- 1 file changed, 58 insertions(+), 10 deletions(-) diff --git a/ClimbObc/src/mod/srs/radsensor.c b/ClimbObc/src/mod/srs/radsensor.c index 09ed042..4e724e8 100644 --- a/ClimbObc/src/mod/srs/radsensor.c +++ b/ClimbObc/src/mod/srs/radsensor.c @@ -91,7 +91,14 @@ static uint8_t srsRx[SRS_DATABLOCK_SIZE+20]; static uint32_t val32ToSend = 0; -typedef enum {SRS_DATA_IDLE, SRS_DATA_GETADDRESSES, SRS_DATA_INIT, SRS_DATA_BLOCKREAD, SRS_DATA_STOP, SRS_DATA_ERROR } srs_transfer_stat; +typedef enum { + SRS_DATA_IDLE, + SRS_DATA_GETADDRESSES, + SRS_DATA_INIT, + SRS_DATA_BLOCKREAD, + SRS_DATA_RESEND, + SRS_DATA_STOP, + SRS_DATA_ERROR } srs_transfer_stat; static srs_transfer_stat srsDataTransferStatus = SRS_DATA_IDLE; static uint32_t srsDataPtrStart; @@ -113,6 +120,9 @@ void srsExecuteRequestIntervals(void); void srsExecuteSendInterval(uint8_t type, uint32_t val); void srsExecuteRequestDataAddresses(void); +bool srsCheckCrc(uint16_t size); + + // Module API // ---------- void srs_init(void *initdata) { @@ -135,6 +145,7 @@ void srs_main() { SysEvent(MODULE_ID_RADSENSOR, EVENT_INFO, EID_SRS_POWEROFF, srsJob.tx_data, 2); } } else { + bool crcOk; // Controller Job finished. if (srsJob.rx_size >= 3) { // Check for errors @@ -146,6 +157,15 @@ void srs_main() { SysEvent(MODULE_ID_RADSENSOR, EVENT_ERROR, EID_SRS_ERROR, &srsJob.rx_data[1], 1); } } + if ((srsPendingCmdExec == SRS_CMDEXEC_REQDATA) && + ((srsDataTransferStatus == SRS_DATA_BLOCKREAD) || (srsDataTransferStatus == SRS_DATA_RESEND)) ) { + uint16_t size = 0; + memcpy(&size,&srsJob.rx_data[14], 2); + size += 17; + crcOk = srsCheckCrc(size); + } else { + crcOk = srsCheckCrc(srsJob.rx_size); + } switch (srsPendingCmdExec) { case SRS_CMDEXEC_SETSYNCTIME: case SRS_CMDEXEC_REQSYNCTIME: @@ -209,13 +229,16 @@ void srs_main() { srsDataTransferStatus = SRS_DATA_BLOCKREAD; srs_transfer(); } - } else if (srsDataTransferStatus == SRS_DATA_BLOCKREAD) { + } else if ( (srsDataTransferStatus == SRS_DATA_BLOCKREAD) || + (srsDataTransferStatus == SRS_DATA_RESEND) ){ if (srsJob.rx_data[1] == SRS_DATACMD_TRANSFER) { - // a valid data block - // Start addr / end addr -> into extra event - // -> CRC Check!!!! -> resend - //SysEvent(MODULE_ID_RADSENSOR, EVENT_INFO, EID_SRS_BLOCKDATA, &srsJob.rx_data[2], srsJob.rx_size-2 ); - SysEvent(MODULE_ID_RADSENSOR, EVENT_INFO, EID_SRS_BLOCKDATA, &srsJob.rx_data[2], 50 ); + if (crcOk) { + // a valid data block + srsDataTransferStatus = SRS_DATA_BLOCKREAD; + SysEvent(MODULE_ID_RADSENSOR, EVENT_INFO, EID_SRS_BLOCKDATA, &srsJob.rx_data[2], 14 ); + } else { + srsDataTransferStatus = SRS_DATA_RESEND; + } srs_transfer(); } else { // Error or no more data @@ -228,7 +251,7 @@ void srs_main() { srsDataTransferStatus = SRS_DATA_IDLE; SysEvent(MODULE_ID_RADSENSOR, EVENT_INFO, EID_SRS_TRANSFERSTOP, 0, 0); } else { - srsDataTransferStatus = SRS_DATA_ERROR; // TODO: Hoiw to clear/leave from here.....??? + srsDataTransferStatus = SRS_DATA_ERROR; // TODO: How to clear/leave from here.....??? SysEvent(MODULE_ID_RADSENSOR, EVENT_ERROR, EID_SRS_ERROR, &srsJob.rx_data[1], 1); } } @@ -388,6 +411,17 @@ uint8_t srs_crc(uint8_t *data, int len) { return ret; } + +bool srsCheckCrc(uint16_t size) { + uint8_t crcCalc = srs_crc(srsJob.rx_data, size-1); + uint8_t crcRx = srsJob.rx_data[size-1]; + + bool isOk = (crcCalc == crcRx); + return isOk; +} + + + void srsExecuteRequestSyncTime(void) { srsJob.device = srs->pI2C; // Redundant but lets do in sake of memory flips..... srsJob.adress = SRS_CTRL_ADDR; @@ -510,8 +544,8 @@ void srs_transfer() { srsTx[2] = (uint8_t)(SRS_DATABLOCK_SIZE & 0x00FF); srsTx[3] = (uint8_t)(SRS_DATABLOCK_SIZE>>8 & 0x00FF); memcpy(&srsTx[4],&srsDataPtrStart, 4); - uint32_t numBlocks = (srsDataPtrEnd - srsDataPtrStart)/SRS_DATABLOCK_SIZE; - if ((srsDataPtrEnd - srsDataPtrStart)%SRS_DATABLOCK_SIZE != 0) { + uint32_t numBlocks = (srsDataPtrEnd - srsDataPtrStart + 1)/SRS_DATABLOCK_SIZE; + if ((srsDataPtrEnd - srsDataPtrStart + 1)%SRS_DATABLOCK_SIZE != 0) { numBlocks++; } memcpy(&srsTx[8],&numBlocks, 4); @@ -544,6 +578,20 @@ void srs_transfer() { srsPendingCmdExec = SRS_CMDEXEC_REQDATA; i2c_add_job(&srsJob); break; + case SRS_DATA_RESEND: + srsJob.device = srs->pI2C; + srsJob.adress = SRS_CTRL_ADDR; + srsTx[0] = SRS_CTRLCMD_REQDATA; + srsTx[1] = SRS_DATACMD_RESEND; + srsTx[2] = srs_crc(srsTx, 2); + srsJob.tx_size = 3; + srsJob.tx_data = srsTx; + srsJob.rx_size = 17 + srsBlockSize; + srsJob.rx_data = srsRx; + srsJobInProgress = true; + srsPendingCmdExec = SRS_CMDEXEC_REQDATA; + i2c_add_job(&srsJob); + break; case SRS_DATA_STOP: srsJob.device = srs->pI2C; srsJob.adress = SRS_CTRL_ADDR; From 625e0ba0467270dc3afee69d89ca27c153950f57 Mon Sep 17 00:00:00 2001 From: RobertK66 Date: Tue, 12 Dec 2023 15:56:25 +0100 Subject: [PATCH 4/6] srs feature ready (1.0/24.9.2023) --- ClimbObc/src/ClimbObc.c | 8 ++-- ClimbObc/src/mod/srs/radsensor.c | 75 ++++++++++++++++++++++++++------ 2 files changed, 65 insertions(+), 18 deletions(-) diff --git a/ClimbObc/src/ClimbObc.c b/ClimbObc/src/ClimbObc.c index 04d3c03..832ff98 100644 --- a/ClimbObc/src/ClimbObc.c +++ b/ClimbObc/src/ClimbObc.c @@ -107,10 +107,10 @@ static const gps_initdata_t GpsInit = { 0, // PTR_FROM_IDX(PINIDX_GPIO4_CP), 0, //PTR_FROM_IDX(PINIDX_STACIE_C_IO1_P) }; - -static const thr_initdata_t ThrInit = { - LPC_UART1, ///Y+ sidepanel -}; +// +//static const thr_initdata_t ThrInit = { +// LPC_UART1, ///Y+ sidepanel +//}; static init_report_t InitReport; diff --git a/ClimbObc/src/mod/srs/radsensor.c b/ClimbObc/src/mod/srs/radsensor.c index 4e724e8..037bb58 100644 --- a/ClimbObc/src/mod/srs/radsensor.c +++ b/ClimbObc/src/mod/srs/radsensor.c @@ -64,9 +64,9 @@ // Data transfer adjustable: #define SRS_DATABLOCK_SIZE 200 // TODO: expand I2C job to uint16 rxsize!!!! 1000 // 1000 is MAX val! -#define SRS_BLOCKDELAY_MS 10 -#define SRS_BLOCKBURST_CNT 42 -#define SRS_BLOCKBURST_DEALY_MS 100 +#define SRS_BLOCKDELAY_MS 50 +#define SRS_BLOCKBURST_CNT 5 +#define SRS_BLOCKBURST_DEALY_MS 500 static uint8_t PowerOnCmd[2] = {0x00, SRS_POWERBUS_ENABLECMD}; @@ -79,6 +79,7 @@ static bool srsRequestedPowerOn = false; static bool srsJobInProgress = false; static bool srsIsPowerJob = false; +static bool srsDelayNextJob = false; static I2C_Data srsJob; @@ -106,8 +107,8 @@ static uint32_t srsDataPtrEnd; static uint16_t srsBlockSize; static uint32_t srsBlocksToRead; - - +obc_systime32_t srsNextJobTime; +static uint16_t srsBlockInBurstCnt; // local module prototypes uint8_t srs_crc(uint8_t *data, int len); @@ -119,8 +120,10 @@ void srsExecuteRequestStatus(uint8_t statusType); void srsExecuteRequestIntervals(void); void srsExecuteSendInterval(uint8_t type, uint32_t val); void srsExecuteRequestDataAddresses(void); +void srsExecuteRequestShutdown(void); bool srsCheckCrc(uint16_t size); +void srs_transfer(void); // Module API @@ -130,6 +133,15 @@ void srs_init(void *initdata) { } void srs_main() { + if (srsDelayNextJob) { + if (srsNextJobTime >= timGetSystime()) { + // Data transfer is delayed over tim ein Blocks of bursts + return; + } else { + srsDelayNextJob = false; + i2c_add_job(&srsJob); + } + } if (srsJobInProgress) { // Wait for job finishing if (srsJob.job_done == 1) { @@ -386,9 +398,7 @@ void srs_getstatus(uint8_t statusType) { } - // TODO: either direct errors or callback !? -> events - // At this moment we alwys initarte a 'download all new data' sequence. - // TODO: allow for specific Adresses to be fetched (again). + //This version starts with GETADDRSS comand an fetches all data (new) available. void srs_maketransfer(void) { if ((srsDataTransferStatus == SRS_DATA_IDLE) || (srsDataTransferStatus == SRS_DATA_ERROR)) { srsDataTransferStatus = SRS_DATA_GETADDRESSES; @@ -399,6 +409,16 @@ void srs_getstatus(uint8_t statusType) { } + //This version uses local Start and End Address (set by command) + void srs_maketransfer_presized(void) { + if ((srsDataTransferStatus == SRS_DATA_IDLE) || (srsDataTransferStatus == SRS_DATA_ERROR)) { + srsDataTransferStatus = SRS_DATA_INIT; + srs_transfer(); // Initiate next job for transfer. + } else { + SysEvent(MODULE_ID_RADSENSOR, EVENT_WARNING, EID_SRS_TRANSFERBUSY, 0, 0); + } + + } // Module local functions @@ -535,6 +555,17 @@ void srsExecuteRequestDataAddresses(void) { // This is called direct from main (after analyses of last JobFinished). So we can setup the next job here. void srs_transfer() { + // Data transfer gets executed in block-bursts with more delay all x datablock transfer jobs + srsNextJobTime = timGetSystime(); + srsBlockInBurstCnt--; + if (srsBlockInBurstCnt == 0) { + srsBlockInBurstCnt = SRS_BLOCKBURST_CNT; + srsNextJobTime += SRS_BLOCKBURST_DEALY_MS; + } else { + srsNextJobTime += SRS_BLOCKDELAY_MS; + } + srsDelayNextJob = true; + switch (srsDataTransferStatus) { case SRS_DATA_INIT: srsJob.device = srs->pI2C; @@ -556,7 +587,8 @@ void srs_transfer() { srsJob.rx_data = srsRx; srsJobInProgress = true; srsPendingCmdExec = SRS_CMDEXEC_REQDATA; - i2c_add_job(&srsJob); + srsBlockInBurstCnt = SRS_BLOCKBURST_CNT; + //i2c_add_job(&srsJob); break; case SRS_DATA_BLOCKREAD: srsJob.device = srs->pI2C; @@ -576,7 +608,7 @@ void srs_transfer() { srsJob.rx_data = srsRx; srsJobInProgress = true; srsPendingCmdExec = SRS_CMDEXEC_REQDATA; - i2c_add_job(&srsJob); + //i2c_add_job(&srsJob); break; case SRS_DATA_RESEND: srsJob.device = srs->pI2C; @@ -590,7 +622,7 @@ void srs_transfer() { srsJob.rx_data = srsRx; srsJobInProgress = true; srsPendingCmdExec = SRS_CMDEXEC_REQDATA; - i2c_add_job(&srsJob); + //i2c_add_job(&srsJob); break; case SRS_DATA_STOP: srsJob.device = srs->pI2C; @@ -604,7 +636,7 @@ void srs_transfer() { srsJob.rx_data = srsRx; srsJobInProgress = true; srsPendingCmdExec = SRS_CMDEXEC_REQDATA; - i2c_add_job(&srsJob); + //i2c_add_job(&srsJob); break; } } @@ -651,8 +683,23 @@ void srs_cmd(int argc, char *argv[]) { srs_shutdown(); break; - case 'd': - srs_maketransfer(); + case 'd': { + if (argc > 2) { + srsDataPtrStart = atol(argv[2]); + srsDataPtrEnd = srsDataPtrStart + 500; + } + if (argc > 3) { + srsDataPtrEnd = atol(argv[3]); + if (srsDataPtrEnd <= srsDataPtrStart) { + srsDataPtrEnd = srsDataPtrStart + 500; + } + } + if (argc == 2) { + srs_maketransfer(); + } else { + srs_maketransfer_presized(); + } + } break; default: From 3f33c96ffaaa28ec1603d33336018387a89422e9 Mon Sep 17 00:00:00 2001 From: RobertK66 Date: Tue, 12 Dec 2023 16:27:42 +0100 Subject: [PATCH 5/6] Update m01_debug_if.md --- doc/m01_debug_if.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/doc/m01_debug_if.md b/doc/m01_debug_if.md index 84a5e39..c644a27 100644 --- a/doc/m01_debug_if.md +++ b/doc/m01_debug_if.md @@ -63,12 +63,15 @@ Note: not all commands are available on all tagret hardware. | 'S' | \ [\] | sends a command to the SRS submodule. | | x | | | p | SRS command 'Power Off' (only commands over I2C if submodule was ON) | | x | | | P | SRS command 'Power On' (only commands over I2C if submodule was OFF) | | x | -| | T | Syncs the SRS to current OBC timestamp. (set eith 't' or over GPS-UART) | | x | -| | t | retreives the SRS unix timestamp | | x | +| | t | Syncs the SRS to current OBC timestamp. (set either with 't' or over GPS-UART) | | x | +| | T | retreives the SRS unix timestamp | | x | | | s [\] | retreives the SRS Status (type=1: default/common; 2: extended; 3: both | | x | | | I | retreives all 3 Interval data from SRS | | x | | | i [\ [\]] | sets the Interval of \ to the value (type=1:default/fgdos, 2:radfet, 3:sram) (default value: 1000) | | x | | | x | sends shutdown to SRS | | x | +| | d | initiates data transfer from SRS (gets Addresses to fetch and receives all available data) | | x | +| | d \[\] | initiates data transfer from SRS for the specified address range | | x | + @@ -141,5 +144,8 @@ where |--------------------|---------|-----------------------------| | 0x06 / 0x02 | 2 bytes | Power On executed (I2cdata) | | 0x06 / 0x03 | 2 bytes | Power Off executed (I2cdata)| +| 0x06 / 0x04 | 8 bytes | UnixTime | +| 0x06 / 0x05 | n bytes | Status info (n depends on type) | +| 0x06 / 0x06 | 3x uint32 | Intervals (answer to 'S I') | |--------------------|---------|-----------------------------| From 0f05a26836eef2bc26f0152ddee80e0045a44a03 Mon Sep 17 00:00:00 2001 From: RobertK66 Date: Tue, 12 Dec 2023 16:29:57 +0100 Subject: [PATCH 6/6] Update ci.yml dev build with OEM board without extensions --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ec2a108..a72b696 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -87,7 +87,7 @@ jobs: - kind: obc board: BA_CLIMBOBC - kind: dev - board: BA_OM13085_EM2T + board: BA_OM13085 steps: - env: OBC_VERSION: ${{needs.prepBuild.outputs.obcVersion2}}