Task delay

Hi at all,
I need your help to find a solution for implement 1-wire comunication on a PIC24 based platform (flyport openPicus).
On the platform I have two tasks TASK1 and TASK2 (with 1 millisecond between each). During TASK1 I want the platform execute a block of statements that commits about 480 milliseconds (max 960). After which I need TASK1 go to sleep for the rest of its time. At this point TASK2 perform its statementes. When the kernel resume TASK1 it must perform another block of statements. I hope I was clear and you can help me…. Davide

Task delay

Not totally sure what you mean by “another” block of statements, but it sounds like one or the other of these would do for task1
void task1(void* parm){
    while(1) {
        dotask1op1();
        vTaskDelay(1);
        dotask1op2();
        vTaskDelay(1);
    }
}
or if another bock is just repeating what was done before
void task1(void* parm){
    while(1) {
        dotask1op();
        vTaskDelay(1);
    }
}
Task 2 then just needs to have a lower priority and then when task 1 blocks on the vTaskDelay it will start up.

Task delay

I have two tasks TASK1 and TASK2 (with 1 millisecond between each)
I don’t understand that statement. Do you mean the tasks have to share a 1ms time slot? Is that every ms? It is hard to get that kind of timing resolution in tasks. You would probably need a tick frequency of 4Khz, which is a bad idea as most of the processing will be tick interrupts and not tasks. At first I thought you might be better using software timers instead of task, but that has the same resolution problem. Can you put all the functionality into one task? Or use two hardware timers with the work done in a hardware timer callback?

Task delay

Hi at all and thanks for reply.
I try to explain better my problem.
I want to write a library for 1-wire comunication for openPicus Flyport module.
On this platform there are two default tasks (one for TCP/IP stack and one for the user code) with 1 millisecond switching time.
I need to synchronize the 1-wire comunication steps with the tasks switching.
(For example:
TASK1: reset pulse for the 1-wire device.
TASK2: TCP/IP stack
TASK1: send command to 1-wire device
TASK2: TCP/IP stack
TASK1: send another command or read the first byte of response from 1-wire device
TASK2: TCP/IP stack
TASK1: Read the second byte of response from 1-wire device
etc etc) I hope is clear my problem… Davide

Task delay

On flyport vTaskDelay(1) is 10 milliseconds. Davide

Task delay

I hope is clear my problem…
Not really. What does 1ms switching time mean if vTaskDelay( 1 ) is 10ms? If your timing resolution is 10ms, and both tasks have the same priority, then the kernel will switch between the tasks every 10ms. If the tasks have different priorities, then the kernel will only running the lower priority task when the higher priority task is blocked (if it is waiting on a semaphore for more TCP/IP data, for example). Your sequence looks like you just want to run the TCP/IP stack at any time there is not 1 wire processing to do. If that is the case, run the 1-wire task at a higher priority, and have the 1-wire task block (allowing the TCP/IP task to run) when it is waiting for 1-wire events. The events can come from the 1-wire interrupt, and the interrupt can give the semaphore to unblock the task.