David Jung
/
MAX32664C_MAXM86146_Mode1_Optical
Mode1 Optical Validation
Diff: main.cpp
- Revision:
- 27:a45d6e38f2de
- Parent:
- 26:33c0d3fd2a95
- Child:
- 28:315604f4b374
--- a/main.cpp Wed Jun 23 21:36:13 2021 +0000 +++ b/main.cpp Wed Jun 23 22:05:36 2021 +0000 @@ -150,6 +150,12 @@ /*****************************************************************************/ // read_sh_fifo /*****************************************************************************/ +/*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*/ +//#define OPTIMIZE_FIFO_READ 1 // Assume that the FIFO is filled at the specified rate, so just periodically check then number of samples in the FIFO to save power +#ifdef OPTIMIZE_FIFO_READ // tested on MAXM86146EVSYS + int32_t check_fifo_countdown; + #define MAX_FIFO_CNT 20 +#endif void read_sh_fifo(void) { char cmd[8], i, j, samples; char rsp[3000]; @@ -167,26 +173,39 @@ int32_t sptr = 0; mfio = 0; wait_us(300); Time_to_Read_PPG = 0; +#if defined(OPTIMIZE_FIFO_READ) + check_fifo_countdown--; + samples = 1; + scnt = 1; + if (check_fifo_countdown == 0) { +#endif + #if defined(MAXREFDES103_CFG) || defined(MAXM86161_CFG) // 2.1 - cmd[0] = 0x00; cmd[1] = 0x00; - sh_i2c.write(SH_ADDR, cmd, 2); - wait_us(100); - sh_i2c.read(SH_ADDR, rsp, 2); -// pc.printf("2.1 Status: %x %x\n\r", rsp[0], rsp[1]); + cmd[0] = 0x00; cmd[1] = 0x00; + sh_i2c.write(SH_ADDR, cmd, 2); + wait_us(100); + sh_i2c.read(SH_ADDR, rsp, 2); +// pc.printf("2.1 Status: %x %x\n\r", rsp[0], rsp[1]); #else // testd 33.13.12 doesn't need 2.1 #endif // 2.2 - cmd[0] = 0x12; cmd[1] = 0x00; - sh_i2c.write(SH_ADDR, cmd, 2); - wait_us(100); - sh_i2c.read(SH_ADDR, rsp, 2); -// pc.printf("2.2 Status: %x %x\n\r", rsp[0], rsp[1]); - samples = rsp[1]; -// pc.printf("num samples %d, (num*ttl)+1 %d\n\r", rsp[1], TTL_SZ*samples+1); -// pc.printf("num smpls %d \n\r", samples); - scnt = rsp[1]; + cmd[0] = 0x12; cmd[1] = 0x00; + sh_i2c.write(SH_ADDR, cmd, 2); + wait_us(100); + sh_i2c.read(SH_ADDR, rsp, 2); +// pc.printf("2.2 Status: %x %x\n\r", rsp[0], rsp[1]); + samples = rsp[1]; +// pc.printf("num samples %d, (num*ttl)+1 %d\n\r", rsp[1], TTL_SZ*samples+1); +// pc.printf("num smpls %d \n\r", samples); + scnt = rsp[1]; +#if defined(OPTIMIZE_FIFO_READ) + } + if (check_fifo_countdown <= 0) + check_fifo_countdown = MAX_FIFO_CNT; +#endif + // 2.3 cmd[0] = 0x12; cmd[1] = 0x01; sh_i2c.write(SH_ADDR, cmd, 2); @@ -320,7 +339,7 @@ ibi_offset = rsp[ptr+20]; sptr += (TTL_SZ); -#if 1 +#if 0 pc.printf("%d,%d,%d,%d,", opmode, hr, hr_conf, ibi); pc.printf("%d,%d,%d,%d,", ibi_conf, act, r, spo2_conf); pc.printf("%d,%d,%d,%d,", spo2, spo2_compl, spo2_lo, spo2_mo); @@ -374,6 +393,11 @@ void init_sh_algo(void) { char cmd[8]; char rsp[256]; + +#ifdef OPTIMIZE_FIFO_READ + check_fifo_countdown = MAX_FIFO_CNT; +#endif + // switch to application mode rst = 0; mfio = 1;