chopstx_poll change

This commit is contained in:
NIIBE Yutaka
2016-06-28 15:48:15 +09:00
parent 40adf95c24
commit 15a4403f24
7 changed files with 42 additions and 22 deletions

View File

@@ -1,3 +1,14 @@
2016-06-28 NIIBE Yutaka <gniibe@fsij.org>
* chopstx.h (struct chx_poll_head): Declare here.
* chopstx.c (chopstx_poll): Don't use varargs, but use
an array of pointer.
(chopstx_intr_wait): Follow the change of chopstx_poll.
* eventflag.c (eventflag_wait_timeout): Likewise.
* contrib/adc-stm32f103.c (adc_wait_completion): Likewise.
* contrib/adc-mkl27z.c (adc_wait_completion): Likewise.
2016-06-16 Niibe Yutaka <gniibe@fsij.org> 2016-06-16 Niibe Yutaka <gniibe@fsij.org>
* VERSION: 1.0. * VERSION: 1.0.

11
NEWS
View File

@@ -1,6 +1,17 @@
NEWS - Noteworthy changes NEWS - Noteworthy changes
* Major changes in Chopstx 1.1
Released 2016-07-XX
** API change: chopstx_poll
In version 1.0, chopstx_poll has variable arguments. It found
that it's challenging for ffi or lower level C implementation.
An example is that a program touches FPU registers for varargs.
So, we decided to avoid use of varargs in Chopstx.
* Major changes in Chopstx 1.0 * Major changes in Chopstx 1.0
Released 2016-06-16 Released 2016-06-16

View File

@@ -335,11 +335,6 @@ struct chx_thread { /* inherits PQ */
struct chx_cleanup *clp; struct chx_cleanup *clp;
}; };
struct chx_poll_head {
uint16_t type;
uint16_t ready;
};
static void static void
chx_cpu_sched_lock (void) chx_cpu_sched_lock (void)
@@ -1464,7 +1459,7 @@ chx_intr_hook (struct chx_px *px, struct chx_poll_head *pd)
void void
chopstx_intr_wait (chopstx_intr_t *intr) chopstx_intr_wait (chopstx_intr_t *intr)
{ {
chopstx_poll (NULL, 1, intr); chopstx_poll (NULL, 1, (struct chx_poll_head **)&intr);
} }
@@ -1749,17 +1744,17 @@ chx_proxy_init (struct chx_px *px, uint32_t *cp)
* chopstx_poll - wait for condition variable, thread's exit, or IRQ * chopstx_poll - wait for condition variable, thread's exit, or IRQ
* @usec_p: Pointer to usec for timeout. Forever if NULL. * @usec_p: Pointer to usec for timeout. Forever if NULL.
* @n: Number of poll descriptors * @n: Number of poll descriptors
* @VARARGS: Pointers to an object which should be one of: * @pd_array: Pointer to an array of poll descriptor pointer which
* should be one of:
* chopstx_poll_cond_t, chopstx_poll_join_t, or chopstx_intr_t. * chopstx_poll_cond_t, chopstx_poll_join_t, or chopstx_intr_t.
* *
* Returns number of active descriptors. * Returns number of active descriptors.
*/ */
int int
chopstx_poll (uint32_t *usec_p, int n, ...) chopstx_poll (uint32_t *usec_p, int n, struct chx_poll_head *pd_array[])
{ {
uint32_t counter = 0; uint32_t counter = 0;
int i; int i;
va_list ap;
struct chx_px px[n]; struct chx_px px[n];
struct chx_poll_head *pd; struct chx_poll_head *pd;
int r = 0; int r = 0;
@@ -1769,10 +1764,9 @@ chopstx_poll (uint32_t *usec_p, int n, ...)
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
chx_proxy_init (&px[i], &counter); chx_proxy_init (&px[i], &counter);
va_start (ap, n);
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
{ {
pd = va_arg (ap, struct chx_poll_head *); pd = pd_array[i];
pd->ready = 0; pd->ready = 0;
px[i].ready_p = &pd->ready; px[i].ready_p = &pd->ready;
if (pd->type == CHOPSTX_POLL_COND) if (pd->type == CHOPSTX_POLL_COND)
@@ -1782,7 +1776,6 @@ chopstx_poll (uint32_t *usec_p, int n, ...)
else else
chx_join_hook (&px[i], pd); chx_join_hook (&px[i], pd);
} }
va_end (ap);
chx_cpu_sched_lock (); chx_cpu_sched_lock ();
chx_spin_lock (&px->lock); chx_spin_lock (&px->lock);
@@ -1818,11 +1811,9 @@ chopstx_poll (uint32_t *usec_p, int n, ...)
while (r == 0); while (r == 0);
} }
va_start (ap, n);
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
{ {
pd = va_arg (ap, struct chx_poll_head *); pd = pd_array[i];
chx_cpu_sched_lock (); chx_cpu_sched_lock ();
chx_spin_lock (&px[i].lock); chx_spin_lock (&px[i].lock);
if (pd->type == CHOPSTX_POLL_COND) if (pd->type == CHOPSTX_POLL_COND)
@@ -1864,7 +1855,6 @@ chopstx_poll (uint32_t *usec_p, int n, ...)
chx_spin_unlock (&px[i].lock); chx_spin_unlock (&px[i].lock);
chx_cpu_sched_unlock (); chx_cpu_sched_unlock ();
} }
va_end (ap);
if (r < 0) if (r < 0)
chopstx_exit (CHOPSTX_CANCELED); chopstx_exit (CHOPSTX_CANCELED);

View File

@@ -121,6 +121,11 @@ enum {
CHOPSTX_POLL_JOIN, CHOPSTX_POLL_JOIN,
}; };
struct chx_poll_head {
uint16_t type;
uint16_t ready;
};
struct chx_poll_cond { struct chx_poll_cond {
uint16_t type; uint16_t type;
uint16_t ready; uint16_t ready;
@@ -153,6 +158,6 @@ void chopstx_claim_irq (chopstx_intr_t *intr, uint8_t irq_num);
void chopstx_intr_wait (chopstx_intr_t *intr); /* DEPRECATED */ void chopstx_intr_wait (chopstx_intr_t *intr); /* DEPRECATED */
int chopstx_poll (uint32_t *usec_p, int n, ...); int chopstx_poll (uint32_t *usec_p, int n, struct chx_poll_head *pd_array[]);
#define CHOPSTX_THREAD_SIZE 64 #define CHOPSTX_THREAD_SIZE 64

View File

@@ -295,12 +295,13 @@ adc_stop (void)
int int
adc_wait_completion (void) adc_wait_completion (void)
{ {
struct chx_poll_head *pd_array[1] = { (struct chx_poll_head *)&adc_intr };
int i;
while (1) while (1)
{ {
int i;
/* Wait DMA completion */ /* Wait DMA completion */
chopstx_poll (NULL, 1, &adc_intr); chopstx_poll (NULL, 1, pd_array);
DMA0->DSR_BCR = (1 << 24); DMA0->DSR_BCR = (1 << 24);
DMA1->DSR_BCR = (1 << 24); DMA1->DSR_BCR = (1 << 24);

View File

@@ -298,10 +298,11 @@ int
adc_wait_completion (void) adc_wait_completion (void)
{ {
uint32_t flags; uint32_t flags;
struct chx_poll_head *pd_array[1] = { (struct chx_poll_head *)&adc_intr };
while (1) while (1)
{ {
chopstx_poll (NULL, 1, &adc_intr); chopstx_poll (NULL, 1, pd_array);
flags = DMA1->ISR & STM32_DMA_ISR_MASK; /* Channel 1 interrupt cause. */ flags = DMA1->ISR & STM32_DMA_ISR_MASK; /* Channel 1 interrupt cause. */
/* /*
* Clear interrupt cause of channel 1. * Clear interrupt cause of channel 1.

View File

@@ -111,9 +111,10 @@ eventmask_t
eventflag_wait_timeout (struct eventflag *ev, uint32_t usec) eventflag_wait_timeout (struct eventflag *ev, uint32_t usec)
{ {
chopstx_poll_cond_t poll_desc; chopstx_poll_cond_t poll_desc;
struct chx_poll_head *pd_array[1] = { (struct chx_poll_head *)&poll_desc };
eventflag_prepare_poll (ev, &poll_desc); eventflag_prepare_poll (ev, &poll_desc);
chopstx_poll (&usec, 1, &poll_desc); chopstx_poll (&usec, 1, pd_array);
return eventflag_get (ev); return eventflag_get (ev);
} }