Skip to content

Commit

Permalink
Merge pull request #266 from VisorFolks/bugfix/akashkollipara/status_…
Browse files Browse the repository at this point in the history
…codes

Bugfix/akashkollipara/status codes
  • Loading branch information
akashkollipara authored Jan 3, 2024
2 parents a237aca + 23db466 commit e725432
Show file tree
Hide file tree
Showing 14 changed files with 135 additions and 135 deletions.
1 change: 1 addition & 0 deletions src/arch/riscv/32/i/terravisor/arch.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ void arch_di_save_state(istate_t *istate)
void arch_ei_restore_state(istate_t *istate)
{
asm volatile("csrs mie, %0" : : "r" (*istate));
arch_ei();
}

static cpu_sleep_t sleep_flag[N_CORES];
Expand Down
2 changes: 1 addition & 1 deletion src/driver/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ status_t driver_register(device_t *dev _UNUSED)

ret = dev->driver_setup();
(ret == success) ? syslog(pass, "Started %s\n", dev->name) :
syslog(fail, "Couldn't start %s (Err: -%p)\n", dev->name, -ret);
syslog(fail, "Couldn't start %s (Err: %p)\n", dev->name, ret);
exit:
return ret;
}
Expand Down
3 changes: 1 addition & 2 deletions src/driver/interrupt/plic/plic.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ static bool plic_get_pending(uint32_t irq_id)

static void plic_register_irq_handler(uint32_t id, void (* handler)(void))
{
assert(id);
assert(handler);
RET_ON_FAIL(id && handler,);
plic_irq_handler[id] = handler;
arch_dsb();
}
Expand Down
32 changes: 11 additions & 21 deletions src/driver/sysclk/sysclk_prci/sysclk_prci.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ static status_t sysclk_setup()
istate_t ist;

sysclk = (sysclk_port_t *)malloc(sizeof(sysclk_port_t));
if(!sysclk)
return error_memory_low;

RET_ON_FAIL(sysclk, error_memory_low);

port = sysclk;

arch_visor_call(fetch_dp, clock, 0, 0, &vres);
Expand Down Expand Up @@ -84,10 +85,8 @@ static status_t sysclk_disable()
istate_t ist;
sysclk_port_t *port = sysclk;

if(!port)
return error_driver_init_failed;

assert(port->baddr && port->base_clk);
RET_ON_FAIL(port && port->baddr && port->base_clk,
error_driver_data);

lock_acquire(&sysclk_key);
arch_di_save_state(&ist);
Expand All @@ -111,10 +110,9 @@ status_t sysclk_reset()
status_t ret;
sysclk_port_t *port = sysclk;
istate_t ist;
if(!port)
return error_driver_init_failed;

assert(port->baddr && port->base_clk);
RET_ON_FAIL(port && port->baddr && port->base_clk,
error_driver_data);

lock_acquire(&sysclk_key);
arch_di_save_state(&ist);
Expand All @@ -136,8 +134,6 @@ static inline void sysclk_set_internal(unsigned int clk _UNUSED)
{
status_t ret;
sysclk_port_t *port = sysclk;
if(!port)
return;
ret = prci_hfxocs_enable(port);
prci_pll_bypass(port);
ret |= prci_hfosc_enable(port);
Expand All @@ -155,8 +151,6 @@ static inline void sysclk_set_external(void)
{
status_t ret;
sysclk_port_t *port = sysclk;
if(!port)
return;
ret = prci_hfosc_enable(port);
ret |= prci_hfxocs_enable(port);
prci_pll_select_xosc(port);
Expand All @@ -172,8 +166,6 @@ static inline void sysclk_set_pll(unsigned int clk)
{
status_t ret;
sysclk_port_t *port = sysclk;
if(!port)
return;
ret = prci_hfosc_enable(port);
ret |= prci_hfxocs_enable(port);
prci_pll_bypass(port);
Expand All @@ -193,10 +185,9 @@ static void sysclk_configure_clk(call_arg_t a0, call_arg_t a1, call_arg_t a2 _UN
istate_t ist;
clock_type_t type = (clock_type_t) a0;
unsigned int clk = (unsigned int) a1;
if(!port)
return;

assert(port->baddr && port->base_clk);
ret->status = error_inval_pointer;
RET_ON_FAIL(port && port->baddr && port->base_clk,);

ret->p = 0;
ret->size = 0;
Expand Down Expand Up @@ -239,10 +230,9 @@ static void sysclk_get_freq(call_arg_t a0 _UNUSED, call_arg_t a1 _UNUSED,
sysclk_port_t *port = sysclk;
istate_t ist;
unsigned int getclk;
if(!port)
return;

assert(port->baddr && port->base_clk);
ret->status = error_inval_pointer;
RET_ON_FAIL(port && port->baddr && port->base_clk,);

lock_acquire(&sysclk_key);
arch_di_save_state(&ist);
Expand Down
113 changes: 59 additions & 54 deletions src/include/status.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,74 +16,79 @@

typedef enum status
{
success = 0x0000,
success = 0x0000,
/* Generic error */
error_generic = -0x0001,
error_func_inval = -0x0002,
error_func_inval_arg = -0x0003,
error_overflow = -0x0004,
error_generic = 0x0001,
error_func_inval = 0x0002,
error_func_inval_arg = 0x0003,
error_overflow = 0x0004,
error_inval_pointer = 0x0005,
/* Driver related error */
error_driver = -0x0100,
error_driver_init_done = -0x0101,
error_driver_init_failed = -0x0102,
error_driver_busy = -0x0103,
error_driver_data = -0x0104,
error_driver = 0x0100,
error_driver_init_done = 0x0101,
error_driver_init_failed = 0x0102,
error_driver_busy = 0x0103,
error_driver_data = 0x0104,
/* Device related error */
error_device = -0x0200,
error_device_id_inval = -0x0201,
error_device_inval = -0x0202,
error_device_busy = -0x0203,
error_device = 0x0200,
error_device_id_inval = 0x0201,
error_device_inval = 0x0202,
error_device_busy = 0x0203,
/* Visor Call related error */
error_vcall = -0x0300,
error_vcall_code_inval = -0x0301,
error_vcall = 0x0300,
error_vcall_code_inval = 0x0301,
/* Memory related error */
error_memory = -0x0600,
error_memory_low = -0x0601,
error_memory = 0x0600,
error_memory_low = 0x0601,
/* File related error */
error_file = -0x0700,
error_file_desc = -0x0701,
error_file_exist = -0x0702,
error_file_not_found = -0x0703,
error_file_no_space = -0x0704,
error_file_long_name = -0x0705,
error_file_io = -0x0706,
error_file = 0x0700,
error_file_desc = 0x0701,
error_file_exist = 0x0702,
error_file_not_found = 0x0703,
error_file_no_space = 0x0704,
error_file_long_name = 0x0705,
error_file_io = 0x0706,
/* String related error */
error_string = -0x0800,
error_string = 0x0800,
/* Math related error */
error_math = -0x0900,
error_math_inval_arg = -0x0901,
error_math_large_val = -0x0902,
error_math = 0x0900,
error_math_inval_arg = 0x0901,
error_math_large_val = 0x0902,
/* Access related error */
error_access = -0x0a00,
error_access = 0x0a00,
/* System related error */
error_system = -0x0b00,
error_system_irq_link_fail = -0x0b01,
error_system_irq_unlink_fail = -0x0b02,
error_system_clk_caliberation = -0x0b03,
error_system_prog_fail = -0x0b04,
error_system = 0x0b00,
error_system_irq_link_fail = 0x0b01,
error_system_irq_unlink_fail = 0x0b02,
error_system_clk_caliberation = 0x0b03,
error_system_prog_fail = 0x0b04,
error_system_inval_cpu = 0x0b05,
/* Network related error */
error_net = -0x0c00,
error_net_con_timeout = -0x0c01,
error_net = 0x0c00,
error_net_con_timeout = 0x0c01,
/* User space related error */
error_user = -0x0d00,
error_user = 0x0d00,
/* IO related error */
error_io = -0x0e00,
error_io = 0x0e00,
/* OS related error */
error_os = -0x0f00,
error_os_task_overfow = -0x0f01,
error_os_deadlock = -0x0f02,
error_os_invalid_op = -0x0f03,
error_os_sem_get = -0x0f04,
error_os_panic_presched_cb_null = -0x0f05,
error_os_panic_sched_algo_null = -0x0f06,
error_os_panic_os_start_fail = -0x0f07,
error_os_mutex_lock = -0x0f08,
error_os_mutex_unlock = -0x0f09,
error_os = 0x0f00,
error_os_task_overfow = 0x0f01,
error_os_deadlock = 0x0f02,
error_os_invalid_op = 0x0f03,
error_os_sem_get = 0x0f04,
error_os_panic_presched_cb_null = 0x0f05,
error_os_panic_sched_algo_null = 0x0f06,
error_os_panic_os_start_fail = 0x0f07,
error_os_mutex_lock = 0x0f08,
error_os_mutex_unlock = 0x0f09,
/* Mesg related error */
error_mesg = -0x1000,
error_mesg_long = -0x1001,
error_mesg = 0x1000,
error_mesg_long = 0x1001,
/* List related error */
error_list = -0x1100,
error_list_node_exists = -0x1101,
error_list_node_not_found = -0x1102,
error_list = 0x1100,
error_list_node_exists = 0x1101,
error_list_node_not_found = 0x1102,
} status_t;

#define STATUS_CHECK_POINTER(x) RET_ON_FAIL(x, error_inval_pointer)
#define STATUS_CHECK_COREID(x) RET_ON_FAIL((x < N_CORES), error_system_inval_cpu)
14 changes: 7 additions & 7 deletions src/platform/mega_avr/common/hal/adc/adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ static inline status_t _adc_config_vref(adc_port_t *port, adc_ref_t vref)
status_t adc_setup(adc_port_t *port)
{
status_t ret = success;
assert(port);
STATUS_CHECK_POINTER(port);
ret |= platform_clk_en(port->clk_id);
_adc_enable(port);
ret |= _adc_set_prescaler(port);
Expand All @@ -132,7 +132,7 @@ status_t adc_setup(adc_port_t *port)
status_t adc_shutdown(adc_port_t *port)
{
status_t ret = success;
assert(port);
STATUS_CHECK_POINTER(port);
ret |= adc_int_dis(port);
_adc_disable(port);
ret |= platform_clk_dis(port->clk_id);
Expand All @@ -149,22 +149,22 @@ bool adc_busy(adc_port_t *port)

status_t adc_int_en(adc_port_t *port)
{
assert(port);
STATUS_CHECK_POINTER(port);
MMIO8(port->baddr + ADCSRA_OFFSET) |= (1 << ADIE);
return success;
}

status_t adc_int_dis(adc_port_t *port)
{
assert(port);
STATUS_CHECK_POINTER(port);
MMIO8(port->baddr + ADCSRA_OFFSET) &= ~(1 << ADIE);
return success;
}

status_t adc_config_pin(adc_port_t *port, uint8_t pin, adc_trig_t trigger, uint8_t resolution, adc_ref_t vref)
{
status_t ret = success;
assert(port);
STATUS_CHECK_POINTER(port);
if(pin > N_ADC_PINS)
return error_func_inval_arg;
ret |= _adc_config_vref(port, vref);
Expand All @@ -178,8 +178,8 @@ status_t adc_config_pin(adc_port_t *port, uint8_t pin, adc_trig_t trigger, uint8
status_t adc_read(adc_port_t *port, uint16_t *adc_val)
{
status_t ret = success;
assert(port);
assert(adc_val);
STATUS_CHECK_POINTER(port);
STATUS_CHECK_POINTER(adc_val);
if(MMIO8(port->baddr + ADMUX_OFFSET) & (1 << ADLAR))
{
*adc_val = MMIO8(port->baddr + ADCH_OFFSET);
Expand Down
Loading

0 comments on commit e725432

Please sign in to comment.