1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-16 18:13:49 +01:00

[board msba2-common] [sys chardev_thread] [sys shell] [driver cc110x_ng] [core msg]

* some cosmetics and cleanups
This commit is contained in:
Oliver Hahm 2012-02-16 21:33:41 +01:00
parent 64e0c5b246
commit 0d6d3e2c43
6 changed files with 24 additions and 26 deletions

View File

@ -202,7 +202,6 @@ bl_uart_init(void)
/* irq */ /* irq */
install_irq(UART0_INT, UART0_IRQHandler, 6); install_irq(UART0_INT, UART0_IRQHandler, 6);
// U0IER |= BIT0 | BIT1; // enable RX+TX irq
U0IER |= BIT0; // enable only RX irq U0IER |= BIT0; // enable only RX irq
return 1; return 1;
} }

View File

@ -105,7 +105,7 @@ int msg_send_int(msg_t* m, unsigned int target_pid) {
tcb_t *target = (tcb_t*)sched_threads[target_pid]; tcb_t *target = (tcb_t*)sched_threads[target_pid];
if (target->status == STATUS_RECEIVE_BLOCKED) { if (target->status == STATUS_RECEIVE_BLOCKED) {
DEBUG("msg_send_int: direct msg copy.\n"); DEBUG("msg_send_int: direct msg copy from %i to %i.\n", thread_getpid(), target_pid);
m->sender_pid = target_pid; m->sender_pid = target_pid;

View File

@ -14,10 +14,11 @@
#ifdef DBG_IGNORE #ifdef DBG_IGNORE
#include <stdio.h> #include <stdio.h>
#include <string.h>
#define IGN_MAX (10) #define IGN_MAX (10)
uint8_t ignored_addr[IGN_MAX]; radio_address_t ignored_addr[IGN_MAX];
static uint8_t is_ignored(uint8_t addr); static uint8_t is_ignored(radio_address_t addr);
#endif #endif
static uint8_t receive_packet_variable(uint8_t *rxBuffer, uint8_t length); static uint8_t receive_packet_variable(uint8_t *rxBuffer, uint8_t length);
@ -60,6 +61,7 @@ void cc110x_rx_handler(void) {
#ifdef DBG_IGNORE #ifdef DBG_IGNORE
if (is_ignored(cc110x_rx_buffer[rx_buffer_next].packet.phy_src)) { if (is_ignored(cc110x_rx_buffer[rx_buffer_next].packet.phy_src)) {
LED_RED_TOGGLE;
return; return;
} }
#endif #endif
@ -114,8 +116,6 @@ static uint8_t receive_packet_variable(uint8_t *rxBuffer, uint8_t length) {
/* Any bytes available in RX FIFO? */ /* Any bytes available in RX FIFO? */
if ((cc110x_read_status(CC1100_RXBYTES) & BYTES_IN_RXFIFO)) { if ((cc110x_read_status(CC1100_RXBYTES) & BYTES_IN_RXFIFO)) {
//LED_GREEN_TOGGLE;
//LED_RED_TOGGLE;
// Read length byte (first byte in RX FIFO) // Read length byte (first byte in RX FIFO)
cc110x_read_fifo((char*) &packetLength, 1); cc110x_read_fifo((char*) &packetLength, 1);
// Read data from RX FIFO and store in rxBuffer // Read data from RX FIFO and store in rxBuffer
@ -153,7 +153,6 @@ static uint8_t receive_packet_variable(uint8_t *rxBuffer, uint8_t length) {
} }
/* no bytes in RX FIFO */ /* no bytes in RX FIFO */
else { else {
//LED_RED_TOGGLE;
// RX FIFO get automatically flushed if return value is false // RX FIFO get automatically flushed if return value is false
return 0; return 0;
} }
@ -172,28 +171,23 @@ static uint8_t receive_packet(uint8_t *rxBuffer, uint8_t length) {
#ifdef DBG_IGNORE #ifdef DBG_IGNORE
void cc110x_init_ignore(void) { void cc110x_init_ignore(void) {
uint8_t i; memset(ignored_addr, 0, IGN_MAX*sizeof(radio_address_t));
for (i = 0; i < IGN_MAX; i++) {
ignored_addr[i] = 0;
}
} }
uint8_t cc110x_add_ignored(uint8_t addr) { uint8_t cc110x_add_ignored(radio_address_t addr) {
uint8_t i = 0; uint8_t i = 0;
while ((i < IGN_MAX) && ignored_addr[i++]) { while ((i < IGN_MAX) && ignored_addr[i++]) {
printf("i: %hu\n", i); printf("i: %hu\n", i);
} }
printf("Adding %hu to ignore list at position %hu\n", addr, i); if (i > IGN_MAX) {
if (i >= IGN_MAX) {
return 0; return 0;
} }
ignored_addr[i-1] = addr; ignored_addr[i-1] = addr;
return 1; return 1;
} }
static uint8_t is_ignored(uint8_t addr) { static uint8_t is_ignored(radio_address_t addr) {
uint8_t i; uint8_t i;
for (i = 0; i < IGN_MAX; i++) { for (i = 0; i < IGN_MAX; i++) {

View File

@ -145,7 +145,7 @@ void cc110x_init_ignore(void);
* @return 0 if list is full, 1 otherwise * @return 0 if list is full, 1 otherwise
* *
*/ */
uint8_t cc110x_add_ignored(uint8_t addr); uint8_t cc110x_add_ignored(radio_address_t addr);
#endif #endif

View File

@ -29,14 +29,16 @@ void chardev_loop(ringbuffer_t *rb) {
while (1) { while (1) {
msg_receive(&m); msg_receive(&m);
if (m.sender_pid == pid) { if (m.sender_pid != pid) {
} else { DEBUG("Receiving message from another thread");
switch (m.type) { switch (m.type) {
case OPEN: case OPEN:
if (reader_pid == -1) { if (reader_pid == -1) {
reader_pid = m.sender_pid; reader_pid = m.sender_pid;
m.content.value = 0; // no error /* no error */
} else { m.content.value = 0;
}
else {
m.content.value = -EBUSY; m.content.value = -EBUSY;
} }
msg_reply(&m,&m); msg_reply(&m,&m);
@ -44,8 +46,10 @@ void chardev_loop(ringbuffer_t *rb) {
case READ: case READ:
if (m.sender_pid != reader_pid) { if (m.sender_pid != reader_pid) {
m.content.value = -EINVAL; m.content.value = -EINVAL;
r = NULL;
msg_reply(&m, &m); msg_reply(&m, &m);
} else { }
else {
r = (struct posix_iop_t *)m.content.ptr; r = (struct posix_iop_t *)m.content.ptr;
} }
break; break;
@ -55,7 +59,8 @@ void chardev_loop(ringbuffer_t *rb) {
reader_pid = -1; reader_pid = -1;
r = NULL; r = NULL;
m.content.value = 0; m.content.value = 0;
} else { }
else {
m.content.value = -EINVAL; m.content.value = -EINVAL;
} }
msg_reply(&m,&m); msg_reply(&m,&m);
@ -69,7 +74,7 @@ void chardev_loop(ringbuffer_t *rb) {
if (rb->avail && (r != NULL)) { if (rb->avail && (r != NULL)) {
int state = disableIRQ(); int state = disableIRQ();
int nbytes = min(r->nbytes, rb->avail); int nbytes = min(r->nbytes, rb->avail);
DEBUG("uart0_thread: sending %i bytes to pid %i\n", nbytes, reader_pid); DEBUG("uart0_thread [%i]: sending %i bytes received from %i to pid %i\n", pid, nbytes, m.sender_pid, reader_pid);
rb_get_elements(rb, r->buffer, nbytes); rb_get_elements(rb, r->buffer, nbytes);
r->nbytes = nbytes; r->nbytes = nbytes;
@ -78,7 +83,6 @@ void chardev_loop(ringbuffer_t *rb) {
m.content.ptr = (char*)r; m.content.ptr = (char*)r;
msg_reply(&m, &m); msg_reply(&m, &m);
// DEBUG("uart0_thread: sending res=%i\n", res);
r = NULL; r = NULL;
restoreIRQ(state); restoreIRQ(state);

View File

@ -136,7 +136,8 @@ int readline(shell_t *shell, char* buf, int size) {
if (c == 10) { if (c == 10) {
*line_buf_ptr = '\0'; *line_buf_ptr = '\0';
return 0; return 0;
} else { }
else {
*line_buf_ptr++ = c; *line_buf_ptr++ = c;
} }
} }