Last active
March 3, 2016 21:29
-
-
Save dekuNukem/61726b07ef15b740809a to your computer and use it in GitHub Desktop.
program mode of FAP controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void program_mode() | |
{ | |
// pull down BUSREQ | |
HAL_GPIO_WritePin(CPU_CTRL_PORT, CPU_BUSREQ_PIN, LOW);\ | |
// cycle clock until BUSACK is low, now CPU is kicked off the bus | |
while(HAL_GPIO_ReadPin(CPU_CTRL_PORT, CPU_BUSACK_PIN) != LOW) | |
cycle_clock(1); | |
// switch memory control signals to output to take over the bus | |
GPIO_InitTypeDef GPIO_InitStruct; | |
GPIO_InitStruct.Pin = CPU_MREQ_PIN | CPU_RD_PIN | CPU_WR_PIN; | |
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; | |
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; | |
HAL_GPIO_Init(CPU_CTRL_PORT, &GPIO_InitStruct); | |
// enable memory read | |
HAL_GPIO_WritePin(CPU_CTRL_PORT, CPU_MREQ_PIN, LOW); | |
HAL_GPIO_WritePin(CPU_CTRL_PORT, CPU_RD_PIN, LOW); | |
HAL_GPIO_WritePin(CPU_CTRL_PORT, CPU_WR_PIN, HIGH); | |
addr_output(); | |
data_input(); | |
CPU_ADDR_PORT->ODR = 0x0; | |
lcd_say("cls WHITE"); | |
lcd_say("xstr 10,10,310,45,2,BLACK,YELLOW,0,0,1,\"Program Mode\""); | |
lcd_say("xstr 10,60,310,45,1,BLACK,YELLOW,0,0,1,\"Awaiting commands...\""); | |
// start receiving serial commands | |
memset(debug_recv_buf, 0, DEBUG_RECV_SIZE); | |
HAL_UART_Receive_IT(&huart2, debug_recv_buf, DEBUG_RECV_SIZE-1); | |
while(1) | |
{ | |
char *cmd_start = has_command(debug_recv_buf, DEBUG_RECV_SIZE); | |
// if something is in recv buffer | |
if(cmd_start != NULL) | |
{ | |
// print the buffer to LCD | |
memset(lcd_xmit_buf, 0, LCD_XMIT_SIZE); | |
sprintf(lcd_xmit_buf, "xstr 10,120,310,45,2,BLACK,YELLOW,0,0,1,\"%s\"", cmd_start); | |
lcd_say(lcd_xmit_buf); | |
// eeprom read | |
if(strncmp(cmd_start, "r ", 2) == 0) | |
{ | |
int16_t arg1_pos = goto_next_arg(0, cmd_start); | |
uint16_t addr = atoi(cmd_start + arg1_pos); | |
uint8_t data = read_eeprom(addr); | |
memset(debug_xmit_buf, 0, DEBUG_XMIT_SIZE); | |
sprintf(debug_xmit_buf, "rd:a=%d,d=%d\r\n", addr, data); | |
HAL_UART_Transmit(&huart2, debug_xmit_buf, strlen(debug_xmit_buf), 1000); | |
} | |
// eeprom write | |
if(strncmp(cmd_start, "w ", 2) == 0) | |
{ | |
int16_t arg1_pos = goto_next_arg(0, cmd_start); | |
uint16_t addr = atoi(cmd_start + arg1_pos); | |
int16_t arg2_pos = goto_next_arg(arg1_pos, cmd_start); | |
uint8_t data = atoi(cmd_start + arg2_pos); | |
write_eeprom(addr, data); | |
uint8_t data_readback = read_eeprom(addr); | |
memset(debug_xmit_buf, 0, DEBUG_XMIT_SIZE); | |
sprintf(debug_xmit_buf, "wr:a=%d,d=%d\r\n", addr, data_readback); | |
HAL_UART_Transmit(&huart2, debug_xmit_buf, strlen(debug_xmit_buf), 1000); | |
} | |
// zeroing eeprom | |
if(strncmp(cmd_start, "z\r\n", 3) == 0) | |
{ | |
for (int i = 0; i < 0x4000; i++) | |
write_eeprom(i, 0); | |
HAL_UART_Transmit(&huart2, "zeroing..\r\n", strlen("zeroing..\r\n"), 1000); | |
HAL_UART_Transmit(&huart2, "zero complete\r\n", strlen("zero complete\r\n"), 1000); | |
} | |
memset(debug_recv_buf, 0, DEBUG_RECV_SIZE); | |
HAL_UART_Receive_IT(&huart2, debug_recv_buf, DEBUG_RECV_SIZE-1); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment