Beispiel #1
0
void event_test(void)
{
	thread_t *threads[5];

	static event_t ievent = EVENT_INITIAL_VALUE(ievent, true, 0x1234);
	printf("preinitialized event:\n");
	hexdump(&ievent, sizeof(ievent));

	printf("event tests starting\n");

	/* make sure signalling the event wakes up all the threads */
	event_init(&e, false, 0);
	threads[0] = thread_create("event signaller", &event_signaller, NULL, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE);
	threads[1] = thread_create("event waiter 0", &event_waiter, (void *)2, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE);
	threads[2] = thread_create("event waiter 1", &event_waiter, (void *)2, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE);
	threads[3] = thread_create("event waiter 2", &event_waiter, (void *)2, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE);
	threads[4] = thread_create("event waiter 3", &event_waiter, (void *)2, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE);

	for (uint i = 0; i < countof(threads); i++)
		thread_resume(threads[i]);

	thread_sleep(2000);
	printf("destroying event\n");
	event_destroy(&e);

	for (uint i = 0; i < countof(threads); i++)
		thread_join(threads[i], NULL, INFINITE_TIME);

	/* make sure signalling the event wakes up precisely one thread */
	event_init(&e, false, EVENT_FLAG_AUTOUNSIGNAL);
	threads[0] = thread_create("event signaller", &event_signaller, NULL, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE);
	threads[1] = thread_create("event waiter 0", &event_waiter, (void *)99, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE);
	threads[2] = thread_create("event waiter 1", &event_waiter, (void *)99, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE);
	threads[3] = thread_create("event waiter 2", &event_waiter, (void *)99, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE);
	threads[4] = thread_create("event waiter 3", &event_waiter, (void *)99, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE);

	for (uint i = 0; i < countof(threads); i++)
		thread_resume(threads[i]);

	thread_sleep(2000);
	event_destroy(&e);

	for (uint i = 0; i < countof(threads); i++)
		thread_join(threads[i], NULL, INFINITE_TIME);

	printf("event tests done\n");
}
Beispiel #2
0
#include <arch/arm/cm.h>

#include <driverlib/prcm.h>
#include <driverlib/rfc.h>
#include <driverlib/rf_mailbox.h>
#include <inc/hw_rfc_dbell.h>

#include <rf_patches/rf_patch_cpe_genfsk.h>

#include <platform/radio.h>

#define RADIO_POLLED_MODE 0

#define CPE0_MASK (IRQ_BOOT_DONE | IRQ_RX_OK | IRQ_LAST_COMMAND_DONE | IRQ_COMMAND_DONE)

static event_t ack_evt = EVENT_INITIAL_VALUE(ack_evt, 0, EVENT_FLAG_AUTOUNSIGNAL);

static event_t cpe0_evt = EVENT_INITIAL_VALUE(cpe0_evt, 0, EVENT_FLAG_AUTOUNSIGNAL);

void ti_cc_rfc_cpe_0_irq(void) {
	arm_cm_irq_entry();
	event_signal(&cpe0_evt, false);

	// disable IRQ until thread handles and re-enables them in response to event
	NVIC_DisableIRQ(rfc_cpe_0_IRQn);

	// reschedule if we woke a thread (indicated by !signaled)
	arm_cm_irq_exit(!cpe0_evt.signaled);
}

static inline uint32_t cpe0_reason(void) {
Beispiel #3
0
#define UTS_RXFULL                  (1 << 3)

#define RXBUF_SIZE 32

// clang-format on

// values read from zbi
static bool initialized = false;
static vaddr_t uart_base = 0;
static uint32_t uart_irq = 0;
static cbuf_t uart_rx_buf;
// static cbuf_t uart_tx_buf;

static bool uart_tx_irq_enabled = false;
static event_t uart_dputc_event = EVENT_INITIAL_VALUE(uart_dputc_event,
                                                      true,
                                                      EVENT_FLAG_AUTOUNSIGNAL);

static spin_lock_t uart_spinlock = SPIN_LOCK_INITIAL_VALUE;

#define UARTREG(reg) (*(volatile uint32_t*)((uart_base) + (reg)))

static interrupt_eoi uart_irq_handler(void* arg) {
    /* read interrupt status and mask */
    while ((UARTREG(MX8_USR1) & USR1_RRDY)) {
        if (cbuf_space_avail(&uart_rx_buf) == 0) {
            break;
        }
        char c = UARTREG(MX8_URXD) & 0xFF;
        cbuf_write_char(&uart_rx_buf, c);
    }
Beispiel #4
0
#include "accelerometer.h"

#include <dev/accelerometer.h>
#include <err.h>
#include <kernel/event.h>
#include <kernel/port.h>
#include <kernel/thread.h>

// Smaller stacks for sensor publishers since they don't do much.
#define SENSOR_PUBLISHER_DEFAULT_STACK_SIZE (512)

// Accelerometer publisher will write data to this port when data is requested.
#define ACCELEROMETER_PORT_NAME ("sys/io/acc")

static event_t accelerometer_event = 
	EVENT_INITIAL_VALUE(accelerometer_event, false, EVENT_FLAG_AUTOUNSIGNAL);

// Worker thread that sleeps until data is requested from the accelerometer. 
// Takes a single reading and publishes it to the accelerometer port when woken.
thread_t *accelerometer_worker;

static int accelerometer_publisher_worker_thread(void *argv)
{
	position_vector_t pos_vector;
	status_t result;
	port_t acc_port;

	// Make sure that position vector elements fit exactly into port packets.
	STATIC_ASSERT(sizeof(pos_vector.x) == sizeof(port_packet_t));
	STATIC_ASSERT(sizeof(pos_vector.y) == sizeof(port_packet_t));
	STATIC_ASSERT(sizeof(pos_vector.z) == sizeof(port_packet_t));