Compare commits
21 Commits
release/1.
...
release/1.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aeea3c31f8 | ||
|
|
91dbfaf6b7 | ||
|
|
304441d393 | ||
|
|
4780da5b5b | ||
|
|
a4aa99f772 | ||
|
|
3315435579 | ||
|
|
bd330d81c3 | ||
|
|
078c8db5d7 | ||
|
|
53e4d1a371 | ||
|
|
2b18685cbf | ||
|
|
b6c90e3df4 | ||
|
|
4d4f82fd06 | ||
|
|
1ef6256784 | ||
|
|
1400e677e3 | ||
|
|
39683dbc5f | ||
|
|
fd98c5e162 | ||
|
|
1369361e59 | ||
|
|
2992b894e0 | ||
|
|
fffb8aa3b3 | ||
|
|
0ed2e95ea2 | ||
|
|
02aa678d4c |
28
AUTHORS
28
AUTHORS
@@ -27,19 +27,30 @@ Mateusz Zalega:
|
||||
|
||||
NIIBE Yutaka:
|
||||
Wrote the library:
|
||||
chopstx.c, entry.c, eventflag.c,
|
||||
chopstx.h, eventflag.h
|
||||
chopstx.c, chopstx.h,
|
||||
chopstx-cortex-m.c, chopstx-cortex-m.h,
|
||||
chopstx-gnu-linux.c, chopstx-gnu-linux.h,
|
||||
entry.c,
|
||||
eventflag.c, eventflag.h
|
||||
Wrote the drivers mcu/*:
|
||||
chx-gnu-linux.c, chx-mkl27z.c, chx-stm32f0.c, chx-stm32f103.c,
|
||||
clk_gpio_init-mkl27z.c, clk_gpio_init-stm32.c,
|
||||
sys-stm32f103.c, sys-stm32f030.c, sys-mkl27z.c,
|
||||
adc-stm32f103.c, adc-mkl27z.c
|
||||
cortex-m.h, mkl27z.h, stm32.h, stm32f103.h,
|
||||
sys-gnu-linux.c,sys-gnu-linux.h,
|
||||
sys-mkl27z.c, sys-mkl27z.h,
|
||||
sys-stm32f0.c, sys-stm32f0.h
|
||||
sys-stm32f103.c, sys-stm32f103.h,
|
||||
usb-stm32f103.c, usb-mkl27z.c
|
||||
Wrote the drivers:
|
||||
controb/adc-mkl27z.c
|
||||
Drew the logo:
|
||||
chopstx.svg, chopstx.png
|
||||
Wrote examples:
|
||||
example-led, example-cdc, example-fsm-55, example-fs-bb48,
|
||||
example-usb-serial
|
||||
example-usb-serial, example-cdc-gnu-linux
|
||||
Wrote board/*:
|
||||
board-fst-01.h, board-fst-01-00.h,
|
||||
board-fst-01sz.h,
|
||||
board-fst-01g.h, board-fst-01.h, board-fst-01-00.h,
|
||||
board-olimex-stm32-h103.h, board-stm8s-discovery.h
|
||||
board-cq-starm.h, board-stbee-mini.h, board-stbee.h,
|
||||
|
||||
@@ -47,9 +58,14 @@ NIIBE Yutaka:
|
||||
|
||||
board-fs-bb48.h
|
||||
|
||||
For Free Software Initiative of Japan, wrote:
|
||||
contrib/adc-stm32f103.c,
|
||||
contrib/adc-gnu-linux.c
|
||||
|
||||
Under contract of g10 Code GmbH, wrote:
|
||||
mcu/usb-usbip.c
|
||||
contrib/usart-stm32f103.c
|
||||
contrib/ackbtn-stm32f103.c
|
||||
|
||||
Paul Fertser:
|
||||
Added Blue Pill support.
|
||||
|
||||
85
ChangeLog
85
ChangeLog
@@ -1,3 +1,88 @@
|
||||
2019-03-02 NIIBE Yutaka <gniibe@fsij.org>
|
||||
|
||||
* VERSION: 1.14.
|
||||
* doc/chopstx.texi (VERSION): 1.14.
|
||||
|
||||
2019-03-01 NIIBE Yutaka <gniibe@fsij.org>
|
||||
|
||||
* contrib/usart-stm32f103.c (usart_config): Fix SCEN setting
|
||||
procedure.
|
||||
|
||||
2019-03-01 NIIBE Yutaka <gniibe@fsij.org>
|
||||
|
||||
* contrib/usart-stm32f103.c (usart_config): Support parity error
|
||||
interrupt setting.
|
||||
(usart_init): Don't call usart_config here.
|
||||
* example-usb-serial/sample.c: It's application calling
|
||||
usart_config.
|
||||
|
||||
2019-02-28 NIIBE Yutaka <gniibe@fsij.org>
|
||||
|
||||
* contrib/usart.h (BSCARD): New.
|
||||
* contrib/usart-stm32f103.c (BSCARD): Baudrate for smartcard.
|
||||
(usart_config_clken): New.
|
||||
(usart_config): Fix for MODE_SMARTCARD.
|
||||
|
||||
* board/board-st-nucleo-f103.h: Define pins for smartcard
|
||||
interface.
|
||||
|
||||
2019-02-21 NIIBE Yutaka <gniibe@fsij.org>
|
||||
|
||||
* contrib/usart.h (MODE_SMARTCARD, MODE_IRDA, MODE_IRDA_LP)
|
||||
(MASK_MODE): New.
|
||||
|
||||
* contrib/usart-stm32f103.c (usart_config): Add support for
|
||||
those modes.
|
||||
|
||||
2018-12-19 NIIBE Yutaka <gniibe@fsij.org>
|
||||
|
||||
* VERSION: 1.13.
|
||||
* doc/chopstx.texi (VERSION): 1.13.
|
||||
|
||||
2018-12-08 NIIBE Yutaka <gniibe@fsij.org>
|
||||
|
||||
* chopstx.c (chx_timer_dequeue): Fix calculation of return value.
|
||||
|
||||
2018-12-07 NIIBE Yutaka <gniibe@fsij.org>
|
||||
|
||||
* chopstx.c (chx_timer_dequeue): Return ticks remained.
|
||||
(chx_wakeup, chopstx_mutex_lock): Use return value of
|
||||
chx_timer_dequeue.
|
||||
(chx_snooze): Update *USEC_P, accordingly.
|
||||
|
||||
2018-11-12 NIIBE Yutaka <gniibe@fsij.org>
|
||||
|
||||
* VERSION: 1.12.
|
||||
* doc/chopstx.texi (VERSION): 1.12.
|
||||
|
||||
* contrib/ackbtn-stm32f103.c (ackbtn_init): Support FST-01 and
|
||||
FST-01G, using PA2.
|
||||
(ackbtn_disable): Fix to correctly clear pending interrupt.
|
||||
|
||||
2018-11-09 NIIBE Yutaka <gniibe@fsij.org>
|
||||
|
||||
* eventflag.c (eventflag_set_mask): New.
|
||||
|
||||
2018-10-02 NIIBE Yutaka <gniibe@fsij.org>
|
||||
|
||||
* VERSION: 1.11.
|
||||
* doc/chopstx.texi (VERSION): 1.11.
|
||||
|
||||
2018-10-01 NIIBE Yutaka <gniibe@fsij.org>
|
||||
|
||||
* contrib/ackbtn-stm32f103.c (PINCFG_EDGE): New.
|
||||
(ackbtn_init): Use PINCFG_EDGE bit.
|
||||
(ackbtn_enable): Configure the edge detector here.
|
||||
(ackbtn_disable): Disable the edge detector.
|
||||
|
||||
* chopstx.c (chopstx_poll): Don't clear ->ready here.
|
||||
(chx_cond_hook): Set ->ready = 0 when condition does
|
||||
not meet.
|
||||
(chopstx_claim_irq): Make sure clearing the interrupt.
|
||||
(chx_intr_hook): Add the case when ->ready == 1.
|
||||
(chopstx_intr_done): Set ->ready = 0.
|
||||
(chx_join_hook): Set ->ready = 0 when it is still alive.
|
||||
|
||||
2018-09-29 NIIBE Yutaka <gniibe@fsij.org>
|
||||
|
||||
* VERSION: 1.10.
|
||||
|
||||
63
NEWS
63
NEWS
@@ -1,11 +1,62 @@
|
||||
NEWS - Noteworthy changes
|
||||
|
||||
|
||||
* Major changes in Chopstx 1.14
|
||||
|
||||
Released 2019-03-02
|
||||
|
||||
** Enhancement of driver: USART for STM32
|
||||
Now, it supports smartcard communication.
|
||||
|
||||
|
||||
* Major changes in Chopstx 1.13
|
||||
|
||||
Released 2018-12-19
|
||||
|
||||
** API fix (redefinition): chopstx_poll
|
||||
In old implementations, when chopstx_poll returns by non-timeout
|
||||
event, *USEC_P is not updated. Now, it is updated.
|
||||
|
||||
|
||||
* Major changes in Chopstx 1.12
|
||||
|
||||
Released 2018-11-12
|
||||
|
||||
** Enhance API of eventflag
|
||||
New function eventflag_set_mask is added, so that we can only handle
|
||||
specified events. See Gnuk 1.2.12 for an example (while USB Tx is
|
||||
busy, the USB thread only accepts EV_TX_FINISHED event, leaving
|
||||
other events).
|
||||
|
||||
** Acknowledge button support for FST-01 and FST-01G
|
||||
While FST-01 and FST-01G don't have any button in the original design,
|
||||
it may be PA2 when user put a hall sensor or a switch.
|
||||
|
||||
|
||||
* Major changes in Chopstx 1.11
|
||||
|
||||
Released 2018-10-02
|
||||
|
||||
** Support calling chopstx_poll with intr->ready==1
|
||||
In version <= 1.10, it assumed that all events should be handled after
|
||||
chopstx_poll, before calling chopstx_poll again. With having
|
||||
chopstx_intr_done, it's OK now that chopstx_poll can be called again
|
||||
not examining/handling all poll descriptors, but only parts of them.
|
||||
|
||||
** Acknowledge button change
|
||||
In 1.10, the action was able to be "memorized" by the edge detector.
|
||||
Now, the edge detector is disabled by ackbtn_disable, and it is
|
||||
enabled by ackbtn_enable. So, the status is cleared correctly.
|
||||
|
||||
** New board support: FST-01SZ
|
||||
It's still under development. Programming-wise, it will be kept same.
|
||||
|
||||
|
||||
* Major changes in Chopstx 1.10
|
||||
|
||||
Released 2018-09-29
|
||||
|
||||
** Function chopstx_intr_wait is not deprecated, now.
|
||||
** Function chopstx_intr_wait is not deprecated, now
|
||||
Once, it was said that it's deprecated, but it's active again
|
||||
to match the new function of chopstx_intr_done.
|
||||
|
||||
@@ -59,7 +110,7 @@ Timer expiration had a bug. When it is waken up, the wake up doesn't
|
||||
handle as a timer expiration when there are multiple threads on same
|
||||
timing of expire. It confuses as if it were forced wakeup.
|
||||
|
||||
** New driver: USART for STM32.
|
||||
** New driver: USART for STM32
|
||||
USART driver for STM32 is added.
|
||||
|
||||
|
||||
@@ -394,11 +445,11 @@ Vectored Interrupt Controller (NVIC), in the ARM v7-M Architecture
|
||||
Reference Manual. The subsection, B3.4.1, Theory of operation,
|
||||
explains how it works.
|
||||
|
||||
|
||||
** gpio_init change
|
||||
Now, gpi_init support AFIO mapping and another GPIO (GPIO_OTHER)
|
||||
settings.
|
||||
|
||||
Local Variables:
|
||||
mode: outline
|
||||
End:
|
||||
|
||||
# Local Variables:
|
||||
# mode: outline
|
||||
# End:
|
||||
|
||||
4
README
4
README
@@ -1,6 +1,6 @@
|
||||
Chopstx - Threads and only Threads
|
||||
Version 1.10
|
||||
2018-09-29
|
||||
Version 1.14
|
||||
2018-03-02
|
||||
Niibe Yutaka
|
||||
Flying Stone Technology
|
||||
|
||||
|
||||
@@ -49,17 +49,26 @@
|
||||
* Port B setup.
|
||||
* PB0 - input with pull-up: AN8 for NeuG
|
||||
* PB1 - input with pull-up: AN9 for NeuG
|
||||
* PB10 - Alternate function push pull output 2MHz USART3-TX
|
||||
* ---
|
||||
* ---
|
||||
* PB4 - Input with pull-up: Card insertion detect: 0 when detected
|
||||
* ---
|
||||
* PB6 - Output push pull 2MHz: Vcc for card: default 0
|
||||
* ---
|
||||
* PB8 - Output push pull 2MHz: Vpp for card: default 0
|
||||
* PB9 - Output push pull 2MHz: RST for card: default 0
|
||||
* PB10 - Alternate function open-drain output 50MHz USART3-TX
|
||||
* PB11 - Input with pull-up USART3-RX
|
||||
* PB12 - Alternate function push pull output 2MHz USART3-CK
|
||||
* PB12 - Alternate function push pull output 50MHz USART3-CK
|
||||
* PB13 - Input with pull-up USART3-CTS
|
||||
* PB14 - Alternate function push pull output 2MHz USART3-RTS
|
||||
* PB14 - Alternate function push pull output 50MHz USART3-RTS
|
||||
* ---
|
||||
* ------------------------ Default
|
||||
* PBx - input with pull-up.
|
||||
*/
|
||||
#define VAL_GPIO_OTHER_ODR 0xFFFFFFFF
|
||||
#define VAL_GPIO_OTHER_CRL 0x88888888 /* PB7...PB0 */
|
||||
#define VAL_GPIO_OTHER_CRH 0x8A8A8A88 /* PB15...PB8 */
|
||||
#define VAL_GPIO_OTHER_ODR 0xFFFFFCBF
|
||||
#define VAL_GPIO_OTHER_CRL 0x82888888 /* PB7...PB0 */
|
||||
#define VAL_GPIO_OTHER_CRH 0x8B8B8F22 /* PB15...PB8 */
|
||||
|
||||
#define RCC_ENR_IOP_EN (RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPBEN)
|
||||
#define RCC_RSTR_IOP_RST (RCC_APB2RSTR_IOPARST | RCC_APB2RSTR_IOPBRST)
|
||||
|
||||
@@ -293,8 +293,8 @@ chx_request_preemption (uint16_t prio)
|
||||
* AAPCS: ARM Architecture Procedure Call Standard
|
||||
*
|
||||
* Returns:
|
||||
* 1 on wakeup by others.
|
||||
* 0 on normal wakeup (timer expiration, lock aquirement).
|
||||
* >= 1 on wakeup by others, value means ticks remained for sleep.
|
||||
* 0 on normal wakeup (timer expiration, lock acquirement).
|
||||
* -1 on cancellation.
|
||||
*/
|
||||
static uintptr_t __attribute__ ((naked, noinline))
|
||||
|
||||
72
chopstx.c
72
chopstx.c
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* chopstx.c - Threads and only threads.
|
||||
*
|
||||
* Copyright (C) 2013, 2014, 2015, 2016, 2017, 2018
|
||||
* Copyright (C) 2013, 2014, 2015, 2016, 2017, 2018, 2019
|
||||
* Flying Stone Technology
|
||||
* Author: NIIBE Yutaka <gniibe@fsij.org>
|
||||
*
|
||||
@@ -107,7 +107,7 @@ static struct chx_queue q_intr;
|
||||
static void chx_request_preemption (uint16_t prio);
|
||||
static int chx_wakeup (struct chx_pq *p);
|
||||
static struct chx_thread * chx_timer_insert (struct chx_thread *tp, uint32_t usec);
|
||||
static void chx_timer_dequeue (struct chx_thread *tp);
|
||||
static uint32_t chx_timer_dequeue (struct chx_thread *tp);
|
||||
|
||||
|
||||
|
||||
@@ -349,29 +349,35 @@ chx_timer_insert (struct chx_thread *tp, uint32_t usec)
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
static uint32_t
|
||||
chx_timer_dequeue (struct chx_thread *tp)
|
||||
{
|
||||
struct chx_thread *tp_prev;
|
||||
uint32_t ticks_remained;
|
||||
|
||||
chx_spin_lock (&q_timer.lock);
|
||||
ticks_remained = chx_systick_get ();
|
||||
tp_prev = (struct chx_thread *)tp->prev;
|
||||
if (tp_prev == (struct chx_thread *)&q_timer.q)
|
||||
{
|
||||
if (tp->next == (struct chx_pq *)&q_timer.q)
|
||||
chx_set_timer (tp_prev, 0); /* Cancel timer*/
|
||||
chx_systick_reload (0); /* Cancel timer. */
|
||||
else
|
||||
{ /* Update timer. */
|
||||
uint32_t next_ticks = chx_systick_get () + tp->v;
|
||||
chx_systick_reload (ticks_remained + tp->v); /* Update timer. */
|
||||
}
|
||||
else
|
||||
{
|
||||
struct chx_pq *p;
|
||||
|
||||
for (p = q_timer.q.next; p != (struct chx_pq *)tp; p = p->next)
|
||||
ticks_remained += p->v;
|
||||
|
||||
chx_set_timer (tp_prev, next_ticks);
|
||||
}
|
||||
}
|
||||
else
|
||||
tp_prev->v += tp->v;
|
||||
}
|
||||
ll_dequeue ((struct chx_pq *)tp);
|
||||
tp->v = 0;
|
||||
chx_spin_unlock (&q_timer.lock);
|
||||
return ticks_remained;
|
||||
}
|
||||
|
||||
|
||||
@@ -502,9 +508,11 @@ chx_wakeup (struct chx_pq *pq)
|
||||
tp = px->master;
|
||||
if (tp->state == THREAD_WAIT_POLL)
|
||||
{
|
||||
tp->v = (uintptr_t)1;
|
||||
if (tp->parent == &q_timer.q)
|
||||
chx_timer_dequeue (tp);
|
||||
tp->v = (uintptr_t)chx_timer_dequeue (tp);
|
||||
else
|
||||
tp->v = (uintptr_t)1;
|
||||
|
||||
chx_ready_enqueue (tp);
|
||||
if (!running || tp->prio > running->prio)
|
||||
yield = 1;
|
||||
@@ -559,19 +567,21 @@ chx_exit (void *retval)
|
||||
|
||||
/*
|
||||
* Lower layer mutex unlocking. Called with schedule lock held.
|
||||
* Return PRIO of the thread which is waken up.
|
||||
*/
|
||||
static chopstx_prio_t
|
||||
chx_mutex_unlock (chopstx_mutex_t *mutex)
|
||||
{
|
||||
struct chx_thread *tp;
|
||||
chopstx_prio_t prio = 0;
|
||||
|
||||
mutex->owner = NULL;
|
||||
running->mutex_list = mutex->list;
|
||||
mutex->list = NULL;
|
||||
|
||||
tp = (struct chx_thread *)ll_pop (&mutex->q);
|
||||
if (tp)
|
||||
if (!tp)
|
||||
return 0;
|
||||
else
|
||||
{
|
||||
uint16_t newprio = running->prio_orig;
|
||||
chopstx_mutex_t *m;
|
||||
@@ -587,11 +597,8 @@ chx_mutex_unlock (chopstx_mutex_t *mutex)
|
||||
/* Then, assign it. */
|
||||
running->prio = newprio;
|
||||
|
||||
if (prio < tp->prio)
|
||||
prio = tp->prio;
|
||||
return tp->prio;
|
||||
}
|
||||
|
||||
return prio;
|
||||
}
|
||||
|
||||
#define CHOPSTX_PRIO_MASK ((1 << CHOPSTX_PRIO_BITS) - 1)
|
||||
@@ -679,6 +686,11 @@ chx_snooze (uint32_t state, uint32_t *usec_p)
|
||||
r = chx_sched (CHX_SLEEP);
|
||||
if (r == 0)
|
||||
*usec_p -= usec0;
|
||||
else if (r > 0)
|
||||
{
|
||||
*usec_p -= (usec0 - r / MHZ);
|
||||
r = 1;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
@@ -803,9 +815,10 @@ chopstx_mutex_lock (chopstx_mutex_t *mutex)
|
||||
if (tp0->state == THREAD_WAIT_TIME
|
||||
|| tp0->state == THREAD_WAIT_POLL)
|
||||
{
|
||||
tp0->v = (uintptr_t)1;
|
||||
if (tp0->parent == &q_timer.q)
|
||||
chx_timer_dequeue (tp0);
|
||||
tp0->v = (uintptr_t)chx_timer_dequeue (tp0);
|
||||
else
|
||||
tp0->v = (uintptr_t)1;
|
||||
|
||||
chx_ready_enqueue (tp0);
|
||||
tp0 = NULL;
|
||||
@@ -969,6 +982,7 @@ chx_cond_hook (struct chx_px *px, struct chx_poll_head *pd)
|
||||
{ /* Condition doesn't met.
|
||||
* Register the proxy to wait for the condition.
|
||||
*/
|
||||
pc->ready = 0;
|
||||
chx_cpu_sched_lock ();
|
||||
chx_spin_lock (&pc->cond->lock);
|
||||
ll_prio_enqueue ((struct chx_pq *)px, &pc->cond->q);
|
||||
@@ -998,6 +1012,7 @@ chopstx_claim_irq (chopstx_intr_t *intr, uint8_t irq_num)
|
||||
chx_cpu_sched_lock ();
|
||||
chx_spin_lock (&q_intr.lock);
|
||||
chx_disable_intr (irq_num);
|
||||
chx_clr_intr (irq_num);
|
||||
chx_set_intr_prio (irq_num);
|
||||
chx_spin_unlock (&q_intr.lock);
|
||||
chx_cpu_sched_unlock ();
|
||||
@@ -1012,10 +1027,19 @@ chx_intr_hook (struct chx_px *px, struct chx_poll_head *pd)
|
||||
chopstx_testcancel ();
|
||||
chx_cpu_sched_lock ();
|
||||
px->v = intr->irq_num;
|
||||
if (intr->ready)
|
||||
{
|
||||
chx_spin_lock (&px->lock);
|
||||
(*px->counter_p)++;
|
||||
chx_spin_unlock (&px->lock);
|
||||
}
|
||||
else
|
||||
{
|
||||
chx_spin_lock (&q_intr.lock);
|
||||
ll_prio_enqueue ((struct chx_pq *)px, &q_intr.q);
|
||||
chx_enable_intr (intr->irq_num);
|
||||
chx_spin_unlock (&q_intr.lock);
|
||||
}
|
||||
chx_cpu_sched_unlock ();
|
||||
}
|
||||
|
||||
@@ -1047,7 +1071,10 @@ chopstx_intr_done (chopstx_intr_t *intr)
|
||||
chx_dmb ();
|
||||
|
||||
if (intr->ready)
|
||||
{
|
||||
chx_clr_intr (intr->irq_num);
|
||||
intr->ready = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1215,6 +1242,7 @@ chx_join_hook (struct chx_px *px, struct chx_poll_head *pd)
|
||||
{ /* Not yet exited.
|
||||
* Register the proxy to wait for TP's exit.
|
||||
*/
|
||||
pj->ready = 0;
|
||||
px->v = (uintptr_t)tp;
|
||||
chx_spin_lock (&q_join.lock);
|
||||
ll_prio_enqueue ((struct chx_pq *)px, &q_join.q);
|
||||
@@ -1332,7 +1360,8 @@ chx_proxy_init (struct chx_px *px, uint32_t *cp)
|
||||
|
||||
/**
|
||||
* 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. It is
|
||||
* updated on return
|
||||
* @n: Number of poll descriptors
|
||||
* @pd_array: Pointer to an array of poll descriptor pointer which
|
||||
* should be one of:
|
||||
@@ -1358,7 +1387,6 @@ chopstx_poll (uint32_t *usec_p, int n, struct chx_poll_head *const pd_array[])
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
pd = pd_array[i];
|
||||
pd->ready = 0;
|
||||
px[i].ready_p = &pd->ready;
|
||||
if (pd->type == CHOPSTX_POLL_COND)
|
||||
chx_cond_hook (&px[i], pd);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* chopstx.h - Threads and only threads.
|
||||
*
|
||||
* Copyright (C) 2013, 2016, 2017 Flying Stone Technology
|
||||
* Copyright (C) 2013, 2016, 2017, 2018 Flying Stone Technology
|
||||
* Author: NIIBE Yutaka <gniibe@fsij.org>
|
||||
*
|
||||
* This file is a part of Chopstx, a thread library for embedded.
|
||||
|
||||
@@ -34,7 +34,17 @@
|
||||
#include "board.h"
|
||||
#include "sys.h"
|
||||
|
||||
/*
|
||||
* All EXTI registers (EXTI_IMR, EXTI_EMR, EXTI_PR , EXTI_RTSR, and
|
||||
* EXTI_FTSR) have same structure, where each bit of X is used for
|
||||
* line X, from 0 up to 19.
|
||||
*
|
||||
* We use 31-bit of PIN_CONFIG to represent if it's for rising edge or
|
||||
* falling edge.
|
||||
*/
|
||||
static uint32_t pin_config;
|
||||
#define PINCFG_EDGE 0x80000000
|
||||
#define PINCFG_EDGE_RISING PINCFG_EDGE
|
||||
|
||||
void
|
||||
ackbtn_init (chopstx_intr_t *intr)
|
||||
@@ -42,10 +52,19 @@ ackbtn_init (chopstx_intr_t *intr)
|
||||
uint8_t irq_num;
|
||||
uint32_t afio_exticr_index;
|
||||
uint32_t afio_exticr_extiX_pY;
|
||||
int rising_edge;
|
||||
|
||||
switch (SYS_BOARD_ID)
|
||||
{
|
||||
case BOARD_ID_FST_01:
|
||||
case BOARD_ID_FST_01G:
|
||||
/* PA2 can be connected to a hall sensor or a switch */
|
||||
afio_exticr_index = 0;
|
||||
afio_exticr_extiX_pY = AFIO_EXTICR1_EXTI2_PA;
|
||||
irq_num = EXTI2_IRQ;
|
||||
pin_config = 0x0004; /* EXTI_PR_PR2 == EXTI_IMR_MR2 == EXTI_RTSR_TR2 */
|
||||
pin_config |= PINCFG_EDGE_RISING;
|
||||
break;
|
||||
|
||||
case BOARD_ID_FST_01SZ:
|
||||
default:
|
||||
/* PA3 is connected to a hall sensor DRV5032FA */
|
||||
@@ -53,36 +72,44 @@ ackbtn_init (chopstx_intr_t *intr)
|
||||
afio_exticr_extiX_pY = AFIO_EXTICR1_EXTI3_PA;
|
||||
irq_num = EXTI3_IRQ;
|
||||
pin_config = 0x0008; /* EXTI_PR_PR3 == EXTI_IMR_MR3 == EXTI_RTSR_TR3 */
|
||||
rising_edge = 1;
|
||||
pin_config |= PINCFG_EDGE_RISING;
|
||||
break;
|
||||
}
|
||||
|
||||
chopstx_claim_irq (intr, irq_num);
|
||||
|
||||
/* Configure EXTI line */
|
||||
if (afio_exticr_extiX_pY)
|
||||
AFIO->EXTICR[afio_exticr_index] |= afio_exticr_extiX_pY;
|
||||
|
||||
/* Interrupt is masked, now */
|
||||
EXTI->IMR &= ~pin_config;
|
||||
EXTI->IMR &= ~(pin_config & ~PINCFG_EDGE);
|
||||
|
||||
/* Configure which edge is detected */
|
||||
if (rising_edge)
|
||||
EXTI->RTSR |= pin_config;
|
||||
else
|
||||
EXTI->FTSR |= pin_config;
|
||||
chopstx_claim_irq (intr, irq_num);
|
||||
}
|
||||
|
||||
void
|
||||
ackbtn_enable (void)
|
||||
{
|
||||
EXTI->PR |= pin_config; /* Clear pending interrupt */
|
||||
EXTI->IMR |= pin_config; /* Enable interrupt clearing the mask */
|
||||
/* Clear pending interrupt */
|
||||
EXTI->PR |= (pin_config & ~PINCFG_EDGE);
|
||||
/* Enable interrupt, clearing the mask */
|
||||
EXTI->IMR |= (pin_config & ~PINCFG_EDGE);
|
||||
|
||||
/* Configure which edge is detected */
|
||||
if ((pin_config & PINCFG_EDGE))
|
||||
EXTI->RTSR |= (pin_config & ~PINCFG_EDGE);
|
||||
else
|
||||
EXTI->FTSR |= (pin_config & ~PINCFG_EDGE);
|
||||
}
|
||||
|
||||
void
|
||||
ackbtn_disable (void)
|
||||
{
|
||||
EXTI->IMR &= ~pin_config; /* Disable interrupt having the mask */
|
||||
EXTI->PR |= pin_config; /* Clear pending interrupt */
|
||||
/* Disable interrupt having the mask */
|
||||
EXTI->IMR &= ~(pin_config & ~PINCFG_EDGE);
|
||||
/* Clear pending interrupt */
|
||||
EXTI->PR |= (pin_config & ~PINCFG_EDGE);
|
||||
|
||||
/* Disable edge detection */
|
||||
EXTI->RTSR &= ~(pin_config & ~PINCFG_EDGE);
|
||||
EXTI->FTSR &= ~(pin_config & ~PINCFG_EDGE);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* usart-stm32.c - USART driver for STM32F103 (USART2 and USART3)
|
||||
*
|
||||
* Copyright (C) 2017 g10 Code GmbH
|
||||
* Copyright (C) 2017, 2019 g10 Code GmbH
|
||||
* Author: NIIBE Yutaka <gniibe@fsij.org>
|
||||
*
|
||||
* This file is a part of Chopstx, a thread library for embedded.
|
||||
@@ -104,6 +104,7 @@ static const struct brr_setting brr_table[] = {
|
||||
{ B230400, ( 9 << 4)|12},
|
||||
{ B460800, ( 4 << 4)|14},
|
||||
{ B921600, ( 2 << 4)|7},
|
||||
{ BSCARD, ( 232 << 4)|8},
|
||||
};
|
||||
|
||||
static void *usart_main (void *arg);
|
||||
@@ -111,6 +112,18 @@ static void *usart_main (void *arg);
|
||||
static struct usart_stat usart2_stat;
|
||||
static struct usart_stat usart3_stat;
|
||||
|
||||
void
|
||||
usart_config_clken (uint8_t dev_no, int on)
|
||||
{
|
||||
struct USART *USARTx = get_usart_dev (dev_no);
|
||||
|
||||
if (on)
|
||||
USARTx->CR2 |= (1 << 11);
|
||||
else
|
||||
USARTx->CR2 &= ~(1 << 11);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
usart_config (uint8_t dev_no, uint32_t config_bits)
|
||||
{
|
||||
@@ -136,9 +149,9 @@ usart_config (uint8_t dev_no, uint32_t config_bits)
|
||||
return -1;
|
||||
|
||||
if ((config_bits & PARENB) == 0)
|
||||
cr1_config &= ~USART_CR1_PCE;
|
||||
cr1_config &= ~(USART_CR1_PCE | USART_CR1_PEIE);
|
||||
else
|
||||
cr1_config |= USART_CR1_PCE;
|
||||
cr1_config |= (USART_CR1_PCE | USART_CR1_PEIE);
|
||||
|
||||
if ((config_bits & PARODD) == 0)
|
||||
cr1_config &= ~USART_CR1_PS;
|
||||
@@ -169,6 +182,21 @@ usart_config (uint8_t dev_no, uint32_t config_bits)
|
||||
USARTx->CR3 = 0;
|
||||
|
||||
USARTx->CR1 = cr1_config;
|
||||
|
||||
/* SCEN (smartcard enable) should be set _after_ CR1. */
|
||||
if ((config_bits & MASK_MODE))
|
||||
{
|
||||
if ((config_bits & MASK_MODE) == MODE_SMARTCARD)
|
||||
{
|
||||
USARTx->GTPR = (16 << 8) | 5;
|
||||
USARTx->CR3 |= ((1 << 5) | (1 << 4));
|
||||
}
|
||||
else if ((config_bits & MASK_MODE) == MODE_IRDA)
|
||||
USARTx->CR3 |= (1 << 1);
|
||||
else if ((config_bits & MASK_MODE) == MODE_IRDA_LP)
|
||||
USARTx->CR3 |= (1 << 2) | (1 << 1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -187,8 +215,6 @@ usart_init (uint16_t prio, uintptr_t stack_addr, size_t stack_size,
|
||||
RCC->APB1RSTR = ((1 << 18) | (1 << 17));
|
||||
RCC->APB1RSTR = 0;
|
||||
|
||||
usart_config (2, B115200 | CS8 | STOP1B);
|
||||
usart_config (3, B115200 | CS8 | STOP1B);
|
||||
chopstx_create (prio, stack_addr, stack_size, usart_main, NULL);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#define B230400 26
|
||||
#define B460800 27
|
||||
#define B921600 28
|
||||
#define BSCARD 63
|
||||
#define MASK_BAUD 0x3f
|
||||
|
||||
/* POSIX supports 5, 6. USB suppots 16 */
|
||||
@@ -43,6 +44,13 @@ PAR_BITS 3
|
||||
/* USB: SERIAL_STATE
|
||||
DSR DCD RI */
|
||||
|
||||
/* non-POSIX, non-USB-CDC configs */
|
||||
#define MODE_SMARTCARD (1 << 30)
|
||||
#define MODE_IRDA (2UL << 30)
|
||||
#define MODE_IRDA_LP (3UL << 30)
|
||||
#define MASK_MODE (0x3UL << 30)
|
||||
/* 0: standard, 1: smartcard, 2: IrDA, 3: IrDA-LP */
|
||||
|
||||
struct usart_stat {
|
||||
uint8_t dev_no;
|
||||
|
||||
@@ -64,3 +72,4 @@ int usart_read (uint8_t dev_no, char *buf, uint16_t buflen);
|
||||
int usart_write (uint8_t dev_no, char *buf, uint16_t buflen);
|
||||
const struct usart_stat *usart_stat (uint8_t dev_no);
|
||||
int usart_send_break (uint8_t dev_no);
|
||||
void usart_config_clken (uint8_t dev_no, int on);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
\input texinfo @c -*-texinfo-*-
|
||||
@c %**start of header
|
||||
@setfilename chopstx.info
|
||||
@set VERSION 1.10
|
||||
@set VERSION 1.14
|
||||
@settitle Chopstx Reference Manual
|
||||
@c Unify some of the indices.
|
||||
@syncodeindex tp fn
|
||||
|
||||
26
eventflag.c
26
eventflag.c
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* eventflag.c - Eventflag
|
||||
*
|
||||
* Copyright (C) 2013, 2016 Flying Stone Technology
|
||||
* Copyright (C) 2013, 2016, 2018 Flying Stone Technology
|
||||
* Author: NIIBE Yutaka <gniibe@fsij.org>
|
||||
*
|
||||
* This file is a part of Chopstx, a thread library for embedded.
|
||||
@@ -36,17 +36,29 @@ void
|
||||
eventflag_init (struct eventflag *ev)
|
||||
{
|
||||
ev->flags = 0;
|
||||
ev->mask = ~0;
|
||||
chopstx_cond_init (&ev->cond);
|
||||
chopstx_mutex_init (&ev->mutex);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
eventflag_set_mask (struct eventflag *ev, eventmask_t m)
|
||||
{
|
||||
chopstx_mutex_lock (&ev->mutex);
|
||||
ev->mask = m;
|
||||
if ((ev->flags & ev->mask))
|
||||
chopstx_cond_signal (&ev->cond);
|
||||
chopstx_mutex_unlock (&ev->mutex);
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
eventflag_check (void *arg)
|
||||
{
|
||||
struct eventflag *ev = arg;
|
||||
|
||||
return ev->flags != 0;
|
||||
return (ev->flags & ev->mask) != 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -62,6 +74,9 @@ eventflag_prepare_poll (struct eventflag *ev, chopstx_poll_cond_t *poll_desc)
|
||||
}
|
||||
|
||||
|
||||
/* When multiple events are marked, event with lower bit has precedence.
|
||||
Because __builtin_ffs returns the least significant 1-bit. */
|
||||
|
||||
eventmask_t
|
||||
eventflag_get (struct eventflag *ev)
|
||||
{
|
||||
@@ -69,7 +84,7 @@ eventflag_get (struct eventflag *ev)
|
||||
eventmask_t m;
|
||||
|
||||
chopstx_mutex_lock (&ev->mutex);
|
||||
n = __builtin_ffs (ev->flags);
|
||||
n = __builtin_ffs ((ev->flags & ev->mask));
|
||||
if (n)
|
||||
{
|
||||
m = (1 << (n - 1));
|
||||
@@ -90,10 +105,10 @@ eventflag_wait (struct eventflag *ev)
|
||||
eventmask_t m;
|
||||
|
||||
chopstx_mutex_lock (&ev->mutex);
|
||||
if (!ev->flags)
|
||||
while (!(ev->flags & ev->mask))
|
||||
chopstx_cond_wait (&ev->cond, &ev->mutex);
|
||||
|
||||
n = __builtin_ffs (ev->flags);
|
||||
n = __builtin_ffs ((ev->flags & ev->mask));
|
||||
if (n) /* Always n > 0 when waked up, but make sure no bad things. */
|
||||
{
|
||||
m = (1 << (n - 1));
|
||||
@@ -124,6 +139,7 @@ eventflag_signal (struct eventflag *ev, eventmask_t m)
|
||||
{
|
||||
chopstx_mutex_lock (&ev->mutex);
|
||||
ev->flags |= m;
|
||||
if ((ev->flags & ev->mask))
|
||||
chopstx_cond_signal (&ev->cond);
|
||||
chopstx_mutex_unlock (&ev->mutex);
|
||||
}
|
||||
|
||||
@@ -2,11 +2,13 @@ typedef uint32_t eventmask_t;
|
||||
|
||||
struct eventflag {
|
||||
eventmask_t flags;
|
||||
eventmask_t mask;
|
||||
chopstx_mutex_t mutex;
|
||||
chopstx_cond_t cond;
|
||||
};
|
||||
|
||||
void eventflag_init (struct eventflag *ev);
|
||||
void eventflag_set_mask (struct eventflag *ev, eventmask_t m);
|
||||
eventmask_t eventflag_wait (struct eventflag *ev);
|
||||
eventmask_t eventflag_wait_timeout (struct eventflag *ev, uint32_t usec);
|
||||
void eventflag_signal (struct eventflag *ev, eventmask_t m);
|
||||
|
||||
@@ -1,12 +1,19 @@
|
||||
This is an application example using ST Nucleo F103 board.
|
||||
|
||||
SB62 and SB63 should be soldered.
|
||||
ST-Link/V2 is disconnected (SB13 and SB14).
|
||||
SB62 and SB63 should be soldered to connect PA2 and PA3 to CN10
|
||||
connector.
|
||||
|
||||
ST-Link/V2's TX and RX are disconnected (by removing SB13 and SB14).
|
||||
|
||||
Smartcard can be connected, by using USART3_TX for I/O and USART3_CK
|
||||
for CLK, PB6 for Vcc, PB8 for Vpp, and PB9 for RST.
|
||||
|
||||
|
||||
NOTE:
|
||||
|
||||
Using the USB CDC-ACM for serial communication is a kind of wrong,
|
||||
because it's designed for modem; No way to control CTSRTS.
|
||||
because it's designed for modem; In the protocol, we have no way to
|
||||
control the CTSRTS signal.
|
||||
|
||||
TIOCGICOUNT
|
||||
|
||||
@@ -19,4 +26,4 @@ TODO:
|
||||
* stats report control
|
||||
By vendor specific control?
|
||||
* Half-duplex support
|
||||
* Support of other communication mode: smartcard, IrDA, etc.
|
||||
* Support of other communication mode: IrDA, etc.
|
||||
|
||||
@@ -238,6 +238,9 @@ main (int argc, const char *argv[])
|
||||
|
||||
usart_init (PRIO_USART, STACK_ADDR_USART, STACK_SIZE_USART, ss_notify);
|
||||
|
||||
usart_config (2, B115200 | CS8 | STOP1B);
|
||||
usart_config (3, B115200 | CS8 | STOP1B);
|
||||
|
||||
cdc_usart0.cdc = cdc_open (0);
|
||||
cdc_usart0.dev_no = 2;
|
||||
cdc_usart1.cdc = cdc_open (1);
|
||||
|
||||
@@ -23,14 +23,14 @@
|
||||
#include "board.h"
|
||||
|
||||
#define ADDR_VECTORS (0x00000900)
|
||||
#define ADDR_SCR_VTOR 0xe000ed08
|
||||
#define ADDR_SCB_VTOR 0xe000ed08
|
||||
|
||||
static void __attribute__ ((naked,section(".fixed_function.reset")))
|
||||
reset (void)
|
||||
{
|
||||
uint32_t r3 = ADDR_SCR_VTOR;
|
||||
uint32_t r3 = ADDR_SCB_VTOR;
|
||||
|
||||
asm volatile ("str %2, [%0]\n\t" /* Set SCR->VTOR */
|
||||
asm volatile ("str %2, [%0]\n\t" /* Set SCB->VTOR */
|
||||
"ldr %0, [%2]\n\t" /* Stack address */
|
||||
"msr MSP, %0\n\t" /* Exception handler stack. */
|
||||
"ldr %0, [%2, #4]\n\t" /* The entry address */
|
||||
|
||||
@@ -340,13 +340,13 @@ reset (void)
|
||||
#else
|
||||
extern const uint32_t FT0[256], FT1[256], FT2[256];
|
||||
asm volatile ("cpsid i\n\t" /* Mask all interrupts. */
|
||||
"ldr r0, 1f\n\t" /* r0 = SCR */
|
||||
"ldr r0, 1f\n\t" /* r0 = SCB start */
|
||||
"mov r1, pc\n\t" /* r1 = (PC + 0x1000) & ~0x0fff */
|
||||
"mov r2, #0x1000\n\t"
|
||||
"add r1, r1, r2\n\t"
|
||||
"sub r2, r2, #1\n\t"
|
||||
"bic r1, r1, r2\n\t"
|
||||
"str r1, [r0, #8]\n\t" /* Set SCR->VCR */
|
||||
"str r1, [r0, #8]\n\t" /* Set SCB->VTOR */
|
||||
"ldr r0, [r1], #4\n\t"
|
||||
"msr MSP, r0\n\t" /* Main (exception handler) stack. */
|
||||
"ldr r0, [r1]\n\t" /* Reset handler. */
|
||||
|
||||
@@ -321,13 +321,13 @@ reset (void)
|
||||
* So, we take the address from PC.
|
||||
*/
|
||||
asm volatile ("cpsid i\n\t" /* Mask all interrupts. */
|
||||
"ldr r0, 1f\n\t" /* r0 = SCR */
|
||||
"ldr r0, 1f\n\t" /* r0 = SCB start */
|
||||
"mov r1, pc\n\t" /* r1 = (PC + 0x1000) & ~0x0fff */
|
||||
"mov r2, #0x1000\n\t"
|
||||
"add r1, r1, r2\n\t"
|
||||
"sub r2, r2, #1\n\t"
|
||||
"bic r1, r1, r2\n\t"
|
||||
"str r1, [r0, #8]\n\t" /* Set SCR->VCR */
|
||||
"str r1, [r0, #8]\n\t" /* Set SCB->VTOR */
|
||||
"ldr r0, [r1], #4\n\t"
|
||||
"msr MSP, r0\n\t" /* Main (exception handler) stack. */
|
||||
"ldr r0, [r1]\n\t" /* Reset handler. */
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* usb-mkl27z.c - USB driver for MKL27Z
|
||||
*
|
||||
* Copyright (C) 2016 Flying Stone Technology
|
||||
* Copyright (C) 2016, 2018 Flying Stone Technology
|
||||
* Author: NIIBE Yutaka <gniibe@fsij.org>
|
||||
*
|
||||
* This file is a part of Chopstx, a thread library for embedded.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* usb-stm32f103.c - USB driver for STM32F103
|
||||
*
|
||||
* Copyright (C) 2016, 2017 Flying Stone Technology
|
||||
* Copyright (C) 2016, 2017, 2018 Flying Stone Technology
|
||||
* Author: NIIBE Yutaka <gniibe@fsij.org>
|
||||
*
|
||||
* This file is a part of Chopstx, a thread library for embedded.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* usb-usbip.c - USB Device Emulation (server side) by USBIP
|
||||
*
|
||||
* Copyright (C) 2017 g10 Code GmbH
|
||||
* Copyright (C) 2017, 2018 g10 Code GmbH
|
||||
* Author: NIIBE Yutaka <gniibe@fsij.org>
|
||||
*
|
||||
* This file is a part of Chopstx, a thread library for embedded.
|
||||
|
||||
Reference in New Issue
Block a user