Skip to content

Commit

Permalink
Changed fram_write_enable to an extern void function
Browse files Browse the repository at this point in the history
  • Loading branch information
malcolmmackay committed Feb 7, 2021
1 parent a5897e3 commit 9603c99
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 29 deletions.
4 changes: 4 additions & 0 deletions wscodec/encoder/pyencoder/c_encoder/nvtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@

#ifndef NOT_CFFI
nv_t nv = {.serial="AAAACCCC", .seckey="AAAACCCC"};

void fram_write_enable() {}

void fram_write_disable() {}
#endif
55 changes: 26 additions & 29 deletions wscodec/encoder/pyencoder/c_encoder/sample.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,11 @@

#define BATV_RESETCAUSE(BATV, RSTC) ((BATV << 8) | (RSTC & 0xFF)) /*!< Macro for creating a 16-bit batv_resetcause value from 8-bit CODEC_FEAT_30 and CODEC_SPEC_16 values. */

#ifndef NOT_CFFI
#define FRAM_WRITE_ENABLE
#define FRAM_WRITE_DISABLE
#else
//#include <msp430.h>
#define FRAM_WRITE_ENABLE SYSCFG0 = FRWPPW | PFWP;
#define FRAM_WRITE_DISABLE SYSCFG0 = FRWPPW | DFWP | PFWP;
#endif

extern nv_t nv; /*!< Externally defined parameters stored in non-volatile memory. */
extern void fram_write_enable(void);
extern void fram_write_disable(void);



typedef enum {
Expand Down Expand Up @@ -92,7 +89,7 @@ endstop_t endstop = {0}; /*!< The 16 byte end stop. */
#pragma PERSISTENT(status)
stat_t status = {0}; /*!< Structure to hold unencoded status data. */

extern nv_t nv; /*!< Externally defined parameters stored in non-volatile memory. */



static bool one_reading_per_sample(void)
Expand All @@ -113,10 +110,10 @@ static void incr_loopcounter(void)
char statusb64[9];
uint16_t batv = batv_measure(); // Measure battery voltage

FRAM_WRITE_ENABLE
fram_write_enable();
status.loopcount += 1; // Increase loopcount by 1.
status.batv_resetcause = BATV_RESETCAUSE(batv, 0); // Clear reset cause because there has not been a reset recently.
FRAM_WRITE_DISABLE
fram_write_disable();

Base64encode(statusb64, (const char *)&status, sizeof(status)); // Base64 encode status. CHECK THIS.
ndef_writepreamble(BUFLEN_BLKS, statusb64); // Write URL in EEPROM up to the start of the circular buffer.
Expand All @@ -134,10 +131,10 @@ static void set_elapsed(unsigned int minutes)
marker.elapsedLSB = minutes & 0xFF; // Lower 8 bits of the minutes field.
marker.elapsedMSB = minutes >> 8; // Upper 8 bits of the minutes field.

FRAM_WRITE_ENABLE
fram_write_enable();
Base64encode(endstop.markerb64, (char *)&marker, sizeof(marker));
endstop.markerb64[3] = ENDSTOP_BYTE; // Change padding byte.
FRAM_WRITE_DISABLE
fram_write_disable();
}

/**
Expand All @@ -149,11 +146,11 @@ static void set_elapsed(unsigned int minutes)
*/
static void set_pair(pair_t *pair, int rd0, int rd1)
{
FRAM_WRITE_ENABLE
fram_write_enable();
pair->rd0Msb = ((rd0 >> 4) & 0xFF);
pair->rd1Msb = ((rd1 >> 4) & 0xFF);
pair->Lsb = ((rd0 & 0xF) << 4) | (rd1 & 0xF);
FRAM_WRITE_DISABLE
fram_write_disable();
}

/**
Expand All @@ -165,11 +162,11 @@ static void set_pair(pair_t *pair, int rd0, int rd1)
*/
static void set_rd1(pair_t *pair, int rd1)
{
FRAM_WRITE_ENABLE
fram_write_enable();
pair->rd1Msb = ((rd1 >> 4) & 0xFF);
pair->Lsb &= ~0x0F; // Clear low nibble of LSB.
pair->Lsb |= (rd1 & 0xF); // Set low nibble of LSB.
FRAM_WRITE_DISABLE
fram_write_disable();
}

/*!
Expand Down Expand Up @@ -199,7 +196,7 @@ void enc_init(unsigned int resetcause, bool err, unsigned int batv)
batv = batv_measure();
}

FRAM_WRITE_ENABLE
fram_write_enable();
// Initialise state variables
overwriting = 0;
npairs = 0;
Expand All @@ -208,7 +205,7 @@ void enc_init(unsigned int resetcause, bool err, unsigned int batv)
status.loopcount = 0;
status.resetsalltime = nv.resetsalltime;
status.batv_resetcause = BATV_RESETCAUSE(batv, resetcause);
FRAM_WRITE_DISABLE
fram_write_disable();

Base64encode(statusb64, (const char *)&status, sizeof(status));

Expand Down Expand Up @@ -266,9 +263,9 @@ int enc_pushsample(int rd0, int rd1)
switch(demistate)
{
case ds_looparound:
FRAM_WRITE_ENABLE
fram_write_enable();
overwriting = 1;
FRAM_WRITE_DISABLE
fram_write_disable();
break;
case ds_newloop:
incr_loopcounter();
Expand All @@ -278,9 +275,9 @@ int enc_pushsample(int rd0, int rd1)
demi_readcursor();
set_pair(&pairbuf[0], rd0, rd1);
set_pair(&pairbuf[1], 0, 0);
FRAM_WRITE_ENABLE
fram_write_enable();
npairs = overwriting ? (npairs + 1 - PAIRS_PER_DEMI) : (npairs + 1);
FRAM_WRITE_DISABLE
fram_write_disable();
pairhist_push(pairbuf[0]);
if (one_reading_per_sample())
{
Expand All @@ -300,9 +297,9 @@ int enc_pushsample(int rd0, int rd1)

case pair1_both:
set_pair(&pairbuf[1], rd0, rd1);
FRAM_WRITE_ENABLE
fram_write_enable();
npairs++;
FRAM_WRITE_DISABLE
fram_write_disable();

pairhist_push(pairbuf[1]);

Expand All @@ -329,9 +326,9 @@ int enc_pushsample(int rd0, int rd1)
// 2 samples (6 bytes) per 8 base64 bytes.
Base64encode(demi, (char *)pairbuf, sizeof(pairbuf));
// 9 bytes per 12 base64 bytes.
FRAM_WRITE_ENABLE
fram_write_enable();
Base64encode(endstop.hashnb64, (char *)&hashn, sizeof(hashn));
FRAM_WRITE_DISABLE
fram_write_disable();

set_elapsed(0);

Expand All @@ -340,9 +337,9 @@ int enc_pushsample(int rd0, int rd1)
demi_write(DEMI2, &endstop.hashnb64[8]);
demi_commit4();

FRAM_WRITE_ENABLE
fram_write_enable();
state = nextstate;
FRAM_WRITE_DISABLE
fram_write_disable();

return (demistate == ds_consecutive);
}

0 comments on commit 9603c99

Please sign in to comment.