Microchip® Advanced Software Framework

fsaccess_example.c File Reference
#include <string.h>
#include "compiler.h"
#include "preprocessor.h"
#include "board.h"
#include "print_funcs.h"
#include "power_clocks_lib.h"
#include "gpio.h"
#include "usart.h"
#include "spi.h"
#include "conf_at45dbx.h"
#include "fsaccess.h"

Macros

#define ABORT_CHAR   CTRL_C
 
#define AT45DBX_ENABLE_NPCS_PIN(NPCS, unused)   {AT45DBX_SPI_NPCS##NPCS##_PIN, AT45DBX_SPI_NPCS##NPCS##_FUNCTION},
 
#define BKSPACE_CHAR   '\b'
 
#define CR   '\r'
 
#define CRLF   "\r\n"
 
#define CTRL_C   0x03
 
#define CTRL_Q   0x11
 
#define LF   '\n'
 
#define MSG_FILENAME   "Enter the filename : "
 
#define MSG_MODE   "\r\nWhat do you want to do ?\r\n\t1 - Read file\r\n\t2 - Concatenate a file to an existing one\r\n\t3 - Copy the content of a file to a new one\r\nenter your choice : "
 
#define MSG_WELCOME   "\r\n ---------- Welcome to FSACCESS Example ---------- \r\n"
 
#define NB_SECTOR_TO_SEND   4
 
#define QUIT_APPEND   CTRL_Q
 
#define TEST_FAIL   "\t[FAIL]\r\n"
 
#define TEST_SUCCESS   "\t[PASS]\r\n"
 

Functions

static void at45dbx_resources_init (void)
 Initialize dataflash memory AT45DBX resources: GPIO, SPI and AT45DBX. More...
 
void fsaccess_example_get_filename (char *buf)
 Wait for user to enter a filename. More...
 
int fsaccess_example_get_mode (void)
 Wait for user to select the mode he wants to test. More...
 
int fsaccess_example_read (char *path)
 Read a file and display it to USART. More...
 
int fsaccess_example_write (char *source, char *destination, int flags)
 Copy a file to another one. More...
 
int main (void)
 Main function, execution starts here. RS232 is used to input/output information. The example lets you issue the following commands on RS232 using POSIX interfaces (open, read, write, close): More...
 

Parameters to pcl_configure_clocks().

#define EXAMPLE_TARGET_PBACLK_FREQ_HZ   FOSC0
 
#define EXAMPLE_TARGET_DFLL_FREQ_HZ   96000000
 
#define EXAMPLE_TARGET_MCUCLK_FREQ_HZ   12000000
 
#define EXAMPLE_TARGET_PBACLK_FREQ_HZ   12000000
 
static scif_gclk_opt_t gc_dfllif_ref_opt = { SCIF_GCCTRL_SLOWCLOCK, 0, false }
 
static pcl_freq_param_t pcl_dfll_freq_param
 

#define ABORT_CHAR   CTRL_C
#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'
#define CR   '\r'
#define CTRL_C   0x03
#define CTRL_Q   0x11
#define EXAMPLE_TARGET_DFLL_FREQ_HZ   96000000
#define EXAMPLE_TARGET_MCUCLK_FREQ_HZ   12000000
#define EXAMPLE_TARGET_PBACLK_FREQ_HZ   FOSC0

Referenced by at45dbx_resources_init(), and main().

#define EXAMPLE_TARGET_PBACLK_FREQ_HZ   12000000
#define LF   '\n'
#define MSG_FILENAME   "Enter the filename : "
#define MSG_MODE   "\r\nWhat do you want to do ?\r\n\t1 - Read file\r\n\t2 - Concatenate a file to an existing one\r\n\t3 - Copy the content of a file to a new one\r\nenter your choice : "
#define MSG_WELCOME   "\r\n ---------- Welcome to FSACCESS Example ---------- \r\n"

Referenced by main().

#define NB_SECTOR_TO_SEND   4
#define QUIT_APPEND   CTRL_Q
#define TEST_FAIL   "\t[FAIL]\r\n"
#define TEST_SUCCESS   "\t[PASS]\r\n"

void fsaccess_example_get_filename ( char *  buf)

Wait for user to enter a filename.

References ABORT_CHAR, BKSPACE_CHAR, CR, CRLF, DBG_USART, MSG_FILENAME, print_dbg(), print_dbg_char(), usart_read_char(), usart_reset_status(), and USART_SUCCESS.

Referenced by main().

int fsaccess_example_get_mode ( void  )

Wait for user to select the mode he wants to test.

References CRLF, DBG_USART, MSG_MODE, print_dbg(), print_dbg_char(), usart_read_char(), usart_reset_status(), and USART_SUCCESS.

Referenced by main().

int fsaccess_example_read ( char *  path)

Read a file and display it to USART.

References close(), CRLF, FS_SIZE_OF_SECTOR, fsaccess_file_get_size(), NB_SECTOR_TO_SEND, O_RDONLY, open(), print_dbg(), print_dbg_ulong(), and read().

Referenced by main().

int fsaccess_example_write ( char *  source,
char *  destination,
int  flags 
)
int main ( void  )

Main function, execution starts here. RS232 is used to input/output information. The example lets you issue the following commands on RS232 using POSIX interfaces (open, read, write, close):

  • read a file from the memory files system;
  • concatenate a file to an existing one;
  • copy the content of a file to a new one.

Connect USART_1 to your serial port via a standard RS-232 D-SUB9 cable Set the following settings in your terminal of choice: 57600 8N1

References at45dbx_mem_check(), at45dbx_resources_init(), b_fsaccess_init(), EXAMPLE_TARGET_PBACLK_FREQ_HZ, FOSC0, fsaccess_example_get_filename(), fsaccess_example_get_mode(), fsaccess_example_read(), fsaccess_example_write(), init_dbg_rs232(), MSG_WELCOME, O_APPEND, O_CREAT, OSC0_STARTUP, pcl_configure_clocks(), pcl_dfll_freq_param, PCL_OSC0, pcl_switch_to_osc(), and print_dbg().

scif_gclk_opt_t gc_dfllif_ref_opt = { SCIF_GCCTRL_SLOWCLOCK, 0, false }
static
pcl_freq_param_t pcl_dfll_freq_param
static
Initial value:
=
{
.main_clk_src = PCL_MC_DFLL0,
.pextra_params = &gc_dfllif_ref_opt
}
Definition: power_clocks_lib.h:106
#define EXAMPLE_TARGET_PBACLK_FREQ_HZ
Definition: fsaccess_example.c:144
static scif_gclk_opt_t gc_dfllif_ref_opt
Definition: fsaccess_example.c:145
#define EXAMPLE_TARGET_MCUCLK_FREQ_HZ
Definition: fsaccess_example.c:142
#define EXAMPLE_TARGET_DFLL_FREQ_HZ
Definition: fsaccess_example.c:141

Referenced by main().