Implemented PINOUT.TXT file
This commit is contained in:
+59
-2
@@ -26,12 +26,12 @@ const char * rsc_get_name(Resource rsc)
|
||||
{
|
||||
assert_param(rsc < RESOURCE_COUNT);
|
||||
|
||||
static char gpionamebuf[4];
|
||||
static char gpionamebuf[5];
|
||||
if (rsc >= R_PA0) {
|
||||
// we assume the returned value is not stored anywhere
|
||||
// and is directly used in a sprintf call.
|
||||
uint8_t index = rsc - R_PA0;
|
||||
SNPRINTF(gpionamebuf, 4, "%c%d", 'A'+(index/16), index%16);
|
||||
SNPRINTF(gpionamebuf, 5, "P%c%d", 'A'+(index/16), index%16);
|
||||
return gpionamebuf;
|
||||
}
|
||||
|
||||
@@ -219,3 +219,60 @@ void rsc_teardown(Unit *unit)
|
||||
unit->resources[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void rsc_print_all_available(IniWriter *iw)
|
||||
{
|
||||
if (iw->count == 0) return;
|
||||
|
||||
static char buf[80];
|
||||
|
||||
iw_string(iw, "Resources available on this platform\r\n"
|
||||
"------------------------------------\r\n");
|
||||
|
||||
ResourceMap scratchmap = {};
|
||||
for (uint32_t i = 0; i < RSCMAP_LEN; i++) {
|
||||
scratchmap[i] = UNIT_PLATFORM.resources[i] | UNIT_SYSTEM.resources[i];
|
||||
}
|
||||
|
||||
uint32_t count0 = (iw->count + iw->skip);
|
||||
bool first = true;
|
||||
for (uint32_t rsc = 0; rsc < R_PA0; rsc++) {
|
||||
if (RSC_IS_HELD(scratchmap, (Resource)rsc)) continue;
|
||||
if (!first) iw_string(iw, ", ");
|
||||
|
||||
// automatic newlines
|
||||
if (count0 - (iw->count + iw->skip) >= 55) {
|
||||
iw_newline(iw);
|
||||
count0 = (iw->count + iw->skip);
|
||||
}
|
||||
|
||||
iw_string(iw, rsc_get_name((Resource) rsc));
|
||||
first = false;
|
||||
}
|
||||
|
||||
// GPIOs will be printed using the range format
|
||||
uint16_t bitmap = 0;
|
||||
for (uint32_t rsc = R_PA0, i = 0; rsc <= R_PF15; rsc++, i++) {
|
||||
if (i%16 == 0) {
|
||||
// here we print the previous port
|
||||
if (bitmap != 0) {
|
||||
iw_string(iw, str_pinmask(bitmap, buf));
|
||||
bitmap = 0;
|
||||
}
|
||||
|
||||
// first of a port
|
||||
iw_newline(iw);
|
||||
iw_sprintf(iw, "P%c: ", (char)('A' + (i/16)));
|
||||
}
|
||||
|
||||
if (RSC_IS_FREE(scratchmap, (Resource)rsc)) {
|
||||
bitmap |= 1<<i%16;
|
||||
}
|
||||
}
|
||||
// the last one
|
||||
if (bitmap != 0) {
|
||||
iw_string(iw, str_pinmask(bitmap, buf));
|
||||
}
|
||||
iw_newline(iw);
|
||||
iw_newline(iw);
|
||||
}
|
||||
|
||||
@@ -36,4 +36,7 @@ const char * rsc_get_name(Resource rsc);
|
||||
/** Get rsc owner name */
|
||||
const char * rsc_get_owner_name(Resource rsc);
|
||||
|
||||
/** Print all available resource names */
|
||||
void rsc_print_all_available(IniWriter *iw);
|
||||
|
||||
#endif //GEX_RESOURCES_H
|
||||
|
||||
+33
-21
@@ -2,13 +2,14 @@
|
||||
// Created by MightyPork on 2017/11/26.
|
||||
//
|
||||
|
||||
#include <utils/avrlibc.h>
|
||||
#include "utils/avrlibc.h"
|
||||
#include "platform.h"
|
||||
#include "utils/hexdump.h"
|
||||
#include "settings.h"
|
||||
#include "unit_registry.h"
|
||||
#include "system_settings.h"
|
||||
#include "utils/str_utils.h"
|
||||
#include "unit_base.h"
|
||||
|
||||
// pre-declarations
|
||||
static void savebuf_flush(PayloadBuilder *pb, bool final);
|
||||
@@ -211,27 +212,37 @@ static void savebuf_flush(PayloadBuilder *pb, bool final)
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
static void ini_preamble(IniWriter *iw, const char *filename)
|
||||
static void gex_file_preamble(IniWriter *iw, const char *filename)
|
||||
{
|
||||
// File header
|
||||
// File header
|
||||
iw_hdr_comment(iw, filename);
|
||||
iw_hdr_comment(iw, "GEX v%s on %s", GEX_VERSION, GEX_PLATFORM);
|
||||
iw_hdr_comment(iw, "built %s at %s", __DATE__, __TIME__);
|
||||
iw_cmt_newline(iw);
|
||||
}
|
||||
|
||||
static void ini_preamble(IniWriter *iw, const char *filename)
|
||||
{
|
||||
gex_file_preamble(iw, filename);
|
||||
|
||||
iw_comment(iw, "Overwrite this file to change settings.");
|
||||
iw_comment(iw, "Close the LOCK jumper to save them to Flash.");
|
||||
#if PLAT_LOCK_BTN
|
||||
iw_comment(iw, "Press the LOCK button to save them to Flash.");
|
||||
#else
|
||||
iw_comment(iw, "Close the LOCK jumper to save them to Flash.");
|
||||
#endif
|
||||
}
|
||||
|
||||
// --- UNITS.INI ---
|
||||
|
||||
extern osMutexId mutScratchBufferHandle;
|
||||
|
||||
/**
|
||||
* Write system settings to INI (without section)
|
||||
* Build units ini file
|
||||
*/
|
||||
void settings_build_units_ini(IniWriter *iw)
|
||||
{
|
||||
ini_preamble(iw, "UNITS.INI");
|
||||
|
||||
assert_param(osOK == osMutexWait(mutScratchBufferHandle, 5000));
|
||||
{
|
||||
ureg_build_ini(iw);
|
||||
@@ -239,31 +250,32 @@ void settings_build_units_ini(IniWriter *iw)
|
||||
assert_param(osOK == osMutexRelease(mutScratchBufferHandle));
|
||||
}
|
||||
|
||||
// --- SYSTEM.INI ---
|
||||
|
||||
/**
|
||||
* Write system settings to INI (without section)
|
||||
* Build system settings ini file
|
||||
*/
|
||||
void settings_build_system_ini(IniWriter *iw)
|
||||
{
|
||||
ini_preamble(iw, "SYSTEM.INI");
|
||||
|
||||
systemsettings_build_ini(iw);
|
||||
}
|
||||
|
||||
uint32_t settings_get_units_ini_len(void)
|
||||
{
|
||||
// this writer is configured to skip everything, so each written byte will decrement the skip count
|
||||
IniWriter iw = iw_init(NULL, 0xFFFFFFFF, 1); // count is never used, we use 1 because 0 means we're full
|
||||
settings_build_units_ini(&iw);
|
||||
// now we just check how many bytes were skipped
|
||||
return 0xFFFFFFFF - iw.skip;
|
||||
}
|
||||
// --- PINOUT.TXT ---
|
||||
|
||||
uint32_t settings_get_system_ini_len(void)
|
||||
/** print system pin.-out info (platform.c) */
|
||||
extern void plat_print_system_pinout(IniWriter *iw);
|
||||
|
||||
/**
|
||||
* Build pinout info file
|
||||
*/
|
||||
void settings_build_pinout_txt(IniWriter *iw)
|
||||
{
|
||||
// same as above
|
||||
IniWriter iw = iw_init(NULL, 0xFFFFFFFF, 1);
|
||||
settings_build_system_ini(&iw);
|
||||
return 0xFFFFFFFF - iw.skip;
|
||||
gex_file_preamble(iw, "PINOUT.TXT");
|
||||
|
||||
rsc_print_all_available(iw);
|
||||
ureg_print_unit_resources(iw);
|
||||
plat_print_system_pinout(iw);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
+3
-11
@@ -56,13 +56,6 @@ void settings_load_ini_end(void);
|
||||
*/
|
||||
void settings_build_units_ini(IniWriter *iw);
|
||||
|
||||
/**
|
||||
* Get UNITS.INI len (expensive, uses dummy read)
|
||||
*
|
||||
* @return bytes
|
||||
*/
|
||||
uint32_t settings_get_units_ini_len(void);
|
||||
|
||||
/**
|
||||
* Write SYSTEM.INI to iniwriter
|
||||
* @param iw - writer handle
|
||||
@@ -70,10 +63,9 @@ uint32_t settings_get_units_ini_len(void);
|
||||
void settings_build_system_ini(IniWriter *iw);
|
||||
|
||||
/**
|
||||
* Get SYSTEM.INI len (expensive, uses dummy read)
|
||||
*
|
||||
* @return bytes
|
||||
* Write UNITS.TXT to iniwriter
|
||||
* @param iw - writer handle
|
||||
*/
|
||||
uint32_t settings_get_system_ini_len(void);
|
||||
void settings_build_pinout_txt(IniWriter *iw);
|
||||
|
||||
#endif //GEX_SETTINGS_H
|
||||
|
||||
@@ -557,3 +557,29 @@ Unit *ureg_get_rsc_owner(Resource resource)
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void ureg_print_unit_resources(IniWriter *iw)
|
||||
{
|
||||
if (iw->count == 0) return;
|
||||
|
||||
iw_string(iw, "Resources held by units\r\n"
|
||||
"-----------------------\r\n");
|
||||
UlistEntry *li = ulist_head;
|
||||
while (li != NULL) {
|
||||
iw_string(iw, li->unit.name);
|
||||
iw_string(iw, ": ");
|
||||
|
||||
bool first = true;
|
||||
for (uint32_t rsc = 0; rsc < RESOURCE_COUNT; rsc++) {
|
||||
if (!RSC_IS_HELD(li->unit.resources, (Resource)rsc)) continue;
|
||||
if (!first) iw_string(iw, ", ");
|
||||
iw_string(iw, rsc_get_name((Resource) rsc));
|
||||
first = false;
|
||||
}
|
||||
if (first) iw_string(iw, "-none-");
|
||||
iw_newline(iw);
|
||||
|
||||
li = li->next;
|
||||
}
|
||||
iw_newline(iw);
|
||||
}
|
||||
|
||||
@@ -135,4 +135,11 @@ void ureg_report_active_units(TF_ID frame_id);
|
||||
*/
|
||||
Unit *ureg_get_rsc_owner(Resource resource);
|
||||
|
||||
/**
|
||||
* Print a overview of resources held by units
|
||||
*
|
||||
* @param iw
|
||||
*/
|
||||
void ureg_print_unit_resources(IniWriter *iw);
|
||||
|
||||
#endif //GEX_UNIT_REGISTRY_H
|
||||
|
||||
Reference in New Issue
Block a user