Skip to content

Commit

Permalink
Fix bug in CFE_TBL_Register stub, address more PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Others committed Apr 28, 2018
1 parent 6d5c47f commit caf490c
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
#include <stdio.h>
#include <string.h>
#include <assert.h>

#include <cos_component.h>
#include <cos_kernel_api.h>
#include <cos_debug.h>
#include <cobj_format.h>
#include <llprint.h>

#include "gen/osapi.h"
#include "cFE_util.h"

void
llprint(const char *s, int len)
{
call_cap(PRINT_CAP_TEMP, (int)s, len, 0, 0);
}

void
panic_impl(const char *function, char *message)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,14 @@

#include <cos_component.h>
#include <cos_kernel_api.h>
#include <cobj_format.h>

#include <llprint.h>

#include <cos_debug.h>

#include "gen/common_types.h"

// These variables store the global SPACECRAFT_ID and CPU_ID
uint32 CFE_PSP_SpacecraftId;
uint32 CFE_PSP_CpuId;

void llprint(const char *s, int len);

int __attribute__((format(printf, 1, 2))) printc(char *fmt, ...);

#define PANIC(a) panic_impl(__func__, a)

void panic_impl(const char *function, char *message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ OS_printf(const char *string, ...)
va_start(arg_ptr, string);
ret = vsnprintf(s, len, string, arg_ptr);
va_end(arg_ptr);
llprint(s, ret);
cos_llprint(s, ret);
}

void
Expand Down
13 changes: 10 additions & 3 deletions src/components/implementation/no_interface/cFE_booter/tar.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#include "osfilesys.h"
#include "tar.h"
#include <string.h>

#include <cos_debug.h>

#include "osfilesys.h"
#include "tar.h"

/* should be overwritten by linking step in build process */
__attribute__((weak)) char _binary_cFE_fs_tar_size = 0;
__attribute__((weak)) char _binary_cFE_fs_tar_start = 0;
Expand Down Expand Up @@ -110,6 +112,7 @@ tar_hdr_read(uint32 tar_offset, struct fsobj *file)
{
char * location;
struct f_part *part;
uint32 file_data_offset;

assert(tar_offset < tar_size);
assert(file->ino > 0);
Expand All @@ -123,14 +126,18 @@ tar_hdr_read(uint32 tar_offset, struct fsobj *file)
location[0] = '/';
file->name = path_to_name(location);

file_data_offset = round_to_blocksize(tar_offset + 500);

PRINT_LOG(PRINT_DEBUG, "Found file in tar: name = %s\n", file->name);

if (*(location + strlen(location) - 1) == '/') {
file->type = FSOBJ_DIR;
file->size = 0;
} else {
file->type = FSOBJ_FILE;
file->size = oct_to_dec(location + 124);
file->file_part = part;
file->file_part->data = location + 500;
file->file_part->data = tar_start + file_data_offset;
}
return OS_FS_SUCCESS;
}
27 changes: 22 additions & 5 deletions src/components/include/llprint.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,20 @@ printc(char *fmt, ...)

typedef enum {
PRINT_ERROR = 0, /* print only error messages */
PRINT_WARN, /* print errors and warnings */
PRINT_DEBUG /* print errors, warnings and debug messages */
PRINT_WARN, /* print errors and warnings */
PRINT_INFO, /* print info messages, errors, and warnings */
PRINT_DEBUG /* print errors, warnings, info messsages, and debug messages */
} cos_print_level_t;

#ifndef PRINT_LEVEL_MAX
#define PRINT_LEVEL_MAX 3
#endif
#define PRINT_LEVEL_COUNT 4

extern cos_print_level_t cos_print_level;
extern int cos_print_lvl_str;
extern const char *cos_print_str[];

/* Prints with current spdid and the thdid */
#define PRINTC(format, ...) printc("%lu,%u=> " format, cos_spd_id(), cos_thdid(), ## __VA_ARGS__)

/* Prints only if @level is <= cos_print_level */
#define PRINTLOG(level, format, ...) \
{ \
Expand All @@ -63,4 +63,21 @@ extern const char *cos_print_str[];
} \
}

#define PRINT_LOG PRINTLOG

static void
log_bytes(cos_print_level_t level, char *message, char *bytes, size_t bytes_count)
{
if (level <= cos_print_level) {
size_t i;

PRINT_LOG(level, "%s [ ", message);
for (i = 0; i < bytes_count; i++) {
printc("%X ", bytes[i]);
}
printc("]\n");
}
}


#endif /* LLPRINT_H */
4 changes: 3 additions & 1 deletion src/components/interface/cFE/stubs/c_stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -663,8 +663,10 @@ CFE_TBL_Register(CFE_TBL_Handle_t *TblHandlePtr, const char *Name, uint32 TblSiz

result = emu_CFE_TBL_Register(spdid);
if (result == CFE_SUCCESS || result == CFE_TBL_INFO_RECOVERED_TBL) {
table_info[shared_region->cfe_tbl_register.TblHandle].size = TblSize;
assert(TblSize <= EMU_TBL_BUF_SIZE);

table_info[shared_region->cfe_tbl_register.TblHandle].size = TblSize;
*TblHandlePtr = shared_region->cfe_tbl_register.TblHandle;
}

return result;
Expand Down
9 changes: 5 additions & 4 deletions src/components/lib/cos_component.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,11 @@ cos_thd_entry_static(u32_t idx)
return 0;
}

const char *cos_print_str[PRINT_LEVEL_MAX] = {
"ERR:",
"WARN:",
"DBG:",
const char *cos_print_str[PRINT_LEVEL_COUNT] = {
"ERR: ",
"WARN: ",
"INFO: ",
"DBG: ",
};

cos_print_level_t cos_print_level = PRINT_ERROR;
Expand Down

0 comments on commit caf490c

Please sign in to comment.