NG preprocessor macro MODULE/REGISTER/END

25 views
Skip to first unread message

Simon Jackson

unread,
Jun 18, 2012, 10:20:37 PM6/18/12
to openc...@googlegroups.com
As a simple modified example so far....

// system
#include <openchronos.h>

// driver
#include <drivers/display.h>

MODULE(rfbsl);

#define rfbsl_up_press NULL
#define rfbsl_down_press NULL
#define rfbsl_num_press NULL
#define rfbsl_lnum_press NULL
#define rfbsl_lstar_press NULL

// Entry point of of the Flash Updater in BSL memory
#define CALL_RFSBL() ((void (*)())0x1000)()

// *************************************************************************************************
// @fn mx_rfbsl
// @brief This functions starts the RFBSL
// @param line LINE1, LINE2
// @return none
// *************************************************************************************************
static void rfbsl_ud_press()
{
/* TODO: we need to reimplement this */
//if (sys.flag.low_battery) return;

// Exit if SimpliciTI stack is active
/*if (is_rf()) return;*/

// Write RAM to indicate we will be downloading the RAM Updater first
display_chars(NULL, LCD_SEG_L1_3_0, (uint8_t *)" RAM", SEG_ON);

// Call RFBSL
CALL_RFSBL();
}


// *************************************************************************************************
// @fn display_rfbsl
// @brief RFBSL display routine.
// @param uint8_t line LINE2
// uint8_t update DISPLAY_LINE_UPDATE_FULL
// @return none
// *************************************************************************************************
static void rfbsl_activated()
{
/* update screen */
display_chars(NULL, LCD_SEG_L2_5_0, (uint8_t *)" RFBSL", SEG_ON);
}

static void rfbsl_deactivated()
{
/* null */
}

void rfbsl_init(void)
{
REGISTER(rfbsl);
}

END(rfbsl);

Simon Jackson

unread,
Jun 18, 2012, 10:33:21 PM6/18/12
to openc...@googlegroups.com
So the modifications are to place the code below into openchronous.h and edit all that applies. use a temp to store menu_item->is and the code becomes smaller, and has complete static allocation of the structure, in flash code, a smaller RAM overhead, and smaller code size. The need to copy a larger argument list into a dynamic structure is avoided. I'll take the new lcd display code on board soon.... :D



/* Menu definitions and declarations */
struct menu {
/* Pointer to up button handler */
void (*up_btn_fn)(void);
/* Pointer to down button handler */
void (*down_btn_fn)(void);
/* Pointer to function button (NUM) */
void (*num_btn_fn)(void);
/* Pointer to settings button (long STAR) */
void (*lstar_btn_fn)(void);
/* Pointer to function button (long NUM) */
void (*lnum_btn_fn)(void);
/* Pointer to simultaneous up&down press */
void (*updown_btn_fn)(void);
/* Pointer to activate function */
void (*activate_fn)(void);
/* Pointer to deactivate function */
void (*deactivate_fn)(void);
};

struct allocation {
struct menu *is;
/* pointer to next menu item */
struct allocation *next;
};

/* The currently active menu item */
struct allocation *menu_item;

/* NB: More public definitions */

#define MODULE(name) struct menu name##_menu; struct allocation name##_allocation = { &name##_menu, NULL }

#define REGISTER(name) menu_add_entry(&name##_allocation)

#define END(name) struct menu name##_menu = { name##_up_press, name##_down_press, name##_num_press, name##_lstar_press, name##_lnum_press, name##_ud_press, name##_activated, name##_deactivated }

Simon Jackson

unread,
Jun 19, 2012, 4:06:11 AM6/19/12
to openc...@googlegroups.com
Bytes are down to 6560 main section, with the rough virtual display allocation not via malloc. Also all allocation and freeing not expressed in user code. The MODULE and END macros gained an extra parameter of how many screens with zero being the LCD.

Simon Jackson

unread,
Jun 19, 2012, 3:43:52 PM6/19/12
to openc...@googlegroups.com
Bytes are down to 6166. A second parameter is required for both MODULE and END. It is a number representing the number of virtual screens you want auto allocated on activate, and auto deallocated on deactivate. They have to be the same number! And it can be zero. I have also made it necessary to

#define modulename_up_press NOP

if you do not use any button event, as it makes for much smaller code size. I need to make the automatic editor work again... Shouldn't be too hard for little code size.

Cheers Jacko

Aljaž Srebrnič

unread,
Jun 20, 2012, 6:40:57 AM6/20/12
to openc...@googlegroups.com
Hey!
I don't wanna sound hostile, but the correct place of your text above would be the commit message of your repository, not the mailing list! Please, just fill the commit message instead of posting to the list, so everyone that is subscribed but not interested in the development of openchronos-ng won't have his inbox full of emails that are not interesting to him.

Thank you,
Aljaž Srebrnič
-- --
My public key:  http://bit.ly/g5pw_pubkey

Simon Jackson

unread,
Jun 21, 2012, 10:08:28 PM6/21/12
to openc...@googlegroups.com
To this end I started a google group called OpenChronosHactivism. A high traffic web interface forum group.
Reply all
Reply to author
Forward
0 new messages