View previous topic :: View next topic |
Author |
Message |
silelis
Joined: 12 Jun 2007 Posts: 68 Location: Poland, podlaskie district
|
I2C interrupt on MASTER |
Posted: Tue Oct 27, 2015 3:28 pm |
|
|
Hello,
I want to develop ROTS program which will support:
- TEA5767 I2C radio
- buttons (on port interrupt)
- other devices on SPI and i2c
As I said I consider ROTS but I am not sure how to handle I2C in this issue.
I mean:
If I will handle I2C communication in task there is possibility that task will be suspended by another task execution. Is it right?
I am consider if it is possible that in main loop or in same task I will make i2c communication start like:
Code: | main()
{
enable_interrupts (INT_I2C);
enable_interrupts (GLOBAL);
i2c_start(); // Start condition
i2c_write(0xa0);// Device address
// the rest of communication will be handle in interrupt function ??? is it possible??
} |
but all the rest of communication will be handled by interrupt in i2c case:
Code: | #INT_I2C
I2C_HANDLE();
void I2C_HANDLE()
{
i2c_master_state=i2c_state(); //get slave ACK(s) and base on it handle all i2c communication?
switch (2c_master_state)
case ???:
- routine 1
case ???:
-routine 2
} |
Is it possible? If Yes where I can find i2c_master_state values?
The idea which I want to achieve is like in this routine - see void I2C_IRQHandler(void) . |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19477
|
|
Posted: Wed Oct 28, 2015 2:09 am |
|
|
The RTOS is _not_ pre-emptive. Your task will not get interrupted by another task. Each task has to finish, or yield.
You are worrying about something that won't happen.
However it raises the important point that when writing RTOS tasks, each _must_ be written to ensure that it does not hang. The I2C transactions will each take only a few uSec (a write, between possibly 20uSec and 80uSec assuming you are using reasonable I2C rates), but there is one condition that can cause a hang, which is that the I2C pull-ups are not present (or a device on the bus is hung).
Look at this thread:
<http://www.ccsinfo.com/forum/viewtopic.php?t=54523>
Obviously 'how' you handle this is down to your software/hardware, but it is a possibility that must be considered. |
|
|
|