void taskExecuter(void *param) { printf(">>[Executer] Started\n"); ExeCmd RunCmd; int cmdStat, queueStat, cmdParam; while(1) { /* Read the CMD that Dispatcher sent - BLOCKING */ queueStat = xQueueReceive(executerCmdQueue, &RunCmd, portMAX_DELAY); if(queueStat == pdPASS) { printf("[Executer] Running a command...\n"); /* Commands may take a long time, so reset the WDT */ ClrWdt(); /* Execute the command */ cmdParam = RunCmd.param; cmdStat = RunCmd.fnct((void *)&cmdParam); /* Commands may take a long time, so reset the WDT */ ClrWdt(); printf("[Executer] Command result: %d\n", cmdStat); /* Send the result to Dispatcher - BLOCKING */ xQueueSend(executerStatQueue, &cmdStat, portMAX_DELAY); } } }
// Sleep mode - External peripherals all allowed to run unless specified void SystemPwrSave(unsigned short NapSetting) { //KL WARNING - modified for simpler behaviour, manage your own interrupt wake sources uint16_t IPLshadow; // Interrupt context saving IPLshadow = SRbits.IPL; SRbits.IPL = 0b111; // Stop all interrupts from vectoring /*Note: Add/remove power down settings as needed*/ U1PWRCbits.USBPWR = 0; // MCHP Bug, not cleared in usb detach +120uA // Wdt if (NapSetting & WAKE_ON_WDT) {ClrWdt();RCONbits.SWDTEN = 1;} // Turn on WDT // Go to sleep... zzzzzzzzzzzzzz if(NapSetting & LOWER_PWR_SLOWER_WAKE) RCONbits.PMSLP = 0; else RCONbits.PMSLP = 1; Sleep(); __builtin_nop(); // ON RETURN FROM SLEEP if (NapSetting & WAKE_ON_WDT) {ClrWdt();RCONbits.SWDTEN = 0;} // Turn off WDT SRbits.IPL = IPLshadow; // Effectively re-enable ints - will vector if flags are set! return ; }
void drp_debug5(void){ int value=0, res=0; unsigned int index; printf("dat_reset_Payload_Buff()..\n"); int pay_i; int lenBuff=10, r_nextIndx, r_MaxIndx; for(pay_i=0; pay_i<dat_pay_last_one; pay_i++, lenBuff=lenBuff+1){ printf(" writing: "); dat_reset_Payload_Buff(pay_i, lenBuff, 0); printf(" dat_reset_Payload_Buff(%d, %d)\r\n", pay_i, lenBuff); printf(" reading: "); r_nextIndx = dat_get_NextPayIndx(pay_i); printf(" dat_get_NextPayIndx(%u) = %d | ", pay_i, r_nextIndx); r_MaxIndx = dat_get_MaxPayIndx(pay_i); printf(" dat_get_MaxPayIndx(%u) = %d | \n", pay_i, r_MaxIndx); printf(" comparing: "); if( r_nextIndx==0 && r_MaxIndx==(lenBuff-1) ){ printf("ok\n"); } else{ printf("fail\n"); return; } ClrWdt(); } printf("DAT_Payload_Buff..\n"); int maxind; BOOL st; for(pay_i=0; pay_i<dat_pay_last_one; pay_i++){ value=20000; st = TRUE; maxind = dat_get_MaxPayIndx(pay_i); for(index=0; st==TRUE; index++, value++){ printf(" writing: "); dat_set_Payload_Buff(pay_i, value, DAT_PAYBUFF_MODE_NO_MAXINDX); printf(" DAT_Payload_Buff[%u][%u] = %d | ",pay_i, index, value); printf("%d/%d [NextIndx/MaxIndx] | \n", dat_get_NextPayIndx(pay_i), dat_get_MaxPayIndx(pay_i) ); printf(" reading: "); dat_get_Payload_Buff(pay_i, index, &res); printf(" DAT_Payload_Buff[%u][%u] = %d | \n",pay_i, index, res); printf(" comparing: "); if( value==res ){ printf("ok\n"); } else{ printf("fail\n"); return; } if( dat_isFull_Payload_Buff(pay_i)==TRUE){ printf(" DAT_Payload_Buff[%u] esta lleno\r\n", pay_i); st = FALSE; } ClrWdt(); } printf("*******************************************\n"); } printf("End of drp_debug5\n"); }
/* *------------------------------------------------------------------------------ * void APP-task(void) *------------------------------------------------------------------------------ */ void APP_task(void) { UINT8 i,*ptr, data; UINT32 addr; UINT8 resetBuzzer = TRUE; ias.curAppTime = GetAppTime(); //Fetches the application time from timer driver if(ias.preAppTime != ias.curAppTime) { ias.preAppTime = ias.curAppTime; for(i = 0; i <MAX_ISSUES; i++) //check for timeout of issues raised { if(ias.issues[i].state == ISSUE_RAISED ) { ias.issues[i].timeout -= 1; ptr = (UINT8*)&ias.issues[i].timeout; data = *ptr; addr = (i*ISSUE_ENTRY_SIZE)+ISSUE_TIMEOUT; Write_b_eep((i*ISSUE_ENTRY_SIZE)+ISSUE_TIMEOUT, *ptr); Busy_eep(); ClrWdt(); data=*(ptr+1); addr = (i*ISSUE_ENTRY_SIZE)+ISSUE_TIMEOUT+1; Write_b_eep((i*ISSUE_ENTRY_SIZE)+ISSUE_TIMEOUT+1, *(ptr+1)); Busy_eep(); ClrWdt(); } } if(update_timeouts() == TRUE) { LAMP_RED = 1; if( ias.issues_raised == 0 ) { LAMP_YELLOW = 0; LAMP_GREEN = 0; } } if(ias.updateCount >= 5) { ias.updateCount = 0; update(); } } ++ias.updateCount; }
void APP_clearIssues() { UINT16 i; ias.state = ISSUE_RESOLVED; ias.issues_raised = 0; //No. of raised issues should be 0 initially ias.issues_critical = 0; //No. of critical issues should be 0 initially ias.preAppTime = 0; ias.curAppTime = 0; ias.openIssue = 0; log.index = 0; log.prevIndex = 0; for( i = 0 ; i < MAX_ISSUES; i++) { ias.issues[i].state = ISSUE_RESOLVED; ias.issues[i].timeout = 0; ias.issues[i].ackStatus = 0; memset(ias.issues[i].data , 0 , MAX_KEYPAD_ENTRIES + 1); ClrWdt(); } for(i = 0; i < (ISSUE_ENTRY_SIZE * MAX_ISSUES); i++) { Write_b_eep(i,0); Busy_eep(); ClrWdt(); } for( i = 1 ; i <= MAX_DEPARTMENTS ; i++) { ias.department_raised[i] = 0 ; } writeDeptRaise(); /* if( ias.logonStatus == 1 ) { updateIndication(1,0,0,0); } else updateIndication(0,0,0,0); */ }
void drp_debug3(void){ int value=0, res=0; unsigned int index; unsigned long block; con_printf("(Destructive) Testing -256block r/w- memSD\r\n"); for(block=0; block<1024; block=block+256){ printf("testing 256Block = %lu\n", block); value=20000; for(index=0; index<=0xFFFF; index++, value++){ con_printf("writing: "); msd_setVar_256BlockExtMem( block, index, value); printf("value[%u] = %d | ", index, value); printf("reading: "); msd_getVar_256BlockExtMem( block, index, &res); printf("value[%u] = %d | ", index, res); printf("comparing: "); if( value==res ){ printf("ok\n"); } else{ con_printf("fail\n"); return; } ClrWdt(); } } //drp_memSD_BlockErase(); }
void InitializeOS() { ClrWdt(); // High priority tasks that must be run all the time core_task = RegisterTask("Core", ProcessCore); core_task->state = tsRun; // Drawing, only needs to be run when screen is on draw_task = RegisterTask("Draw", DrawLoop); // Initialize button interrupts _CNIEn(BTN1_CN) = 1; _CNIEn(BTN2_CN) = 1; _CNIEn(BTN3_CN) = 1; _CNIEn(BTN4_CN) = 1; cn_register_cb(_CNIDX(BTN1_CN), _PINREF(BTN1), OnBTN1Change); cn_register_cb(_CNIDX(BTN2_CN), _PINREF(BTN2), OnBTN2Change); cn_register_cb(_CNIDX(BTN3_CN), _PINREF(BTN3), OnBTN3Change); cn_register_cb(_CNIDX(BTN4_CN), _PINREF(BTN4), OnBTN4Change); uint i; for (i=1; i<=4; i++) { btn_debounce_tick[i] = 0; btn_state[i] = 0; } }
//*************************************************************************** // Main() - Main Routine //*************************************************************************** void main(){ OSCCON = 0xF0; //Initialitation of Internal Oscillator OSCTUNEbits.PLLEN = 1; hardware_setup(); //Hardware initialization if ( !vscp_check_pstorage() ) // Check VSCP persistent storage and init_app_eeprom(); // restore if needed init_app_ram(); // Initialize data vscp_init(); // Initialize the VSCP functionality while(1){ //Handler scheduler ClrWdt(); // Feed the dog if(timeEvent._10mS){ //10mS Event timeEvent._10mS = 0; vscp_10mS_Running(); hardware_10mS(); } if(timeEvent._100mS){ //100mS Event timeEvent._100mS = 0; vscp_100mS_Running(); vscp_ledActivity(); } if(timeEvent._1s){ //1second Event timeEvent._1s = 0; vscp_doOneSecondWork(); // Do VSCP one second jobs greenLed_pin = !greenLed_pin; } vscp_freeRunning(); //TODO: Handling the override event } }
void _ISR_PSV _U2TXInterrupt(void) { //InterruptTest5++; _U2TXIF = 0; // interrupt flag reset unsigned char debugTX; IFS1bits.U2TXIF = 0; // clear TX interrupt flag __builtin_disi(0x3FFF); //disable interrupts up to priority 6 for n cycles ClrWdt(); // [1] if(TxNByte_UART2) { debugTX = *TxPointer_UART2++; // Trasmette il carattere del buffer puntato da TxPointer U2TXREG = debugTX; TxNByte_UART2 = TxNByte_UART2 - 1; // TxNByte_UART2--; non pare funzionare } else { TxComplete[PORT_COM2] = TRUE; IEC1bits.U2TXIE = 0; // Disable Transmit Interrupts } DISICNT = 0; //re-enable interrupts //InterruptTest5--; }
void IAS_acknowledgeIssues(UINT8 ID) { UINT8 i; ias.issues[ID].ackStatus = 0; updateLog(ias.issues[ID].data); Write_b_eep((ID*ISSUE_ENTRY_SIZE)+ISSUE_ACKSTATUS, ias.issues[ID].ackStatus); Busy_eep(); ClrWdt(); //IAS_updateIssues(ias.issues[ID].data); for( i = 0 ; i < MAX_ISSUES ;i++) { if( ias.issues[i].ackStatus == 1) return; } BUZ_OP = 0; }
void _ISR_PSV _U2RXInterrupt(void) { // UART2 RX [6zb] //InterruptTest6++; __builtin_disi(0x3FFF); //disable interrupts up to priority 6 for n cycles _U2RXIF = 0; // interrupt flag reset ClrWdt(); // [1] unsigned char DatoRx; DatoRx = ReadUART2(); if(StatoSeriale[PORT_COM2] == WAIT_MESSAGE) { // time-out dei dati in ricezione non sia scaduto, altrimenti if (!TimerOutRxModbus[PORT_COM2]) { FreeRxBuffer(PORT_COM2); } TimerOutRxModbus[PORT_COM2] = TIME_OUT_MODBUS; *RxPointer[PORT_COM2] = DatoRx; // Salva nel buffer il dato ricevuto RxPointer[PORT_COM2]++; RxNByte[PORT_COM2]++; if (RxNByte[PORT_COM2] >= MODBUS_N_BYTE_RX) // se ricevuti più caratteri della lunghezza del buffer { RxPointer[PORT_COM2] = ModbusRxBuff[PORT_COM2]; // azzera il puntatore di ricezione RxNByte[PORT_COM2] = 0; // e il numero di byte ricevuti } } DISICNT = 0; //re-enable interrupts //InterruptTest6--; }
/************************************************** * Function name : void main(void) * * Created by : Luca Lucci * Date created : 07/10/12 * Description : Main program entry point * Notes : - **************************************************/ void main(void) { initialize_system(); // initialize usart uart_init(); uart2_open(); // initialize interrupt INTCON2bits.INTEDG0 = 0; // falling edge int0 interrupt INTCONbits.INT0IE = 1; // enable int0 interrupt INTCONbits.INT0IF = 0; INTCONbits.PEIE = 1; // enable peripheral interrupts INTCONbits.GIE = 1; // enable global interrupt while(1) { ClrWdt(); // if the buffer isn't empty will send back the data if(uart2_buffer_read(temp)) uart2_buffer_tx_load(temp); // ProcessIO } }//main()
/*--------------------------------------------------------------------------------------------------------------- * BOOL update_timeouts(void) *---------------------------------------------------------------------------------------------------------------- */ BOOL update_timeouts(void) { UINT8 i; BOOL result = FALSE; for(i = 0; i <MAX_ISSUES; i++) //check for timeout of issues raised { if(ias.issues[i].state == ISSUE_RAISED) { if(ias.issues[i].timeout == 0) { ias.issues_critical++; ias.issues_raised--; ias.issues[i].state = ISSUE_CRITICAL; Write_b_eep((i*ISSUE_ENTRY_SIZE)+ISSUE_STATE,ias.issues[i].state); Busy_eep(); ClrWdt(); ias.state = ISSUE_CRITICAL;//put up result = TRUE; } } } return result; }
void BootMain(void) #endif { //NOTE: The c018.o file is not included in the linker script for this project. //The C initialization code in the c018.c (comes with C18 compiler in the src directory) //file is instead modified and included here manually. This is done so as to provide //a more convenient entry method into the bootloader firmware. Ordinarily the _entry_scn //program code section starts at 0x00 and is created by the code of c018.o. However, //the linker will not work if there is more than one section of code trying to occupy 0x00. //Therefore, must not use the c018.o code, must instead manually include the useful code //here instead. //Make sure interrupts are disabled for this code (could still be on, //if the application firmware jumped into the bootloader via software methods) INTCON = 0x00; //Initialize the C stack pointer, and other compiler managed items as //normally done in the c018.c file (applicable when using C18 compiler) #ifndef __XC8__ _asm lfsr 1, _stack lfsr 2, _stack clrf TBLPTRU, 0 _endasm #endif //Clear the stack pointer, in case the user application jumped into //bootloader mode with excessive junk on the call stack STKPTR = 0x00; // End of the important parts of the C initializer. This bootloader firmware does not use // any C initialized user variables (idata memory sections). Therefore, the above is all // the initialization that is required. //Call other initialization code and (re)enable the USB module InitializeSystem(); //Some USB, I/O pins, and other initialization //Execute main loop while(1) { ClrWdt(); //Need to call USBDeviceTasks() periodically. This function takes care of //processing non-USB application related USB packets (ex: "Chapter 9" //packets associated with USB enumeration) USBDeviceTasks(); BlinkUSBStatus(); //When enabled, blinks LEDs on the board, based on USB bus state LowVoltageCheck(); //Regularly monitor voltage to make sure it is sufficient //for safe operation at full frequency and for erase/write //operations. ProcessIO(); //This is where all the actual bootloader related data transfer/self programming takes //place see ProcessIO() function in the BootPIC[xxxx].c file. }//end while }
/* switch to ADC chan 8 (shorted to ground) to reset ADC measurement cap to zero before next measurement */ void ADC_zero(void) { ClrWdt(); // reset the WDT timer SetChanADC(ADC_CH8); // F3 grounded input Delay10TCYx(ADC_CHAN_DELAY); ConvertADC(); while (BusyADC()); }
void DisplayBootScreen() { byte y = 8; char s[10]; byte x; uint32 i; ClrWdt(); ClearImage(); ClrWdt(); BootPrintln("OLED Watch v1.0"); //DrawString("Booting...", 8, y, WHITE); y += 10; for (i=0; i<1000000; i++) { ClrWdt(); } }
int main() { DWORD t = 0; //Needed because a bug in picc-18? MIWRL=0; MIWRH=0; TRISA = 0; TRISB = 0; TRISC = 0; TRISD = 0; TRISE = 0; TRISF = 0; TRISG = 0; PORTA=0; PORTB=0; PORTC=0; PORTD=0; PORTE=0; PORTF=0; OSCTUNE = 0x40; //Speed up to 41.67 MHz //Turn off AD ADCON1 = 0x0F; #if defined(DEBUG) && defined(_18F87J60) initUsart2(); #endif initTransmitter(); initReceiver(); initPwm(); initInterrupts(); initAppConfig(); initWDT(); TickInit(); StackInit(); //Set the LED on the connector SetLEDConfig(0x3742); //See MAC.h for the values printf("Telldus TellStick Net v%s\r\n", FIRMWARE_VERSION); while(1) { StackTask(); StackApplications(); if(TickGet() - t >= TICK_SECOND) { t = TickGet(); } #if defined(DEBUG) debugTask(); #endif rfReceiveTask(); discoveryTask(); ClrWdt(); } return 42; }
void dumpHandler() { u8 ii; isError = 1; switch(test_pos_now) { case TEST_CHANNEL_1: OPEN_CHANNEL_1();LED1_R_ON();break; case TEST_CHANNEL_2: OPEN_CHANNEL_2();LED2_R_ON();break; case TEST_CHANNEL_3: OPEN_CHANNEL_3();LED3_R_ON();break; case TEST_CHANNEL_4: OPEN_CHANNEL_4();LED4_R_ON();break; default: dumpHandler();break; } return; for(ii=0; ii <= 3; ii++) { if(stepNow & (1<<ii)) LED_ON(ii); else LED_OFF(ii); } while(1) { NOP(); ClrWdt(); } LED1_R_ON(); LED2_R_ON(); LED3_R_ON(); LED4_R_ON(); while(1) { NOP(); ClrWdt(); } }
void delay_ms(u16 nus) { unsigned int i , j; for(i=0;i<nus;i++) { ClrWdt(); for(j=0;j<1000;j++); } }
void lcd_send_byte( unsigned char address, unsigned char n ) { PIN_LCD_RS = 0; LCD_DELAY(); PIN_LCD_RS = address; ClrWdt(); PIN_LCD_E = 0; lcd_send_nibble(n >> 4); lcd_send_nibble(n & 0xf); }
/*---------------------------------------------- Store department riase vlaue to EEPROM ------------------------------------------------*/ void writeDeptRaise(void) { UINT8 i; for( i = 0; i < MAX_DEPARTMENTS ;i++) { Write_b_eep(DEPARTMENT_RAISE_ADD + i ,ias.department_raised[i+1] ); Busy_eep(); ClrWdt(); } }
void U1SetBaudrate(uint32_t baudrate) { while (!U1TxReady()) ClrWdt(); // wait for buffer to flush TXSTA1bits.SYNC = 0; // Asynchronous TXSTA1bits.BRGH = 1; // High speed BAUDCONbits.BRG16 = 1; // 16-Bit Baud Rate Register uint16_t baud = _XTAL_FREQ / (4 * (baudrate + 1)); SPBRG = baud & 0xFF; SPBRGH = baud >> 8; uart1BaudSetting = baudrate; }
void main () { TRISB = 0b11111001; TRISCbits.TRISC6 = 0; // Gobally disable IRQs INTCONbits.GIE = 0; // init USART peripheral RCSTAbits.SPEN = 1; // baud rate to 115200 Baud SPBRG = 6; // enable TX + high speed mode TXSTA = 0b00100100; // light red LED to indicate dump process LED_RED = 0; LED_GREEN = 1; EEADR = 0; EECON1bits.CFGS = 0; EECON1bits.EEPGD = 0; do { EECON1bits.RD = 1; TXREG = EEDATA; EEADR++; while (!TXSTAbits.TRMT); ClrWdt (); } while (EEADR); // turn off red LED // light green LED to indicate stopped dump process LED_RED = 1; LED_GREEN = 0; // sit there idle for (;;) ClrWdt (); }
void APP_raiseIssues(far UINT8* data) { UINT8 i,j,issueIndex; UINT8 *ptr; for(i = 0; i < MAX_ISSUES; i++) //for each issue if(ias.issues[i].state != ISSUE_RESOLVED ) //if it is raised if(strcmp((INT8*)data,(INT8 *)ias.issues[i].data) == 0) //if input matches return; //do nothing for( i = 0 ; i < MAX_ISSUES ;i++) { if( ias.issues[i].state == ISSUE_RESOLVED ) { ias.issues[i].state = ISSUE_RAISED; ias.issues[i].timeout = timeout; ias.issues[i].ackStatus = 1; strcpy((INT8*) ias.issues[i].data, (INT8*)data); ptr = (UINT8*)&ias.issues[i]; for(j = 0; j < ISSUE_ENTRY_SIZE; j++) { Write_b_eep(j+(i*ISSUE_ENTRY_SIZE),*(ptr+j)); Busy_eep(); ClrWdt(); } ias.issues_raised++; if(ias.issues_critical == 0) { if( ias.mutualAid == 1 ) updateIndication(-1,1,0,0); else updateIndication(0,1,0,0); } else { if( ias.mutualAid == 1) updateIndication(-1,1,1,0); else updateIndication(0,1,1,0); } updateLog(data); break; } } if( ias.issues_critical == 0 ) ias.state = ISSUE_RAISED; }
/*---------------------------------------------- Store department riase vlaue from EEPROM ------------------------------------------------*/ void readDeptRaise(void) { UINT8 i; for( i = 0; i < MAX_DEPARTMENTS ;i++) { ias.department_raised[i+1] = Read_b_eep( DEPARTMENT_RAISE_ADD + i ); Busy_eep(); ClrWdt(); } }
void IoWait(unsigned int Micros) { int micros; // Pre : Micros és positiu // Post: Espera el nombre de microsegons especificat. NO ES COOPERATIVA // i per tant s'ha d'usar amb molta precaució. Esta afinada per a un clock de 8M micros=Micros>>1; while(micros!=0) { ClrWdt(); --micros; Nop(); Nop(); Nop(); } }
void vApplicationIdleHook(void) { /* * **configUSE_IDLE_HOOK must be set to 1** * Esta funcion se ejecuta cuando el procesador * no esta siendo utilizado por otra tarea */ ClrWdt(); Idle(); }
void U2SetBaudrate(uint32_t baudrate) { while (!U2TxReady()) ClrWdt(); // wait for buffer to flush TXSTA2bits.SYNC = 0; // Asynchronous TXSTA2bits.BRGH = 1; // High speed BAUDCON2bits.BRG16 = 1; // 16-Bit Baud Rate Register uint16_t baud = _XTAL_FREQ / (4 * (baudrate + 1)); SPBRG2 = baud & 0xFF; // SPBRG 416 --> baud 38400 SPBRGH2 = baud >> 8; // SPRGB 138 --> baud 115200 uart2BaudSetting = baudrate; }
byte DTMFGetBin(DTMFDriver *me) { byte HexDigit = me_data &= me_mask; /* Leer dato desde el puerto */ /*************/ PortEnable8870(me); /* Tomar bus */ while (me_std && !me_hook) /* Esperar key release */ ClrWdt(); return HexDigit; }//
void high_isr(void) { ClrWdt(); #ifdef USE_CAN canISR(); #endif tickUpdate(); }