Skip to content

Commit

Permalink
sched: Introduce sched_wake_tasks() function to wake up tasks
Browse files Browse the repository at this point in the history
Add function to indicate when tasks need to be run.  This will allow
the scheduler code to know if there are any tasks that need to be
processed.

Signed-off-by: Kevin O'Connor <[email protected]>
  • Loading branch information
KevinOConnor committed Aug 8, 2017
1 parent e9d2ec7 commit a9982be
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 10 deletions.
4 changes: 3 additions & 1 deletion lib/README
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ This directory contains external library code.
The pjrc_usb_serial directory contains code from:
http://www.pjrc.com/teensy/usb_serial.html
version 1.7 (extracted on 20160605). It has been modified to compile
on recent versions of gcc. See usb_serial.patch for the modifications.
on recent versions of gcc, to support asynchronous notification of
incoming data, and to not use SOF interrupts. See usb_serial.patch for
the modifications.

The cmsis-sam3x8e directory contains code from the Arduino project:
https://www.arduino.cc/
Expand Down
12 changes: 10 additions & 2 deletions lib/pjrc_usb_serial/usb_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ void usb_init(void)
UDCON = 0; // enable attach resistor
usb_configuration = 0;
cdc_line_rtsdtr = 0;
UDIEN = (1<<EORSTE)|(1<<SOFE);
UDIEN = (1<<EORSTE);
sei();
}

Expand Down Expand Up @@ -359,6 +359,7 @@ int16_t usb_serial_getchar(void)
UEINTX = 0x6B;
goto retry;
}
UEIENX = (1<<RXOUTE);
SREG = intr_state;
return -1;
}
Expand Down Expand Up @@ -775,7 +776,14 @@ static inline void usb_ack_out(void)
//
ISR(USB_COM_vect)
{
uint8_t intbits;
uint8_t intbits = UEINT;
if (intbits & (1<<CDC_RX_ENDPOINT)) {
UENUM = CDC_RX_ENDPOINT;
UEIENX = 0;
extern void sched_wake_tasks(void);
sched_wake_tasks();
return;
}
const uint8_t *list;
const uint8_t *cfg;
uint8_t i, n, len, en;
Expand Down
39 changes: 36 additions & 3 deletions lib/pjrc_usb_serial/usb_serial.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--- usb_serial.c 2011-04-19 05:54:12.000000000 -0400
+++ usb_serial.c 2016-06-04 23:48:52.590001697 -0400
--- ../../../lib/pjrc/usb_serial/usb_serial.c 2011-04-19 05:54:12.000000000 -0400
+++ usb_serial.c 2017-08-07 11:32:47.106357362 -0400
@@ -30,6 +30,7 @@
// Version 1.6: fix zero length packet bug
// Version 1.7: fix usb_serial_set_control
Expand Down Expand Up @@ -62,7 +62,24 @@
uint16_t wValue;
uint16_t wIndex;
const uint8_t *addr;
@@ -646,7 +647,9 @@
@@ -324,7 +325,7 @@
UDCON = 0; // enable attach resistor
usb_configuration = 0;
cdc_line_rtsdtr = 0;
- UDIEN = (1<<EORSTE)|(1<<SOFE);
+ UDIEN = (1<<EORSTE);
sei();
}

@@ -358,6 +359,7 @@
UEINTX = 0x6B;
goto retry;
}
+ UEIENX = (1<<RXOUTE);
SREG = intr_state;
return -1;
}
@@ -646,7 +648,9 @@
// communication
uint32_t usb_serial_get_baud(void)
{
Expand All @@ -73,3 +90,19 @@
}
uint8_t usb_serial_get_stopbits(void)
{
@@ -772,7 +776,14 @@
//
ISR(USB_COM_vect)
{
- uint8_t intbits;
+ uint8_t intbits = UEINT;
+ if (intbits & (1<<CDC_RX_ENDPOINT)) {
+ UENUM = CDC_RX_ENDPOINT;
+ UEIENX = 0;
+ extern void sched_wake_tasks(void);
+ sched_wake_tasks();
+ return;
+ }
const uint8_t *list;
const uint8_t *cfg;
uint8_t i, n, len, en;
3 changes: 3 additions & 0 deletions src/avr/serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ DECL_INIT(serial_init);
ISR(USART0_RX_vect)
{
uint8_t data = UDR0;
if (data == MESSAGE_SYNC)
sched_wake_tasks();
if (receive_pos >= sizeof(receive_buf))
// Serial overflow - ignore it as crc error will force retransmit
return;
Expand Down Expand Up @@ -104,6 +106,7 @@ console_pop_input(uint8_t len)
memmove(&receive_buf[copied], &receive_buf[copied + len]
, needcopy - copied);
copied = needcopy;
sched_wake_tasks();
}
irqstatus_t flag = irq_save();
if (rpos != readb(&receive_pos)) {
Expand Down
4 changes: 3 additions & 1 deletion src/avr/usbserial.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ static void
console_pop_input(uint8_t len)
{
uint8_t needcopy = receive_pos - len;
if (needcopy)
if (needcopy) {
memmove(receive_buf, &receive_buf[len], needcopy);
sched_wake_tasks();
}
receive_pos = needcopy;
}

Expand Down
2 changes: 1 addition & 1 deletion src/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "board/misc.h" // crc16_ccitt
#include "board/pgm.h" // READP
#include "command.h" // output_P
#include "sched.h" // DECL_TASK
#include "sched.h" // sched_is_shutdown

static uint8_t next_sequence = MESSAGE_DEST;

Expand Down
6 changes: 4 additions & 2 deletions src/pru/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ timer_kick(void)
static void
_irq_poll(void)
{
if (CT_INTC.SECR0 & (1 << IEP_EVENT)) {
uint32_t secr0 = CT_INTC.SECR0;
if (secr0 & (1 << KICK_PRU1_EVENT))
sched_wake_tasks();
if (secr0 & (1 << IEP_EVENT)) {
CT_IEP.TMR_CMP_STS = 0xff;
uint32_t next = timer_dispatch_many();
timer_set(next);
Expand Down Expand Up @@ -121,7 +124,6 @@ console_task(void)
const struct command_parser *cp = SHARED_MEM->next_command;
if (!cp)
return;
barrier();

if (sched_is_shutdown() && !(cp->flags & HF_IN_SHUTDOWN)) {
sched_report_shutdown();
Expand Down
3 changes: 3 additions & 0 deletions src/sam3x8e/serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ UART_Handler(void)
uint32_t status = UART->UART_SR;
if (status & UART_SR_RXRDY) {
uint8_t data = UART->UART_RHR;
if (data == MESSAGE_SYNC)
sched_wake_tasks();
if (receive_pos >= sizeof(receive_buf))
// Serial overflow - ignore it as crc error will force retransmit
return;
Expand Down Expand Up @@ -94,6 +96,7 @@ console_pop_input(uint32_t len)
memmove(&receive_buf[copied], &receive_buf[copied + len]
, needcopy - copied);
copied = needcopy;
sched_wake_tasks();
}
irqstatus_t flag = irq_save();
if (rpos != readl(&receive_pos)) {
Expand Down
10 changes: 10 additions & 0 deletions src/sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ static struct timer sentinel_timer, deleted_timer;
static uint_fast8_t
periodic_event(struct timer *t)
{
// Make sure the stats task runs periodically
sched_wake_tasks();
// Reschedule timer
periodic_timer.waketime += timer_from_us(100000);
sentinel_timer.waketime = periodic_timer.waketime + 0x80000000;
return SF_RESCHEDULE;
Expand Down Expand Up @@ -177,10 +180,17 @@ sched_timer_reset(void)
* Task waking
****************************************************************/

// Note that at least one task is ready to run
void
sched_wake_tasks(void)
{
}

// Note that a task is ready to run
void
sched_wake_task(struct task_wake *w)
{
sched_wake_tasks();
writeb(&w->wake, 1);
}

Expand Down
1 change: 1 addition & 0 deletions src/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ struct task_wake {
void sched_add_timer(struct timer*);
void sched_del_timer(struct timer *del);
unsigned int sched_timer_dispatch(void);
void sched_wake_tasks(void);
void sched_wake_task(struct task_wake *w);
uint8_t sched_check_wake(struct task_wake *w);
uint8_t sched_is_shutdown(void);
Expand Down

0 comments on commit a9982be

Please sign in to comment.