Example #1
0
int board_nand_init(struct nand_chip *nand)
{
	u_int32_t cfg;
	u_int8_t tacls, twrph0, twrph1;
	S3C24X0_CLOCK_POWER * const clk_power = S3C24X0_GetBase_CLOCK_POWER();

	DEBUGN("board_nand_init()\n");

	clk_power->CLKCON |= (1 << 4);

	/* initialize hardware */
	twrph0 = 3; twrph1 = 0; tacls = 0;

	cfg = S3C2440_NFCONF_TACLS(tacls);
	cfg |= S3C2440_NFCONF_TWRPH0(twrph0);
	cfg |= S3C2440_NFCONF_TWRPH1(twrph1);

	//S3C2440_NFCONT |= S3C2440_NFCONT_ENABLE;
	//S3C2440_NFCONF = cfg;
	S3C2440_NFCONT = 0x1;
	S3C2440_NFCONF = 0x2440;

	/* initialize nand_chip data structure */
	nand->IO_ADDR_R = nand->IO_ADDR_W = (void *)0x4e000010;

	/* read_buf and write_buf are default */
	/* read_byte and write_byte are default */

	/* hwcontrol always must be implemented */
	nand->cmd_ctrl = s3c2440_hwcontrol;

	nand->dev_ready = s3c2440_dev_ready;

#ifdef CONFIG_S3C2440_NAND_HWECC
	nand->ecc.hwctl = s3c2440_nand_enable_hwecc;
	nand->ecc.calculate = s3c2440_nand_calculate_ecc;
	nand->ecc.correct = s3c2440_nand_correct_data;
	nand->ecc.mode = NAND_ECC_HW3_512;
#else
	nand->ecc.mode = NAND_ECC_SOFT;
#endif

#ifdef CONFIG_S3C2440_NAND_BBT
	nand->options = NAND_USE_FLASH_BBT;
#else
	nand->options = 0;
#endif

        DEBUGN("board_nand_init() in cpu/arm920t/s3c24x0/nand.c\n");

	DEBUGN("end of nand_init\n");

	return 0;
}
Example #2
0
static void s3c2440_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl)
{
	struct nand_chip *chip = mtd->priv;
       
	DEBUGN("hwcontrol(): 0x%02x 0x%02x\n", cmd, ctrl);

	if (ctrl & NAND_CTRL_CHANGE) {
		ulong IO_ADDR_W = 0x4E000000;

		if (!(ctrl & NAND_CLE))
			IO_ADDR_W |= S3C2440_ADDR_NCLE;
		if (!(ctrl & NAND_ALE))
			IO_ADDR_W |= S3C2440_ADDR_NALE;

		chip->IO_ADDR_W = (void *)IO_ADDR_W;

		if (ctrl & NAND_NCE)
			S3C2440_NFCONT &= ~S3C2440_NFCONT_nFCE;
		else
			S3C2440_NFCONT |= S3C2440_NFCONT_nFCE;
	}

	if (cmd != NAND_CMD_NONE)
		writeb(cmd, chip->IO_ADDR_W);

}
void sendspeed(int leftSpeed, int rightSpeed)
{
    char buffer[20];
    static int errorCount;

#define DEBUGROBOTEQ //Print Speed Commands
#ifdef DEBUGROBOTEQ
    DEBUG(leftSpeed); DEBUGN(rightSpeed);
#endif
    if (roboteqHandle == INVALID_HANDLE_VALUE) {
        // Either the port was not opened or there was a failure
        // Try and open the robotEq again hope it works
        initRoboteq();
    }
    if(ABS(leftSpeed) > 1000) leftSpeed = SIGN(leftSpeed) * 1000;
    if(ABS(rightSpeed) > 1000) rightSpeed = SIGN(rightSpeed) * 1000;

    sprintf(buffer, "!G %01d %04d\r!G %01d %04d\r",
                leftChannelNum, leftSpeed, rightChannelNum,rightSpeed);

    if (roboteqHandle != INVALID_HANDLE_VALUE) {
        SerialPuts(roboteqHandle, buffer);
        FlushRx(roboteqHandle);
        FlushTx(roboteqHandle);
    } else {
        if (++errorCount % 100 == 0)    // Print every 100 times this happens
            fprintf(stderr, "Invalid roboteqPort. Did you open the port?\n");
    }
}
Example #4
0
static int s3c2440_nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat,
				      u_char *ecc_code)
{
	ecc_code[0] = NFMECC0;
	ecc_code[1] = NFMECC0>>8;
	ecc_code[2] = NFMECC0>>16;
	DEBUGN("s3c2440_nand_calculate_hwecc(%p,): 0x%02x 0x%02x 0x%02x\n",
		mtd , ecc_code[0], ecc_code[1], ecc_code[2]);

	return 0;
}
int open_serial(char *port, int baud, int nbits, int parity)
{
    int fd;
    struct termios options;

    DEBUG(baud);
    DEBUG(nbits);
    DEBUGN(parity);
    fd = open(port, O_RDWR | O_NOCTTY | O_NONBLOCK | O_NDELAY);
    if (fd == -1) {
        fprintf(stderr, "Open failure\n");
        return fd;
    }

    if (tcgetattr(fd, &options) == -1) {
        close(fd);
        fprintf(stderr, "Open failure\n");
        return -1;
    }
    cfsetispeed(&options, 9600);
    cfsetospeed(&options, baud);
    options.c_cflag &= ~(CRTSCTS | CSTOPB | CSIZE);
    options.c_cflag |= (nbits == 8 ? CS8 : CS7);
    if (parity == 0)
        options.c_cflag &= ~PARENB;
    else
        options.c_cflag |= PARENB;
    if (parity == 2)
        options.c_cflag &= ~PARODD;
    else
        options.c_cflag |= PARODD;

    options.c_oflag &= ~OPOST;
    options.c_oflag &= ~(NLDLY | CRDLY | TABDLY | BSDLY | VTDLY | FFDLY);

    fcntl(fd, F_SETFL, O_NONBLOCK);
//      fcntl(fd, F_SETFL, FASYNC);

    if (tcsetattr(fd, TCSANOW, &options) == -1) {
        close(fd);
        fprintf(stderr, "Open failure\n");
        return -1;
    }
    return fd;
}
//------------------------------------------------------------------------------
HANDLE SerialInit(int PortNum, int BaudRate, int dataBit, int parity,
                  int cts, int rts, int dsr, int dtr)
{
    HANDLE hCom;
    char serfilename[512];
    BOOL bPortReady;            // Not used except for debugging
    DCB dcb;
    COMMTIMEOUTS CommTimeouts;

    sprintf(serfilename, "%s%d", "\\\\.\\com", PortNum);

    hCom = CreateFile(serfilename, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, //FILE_FLAG_OVERLAPPED,
                      0);

    //  DEBUG(hCom);
    if (hCom == INVALID_HANDLE_VALUE) {
        //     fprintf(stderr, "Error: COM%d(%s):%d\n", PortNum, serfilename, GetLastError());
//        if (GetLastError() == ERROR_FILE_NOT_FOUND)
//            printf("Serial port %d does not exist \n", PortNum);
        return hCom;
    }

    bPortReady = SetupComm(hCom, 128, 128);       // set buffer sizes
    DEBUGN(bPortReady);// verify action completed successfully
    bPortReady = GetCommState(hCom, &dcb);
    DEBUGN(bPortReady);// verify action completed successfully

    dcb.BaudRate = BaudRate;
    dcb.ByteSize = dataBit;
    dcb.StopBits = ONESTOPBIT;
    if (parity == 0)
        dcb.Parity = NOPARITY;
    else if (parity == 1)
        dcb.Parity = ODDPARITY;
    else if (parity == 2)
        dcb.Parity = EVENPARITY;
    else if (parity == 3)
        dcb.Parity = MARKPARITY;
    else
        dcb.Parity = NOPARITY;  //default

    dcb.fAbortOnError = TRUE;

/**set XON/XOFF**/
    dcb.fOutX = FALSE;          // XON/XOFF off for transmit
    dcb.fInX = FALSE;           // XON/XOFF off for receive
/**set RTSCTS**/
    if (cts == 1)
        dcb.fOutxCtsFlow = TRUE;
    else
        dcb.fOutxCtsFlow = FALSE;       //default is FALSE
    //dcb.fOutxCtsFlow = FALSE;   // turn off CTS flow control
    if (rts == 0)
        dcb.fRtsControl = FALSE;
    else if (rts == 1)
        dcb.fRtsControl = TRUE;
    else if (rts == 2)
        dcb.fRtsControl = RTS_CONTROL_HANDSHAKE;
    else
        dcb.fRtsControl = RTS_CONTROL_HANDSHAKE;        //default is HANDSHAKE
    //dcb.fRtsControl = RTS_CONTROL_ENABLE;//
/** set DSRDTR**/
    if (dsr == 1)
        dcb.fOutxDsrFlow = TRUE;
    else
        dcb.fOutxDsrFlow = FALSE;       //default is FALSE
    //dcb.fOutxDsrFlow = FALSE;   // turn off DSR flow control
    if (dtr == 0)
        dcb.fDtrControl = DTR_CONTROL_DISABLE;  //
    else if (dtr == 1)
        dcb.fDtrControl = DTR_CONTROL_ENABLE;   //
    else if (dtr == 2)
        dcb.fDtrControl = DTR_CONTROL_HANDSHAKE;        //
    else
        dcb.fDtrControl = DTR_CONTROL_DISABLE;  //default DISABLE

    bPortReady = SetCommState(hCom, &dcb);
    DEBUGN(bPortReady);// verify action completed successfully

// Communication timeouts are optional

    bPortReady = GetCommTimeouts(hCom, &CommTimeouts);
    DEBUGN(bPortReady);// verify action completed successfully

    CommTimeouts.ReadIntervalTimeout = Read_Timeout;    //Was 5000;
    CommTimeouts.ReadTotalTimeoutConstant = Read_Timeout;       //Was 5000;
    CommTimeouts.ReadTotalTimeoutMultiplier = Read_Timeout / 5; //Was 1000;
    CommTimeouts.WriteTotalTimeoutConstant = 5000;
    CommTimeouts.WriteTotalTimeoutMultiplier = 1000;

    bPortReady = SetCommTimeouts(hCom, &CommTimeouts);
    DEBUGN(bPortReady);// verify action completed successfully

    return hCom;
}
Example #7
0
void s3c2440_nand_enable_hwecc(struct mtd_info *mtd, int mode)
{
	DEBUGN("s3c2440_nand_enable_hwecc(%p, %d)\n", mtd, mode);
	NFCONT |= S3C2440_NFCONT_INITECC;
}
Example #8
0
static int s3c2440_dev_ready(struct mtd_info *mtd)
{
	DEBUGN("dev_ready\n");
	return (S3C2440_NFSTAT & S3C2440_NFSTAT_READY);
}