Skip to content

Commit

Permalink
Create new non-timer based blink app
Browse files Browse the repository at this point in the history
Now that timeslicing is up and running, there is no harm in having a
synchronous blink app and it is useful for porting new hardware (before
a driver for the hardware driver has been implemented).

Renames the timer-based, asynchronous, blink app to "blink" and creates
a new synchronous app (that just spins for a while) called "blink_sync".
  • Loading branch information
alevy committed Jul 14, 2016
1 parent 9531b2a commit 1cd3fd4
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 1 deletion.
2 changes: 1 addition & 1 deletion apps/c_blinky/Makefile → apps/blink/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
TOCK_APPS_DIR=..
APP=c_blinky
APP=blink

include $(TOCK_APPS_DIR)/Makefile.GenericApp.mk

Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions apps/blink_sync/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
TOCK_APPS_DIR=..
APP=blink_sync

include $(TOCK_APPS_DIR)/Makefile.GenericApp.mk

CPPFLAGS += -DSTACK_SIZE=2048
56 changes: 56 additions & 0 deletions apps/blink_sync/loader.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
ENTRY(_start)

MEMORY {
FLASH (rx) : ORIGIN = 0x80000000, LENGTH = 0x00080000
SRAM (RWX) : ORIGIN = 0x00000000, LENGTH = 0x00002000
}

SECTIONS {
/* Load information, used by runtime to load app */
.load_info :
{
KEEP(*(.load_info))
} > FLASH =0xFF

/* Text section, Code! */
.text :
{
_text = .;
KEEP (*(.start))
*(.text*)
*(.rodata*)
KEEP (*(.syscalls))
_etext = .;
} > FLASH =0xFF

/* Global Offset Table */
.got :
{
_got = .;
*(.got*)
_egot = .;
_plt = .;
*(.got.plt*)
_eplt = .;
} > SRAM AT > FLASH

/* Data section, static initialized variables
* Note: This is placed in Flash after the text section, but needs to be
* moved to SRAM at runtime
*/
.data :
{
_data = .;
*(.data*)
_edata = .;
} > SRAM AT > FLASH

/* BSS section, static uninitialized variables */
.bss :
{
_bss = .;
*(.bss*)
*(COMMON)
_ebss = .;
} > SRAM
}
50 changes: 50 additions & 0 deletions apps/blink_sync/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include <firestorm.h>
#include <gpio.h>

/* Delay for for the given microseconds (approximately).
*
* For a 16 MHz CPU, 1us == 16 instructions (assuming each instruction takes
* one cycle). */
static void busy_delay_us(int duration)
{
// The inner loop instructions are: 14 NOPs + 1 SUBS/ADDS + 1 CMP
while (duration-- != 0) {
__asm volatile (
"nop\n"
"nop\n"
"nop\n"
"nop\n"
"nop\n"
"nop\n"
"nop\n"
"nop\n"
"nop\n"
"nop\n"
"nop\n"
"nop\n"
"nop\n"
"nop\n"
);
}
}

/* Delay for for the given milliseconds (approximately).
*
* Note that this is not precise as there are 2 extra instructions on the inner
* loop. Therefore, there is 1us added every 8 iterations. */
static void busy_delay_ms(int duration)
{
while (duration-- != 0) {
busy_delay_us(1000);
}
}

void main(void) {
gpio_enable_output(LED_0);

while(1) {
gpio_toggle(LED_0);
busy_delay_ms(500);
}
}

0 comments on commit 1cd3fd4

Please sign in to comment.