i2c: Reduce __data usage by switching i2c routines to use the stack.

By default with the large memory mode, sdcc places temp data in DSEG
(__data) and parameters in XSEG (__xdata). This causes both to be placed
on the stack instead.

Previously, the temperary variables were using up to ox69 bytes in DSEG.
After the change, temperary variables now end at 0x5D (12 bytes less).

The i2c routines were using the following XSEG bytes:
- 0x03 - 0x0b (i2c_recv - 8 bytes now on the stack)
- 0x0c - 0x14 (i2c_send - 8 bytes now on the stack)
- 0x15 - 0x1e (i2c_get - 9 bytes now on the stack)
- 0x1f - 0x2c (i2c_set - 13 bytes now on the stack)
- 0x1e2 - 0x1e5 (i2c_reset - 4 bytes now on the stack)
- 0x1e6 - ? (i2c_start - ? bytes now on the stack)
This commit is contained in:
Evan Lojewski
2020-05-18 18:57:10 -06:00
committed by Jeremy Soller
parent ba5f1ab55c
commit b4689cb3f1
4 changed files with 18 additions and 18 deletions

View File

@@ -55,7 +55,7 @@ void i2c_reset(struct I2C * i2c, bool kill) {
*(i2c->hoctl2) = 0;
}
int i2c_start(struct I2C * i2c, uint8_t addr, bool read) {
int i2c_start(struct I2C * i2c, uint8_t addr, bool read) __reentrant {
// If we are already in a transaction
if (*(i2c->hosta) & HOSTA_BYTE_DONE) {
// If we are switching direction
@@ -151,10 +151,10 @@ static int i2c_transaction(struct I2C * i2c, uint8_t * data, int length, bool re
return i;
}
int i2c_read(struct I2C * i2c, uint8_t * data, int length) {
int i2c_read(struct I2C * i2c, uint8_t * data, int length) __reentrant {
return i2c_transaction(i2c, data, length, true);
}
int i2c_write(struct I2C * i2c, uint8_t * data, int length) {
int i2c_write(struct I2C * i2c, uint8_t * data, int length) __reentrant {
return i2c_transaction(i2c, data, length, false);
}

View File

@@ -47,7 +47,7 @@ void i2c_reset(struct I2C * i2c, bool kill) {
*(i2c->hoctl2) = 0;
}
int i2c_start(struct I2C * i2c, uint8_t addr, bool read) {
int i2c_start(struct I2C * i2c, uint8_t addr, bool read) __reentrant {
// If we are already in a transaction
if (*(i2c->hosta) & HOSTA_BYTE_DONE) {
// If we are switching direction
@@ -143,10 +143,10 @@ static int i2c_transaction(struct I2C * i2c, uint8_t * data, int length, bool re
return i;
}
int i2c_read(struct I2C * i2c, uint8_t * data, int length) {
int i2c_read(struct I2C * i2c, uint8_t * data, int length) __reentrant {
return i2c_transaction(i2c, data, length, true);
}
int i2c_write(struct I2C * i2c, uint8_t * data, int length) {
int i2c_write(struct I2C * i2c, uint8_t * data, int length) __reentrant {
return i2c_transaction(i2c, data, length, false);
}