summaryrefslogtreecommitdiff
path: root/openpicc/application
diff options
context:
space:
mode:
authorhenryk <henryk@6dc7ffe9-61d6-0310-9af1-9938baff3ed1>2007-11-06 20:26:48 +0000
committerhenryk <henryk@6dc7ffe9-61d6-0310-9af1-9938baff3ed1>2007-11-06 20:26:48 +0000
commit633c646ab36368caf6eaeedd326d9f1835196afd (patch)
treefdd0f60747745d3e528c0f5d8f8895b26fb79633 /openpicc/application
parent3b41196cb6b64cf6ba8ba41d6995428f73d4764a (diff)
Initial import of FreeRTOS code for OpenPICC
git-svn-id: https://svn.openpcd.org:2342/trunk@311 6dc7ffe9-61d6-0310-9af1-9938baff3ed1
Diffstat (limited to 'openpicc/application')
-rw-r--r--openpicc/application/cmd.c303
-rw-r--r--openpicc/application/cmd.h18
-rw-r--r--openpicc/application/env.c149
-rw-r--r--openpicc/application/env.h46
-rw-r--r--openpicc/application/led.c90
-rw-r--r--openpicc/application/led.h33
-rw-r--r--openpicc/application/main.c93
-rw-r--r--openpicc/application/openpicc.h36
8 files changed, 768 insertions, 0 deletions
diff --git a/openpicc/application/cmd.c b/openpicc/application/cmd.c
new file mode 100644
index 0000000..ec8236a
--- /dev/null
+++ b/openpicc/application/cmd.c
@@ -0,0 +1,303 @@
+#include <AT91SAM7.h>
+#include <FreeRTOS.h>
+#include <task.h>
+#include <queue.h>
+#include <USB-CDC.h>
+#include <board.h>
+
+#include "env.h"
+#include "cmd.h"
+#include "openpicc.h"
+#include "led.h"
+
+xQueueHandle xCmdQueue;
+xTaskHandle xCmdTask;
+xTaskHandle xCmdRecvUsbTask;
+
+/**********************************************************************/
+void DumpUIntToUSB(unsigned int data)
+{
+ int i=0;
+ unsigned char buffer[10],*p=&buffer[sizeof(buffer)];
+
+ do {
+ *--p='0'+(unsigned char)(data%10);
+ data/=10;
+ i++;
+ } while(data);
+
+ while(i--)
+ vUSBSendByte(*p++);
+}
+/**********************************************************************/
+
+void DumpStringToUSB(char* text)
+{
+ unsigned char data;
+
+ if(text)
+ while((data=*text++)!=0)
+ vUSBSendByte(data);
+}
+/**********************************************************************/
+
+static inline unsigned char HexChar(unsigned char nibble)
+{
+ return nibble + ((nibble<0x0A) ? '0':('A'-0xA));
+}
+
+void DumpBufferToUSB(char* buffer, int len)
+{
+ int i;
+
+ for(i=0; i<len; i++) {
+ vUSBSendByte(HexChar( *buffer >> 4));
+ vUSBSendByte(HexChar( *buffer++ & 0xf));
+ }
+}
+/**********************************************************************/
+
+/*
+ * Convert a string to an integer. Ignores leading spaces.
+ * Optionally returns a pointer to the end of the number in the string */
+int atoiEx(const char * nptr, char * * eptr)
+{
+ portBASE_TYPE sign = 1, i=0;
+ int curval = 0;
+ while(nptr[i] == ' ' && nptr[i] != 0) i++;
+ if(nptr[i] == 0) goto out;
+ if(nptr[i] == '-') {sign *= -1; i++; }
+ else if(nptr[i] == '+') { i++; }
+ while(nptr[i] != 0 && nptr[i] >= '0' && nptr[i] <= '9')
+ curval = curval * 10 + (nptr[i++] - '0');
+
+ out:
+ if(eptr != NULL) *eptr = (char*)nptr+i;
+ return sign * curval;
+}
+
+static const AT91PS_SPI spi = AT91C_BASE_SPI;
+#define SPI_MAX_XFER_LEN 33
+
+extern volatile unsigned portLONG ulCriticalNesting;
+void prvExecCommand(u_int32_t cmd, portCHAR *args) {
+ static int led = 0;
+ portCHAR cByte = cmd & 0xff;
+ portLONG j;
+ int i,h,m,s;
+ if(cByte>='A' && cByte<='Z')
+ cByte-=('A'-'a');
+
+ DumpStringToUSB("Got command ");
+ DumpUIntToUSB(cmd);
+ DumpStringToUSB(" with args ");
+ DumpStringToUSB(args);
+ DumpStringToUSB("\n\r");
+
+ i=0;
+ // Note: Commands have been uppercased when this code is called
+ switch(cmd)
+ {
+ case '4':
+ case '3':
+ case '2':
+ case '1':
+ env.e.mode=cmd-'0';
+ DumpStringToUSB(" * Switched to transmit mode at power level ");
+ DumpUIntToUSB(env.e.mode);
+ DumpStringToUSB("\n\r");
+ break;
+ case 'S':
+ env_store();
+ DumpStringToUSB(" * Stored environment variables\n\r");
+ break;
+ case '0':
+ DumpStringToUSB(" * switched to RX mode\n\r");
+ break;
+ case 'TEST':
+ DumpStringToUSB("Testing critical sections\r\n");
+ j=ulCriticalNesting;
+ DumpStringToUSB("Nesting is now ");
+ DumpUIntToUSB(j);
+ DumpStringToUSB("\n\r");
+ taskENTER_CRITICAL();
+ for(i=0; i<1000; i++) {;}
+ j=ulCriticalNesting;
+ taskEXIT_CRITICAL();
+ DumpStringToUSB("Nesting was ");
+ DumpUIntToUSB(j);
+ DumpStringToUSB("\n\r");
+ j=ulCriticalNesting;
+ DumpStringToUSB("Nesting is now ");
+ DumpUIntToUSB(j);
+ DumpStringToUSB("\n\r");
+ break;
+ case 'I':
+ i=atoiEx(args, &args);
+ if(i!=0) {
+ env.e.reader_id = i;
+ DumpStringToUSB("Reader ID set to ");
+ DumpUIntToUSB(env.e.reader_id);
+ DumpStringToUSB("\n\r");
+ }
+ break;
+ case 'C':
+ DumpStringToUSB(
+ " *****************************************************\n\r"
+ " * Current configuration: *\n\r"
+ " *****************************************************\n\r"
+ " *\n\r");
+ DumpStringToUSB(" * Uptime is ");
+ s=xTaskGetTickCount()/1000;
+ h=s/3600;
+ s%=3600;
+ m=s/60;
+ s%=60;
+ DumpUIntToUSB(h);
+ DumpStringToUSB("h:");
+ DumpUIntToUSB(m);
+ DumpStringToUSB("m:");
+ DumpUIntToUSB(s);
+ DumpStringToUSB("s");
+ DumpStringToUSB("\n\r");
+ DumpStringToUSB(" * The reader id is ");
+ DumpUIntToUSB(env.e.reader_id);
+ DumpStringToUSB("\n\r");
+ DumpStringToUSB(" * The mode is ");
+ DumpUIntToUSB(env.e.mode);
+ DumpStringToUSB("\n\r");
+ DumpStringToUSB(" * The transmit interval is ");
+ DumpUIntToUSB(env.e.speed);
+ DumpStringToUSB("00ms\n\r");
+ DumpStringToUSB(
+ " *\n\r"
+ " *****************************************************\n\r"
+ );
+ break;
+ case '+':
+ case '-':
+ if(cmd == '+')
+ {
+ if(env.e.speed<9)
+ env.e.speed++;
+ }
+ else
+ if(env.e.speed>1)
+ env.e.speed--;
+
+ DumpStringToUSB(" * Transmit interval set to ");
+ vUSBSendByte(((char)(env.e.speed))+'0');
+ DumpStringToUSB("00ms\n\r");
+ break;
+ case 'L':
+ led = (led+1)%4;
+ vLedSetRed( (led&1) );
+ vLedSetGreen( led&2 );
+ DumpStringToUSB(" * LEDs set to ");
+ vUSBSendByte( (char)led + '0' );
+ DumpStringToUSB("\n\r");
+ break;
+ case 'H':
+ case '?':
+ DumpStringToUSB(
+ " *****************************************************\n\r"
+ " * OpenPICC USB terminal *\n\r"
+ " * (C) 2007 Milosch Meriac <meriac@openbeacon.de> *\n\r"
+ " * (C) 2007 Henryk Plötz <henryk@ploetzli.ch> *\n\r"
+ " *****************************************************\n\r"
+ " *\n\r"
+ " * s - store transmitter settings\n\r"
+ " * test - test critical sections\n\r"
+ " * c - print configuration\n\r"
+ " * 0 - receive only mode\n\r"
+ " * 1..4 - automatic transmit at selected power levels\n\r"
+ " * +,- - faster/slower transmit speed\n\r"
+ " * l - cycle LEDs\n\r"
+ " * ?,h - display this help screen\n\r"
+ " *\n\r"
+ " *****************************************************\n\r"
+ );
+ break;
+ }
+
+}
+
+// A task to execute commands
+void vCmdCode(void *pvParameters) {
+ (void) pvParameters;
+ u_int32_t cmd;
+ portBASE_TYPE i, j=0;
+
+ for(;;) {
+ cmd_type next_command;
+ cmd = j = 0;
+ if( xQueueReceive(xCmdQueue, &next_command, ( portTickType ) 100 ) ) {
+ DumpStringToUSB("Command received:");
+ DumpStringToUSB(next_command.command);
+ DumpStringToUSB("\n\r");
+ while(next_command.command[j] == ' ' && next_command.command[j] != 0) {
+ j++;
+ }
+ for(i=0;i<4;i++) {
+ portCHAR cByte = next_command.command[i+j];
+ if(next_command.command[i+j] == 0 || next_command.command[i+j] == ' ')
+ break;
+ if(cByte>='a' && cByte<='z') {
+ cmd = (cmd<<8) | (cByte+('A'-'a'));
+ } else cmd = (cmd<<8) | cByte;
+ }
+ while(next_command.command[i+j] == ' ' && next_command.command[i+j] != 0) {
+ i++;
+ }
+ prvExecCommand(cmd, next_command.command+i+j);
+ } else {
+ }
+ }
+}
+
+// A task to read commands from USB
+void vCmdRecvUsbCode(void *pvParameters) {
+ portBASE_TYPE len=0;
+ cmd_type next_command = { source: SRC_USB, command: ""};
+ (void) pvParameters;
+
+ for( ;; ) {
+ if(vUSBRecvByte(&next_command.command[len], 1, 100)) {
+ next_command.command[len+1] = 0;
+ DumpStringToUSB(next_command.command + len);
+ if(next_command.command[len] == '\n' || next_command.command[len] == '\r') {
+ next_command.command[len] = 0;
+ if(len > 0) {
+ if( xQueueSend(xCmdQueue, &next_command, 0) != pdTRUE) {
+ DumpStringToUSB("Queue full, command can't be processed.\n");
+ }
+ len=0;
+ }
+ } else len++;
+ if(len >= MAX_CMD_LEN-1) {
+ DumpStringToUSB("ERROR: Command too long. Ignored.");
+ len=0;
+ }
+ }
+ }
+}
+
+portBASE_TYPE vCmdInit(void) {
+ /* FIXME Maybe modify to use pointers? */
+ xCmdQueue = xQueueCreate( 10, sizeof(cmd_type) );
+ if(xCmdQueue == 0) {
+ return 0;
+ }
+
+ if(xTaskCreate(vCmdCode, (signed portCHAR *)"CMD", TASK_CMD_STACK, NULL,
+ TASK_CMD_PRIORITY, &xCmdTask) != pdPASS) {
+ return 0;
+ }
+
+ if(xTaskCreate(vCmdRecvUsbCode, (signed portCHAR *)"CMDUSB", TASK_CMD_STACK, NULL,
+ TASK_CMD_PRIORITY, &xCmdRecvUsbTask) != pdPASS) {
+ return 0;
+ }
+
+ return 1;
+}
diff --git a/openpicc/application/cmd.h b/openpicc/application/cmd.h
new file mode 100644
index 0000000..8c048f2
--- /dev/null
+++ b/openpicc/application/cmd.h
@@ -0,0 +1,18 @@
+#ifndef CMD_H_
+#define CMD_H_
+
+#include <queue.h>
+
+#define MAX_CMD_LEN 32
+
+typedef struct {
+ enum { SRC_USB, SRC_RF } source;
+ portCHAR command[ MAX_CMD_LEN ];
+} cmd_type;
+
+portBASE_TYPE vCmdInit(void);
+extern void DumpStringToUSB(char *string);
+extern void DumpBufferToUSB(char* buffer, int len);
+extern xQueueHandle xCmdQueue;
+
+#endif /*CMD_H_*/
diff --git a/openpicc/application/env.c b/openpicc/application/env.c
new file mode 100644
index 0000000..92c8014
--- /dev/null
+++ b/openpicc/application/env.c
@@ -0,0 +1,149 @@
+/***************************************************************
+ *
+ * OpenBeacon.org - flash routines for persistent environment
+ *
+ * Copyright 2007 Milosch Meriac <meriac@openbeacon.de>
+ *
+ ***************************************************************
+
+ 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; version 2.
+
+ This program 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, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+*/
+#include <FreeRTOS.h>
+#include <AT91SAM7.h>
+#include <lib_AT91SAM7.h>
+#include <string.h>
+#include <board.h>
+#include <task.h>
+#include "env.h"
+
+#define EFCS_CMD_WRITE_PAGE 0x1
+#define EFCS_CMD_SET_LOCK_BIT 0x2
+#define EFCS_CMD_WRITE_PAGE_LOCK 0x3
+#define EFCS_CMD_CLEAR_LOCK 0x4
+#define EFCS_CMD_ERASE_ALL 0x8
+#define EFCS_CMD_SET_NVM_BIT 0xb
+#define EFCS_CMD_CLEAR_NVM_BIT 0xd
+#define EFCS_CMD_SET_SECURITY_BIT 0xf
+
+#define PAGES_PER_LOCKREGION (AT91C_IFLASH_LOCK_REGION_SIZE>>AT91C_IFLASH_PAGE_SHIFT)
+#define IS_FIRST_PAGE_OF_LOCKREGION(x) ((x % PAGES_PER_LOCKREGION) == 0)
+#define LOCKREGION_FROM_PAGE(x) (x / PAGES_PER_LOCKREGION)
+#define ENV_FLASH ((unsigned int *)AT91C_IFLASH + AT91C_IFLASH_SIZE - ENVIRONMENT_SIZE)
+
+TEnvironmentBlock env;
+
+static inline unsigned short RAMFUNC page_from_ramaddr(const void *addr)
+{
+ unsigned long ramaddr = (unsigned long) addr;
+ ramaddr -= (unsigned long) AT91C_IFLASH;
+ return ((ramaddr >> AT91C_IFLASH_PAGE_SHIFT));
+}
+
+static inline int RAMFUNC is_page_locked(unsigned short page)
+{
+ unsigned short lockregion = LOCKREGION_FROM_PAGE(page);
+
+ return (AT91C_BASE_MC->MC_FSR & (lockregion << 16));
+}
+
+static inline void RAMFUNC flash_cmd_wait(void)
+{
+ while(( *AT91C_MC_FSR & AT91C_MC_FRDY ) != AT91C_MC_FRDY );
+}
+
+static inline void RAMFUNC unlock_page(unsigned short page)
+{
+ page &= 0x3ff;
+ AT91F_MC_EFC_PerformCmd(AT91C_BASE_MC, AT91C_MC_FCMD_UNLOCK |
+ AT91C_MC_CORRECT_KEY | (page << 8));
+ flash_cmd_wait();
+}
+
+static inline void RAMFUNC flash_page(const void *addr)
+{
+ unsigned short page = page_from_ramaddr(addr) & 0x3ff;
+
+ if (is_page_locked(page))
+ unlock_page(page);
+
+ AT91F_MC_EFC_PerformCmd(AT91C_BASE_MC, AT91C_MC_FCMD_START_PROG |
+ AT91C_MC_CORRECT_KEY | (page << 8));
+ flash_cmd_wait();
+}
+
+unsigned short RAMFUNC env_crc16 (const unsigned char *buffer, int size)
+{
+ unsigned short crc = 0xFFFF;
+
+ if(buffer && size)
+ while (size--)
+ {
+ crc = (crc >> 8) | (crc << 8);
+ crc ^= *buffer++;
+ crc ^= ((unsigned char) crc) >> 4;
+ crc ^= crc << 12;
+ crc ^= (crc & 0xFF) << 5;
+ }
+
+ return crc;
+}
+
+void RAMFUNC env_store(void)
+{
+ unsigned int i,*src,*dst;
+
+ /* During flashing only RAMFUNC code may be executed.
+ * For now, this means that no other code whatsoever may
+ * be run until this function returns. */
+ vTaskSuspendAll();
+ portENTER_CRITICAL();
+
+ env.e.magic=TENVIRONMENT_MAGIC;
+ env.e.crc16=0;
+ env.e.size=sizeof(env);
+ env.e.crc16=env_crc16((unsigned char*)&env,sizeof(env));
+
+ src=env.data;
+ dst=ENV_FLASH;
+ for (i = 0; i < (sizeof(env.data)/sizeof(env.data[0])); i++)
+ *dst++ = *src++;
+
+ flash_page(ENV_FLASH);
+
+ portEXIT_CRITICAL();
+ xTaskResumeAll();
+}
+
+int env_load(void)
+{
+ unsigned int crc;
+
+ memcpy(&env,ENV_FLASH,sizeof(env));
+
+ if(env.e.magic!=TENVIRONMENT_MAGIC || env.e.size!=sizeof(env) )
+ return 0;
+
+ crc=env.e.crc16;
+ env.e.crc16=0;
+
+ return env_crc16((unsigned char*)&env,sizeof(env))==crc;
+}
+
+void env_init(void)
+{
+ unsigned int fmcn = AT91F_MC_EFC_ComputeFMCN(MCK);
+
+ AT91F_MC_EFC_CfgModeReg(AT91C_BASE_MC, fmcn << 16 | AT91C_MC_FWS_3FWS);
+}
diff --git a/openpicc/application/env.h b/openpicc/application/env.h
new file mode 100644
index 0000000..50d27b6
--- /dev/null
+++ b/openpicc/application/env.h
@@ -0,0 +1,46 @@
+/***************************************************************
+ *
+ * OpenBeacon.org - flash routines for persistent environment storage
+ *
+ * Copyright 2007 Milosch Meriac <meriac@openbeacon.de>
+ *
+ ***************************************************************
+
+ 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; version 2.
+
+ This program 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, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#ifndef __ENV_H__
+#define __ENV_H__
+
+#define TENVIRONMENT_MAGIC 0x0CCC2007
+
+typedef struct
+{
+ unsigned int magic,size,crc16;
+ unsigned int mode,speed;
+ unsigned int reader_id;
+} TEnvironment;
+
+typedef union {
+ TEnvironment e;
+ unsigned int data[AT91C_IFLASH_PAGE_SIZE/sizeof(unsigned int)];
+} TEnvironmentBlock;
+
+extern void env_store(void) RAMFUNC;
+extern int env_load(void);
+extern void env_init(void);
+extern TEnvironmentBlock env;
+extern unsigned short env_crc16 (const unsigned char *buffer, int size) RAMFUNC;
+
+#endif/*__ENV_H__*/
diff --git a/openpicc/application/led.c b/openpicc/application/led.c
new file mode 100644
index 0000000..c414e92
--- /dev/null
+++ b/openpicc/application/led.c
@@ -0,0 +1,90 @@
+/***************************************************************
+ *
+ * OpenBeacon.org - LED support
+ *
+ * Copyright 2007 Milosch Meriac <meriac@openbeacon.de>
+ *
+ ***************************************************************
+
+ 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; version 2.
+
+ This program 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, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+*/
+#include <FreeRTOS.h>
+#include <AT91SAM7.h>
+#include <lib_AT91SAM7.h>
+#include <string.h>
+#include <board.h>
+#include <task.h>
+#include "led.h"
+/**********************************************************************/
+
+void vLedSetRed(bool_t on)
+{
+ if(on)
+ AT91F_PIO_ClearOutput( AT91C_BASE_PIOA, LED_RED );
+ else
+ AT91F_PIO_SetOutput( AT91C_BASE_PIOA, LED_RED );
+}
+/**********************************************************************/
+
+extern void vLedSetGreen(bool_t on)
+{
+ if(on)
+ AT91F_PIO_ClearOutput( AT91C_BASE_PIOA, LED_GREEN );
+ else
+ AT91F_PIO_SetOutput( AT91C_BASE_PIOA, LED_GREEN );
+}
+/**********************************************************************/
+
+void vLedHaltBlinking(int reason)
+{
+ volatile u_int32_t i=0;
+ while(1)
+ {
+ AT91F_PIO_ClearOutput( AT91C_BASE_PIOA, LED_MASK );
+ for(i=0; i<MCK/40; i++) ;
+
+ switch(reason) {
+ case 1:
+ vLedSetGreen(1);
+ vLedSetRed(0);
+ break;
+ case 2:
+ vLedSetGreen(0);
+ vLedSetRed(1);
+ break;
+ case 3:
+ vLedSetGreen(1);
+ vLedSetRed(1);
+ break;
+ case 0:
+ default:
+ vLedSetGreen(0);
+ vLedSetRed(0);
+ break;
+ }
+ for(i=0; i<MCK/20; i++) ;
+
+ AT91F_PIO_SetOutput( AT91C_BASE_PIOA, LED_MASK );
+ for(i=0; i<MCK/40; i++) ;
+ }
+}
+/**********************************************************************/
+
+void vLedInit(void)
+{
+ // turn off LED's
+ AT91F_PIO_CfgOutput( AT91C_BASE_PIOA, LED_MASK );
+ AT91F_PIO_SetOutput( AT91C_BASE_PIOA, LED_MASK );
+}
diff --git a/openpicc/application/led.h b/openpicc/application/led.h
new file mode 100644
index 0000000..83a6138
--- /dev/null
+++ b/openpicc/application/led.h
@@ -0,0 +1,33 @@
+/***************************************************************
+ *
+ * OpenBeacon.org - LED support
+ *
+ * Copyright 2007 Milosch Meriac <meriac@openbeacon.de>
+ *
+ ***************************************************************
+
+ 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; version 2.
+
+ This program 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, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#ifndef __LED_H__
+#define __LED_H__
+
+#include "openpicc.h"
+
+extern void vLedSetRed(bool_t on);
+extern void vLedSetGreen(bool_t on);
+extern void vLedHaltBlinking(int reason);
+extern void vLedInit(void);
+
+#endif/*__PROTO_H__*/
diff --git a/openpicc/application/main.c b/openpicc/application/main.c
new file mode 100644
index 0000000..6dc9637
--- /dev/null
+++ b/openpicc/application/main.c
@@ -0,0 +1,93 @@
+/***************************************************************
+ *
+ * OpenBeacon.org - main entry for 2.4GHz RFID USB reader
+ *
+ * Copyright 2007 Milosch Meriac <meriac@openbeacon.de>
+ *
+ * basically starts the USB task, initializes all IO ports
+ * and introduces idle application hook to handle the HF traffic
+ * from the nRF24L01 chip
+ *
+ ***************************************************************
+
+ 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; version 2.
+
+ This program 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, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+*/
+/* Library includes. */
+#include <string.h>
+#include <stdio.h>
+
+#include <FreeRTOS.h>
+#include <AT91SAM7.h>
+#include <USB-CDC.h>
+#include <task.h>
+
+#include "openpicc.h"
+#include "board.h"
+#include "led.h"
+#include "env.h"
+#include "cmd.h"
+
+/**********************************************************************/
+static inline void prvSetupHardware (void)
+{
+ /* When using the JTAG debugger the hardware is not always initialised to
+ the correct default state. This line just ensures that this does not
+ cause all interrupts to be masked at the start. */
+ AT91C_BASE_AIC->AIC_EOICR = 0;
+
+ /* Enable the peripheral clock. */
+ AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOA;
+ AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOB;
+
+ /* initialize environment variables */
+ env_init();
+ if(!env_load())
+ {
+ env.e.mode=0;
+ env.e.reader_id=255;
+ env_store();
+ }
+}
+
+/**********************************************************************/
+void vApplicationIdleHook(void)
+{
+ static char disabled_green = 0;
+ /* Restart watchdog, has been enabled in Cstartup_SAM7.c */
+ AT91F_WDTRestart(AT91C_BASE_WDTC);
+ if(!disabled_green) {
+ //vLedSetGreen(0);
+ disabled_green = 1;
+ }
+}
+
+/**********************************************************************/
+int main (void)
+{
+ prvSetupHardware ();
+
+ vLedInit();
+
+ xTaskCreate (vUSBCDCTask, (signed portCHAR *) "USB", TASK_USB_STACK,
+ NULL, TASK_USB_PRIORITY, NULL);
+
+ vCmdInit();
+
+ vLedSetGreen(1);
+
+ vTaskStartScheduler ();
+
+ return 0;
+}
diff --git a/openpicc/application/openpicc.h b/openpicc/application/openpicc.h
new file mode 100644
index 0000000..d3575a6
--- /dev/null
+++ b/openpicc/application/openpicc.h
@@ -0,0 +1,36 @@
+/***************************************************************
+ *
+ * OpenPICC.org
+ *
+ * Copyright 2006 Milosch Meriac <meriac@openbeacon.de>
+ *
+ ***************************************************************
+
+ 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; version 2.
+
+ This program 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, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+*/
+
+#ifndef __OPENPICC_H__
+#define __OPENPICC_H__
+
+typedef unsigned char bool_t;
+typedef unsigned char u_int8_t;
+typedef unsigned short u_int16_t;
+typedef unsigned long u_int32_t;
+typedef signed char s_int8_t;
+typedef signed short s_int16_t;
+typedef int s_int32_t;
+
+
+#endif/*__OPENPICC_H__*/
personal git repositories of Harald Welte. Your mileage may vary