Skip to content

Refactor for applying astyle reformat #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion APIs_Drivers/BufferedSerial_echo/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ static DigitalOut led(LED1);
// Create a BufferedSerial object with a default baud rate.
static BufferedSerial serial_port(USBTX, USBRX);

int main(void) {
int main(void)
{
// Set desired properties (9600-8-N-1).
serial_port.set_baud(9600);
serial_port.set_format(
Expand Down
6 changes: 4 additions & 2 deletions APIs_Drivers/BufferedSerial_printf/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
// Create a BufferedSerial object to be used by the system I/O retarget code.
static BufferedSerial serial_port(TARGET_TX_PIN, TARGET_RX_PIN, 9600);

FileHandle *mbed::mbed_override_console(int fd) {
FileHandle *mbed::mbed_override_console(int fd)
{
return &serial_port;
}

int main(void) {
int main(void)
{
// print to the console using the `serial_port` object.
printf(
"Mbed OS version %d.%d.%d\n",
Expand Down
16 changes: 8 additions & 8 deletions APIs_Drivers/QSPI/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ static bool mem_ready()
} while ((status_value[0] & BIT_WIP) != 0 && retries);

if ((status_value[0] & BIT_WIP) != 0) {
printf ("mem_ready FALSE: status value = 0x%x\n", (int)status_value[0]);
printf("mem_ready FALSE: status value = 0x%x\n", (int)status_value[0]);
mem_ready = false;
}
return mem_ready;
Expand Down Expand Up @@ -138,8 +138,7 @@ static int sector_erase(unsigned int flash_addr)
return -1;
}

if (QSPI_STATUS_OK!= qspi_device.command_transfer(CMD_ERASE, (((int)flash_addr) & 0x00FFF000), NULL, 0, NULL, 0))
{
if (QSPI_STATUS_OK != qspi_device.command_transfer(CMD_ERASE, (((int)flash_addr) & 0x00FFF000), NULL, 0, NULL, 0)) {
printf("Erase failed\n");
return -1;
}
Expand All @@ -152,22 +151,23 @@ static int sector_erase(unsigned int flash_addr)
return 0;
}

int main() {
int main()
{
char tx_buf[BUF_SIZE] = { 'h', 'e', 'l', 'l', 'o', '\0' };
char rx_buf[BUF_SIZE] = {0};
size_t buf_len = sizeof(tx_buf);
qspi_status_t result;
uint32_t address = 0x1000;

result = qspi_device.configure_format(QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_SINGLE,
QSPI_CFG_ADDR_SIZE_24, QSPI_CFG_BUS_SINGLE,
QSPI_CFG_ALT_SIZE_8, QSPI_CFG_BUS_SINGLE, 0);
QSPI_CFG_ADDR_SIZE_24, QSPI_CFG_BUS_SINGLE,
QSPI_CFG_ALT_SIZE_8, QSPI_CFG_BUS_SINGLE, 0);
if (result != QSPI_STATUS_OK) {
printf("Config format failed\n");
}

if (QSPI_STATUS_OK != flash_init()) {
printf ("Init failed\n");
printf("Init failed\n");
return -1;
}

Expand Down Expand Up @@ -198,6 +198,6 @@ int main() {
return result;
}

printf ("Data Read = %s\n", rx_buf);
printf("Data Read = %s\n", rx_buf);
return 0;
}
6 changes: 4 additions & 2 deletions APIs_Drivers/UnbufferedSerial/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ static DigitalOut led(LED1);
// Create a UnbufferedSerial object with a default baud rate.
static UnbufferedSerial serial_port(USBTX, USBRX);

void on_rx_interrupt() {
void on_rx_interrupt()
{
char c;

// Toggle the LED.
Expand All @@ -24,7 +25,8 @@ void on_rx_interrupt() {
}
}

int main(void) {
int main(void)
{
// Set desired properties (9600-8-N-1).
serial_port.baud(9600);
serial_port.format(
Expand Down
9 changes: 6 additions & 3 deletions APIs_RTOS/EventQueue_ex_1/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,24 @@ Thread t;
// It's safe to use UnbufferedSerial in ISR context
UnbufferedSerial console(USBTX, USBRX);

void rise_handler(void) {
void rise_handler(void)
{
char buf[64];
sprintf(buf, "rise_handler in context %p\n", ThisThread::get_id());
console.write(buf, strlen(buf));
// Toggle LED
led1 = !led1;
}

void fall_handler(void) {
void fall_handler(void)
{
printf("rise_handler in context %p\n", ThisThread::get_id());
// Toggle LED
led1 = !led1;
}

int main() {
int main()
{
// Start the event queue
t.start(callback(&queue, &EventQueue::dispatch_forever));
printf("Starting in context %p\r\n", ThisThread::get_id());
Expand Down
6 changes: 3 additions & 3 deletions APIs_RTOS/Kernel_get_ms_count/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ int main()
{
// 64-bit time doesn't wrap for half a billion years, at least
uint64_t now = Kernel::get_ms_count();

// wait a while
ThisThread::sleep_for(10);
ThisThread::sleep_for(10);

uint64_t later = Kernel::get_ms_count();

//calculate millisecs elapsed
uint64_t elapsed_ms = later - now;

printf("Elapsed ms: %u \r\n", (uint32_t)elapsed_ms);
}
11 changes: 6 additions & 5 deletions APIs_RTOS/UserAllocatedEvent_ex_1/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ auto event2 = make_user_allocated_event(handler, 2);
// Creates event bound to the specified event queue
auto event3 = queue.make_user_allocated_event(handler, 3);
auto event4 = queue.make_user_allocated_event(handler, 4);

void handler(int count) {

void handler(int count)
{
printf("UserAllocatedEvent = %d \n", count);
return;
}
void post_events(void)

void post_events(void)
{
// Single instance of user allocated event can be posted only once.
// Event can be posted again if the previous dispatch has finished or event has been canceled.
Expand Down Expand Up @@ -64,7 +65,7 @@ void post_events(void)
event4();
}

int main()
int main()
{
printf("*** start ***\n");
Thread event_thread;
Expand Down
6 changes: 3 additions & 3 deletions APIs_Security/DeviceKey/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ int inject_rot_key()
memset(key, 0, DEVICE_KEY_16BYTE);
memcpy(key, "ABCDEF1234567890", DEVICE_KEY_16BYTE);
int size = DEVICE_KEY_16BYTE;
DeviceKey& devkey = DeviceKey::get_instance();
DeviceKey &devkey = DeviceKey::get_instance();
return devkey.device_inject_root_of_trust(key, size);
}

Expand All @@ -47,7 +47,7 @@ int main()
printf("\nMbed OS DeviceKey example \n");

// DeviceKey is a singleton
DeviceKey& devkey = DeviceKey::get_instance();
DeviceKey &devkey = DeviceKey::get_instance();

#if !defined(DEVICE_TRNG)

Expand All @@ -59,7 +59,7 @@ int main()
return -1;
}

if ( DEVICEKEY_ALREADY_EXIST == ret ) {
if (DEVICEKEY_ALREADY_EXIST == ret) {
printf("ROT Key already exists in the persistent memory.\n", ret);
} else {
printf("ROT Key injected and stored in persistent memory.\n", ret);
Expand Down
11 changes: 6 additions & 5 deletions APIs_Storage/BlockDevice/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <stdio.h>
#include <algorithm>

// This takes the system's default block device.
// This takes the system's default block device.
BlockDevice *bd = BlockDevice::get_default_instance();

// Instead of the default block device, you can define your own block device.
Expand All @@ -27,7 +27,8 @@ BlockDevice *bd = BlockDevice::get_default_instance();
// BlockDevice *bd = new HeapBlockDevice(2048, 1, 1, 512);

// Entry point for the example:
int main() {
int main()
{
printf("--- Mbed OS block device example ---\n");

// Initialize the block device.
Expand All @@ -51,7 +52,7 @@ int main() {
// Allocate a block with enough space for our data, aligned to the
// nearest program_size. This is the minimum size necessary to write
// data to a block.
size_t buffer_size = sizeof("Hello Storage!") + program_size-1;
size_t buffer_size = sizeof("Hello Storage!") + program_size - 1;
buffer_size = buffer_size - (buffer_size % program_size);
char *buffer = new char[buffer_size];

Expand Down Expand Up @@ -80,8 +81,8 @@ int main() {
printf("--- Stored data ---\n");
for (size_t i = 0; i < buffer_size; i += 16) {
for (size_t j = 0; j < 16; j++) {
if (i+j < buffer_size) {
printf("%02x ", buffer[i+j]);
if (i + j < buffer_size) {
printf("%02x ", buffer[i + j]);
} else {
printf(" ");
}
Expand Down
56 changes: 28 additions & 28 deletions APIs_Storage/BufferedBlockDevice/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,32 @@

int main()
{
// Define a HeapBlockDevice with program size 512 bytes and read size 256
HeapBlockDevice heap_bd(1024, 256, 512, 512);
// BufferedBlockDevice is used to program or read a much smaller amount of data than the minimum program or read size supported by the underlying block device
BufferedBlockDevice buf_bd(&heap_bd);
// This initializes the buffered block device (as well as the underlying heap block device)
int err = buf_bd.init();
uint8_t buf[8];
for (uint8_t i = 0; i < sizeof(buf); i++) {
buf[i] = i;
}
// Now we can program an 8-byte buffer (we couldn't do that in the underlying block device, which had a 512-byte program size)
err = buf_bd.program(buf, 0, sizeof(buf));
// Now read any amount of data from any address (for example, the last three bytes of data from address 5)
memset(buf,0,8);
err = buf_bd.read(buf, 5, 3);
printf("Read Data (Expected 5,6,7): %d %d %d\n", (int)(buf[0]), (int)(buf[1]), (int)(buf[2]));
// Ensure programmed data is flushed to the underlying block device
err = buf_bd.sync();
// Finally, deinint the BufferedBlockDevice (which also deinits its underlying block device)
err = buf_bd.deinit();
// Define a HeapBlockDevice with program size 512 bytes and read size 256
HeapBlockDevice heap_bd(1024, 256, 512, 512);
// BufferedBlockDevice is used to program or read a much smaller amount of data than the minimum program or read size supported by the underlying block device
BufferedBlockDevice buf_bd(&heap_bd);

// This initializes the buffered block device (as well as the underlying heap block device)
int err = buf_bd.init();

uint8_t buf[8];
for (uint8_t i = 0; i < sizeof(buf); i++) {
buf[i] = i;
}

// Now we can program an 8-byte buffer (we couldn't do that in the underlying block device, which had a 512-byte program size)
err = buf_bd.program(buf, 0, sizeof(buf));


// Now read any amount of data from any address (for example, the last three bytes of data from address 5)
memset(buf, 0, 8);
err = buf_bd.read(buf, 5, 3);

printf("Read Data (Expected 5,6,7): %d %d %d\n", (int)(buf[0]), (int)(buf[1]), (int)(buf[2]));

// Ensure programmed data is flushed to the underlying block device
err = buf_bd.sync();

// Finally, deinint the BufferedBlockDevice (which also deinits its underlying block device)
err = buf_bd.deinit();
}
5 changes: 3 additions & 2 deletions APIs_Storage/FlashIAPBlockDevice/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
// Create flash IAP block device
FlashIAPBlockDevice bd;

int main() {
int main()
{
printf("FlashIAPBlockDevice test\n");

// Initialize the flash IAP block device and print the memory layout
Expand All @@ -15,7 +16,7 @@ int main() {
printf("Flash block device erase size: %llu\n", bd.get_erase_size());

// Write "Hello World!" to the first block
char *buffer = (char*)malloc(bd.get_erase_size());
char *buffer = (char *)malloc(bd.get_erase_size());
sprintf(buffer, "Hello World!\n");
bd.erase(0, bd.get_erase_size());
bd.program(buffer, 0, bd.get_erase_size());
Expand Down
3 changes: 2 additions & 1 deletion APIs_Storage/FlashSimBlockDevice/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
HeapBlockDevice bd(2048, BLOCK_SIZE); // 2048 bytes with a block size of 512 bytes.
uint8_t block[BLOCK_SIZE] = "Hello World!\n";

int main() {
int main()
{

int erase_unit_size = 512;
HeapBlockDevice heap_bd(4 * erase_unit_size, 1, 4, erase_unit_size);
Expand Down
9 changes: 5 additions & 4 deletions APIs_Storage/MBRBlockDevice_ex_1/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
#include "HeapBlockDevice.h"
#include "MBRBlockDevice.h"

int main(void) {
int main(void)
{
// Create a block device with 64 blocks of size 512
printf("Create a block device with 64 blocks of size 512\n");
HeapBlockDevice mem(64*512, 512);
HeapBlockDevice mem(64 * 512, 512);

// Partition into two partitions with ~half the blocks
printf("Partition into two partitions with ~half the blocks\n");
MBRBlockDevice::partition(&mem, 1, 0x83, 0*512, 32*512);
MBRBlockDevice::partition(&mem, 2, 0x83, 32*512);
MBRBlockDevice::partition(&mem, 1, 0x83, 0 * 512, 32 * 512);
MBRBlockDevice::partition(&mem, 2, 0x83, 32 * 512);

// Create a block device that maps to the first 32 blocks (excluding MBR block)
printf("Create a block device that maps to the first 32 blocks (excluding MBR block)\n");
Expand Down
5 changes: 3 additions & 2 deletions APIs_Storage/MBRBlockDevice_ex_2/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
#include "MBRBlockDevice.h"
#include "FATFileSystem.h"

int main(void) {
int main(void)
{
// Create an SD card
printf("Creating SD block device\n");
SDBlockDevice sd(MBED_CONF_SD_SPI_MOSI, MBED_CONF_SD_SPI_MISO, MBED_CONF_SD_SPI_CLK, MBED_CONF_SD_SPI_CS);

// Create a partition with 1 GB of space
printf("Creating a partition with 1GB of space\n");
MBRBlockDevice::partition(&sd, 1, 0x83, 0, 1024*1024);
MBRBlockDevice::partition(&sd, 1, 0x83, 0, 1024 * 1024);

// Create the block device that represents the partition
printf("Create the block device that represents the partition\n");
Expand Down
3 changes: 2 additions & 1 deletion APIs_Storage/ProfilingBlockDevice/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
HeapBlockDevice bd(2048, BLOCK_SIZE); // 2048 bytes with a block size of 512 bytes
uint8_t block[BLOCK_SIZE] = "Hello World!\n";

int main() {
int main()
{
ProfilingBlockDevice profiler(&bd);
profiler.init();
profiler.erase(0, BLOCK_SIZE);
Expand Down
Loading