Browse Source

merged

dev/timer
mlenders 12 years ago
parent
commit
9521142842
  1. 2
      board/chronos/Jamfile
  2. 2
      board/chronos/Jamrules.chronos
  3. 21
      board/chronos/debug_uart.c
  4. 7
      board/chronos/drivers/Jamfile
  5. 13
      board/chronos/drivers/battery.c
  6. 28
      board/chronos/drivers/buzzer.c
  7. 2
      board/chronos/drivers/display.c
  8. 42
      board/chronos/drivers/display_putchar.c
  9. 6
      board/chronos/drivers/include/battery.h
  10. 6
      board/chronos/drivers/include/buzzer.h
  11. 4
      board/chronos/drivers/include/display.h
  12. 6
      board/chronos/drivers/include/display_putchar.h
  13. 11
      board/chronos/include/buttons.h
  14. 11
      board/chronos/putchar.c
  15. 4
      board/msb-430-common/Jamfile
  16. 7
      board/msb-430-common/putchar.c
  17. 0
      board/msb-430-common/uart1.c
  18. 8
      board/msba2-common/drivers/msba2-ltc4150.c
  19. 8
      board/msba2-common/drivers/msba2-uart0.c
  20. 6
      board/msba2-common/include/msba2_common.h
  21. 1
      board/msba2/include/board.h
  22. 2
      core/include/kernel.h
  23. 14
      core/include/msg.h
  24. 1
      core/include/queue.h
  25. 10
      core/include/sched.h
  26. 6
      core/include/tcb.h
  27. 2
      core/include/thread.h
  28. 4
      core/kernel_init.c
  29. 44
      core/msg.c
  30. 4
      core/mutex.c
  31. 21
      core/sched.c
  32. 8
      core/thread.c
  33. 5
      cpu/arm_common/Jamfile
  34. 5
      cpu/arm_common/Jamrules.arm_common
  35. 89
      cpu/arm_common/profiling.c
  36. 2
      cpu/cc430/Jamfile
  37. 147
      cpu/cc430/cc430-adc.c
  38. 231
      cpu/cc430/cc430-gpioint.c
  39. 37
      cpu/cc430/cc430-rtc.c
  40. 44
      cpu/cc430/include/cc430-adc.h
  41. 48
      cpu/lpc2387/linkerscript.x
  42. 12
      cpu/lpc2387/lpc2387-gpioint.c
  43. 2
      cpu/msp430-common/Jamfile
  44. 1
      cpu/msp430x16x/Jamfile
  45. 80
      cpu/msp430x16x/flashrom.c
  46. 4
      drivers/Jamfile
  47. 2
      drivers/cc110x/Jamfile
  48. 16
      drivers/cc110x/arch_cc1100.h
  49. 13
      drivers/cc110x/cc1100-csmaca-mac.c
  50. 48
      drivers/cc110x/cc1100.c
  51. 17
      drivers/cc110x/cc1100_phy.c
  52. 46
      drivers/cc110x/cc1100_spi.c
  53. 14
      drivers/cc110x/cc1100_spi.h
  54. 2
      drivers/cc110x_ng/cc110x-rx.c
  55. 1
      drivers/include/gpioint.h
  56. 2
      drivers/include/ltc4150.h
  57. 1
      drivers/include/ltc4150_arch.h
  58. 4
      drivers/include/rtc.h
  59. 18
      drivers/ltc4150.c
  60. 5
      projects/WEAtHeR/Jamfile
  61. 347
      projects/WEAtHeR/main.c
  62. 58
      projects/WEAtHeR/protocol_msg_gateway.c
  63. 18
      projects/WEAtHeR/protocol_msg_gateway.h
  64. 13
      projects/WEAtHeR/tests/hello-world
  65. 43
      projects/WEAtHeR/weather_protocol.h
  66. 77
      projects/WEAtHeR/weather_routing.c
  67. 17
      projects/WEAtHeR/weather_routing.h
  68. 20
      projects/chronos_cc110x_ng/main.c
  69. 5
      projects/chronos_default/Jamfile
  70. 167
      projects/chronos_default/main.c
  71. 13
      projects/chronos_default/tests/hello-world
  72. 2
      projects/default/Jamfile
  73. 4
      projects/default/main.c
  74. 2
      projects/hi_earth/Jamfile
  75. 56
      projects/hi_earth/main.c
  76. 5
      projects/laser/main.c
  77. 6
      projects/msb430_cc110x_ng/main.c
  78. 4
      projects/pingpong/main.c
  79. 4
      projects/pingpong_sync/main.c
  80. 2
      projects/test_cc110x_ng/Jamfile
  81. 6
      projects/test_cc110x_ng/main.c
  82. 2
      projects/test_swtimer_basic/main.c
  83. 5
      projects/watch/Jamfile
  84. 62
      projects/watch/alarm_app.c
  85. 6
      projects/watch/alarm_app.h
  86. 58
      projects/watch/clock_app.c
  87. 7
      projects/watch/clock_app.h
  88. 83
      projects/watch/main.c
  89. 13
      projects/watch/tests/hello-world
  90. 9
      projects/watch/watch.h
  91. 5
      projects/wiselib/Jamfile
  92. 42
      projects/wiselib/main.c
  93. 3
      projects/wiselib/script
  94. 14
      sys/auto_init.c
  95. 8
      sys/chardev_thread.c
  96. 2
      sys/include/chardev_thread.h
  97. 2
      sys/include/posix_io.h
  98. 3
      sys/include/vtimer.h
  99. 10
      sys/lib/ringbuffer.c
  100. 12
      sys/lib/ringbuffer.h
  101. Some files were not shown because too many files have changed in this diff Show More

2
board/chronos/Jamfile

@ -2,7 +2,7 @@ SubDir TOP board chronos ;
HDRS += $(TOP)/board/$(CPU)/include ;
Module board : debug_uart.c board_init.c ;
Module board : putchar.c board_init.c ;
UseModule board ;
SubInclude TOP board $(BOARD) drivers ;

2
board/chronos/Jamrules.chronos

@ -7,6 +7,8 @@ BOARD = chronos ;
CPU = cc430 ;
MCU = cc430x6137 ;
HDRS += [ FPath $(TOP) board chronos drivers include ] ;
FLASHER ?= mspdebug ;
FLASHFLAGS ?= rf2500 ;

21
board/chronos/debug_uart.c

@ -1,21 +0,0 @@
#include <stdio.h>
#include "board.h"
#define UART1_TX TXBUF1
#define UART1_WAIT_TXDONE() while( (UTCTL1 & TXEPT) == 0 ) { _NOP(); }
int putchar(int c)
{
// UART1_TX = c;
// UART1_WAIT_TXDONE();
//
// if (c == 10) {
// UART1_TX = 13;
// UART1_WAIT_TXDONE();
// }
return c;
}

7
board/chronos/drivers/Jamfile

@ -1,4 +1,11 @@
SubDir TOP board chronos drivers ;
HDRS += $(TOP)/board/$(CPU)/drivers/include ;
Module board_display : display.c display1.c ;
Module board_cc110x : cc430-cc110x.c : cc110x_cc430 ;
Module board_buzzer : buzzer.c : hwtimer ;
Module battery : battery.c : adc hwtimer ;
Module vti_ps_twi : vti_ps_twi.c : hwtimer ;
Module display_putchar : display_putchar.c : board_display ;

13
board/chronos/drivers/battery.c

@ -0,0 +1,13 @@
#include <stdint.h>
#include <cc430x613x.h>
#include <cc430-adc.h>
uint32_t battery_get_voltage(void) {
uint32_t voltage;
voltage = adc12_single_conversion(REFVSEL_1, ADC12SHT0_10, ADC12INCH_11);
/* Ideally we have A11=0->AVCC=0V ... A11=4095(2^12-1)->AVCC=4V
* --> (A11/4095)*4V=AVCC --> AVCC=(A11*4)/4095 */
voltage = (voltage * 2 * 2 * 1000) / 4095;
return voltage;
}

28
board/chronos/drivers/buzzer.c

@ -0,0 +1,28 @@
#include <stdint.h>
#include <buzzer.h>
#include <hwtimer.h>
#include <cc430x613x.h>
void buzzer_beep(uint8_t pitch, uint16_t duration) {
// Reset TA1R, set up mode, TA1 runs from 32768Hz ACLK
TA1CTL = TACLR | MC_1 | TASSEL__ACLK;
// Set PWM frequency
TA1CCR0 = pitch;
// Enable IRQ, set output mode "toggle"
TA1CCTL0 = OUTMOD_4;
// Allow buzzer PWM output on P2.7
P2SEL |= BIT7;
hwtimer_wait(duration);
// Stop PWM timer
TA1CTL &= ~(BIT4 | BIT5);
// Reset and disable buzzer PWM output
P2OUT &= ~BIT7;
P2SEL &= ~BIT7;
TA1CCTL0 &= ~CCIE;
}

2
board/chronos/drivers/display.c

@ -57,7 +57,7 @@ void display_symbol(uint8_t symbol, uint8_t mode);
* Global Variable section */
/* Display flags */
volatile s_display_flags display;
volatile s_display_flags_t display;
/* Global return string for itoa function */
char itoa_str[8];

42
board/chronos/drivers/display_putchar.c

@ -0,0 +1,42 @@
#include <stdio.h>
#include <display.h>
#include <string.h>
extern int toupper(int c);
extern void (*_putchar)(int c);
static char display_buf[11];
void putchar_to_display();
void init_display_putchar() {
memset(display_buf, '\0', 11);
_putchar = putchar_to_display;
}
void putchar_to_display(int c) {
if (c == '\n') {
display_buf[4] = 1;
return;
}
if (display_buf[4]) {
memset(display_buf, '\0', 11);
} else {
display_buf[0] = display_buf[1];
display_buf[1] = display_buf[2];
display_buf[2] = display_buf[3];
display_buf[3] = display_buf[5];
display_buf[5] = display_buf[6];
display_buf[6] = display_buf[7];
display_buf[7] = display_buf[8];
display_buf[8] = display_buf[9];
}
display_buf[9] = toupper(c);
clear_display_all();
display_chars(LCD_SEG_L1_3_0, display_buf, SEG_ON);
display_chars(LCD_SEG_L2_5_0, display_buf+4, SEG_ON);
}

6
board/chronos/drivers/include/battery.h

@ -0,0 +1,6 @@
#ifndef BATTERY_H
#define BATTERY_H
uint32_t battery_get_voltage(void);
#endif /* BATTERY_H */

6
board/chronos/drivers/include/buzzer.h

@ -0,0 +1,6 @@
#ifndef BUZZER_H
#define BUZZER_H
void buzzer_beep(uint8_t pitch, uint16_t duration);
#endif /* BUZZER_H */

4
board/chronos/drivers/display.h → board/chronos/drivers/include/display.h

@ -67,9 +67,9 @@ typedef union {
uint16_t update_acceleration : 1; // 1 = Acceleration data was updated
} flag;
uint16_t all_flags; // Shortcut to all display flags (for reset)
} s_display_flags;
} s_display_flags_t;
extern volatile s_display_flags display;
extern volatile s_display_flags_t display;
// Constants defined in library
extern const uint8_t lcd_font[];

6
board/chronos/drivers/include/display_putchar.h

@ -0,0 +1,6 @@
#ifndef __DISPLAY_PUTCHAR_H
#define __DISPLAY_PUTCHAR_H
void init_display_putchar();
#endif /* __DISPLAY_PUTCHAR_H */

11
board/chronos/include/buttons.h

@ -0,0 +1,11 @@
#ifndef BUTTONS_H
#define BUTTONS_H
// Button ports
#define BUTTON_STAR_PIN (BIT2)
#define BUTTON_NUM_PIN (BIT1)
#define BUTTON_UP_PIN (BIT4)
#define BUTTON_DOWN_PIN (BIT0)
#define BUTTON_BACKLIGHT_PIN (BIT3)
#endif

11
board/chronos/putchar.c

@ -0,0 +1,11 @@
static void _dummy(int c) {
}
void (*_putchar)(int c) = _dummy;
int putchar(int c)
{
_putchar(c);
return c;
}

4
board/msb-430-common/Jamfile

@ -27,8 +27,8 @@
SubDir TOP board msb-430-common ;
Module board : board_init.c debug_uart.c ;
Module board_config : board_config.c ;
Module board : board_init.c uart1.c ;
Module board_config : board_config.c : flashrom ;
UseModule board ;
SubInclude TOP cpu $(CPU) ;

7
board/msb-430-common/putchar.c

@ -0,0 +1,7 @@
#include <stdio.h>
void (_putchar(int)) = uart1_putchar;
void putchar(int c) {
_putchar(c);
}

0
board/msb-430-common/debug_uart.c → board/msb-430-common/uart1.c

8
board/msba2-common/drivers/msba2-ltc4150.c

@ -45,19 +45,19 @@ and the mailinglist (subscription via web site)
#include "ltc4150_arch.h"
#include "gpioint.h"
void ltc4150_disable_int(void) {
void __attribute__((__no_instrument_function__)) ltc4150_disable_int(void) {
gpioint_set(0, BIT4, GPIOINT_DISABLE, NULL);
}
void ltc4150_enable_int(void) {
void __attribute__((__no_instrument_function__)) ltc4150_enable_int(void) {
gpioint_set(0, BIT4, GPIOINT_FALLING_EDGE, &ltc4150_interrupt);
}
void ltc4150_sync_blocking(void) {
void __attribute__((__no_instrument_function__)) ltc4150_sync_blocking(void) {
while(!(FIO0PIN & BIT4)) {};
}
void ltc4150_arch_init() {
void __attribute__((__no_instrument_function__)) ltc4150_arch_init() {
FIO0DIR |= BIT5;
FIO0SET = BIT5;
}

8
board/msba2-common/drivers/msba2-uart0.c

@ -49,13 +49,13 @@ and the mailinglist (subscription via web site)
* @note $Id$
*/
typedef struct toprint {
typedef struct toprint_t {
unsigned int len;
char content[];
}toprint;
}toprint_t;
#define QUEUESIZE 255
static volatile toprint* queue[QUEUESIZE];
static volatile toprint_t* queue[QUEUESIZE];
static volatile unsigned char queue_head = 0;
static volatile unsigned char queue_tail = 0;
static volatile unsigned char queue_items = 0;
@ -64,7 +64,7 @@ static volatile unsigned int actual_pos = 0;
static volatile unsigned int running = 0;
static volatile unsigned int fifo = 0;
static volatile toprint* actual = NULL;
static volatile toprint_t* actual = NULL;
static inline void enqueue(void) {
queue_items++;

6
board/msba2-common/include/msba2_common.h

@ -24,8 +24,8 @@ and the mailinglist (subscription via web site)
scatterweb@lists.spline.inf.fu-berlin.de
*******************************************************************************/
#ifndef __BOARD_H
#define __BOARD_H
#ifndef __MSBA2_COMMON_H
#define __MSBA2_COMMON_H
/**
* @ingroup msb_a2
@ -48,4 +48,4 @@ and the mailinglist (subscription via web site)
#define VICIntEnClear VICIntEnClr
/** @} */
#endif // __BOARD_H
#endif // __MSBA2_COMMON_H

1
board/msba2/include/board.h

@ -2,6 +2,7 @@
#define __BOARD_H
#include <msba2_common.h>
#include <bitarithm.h>
#define LED_RED_PIN (BIT25)
#define LED_GREEN_PIN (BIT26)

2
core/include/kernel.h

@ -22,7 +22,7 @@
*/
#include <stdbool.h>
#include <config.h>
#include "config.h"
#include "tcb.h"
#include "cpu.h"
#include "flags.h"

14
core/include/msg.h

@ -35,7 +35,7 @@ typedef struct msg {
char *ptr; ///< pointer content field
uint32_t value; ///< value content field
} content;
} msg;
} msg_t;
/**
@ -54,7 +54,7 @@ typedef struct msg {
* @return 0 if receiver is not waiting and block == false
* @return -1 on error (invalid PID)
*/
int msg_send(msg* m, unsigned int target_pid, bool block);
int msg_send(msg_t* m, unsigned int target_pid, bool block);
/**
@ -68,7 +68,7 @@ int msg_send(msg* m, unsigned int target_pid, bool block);
* @return 1 if sending was successfull
* @return 0 if receiver is not waiting and block == false
*/
int msg_send_int(msg* m, unsigned int target_pid);
int msg_send_int(msg_t* m, unsigned int target_pid);
/**
@ -79,7 +79,7 @@ int msg_send_int(msg* m, unsigned int target_pid);
*
* @return 1 Function always succeeds or blocks forever.
*/
int msg_receive(msg* m);
int msg_receive(msg_t* m);
/**
* @brief Send a message, block until reply received.
@ -90,7 +90,7 @@ int msg_receive(msg* m);
* @param target pid the pid of the target process
* @return 1 if successful
*/
int msg_send_receive(msg *m, msg *reply, unsigned int target_pid);
int msg_send_receive(msg_t *m, msg_t *reply, unsigned int target_pid);
/**
* @brief Replies to a message.
@ -103,7 +103,7 @@ int msg_send_receive(msg *m, msg *reply, unsigned int target_pid);
* @return 1 if succcessful
* qreturn 0 on error
*/
int msg_reply(msg *m, msg *reply);
int msg_reply(msg_t *m, msg_t *reply);
/**
* @brief Initialize the current thread's message queue.
@ -111,7 +111,7 @@ int msg_reply(msg *m, msg *reply);
* @param array Pointer to preallocated array of msg objects
* @param num Number of msg objects in array. MUST BE POWER OF TWO!
*/
int msg_init_queue(msg* array, int num);
int msg_init_queue(msg_t* array, int num);
/** @} */
#endif /* __MSG_H */

1
core/include/queue.h

@ -23,6 +23,7 @@ void queue_add_head(queue_node_t* root, queue_node_t* new_obj);
queue_node_t *queue_remove_head(queue_node_t* root);
void queue_priority_add(queue_node_t* root, queue_node_t* new_obj);
void queue_priority_add_generic(queue_node_t* root, queue_node_t* new_obj, int(*cmp)(queue_node_t*,queue_node_t*)) ;
void queue_remove(queue_node_t* root, queue_node_t *node);
/** @} */
#endif // __QUEUE_H

10
core/include/sched.h

@ -24,16 +24,16 @@
void sched_init();
void sched_run();
void sched_set_status(tcb *process, unsigned int status);
void sched_set_status(tcb_t *process, unsigned int status);
void sched_switch(uint16_t current_prio, uint16_t other_prio, int in_isr);
volatile unsigned int sched_context_switch_request;
extern volatile unsigned int sched_context_switch_request;
volatile tcb *sched_threads[MAXTHREADS];
volatile tcb *active_thread;
extern volatile tcb_t *sched_threads[MAXTHREADS];
extern volatile tcb_t *active_thread;
extern volatile int num_tasks;
volatile int thread_pid;
extern volatile int thread_pid;
//#define SCHEDSTATISTICS
#if SCHEDSTATISTICS

6
core/include/tcb.h

@ -35,7 +35,7 @@
#define STATUS_REPLY_BLOCKED (0x0100)
#define STATUS_TIMER_WAITING (0x0200)
typedef struct tcb {
typedef struct tcb_t {
char* sp;
uint16_t status;
@ -48,12 +48,12 @@ typedef struct tcb {
queue_node_t msg_waiters;
cib_t msg_queue;
msg* msg_array;
msg_t* msg_array;
const char* name;
char* stack_start;
int stack_size;
} tcb;
} tcb_t;
/** @} */
#endif /* TCB_H_ */

2
core/include/thread.h

@ -17,7 +17,7 @@
#include <tcb.h>
/** Minimum stack size */
#define MINIMUM_STACK_SIZE (sizeof(tcb))
#define MINIMUM_STACK_SIZE (sizeof(tcb_t))
/**
* @brief Creates a new thread.

4
core/kernel_init.c

@ -33,8 +33,8 @@
#define ENABLE_DEBUG
#include <debug.h>
volatile tcb *sched_threads[MAXTHREADS];
volatile tcb *active_thread;
volatile tcb_t *sched_threads[MAXTHREADS];
volatile tcb_t *active_thread;
volatile int lpm_prevent_sleep = 0;
extern void main(void);

44
core/msg.c

@ -27,7 +27,7 @@
//#define ENABLE_DEBUG
#include "debug.h"
static int queue_msg(tcb *target, msg *m) {
static int queue_msg(tcb_t *target, msg_t *m) {
int n = cib_put(&(target->msg_queue));
if (n != -1) {
@ -38,12 +38,12 @@ static int queue_msg(tcb *target, msg *m) {
return 0;
}
int msg_send(msg* m, unsigned int target_pid, bool block) {
int msg_send(msg_t* m, unsigned int target_pid, bool block) {
if (inISR()) {
return msg_send_int(m, target_pid);
}
tcb *target = (tcb*)sched_threads[target_pid];
tcb_t *target = (tcb_t*)sched_threads[target_pid];
m->sender_pid = thread_pid;
if (m->sender_pid == target_pid) {
@ -84,13 +84,13 @@ int msg_send(msg* m, unsigned int target_pid, bool block) {
newstatus = STATUS_SEND_BLOCKED;
}
sched_set_status((tcb*)active_thread, newstatus);
sched_set_status((tcb_t*)active_thread, newstatus);
DEBUG("%s: back from send block.\n", active_thread->name);
} else {
DEBUG("%s: direct msg copy.\n", active_thread->name);
/* copy msg to target */
msg* target_message = (msg*)target->wait_data;
msg_t* target_message = (msg_t*)target->wait_data;
*target_message = *m;
sched_set_status(target, STATUS_PENDING);
}
@ -101,8 +101,8 @@ int msg_send(msg* m, unsigned int target_pid, bool block) {
return 1;
}
int msg_send_int(msg* m, unsigned int target_pid) {
tcb *target = (tcb*)sched_threads[target_pid];
int msg_send_int(msg_t* m, unsigned int target_pid) {
tcb_t *target = (tcb_t*)sched_threads[target_pid];
if (target->status == STATUS_RECEIVE_BLOCKED) {
DEBUG("msg_send_int: direct msg copy.\n");
@ -110,7 +110,7 @@ int msg_send_int(msg* m, unsigned int target_pid) {
m->sender_pid = target_pid;
/* copy msg to target */
msg* target_message = (msg*)target->wait_data;
msg_t* target_message = (msg_t*)target->wait_data;
*target_message = *m;
sched_set_status(target, STATUS_PENDING);
@ -122,9 +122,9 @@ int msg_send_int(msg* m, unsigned int target_pid) {
}
}
int msg_send_receive(msg *m, msg *reply, unsigned int target_pid) {
int msg_send_receive(msg_t *m, msg_t *reply, unsigned int target_pid) {
dINT();
tcb *me = (tcb*) sched_threads[thread_pid];
tcb_t *me = (tcb_t*) sched_threads[thread_pid];
sched_set_status(me, STATUS_REPLY_BLOCKED);
me->wait_data = (void*) reply;
msg_send(m, target_pid, true);
@ -134,10 +134,10 @@ int msg_send_receive(msg *m, msg *reply, unsigned int target_pid) {
return 1;
}
int msg_reply(msg *m, msg *reply) {
int msg_reply(msg_t *m, msg_t *reply) {
int state = disableIRQ();
tcb *target = (tcb*)sched_threads[m->sender_pid];
tcb_t *target = (tcb_t*)sched_threads[m->sender_pid];
if (target->status != STATUS_REPLY_BLOCKED) {
DEBUG("%s: msg_reply(): target \"%s\" not waiting for reply.", active_thread->name, target->name);
restoreIRQ(state);
@ -146,7 +146,7 @@ int msg_reply(msg *m, msg *reply) {
DEBUG("%s: msg_reply(): direct msg copy.\n", active_thread->name);
/* copy msg to target */
msg* target_message = (msg*)target->wait_data;
msg_t* target_message = (msg_t*)target->wait_data;
*target_message = *reply;
sched_set_status(target, STATUS_PENDING);
restoreIRQ(state);
@ -155,24 +155,24 @@ int msg_reply(msg *m, msg *reply) {
return 1;
}
int msg_reply_int(msg *m, msg *reply) {
tcb *target = (tcb*)sched_threads[m->sender_pid];
int msg_reply_int(msg_t *m, msg_t *reply) {
tcb_t *target = (tcb_t*)sched_threads[m->sender_pid];
if (target->status != STATUS_REPLY_BLOCKED) {
DEBUG("%s: msg_reply_int(): target \"%s\" not waiting for reply.", active_thread->name, target->name);
return -1;
}
msg* target_message = (msg*)target->wait_data;
msg_t* target_message = (msg_t*)target->wait_data;
*target_message = *reply;
sched_set_status(target, STATUS_PENDING);
sched_context_switch_request = 1;
return 1;
}
int msg_receive(msg* m) {
int msg_receive(msg_t* m) {
dINT();
DEBUG("%s: msg_receive.\n", active_thread->name);
tcb *me = (tcb*) sched_threads[thread_pid];
tcb_t *me = (tcb_t*) sched_threads[thread_pid];
int n = -1;
if (me->msg_array) {
@ -202,7 +202,7 @@ int msg_receive(msg* m) {
return 1;
} else {
DEBUG("%s: msg_receive(): Wakeing up waiting thread.\n", active_thread->name);
tcb *sender = (tcb*)node->data;
tcb_t *sender = (tcb_t*)node->data;
if (n >= 0) {
/* we've already got a messgage from the queue. as there is a
@ -212,7 +212,7 @@ int msg_receive(msg* m) {
}
/* copy msg */
msg* sender_msg = (msg*)sender->wait_data;
msg_t* sender_msg = (msg_t*)sender->wait_data;
*m = *sender_msg;
/* remove sender from queue */
@ -224,10 +224,10 @@ int msg_receive(msg* m) {
}
}
int msg_init_queue(msg* array, int num) {
int msg_init_queue(msg_t* array, int num) {
/* make sure brainfuck condition is met */
if (num && (num & (num - 1)) == 0) {
tcb *me = (tcb*)active_thread;
tcb_t *me = (tcb_t*)active_thread;
me->msg_array = array;
cib_init(&(me->msg_queue), num);
return 0;

4
core/mutex.c

@ -65,7 +65,7 @@ void mutex_wait(struct mutex_t *mutex) {
return;
}
sched_set_status((tcb*)active_thread, STATUS_MUTEX_BLOCKED);
sched_set_status((tcb_t*)active_thread, STATUS_MUTEX_BLOCKED);
queue_node_t n;
n.priority = (unsigned int) active_thread->priority;
@ -90,7 +90,7 @@ void mutex_unlock(struct mutex_t* mutex, int yield) {
if (mutex->val != 0) {
if (mutex->queue.next) {
queue_node_t *next = queue_remove_head(&(mutex->queue));
tcb* process = (tcb*)next->data;
tcb_t* process = (tcb_t*)next->data;
DEBUG("%s: waking up waiter %s.\n", process->name);
sched_set_status(process, STATUS_PENDING);

21
core/sched.c

@ -25,6 +25,13 @@
volatile int num_tasks = 0;
volatile unsigned int sched_context_switch_request;
volatile tcb_t *sched_threads[MAXTHREADS];
volatile tcb_t *active_thread;
volatile int thread_pid;
clist_node_t *runqueues[SCHED_PRIO_LEVELS];
static uint32_t runqueue_bitcache = 0;
@ -56,7 +63,7 @@ void sched_init() {
void sched_run() {
sched_context_switch_request = 0;
tcb *my_active_thread = (tcb*)active_thread;
tcb_t *my_active_thread = (tcb_t*)active_thread;
if (my_active_thread) {
if( my_active_thread->status == STATUS_RUNNING) {
@ -94,9 +101,9 @@ void sched_run() {
// if (runqueues[i]) {
int nextrq = number_of_lowest_bit(runqueue_bitcache);
clist_node_t next = *(runqueues[nextrq]);
DEBUG("scheduler: first in queue: %s\n", ((tcb*)next.data)->name);
DEBUG("scheduler: first in queue: %s\n", ((tcb_t*)next.data)->name);
clist_advance(&(runqueues[nextrq]));
my_active_thread = (tcb*)next.data;
my_active_thread = (tcb_t*)next.data;
thread_pid = (volatile int) my_active_thread->pid;
#if SCHEDSTATISTICS
pidlist[my_active_thread->pid].laststart = time;
@ -115,16 +122,16 @@ void sched_run() {
active_thread->status = STATUS_PENDING ;
}
}
sched_set_status((tcb*)my_active_thread, STATUS_RUNNING);
sched_set_status((tcb_t*)my_active_thread, STATUS_RUNNING);
}
active_thread = (volatile tcb*) my_active_thread;
active_thread = (volatile tcb_t*) my_active_thread;
DEBUG("scheduler: done.\n");
}
void sched_set_status(tcb *process, unsigned int status) {
void sched_set_status(tcb_t *process, unsigned int status) {
if (status & STATUS_ON_RUNQUEUE) {
if (! (process->status & STATUS_ON_RUNQUEUE)) {
DEBUG("adding process %s to runqueue %u.\n", process->name, process->priority);
@ -163,7 +170,7 @@ void sched_task_exit(void) {
sched_threads[active_thread->pid] = NULL;
num_tasks--;
sched_set_status((tcb*)active_thread, STATUS_STOPPED);
sched_set_status((tcb_t*)active_thread, STATUS_STOPPED);
active_thread = NULL;
cpu_switch_context_exit();

8
core/thread.c

@ -39,7 +39,7 @@ unsigned int thread_getstatus(int pid) {
void thread_sleep() {
if ( inISR()) return;
dINT();
sched_set_status((tcb*)active_thread, STATUS_SLEEPING);
sched_set_status((tcb_t*)active_thread, STATUS_SLEEPING);
thread_yield();
}
@ -54,7 +54,7 @@ int thread_wakeup(int pid) {
int result = sched_threads[pid]->status;
if (result == STATUS_SLEEPING) {
DEBUG("thread_wakeup: Thread is sleeping.\n");
sched_set_status((tcb*)sched_threads[pid], STATUS_RUNNING);
sched_set_status((tcb_t*)sched_threads[pid], STATUS_RUNNING);
if (!isr) {
eINT();
thread_yield();
@ -83,7 +83,7 @@ int thread_create(char *stack, int stacksize, char priority, int flags, void (*f
{
/* allocate our thread control block at the top of our stackspace */
int total_stacksize = stacksize;
stacksize -= sizeof(tcb);
stacksize -= sizeof(tcb_t);
/* align tcb address on 32bit boundary */
unsigned int tcb_address = (unsigned int) stack + stacksize;
@ -95,7 +95,7 @@ int thread_create(char *stack, int stacksize, char priority, int flags, void (*f
tcb_address-=2;
stacksize-=2;
}
tcb *cb = (tcb*) tcb_address;
tcb_t *cb = (tcb_t*) tcb_address;
if (priority >= SCHED_PRIO_LEVELS) {
return -EINVAL;

5
cpu/arm_common/Jamfile

@ -30,6 +30,11 @@ SubDir TOP cpu arm_common ;
Module arm_common : common.s bootloader.c VIC.c atomic.s arm_cpu.c iap.c ;
UseModule arm_common ;
Module profiling : profiling.c ;
if $(PROFILING) {
UseModule profiling ;
}
Module hwtimer_cpu : hwtimer_cpu.c ;
Objects syscalls.c ;

5
cpu/arm_common/Jamrules.arm_common

@ -40,9 +40,14 @@ LINK = $(CC) ;
OPTIM = -Os ;
#OPTIM = -O0 -g ;
CCFLAGS += -std=gnu99 -Wall -mcpu=arm7tdmi-s -mfloat-abi=soft -mfpu=vfp ;
LINKFLAGS = -mcpu=arm7tdmi-s -static -lgcc -nostartfiles -T [ FPath $(TOP) cpu $(CPU) linkerscript.x ] ;
if $(PROFILING) = 1 {
CCFLAGS += -g -finstrument-functions ;
}
AS = $(TOOLCHAIN)as ;
ASFLAGS += -mcpu=arm7tdmi-s --defsym $(CPU)=1 -mfloat-abi=soft -mfpu=vfp ;

89
cpu/arm_common/profiling.c

@ -0,0 +1,89 @@
#include <stdio.h>
#include <stdint.h>
#include <cpu.h>
#include <ltc4150.h>
#define MAX_TRACED_FUNCTIONS (32)
#define PROFILING_STACK_SIZE (16)
typedef struct {
uint32_t address;
uint32_t time;
uint32_t start_time;
double consumption;
double consumption_start;
uint16_t counter;
} profiling_info_t;
static profiling_info_t functions[MAX_TRACED_FUNCTIONS];
static uint8_t profiling_stack[PROFILING_STACK_SIZE];
static uint8_t profiling_sp = 0;
static uint8_t traced_functions = 0;
static uint8_t profiling = 0;
void __attribute__((__no_instrument_function__)) profiling_init(void) {
uint8_t i;
for (i = 0; i < MAX_TRACED_FUNCTIONS; i++) {
functions[i].address = 0;
functions[i].time = 0;
functions[i].consumption = 0;
functions[i].counter = 0;
}
for (i = 0; i < PROFILING_STACK_SIZE; i++) {
profiling_stack[i] = 0;
}
ltc4150_start();
profiling = 1;
}
static int16_t __attribute__((__no_instrument_function__)) get_function_index(uint32_t addr) {
uint8_t i;
for (i = 0; i < MAX_TRACED_FUNCTIONS; i++) {
if (functions[i].address == addr) {
return i;
}
}
return -1;
}
void __attribute__((__no_instrument_function__)) __cyg_profile_func_enter (void *func, void *caller) {
if (!profiling) {
return;
}
int16_t idx = get_function_index((uint32_t) func);
if ((idx < 0) && (traced_functions < MAX_TRACED_FUNCTIONS)) {
idx = traced_functions++;
functions[idx].address = (uint32_t) func;
}
else if (idx < 0) {
return;
}
functions[idx].start_time = T0TC;
functions[idx].counter++;
functions[idx].consumption_start = ltc4150_get_total_mAh();
// functions[idx].consumption_start = ltc4150_get_intcount();
}
void __attribute__((__no_instrument_function__)) __cyg_profile_func_exit (void *func, void *caller) {
if (!profiling) {
return;
}
int16_t idx = get_function_index((uint32_t) func);
if (idx >= 0) {
functions[idx].time += T0TC - functions[idx].start_time;
//functions[idx].consumption += ltc4150_get_intcount() - functions[idx].consumption_start;
functions[idx].consumption += ltc4150_get_total_mAh() - functions[idx].consumption_start;
}
}
void profiling_stats(void) {
uint8_t i;
for (i = 0; i < traced_functions; i++) {
// printf("Function @%04lX was running %u times for %lu ticks, consuming %li ltc-ticks\n", functions[i].address, functions[i].counter, functions[i].time, functions[i].consumption);
printf("Function @%04lX was running %u times for %lu ticks, consuming %lf mAh\n", functions[i].address, functions[i].counter, functions[i].time, functions[i].consumption);
}
puts("________________________________________________________");
}

2
cpu/cc430/Jamfile

@ -29,5 +29,7 @@ SubDir TOP cpu cc430 ;
Module hwtimer_cpu : hwtimer_cc430.c : hwtimer_msp430 ;
Module rtc : cc430-rtc.c ;
Module gpioint : cc430-gpioint.c ;
Module adc : cc430-adc.c : hwtimer ;
SubInclude TOP cpu msp430-common ;

147
cpu/cc430/cc430-adc.c

@ -0,0 +1,147 @@
/* *************************************************************************************************
*
* Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* *************************************************************************************************
* ADC12 functions.
* ************************************************************************************************/
#include <signal.h>
#include <cpu.h>
#include <cc430-adc.h>
#include <hwtimer.h>
uint16_t adc12_result;
uint8_t adc12_data_ready;
/* *************************************************************************************************
* @fn adc12_single_conversion
* @brief Init ADC12. Do single conversion. Turn off ADC12.
* @param none
* @return none
* ************************************************************************************************/
uint16_t adc12_single_conversion(uint16_t ref, uint16_t sht, uint16_t channel) {
/* Initialize the shared reference module */
REFCTL0 |= REFMSTR + ref + REFON; /* Enable internal reference (1.5V or 2.5V) */
/* Initialize ADC12_A */
ADC12CTL0 = sht + ADC12ON; /* Set sample time */
ADC12CTL1 = ADC12SHP; /* Enable sample timer */
ADC12MCTL0 = ADC12SREF_1 + channel; /* ADC input channel */
ADC12IE = 0x001; /* ADC_IFG upon conv result-ADCMEMO */
eINT();
/* Wait 2 ticks (66us) to allow internal reference to settle */
hwtimer_wait(2);
/* Start ADC12 */
ADC12CTL0 |= ADC12ENC;
/* Clear data ready flag */
adc12_data_ready = 0;
/* Sampling and conversion start */
ADC12CTL0 |= ADC12SC;
/* Wait until ADC12 has finished */
hwtimer_wait(5);
while (!adc12_data_ready);
/* Shut down ADC12 */
ADC12CTL0 &= ~(ADC12ENC | ADC12SC | sht);
ADC12CTL0 &= ~ADC12ON;
/* Shut down reference voltage */
REFCTL0 &= ~(REFMSTR + ref + REFON);
ADC12IE = 0;
/* Return ADC result */
return adc12_result;
}
/* *************************************************************************************************
* @fn ADC12ISR
* @brief Store ADC12 conversion result. Set flag to indicate data ready.
* @param none
* @return none
* ************************************************************************************************/
interrupt (ADC12_VECTOR) __attribute__ ((naked)) adc_isr (void) {
__enter_isr();
switch(ADC12IV) {
case 0:
break; /* Vector 0: No interrupt */
case 2:
break; /* Vector 2: ADC overflow */
case 4:
break; /* Vector 4: ADC timing overflow */
case 6:
/* Vector 6: ADC12IFG0 */
adc12_result = ADC12MEM0; /* Move results, IFG is cleared */
adc12_data_ready = 1;
break;
case 8:
break; /* Vector 8: ADC12IFG1 */
case 10:
break; /* Vector 10: ADC12IFG2 */
case 12:
break; /* Vector 12: ADC12IFG3 */
case 14:
break; /* Vector 14: ADC12IFG4 */
case 16:
break; /* Vector 16: ADC12IFG5 */
case 18:
break; /* Vector 18: ADC12IFG6 */
case 20:
break; /* Vector 20: ADC12IFG7 */
case 22:
break; /* Vector 22: ADC12IFG8 */
case 24:
break; /* Vector 24: ADC12IFG9 */
case 26:
break; /* Vector 26: ADC12IFG10 */
case 28:
break; /* Vector 28: ADC12IFG11 */
case 30:
break; /* Vector 30: ADC12IFG12 */
case 32:
break; /* Vector 32: ADC12IFG13 */
case 34:
break; /* Vector 34: ADC12IFG14 */
default:
break;
}
__exit_isr();
}

231
cpu/cc430/cc430-gpioint.c

@ -0,0 +1,231 @@
/******************************************************************************
Copyright 2010, Freie Universität Berlin (FUB). All rights reserved.
These sources were developed at the Freie Universitaet Berlin, Computer Systems
and Telematics group (http://cst.mi.fu-berlin.de).
-------------------------------------------------------------------------------
This file is part of µkleos.
This program is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
FeuerWare is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see http://www.gnu.org/licenses/ .
--------------------------------------------------------------------------------
For further information and questions please use the web site
http://scatterweb.mi.fu-berlin.de
and the mailinglist (subscription via web site)
scatterweb@lists.spline.inf.fu-berlin.de
*******************************************************************************/
#include <stdlib.h>
#include <signal.h>
#include <gpioint.h>
#include <bitarithm.h>
#include <cpu.h>
#include <irq.h>
#include <hwtimer.h>
#include <cc430x613x.h>
/** min and max portnumber to generate interrupts */
#define PORTINT_MIN (1)
#define PORTINT_MAX (2)
/** amount of interrupt capable ports */
#define INT_PORTS (2)
/** number of bits per port */
#define BITMASK_SIZE (8)
/** debouncing port interrupts */
#define DEBOUNCE_TIMEOUT (250)
/** interrupt callbacks */
fp_irqcb cb[INT_PORTS][BITMASK_SIZE];
/** debounce interrupt flags */
uint8_t debounce_flags[INT_PORTS];
/** debounce interrupt times */
uint16_t debounce_time[INT_PORTS][BITMASK_SIZE];
uint16_t c1 = 0, c2 = 0;
void gpioint_init(void) {
uint8_t i, j;
for (i = 0; i < INT_PORTS; i++) {
for (j = 0; j < BITMASK_SIZE; j++) {
cb[i][j] = NULL;
debounce_time[i][j] = 0;
}
}
}
bool gpioint_set(int port, uint32_t bitmask, int flags, fp_irqcb callback) {
int8_t base;
if ((port >= PORTINT_MIN) && (port <= PORTINT_MAX)) {
/* set the callback function */
base = number_of_highest_bit(bitmask);
if (base >= 0) {
cb[port - PORTINT_MIN][base] = callback;
}
else {
return false;
}
if (flags & GPIOINT_DEBOUNCE) {
debounce_flags[port - PORTINT_MIN] |= bitmask;
}
else {
debounce_flags[port - PORTINT_MIN] &= ~bitmask;
}
}
switch (port) {
case 1:
/* set port to input */
P1DIR &= ~bitmask;
/* enable internal pull-down */
P1OUT &= ~bitmask;
P1REN |= bitmask;
/* reset IRQ flag */
P1IFG &= ~bitmask;
/* trigger on rising... */
if (flags & GPIOINT_RISING_EDGE) {
P1IES &= bitmask;
}
/* ...or falling edge */
if (flags & GPIOINT_FALLING_EDGE) {
P1IES |= bitmask;
}
/* disable interrupt */
if (flags == GPIOINT_DISABLE) {
P1IE &= ~bitmask;
}
/* enable interrupt */
P1IE |= bitmask;
break;
case 2:
/* set port to input */
P2DIR &= ~bitmask;
/* enable internal pull-down */
P2OUT &= ~bitmask;
P2REN |= bitmask;
/* reset IRQ flag */
P2IFG &= ~bitmask;
/* trigger on rising... */
if (flags == GPIOINT_RISING_EDGE) {
P2IES &= bitmask;
}
/* ...or falling edge */
else if (flags == GPIOINT_FALLING_EDGE) {
P2IES |= bitmask;
}
/* or disable interrupt */
else {
P2IE &= ~bitmask;
}
/* enable interrupt */
P2IE |= bitmask;
break;
default:
return false;
}
return 1;
}
interrupt (PORT1_VECTOR) __attribute__ ((naked)) port1_isr(void) {
uint8_t int_enable, ifg_num, p1ifg;
uint16_t p1iv;
uint16_t diff;
__enter_isr();
/* Debounce
* Disable PORT1 IRQ
*/
p1ifg = P1IFG;
p1iv = P1IV;
int_enable = P1IE;
P1IE = 0x00;
ifg_num = (p1iv >> 1) - 1;
/* check interrupt source */
if (debounce_flags[0] & p1ifg) {
/* check if bouncing */
diff = hwtimer_now() - debounce_time[0][ifg_num];
if (diff > DEBOUNCE_TIMEOUT) {
debounce_time[0][ifg_num] = hwtimer_now();
if (cb[0][ifg_num] != NULL) {
cb[0][ifg_num]();
}
}