Microchip® Advanced Software Framework

fat_example.c File Reference
#include <string.h>
#include "compiler.h"
#include "preprocessor.h"
#include "board.h"
#include "print_funcs.h"
#include "ctrl_access.h"
#include "power_clocks_lib.h"
#include "gpio.h"
#include "usart.h"
#include "spi.h"
#include "conf_at45dbx.h"
#include "fat.h"
#include "file.h"
#include "navigation.h"

Macros

#define AT45DBX_ENABLE_NPCS_PIN(NPCS, unused)   {AT45DBX_SPI_NPCS##NPCS##_PIN, AT45DBX_SPI_NPCS##NPCS##_FUNCTION},
 
#define EXAMPLE_TARGET_PBACLK_FREQ_HZ   FOSC0
 
Shell USART Configuration
#define SHL_USART   (&AVR32_USART1)
 
#define SHL_USART_RX_PIN   AVR32_USART1_RXD_0_0_PIN
 
#define SHL_USART_RX_FUNCTION   AVR32_USART1_RXD_0_0_FUNCTION
 
#define SHL_USART_TX_PIN   AVR32_USART1_TXD_0_0_PIN
 
#define SHL_USART_TX_FUNCTION   AVR32_USART1_TXD_0_0_FUNCTION
 
#define SHL_USART_BAUDRATE   57600
 
Shell Commands
#define CMD_NONE   0x00
 
#define CMD_MOUNT   0x01
 
#define CMD_LS   0x02
 
#define CMD_CD   0x03
 
#define CMD_CAT   0x04
 
#define CMD_HELP   0x05
 
#define CMD_MKDIR   0x06
 
#define CMD_TOUCH   0x07
 
#define CMD_RM   0x08
 
#define CMD_APPEND   0x09
 
#define CMD_NB_DRIVE   0x0A
 
#define CMD_SET_ID   0x0B
 
#define CMD_GOTO_ID   0x0C
 
#define CMD_CP   0x0D
 
#define CMD_DF   0x0E
 
#define CMD_MV   0x0F
 
#define CMD_FORMAT   0x10
 
#define CMD_FAT   0x11
 
#define CMD_FORMAT32   0x12
 
Special Char Values
#define CR   '\r'
 
#define LF   '\n'
 
#define CRLF   "\r\n"
 
#define CTRL_C   0x03
 
#define CTRL_Q   0x11
 
#define BKSPACE_CHAR   '\b'
 
#define ABORT_CHAR   CTRL_C
 
#define QUIT_APPEND   CTRL_Q
 
#define HISTORY_CHAR   '!'
 
String Values for Commands
#define STR_CD   "cd"
 
#define STR_MOUNT   "mount"
 
#define STR_CP   "cp"
 
#define STR_LS   "ls"
 
#define STR_RM   "rm"
 
#define STR_DF   "df"
 
#define STR_MKDIR   "mkdir"
 
#define STR_TOUCH   "touch"
 
#define STR_APPEND   "append"
 
#define STR_CAT   "cat"
 
#define STR_DISK   "disk"
 
#define STR_MARK   "mark"
 
#define STR_GOTO   "goto"
 
#define STR_MV   "mv"
 
#define STR_A   "a:"
 
#define STR_B   "b:"
 
#define STR_C   "c:"
 
#define STR_D   "d:"
 
#define STR_HELP   "help"
 
#define STR_FORMAT   "format"
 
#define STR_FORMAT32   "format32"
 
#define STR_FAT   "fat"
 
String Messages
#define MSG_PROMPT   "$>"
 
#define MSG_WELCOME
 
#define MSG_ER_CMD_NOT_FOUND   "Command not found\r\n"
 
#define MSG_ER_MOUNT   "Unable to mount drive\r\n"
 
#define MSG_ER_DRIVE   "Drive does not exist\r\n"
 
#define MSG_ER_RM   "Can not erase; if the name is a directory, check it is empty\r\n"
 
#define MSG_ER_UNKNOWN_FILE   "Unknown file\r\n"
 
#define MSG_ER_MV   "Error during move\r\n"
 
#define MSG_ER_FORMAT   "Format fails\r\n"
 
#define MSG_APPEND_WELCOME   "\r\nSimple text editor, enter char to append, ^q to exit and save\r\n"
 
#define MSG_HELP
 

Functions

static void at45dbx_resources_init (void)
 Initializes the dataflash memory AT45DBX resources: GPIO, SPI and AT45DBX. More...
 
static void fat_example_append_file (void)
 Minimalist file editor to append char to a file. More...
 
static void fat_example_build_cmd (void)
 Gets the full command line on RS232 input to be interpreted. The cmd_str variable is built with the user inputs. More...
 
static void fat_example_parse_cmd (void)
 Decodes full command line into command type and arguments. More...
 
static void init_shl_rs232 (long pba_hz)
 Sets up USART for shell. More...
 
int main (void)
 Main function. Execution starts here. More...
 

Variables

static bool cmd
 flag for a command presence More...
 
static char cmd_str [10+2 *MAX_FILE_PATH_LENGTH]
 string for command More...
 
static uint8_t cmd_type
 command number More...
 
static bool first_ls
 flag for first ls : mount if set More...
 
static uint8_t i_str = 0
 string length More...
 
static char par_str1 [MAX_FILE_PATH_LENGTH]
 string for first arg More...
 
static char par_str2 [MAX_FILE_PATH_LENGTH]
 string for second arg More...
 
static char str_buff [MAX_FILE_PATH_LENGTH]
 buffer for command line More...
 

#define ABORT_CHAR   CTRL_C

Referenced by fat_example_build_cmd().

#define AT45DBX_ENABLE_NPCS_PIN (   NPCS,
  unused 
)    {AT45DBX_SPI_NPCS##NPCS##_PIN, AT45DBX_SPI_NPCS##NPCS##_FUNCTION},

Referenced by at45dbx_resources_init().

#define BKSPACE_CHAR   '\b'

Referenced by fat_example_build_cmd().

#define CMD_APPEND   0x09

Referenced by fat_example_parse_cmd(), and main().

#define CMD_CAT   0x04

Referenced by fat_example_parse_cmd(), and main().

#define CMD_CD   0x03

Referenced by fat_example_parse_cmd(), and main().

#define CMD_CP   0x0D

Referenced by fat_example_parse_cmd(), and main().

#define CMD_DF   0x0E

Referenced by fat_example_parse_cmd(), and main().

#define CMD_FAT   0x11

Referenced by fat_example_parse_cmd(), and main().

#define CMD_FORMAT   0x10

Referenced by fat_example_parse_cmd(), and main().

#define CMD_FORMAT32   0x12

Referenced by fat_example_parse_cmd(), and main().

#define CMD_GOTO_ID   0x0C

Referenced by fat_example_parse_cmd(), and main().

#define CMD_HELP   0x05

Referenced by fat_example_parse_cmd(), and main().

#define CMD_LS   0x02

Referenced by fat_example_parse_cmd(), and main().

#define CMD_MKDIR   0x06

Referenced by fat_example_parse_cmd(), and main().

#define CMD_MOUNT   0x01

Referenced by fat_example_parse_cmd(), and main().

#define CMD_MV   0x0F

Referenced by fat_example_parse_cmd(), and main().

#define CMD_NB_DRIVE   0x0A

Referenced by fat_example_parse_cmd(), and main().

#define CMD_NONE   0x00

Referenced by main().

#define CMD_RM   0x08

Referenced by fat_example_parse_cmd(), and main().

#define CMD_SET_ID   0x0B

Referenced by fat_example_parse_cmd(), and main().

#define CMD_TOUCH   0x07

Referenced by fat_example_parse_cmd(), and main().

#define CR   '\r'

Referenced by fat_example_build_cmd().

#define CRLF   "\r\n"

Referenced by fat_example_build_cmd(), and main().

#define CTRL_C   0x03
#define CTRL_Q   0x11
#define EXAMPLE_TARGET_PBACLK_FREQ_HZ   FOSC0

Referenced by at45dbx_resources_init(), and main().

#define HISTORY_CHAR   '!'
#define LF   '\n'
#define MSG_APPEND_WELCOME   "\r\nSimple text editor, enter char to append, ^q to exit and save\r\n"

Referenced by fat_example_append_file().

#define MSG_ER_CMD_NOT_FOUND   "Command not found\r\n"

Referenced by fat_example_parse_cmd(), and main().

#define MSG_ER_DRIVE   "Drive does not exist\r\n"

Referenced by main().

#define MSG_ER_FORMAT   "Format fails\r\n"

Referenced by main().

#define MSG_ER_MOUNT   "Unable to mount drive\r\n"

Referenced by main().

#define MSG_ER_MV   "Error during move\r\n"

Referenced by main().

#define MSG_ER_RM   "Can not erase; if the name is a directory, check it is empty\r\n"

Referenced by main().

#define MSG_ER_UNKNOWN_FILE   "Unknown file\r\n"

Referenced by main().

#define MSG_HELP
Value:
"Commands summary\r\n" \
" a:, b:... goto selected drive mount disk(a, b...)\r\n" \
" cd dirname ls\r\n" \
" mkdir dirname cat filename\r\n" \
" touch filename disk: get number of drives\r\n" \
" append filename goto: goto bookmark\r\n" \
" mark: bookmark current directory df: get free space information\r\n" \
" cp filename: copy filename to bookmark fat: get FAT type for current drive\r\n" \
" rm filename: erase file or EMPTY directory format drivename, with drivename: a, b...\r\n" \
" mv src dst: move file or directory format32 drivename, with drivename: a, b...\r\n" \
" help\r\n"

Referenced by main().

#define MSG_PROMPT   "$>"
#define MSG_WELCOME
Value:
"\r\n" \
"-------------------------\r\n" \
" ATMEL AVR32 Shell\r\n" \
"-------------------------\r\n"

Referenced by main().

#define QUIT_APPEND   CTRL_Q

Referenced by fat_example_append_file().

#define SHL_USART   (&AVR32_USART1)
#define SHL_USART_BAUDRATE   57600

Referenced by init_shl_rs232().

#define SHL_USART_RX_FUNCTION   AVR32_USART1_RXD_0_0_FUNCTION

Referenced by init_shl_rs232().

#define SHL_USART_RX_PIN   AVR32_USART1_RXD_0_0_PIN

Referenced by init_shl_rs232().

#define SHL_USART_TX_FUNCTION   AVR32_USART1_TXD_0_0_FUNCTION

Referenced by init_shl_rs232().

#define SHL_USART_TX_PIN   AVR32_USART1_TXD_0_0_PIN

Referenced by init_shl_rs232().

#define STR_A   "a:"

Referenced by fat_example_parse_cmd().

#define STR_APPEND   "append"

Referenced by fat_example_parse_cmd().

#define STR_B   "b:"

Referenced by fat_example_parse_cmd().

#define STR_C   "c:"

Referenced by fat_example_parse_cmd().

#define STR_CAT   "cat"

Referenced by fat_example_parse_cmd().

#define STR_CD   "cd"

Referenced by fat_example_parse_cmd().

#define STR_CP   "cp"

Referenced by fat_example_parse_cmd().

#define STR_D   "d:"

Referenced by fat_example_parse_cmd().

#define STR_DF   "df"

Referenced by fat_example_parse_cmd().

#define STR_DISK   "disk"

Referenced by fat_example_parse_cmd().

#define STR_FAT   "fat"

Referenced by fat_example_parse_cmd().

#define STR_FORMAT   "format"

Referenced by fat_example_parse_cmd().

#define STR_FORMAT32   "format32"

Referenced by fat_example_parse_cmd().

#define STR_GOTO   "goto"

Referenced by fat_example_parse_cmd().

#define STR_HELP   "help"

Referenced by fat_example_parse_cmd().

#define STR_LS   "ls"

Referenced by fat_example_parse_cmd().

#define STR_MARK   "mark"

Referenced by fat_example_parse_cmd().

#define STR_MKDIR   "mkdir"

Referenced by fat_example_parse_cmd().

#define STR_MOUNT   "mount"

Referenced by fat_example_parse_cmd().

#define STR_MV   "mv"

Referenced by fat_example_parse_cmd().

#define STR_RM   "rm"

Referenced by fat_example_parse_cmd().

#define STR_TOUCH   "touch"

Referenced by fat_example_parse_cmd().

static void fat_example_append_file ( void  )
static

Minimalist file editor to append char to a file.

Note
Hit ^q to exit and save file.

References file_putc(), MSG_APPEND_WELCOME, print(), print_char(), QUIT_APPEND, SHL_USART, usart_read_char(), usart_reset_status(), and USART_SUCCESS.

Referenced by main().

static void fat_example_build_cmd ( void  )
static

Gets the full command line on RS232 input to be interpreted. The cmd_str variable is built with the user inputs.

References ABORT_CHAR, BKSPACE_CHAR, cmd_str, CR, CRLF, fat_example_parse_cmd(), i_str, MSG_PROMPT, print(), print_char(), SHL_USART, usart_read_char(), usart_reset_status(), and USART_SUCCESS.

Referenced by main().

static void fat_example_parse_cmd ( void  )
static

Decodes full command line into command type and arguments.

This function allows to set the cmd_type variable to the command type decoded with its respective arguments par_str1 and par_str2.

References cmd, CMD_APPEND, CMD_CAT, CMD_CD, CMD_CP, CMD_DF, CMD_FAT, CMD_FORMAT, CMD_FORMAT32, CMD_GOTO_ID, CMD_HELP, CMD_LS, CMD_MKDIR, CMD_MOUNT, CMD_MV, CMD_NB_DRIVE, CMD_RM, CMD_SET_ID, cmd_str, CMD_TOUCH, cmd_type, i_str, MSG_ER_CMD_NOT_FOUND, MSG_PROMPT, par_str1, par_str2, print(), SHL_USART, STR_A, STR_APPEND, STR_B, STR_C, STR_CAT, STR_CD, STR_CP, STR_D, STR_DF, STR_DISK, STR_FAT, STR_FORMAT, STR_FORMAT32, STR_GOTO, STR_HELP, STR_LS, STR_MARK, STR_MKDIR, STR_MOUNT, STR_MV, STR_RM, and STR_TOUCH.

Referenced by fat_example_build_cmd().

static void init_shl_rs232 ( long  pba_hz)
static
int main ( void  )

Main function. Execution starts here.

References at45dbx_resources_init(), cmd, CMD_APPEND, CMD_CAT, CMD_CD, CMD_CP, CMD_DF, CMD_FAT, CMD_FORMAT, CMD_FORMAT32, CMD_GOTO_ID, CMD_HELP, CMD_LS, CMD_MKDIR, CMD_MOUNT, CMD_MV, CMD_NB_DRIVE, CMD_NONE, CMD_RM, CMD_SET_ID, CMD_TOUCH, cmd_type, COPY_BUSY, CRLF, CTRL_GOOD, EXAMPLE_TARGET_PBACLK_FREQ_HZ, fat_example_append_file(), fat_example_build_cmd(), file_close(), file_eof(), file_getc(), file_open(), first_ls, FOPEN_MODE_APPEND, FOPEN_MODE_R, FOSC0, FS_DIR, FS_FILE, FS_FIND_NEXT, FS_FORMAT_DEFAULT, FS_FORMAT_FAT32, FS_NAME_GET, FS_SHIFT_B_TO_SECTOR, FS_TYPE_FAT_12, FS_TYPE_FAT_16, FS_TYPE_FAT_32, init_shl_rs232(), LUN_ID_AT45DBX_MEM, MAX_FILE_PATH_LENGTH, mem_name(), mem_read_capacity(), mem_test_unit_ready(), MSG_ER_CMD_NOT_FOUND, MSG_ER_DRIVE, MSG_ER_FORMAT, MSG_ER_MOUNT, MSG_ER_MV, MSG_ER_RM, MSG_ER_UNKNOWN_FILE, MSG_HELP, MSG_PROMPT, MSG_WELCOME, nav_dir_make(), nav_dir_name(), nav_drive_format(), nav_drive_get(), nav_drive_nb(), nav_drive_set(), nav_file_copy(), nav_file_create(), nav_file_del(), nav_file_isdir(), nav_file_lgt(), nav_file_lgtsector(), nav_file_name(), nav_file_paste_start(), nav_file_paste_state(), nav_file_rename(), nav_filelist_first(), nav_filelist_nb(), nav_filelist_reset(), nav_filelist_set(), nav_getindex(), nav_gotoindex(), nav_partition_freespace(), nav_partition_mount(), nav_partition_space(), nav_partition_type(), nav_reset(), nav_setcwd(), OSC0_STARTUP, par_str1, par_str2, pcl_configure_clocks(), PCL_OSC0, pcl_switch_to_osc(), print(), print_char(), print_ulong(), SHL_USART, and str_buff.

bool cmd
static

flag for a command presence

Referenced by fat_example_parse_cmd(), and main().

char cmd_str[10+2 *MAX_FILE_PATH_LENGTH]
static

string for command

Referenced by fat_example_build_cmd(), and fat_example_parse_cmd().

uint8_t cmd_type
static

command number

Referenced by fat_example_parse_cmd(), and main().

bool first_ls
static

flag for first ls : mount if set

Referenced by main().

uint8_t i_str = 0
static

string length

Referenced by fat_example_build_cmd(), and fat_example_parse_cmd().

char par_str1[MAX_FILE_PATH_LENGTH]
static

string for first arg

Referenced by fat_example_parse_cmd(), and main().

char par_str2[MAX_FILE_PATH_LENGTH]
static

string for second arg

Referenced by fat_example_parse_cmd(), and main().

char str_buff[MAX_FILE_PATH_LENGTH]
static

buffer for command line

Referenced by main().