Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQUASH ME: x86 rtc patch #6

Closed
wants to merge 11 commits into from
2 changes: 1 addition & 1 deletion boards/avsextrem/drivers/avsextrem-smb380.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
#include "lpc2387.h"


uint8_t simple_pid;
kernel_pid_t simple_pid;
int16_t simple_buffer[4];

volatile int16_t *ringBuff_X = NULL;
Expand Down
2 changes: 1 addition & 1 deletion boards/msba2-common/drivers/include/uart0.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef __UART0_H
#define __UART0_H

extern int uart0_handler_pid;
extern kernel_pid_t uart0_handler_pid;

#endif /* __UART0_H */
4 changes: 2 additions & 2 deletions core/include/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#define KERNEL_H_

#include <stdbool.h>
#include <stdint.h>

#include "attributes.h"
#include "config.h"
Expand Down Expand Up @@ -67,12 +68,11 @@
#endif

/* ------------------------------------------------------------------------- */

/**
* @def PID_NULL
* @brief Identifier to detect an invalid PID
*/
#define PID_NULL -1
#define KERNEL_PID_NULL -1

/**
* @def PRIORITY_MIN
Expand Down
17 changes: 17 additions & 0 deletions core/include/kernel_types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef KERNEL_TYPES_H
#define KERNEL_TYPES_H

#include <stdint.h>

/**
* Macro for printing formatter
*/
#define PRIkernel_pid PRIi16

/**
* @brief Unique process identifier
*
*/
typedef int16_t kernel_pid_t;

#endif /* KERNEL_TYPES_H */
9 changes: 5 additions & 4 deletions core/include/msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

#include <stdint.h>
#include <stdbool.h>
#include "kernel_types.h"

/**
* @brief Describes a message object which can be sent between threads.
Expand All @@ -45,7 +46,7 @@
*
*/
typedef struct msg {
uint16_t sender_pid; /**< PID of sending thread. Will be filled in
kernel_pid_t sender_pid; /**< PID of sending thread. Will be filled in
by msg_send. */
uint16_t type; /**< Type field. */
union {
Expand Down Expand Up @@ -75,7 +76,7 @@ typedef struct msg {
* ``block == 0``
* @return -1, on error (invalid PID)
*/
int msg_send(msg_t *m, unsigned int target_pid, bool block);
int msg_send(msg_t *m, kernel_pid_t target_pid, bool block);


/**
Expand Down Expand Up @@ -107,7 +108,7 @@ int msg_send_to_self(msg_t *m);
* @return 0, if receiver is not waiting and ``block == 0``
* @return -1, on error (invalid PID)
*/
int msg_send_int(msg_t *m, unsigned int target_pid);
int msg_send_int(msg_t *m, kernel_pid_t target_pid);


/**
Expand Down Expand Up @@ -151,7 +152,7 @@ int msg_try_receive(msg_t *m);
*
* @return 1, if successful.
*/
int msg_send_receive(msg_t *m, msg_t *reply, unsigned int target_pid);
int msg_send_receive(msg_t *m, msg_t *reply, kernel_pid_t target_pid);

/**
* @brief Replies to a message.
Expand Down
2 changes: 1 addition & 1 deletion core/include/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ extern volatile int sched_num_threads;
/**
* Process ID of active thread
*/
extern volatile int sched_active_pid;
extern volatile kernel_pid_t sched_active_pid;

/**
* List of runqueues per priority level
Expand Down
2 changes: 1 addition & 1 deletion core/include/tcb.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ typedef struct tcb_t {
char *sp; /**< thread's stack pointer */
uint16_t status; /**< thread's status */

uint16_t pid; /**< thread's process id */
kernel_pid_t pid; /**< thread's process id */
uint16_t priority; /**< thread's priority */

clist_node_t rq_entry; /**< run queue entry */
Expand Down
10 changes: 5 additions & 5 deletions core/include/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
* @return value ``<0`` on error
* @return pid of newly created task, otherwise
*/
int thread_create(char *stack,
kernel_pid_t thread_create(char *stack,
int stacksize,
char priority,
int flags,
Expand All @@ -88,7 +88,7 @@ int thread_create(char *stack,
* @return status of the thread
* @return `STATUS_NOT_FOUND` if pid is unknown
*/
int thread_getstatus(int pid);
int thread_getstatus(kernel_pid_t pid);

/**
* @brief Returns the name of a process
Expand All @@ -98,7 +98,7 @@ int thread_getstatus(int pid);
* @return the threads name
* @return `NULL` if pid is unknown
*/
const char *thread_getname(int pid);
const char *thread_getname(kernel_pid_t pid);

/**
* @brief Puts the current thread into sleep mode. Has to be woken up externally.
Expand All @@ -121,15 +121,15 @@ void thread_yield(void);
* @return `1` on success
* @return `STATUS_NOT_FOUND` if pid is unknown or not sleeping
*/
int thread_wakeup(int pid);
int thread_wakeup(kernel_pid_t pid);


/**
* @brief Returns the process ID of the currently running thread
*
* @return obviously you are not a golfer.
*/
int thread_getpid(void);
kernel_pid_t thread_getpid(void);

/**
* @brief Measures the stack usage of a stack
Expand Down
20 changes: 10 additions & 10 deletions core/msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ static int queue_msg(tcb_t *target, msg_t *m)
return 0;
}

int msg_send(msg_t *m, unsigned int target_pid, bool block)
int msg_send(msg_t *m, kernel_pid_t target_pid, bool block)
{
if (inISR()) {
return msg_send_int(m, target_pid);
}

if ((unsigned int)sched_active_pid == target_pid) {
if (sched_active_pid == target_pid) {
return msg_send_to_self(m);
}

Expand All @@ -74,12 +74,12 @@ int msg_send(msg_t *m, unsigned int target_pid, bool block)
return -1;
}

DEBUG("msg_send() %s:%i: Sending from %i to %i. block=%i src->state=%i target->state=%i\n", __FILE__, __LINE__, sched_active_pid, target_pid, block, sched_active_thread->status, target->status);
DEBUG("msg_send() %s:%i: Sending from %" PRIkernel_pid " to %" PRIkernel_pid ". block=%i src->state=%i target->state=%i\n", __FILE__, __LINE__, sched_active_pid, target_pid, block, sched_active_thread->status, target->status);

if (target->status != STATUS_RECEIVE_BLOCKED) {
DEBUG("msg_send() %s:%i: Target %i is not RECEIVE_BLOCKED.\n", __FILE__, __LINE__, target_pid);
DEBUG("msg_send() %s:%i: Target %" PRIkernel_pid " is not RECEIVE_BLOCKED.\n", __FILE__, __LINE__, target_pid);
if (target->msg_array && queue_msg(target, m)) {
DEBUG("msg_send() %s:%i: Target %i has a msg_queue. Queueing message.\n", __FILE__, __LINE__, target_pid);
DEBUG("msg_send() %s:%i: Target %" PRIkernel_pid " has a msg_queue. Queueing message.\n", __FILE__, __LINE__, target_pid);
eINT();
if (sched_active_thread->status == STATUS_REPLY_BLOCKED) {
thread_yield();
Expand Down Expand Up @@ -118,7 +118,7 @@ int msg_send(msg_t *m, unsigned int target_pid, bool block)
DEBUG("msg_send: %s: Back from send block.\n", sched_active_thread->name);
}
else {
DEBUG("msg_send: %s: Direct msg copy from %i to %i.\n", sched_active_thread->name, thread_getpid(), target_pid);
DEBUG("msg_send: %s: Direct msg copy from %" PRIkernel_pid " to %" PRIkernel_pid ".\n", sched_active_thread->name, thread_getpid(), target_pid);
/* copy msg to target */
msg_t *target_message = (msg_t*) target->wait_data;
*target_message = *m;
Expand All @@ -142,7 +142,7 @@ int msg_send_to_self(msg_t *m)
return res;
}

int msg_send_int(msg_t *m, unsigned int target_pid)
int msg_send_int(msg_t *m, kernel_pid_t target_pid)
{
tcb_t *target = (tcb_t *) sched_threads[target_pid];

Expand All @@ -152,7 +152,7 @@ int msg_send_int(msg_t *m, unsigned int target_pid)
}

if (target->status == STATUS_RECEIVE_BLOCKED) {
DEBUG("msg_send_int: Direct msg copy from %i to %i.\n", thread_getpid(), target_pid);
DEBUG("msg_send_int: Direct msg copy from %" PRIkernel_pid " to %" PRIkernel_pid ".\n", thread_getpid(), target_pid);

m->sender_pid = target_pid;

Expand All @@ -170,7 +170,7 @@ int msg_send_int(msg_t *m, unsigned int target_pid)
}
}

int msg_send_receive(msg_t *m, msg_t *reply, unsigned int target_pid)
int msg_send_receive(msg_t *m, msg_t *reply, kernel_pid_t target_pid)
{
dINT();
tcb_t *me = (tcb_t*) sched_threads[sched_active_pid];
Expand All @@ -189,7 +189,7 @@ int msg_reply(msg_t *m, msg_t *reply)
tcb_t *target = (tcb_t*) sched_threads[m->sender_pid];

if (!target) {
DEBUG("msg_reply(): %s: Target \"%" PRIu16 "\" not existing...dropping msg!\n", sched_active_thread->name, m->sender_pid);
DEBUG("msg_reply(): %s: Target \"%" PRIkernel_pid "\" not existing...dropping msg!\n", sched_active_thread->name, m->sender_pid);
return -1;
}

Expand Down
4 changes: 2 additions & 2 deletions core/mutex.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ static void mutex_wait(struct mutex_t *mutex)

void mutex_unlock(struct mutex_t *mutex)
{
DEBUG("%s: unlocking mutex. val: %u pid: %u\n", sched_active_thread->name, mutex->val, sched_active_pid);
DEBUG("%s: unlocking mutex. val: %u pid: %" PRIkernel_pid "\n", sched_active_thread->name, mutex->val, sched_active_pid);
int irqstate = disableIRQ();

if (mutex->val != 0) {
Expand All @@ -119,7 +119,7 @@ void mutex_unlock(struct mutex_t *mutex)

void mutex_unlock_and_sleep(struct mutex_t *mutex)
{
DEBUG("%s: unlocking mutex. val: %u pid: %u, and taking a nap\n", sched_active_thread->name, mutex->val, sched_active_pid);
DEBUG("%s: unlocking mutex. val: %u pid: %" PRIkernel_pid ", and taking a nap\n", sched_active_thread->name, mutex->val, sched_active_pid);
int irqstate = disableIRQ();

if (mutex->val != 0) {
Expand Down
6 changes: 3 additions & 3 deletions core/sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ volatile unsigned int sched_context_switch_request;
volatile tcb_t *sched_threads[MAXTHREADS];
volatile tcb_t *sched_active_thread;

volatile int sched_active_pid = -1;
volatile kernel_pid_t sched_active_pid = KERNEL_PID_NULL;

clist_node_t *sched_runqueues[SCHED_PRIO_LEVELS];
static uint32_t runqueue_bitcache = 0;
Expand All @@ -71,7 +71,7 @@ void sched_run(void)

#ifdef SCHED_TEST_STACK
if (*((unsigned int *)my_active_thread->stack_start) != (unsigned int) my_active_thread->stack_start) {
printf("scheduler(): stack overflow detected, task=%s pid=%u\n", my_active_thread->name, my_active_thread->pid);
printf("scheduler(): stack overflow detected, task=%s pid=%" PRIkernel_pid "\n", my_active_thread->name, my_active_thread->pid);
}
#endif

Expand All @@ -93,7 +93,7 @@ void sched_run(void)
clist_advance(&(sched_runqueues[nextrq]));
my_active_thread = (tcb_t *)next.data;

int my_next_pid = my_active_thread->pid;
kernel_pid_t my_next_pid = my_active_thread->pid;

#if SCHEDSTATISTICS
sched_pidlist[my_next_pid].laststart = time;
Expand Down
16 changes: 8 additions & 8 deletions core/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
#include "hwtimer.h"
#include "sched.h"

inline int thread_getpid(void)
inline kernel_pid_t thread_getpid(void)
{
return sched_active_thread->pid;
}

int thread_getstatus(int pid)
int thread_getstatus(kernel_pid_t pid)
{
if (sched_threads[pid] == NULL) {
return STATUS_NOT_FOUND;
Expand All @@ -46,7 +46,7 @@ int thread_getstatus(int pid)
return sched_threads[pid]->status;
}

const char *thread_getname(int pid)
const char *thread_getname(kernel_pid_t pid)
{
if (sched_threads[pid] == NULL) {
return NULL;
Expand All @@ -67,9 +67,9 @@ void thread_sleep(void)
thread_yield();
}

int thread_wakeup(int pid)
int thread_wakeup(kernel_pid_t pid)
{
DEBUG("thread_wakeup: Trying to wakeup PID %i...\n", pid);
DEBUG("thread_wakeup: Trying to wakeup PID %" PRIkernel_pid "...\n", pid);

int old_state = disableIRQ();

Expand Down Expand Up @@ -106,7 +106,7 @@ int thread_measure_stack_free(char *stack)
return space_free;
}

int thread_create(char *stack, int stacksize, char priority, int flags, void *(*function)(void *arg), void *arg, const char *name)
kernel_pid_t thread_create(char *stack, int stacksize, char priority, int flags, void *(*function)(void *arg), void *arg, const char *name)
{
/* allocate our thread control block at the top of our stackspace */
int total_stacksize = stacksize;
Expand Down Expand Up @@ -150,7 +150,7 @@ int thread_create(char *stack, int stacksize, char priority, int flags, void *(*
dINT();
}

int pid = 0;
kernel_pid_t pid = 0;

while (pid < MAXTHREADS) {
if (sched_threads[pid] == NULL) {
Expand Down Expand Up @@ -196,7 +196,7 @@ int thread_create(char *stack, int stacksize, char priority, int flags, void *(*

sched_num_threads++;

DEBUG("Created thread %s. PID: %u. Priority: %u.\n", name, cb->pid, priority);
DEBUG("Created thread %s. PID: %" PRIkernel_pid ". Priority: %u.\n", name, cb->pid, priority);

if (flags & CREATE_SLEEPING) {
sched_set_status(cb, STATUS_SLEEPING);
Expand Down
1 change: 1 addition & 0 deletions cpu/arm_common/gettimeofday.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/

#include <sys/time.h>
#include "kernel_types.h"

#if defined MODULE_RTC
# include "rtc.h"
Expand Down
4 changes: 2 additions & 2 deletions cpu/arm_common/syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,9 @@ void _exit(int n)
while (1);
}
/*---------------------------------------------------------------------------*/
int _getpid(void)
pid_t _getpid(void)
{
return sched_active_thread->pid;
return (pid_t) sched_active_thread->pid;
}
/*---------------------------------------------------------------------------*/
int _kill_r(struct _reent *r, int pid, int sig)
Expand Down
2 changes: 1 addition & 1 deletion cpu/cc430/cc430-rtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ See the file LICENSE in the top level directory for more details.
//static volatile time_t epoch;
static struct tm time_to_set;
static int set_time = 0;
int rtc_second_pid = 0;
kernel_pid_t rtc_second_pid = 0;

/*---------------------------------------------------------------------------*/
void rtc_init(void)
Expand Down
2 changes: 1 addition & 1 deletion cpu/cortex-m3_common/thread_arch.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void thread_arch_stack_print(void)
int count = 0;
uint32_t *sp = (uint32_t *)sched_active_thread->sp;

printf("printing the current stack of thread %u\n", thread_getpid());
printf("printing the current stack of thread %" PRIkernel_pid "\n", thread_getpid());
printf(" address: data:\n");

do {
Expand Down
4 changes: 2 additions & 2 deletions cpu/lpc1768/syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,9 @@ void _exit(int n)
while(1);
}
/*---------------------------------------------------------------------------*/
int _getpid(void)
pid_t _getpid(void)
{
return sched_active_thread->pid;
return (pid_t) sched_active_thread->pid;
}
/*---------------------------------------------------------------------------*/
int _kill_r(struct _reent *r, int pid, int sig)
Expand Down
Loading