|
| 1 | +#include "ina230.h" |
| 2 | +#include "obc_sci_io.h" |
| 3 | +#include "obc_i2c_io.h" |
| 4 | +#include "obc_print.h" |
| 5 | +#include "obc_board_config.h" |
| 6 | + |
| 7 | +#include <sci.h> |
| 8 | +#include <stdio.h> |
| 9 | +#include <gio.h> |
| 10 | +#include <FreeRTOS.h> |
| 11 | +#include <os_task.h> |
| 12 | + |
| 13 | +#include <sys_common.h> |
| 14 | +#include <sys_core.h> |
| 15 | + |
| 16 | +static StaticTask_t taskBuffer; |
| 17 | +static StackType_t taskStack[1024]; |
| 18 | + |
| 19 | +void vTaskCode(void* pvParameters) { |
| 20 | + float num = 100; |
| 21 | + obc_error_code_t errCode = 0; |
| 22 | + while (1) { |
| 23 | + errCode = getINA230ShuntVoltage(INA230_DEVICE_ONE, &num); |
| 24 | + if (errCode != OBC_ERR_CODE_SUCCESS) { |
| 25 | + sciPrintf("Error Reading Shunt Voltage - %d\r\n", (int)errCode); |
| 26 | + } else { |
| 27 | + sciPrintf("Shunt Voltage - %f\r\n", num); |
| 28 | + } |
| 29 | + |
| 30 | + errCode = getINA230Current(INA230_DEVICE_ONE, &num); |
| 31 | + if (errCode != OBC_ERR_CODE_SUCCESS) { |
| 32 | + sciPrintf("Error Reading Current - %d\r\n", (int)errCode); |
| 33 | + } else { |
| 34 | + sciPrintf("Current - %f\r\n", num); |
| 35 | + } |
| 36 | + |
| 37 | + errCode = getINA230BusVoltage(INA230_DEVICE_ONE, &num); |
| 38 | + if (errCode != OBC_ERR_CODE_SUCCESS) { |
| 39 | + sciPrintf("Error Reading Bus Voltage - %d\r\n", (int)errCode); |
| 40 | + } else { |
| 41 | + sciPrintf("Bus Voltage - %f\r\n", num); |
| 42 | + } |
| 43 | + |
| 44 | + errCode = getINA230Power(INA230_DEVICE_ONE, &num); |
| 45 | + if (errCode != OBC_ERR_CODE_SUCCESS) { |
| 46 | + sciPrintf("Error Reading Power - %d\r\n", (int)errCode); |
| 47 | + } else { |
| 48 | + sciPrintf("Power - %f\r\n", num); |
| 49 | + } |
| 50 | + gioToggleBit(STATE_MGR_DEBUG_LED_GIO_PORT, STATE_MGR_DEBUG_LED_GIO_BIT); |
| 51 | + |
| 52 | + // Simple delay. |
| 53 | + vTaskDelay(pdMS_TO_TICKS(1000)); |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | +int main(void) { |
| 58 | + // Run hardware initialization code |
| 59 | + gioInit(); |
| 60 | + sciInit(); |
| 61 | + i2cInit(); |
| 62 | + |
| 63 | + sciEnableNotification(UART_PRINT_REG, SCI_RX_INT); |
| 64 | + |
| 65 | + _enable_interrupt_(); |
| 66 | + |
| 67 | + // Initialize bus mutexes |
| 68 | + initSciPrint(); |
| 69 | + initI2CMutex(); |
| 70 | + initINA230(); |
| 71 | + |
| 72 | + // Assume all tasks are created correctly |
| 73 | + xTaskCreateStatic(vTaskCode, "Demo", 1024, NULL, 1, taskStack, &taskBuffer); |
| 74 | + |
| 75 | + vTaskStartScheduler(); |
| 76 | +} |
0 commit comments