void configure_ports(const uint8_t *port_mapping, uint8_t *PxMAPy, uint8_t num_of_ports, uint8_t port_map_reconfig) { uint16_t i; // Store current interrupt state, then disable all interrupts uint16_t globalInterruptState = __read_status_register() & GIE; __dint(); // Get write-access to port mapping registers: PMAPPWD = PMAPPW; if (port_map_reconfig){ // Allow reconfiguration during runtime: PMAPCTL = PMAPRECFG; } // Configure Port Mapping: for (i = 0; i < num_of_ports * 8; i++){ PxMAPy[i] = port_mapping[i]; } // Disable write-access to port mapping registers: PMAPPWD = 0; // Restore previous interrupt state __bis_status_register(globalInterruptState); }
uint8_t get_button_rpt(uint8_t button_mask) { __dint(); __no_operation(); button_mask &= button_rpt; button_rpt ^= button_mask; __nop(); __eint(); return button_mask; }
uint8_t get_button_press(uint8_t button_mask) { __dint(); __no_operation(); button_mask &= button_press; button_press ^= button_mask; __nop(); __eint(); return button_mask; }
/******************************************* INITIALIZE *******************************************/ int main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer BCSCTL1 = CALBC1_1MHZ; DCOCTL = CALDCO_1MHZ; serial_init(9600); __dint(); // Enable global interrupts /******************************************* MAIN LOOP *******************************************/ for(;;) { int j = 0; // Char array counter char cmd_line[90] = { 0 }; // Init empty array cio_print((char *) "$ "); // Display prompt char c = cio_getc(); // Wait for a character while(c != '\r') { // until return sent then ... if(c == 0x08) { // was it the delete key? if(j != 0) { // cursor NOT at start? cmd_line[--j] = 0; // delete key logic cio_printc(0x08); cio_printc(' '); cio_printc(0x08); } } else { // otherwise ... cmd_line[j++] = c; cio_printc(c); // echo received char } c = cio_getc(); // Wait for another } cio_print((char *) "\n\n\r"); // Delimit command result switch(shell_process(cmd_line)) // Execute specified shell command { // and handle any errors case SHELL_PROCESS_ERR_CMD_UNKN: cio_print((char *) "ERROR, unknown command given\n\r"); break; case SHELL_PROCESS_ERR_ARGS_LEN: cio_print((char *) "ERROR, an arguement is too lengthy\n\r"); break; case SHELL_PROCESS_ERR_ARGS_MAX: cio_print((char *) "ERROR, too many arguements given\n\r"); break; default: break; } cio_print((char *) "\n"); // Delimit before prompt } return 0; }
/** * Timer Get * * Get time ellapsed on our timer (maxes out at TICK_MAX) */ uint16_t TimerGet(Timer_t * timer) { Tick_t diff; __dint(); // disable interrupts diff = local_tick - timer->local_last; //works with uint wrap around timer->local_last = local_tick; __eint(); // enable interrupts if (((uint32_t)timer->tick + (uint32_t)diff) > (uint32_t)TICK_MAX) { timer->tick = TICK_MAX; } else { timer->tick = timer->tick+diff; } return timer->tick; }
void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode) { uint8_t bit = digitalPinToBitMask(interruptNum); uint8_t port = digitalPinToPort(interruptNum); if ((port == NOT_A_PIN) || !((mode == FALLING) || (mode == RISING) || (mode == CHANGE))) return; __dint(); switch(port) { case P1: if(mode != CHANGE) { P1IES = mode ? P1IES | bit : P1IES & ~bit; } else { intChangeVectP1 |= bit; P1IES = (P1IN & bit) ? (P1IES | bit) : (P1IES & ~bit); } P1IFG &= ~bit; intFuncP1[bit_pos(bit)] = userFunc; P1IE |= bit; break; #if defined(PORT2_VECTOR) case P2: if(mode != CHANGE) { P2IES = mode ? P2IES | bit : P2IES & ~bit; } else { intChangeVectP2 |= bit; P2IES = (P2IN & bit) ? (P2IES | bit) : (P2IES & ~bit); } P2IFG &= ~bit; intFuncP2[bit_pos(bit)] = userFunc; P2IE |= bit; break; #endif #if defined(PORT3_VECTOR) case P3: if(mode != CHANGE) { P3IES = mode ? P3IES | bit : P3IES & ~bit; } else { intChangeVectP3 |= bit; P3IES = (P3IN & bit) ? (P3IES | bit) : (P3IES & ~bit); } P3IFG &= ~bit; intFuncP3[bit_pos(bit)] = userFunc; P3IE |= bit; break; #endif #if defined(PORT4_VECTOR) case P4: if(mode != CHANGE) { P4IES = mode ? P4IES | bit : P4IES & ~bit; } else { intChangeVectP4 |= bit; P4IES = (P4IN & bit) ? (P4IES | bit) : (P4IES & ~bit); } P4IFG &= ~bit; intFuncP4[bit_pos(bit)] = userFunc; P4IE |= bit; break; #endif default: break; } __eint(); }