Continue work on Rowley LPC1768 demo.

pull/1/head
Richard Barry 16 years ago
parent ee0ff3a207
commit 312b19b236

@ -53,7 +53,6 @@
#define FREERTOS_CONFIG_H
#include "LPC17xx.h"
#include "LPC17xx_defs.h"
/*-----------------------------------------------------------
* Application specific definitions.
@ -72,7 +71,7 @@
#define configCPU_CLOCK_HZ ( ( unsigned portLONG ) 64000000 )
#define configTICK_RATE_HZ ( ( portTickType ) 1000 )
#define configMINIMAL_STACK_SIZE ( ( unsigned portSHORT ) 80 )
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 1 * 1024 ) )
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 19 * 1024 ) )
#define configMAX_TASK_NAME_LEN ( 12 )
#define configUSE_TRACE_FACILITY 1
#define configUSE_16_BIT_TICKS 0
@ -146,7 +145,7 @@ to exclude the API function. */
*-----------------------------------------------------------*/
extern void vConfigureTimerForRunTimeStats( void );
#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() vConfigureTimerForRunTimeStats()
#define portGET_RUN_TIME_COUNTER_VALUE() T0TC
#define portGET_RUN_TIME_COUNTER_VALUE() TIM0->TC
/* The structure that is passed on the xLCDQueue. Put here for convenience. */

File diff suppressed because it is too large Load Diff

@ -68,12 +68,12 @@
void vParTestInitialise( void )
{
/* LEDs on ports 1 and 2 to output. */
FIO2DIR = partstFIO2_BITS;
FIO1DIR = partstFIO1_BITS;
GPIO2->FIODIR = partstFIO2_BITS;
GPIO1->FIODIR = partstFIO1_BITS;
/* Start will all LEDs off. */
FIO1CLR = partstFIO1_BITS;
FIO2CLR = partstFIO2_BITS;
GPIO2->FIOCLR = partstFIO2_BITS;
GPIO1->FIOCLR = partstFIO1_BITS;
}
/*-----------------------------------------------------------*/
@ -89,11 +89,11 @@ unsigned portLONG ulLED = partstFIRST_IO;
/* Set of clear the output. */
if( xValue )
{
FIO2CLR = ulLED;
GPIO2->FIOCLR = ulLED;
}
else
{
FIO2SET = ulLED;
GPIO2->FIOSET = ulLED;
}
}
}
@ -110,14 +110,14 @@ unsigned portLONG ulLED = partstFIRST_IO, ulCurrentState;
ulLED <<= ( unsigned portLONG ) uxLED;
/* If this bit is already set, clear it, and visa versa. */
ulCurrentState = FIO2PIN;
ulCurrentState = GPIO2->FIOPIN;
if( ulCurrentState & ulLED )
{
FIO2CLR = ulLED;
GPIO2->FIOCLR = ulLED;
}
else
{
FIO2SET = ulLED;
GPIO2->FIOSET = ulLED;
}
}
}
@ -129,7 +129,7 @@ unsigned portLONG ulLED = partstFIRST_IO;
ulLED <<= ( unsigned portLONG ) uxLED;
return ( FIO2PIN & ulLED );
return ( GPIO2->FIOPIN & ulLED );
}
/*-----------------------------------------------------------*/
@ -139,11 +139,3 @@ long lParTestGetLEDState( unsigned portBASE_TYPE uxLED )
}
/*-----------------------------------------------------------*/
int __putchar( int x )
{
/* Not used. */
}

@ -1,7 +1,7 @@
<!DOCTYPE CrossStudio_Project_File>
<solution Name="RTOSDemo" version="2">
<project Name="RTOSDemo">
<configuration Name="Common" Target="LPC1768" arm_architecture="v7M" arm_core_type="Cortex-M3" arm_linker_heap_size="128" arm_linker_process_stack_size="0" arm_linker_stack_size="128" arm_simulator_memory_simulation_filename="$(TargetsDir)/LPC1000/LPC1000SimulatorMemory.dll" arm_simulator_memory_simulation_parameter="0x80000;0x8000;0x8000" arm_target_debug_interface_type="ADIv5" arm_target_loader_parameter="12000000" c_preprocessor_definitions="PACK_STRUCT_END=__attribute((packed));ALIGN_STRUCT_END=__attribute((aligned(4)))" c_user_include_directories="$(TargetsDir)/LPC1000/include;../../Source/include;../Common/include;../../Source/portable/GCC/ARM_CM3;../Common/ethernet/uIP/uip-1.0/uip;.;./webserver;./USBHost;./FatFS" link_include_startup_code="No" linker_additional_files="$(TargetsDir)/LPC1000/lib/liblpc1000$(LibExt)$(LIB);$(TargetsDir)/LPC1000/lib/cmsis$(LibExt)$(LIB)" linker_memory_map_file="$(TargetsDir)/LPC1000/LPC1768_MemoryMap.xml" linker_printf_fmt_level="int" linker_printf_width_precision_supported="No" linker_section_placement_file="$(ProjectDir)/flash_placement.xml" oscillator_frequency="12MHz" project_directory="" project_type="Executable" property_groups_file_path="$(TargetsDir)/LPC1000/propertyGroups.xml"/>
<configuration Name="Common" Target="LPC1768" arm_architecture="v7M" arm_core_type="Cortex-M3" arm_linker_heap_size="128" arm_linker_process_stack_size="0" arm_linker_stack_size="128" arm_simulator_memory_simulation_filename="$(TargetsDir)/LPC1000/LPC1000SimulatorMemory.dll" arm_simulator_memory_simulation_parameter="0x80000;0x8000;0x8000" arm_target_debug_interface_type="ADIv5" arm_target_loader_parameter="12000000" c_enforce_ansi_checking="No" c_only_additional_options="-Wall;-Wextra" c_preprocessor_definitions="PACK_STRUCT_END=__attribute((packed));ALIGN_STRUCT_END=__attribute((aligned(4)))" c_user_include_directories="$(TargetsDir)/LPC1000/include;../../Source/include;../Common/include;../../Source/portable/GCC/ARM_CM3;../Common/ethernet/uIP/uip-1.0/uip;.;./webserver;./USBHost/Include" link_include_startup_code="No" linker_additional_files="$(TargetsDir)/LPC1000/lib/liblpc1000$(LibExt)$(LIB);$(TargetsDir)/LPC1000/lib/cmsis$(LibExt)$(LIB)" linker_memory_map_file="$(TargetsDir)/LPC1000/LPC1768_MemoryMap.xml" linker_printf_fmt_level="int" linker_printf_width_precision_supported="No" linker_section_placement_file="$(ProjectDir)/flash_placement.xml" oscillator_frequency="12MHz" project_directory="" project_type="Executable" property_groups_file_path="$(TargetsDir)/LPC1000/propertyGroups.xml"/>
<configuration Name="RAM" Placement="RAM" linker_section_placement_file="$(StudioDir)/targets/Cortex_M/ram_placement.xml" target_reset_script="SRAMReset()"/>
<configuration Name="Flash" Placement="Flash" arm_target_flash_loader_file_path="$(TargetsDir)/LPC1000/Release/Loader_rpc.elf" arm_target_flash_loader_type="LIBMEM RPC Loader" linker_patch_build_command="$(StudioDir)/bin/crossscript &quot;load(\&quot;$(TargetsDir)/LPC1000/LPC1000_LinkPatch.js\&quot;);patch(\&quot;$(TargetPath)\&quot;);&quot;" linker_section_placement_file="$(ProjectDir)/flash_placement.xml" target_reset_script="FLASHReset()"/>
<folder Name="Source Files">
@ -41,18 +41,6 @@
</folder>
<file file_name="ParTest.c"/>
<file file_name="printf-stdarg.c"/>
<folder Name="USBHost">
<file file_name="UsbHost/usbhost_ms.c"/>
<file file_name="UsbHost/usbhost_lpc1768.c"/>
</folder>
<folder Name="FatFS">
<file file_name="FatFS/comm.c"/>
<file file_name="FatFS/diskio.c"/>
<file file_name="FatFS/ff.c"/>
<file file_name="FatFS/mci.c"/>
<file file_name="FatFS/monitor.c"/>
<file file_name="FatFS/rtc.c"/>
</folder>
</folder>
<folder Name="System Files">
<file file_name="$(StudioDir)/source/thumb_crt0.s"/>

@ -1,7 +1,10 @@
<!DOCTYPE CrossStudio_for_ARM_Session_File>
<session>
<Bookmarks/>
<Breakpoints/>
<Breakpoints>
<BreakpointListItem line="184" action="" hardwareBreakpoint="" trigger="" useHWbreakpoint="false" group="Breakpoints" type="Breakpoint" state="2" counter="0" isFunctionBreakpoint="false" filename="C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\CORTEX_LPC1768_GCC_Rowley\UsbHost\Host\usbhost_lpc17xx.c" expression="" />
<BreakpointListItem line="46" action="" hardwareBreakpoint="" trigger="" useHWbreakpoint="false" group="Breakpoints" type="Breakpoint" state="2" counter="0" isFunctionBreakpoint="false" filename="C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\CORTEX_LPC1768_GCC_Rowley\UsbHost\Main\usbhost_task.c" expression="" />
</Breakpoints>
<ExecutionCountWindow/>
<Memory1>
<MemoryWindow autoEvaluate="0" addressText="0x10003c24" numColumns="8" sizeText="100" dataSize="1" radix="16" addressSpace="" />
@ -19,8 +22,7 @@
<ProjectSessionItem path="RTOSDemo" name="unnamed" />
<ProjectSessionItem path="RTOSDemo;RTOSDemo" name="unnamed" />
<ProjectSessionItem path="RTOSDemo;RTOSDemo;Source Files" name="unnamed" />
<ProjectSessionItem path="RTOSDemo;RTOSDemo;Source Files;USBHost" name="unnamed" />
<ProjectSessionItem path="RTOSDemo;RTOSDemo;System Files" name="unnamed" />
<ProjectSessionItem path="RTOSDemo;RTOSDemo;Source Files;NXPUSBHostLite" name="unnamed" />
</Project>
<Register1>
<RegisterWindow openNodes="CPU;CPU/xPSR;CPU/CFBP;CPU/CFBP/CONTROL[0];CPU/CFBP/CONTROL[1]" binaryNodes="" unsignedNodes="" visibleGroups="CPU" decimalNodes="" octalNodes="" asciiNodes="" />
@ -51,8 +53,12 @@
<Watches active="0" update="Never" />
</Watch4>
<Files>
<SessionOpenFile useTextEdit="1" useBinaryEdit="0" codecName="Latin1" x="54" debugPath="C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\CORTEX_LPC1768_GCC_Rowley\flash_placement.xml" y="22" path="C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\CORTEX_LPC1768_GCC_Rowley\flash_placement.xml" left="0" selected="1" name="unnamed" top="0" />
<SessionOpenFile useTextEdit="1" useBinaryEdit="0" codecName="Latin1" x="0" debugPath="C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\CORTEX_LPC1768_GCC_Rowley\UsbHost\usbhost_ms.c" y="451" path="C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\CORTEX_LPC1768_GCC_Rowley\UsbHost\usbhost_ms.c" left="0" selected="0" name="unnamed" top="436" />
<SessionOpenFile useTextEdit="1" useBinaryEdit="0" codecName="Latin1" x="0" debugPath="C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\CORTEX_LPC1768_GCC_Rowley\main.c" y="96" path="C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\CORTEX_LPC1768_GCC_Rowley\main.c" left="0" selected="0" name="unnamed" top="82" />
<SessionOpenFile useTextEdit="1" useBinaryEdit="0" codecName="Latin1" x="0" debugPath="C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\CORTEX_LPC1768_GCC_Rowley\UsbHost\Main\usbhost_task.c" y="45" path="C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\CORTEX_LPC1768_GCC_Rowley\UsbHost\Main\usbhost_task.c" left="0" selected="0" name="unnamed" top="21" />
<SessionOpenFile useTextEdit="1" useBinaryEdit="0" codecName="Latin1" x="0" debugPath="C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\CORTEX_LPC1768_GCC_Rowley\UsbHost\Host\usbhost_lpc17xx.c" y="332" path="C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\CORTEX_LPC1768_GCC_Rowley\UsbHost\Host\usbhost_lpc17xx.c" left="0" selected="0" name="unnamed" top="172" />
<SessionOpenFile useTextEdit="1" useBinaryEdit="0" codecName="Latin1" x="0" debugPath="C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\CORTEX_LPC1768_GCC_Rowley\FreeRTOSConfig.h" y="55" path="C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\CORTEX_LPC1768_GCC_Rowley\FreeRTOSConfig.h" left="0" selected="0" name="unnamed" top="40" />
<SessionOpenFile useTextEdit="1" useBinaryEdit="0" codecName="Latin1" x="0" debugPath="C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\CORTEX_LPC1768_GCC_Rowley\webserver\emac.c" y="59" path="C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\CORTEX_LPC1768_GCC_Rowley\webserver\emac.c" left="0" selected="0" name="unnamed" top="44" />
<SessionOpenFile useTextEdit="1" useBinaryEdit="0" codecName="Latin1" x="0" debugPath="C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\CORTEX_LPC1768_GCC_Rowley\UsbHost\Fat\usbhost_fat.c" y="0" path="C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\CORTEX_LPC1768_GCC_Rowley\UsbHost\Fat\usbhost_fat.c" left="0" selected="0" name="unnamed" top="0" />
</Files>
<ARMCrossStudioWindow activeProject="RTOSDemo" autoConnectTarget="Amontec JTAGkey" debugSearchFileMap="" fileDialogInitialDirectory="C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\CORTEX_LPC1768_GCC_Rowley" fileDialogDefaultFilter="*.*" autoConnectCapabilities="388991" debugSearchPath="" buildConfiguration="THUMB Flash Debug" />
<ARMCrossStudioWindow activeProject="RTOSDemo" autoConnectTarget="USB CrossConnect for ARM" debugSearchFileMap="" fileDialogInitialDirectory="C:\E\Dev\FreeRTOS\WorkingCopy3\Demo\CORTEX_LPC1768_GCC_Rowley\UsbHost\Uart" fileDialogDefaultFilter="*.*" autoConnectCapabilities="388991" debugSearchPath="" buildConfiguration="THUMB Flash Debug" />
</session>

@ -0,0 +1,37 @@
<!DOCTYPE Linker_Placement_File>
<Root name="Flash Section Placement">
<MemorySegment name="FLASH">
<ProgramSection load="Yes" inputsections="*(.vectors .vectors.*)" name=".vectors"/>
<ProgramSection alignment="4" load="Yes" inputsections="*(.init .init.*)" name=".init"/>
<ProgramSection alignment="4" load="Yes" inputsections="*(.text .text.* .glue_7t .glue_7 .gnu.linkonce.t.* .gcc_except_table)" name=".text"/>
<ProgramSection alignment="4" load="Yes" inputsections="KEEP (*(SORT(.dtors.*))) KEEP (*(.dtors))" name=".dtors"/>
<ProgramSection alignment="4" load="Yes" inputsections="KEEP (*(SORT(.ctors.*))) KEEP (*(.ctors))" name=".ctors"/>
<ProgramSection alignment="4" load="Yes" inputsections="*(.rodata .rodata.* .gnu.linkonce.r.*)" name=".rodata"/>
<ProgramSection alignment="4" load="Yes" runin=".fast_run" inputsections="*(.fast .fast.*)" name=".fast"/>
<ProgramSection alignment="4" load="Yes" runin=".data_run" inputsections="*(.data .data.* .gnu.linkonce.d.*)" name=".data"/>
</MemorySegment>
<MemorySegment name="RAM">
<ProgramSection alignment="4" load="No" name=".fast_run"/>
<ProgramSection alignment="4" load="No" name=".data_run"/>
<ProgramSection alignment="4" load="No" inputsections="*(.bss .bss.* .gnu.linkonce.b.*) *(COMMON)" name=".bss"/>
<ProgramSection alignment="4" load="No" inputsections="*(.non_init .non_init.*)" name=".non_init"/>
<ProgramSection alignment="4" size="__HEAPSIZE__" load="No" name=".heap"/>
<ProgramSection alignment="4" size="__STACKSIZE__" load="No" name=".stack"/>
<ProgramSection alignment="4" size="__STACKSIZE_PROCESS__" load="No" name=".stack_process"/>
</MemorySegment>
<MemorySegment name="AHBSRAM0">
<ProgramSection alignment="4" load="No" name=".ethram"/>
</MemorySegment>
<MemorySegment name="AHBSRAM1">
<ProgramSection alignment="4" load="No" name=".usbram"/>
</MemorySegment>
<MemorySegment name="FLASH2">
<ProgramSection alignment="4" load="Yes" inputsections="*(.text2 .text2.*)" name=".text2"/>
<ProgramSection alignment="4" load="Yes" inputsections="*(.rodata2 .rodata2.*)" name=".rodata2"/>
<ProgramSection alignment="4" load="Yes" runin=".data2_run" inputsections="*(.data2 .data2.*)" name=".data2"/>
</MemorySegment>
<MemorySegment name="RAM2">
<ProgramSection alignment="4" load="No" name=".data2_run"/>
<ProgramSection alignment="4" load="No" inputsections="*(.bss2 .bss2.*" name=".bss2"/>
</MemorySegment>
</Root>

@ -1,5 +1,5 @@
/*
FreeRTOS.org V5.4.0 - Copyright (C) 2003-2009 Richard Barry.
FreeRTOS.org V5.3.1 - Copyright (C) 2003-2009 Richard Barry.
This file is part of the FreeRTOS.org distribution.
@ -94,9 +94,6 @@
#include "queue.h"
#include "semphr.h"
/* Hardware library includes. */
#include "LPC17xx_defs.h"
/* Demo app includes. */
#include "BlockQ.h"
#include "integer.h"
@ -109,13 +106,6 @@
#include "QPeek.h"
#include "recmutex.h"
#if 0
/*-----------------------------------------------------------*/
/* The number of LED tasks that will be created. */
@ -176,8 +166,6 @@ xQueueHandle xLCDQueue;
int main( void )
{
long l;
/* Configure the hardware for use by this demo. */
prvSetupHardware();
@ -306,59 +294,59 @@ portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
void prvSetupHardware( void )
{
/* Disable peripherals power. */
PCONP = 0;
SC->PCONP = 0;
/* Enable GPIO power. */
PCONP = PCONP_PCGPIO;
SC->PCONP = PCONP_PCGPIO;
/* Disable TPIU. */
PINSEL10 = 0;
PINCON->PINSEL10 = 0;
/* Disconnect the main PLL. */
PLL0CON &= ~PLLCON_PLLC;
PLL0FEED = PLLFEED_FEED1;
PLL0FEED = PLLFEED_FEED2;
while ((PLL0STAT & PLLSTAT_PLLC) != 0);
SC->PLL0CON &= ~PLLCON_PLLC;
SC->PLL0FEED = PLLFEED_FEED1;
SC->PLL0FEED = PLLFEED_FEED2;
while ((SC->PLL0STAT & PLLSTAT_PLLC) != 0);
/* Turn off the main PLL. */
PLL0CON &= ~PLLCON_PLLE;
PLL0FEED = PLLFEED_FEED1;
PLL0FEED = PLLFEED_FEED2;
while ((PLL0STAT & PLLSTAT_PLLE) != 0);
SC->PLL0CON &= ~PLLCON_PLLE;
SC->PLL0FEED = PLLFEED_FEED1;
SC->PLL0FEED = PLLFEED_FEED2;
while ((SC->PLL0STAT & PLLSTAT_PLLE) != 0);
/* No CPU clock divider. */
CCLKCFG = 0;
SC->CCLKCFG = 0;
/* OSCEN. */
SCS = 0x20;
while ((SCS & 0x40) == 0);
SC->SCS = 0x20;
while ((SC->SCS & 0x40) == 0);
/* Use main oscillator. */
CLKSRCSEL = 1;
PLL0CFG = (PLLCFG_MUL16 | PLLCFG_DIV1);
SC->CLKSRCSEL = 1;
SC->PLL0CFG = (PLLCFG_MUL16 | PLLCFG_DIV1);
PLL0FEED = PLLFEED_FEED1;
PLL0FEED = PLLFEED_FEED2;
SC->PLL0FEED = PLLFEED_FEED1;
SC->PLL0FEED = PLLFEED_FEED2;
/* Activate the PLL by turning it on then feeding the correct
sequence of bytes. */
PLL0CON = PLLCON_PLLE;
PLL0FEED = PLLFEED_FEED1;
PLL0FEED = PLLFEED_FEED2;
SC->PLL0CON = PLLCON_PLLE;
SC->PLL0FEED = PLLFEED_FEED1;
SC->PLL0FEED = PLLFEED_FEED2;
/* 6x CPU clock divider (64 MHz) */
CCLKCFG = 5;
SC->CCLKCFG = 5;
/* Wait for the PLL to lock. */
while ((PLL0STAT & PLLSTAT_PLOCK) == 0);
while ((SC->PLL0STAT & PLLSTAT_PLOCK) == 0);
/* Connect the PLL. */
PLL0CON = PLLCON_PLLC | PLLCON_PLLE;
PLL0FEED = PLLFEED_FEED1;
PLL0FEED = PLLFEED_FEED2;
SC->PLL0CON = PLLCON_PLLC | PLLCON_PLLE;
SC->PLL0FEED = PLLFEED_FEED1;
SC->PLL0FEED = PLLFEED_FEED2;
/* Setup the peripheral bus to be the same as the PLL output (64 MHz). */
PCLKSEL0 = 0x05555555;
SC->PCLKSEL0 = 0x05555555;
/* Configure the LEDs. */
vParTestInitialise();
@ -387,627 +375,21 @@ const unsigned long TCR_COUNT_RESET = 2, CTCR_CTM_TIMER = 0x00, TCR_COUNT_ENABLE
to 1. */
/* Power up and feed the timer. */
PCONP |= 0x02UL;
PCLKSEL0 = (PCLKSEL0 & (~(0x3<<2))) | (0x01 << 2);
SC->PCONP |= 0x02UL;
SC->PCLKSEL0 = (SC->PCLKSEL0 & (~(0x3<<2))) | (0x01 << 2);
/* Reset Timer 0 */
T0TCR = TCR_COUNT_RESET;
TIM0->TCR = TCR_COUNT_RESET;
/* Just count up. */
T0CTCR = CTCR_CTM_TIMER;
TIM0->CTCR = CTCR_CTM_TIMER;
/* Prescale to a frequency that is good enough to get a decent resolution,
but not too fast so as to overflow all the time. */
T0PR = ( configCPU_CLOCK_HZ / 10000UL ) - 1UL;
TIM0->PR = ( configCPU_CLOCK_HZ / 10000UL ) - 1UL;
/* Start the counter. */
T0TCR = TCR_COUNT_ENABLE;
TIM0->TCR = TCR_COUNT_ENABLE;
}
/*-----------------------------------------------------------*/
#else
/*----------------------------------------------------------------------*/
/* FAT file system sample project for FatFs R0.06 (C)ChaN, 2008 */
/*----------------------------------------------------------------------*/
#include <string.h>
#include "LPC17xx.h"
#include "integer.h"
//#include "interrupt.h"
#include "comm.h"
#include "monitor.h"
#include "rtc.h"
#include "diskio.h"
#include "ff.h"
#include "ctl_api.h"
#include "usbhost_lpc1768.h"
DWORD acc_size; /* Work register for fs command */
WORD acc_files, acc_dirs;
FILINFO finfo;
char linebuf[120]; /* Console input buffer */
FATFS fatfs[_DRIVES]; /* File system object for each logical drive */
FIL file1, file2; /* File objects */
DIR dir; /* Directory object */
BYTE Buff[16384] __attribute__ ((aligned (4))) ; /* Working buffer */
volatile UINT Timer; /* Performance timer (1kHz increment) */
/*---------------------------------------------------------*/
/* 1000Hz timer interrupt generated by TIMER0 */
/*---------------------------------------------------------*/
void Isr_TIMER0 (void)
{
T0IR = 1; /* Clear irq flag */
Timer++;
MMC_TimerProc();
}
/*---------------------------------------------------------*/
/* User Provided Timer Function for FatFs module */
/*---------------------------------------------------------*/
/* This is a real time clock service to be called from */
/* FatFs module. Any valid time must be returned even if */
/* the system does not support a real time clock. */
/* This is not required in read-only configuration. */
DWORD get_fattime ()
{
RTC rtc;
rtc_gettime(&rtc);
return ((DWORD)(rtc.year) << 25)
| ((DWORD)rtc.month << 21)
| ((DWORD)rtc.mday << 16)
| ((DWORD)rtc.hour << 11)
| ((DWORD)rtc.min << 5)
| ((DWORD)rtc.sec >> 1);
}
/*--------------------------------------------------------------------------*/
/* Monitor */
/*--------------------------------------------------------------------------*/
static
FRESULT scan_files (char* path)
{
DIR dirs;
FRESULT res;
BYTE i;
if ((res = f_opendir(&dirs, path)) == FR_OK) {
i = strlen(path);
while (((res = f_readdir(&dirs, &finfo)) == FR_OK) && finfo.fname[0]) {
if (finfo.fattrib & AM_DIR) {
acc_dirs++;
*(path+i) = '/'; strcpy(path+i+1, &finfo.fname[0]);
res = scan_files(path);
*(path+i) = '\0';
if (res != FR_OK) break;
} else {
acc_files++;
acc_size += finfo.fsize;
}
}
}
return res;
}
static
void put_rc (FRESULT rc)
{
const char *p;
static const char str[] =
"OK\0" "NOT_READY\0" "NO_FILE\0" "FR_NO_PATH\0" "INVALID_NAME\0" "INVALID_DRIVE\0"
"DENIED\0" "EXIST\0" "RW_ERROR\0" "WRITE_PROTECTED\0" "NOT_ENABLED\0"
"NO_FILESYSTEM\0" "INVALID_OBJECT\0" "MKFS_ABORTED\0";
FRESULT i;
for (p = str, i = 0; i != rc && *p; i++) {
while(*p++);
}
xprintf("rc=%u FR_%s\n", (UINT)rc, p);
}
static
void IoInit (void)
{
#define PLL_N 1UL
#define PLL_M 12UL
#define CCLK_DIV 4 // 288MHz / 4 = 72MHz
#define USBCLK_DIV 6 // 288MHz / 6 = 48MHz
//_RB_ if ( PLLSTAT & (1 << 25) ) {
//_RB_ PLLCON = 1; /* Disconnect PLL output if PLL is in use */
//_RB_ PLLFEED = 0xAA; PLLFEED = 0x55;
//_RB_ }
//_RB_ PLLCON = 0; /* Disable PLL */
//_RB_ PLLFEED = 0xAA; PLLFEED = 0x55;
CLKSRCSEL = 0; /* Select IRC (4MHz) as the PLL clock source */
SCS |= 0x20; /* Enable main OSC */
while( !(SCS & 0x40) ); /* Wait until main OSC is usable */
CLKSRCSEL = 0x1; /* select main OSC, 12MHz, as the PLL clock source */
//_RB_ PLLCFG = ((PLL_N - 1) << 16) | (PLL_M - 1); /* Re-configure PLL */
//_RB_ PLLFEED = 0xAA; PLLFEED = 0x55;
//_RB_ PLLCON = 1; /* Enable PLL */
//_RB_ PLLFEED = 0xAA; PLLFEED = 0x55;
//_RB_ while ((PLLSTAT & (1 << 26)) == 0); /* Wait for PLL locked */
CCLKCFG = CCLK_DIV-1; /* Select CCLK frequency (divide ratio of hclk) */
USBCLKCFG = USBCLK_DIV-1; /* usbclk = 288 MHz/6 = 48 MHz */
//_RB_ PLLCON = 3; /* Connect PLL output to the sysclk */
//_RB_ PLLFEED = 0xAA; PLLFEED = 0x55;
//_RB_ MAMCR = 0; /* Configure MAM for 72MHz operation */
//_RB_ MAMTIM = 3;
//_RB_ MAMCR = 2;
PCLKSEL0 = 0x00000000; /* Initialize peripheral clock to default */
PCLKSEL1 = 0x00000000;
// ClearVector(); /* Initialie VIC */
SCS |= 1; /* Enable FIO0 and FIO1 */
FIO1DIR = (1<<26); /* Disable Piezo */
FIO2CLR = (1<<26);
FIO2DIR = (1<<30); /* Heartbeat LED output */
FIO2CLR = (1<<30);
/* Initialize Timer0 as 1kHz interval timer */
// RegisterVector(TIMER0_INT, Isr_TIMER0, PRI_LOWEST, CLASS_IRQ);
//_RB_ ctl_set_isr(TIMER0_INT, PRI_LOWEST, CTL_ISR_TRIGGER_FIXED, Isr_TIMER0, 0);
//_RB_ ctl_unmask_isr(TIMER0_INT);
T0CTCR = 0;
T0MR0 = 18000 - 1; /* 18M / 1k = 18000 */
T0MCR = 0x3; /* Clear TC and Interrupt on MR0 match */
T0TCR = 1;
uart0_init(); /* Initialize UART0 */
// IrqEnable(); /* Enable Irq */
ctl_global_interrupts_enable();
}
int main (void)
{
char *ptr, *ptr2;
long p1, p2, p3;
BYTE res, b1;
WORD w1;
UINT s1, s2, cnt, blen = sizeof(Buff);
DWORD ofs = 0, sect = 0;
FATFS *fs; /* Pointer to file system object */
RTC rtc;
BYTE ActiveDisk = 0;
USB_INT32S rc;
IoInit();
Host_Init();
xputs("\nFatFs module test monitor for LPC2468\n");
xputc('>');
ptr = linebuf;
for (;;) {
if (ConnectedDeviceState == DEVICE_CONNECTED) {
ConnectedDeviceState = DEVICE_CLEAR;
xprintf("USB Mass Storage device detected\n");
rc = Host_EnumDev(); // Enumerate the device connected
if (rc == OK) {
xprintf("USB device enumerated\n");
}
xputc('>');
}
else if (ConnectedDeviceState == DEVICE_DISCONNECTED) {
ConnectedDeviceState = DEVICE_CLEAR;
Host_Init(); // FreeDevice();
xprintf("Device Disconnected\n");
xputc('>');
}
if (get_line(ptr, sizeof(linebuf)) == '\r') {
switch (*ptr++) {
case 'm' :
switch (*ptr++) {
case 'd' : /* md <address> [<count>] - Dump memory */
if (!xatoi(&ptr, &p1)) break;
if (!xatoi(&ptr, &p2)) p2 = 128;
for (ptr=(char*)p1; p2 >= 16; ptr += 16, p2 -= 16) {
put_dump((BYTE*)ptr, (UINT)ptr, 16);
}
if (p2) put_dump((BYTE*)ptr, (UINT)ptr, p2);
break;
}
break;
case 'd' :
switch (*ptr++) {
case 'a' : /* da [#] - select active disk */
if (xatoi(&ptr, &p1)) {
ActiveDisk = (BYTE)p1;
}
ActiveDisk = VerifyActiveDisk(ActiveDisk);
break;
case 'd' : /* dd [<lba>] - Dump secrtor */
if (!xatoi(&ptr, &p2)) p2 = sect;
res = disk_read(ActiveDisk, Buff, p2, 1);
// res = disk_read(ActiveDisk, gUsbXferBuffer, p2, 1);
if (res) { xprintf("rc=%d\n", (WORD)res); break; }
sect = p2 + 1;
xprintf("Sector:%lu\n", p2);
for (ptr=(char*)Buff, ofs = 0; ofs < 0x200; ptr+=16, ofs+=16) {
// for (ptr=(char*)gUsbXferBuffer, ofs = 0; ofs < 0x200; ptr+=16, ofs+=16) {
put_dump((BYTE*)ptr, ofs, 16);
}
break;
case 'i' : /* di - Initialize disk */
xprintf("rc=%d\n", (WORD)disk_initialize(ActiveDisk));
break;
case 's' : /* ds <phy_drv#> - Show disk status */
// if (!xatoi(&ptr, &p1)) break;
if (disk_ioctl(ActiveDisk, GET_SECTOR_COUNT, &p2) == RES_OK)
{ xprintf("Drive size: %lu sectors\n", p2); }
if (disk_ioctl(ActiveDisk, GET_SECTOR_SIZE, &w1) == RES_OK)
{ xprintf("Sector size: %u\n", w1); }
if (disk_ioctl(ActiveDisk, GET_BLOCK_SIZE, &p2) == RES_OK)
{ xprintf("Erase block size: %lu sectors\n", p2); }
if (disk_ioctl(ActiveDisk, MMC_GET_TYPE, &b1) == RES_OK)
{ xprintf("MMC/SDC type: %u\n", b1); }
if (disk_ioctl(ActiveDisk, MMC_GET_CSD, Buff) == RES_OK)
{ xputs("CSD:\n"); put_dump(Buff, 0, 16); }
if (disk_ioctl(ActiveDisk, MMC_GET_CID, Buff) == RES_OK)
{ xputs("CID:\n"); put_dump(Buff, 0, 16); }
if (disk_ioctl(ActiveDisk, MMC_GET_OCR, Buff) == RES_OK)
{ xputs("OCR:\n"); put_dump(Buff, 0, 4); }
if (disk_ioctl(ActiveDisk, MMC_GET_SDSTAT, Buff) == RES_OK) {
xputs("SD Status:\n");
for (s1 = 0; s1 < 64; s1 += 16) put_dump(Buff+s1, s1, 16);
}
break;
}
break;
case 'b' :
switch (*ptr++) {
case 'd' : /* bd <addr> - Dump R/W buffer */
if (!xatoi(&ptr, &p1)) break;
for (ptr=(char*)&Buff[p1], ofs = p1, cnt = 32; cnt; cnt--, ptr+=16, ofs+=16) {
put_dump((BYTE*)ptr, ofs, 16);
}
break;
case 'e' : /* be <addr> [<data>] ... - Edit R/W buffer */
if (!xatoi(&ptr, &p1)) break;
if (xatoi(&ptr, &p2)) {
do {
Buff[p1++] = (BYTE)p2;
} while (xatoi(&ptr, &p2));
break;
}
for (;;) {
xprintf("%04X %02X-", (WORD)(p1), (WORD)Buff[p1]);
get_line(linebuf, sizeof(linebuf));
ptr = linebuf;
if (*ptr == '.') break;
if (*ptr < ' ') { p1++; continue; }
if (xatoi(&ptr, &p2))
Buff[p1++] = (BYTE)p2;
else
xputs("???\n");
}
break;
case 'r' : /* br <lba> [<num>] - Read disk into R/W buffer */
if (!xatoi(&ptr, &p2)) break;
if (!xatoi(&ptr, &p3)) p3 = 1;
xprintf("rc=%u\n", (WORD)disk_read(ActiveDisk, Buff, p2, p3));
break;
case 'w' : /* bw <lba> [<num>] - Write R/W buffer into disk */
if (!xatoi(&ptr, &p2)) break;
if (!xatoi(&ptr, &p3)) p3 = 1;
xprintf("rc=%u\n", (WORD)disk_write(ActiveDisk, Buff, p2, p3));
break;
case 'f' : /* bf <val> - Fill working buffer */
if (!xatoi(&ptr, &p1)) break;
memset(Buff, (BYTE)p1, sizeof(Buff));
break;
}
break;
case 'f' :
switch (*ptr++) {
case 'i' : /* fi <log drv#> - Initialize logical drive */
if (!xatoi(&ptr, &p1)) break;
put_rc(f_mount((BYTE)p1, &fatfs[p1]));
// put_rc(f_mount(ActiveDisk, &fatfs[ActiveDisk]));
break;
case 's' : /* fs [<path>] - Show logical drive status */
res = f_getfree(ptr, (DWORD*)&p2, &fs);
if (res) { put_rc(res); break; }
xprintf("FAT type = %u\nBytes/Cluster = %lu\nNumber of FATs = %u\n"
"Root DIR entries = %u\nSectors/FAT = %lu\nNumber of clusters = %lu\n"
"FAT start (lba) = %lu\nDIR start (lba,cluster) = %lu\nData start (lba) = %lu\n\n",
(WORD)fs->fs_type, (DWORD)fs->csize * 512, (WORD)fs->n_fats,
fs->n_rootdir, fs->sects_fat, (DWORD)fs->max_clust - 2,
fs->fatbase, fs->dirbase, fs->database
);
acc_size = acc_files = acc_dirs = 0;
res = scan_files(ptr);
if (res) { put_rc(res); break; }
xprintf("%u files, %lu bytes.\n%u folders.\n"
"%lu KB total disk space.\n%lu KB available.\n",
acc_files, acc_size, acc_dirs,
(fs->max_clust - 2) * (fs->csize / 2), p2 * (fs->csize / 2)
);
break;
case 'l' : /* fl [<path>] - Directory listing */
res = f_opendir(&dir, ptr);
if (res) { put_rc(res); break; }
p1 = s1 = s2 = 0;
for(;;) {
res = f_readdir(&dir, &finfo);
if ((res != FR_OK) || !finfo.fname[0]) break;
if (finfo.fattrib & AM_DIR) {
s2++;
} else {
s1++; p1 += finfo.fsize;
}
xprintf("%c%c%c%c%c %u/%02u/%02u %02u:%02u %9lu %s\n",
(finfo.fattrib & AM_DIR) ? 'D' : '-',
(finfo.fattrib & AM_RDO) ? 'R' : '-',
(finfo.fattrib & AM_HID) ? 'H' : '-',
(finfo.fattrib & AM_SYS) ? 'S' : '-',
(finfo.fattrib & AM_ARC) ? 'A' : '-',
(finfo.fdate >> 9) + 1980, (finfo.fdate >> 5) & 15, finfo.fdate & 31,
(finfo.ftime >> 11), (finfo.ftime >> 5) & 63,
finfo.fsize, &(finfo.fname[0]));
}
xprintf("%4u File(s),%10lu bytes total\n%4u Dir(s)", s1, p1, s2);
if (f_getfree(ptr, (DWORD*)&p1, &fs) == FR_OK)
xprintf(", %10lu bytes free\n", p1 * fs->csize * 512);
break;
case 'o' : /* fo <mode> <file> - Open a file */
if (!xatoi(&ptr, &p1)) break;
put_rc(f_open(&file1, ptr, (BYTE)p1));
break;
case 'c' : /* fc - Close a file */
put_rc(f_close(&file1));
break;
case 'e' : /* fe - Seek file pointer */
if (!xatoi(&ptr, &p1)) break;
res = f_lseek(&file1, p1);
put_rc(res);
if (res == FR_OK)
xprintf("fptr=%lu(0x%lX)\n", file1.fptr, file1.fptr);
break;
case 'd' : /* fd <len> - read and dump file from current fp */
if (!xatoi(&ptr, &p1)) break;
ofs = file1.fptr;
while (p1) {
if ((UINT)p1 >= 16) { cnt = 16; p1 -= 16; }
else { cnt = p1; p1 = 0; }
res = f_read(&file1, Buff, cnt, &cnt);
if (res != FR_OK) { put_rc(res); break; }
if (!cnt) break;
put_dump(Buff, ofs, cnt);
ofs += 16;
}
break;
case 'r' : /* fr <len> - read file */
if (!xatoi(&ptr, &p1)) break;
p2 = 0;
Timer = 0;
while (p1) {
if ((UINT)p1 >= blen) {
cnt = blen; p1 -= blen;
} else {
cnt = p1; p1 = 0;
}
res = f_read(&file1, Buff, cnt, &s2);
if (res != FR_OK) { put_rc(res); break; }
p2 += s2;
if (cnt != s2) break;
}
xprintf("%lu bytes read with %lu kB/sec.\n", p2, p2 / Timer);
break;
case 'w' : /* fw <len> <val> - write file */
if (!xatoi(&ptr, &p1) || !xatoi(&ptr, &p2)) break;
memset(Buff, (BYTE)p2, blen);
p2 = 0;
Timer = 0;
while (p1) {
if ((UINT)p1 >= blen) {
cnt = blen; p1 -= blen;
} else {
cnt = p1; p1 = 0;
}
res = f_write(&file1, Buff, cnt, &s2);
if (res != FR_OK) { put_rc(res); break; }
p2 += s2;
if (cnt != s2) break;
}
xprintf("%lu bytes written with %lu kB/sec.\n", p2, p2 / Timer);
break;
case 'n' : /* fn <old_name> <new_name> - Change file/dir name */
while (*ptr == ' ') ptr++;
ptr2 = strchr(ptr, ' ');
if (!ptr2) break;
*ptr2++ = 0;
while (*ptr2 == ' ') ptr2++;
put_rc(f_rename(ptr, ptr2));
break;
case 'u' : /* fu <name> - Unlink a file or dir */
put_rc(f_unlink(ptr));
break;
case 'v' : /* fv - Truncate file */
put_rc(f_truncate(&file1));
break;
case 'k' : /* fk <name> - Create a directory */
put_rc(f_mkdir(ptr));
break;
case 'a' : /* fa <atrr> <mask> <name> - Change file/dir attribute */
if (!xatoi(&ptr, &p1) || !xatoi(&ptr, &p2)) break;
put_rc(f_chmod(ptr, p1, p2));
break;
case 't' : /* ft <year> <month> <day> <hour> <min> <sec> <name> - Change timestamp */
if (!xatoi(&ptr, &p1) || !xatoi(&ptr, &p2) || !xatoi(&ptr, &p3)) break;
finfo.fdate = ((p1 - 1980) << 9) | ((p2 & 15) << 5) | (p3 & 31);
if (!xatoi(&ptr, &p1) || !xatoi(&ptr, &p2) || !xatoi(&ptr, &p3)) break;
finfo.ftime = ((p1 & 31) << 11) | ((p1 & 63) << 5) | ((p1 >> 1) & 31);
put_rc(f_utime(ptr, &finfo));
break;
case 'x' : /* fx <src_name> <dst_name> - Copy file */
while (*ptr == ' ') ptr++;
ptr2 = strchr(ptr, ' ');
if (!ptr2) break;
*ptr2++ = 0;
while (*ptr2 == ' ') ptr2++;
xprintf("Opening \"%s\"", ptr);
res = f_open(&file1, ptr, FA_OPEN_EXISTING | FA_READ);
xputc('\n');
if (res) {
put_rc(res);
break;
}
xprintf("Creating \"%s\"", ptr2);
res = f_open(&file2, ptr2, FA_CREATE_ALWAYS | FA_WRITE);
xputc('\n');
if (res) {
put_rc(res);
f_close(&file1);
break;
}
xprintf("Copying file...");
Timer = 0;
p1 = 0;
for (;;) {
res = f_read(&file1, Buff, blen, &s1);
if (res || s1 == 0) break; /* error or eof */
res = f_write(&file2, Buff, s1, &s2);
p1 += s2;
if (res || s2 < s1) break; /* error or disk full */
}
xprintf("%lu bytes copied with %lu kB/sec.\n", p1, p1 / Timer);
f_close(&file1);
f_close(&file2);
break;
#if _USE_MKFS
case 'm' : /* fm <partition rule> <cluster size> - Create file system */
if (!xatoi(&ptr, &p2) || !xatoi(&ptr, &p3)) break;
xprintf("The drive %u will be formatted. Are you sure? (Y/n)=", ActiveDisk);
get_line(ptr, sizeof(linebuf));
if (*ptr == 'Y')
put_rc(f_mkfs(ActiveDisk, (BYTE)p2, (WORD)p3));
break;
#endif
case 'z' : /* fz [<rw size>] - Change R/W length for fr/fw/fx command */
if (xatoi(&ptr, &p1) && p1 >= 1 && p1 <= sizeof(Buff))
blen = p1;
xprintf("blen=%u\n", blen);
break;
}
break;
case 't' : /* t [<year> <mon> <mday> <hour> <min> <sec>] */
if (xatoi(&ptr, &p1)) {
rtc.year = (WORD)p1;
xatoi(&ptr, &p1); rtc.month = (BYTE)p1;
xatoi(&ptr, &p1); rtc.mday = (BYTE)p1;
xatoi(&ptr, &p1); rtc.hour = (BYTE)p1;
xatoi(&ptr, &p1); rtc.min = (BYTE)p1;
if (!xatoi(&ptr, &p1)) break;
rtc.sec = (BYTE)p1;
rtc_settime(&rtc);
}
rtc_gettime(&rtc);
xprintf("%u/%u/%u %02u:%02u:%02u\n", rtc.year, rtc.month, rtc.mday, rtc.hour, rtc.min, rtc.sec);
break;
case 'u' : /* usb test commands */
switch (*ptr++) {
case 's' : /* print bulk size */
xprintf("MS Bulk size %lu\n", MS_BlkSize);
break;
}
break;
}
xputc('>');
ptr = linebuf;
}
}
}
void vApplicationTickHook( void )
{
}
/*-----------------------------------------------------------*/
void vConfigureTimerForRunTimeStats( void )
{
}
void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed portCHAR *pcTaskName )
{
}
xQueueHandle xLCDQueue;
#endif

Loading…
Cancel
Save