Services

Timer Services

Getting system time using C libraries is an option, but you can also get time directly from "rtc.h". Other than this, there are two more timer services you can use as demonstrated in the code sample below.

#include "lpc_sys.h"
#include "soft_timer.hpp"

void timers()
{
	/* You can get the time since the board has been powered */
	uint64_t uptime_ms = sys_get_uptime_ms();
	uint64_t uptime_us = sys_get_uptime_us();

	/* There is also a polling timer available in C++, read "soft_timer.hpp" for more info. */
	SoftTimer myTimer(1000);

	if (myTimer.expired())
	{
		/* Do something */
	}
}

File I/O

You can read or write files on the SPI Flash or an SD card. You can open a limited amount of files using standard C libraries. First, at your sys_config.h file, please enable ENABLE_C_FILE_IO

#include "io.hpp"

void file_io()
{
	/* Option 1 : C library I/O (less efficient)
	 * 0: is for SPI Flash
	 * 1: is for SD Card
	 */
	FILE *fd = fopen("1:myfile.txt", "r");
	char line[128] = { 0 };
	if (fd)
	{
		fgets(line, sizeof(line) - 1, fd);
		fclose(fd);
	}

	/* Option 2 : Use "storage" object (more efficient)
	 * This option doesn't require 'ENABLE_C_FILE_IO'
	 */

	/* Write "hello" to "myfile.txt" */
	Storage::write("1:myfile.txt", "hello", 5, 0))

	/* Read the size of data array from myfile.txt
	 * Not using 0: or 1: will default to 0: (SPI Flash)
	 */
	char data[16] = { 0 };
	Storage::read("1:myfile.txt", data, sizeof(data) - 1, 0));

	/* Option 3 : Directly use ff.h API that will
	 * read/write SD card or SPI Flash
	 * Read documentation at : http://elm-chan.org/fsw/ff/00index_e.html
	 */
}
Back to top