Skip to content

Commit 8765225

Browse files
authored
Merge pull request #10633 from ganesh-ramachandran/m4g9_newfeatures
Add new features to Toshiba's TMPM4G9
2 parents 5bc30df + b4c0ce3 commit 8765225

File tree

11 files changed

+1106
-245
lines changed

11 files changed

+1106
-245
lines changed

targets/TARGET_TOSHIBA/TARGET_TMPM4G9/Periph_Driver/inc/txz_i2c_api.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ uint8_t i2c_active_t(_i2c_t *p_obj);
280280
TXZ_Result i2c_transfer_asynch_t(_i2c_t *p_obj, uint8_t *p_tx, int32_t tx_length, uint8_t *p_rx, int32_t rx_length, int32_t address, int32_t stop);
281281
uint32_t i2c_irq_handler_asynch_t(_i2c_t *p_obj);
282282
void i2c_abort_asynch_t(_i2c_t *p_obj);
283+
uint32_t set_i2c(uint8_t ch, uint32_t *p_irqn);
283284

284285
/* For slave */
285286
void i2c_slave_mode_t(_i2c_t *p_obj, int32_t enable_slave);

targets/TARGET_TOSHIBA/TARGET_TMPM4G9/Periph_Driver/src/txz_i2c_api.c

Lines changed: 27 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,6 @@ __STATIC_INLINE void set_port_ch1(i2c_port_t sda, i2c_port_t scl);
237237
__STATIC_INLINE void set_port_ch2(i2c_port_t sda, i2c_port_t scl);
238238
__STATIC_INLINE void set_port_ch3(i2c_port_t sda, i2c_port_t scl);
239239
__STATIC_INLINE void set_port_ch4(i2c_port_t sda, i2c_port_t scl);
240-
__STATIC_INLINE uint32_t set_i2c(uint8_t ch, uint32_t *p_irqn);
241240
__STATIC_INLINE void reset_asynch(_i2c_t *p_obj);
242241
__STATIC_INLINE int32_t wait_status(_i2c_t *p_obj);
243242
static void i2c_irq_handler(_i2c_t *p_obj);
@@ -574,7 +573,7 @@ __STATIC_INLINE void set_port_ch4(i2c_port_t sda, i2c_port_t scl)
574573
* @note -
575574
*/
576575
/*--------------------------------------------------*/
577-
__STATIC_INLINE uint32_t set_i2c(uint8_t ch, uint32_t *p_irqn)
576+
uint32_t set_i2c(uint8_t ch, uint32_t *p_irqn)
578577
{
579578
uint32_t instance = 0;
580579

@@ -725,7 +724,7 @@ static void i2c_irq_handler(_i2c_t *p_obj)
725724
}
726725
else
727726
{
728-
if (p_obj->tx_buff.pos < p_obj->tx_buff.length)
727+
if ((p_obj->tx_buff.pos < p_obj->tx_buff.length) || (p_obj->tx_buff.length == 0))
729728
{
730729
if (p_obj->tx_buff.pos == 0)
731730
{
@@ -740,16 +739,7 @@ static void i2c_irq_handler(_i2c_t *p_obj)
740739
}
741740
else if (p_obj->rx_buff.length != 0)
742741
{
743-
if (p_obj->tx_buff.pos == 0)
744-
{
745-
p_obj->info.asynch.event = (I2C_EVENT_ERROR | I2C_EVENT_ERROR_NO_SLAVE);
746-
p_obj->info.asynch.state = I2C_TRANSFER_STATE_IDLE;
747-
}
748-
else
749-
{
750-
p_obj->info.asynch.event = (I2C_EVENT_ERROR | I2C_EVENT_TRANSFER_EARLY_NACK);
751-
p_obj->info.asynch.state = I2C_TRANSFER_STATE_IDLE;
752-
}
742+
I2C_start_condition(&p_obj->i2c, (p_obj->info.asynch.address | 1U));
753743
}
754744
else
755745
{
@@ -1470,35 +1460,32 @@ TXZ_Result i2c_transfer_asynch_t(_i2c_t *p_obj, uint8_t *p_tx, int32_t tx_length
14701460

14711461
if (p_obj->info.asynch.state == I2C_TRANSFER_STATE_IDLE)
14721462
{
1473-
if (((p_tx != I2C_NULL) && (tx_length > 0)) || ((p_rx != I2C_NULL) && (rx_length > 0)))
1463+
reset_asynch(p_obj);
1464+
I2C_clear_int_status(&p_obj->i2c);
1465+
clear_irq(p_obj->info.irqn);
1466+
p_obj->info.asynch.address = (uint32_t)address;
1467+
p_obj->info.asynch.event = 0;
1468+
p_obj->info.asynch.stop = (uint32_t)stop;
1469+
p_obj->tx_buff.p_buffer = p_tx;
1470+
p_obj->tx_buff.length = (uint32_t)tx_length;
1471+
p_obj->tx_buff.pos = 0;
1472+
p_obj->rx_buff.p_buffer = p_rx;
1473+
p_obj->rx_buff.length = (uint32_t)rx_length;
1474+
p_obj->rx_buff.pos = 0;
1475+
p_obj->info.asynch.state = I2C_TRANSFER_STATE_BUSY;
1476+
I2C_enable_interrupt(&p_obj->i2c);
1477+
if ((tx_length == 0) && (rx_length != 0))
14741478
{
1475-
reset_asynch(p_obj);
1476-
I2C_clear_int_status(&p_obj->i2c);
1477-
clear_irq(p_obj->info.irqn);
1478-
p_obj->info.asynch.address = (uint32_t)address;
1479-
p_obj->info.asynch.event = 0;
1480-
p_obj->info.asynch.stop = (uint32_t)stop;
1481-
p_obj->tx_buff.p_buffer = p_tx;
1482-
p_obj->tx_buff.length = (uint32_t)tx_length;
1483-
p_obj->tx_buff.pos = 0;
1484-
p_obj->rx_buff.p_buffer = p_rx;
1485-
p_obj->rx_buff.length = (uint32_t)rx_length;
1486-
p_obj->rx_buff.pos = 0;
1487-
p_obj->info.asynch.state = I2C_TRANSFER_STATE_BUSY;
1488-
I2C_enable_interrupt(&p_obj->i2c);
1489-
if ((tx_length == 0) && (rx_length != 0))
1490-
{
1491-
I2C_start_condition(&p_obj->i2c, (uint32_t)((uint32_t)address | 1U));
1492-
}
1493-
else
1494-
{
1495-
I2C_start_condition(&p_obj->i2c, (uint32_t)address);
1496-
}
1497-
p_obj->info.bus_free = 0;
1498-
p_obj->info.start = 0;
1499-
enable_irq(p_obj->info.irqn);
1500-
result = TXZ_SUCCESS;
1479+
I2C_start_condition(&p_obj->i2c, (uint32_t)((uint32_t)address | 1U));
15011480
}
1481+
else
1482+
{
1483+
I2C_start_condition(&p_obj->i2c, (uint32_t)address);
1484+
}
1485+
p_obj->info.bus_free = 0;
1486+
p_obj->info.start = 0;
1487+
enable_irq(p_obj->info.irqn);
1488+
result = TXZ_SUCCESS;
15021489
}
15031490
return (result);
15041491
}

targets/TARGET_TOSHIBA/TARGET_TMPM4G9/device.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#ifndef MBED_DEVICE_H
1717
#define MBED_DEVICE_H
1818

19+
#define TRANSACTION_QUEUE_SIZE_SPI 4
1920
#define DEVICE_ID_LENGTH 32
2021

2122
#include <stddef.h>

targets/TARGET_TOSHIBA/TARGET_TMPM4G9/device/TOOLCHAIN_ARM_STD/tmpm4g9f15.sct

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ LR_IROM1 MBED_APP_START MBED_APP_SIZE ; load region size_region
4545
.ANY (+RW, +ZI)
4646
}
4747

48-
ARM_LIB_STACK (0x20000320+0x30000) EMPTY -Stack_Size { ; stack
48+
ARM_LIB_STACK (0x20000000+0x30000) EMPTY -Stack_Size { ; stack
4949
}
5050
}

targets/TARGET_TOSHIBA/TARGET_TMPM4G9/gpio_irq_api.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,14 +179,14 @@ void gpio_irq_set(gpio_irq_t *obj, gpio_irq_event event, uint32_t enable)
179179
// Get gpio interrupt event
180180
if (event == IRQ_RISE) {
181181
if ((obj->event == CG_INT_ACTIVE_STATE_FALLING) ||
182-
(obj->event == CG_INT_ACTIVE_STATE_BOTH_EDGES)) {
182+
(obj->event == CG_INT_ACTIVE_STATE_BOTH_EDGES)) {
183183
obj->event = CG_INT_ACTIVE_STATE_BOTH_EDGES;
184184
} else {
185185
obj->event = CG_INT_ACTIVE_STATE_RISING;
186186
}
187187
} else if (event == IRQ_FALL) {
188188
if ((obj->event == CG_INT_ACTIVE_STATE_RISING) ||
189-
(obj->event == CG_INT_ACTIVE_STATE_BOTH_EDGES)) {
189+
(obj->event == CG_INT_ACTIVE_STATE_BOTH_EDGES)) {
190190
obj->event = CG_INT_ACTIVE_STATE_BOTH_EDGES;
191191
} else {
192192
obj->event = CG_INT_ACTIVE_STATE_FALLING;
@@ -198,14 +198,14 @@ void gpio_irq_set(gpio_irq_t *obj, gpio_irq_event event, uint32_t enable)
198198
// Get gpio interrupt event
199199
if (event == IRQ_RISE) {
200200
if ((obj->event == CG_INT_ACTIVE_STATE_RISING) ||
201-
(obj->event == CG_INT_ACTIVE_STATE_INVALID)) {
201+
(obj->event == CG_INT_ACTIVE_STATE_INVALID)) {
202202
obj->event = CG_INT_ACTIVE_STATE_BOTH_EDGES;
203203
} else {
204204
obj->event = CG_INT_ACTIVE_STATE_FALLING;
205205
}
206206
} else if (event == IRQ_FALL) {
207207
if ((obj->event == CG_INT_ACTIVE_STATE_FALLING) ||
208-
(obj->event == CG_INT_ACTIVE_STATE_INVALID)) {
208+
(obj->event == CG_INT_ACTIVE_STATE_INVALID)) {
209209
obj->event = CG_INT_ACTIVE_STATE_BOTH_EDGES;
210210
} else {
211211
obj->event = CG_INT_ACTIVE_STATE_RISING;

0 commit comments

Comments
 (0)