[Tinyos-beta-commits] CVS: tinyos-1.x/beta/platform/pxa27x/lib assert.h, NONE, 1.1 criticalSection.h, NONE, 1.1 systemUtil.c, NONE, 1.1 systemUtil.h, NONE, 1.1 utils.c, NONE, 1.1 utils.h, NONE, 1.1 Makefile, 1.4, 1.5 queue.c, 1.3, 1.4 queue.h, 1.3, 1.4

Robbie Adler radler at users.sourceforge.net
Wed Oct 25 08:32:54 PDT 2006


Update of /cvsroot/tinyos/tinyos-1.x/beta/platform/pxa27x/lib
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv9017

Modified Files:
	Makefile queue.c queue.h 
Added Files:
	assert.h criticalSection.h systemUtil.c systemUtil.h utils.c 
	utils.h 
Log Message:
release of new motelib functions and headers

--- NEW FILE: assert.h ---
#ifndef __ASSERT_H__
#define __ASSERT_H__

#undef assert
#ifdef NDEBUG
#define assert(e) ((void)0)
#else
extern void printAssertMsg(const char* file, uint32_t line, char *condition) __attribute__((C));
#define assert(e) ((void)((e) || (printAssertMsg(__FILE__, (int)__LINE__, #e), 0)))
#endif

#endif //__ASSERT_H__


--- NEW FILE: criticalSection.h ---
#ifndef __CRITICAL_SECTION_H__
#define __CRITICAL_SECTION_H__

#define DECLARE_CRITICAL_SECTION()  uint32_t fInterruptFlags
#define CRITICAL_SECTION_BEGIN() fInterruptFlags = __nesc_atomic_start()
#define CRITICAL_SECTION_END()   __nesc_atomic_end(fInterruptFlags)

#endif // __CRITICAL_SECTION_H__

--- NEW FILE: systemUtil.c ---

#include "systemUtil.h"
#include "pxa27x_registers_def.h"

#define RESET_DELAY 10000  // delay in 1/3.25 MHz increments = ~3 ms

const char csFatalError[] = "FATAL ERROR: ";
const char csRebootMsg[] = "Rebooting...";

static void configureUART(){
  
  GPIO_SET_ALT_FUNC(46,2,GPIO_IN);
  GPIO_SET_ALT_FUNC(47,1,GPIO_OUT);
  
  //turn on the port's clock
  CKEN |= (CKEN_CKEN5);

  STIER = IER_UUE; //disable all interrupts on the port and enable
  
  STLCR |=LCR_DLAB; //turn on DLAB so we can change the divisor
  STDLL = 8;  //configure to 115200;
  STDLH = 0;
  STLCR &= ~(LCR_DLAB);  //turn off DLAB
    
  STLCR |= 0x3; //configure to 8 bits

  STFCR = FCR_ITL(0) | FCR_TIL | FCR_RESETTF | FCR_TRFIFOE;
  STMCR &= ~MCR_LOOP;
  STMCR |= MCR_OUT2;
}

static void printChar(char data){
  STTHR = data;
  while((STLSR & LSR_TEMT) == 0);
}

static void printString(const char *str,uint32_t strlen){
  uint32_t i;
  
  for(i=0; i<strlen; i++){
    printChar(str[i]);
  }
}

// print one byte in hex
static void printHex(uint8_t num){
  uint32_t i;

  switch(num & 0xF){
    case 0:
      printChar('0');
      break;
    case 1:
      printChar('1');
      break;
    case 2:
      printChar('2');
      break;
    case 3:
      printChar('3');
      break;
    case 4:
      printChar('4');
      break;
    case 5:
      printChar('5');
      break;
    case 6:
      printChar('6');
      break;
    case 7:
      printChar('7');
      break;
    case 8:
      printChar('8');
      break;
    case 9:
      printChar('9');
      break;
    case 10:
      printChar('A');
      break;
    case 11:
      printChar('B');
      break;
    case 12:
      printChar('C');
      break;
    case 13:
      printChar('D');
      break;
    case 14:
      printChar('E');
      break;
    case 15:
      printChar('F');
      break;
  }
}


static void printHex32(uint32_t num){
  int i;
  
  printChar('0');
  printChar('x');
  
  for(i=7; i>=0; i--){
    printHex(num>>(4*i));
  }
}

static void printDecimal(uint32_t num){
  int i,numDigits =1;
  char buf[10];

  for(i=0;i<10;i++){
    buf[9-i] = '0' + (num % 10);
    if(buf[9-i] != '0'){
      numDigits = i+1;
    }
    num = num/10;
  }
  printString((const char *)(buf+10-numDigits),numDigits);
}

void printAssertMsg(const char* file, uint32_t line, char *condition){
  
  configureUART();
  
  printString(csFatalError, strlen(csFatalError));
  printString(file,strlen(file));
  printChar(':');
  printDecimal(line);
  printString(": Assertion failed: ",strlen(": Assertion failed: "));
  printString(condition, strlen(condition));
  printChar('\r');
  printChar('\n');

  resetNode();
}

void printFatalErrorMsg(const char *msg, uint32_t status){
  uint32_t i, len;
  
  configureUART();
  
  printString(csFatalError, strlen(csFatalError)); 
  printString(msg, strlen(msg));
  printDecimal(status);
  printChar('\r');
  printChar('\n');
  
  resetNode();
}

void resetNode(){
  
  configureUART();
  
  printString(csRebootMsg, strlen(csRebootMsg));
  printChar('\r');
  printChar('\n');
  
  OSMR3 = OSCR0 + RESET_DELAY;
  OWER = 1;
  while(1);
}

--- NEW FILE: systemUtil.h ---
#ifndef __SYSTEM_UTIL_H__
#define __SYSTEM_UTIL_H__

#include "inttypes.h"

/****
printFatalErrorMsg will print the parameter msg prepended with FATAL ERROR
and appended with status printed as a hex # to the STUART. 

*****/
void printFatalErrorMsg(const char *msg, uint32_t status);

void resetNode();


#endif // __SYSTEM_UTIL_H__

--- NEW FILE: utils.c ---
#include "utils.h"
#include "inttypes.h"
#include "criticalSection.h"
#include <stdlib.h>


/*
 * These functions are equivalent to the standard lib functions, except that
 * they disable all interrupts before executing the function.
 */

void *safe_malloc(size_t size) {
  DECLARE_CRITICAL_SECTION();
  void *retVal;

  CRITICAL_SECTION_BEGIN();
  retVal = malloc(size);
  CRITICAL_SECTION_END();
  return retVal;
}

void *safe_calloc(size_t nelem, size_t elsize) {
  DECLARE_CRITICAL_SECTION();
  void *retVal;

  CRITICAL_SECTION_BEGIN();
  retVal = calloc(nelem, elsize);
  CRITICAL_SECTION_END();
  return retVal;
}

void *safe_memalign(size_t alignment, size_t length){
  
  DECLARE_CRITICAL_SECTION();
  void *retVal;
  
  CRITICAL_SECTION_BEGIN();
  retVal = memalign(alignment, length);
  CRITICAL_SECTION_END();
  return retVal;
}


void *safe_realloc(void *ptr, size_t size) {
  DECLARE_CRITICAL_SECTION();
  void *retVal;

  CRITICAL_SECTION_BEGIN();
  retVal = realloc(ptr, size);
  CRITICAL_SECTION_END();
  return retVal;
}

void safe_free(void *ptr) {
  DECLARE_CRITICAL_SECTION();
  
  CRITICAL_SECTION_BEGIN();
  free(ptr);
  CRITICAL_SECTION_END();
  return;
}

--- NEW FILE: utils.h ---
#ifndef __UTILS_H__
#define __UTILS_H__

#include <stddef.h>

/*
 * These functions are equivalent to the standard lib functions, except that
 * they disable all interrupts before executing the function.
 */

void *safe_malloc(size_t size);
void *safe_calloc(size_t nelem, size_t elsize);
void *safe_realloc(void *ptr, size_t size);
void *safe_memalign(size_t alignment, size_t length);
void safe_free(void *ptr);


#endif

Index: Makefile
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/platform/pxa27x/lib/Makefile,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** Makefile	10 Oct 2006 02:29:11 -0000	1.4
--- Makefile	25 Oct 2006 15:32:47 -0000	1.5
***************
*** 4,8 ****
  
  CC = xscale-elf-gcc
! CFLAGS = -g -O3 $(INCLUDE_DIRS)
  
  AS = xscale-elf-as
--- 4,8 ----
  
  CC = xscale-elf-gcc
! CFLAGS = -g -O2 $(INCLUDE_DIRS)
  
  AS = xscale-elf-as
***************
*** 37,41 ****
  
  #always make the library for debugging
! #.PHONY: libimote2.a
  
  libimote2.a: $(SRCS)
--- 37,41 ----
  
  #always make the library for debugging
! .PHONY: libimote2.a
  
  libimote2.a: $(SRCS)

Index: queue.c
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/platform/pxa27x/lib/queue.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** queue.c	10 Oct 2006 02:29:11 -0000	1.3
--- queue.c	25 Oct 2006 15:32:47 -0000	1.4
***************
*** 31,34 ****
--- 31,39 ----
  }
  
+ int getCurrentQueueSize(queue_t *queue){
+   
+   return (queue->head <= queue->tail) ? queue->size - queue->tail + queue->head: queue->head - queue->tail;
+ 
+ }
  
  int popqueue(queue_t *queue, uint32_t *val) {

Index: queue.h
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/platform/pxa27x/lib/queue.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** queue.h	10 Oct 2006 02:29:11 -0000	1.3
--- queue.h	25 Oct 2006 15:32:47 -0000	1.4
***************
*** 58,60 ****
--- 58,62 ----
  void initqueue(queue_t *queue, uint32_t size);
  
+ int getCurrentQueueSize(queue_t *queue);
+ 
  #endif



More information about the Tinyos-beta-commits mailing list