// init one call void light_init(void) { dbg_printf("Initializing LIGHT..."); pin_on(OPIN_TR_EN );//включить выходные регистры LIGHT_STA=LIGHT_WORK;// machine stat light_machine.work = FALSE; // stop machine // setStatusRestart(true);// перезагрузка // BOOL is_init; dk_num=0; // GREEN_PORT_CONF = 0; RED_PORT_CONF = 0; YEL_PORT_CONF = 0; // for (int i_dk=0; i_dk<DK_N; i_dk++) { CUR_DK = i_dk; for (int i_try=0; i_try<3; i_try++) { is_init = ligh_load_init(2-i_try); if (is_init) { dk_num++; break; } } // if (!is_init) break; } if (dk_num) light_machine.work = TRUE; // start machine /*create event*/ if (tn_event_create(&g_light_evt, TN_EVENT_ATTR_SINGLE | TN_EVENT_ATTR_CLR, 0) != TERR_NO_ERR){ dbg_puts("tn_event_create(&g_light_evt) error"); dbg_trace(); tn_halt(); } /*create task_light_func*/ if (tn_task_create(&task_light_tcb, &task_light_func, TASK_LIGHT_PRI, &task_light_stk[TASK_LIGHT_STK_SZ - 1], TASK_LIGHT_STK_SZ, 0, TN_TASK_START_ON_CREATION) != TERR_NO_ERR){ dbg_puts("tn_task_create(&task_light_tcb) error"); dbg_trace(); tn_halt(); } dbg_puts("[done]"); }
void hw_timer0a_init(TN_EVENT* evt, unsigned evt_pattern) { if (evt == NULL || evt_pattern == 0) { dbg_puts("evt == NULL || evt_pattern == 0"); dbg_trace(); tn_halt(); } g_timer0a_evt = evt; g_timer0a_evt_pattern = evt_pattern; // TIMER_0_A32 MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); MAP_SysCtlPeripheralReset(SYSCTL_PERIPH_TIMER0); MAP_TimerDisable(TIMER0_BASE, TIMER_A); MAP_TimerConfigure(TIMER0_BASE, TIMER_CFG_32_BIT_PER); // periodic mode MAP_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); //MAP_IntPrioritySet(INT_TIMER0A, 0); // 0 - max pri 7 - min pri MAP_IntEnable(INT_TIMER0A); /* MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER3); MAP_TimerDisable(TIMER3_BASE, TIMER_A); MAP_TimerConfigure(TIMER3_BASE, TIMER_CFG_32_BIT_OS); MAP_TimerEnable(TIMER3_BASE, TIMER_A); */ }
/*-----------------------Start system-----------------------------------------*/ void tn_app_init() { tn_cpu_int_disable(); // прерывания включаются обратно после выхода из tn_app_init(); // start startup(); // for static IP struct ip_addr ipaddr = { pref_get_long(PREF_L_NET_IP) }; struct ip_addr netmask = { pref_get_long(PREF_L_NET_MSK) }; struct ip_addr gw = { pref_get_long(PREF_L_NET_GW) }; //ip_addr_debug_print(buf, ipaddr); ethernet_init((enum net_mode)pref_get_long(PREF_L_NET_MODE), &ipaddr, &netmask, &gw); cmd_ch_init(); // init cmd for ethernet // creat task_leds_func if (tn_task_create(&task_leds_tcb, &task_leds_func, TASK_LEDS_PRI, &task_leds_stk[TASK_LEDS_STK_SZ - 1], TASK_LEDS_STK_SZ, 0, TN_TASK_START_ON_CREATION) != TERR_NO_ERR) { dbg_puts("tn_task_create(&task_leds_tcb) error"); goto err; } //time_init=true; return; err: dbg_trace(); tn_halt(); }
void fault_print(unsigned int * hardfault_args) { unsigned int stacked_r0; unsigned int stacked_r1; unsigned int stacked_r2; unsigned int stacked_r3; unsigned int stacked_r12; unsigned int stacked_lr; unsigned int stacked_pc; unsigned int stacked_psr; stacked_r0 = ((unsigned long) hardfault_args[0]); stacked_r1 = ((unsigned long) hardfault_args[1]); stacked_r2 = ((unsigned long) hardfault_args[2]); stacked_r3 = ((unsigned long) hardfault_args[3]); stacked_r12 = ((unsigned long) hardfault_args[4]); stacked_lr = ((unsigned long) hardfault_args[5]); stacked_pc = ((unsigned long) hardfault_args[6]); stacked_psr = ((unsigned long) hardfault_args[7]); dbg_puts ("\n\n[Hard fault handler]\n"); dbg_printf ("R0 = %x\n", stacked_r0); dbg_printf ("R1 = %x\n", stacked_r1); dbg_printf ("R2 = %x\n", stacked_r2); dbg_printf ("R3 = %x\n", stacked_r3); dbg_printf ("R12 = %x\n", stacked_r12); dbg_printf ("LR [R14] = %x subroutine call return address\n", stacked_lr); dbg_printf ("PC [R15] = %x program counter\n", stacked_pc); dbg_printf ("PSR = %x\n", stacked_psr); tn_halt(); }
void hw_timer0a_set_timeout(unsigned long uS) { #ifdef DEBUG if (uS > 1000000) { dbg_puts("uS > 1000000"); dbg_trace(); tn_halt(); } #endif // DEBUG MAP_TimerLoadSet(TIMER0_BASE, TIMER_A, MAP_SysCtlClockGet() / 1000000 * uS); }
void hw_timer1a_start_once(unsigned long uS) { #ifdef DEBUG if (uS > 1000000) { dbg_puts("uS > 1000000"); dbg_trace(); tn_halt(); } #endif // DEBUG MAP_TimerLoadSet(TIMER1_BASE, TIMER_A, MAP_SysCtlClockGet() / 1000000 * uS); MAP_TimerEnable(TIMER1_BASE, TIMER_A); }
void GPS_init() { dbg_printf("Initializing GPS module..."); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART); MAP_GPIOPinConfigure(GPIO_PA0_U0RX); MAP_GPIOPinConfigure(GPIO_PA1_U0TX); MAP_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); MAP_UARTConfigSetExpClk(UART_BASE, MAP_SysCtlClockGet(), UART_SPEED, UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE); MAP_UARTDisable(UART_BASE); MAP_UARTTxIntModeSet(UART_BASE, UART_TXINT_MODE_EOT); MAP_UARTIntEnable(UART_BASE, UART_INT_RX | UART_INT_TX); MAP_IntEnable(INT_UART); MAP_UARTEnable(UART_BASE); MAP_UARTFIFODisable(UART_BASE); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG); // MAP_IntEnable(INT_GPIOG); // Настроить прерывания на PPS MAP_GPIOIntTypeSet(GPIO_PORTG_BASE, GPIO_PIN_7, GPIO_FALLING_EDGE); MAP_GPIOPinIntEnable(GPIO_PORTG_BASE, GPIO_PIN_7); // if (tn_task_create(&task_GPS_tcb, &task_GPS_func, TASK_GPS_PRI, &task_GPS_stk[TASK_GPS_STK_SZ - 1], TASK_GPS_STK_SZ, 0, TN_TASK_START_ON_CREATION) != TERR_NO_ERR) { dbg_puts("tn_task_create(&task_GPS_tcb) error"); goto err; } // Настроить прерывания на PPS //MAP_IntEnable(INT_GPIOG); //MAP_GPIOIntTypeSet(GPIO_PORTG_BASE, GPIO_PIN_7, GPIO_FALLING_EDGE); //MAP_GPIOPinIntEnable(GPIO_PORTG_BASE, GPIO_PIN_7); dbg_puts("[done]"); return; err: dbg_trace(); tn_halt(); }
void __error__(char *pcFilename, unsigned long ulLine) { dbg_printf("__error__(\"%s\", ln=%u);\n", pcFilename, ulLine); tn_halt(); }
void tn_default_int_handler() { dbg_puts("default interrupt"); tn_halt(); }
void tn_nmi_int_handler() { dbg_puts("NMI interrupt"); tn_halt(); }